Browse Source

sensor - hide aggregation option

kunickyd 3 years ago
parent
commit
5c7b3c06b0

+ 2 - 2
src/app/sensor/components/sensor.component.html

@@ -32,7 +32,7 @@
         <div class="input-group-prepend">
           <span class="input-group-text text-color-date background-date-color"><i class="fa fa-calendar-alt" aria-hidden="false"></i></span>
         </div>
-        <p-calendar id="from" [(ngModel)]="from" [showTime]="true" (onSelect)="aggregationShow()" [maxDate]="today" showButtonBar="true"></p-calendar>
+        <p-calendar id="from" [(ngModel)]="from" [showTime]="true" (onSelect)="onDateChanged()" [maxDate]="today" showButtonBar="true"></p-calendar>
       </div>
       <div class="graph-range-dates-separator">
         <div></div>
@@ -41,7 +41,7 @@
         <div class="input-group-prepend">
           <span class="input-group-text text-color-date background-date-color"><i class="fa fa-calendar-alt" aria-hidden="false"></i></span>
         </div>
-        <p-calendar id="to" [(ngModel)]="to" [showTime]="true" (onSelect)="aggregationShow()" [maxDate]="today" showButtonBar="true"></p-calendar>
+        <p-calendar id="to" [(ngModel)]="to" [showTime]="true" (onSelect)="onDateChanged()" [maxDate]="today" showButtonBar="true"></p-calendar>
       </div>
       <p-listbox *ngIf="showAggregation" [options]="aggregationFunction" [(ngModel)]="selectedAggregationFunction" optionLabel="name" optionValue="code"></p-listbox>
       <div>

+ 34 - 30
src/app/sensor/components/sensor.component.ts

@@ -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 {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({
   selector: 'app-sensor',
@@ -43,7 +43,7 @@ export class SensorComponent implements OnInit, OnDestroy {
     private route: ActivatedRoute,
   ) {
     this.getInitData();
-    this.sensorsService.getUnitSensors({unit_id: this.unitId}).subscribe(sensors => {
+    this.sensorsService.getUnitSensors({ unit_id: this.unitId }).subscribe(sensors => {
       if (sensors) {
         this.sensor = sensors.filter(value => value.sensorId === this.sensorId)[0];
         this.showGraph(); // show default graph
@@ -56,17 +56,17 @@ export class SensorComponent implements OnInit, OnDestroy {
    */
   getInitData() {
     this.route.queryParams.subscribe(params => {
-      if(params.unitName)  {
+      if (params.unitName) {
         this.unitDescription = params.unitName;
       }
     });
     this.sensorId = parseInt(this.activatedRoute.snapshot.paramMap.get('sensorId'), 10);
     this.unitId = parseInt(this.activatedRoute.snapshot.paramMap.get('unitId'), 10);
     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
    */
-  aggregationShow() {
+  // aggregationShow() {
+  //   this.dateChanged = true;
+  //   this.showAggregation = moment(this.to).diff(moment(this.from), 'days') > 7;
+  // }
+
+  onDateChanged(): void{
     this.dateChanged = true;
-    this.showAggregation = moment(this.to).diff(moment(this.from), 'days') > 7;
   }
 
   /**
    * Gets data based on selected time range
    */
   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) {
           GraphLoader.getGraph(this.sensorId, observations, this.sensor, '#view', false);
         } else {
-          GraphLoader.getGraph(null, null, null,'#view', null);
+          GraphLoader.getGraph(null, null, null, '#view', null);
         }
       }, err => this.toastService.showError(err.error.message));
   }