|
@@ -1,16 +1,16 @@
|
|
|
-import {Component, OnDestroy, OnInit} from '@angular/core';
|
|
|
|
|
-import {ActivatedRoute} from '@angular/router';
|
|
|
|
|
|
|
+import { Component, OnDestroy, OnInit } from '@angular/core';
|
|
|
|
|
+import { ActivatedRoute } from '@angular/router';
|
|
|
import * as moment from 'moment-timezone';
|
|
import * as moment from 'moment-timezone';
|
|
|
-import {AnalyticsService} from '../../shared/api/endpoints/services/analytics.service';
|
|
|
|
|
-import {AggregationModel} from '../../shared/models/aggregationModel';
|
|
|
|
|
-import {GraphLoader} from '../../shared/graph-loading/graphloader';
|
|
|
|
|
-import {ObservationService} from '../../shared/api/endpoints/services/observation.service';
|
|
|
|
|
-import {HttpResponse} from '@angular/common/http';
|
|
|
|
|
-import {map} from 'rxjs/operators';
|
|
|
|
|
-import {ToastService} from '../../shared/services/toast.service';
|
|
|
|
|
-import {Sensor} from '../../shared/api/endpoints/models/sensor';
|
|
|
|
|
-import {SensorsService} from '../../shared/api/endpoints/services/sensors.service';
|
|
|
|
|
-import {Subscription} from 'rxjs';
|
|
|
|
|
|
|
+import { AnalyticsService } from '../../shared/api/endpoints/services/analytics.service';
|
|
|
|
|
+import { AggregationModel } from '../../shared/models/aggregationModel';
|
|
|
|
|
+import { GraphLoader } from '../../shared/graph-loading/graphloader';
|
|
|
|
|
+import { ObservationService } from '../../shared/api/endpoints/services/observation.service';
|
|
|
|
|
+import { HttpResponse } from '@angular/common/http';
|
|
|
|
|
+import { map } from 'rxjs/operators';
|
|
|
|
|
+import { ToastService } from '../../shared/services/toast.service';
|
|
|
|
|
+import { Sensor } from '../../shared/api/endpoints/models/sensor';
|
|
|
|
|
+import { SensorsService } from '../../shared/api/endpoints/services/sensors.service';
|
|
|
|
|
+import { Subscription } from 'rxjs';
|
|
|
|
|
|
|
|
@Component({
|
|
@Component({
|
|
|
selector: 'app-sensor',
|
|
selector: 'app-sensor',
|
|
@@ -43,7 +43,7 @@ export class SensorComponent implements OnInit, OnDestroy {
|
|
|
private route: ActivatedRoute,
|
|
private route: ActivatedRoute,
|
|
|
) {
|
|
) {
|
|
|
this.getInitData();
|
|
this.getInitData();
|
|
|
- this.sensorsService.getUnitSensors({unit_id: this.unitId}).subscribe(sensors => {
|
|
|
|
|
|
|
+ this.sensorsService.getUnitSensors({ unit_id: this.unitId }).subscribe(sensors => {
|
|
|
if (sensors) {
|
|
if (sensors) {
|
|
|
this.sensor = sensors.filter(value => value.sensorId === this.sensorId)[0];
|
|
this.sensor = sensors.filter(value => value.sensorId === this.sensorId)[0];
|
|
|
this.showGraph(); // show default graph
|
|
this.showGraph(); // show default graph
|
|
@@ -56,17 +56,17 @@ export class SensorComponent implements OnInit, OnDestroy {
|
|
|
*/
|
|
*/
|
|
|
getInitData() {
|
|
getInitData() {
|
|
|
this.route.queryParams.subscribe(params => {
|
|
this.route.queryParams.subscribe(params => {
|
|
|
- if(params.unitName) {
|
|
|
|
|
|
|
+ if (params.unitName) {
|
|
|
this.unitDescription = params.unitName;
|
|
this.unitDescription = params.unitName;
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
this.sensorId = parseInt(this.activatedRoute.snapshot.paramMap.get('sensorId'), 10);
|
|
this.sensorId = parseInt(this.activatedRoute.snapshot.paramMap.get('sensorId'), 10);
|
|
|
this.unitId = parseInt(this.activatedRoute.snapshot.paramMap.get('unitId'), 10);
|
|
this.unitId = parseInt(this.activatedRoute.snapshot.paramMap.get('unitId'), 10);
|
|
|
this.aggregationFunction = [
|
|
this.aggregationFunction = [
|
|
|
- {name: 'Hour', code: 'HOUR'},
|
|
|
|
|
- {name: 'Day', code: 'DAY'},
|
|
|
|
|
- {name: 'Month', code: 'MONTH'},
|
|
|
|
|
- {name: 'Year', code: 'YEAR'}
|
|
|
|
|
|
|
+ { name: 'Hour', code: 'HOUR' },
|
|
|
|
|
+ { name: 'Day', code: 'DAY' },
|
|
|
|
|
+ { name: 'Month', code: 'MONTH' },
|
|
|
|
|
+ { name: 'Year', code: 'YEAR' }
|
|
|
];
|
|
];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -83,24 +83,28 @@ export class SensorComponent implements OnInit, OnDestroy {
|
|
|
/**
|
|
/**
|
|
|
* Shows aggregation select box and get data button
|
|
* Shows aggregation select box and get data button
|
|
|
*/
|
|
*/
|
|
|
- aggregationShow() {
|
|
|
|
|
|
|
+ // aggregationShow() {
|
|
|
|
|
+ // this.dateChanged = true;
|
|
|
|
|
+ // this.showAggregation = moment(this.to).diff(moment(this.from), 'days') > 7;
|
|
|
|
|
+ // }
|
|
|
|
|
+
|
|
|
|
|
+ onDateChanged(): void{
|
|
|
this.dateChanged = true;
|
|
this.dateChanged = true;
|
|
|
- this.showAggregation = moment(this.to).diff(moment(this.from), 'days') > 7;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Gets data based on selected time range
|
|
* Gets data based on selected time range
|
|
|
*/
|
|
*/
|
|
|
showGraph() {
|
|
showGraph() {
|
|
|
- if (moment(this.to).diff(moment(this.from), 'days') > 7) {
|
|
|
|
|
- this.showAggregation = true;
|
|
|
|
|
- const range: Date[] = [this.from, this.to];
|
|
|
|
|
- this.getAnalytics(range);
|
|
|
|
|
- } else {
|
|
|
|
|
- this.showAggregation = false;
|
|
|
|
|
- const range: Date[] = [this.from, this.to];
|
|
|
|
|
- this.getObservations(range);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // if (moment(this.to).diff(moment(this.from), 'days') > 7) {
|
|
|
|
|
+ // this.showAggregation = true;
|
|
|
|
|
+ // const range: Date[] = [this.from, this.to];
|
|
|
|
|
+ // this.getAnalytics(range);
|
|
|
|
|
+ // } else {
|
|
|
|
|
+ //this.showAggregation = false;
|
|
|
|
|
+ const range: Date[] = [this.from, this.to];
|
|
|
|
|
+ this.getObservations(range);
|
|
|
|
|
+ //}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -159,7 +163,7 @@ export class SensorComponent implements OnInit, OnDestroy {
|
|
|
if (observations) {
|
|
if (observations) {
|
|
|
GraphLoader.getGraph(this.sensorId, observations, this.sensor, '#view', false);
|
|
GraphLoader.getGraph(this.sensorId, observations, this.sensor, '#view', false);
|
|
|
} else {
|
|
} else {
|
|
|
- GraphLoader.getGraph(null, null, null,'#view', null);
|
|
|
|
|
|
|
+ GraphLoader.getGraph(null, null, null, '#view', null);
|
|
|
}
|
|
}
|
|
|
}, err => this.toastService.showError(err.error.message));
|
|
}, err => this.toastService.showError(err.error.message));
|
|
|
}
|
|
}
|