import { Component , Input , OnInit } from '@angular/core' ; import { FileMetadata } from '../../../components/file-explorer/model/metadata' ; import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap' ; import { APIGetMultiResponse } from '../../../../services/models/api-response' ; import { FileElement , SelectedFileArray } from '../../../components/file-explorer/model/file-element' ; import { FileService } from '../../../components/file-explorer/service/file.service' ; import { ToastService } from '../../../toast/toast.service' ; @ Component ( { selector : 'cmdb-filemanager-modal' , templateUrl : './filemanager-modal.component.html' , styleUrls : [ './filemanager-modal.component.scss' ] } ) export class FilemanagerModalComponent implements OnInit { @ Input ( ) localMetadata : FileMetadata = new FileMetadata ( ) ; public selectedFileElements : SelectedFileArray = { files : [ ] , totalSize : 0 } ; public recordsTotal : number = 0 ; constructor ( public activeModal , private fileService , private toast ) { } public ngOnInit ( ) { this . fileService . getAllFilesList ( this . localMetadata ) . subscribe ( ( data ) => { this . recordsTotal = data . total ; } ) ; } public postFileOnDone ( ) { const { reference , reference_type } = this . localMetadata ; const newReference = typeof reference === 'number' ? [ reference ] : reference ; this . selectedFileElements . files . forEach ( fileElement => { const tempReference = fileElement . metadata . reference ? fileElement . metadata . reference : [ ] ; fileElement . metadata . reference = typeof tempReference === 'number' ? [ tempReference ] . concat ( newReference ) : tempReference . concat ( newReference ) ; fileElement . metadata . reference_type = reference_type ; this . fileService . putFile ( fileElement , true ) . subscribe ( ( resp ) => { this . toast . info ( `File(s) was successfully added: ${ resp . filename }` ) ; } ) ; } ) ; this . activeModal . close ( true ) ; } }