Ver código fonte

sensor date interval alert

kunickyd 3 anos atrás
pai
commit
d99a3e92ec

+ 4 - 1
src/app/sensor/components/sensor.component.html

@@ -42,12 +42,15 @@
           <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)="onDateChanged()" [maxDate]="today" showButtonBar="true"></p-calendar>
-      </div>
+      </div>      
       <!-- <p-listbox *ngIf="showAggregation" [options]="aggregationFunction" [(ngModel)]="selectedAggregationFunction" optionLabel="name" optionValue="code"></p-listbox> -->
       <div>
         <button pButton label="Load data" *ngIf="dateChanged" 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>
   <div class="graph-view-wrapper">
     <div id="view"></div>

+ 10 - 1
src/app/sensor/components/sensor.component.ts

@@ -28,6 +28,7 @@ export class SensorComponent implements OnInit, OnDestroy {
   unitDescription: string;
   today: Date = moment().toDate();
   subscription: Subscription[] = [];
+  showIntervalError: boolean = false;
 
   constructor(
     private activatedRoute: ActivatedRoute,    
@@ -72,7 +73,15 @@ export class SensorComponent implements OnInit, OnDestroy {
    * Shows get data button
    */
   onDateChanged(): void {
-    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;
+    }
+    
   }
 
   /**