import { Component , Input , OnDestroy , OnInit } from '@angular/core' ; import { LinkService } from '../../../../services/link.service' ; import { CmdbLink } from '../../../../models/cmdb-link' ; import { ObjectService } from '../../../../services/object.service' ; import { RenderResult } from '../../../../models/cmdb-render' ; import { CmdbObject } from '../../../../models/cmdb-object' ; import { BehaviorSubject , Observable , ReplaySubject } from 'rxjs' ; import { takeUntil } from 'rxjs/operators' ; @ Component ( { selector : 'cmdb-object-links-table-partner-cell' , templateUrl : './object-links-table-partner-cell.component.html' , styleUrls : [ './object-links-table-partner-cell.component.scss' ] } ) export class ObjectLinksTablePartnerCellComponent implements OnInit , OnDestroy { /**
     * Global un-subscriber for http calls to the rest backend.
     */ private subscriber : ReplaySubject < void > = new ReplaySubject < void > ( ) ; @ Input ( ) public objectID : number ; public link : CmdbLink ; @ Input ( 'link' ) public set Link ( link ) { this . link = link ; this . partnerIDSubject . next ( this . linkService . getPartnerID ( this . objectID , this . link ) ) ; } public errorLoading : boolean = false ; public partnerIDSubject : BehaviorSubject < number > = new BehaviorSubject < number > ( undefined ) ; public partnerIDObservable : Observable < number > = this . partnerIDSubject . asObservable ( ) ; public partnerObject : RenderResult | CmdbObject ; constructor ( private linkService , private objectService ) { } public ngOnInit ( ) { this . partnerIDObservable . pipe ( takeUntil ( this . subscriber ) ) . subscribe ( ( id ) => { this . objectService . getObject ( id ) . pipe ( takeUntil ( this . subscriber ) ) . subscribe ( ( result ) => { this . partnerObject = result ; } , ( ) => this . errorLoading = true ) ; } ) ; } /**
     * Unsubscribe all on component destroy.
     */ public ngOnDestroy ( ) { this . subscriber . next ( ) ; this . subscriber . complete ( ) ; } }