import { Component , EventEmitter , Input , Output } from '@angular/core' ; import { RenderResult } from '../../../models/cmdb-render' ; import { ObjectService } from '../../../services/object.service' ; import { ToastService } from '../../../../layout/toast/toast.service' ; @ Component ( { selector : 'cmdb-object-header' , templateUrl : './object-header.component.html' , styleUrls : [ './object-header.component.scss' ] } ) export class ObjectHeaderComponent { public activeState : boolean = true ; private result : RenderResult ; private objectID : number ; @ Output ( ) stateChange = new EventEmitter < boolean > ( ) ; @ Input ( 'renderResult' ) public set renderResult ( result ) { if ( result !== undefined ) { this . result = result ; this . activeState = this . result . object_information . active ; this . objectID = this . result . object_information . object_id ; } } public get renderResult ( ) : RenderResult { return this . result ; } public constructor ( private objectService , private toastService ) { } public toggleChange ( ) { this . activeState = this . activeState !== true ; this . objectService . changeState ( this . objectID , this . activeState ) . subscribe ( ( resp ) => { this . toastService . info ( `Changed active state to ${ this . activeState }` ) ; this . stateChange . emit ( true ) ; } ) ; } }