import { Component , HostListener , OnDestroy , OnInit } from '@angular/core' ; import { ActivatedRoute , Data } from '@angular/router' ; import { ObjectService } from '../../services/object.service' ; import { CmdbMode } from '../../modes.enum' ; import { RenderResult } from '../../models/cmdb-render' ; import { BehaviorSubject , Subject } from 'rxjs' ; import { take , takeUntil } from 'rxjs/operators' ; @ Component ( { selector : 'cmdb-object-view' , templateUrl : './object-view.component.html' , styleUrls : [ './object-view.component.scss' ] } ) export class ObjectViewComponent implements OnInit , OnDestroy { public mode : CmdbMode = CmdbMode . View ; public renderResult : RenderResult ; /**
     * Component un-subscriber.
     */ private unsubscribe = new Subject ( ) ; /**
     * Current type from the route resolve.
     */ private objectViewSubject : BehaviorSubject < RenderResult > = new BehaviorSubject < RenderResult > ( undefined ) ; constructor ( public objectService , private activateRoute ) { this . activateRoute . data . subscribe ( ( data ) => { this . objectViewSubject . next ( data . object as RenderResult ) ; } ) ; } public ngOnInit ( ) { this . objectViewSubject . asObservable ( ) . pipe ( takeUntil ( this . unsubscribe ) ) . subscribe ( ( result ) => { this . renderResult = result ; } ) ; } @ HostListener ( 'window:scroll' ) onWindowScroll ( ) { const dialog = document . getElementsByClassName ( 'object-view-navbar' ) as HTMLCollectionOf < any > ; dialog [ 0 ] . id = 'object-form-action' ; if ( document . body . scrollTop > 20 || document . documentElement . scrollTop > 20 ) { dialog [ 0 ] . style . visibility = 'visible' ; dialog [ 0 ] . classList . add ( 'shadow' ) ; } else { dialog [ 0 ] . classList . remove ( 'shadow' ) ; dialog [ 0 ] . id = '' ; } } public ngOnDestroy ( ) { this . unsubscribe . next ( ) ; this . unsubscribe . complete ( ) ; } }