import { Component , ElementRef , Inject , ViewRef } from '@angular/core' ; import { HsDialogComponent } from 'hslayers-ng' ; import { HsDialogContainerService } from 'hslayers-ng' ; import { HsLayoutService } from 'hslayers-ng' ; import { HsSensorsUnitDialogService } from './unit-dialog.service' ; import { HsUtilsService } from 'hslayers-ng' ; @ Component ( { selector : 'hs-sensor-unit' , templateUrl : './partials/unit-dialog.html' , } ) export class HsSensorsUnitDialogComponent implements HsDialogComponent { customInterval = { name : 'Custom' , fromTime : new Date ( ) , toTime : new Date ( ) } ; constructor ( public HsLayoutService , public HsDialogContainerService , public HsSensorsUnitDialogService , public HsUtilsService , elementRef ) { this . HsSensorsUnitDialogService . unitDialogVisible = true ; this . HsSensorsUnitDialogService . dialogElement = elementRef ; } viewRef : ViewRef ; data : any ; ngOnInit ( ) { this . timeButtonClicked ( this . HsSensorsUnitDialogService . intervals [ 2 ] ) ; } param { object } sensor description sensorClicked ( sensor ) { this . HsSensorsUnitDialogService . selectSensor ( sensor ) ; if ( this . HsSensorsUnitDialogService . currentInterval == undefined ) { this . timeButtonClicked ( { amount : 1 , unit : 'days' } ) ; } else { this . HsSensorsUnitDialogService . createChart ( this . HsSensorsUnitDialogService . unit ) ; } } param { object } interval description timeButtonClicked ( interval ) { this . HsSensorsUnitDialogService . currentInterval = interval ; const fromTo = this . HsSensorsUnitDialogService . getTimeForInterval ( interval ) ; Object . assign ( this . customInterval , { fromTime : fromTo . from_time . toDate ( ) , toTime : fromTo . to_time . toDate ( ) , } ) ; this . HsSensorsUnitDialogService . getObservationHistory ( this . HsSensorsUnitDialogService . unit , interval ) . then ( ( _ ) => { this . HsSensorsUnitDialogService . createChart ( this . HsSensorsUnitDialogService . unit ) ; } ) ; } customIntervalChanged ( ) { this . HsSensorsUnitDialogService . currentInterval = this . customInterval ; this . HsSensorsUnitDialogService . getObservationHistory ( this . HsSensorsUnitDialogService . unit , this . customInterval ) . then ( ( _ ) => this . HsSensorsUnitDialogService . createChart ( this . HsSensorsUnitDialogService . unit ) ) ; } dialogStyle ( ) { return { 'visibility' : this . HsSensorsUnitDialogService . unitDialogVisible ? 'visible' : 'hidden' , 'left' : this . HsLayoutService . sidebarBottom ( ) ? '3px' : this . HsLayoutService . panelSpaceWidth ( ) + 10 + 'px' , 'width' : this . HsLayoutService . sidebarBottom ( ) ? '100%' : 'calc(' + this . HsLayoutService . widthWithoutPanelSpace ( ) + ')' , 'bottom' : this . HsLayoutService . sidebarBottom ( ) ? '46.5em' : '0' , 'height' : this . HsLayoutService . sidebarBottom ( ) ? '5em' : 'auto' , } ; } close ( ) { this . HsDialogContainerService . destroy ( this ) ; this . HsSensorsUnitDialogService . unitDialogVisible = false ; } }