import { Component , OnDestroy , OnInit } from '@angular/core' ; import { FileSaverService } from 'ngx-filesaver' ; import { ActivatedRoute } from '@angular/router' ; import { NgbModal , NgbModalConfig , NgbModalRef } from '@ng-bootstrap/ng-bootstrap' ; import { APIGetMultiResponse } from '../../../../services/models/api-response' ; import { FileMetadata } from '../../../../layout/components/file-explorer/model/metadata' ; import { FileService } from '../../../../layout/components/file-explorer/service/file.service' ; import { FileElement } from '../../../../layout/components/file-explorer/model/file-element' ; import { AttachmentsListModalComponent } from '../../../../layout/helpers/modals/attachments-list-modal/attachments-list-modal.component' ; @ Component ( { selector : 'cmdb-object-attachments' , templateUrl : './object-attachments.component.html' , styleUrls : [ './object-attachments.component.scss' ] } ) export class ObjectAttachmentsComponent implements OnInit , OnDestroy { public attachments : FileElement [ ] = [ ] ; public attachmentsTotal : number = 0 ; private metadata : FileMetadata = new FileMetadata ( ) ; private modalRef : NgbModalRef ; constructor ( private fileService , private fileSaverService , private route , private modalService , private config ) { this . route . params . subscribe ( ( params ) => { this . metadata . reference = Number ( params . publicID ) ; this . metadata . reference_type = 'object' ; } ) ; config . backdrop = 'static' ; config . keyboard = false ; } public ngOnInit ( ) { this . fileService . getAllFilesList ( this . metadata ) . subscribe ( ( resp ) => { this . attachments = resp . results ; this . attachmentsTotal = resp . total ; } ) ; } public ngOnDestroy ( ) { if ( this . modalRef ) { this . modalRef . close ( ) ; } } public showAttachments ( ) { this . modalRef = this . modalService . open ( AttachmentsListModalComponent ) ; this . modalRef . componentInstance . metadata = this . metadata ; this . modalRef . result . then ( ( result ) => { this . attachmentsTotal = result . total ; } ) ; } }