import { Component , OnInit } from '@angular/core' ; import { FormControl , FormGroup , Validators } from '@angular/forms' ; import { FileMetadata } from '../../model/metadata' ; import { FileService } from '../../service/file.service' ; import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap' ; import { FileElement } from '../../model/file-element' ; import { APIGetMultiResponse } from '../../../../../services/models/api-response' ; import { CollectionParameters } from "../../../../../services/models/api-parameter" ; @ Component ( { selector : 'cmdb-move-dialog' , templateUrl : './move-dialog.component.html' , styleUrls : [ './move-dialog.component.scss' ] } ) export class MoveDialogComponent implements OnInit { public basicForm : FormGroup ; public destinationFolder : FileElement [ ] = [ ] ; private readonly defaultApiParameter : CollectionParameters = { page : 1 , limit : 100 , order : 1 } ; constructor ( private fileService , public activeModal ) { } groupByFn = ( item ) => item . metadata . parent ? item . metadata . parent : 0 ; groupValueFn = ( _ , children ) => ( { parentName : this . findParentName ( children [ 0 ] . metadata . parent ) , total : children . length , public_id : children [ 0 ] . metadata . parent } ) ; private findParentName ( publicID ) { return publicID === null ? 'Without Parent' : this . destinationFolder . filter ( x => x . public_id === publicID ) [ 0 ] . filename ; } public ngOnInit ( ) { this . basicForm = new FormGroup ( { folder : new FormControl ( null , Validators . required ) } ) ; this . fileService . getAllFilesList ( new FileMetadata ( { folder : true } ) , this . defaultApiParameter ) . subscribe ( ( data ) => { this . destinationFolder = data . results ; } ) ; } }