import { Component , OnChanges , Input , SimpleChanges } from '@angular/core' ; import { RenderResult } from '../../../models/cmdb-render' ; import { DocTemplate } from '../../../../docapi/models/cmdb-doctemplate' ; import { DocapiService } from '../../../../docapi/docapi.service' ; import { FileSaverService } from 'ngx-filesaver' ; @ Component ( { selector : 'cmdb-object-docs' , templateUrl : './object-docs.component.html' , styleUrls : [ './object-docs.component.scss' ] } ) export class ObjectDocsComponent implements OnChanges { @ Input ( ) renderResult : RenderResult ; docs : DocTemplate [ ] ; constructor ( private docapiService , private fileSaverService ) { } ngOnChanges ( changes ) { if ( changes . renderResult && this . renderResult ) { this . docapiService . getObjectDocTemplateList ( this . renderResult . type_information . type_id ) . subscribe ( ( docs ) => { this . docs = docs ; } ) ; } } public downloadDocument ( templateId , objectId , docName ) { const filename = docName + '.pdf' ; this . docapiService . getRenderedObjectDoc ( templateId , objectId ) . subscribe ( res => this . saveFile ( res , filename ) ) ; } public saveFile ( data , filename ) { this . fileSaverService . save ( data . body , filename ) ; } }