import { ChangeDetectorRef , Component } from '@angular/core' ; import { RuntimeService } from '../../services/runtime.service' ; import { GadgetInstanceService } from '../../grid/grid.service' ; import { EndPointService } from '../../configuration/tab-endpoint/endpoint.service' ; import { GadgetPropertyService } from '../_common/gadget-property.service' ; import { GadgetBase } from '../_common/gadget-base' ; import { StatisticService } from './service' ; import { OptionsService } from "../../configuration/tab-options/service" ; @ Component ( { selector : 'app-dynamic-component' , moduleId : module . id , templateUrl : './view.html' , styleUrls : [ '../_common/styles-gadget.css' ] } ) export class StatisticGadgetComponent extends GadgetBase { gadgetHasOperationControls = false ; data : any ; resource : string ; constructor ( protected _statisticService , protected _procMonRuntimeService , protected _gadgetInstanceService , protected _propertyService , protected _endPointService , protected _changeDetectionRef , protected _optionsService ) { super ( _procMonRuntimeService , _gadgetInstanceService , _propertyService , _endPointService , _changeDetectionRef , _optionsService ) ; this . run ( ) ; } public preRun ( ) { this . resource = this . getPropFromPropertyPages ( 'resource' ) ; this . updateData ( null ) ; } public run ( ) { this . data = [ ] ; this . initializeRunState ( true ) ; this . updateData ( null ) ; } public stop ( ) { this . setStopState ( false ) ; } public updateData ( data ) { this . _statisticService . get ( this . resource ) . subscribe ( data => { this . data = data ; } , error => this . handleError ( error ) ) ; } public updateProperties ( updatedProperties ) { /**
         * todo
         *  A similar operation exists on the procmman-config-service
         *  whenever the property page form is saved, the in memory board model
         *  is updated as well as the gadget instance properties
         *  which is what the code below does. This can be eliminated with code added to the
         *  config service or the property page service.
         *
         * **/ const updatedPropsObject = JSON . parse ( updatedProperties ) ; this . propertyPages . forEach ( function ( propertyPage ) { for ( let x = 0 ; x < propertyPage . properties . length ; x ++ ) { for ( const prop in updatedPropsObject ) { if ( updatedPropsObject . hasOwnProperty ( prop ) ) { if ( prop === propertyPage . properties [ x ] . key ) { propertyPage . properties [ x ] . value = updatedPropsObject [ prop ] ; } } } } } ) ; this . resource = updatedPropsObject . resource ; this . title = updatedPropsObject . title ; this . setEndPoint ( updatedPropsObject . endpoint ) ; this . updateData ( null ) ; } }