ソースを参照

unit date interval alert

kunickyd 3 年 前
コミット
f936789c7b

+ 3 - 0
src/app/unit/components/unit.component.html

@@ -31,6 +31,9 @@
         <button pButton type="button" *ngIf="dateChanged" label="Load data" class="p-button-primary" icon="pi pi-chart-line" (click)="showGraph()"></button>
       </div>
     </div>
+    <div *ngIf="showIntervalError" class="alert alert-danger" role="alert">
+      Select data from interval smaller than <b>6 months</b>!
+    </div>
   </div>
 
   <p-accordion [multiple]="true" class="graph-view-wrapper">

+ 9 - 1
src/app/unit/components/unit.component.ts

@@ -35,6 +35,7 @@ export class UnitComponent implements OnInit, OnDestroy {
   sensorTypes: SensorType[];
   unitDescription: string;
   subscription: Subscription[] = [];
+  showIntervalError: boolean = false;
 
   constructor(
     private activatedRoute: ActivatedRoute,
@@ -93,7 +94,14 @@ export class UnitComponent implements OnInit, OnDestroy {
    * Shows get data button
    */
   onDateChanged() {
-    this.dateChanged = true;
+    if (moment(this.to).diff(moment(this.from), 'months') > 6){
+      this.dateChanged = false;
+      this.showIntervalError = true;
+    }
+    else{
+      this.dateChanged = true;
+      this.showIntervalError = false;
+    }
   }
 
   /**