|
@@ -1,4 +1,4 @@
|
|
|
-import { Component, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core';
|
|
|
|
|
|
|
+import { Component, OnDestroy, OnInit, ViewEncapsulation, Renderer2, ViewChildren, QueryList, ElementRef } from '@angular/core';
|
|
|
import { ActivatedRoute } from '@angular/router';
|
|
import { ActivatedRoute } from '@angular/router';
|
|
|
import { map, tap } from 'rxjs/operators';
|
|
import { map, tap } from 'rxjs/operators';
|
|
|
import * as moment from 'moment-timezone';
|
|
import * as moment from 'moment-timezone';
|
|
@@ -10,6 +10,7 @@ import { Sensor } from '../../shared/api/endpoints/models/sensor';
|
|
|
import { ObservationService } from '../../shared/api/endpoints/services/observation.service';
|
|
import { ObservationService } from '../../shared/api/endpoints/services/observation.service';
|
|
|
import { SensorType } from '../../shared/api/endpoints/models/sensor-type';
|
|
import { SensorType } from '../../shared/api/endpoints/models/sensor-type';
|
|
|
import { Subscription } from 'rxjs';
|
|
import { Subscription } from 'rxjs';
|
|
|
|
|
+import {ConsoleLogger} from '@angular/compiler-cli';
|
|
|
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
@Component({
|
|
@@ -37,12 +38,20 @@ export class UnitComponent implements OnInit, OnDestroy {
|
|
|
subscription: Subscription[] = [];
|
|
subscription: Subscription[] = [];
|
|
|
showIntervalError = false;
|
|
showIntervalError = false;
|
|
|
|
|
|
|
|
|
|
+ // One flag per group
|
|
|
|
|
+ showVega: Record<string, boolean> = {};
|
|
|
|
|
+ showVegaCounter: Record<string, number> = {};
|
|
|
|
|
+
|
|
|
|
|
+ // Grab *all* containers that match the template ref vegaContainer
|
|
|
|
|
+ @ViewChildren('vegaContainer') vegaContainers!: QueryList<ElementRef>;
|
|
|
|
|
+
|
|
|
constructor(
|
|
constructor(
|
|
|
private activatedRoute: ActivatedRoute,
|
|
private activatedRoute: ActivatedRoute,
|
|
|
private sensorService: SensorsService,
|
|
private sensorService: SensorsService,
|
|
|
private toastService: ToastService,
|
|
private toastService: ToastService,
|
|
|
private observationService: ObservationService,
|
|
private observationService: ObservationService,
|
|
|
private route: ActivatedRoute,
|
|
private route: ActivatedRoute,
|
|
|
|
|
+ private renderer: Renderer2
|
|
|
) {
|
|
) {
|
|
|
this.getInitData();
|
|
this.getInitData();
|
|
|
// get unit sensors and prepare them for view
|
|
// get unit sensors and prepare them for view
|
|
@@ -98,6 +107,10 @@ export class UnitComponent implements OnInit, OnDestroy {
|
|
|
this.dateChanged = false;
|
|
this.dateChanged = false;
|
|
|
this.showIntervalError = true;
|
|
this.showIntervalError = true;
|
|
|
}
|
|
}
|
|
|
|
|
+ else if (this.to < this.from) {
|
|
|
|
|
+ this.dateChanged = false;
|
|
|
|
|
+ this.showIntervalError = true;
|
|
|
|
|
+ }
|
|
|
else{
|
|
else{
|
|
|
this.dateChanged = true;
|
|
this.dateChanged = true;
|
|
|
this.showIntervalError = false;
|
|
this.showIntervalError = false;
|
|
@@ -112,6 +125,7 @@ export class UnitComponent implements OnInit, OnDestroy {
|
|
|
this.getObservations(range, changedDate, changedSensor);
|
|
this.getObservations(range, changedDate, changedSensor);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* Check button handler.
|
|
* Check button handler.
|
|
|
* @param sensorId checked sensorId
|
|
* @param sensorId checked sensorId
|
|
@@ -120,6 +134,12 @@ export class UnitComponent implements OnInit, OnDestroy {
|
|
|
addSensorToGraph(sensorId: string, event) {
|
|
addSensorToGraph(sensorId: string, event) {
|
|
|
const groupId = sensorId.toString().slice(0, 5);
|
|
const groupId = sensorId.toString().slice(0, 5);
|
|
|
const sensorGroupElement = '#vega_container_' + groupId;
|
|
const sensorGroupElement = '#vega_container_' + groupId;
|
|
|
|
|
+
|
|
|
|
|
+ // if the checkmark is checked then the graph will be displayed
|
|
|
|
|
+ // this.showVega[groupId] = false;
|
|
|
|
|
+ // if (event.checked.includes(sensorId.toString()))
|
|
|
|
|
+ this.showVega[groupId] = true;
|
|
|
|
|
+
|
|
|
if (!this.selectedSensors.find(sensId => sensId.toString().slice(0, 5) === groupId)) { // if group of sensors is empty show empty graph
|
|
if (!this.selectedSensors.find(sensId => sensId.toString().slice(0, 5) === groupId)) { // if group of sensors is empty show empty graph
|
|
|
// GraphLoader.getAnalyticsGraph(null, null, null, sensorGroupElement);
|
|
// GraphLoader.getAnalyticsGraph(null, null, null, sensorGroupElement);
|
|
|
GraphLoader.getGraph(null, null, null, sensorGroupElement, null);
|
|
GraphLoader.getGraph(null, null, null, sensorGroupElement, null);
|
|
@@ -137,6 +157,15 @@ export class UnitComponent implements OnInit, OnDestroy {
|
|
|
this.filteredSensorsInfos(groupId), sensorGroupElement, false);
|
|
this.filteredSensorsInfos(groupId), sensorGroupElement, false);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // no data in graph -> the graph element will be destroyed
|
|
|
|
|
+ if (!this.showVega[groupId]) {
|
|
|
|
|
+ const container = document.getElementById(`vega_container_${groupId}`);
|
|
|
|
|
+ if (container) {
|
|
|
|
|
+ container.innerHTML = '';
|
|
|
|
|
+ }
|
|
|
|
|
+ console.log(`Cleared children of #vega_container_${groupId}`);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|