commit 05d4a2a9c3bb45aca50c71274a53bcb90ee4d190
Author: hlavja <hlavjah@gmail.com>
Date:   Thu May 13 11:40:42 2021 +0200

    Re #XXXX - Podpora
    
    * fixing merge

diff --git a/src/app/dashboard/components/sensor-insert-popup/sensor-insert-popup.component.html b/src/app/dashboard/components/sensor-insert-popup/sensor-insert-popup.component.html
index c1d536c..5cf4e92 100644
--- a/src/app/dashboard/components/sensor-insert-popup/sensor-insert-popup.component.html
+++ b/src/app/dashboard/components/sensor-insert-popup/sensor-insert-popup.component.html
@@ -23,7 +23,7 @@
             <span class="input-group-text"><i class="fas fa-file-signature"></i></span>
           </div>
           <select formControlName="sensorType" id="sensorType">
-            <option [ngValue]="null" disabled>Select sensor type</option>
+            <option value="null" disabled>Select sensor type</option>
             <option *ngFor="let sensorType of sensorTypes; let i = index" [value]="sensorTypes[i].sensorType">
               {{sensorTypes[i].sensorType}}
             </option>
@@ -34,7 +34,7 @@
             <span class="input-group-text"><i class="fas fa-tint"></i></span>
           </div>
           <select formControlName="phenomenons" id="phenomenons">
-            <option [ngValue]="null" disabled>Select phenomenon</option>
+            <option value="null" disabled>Select phenomenon</option>
             <option *ngFor="let phenomenon of phenomenons; let i = index" [value]="phenomenons[i].phenomenonId">
               {{phenomenons[i].phenomenonName}} ( {{ phenomenons[i].unit}})
             </option>
diff --git a/src/app/dashboard/components/sensor-insert-popup/sensor-insert-popup.component.ts b/src/app/dashboard/components/sensor-insert-popup/sensor-insert-popup.component.ts
index a5cb506..0b52f57 100644
--- a/src/app/dashboard/components/sensor-insert-popup/sensor-insert-popup.component.ts
+++ b/src/app/dashboard/components/sensor-insert-popup/sensor-insert-popup.component.ts
@@ -53,8 +53,8 @@ export class SensorInsertPopupComponent implements OnInit {
     return this.formBuilder.group({
       sensorId: ['', Validators.required],
       sensorName: ['', Validators.required],
-      sensorType: ['', Validators.required],
-      phenomenons: ['', Validators.required]
+      sensorType: ['null', Validators.required],
+      phenomenons: ['null', Validators.required]
     });
   }
 
diff --git a/src/app/sensor/components/sensor.component.html b/src/app/sensor/components/sensor.component.html
index b9f6cd0..73bac33 100644
--- a/src/app/sensor/components/sensor.component.html
+++ b/src/app/sensor/components/sensor.component.html
@@ -7,7 +7,7 @@
     </div>
     <div class="col-1"></div>
     <div class="col-xs-3">
-      <h5><span class="text-color-sensor-unit">Unit ID: {{unitId}}</span></h5>
+      <h5><span class="text-color-sensor-unit">Unit ID: <a [routerLink]="['/dashboard/unit', unitId]">{{unitId}}</a></span></h5>
     </div>
     <div class="col-1"></div>
   </div>
diff --git a/src/app/sensor/components/sensor.component.ts b/src/app/sensor/components/sensor.component.ts
index e5a45cb..c39bf64 100644
--- a/src/app/sensor/components/sensor.component.ts
+++ b/src/app/sensor/components/sensor.component.ts
@@ -8,6 +8,8 @@ import {ObservationService} from '../../shared/api/endpoints/services/observatio
 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';
 
 declare var require: any
 
@@ -31,12 +33,14 @@ export class SensorComponent implements OnInit {
   showAggregation = false;
   aggregationFunction: AggregationModel[];
   selectedAggregationFunction = 'HOUR';
+  sensor: Sensor;
 
   constructor(
     private activatedRoute: ActivatedRoute,
     private analyticsService: AnalyticsService,
     private observationService: ObservationService,
-    private toastService: ToastService
+    private toastService: ToastService,
+    private sensorsService: SensorsService
   ) {
     this.sensorId = parseInt(this.activatedRoute.snapshot.paramMap.get('sensorId'), 10);
     this.unitId = parseInt(this.activatedRoute.snapshot.paramMap.get('unitId'), 10);
@@ -50,7 +54,12 @@ export class SensorComponent implements OnInit {
   }
 
   ngOnInit(): void {
-    this.showGraph();
+    this.sensorsService.getUnitSensors({unit_id: this.unitId}).subscribe(sensors => {
+      if (sensors) {
+        this.sensor = sensors.filter(value => value.sensorId === this.sensorId)[0];
+        this.showGraph();
+      }
+    });
   }
 
   showGraph() {
@@ -94,7 +103,7 @@ export class SensorComponent implements OnInit {
       observations => {
         if (observations) {
         //  GraphLoader.getGraph(this.sensorId, observations[this.sensorId].data, observations[this.sensorId].interval, '#view');
-          GraphLoader.getGraph(this.sensorId, observations, this.getDummySensor(), '#view', true);
+          GraphLoader.getGraph(this.sensorId, observations, this.sensor, '#view', true);
         } else {
           GraphLoader.getGraph(null, null, null, '#view', null);
         }
@@ -122,7 +131,7 @@ export class SensorComponent implements OnInit {
       observations => {
         if (observations) {
          // GraphLoader.getObservationGraph(this.sensorId, observations, '#view');
-          GraphLoader.getGraph(this.sensorId, observations, this.getDummySensor(), '#view', false);
+          GraphLoader.getGraph(this.sensorId, observations, this.sensor, '#view', false);
         } else {
          // GraphLoader.getObservationGraph(null, null, null);
           GraphLoader.getGraph(null, null, null,'#view', null);
diff --git a/src/app/sensor/sensor.module.ts b/src/app/sensor/sensor.module.ts
index c558195..c83dd33 100644
--- a/src/app/sensor/sensor.module.ts
+++ b/src/app/sensor/sensor.module.ts
@@ -5,17 +5,19 @@ import {NavBarModule} from '../shared/nav-bar/nav-bar.module';
 import {CalendarModule} from 'primeng/calendar';
 import {FormsModule} from '@angular/forms';
 import {ListboxModule} from 'primeng/listbox';
+import {RouterModule} from '@angular/router';
 
 
 
 @NgModule({
   declarations: [SensorComponent],
-  imports: [
-    CommonModule,
-    NavBarModule,
-    CalendarModule,
-    FormsModule,
-    ListboxModule
-  ]
+    imports: [
+        CommonModule,
+        NavBarModule,
+        CalendarModule,
+        FormsModule,
+        ListboxModule,
+        RouterModule
+    ]
 })
 export class SensorModule { }
diff --git a/src/app/shared/nav-bar/components/unit-insert-popup/unit-insert-popup.component.html b/src/app/shared/nav-bar/components/unit-insert-popup/unit-insert-popup.component.html
index 6b1a4a3..8cd61b4 100644
--- a/src/app/shared/nav-bar/components/unit-insert-popup/unit-insert-popup.component.html
+++ b/src/app/shared/nav-bar/components/unit-insert-popup/unit-insert-popup.component.html
@@ -99,15 +99,19 @@
             <div class="input-group-prepend">
               <span class="input-group-text"><i class="fas fa-file-signature"></i></span>
             </div>
-            <input type="text" formControlName="sensorType" class="form-control" id="sensorType"
-                   placeholder="Sensor type"/>
+            <select formControlName="sensorType" id="sensorType">
+              <option value="null" disabled>Select sensor type</option>
+              <option *ngFor="let sensorType of sensorTypes; let i = index" [value]="sensorTypes[i].sensorType">
+                {{sensorTypes[i].sensorType}}
+              </option>
+            </select>
           </div>
           <div class="input-group form-group">
             <div class="input-group-prepend">
               <span class="input-group-text"><i class="fas fa-tint"></i></span>
             </div>
             <select formControlName="phenomenons" id="phenomenons">
-              <option [ngValue]="null" disabled>Select phenomenon</option>
+              <option value="null" disabled>Select phenomenon</option>
               <option *ngFor="let phenomenon of phenomenons; let i = index" [value]="phenomenons[i].phenomenonId">
                 {{phenomenons[i].phenomenonName}} ( {{ phenomenons[i].unit}})
               </option>
@@ -120,7 +124,10 @@
   </form>
   <p-footer>
     <div class="popup-buttons-wrapper">
-      <p-button type="button" (click)="addSensor()" class="pr-2">Add sensor</p-button>
+      <div>
+        <p-button type="button" (click)="addSensor()" class="pr-2">Add sensor</p-button>
+        <p-button *ngIf="sensors > 0" type="button" (click)="removeSensor()" class="pr-2">Remove last sensor</p-button>
+      </div>
       <div>
         <p-button icon="pi pi-times" (click)="close()" label="Close" class="pr-2"></p-button>
         <p-button icon="pi pi-check" (click)="processInsertion()" type="submit" label="Save" class="pr-2"></p-button>
diff --git a/src/app/shared/nav-bar/components/unit-insert-popup/unit-insert-popup.component.ts b/src/app/shared/nav-bar/components/unit-insert-popup/unit-insert-popup.component.ts
index 8daa073..c27f246 100644
--- a/src/app/shared/nav-bar/components/unit-insert-popup/unit-insert-popup.component.ts
+++ b/src/app/shared/nav-bar/components/unit-insert-popup/unit-insert-popup.component.ts
@@ -57,10 +57,10 @@ export class UnitInsertPopupComponent implements OnInit {
 
   createSensor(): FormGroup {
     return this.formBuilder.group({
-      sensorId: '',
-      sensorName: '',
-      sensorType: '',
-      phenomenons: ['']
+      sensorId: ['', Validators.required],
+      sensorName: ['', Validators.required],
+      sensorType: ['null', Validators.required],
+      phenomenons: ['null', Validators.required]
     });
   }
 
diff --git a/src/app/unit/components/unit.component.html b/src/app/unit/components/unit.component.html
index ce70f3f..0bae1c6 100644
--- a/src/app/unit/components/unit.component.html
+++ b/src/app/unit/components/unit.component.html
@@ -37,7 +37,7 @@
       <ng-container *ngFor="let sensor of sensors">
           <div *ngIf="sensor.sensorId.toString().slice(0, 5) === group" class="p-field-checkbox">
             <p-checkbox name="{{group}}" [value]="sensor.sensorId.toString()" [(ngModel)]="selectedSensors" [inputId]="sensor.sensorId.toString()" (onChange)="addSensorToGraph(sensor.sensorId.toString(), $event)"></p-checkbox>
-            <label>{{sensor.sensorId}}</label>
+            <label>{{sensor.sensorName}}</label>
           </div>
       </ng-container>
     </div>
diff --git a/src/app/unit/components/unit.component.ts b/src/app/unit/components/unit.component.ts
index 3155d7b..62e8ccf 100644
--- a/src/app/unit/components/unit.component.ts
+++ b/src/app/unit/components/unit.component.ts
@@ -64,7 +64,7 @@ export class UnitComponent implements OnInit {
             if (!this.sensorGroups.some(group => group === sensorType)) {
               this.sensorGroups.push(sensorType);
               setTimeout(() => {
-                //GraphLoader.getAnalyticsGraph(null, null, null, '#vega_container_' + sensor.sensorId.toString().slice(0, 5));
+                // GraphLoader.getAnalyticsGraph(null, null, null, '#vega_container_' + sensor.sensorId.toString().slice(0, 5));
                 GraphLoader.getGraph(null, null, null, '#vega_container_' + sensor.sensorId.toString().slice(0, 5),null );
               }, 0);
             }
@@ -111,7 +111,7 @@ export class UnitComponent implements OnInit {
             if (response.status === 200) {
               return response.body;
             } else if (response.status === 204) {
-              //GraphLoader.getAnalyticsGraph(null, null, null, '#vega_container_' + selectSens.toString().slice(0, 5));
+              // GraphLoader.getAnalyticsGraph(null, null, null, '#vega_container_' + selectSens.toString().slice(0, 5));
               GraphLoader.getGraph(null, null, null, '#vega_container_' + selectSens.toString().slice(0, 5),null );
               this.toastService.showWarningNoData();
               return response.body;
@@ -127,8 +127,8 @@ export class UnitComponent implements OnInit {
               if (data[key].data) {
                 const view = '#vega_container_' + key.slice(0, 5);
                 if (this.selectedSensors.some(sens => sens.toString() === key)) {
-                  //GraphLoader.getAnalyticsGraph(key, data[key].data, data[key].interval, view);
-                  //GraphLoader.getGraph(this.selectedSensors, this.filteredAnalyticsData(groupId), view, true);
+                  // GraphLoader.getAnalyticsGraph(key, data[key].data, data[key].interval, view);
+                  // GraphLoader.getGraph(this.selectedSensors, this.filteredAnalyticsData(groupId), view, true);
                 } else {
                   GraphLoader.getGraph(null, null, null, view, null);
                 }
@@ -162,7 +162,7 @@ export class UnitComponent implements OnInit {
                // GraphLoader.getAnalyticsGraph(key, data[key].data, data[key].interval, view);
                 GraphLoader.getGraph(this.selectedSensors, this.analyticsData, this.filteredSensorsInfos(groupId), view, true);
               } else {
-                //GraphLoader.getAnalyticsGraph(null, null, null, view);
+                // GraphLoader.getAnalyticsGraph(null, null, null, view);
                 GraphLoader.getGraph(null, null, null, view, null);
               }
             }
@@ -181,13 +181,13 @@ export class UnitComponent implements OnInit {
     const groupId = sensorId.toString().slice(0, 5);
     const sensorGroupElement = '#vega_container_' + groupId;
     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);
     } else {
       if (this.useAnalyticsData) { // use analytics data
         if (event.checked) { // if checked > add to graph
           if (this.analyticsData.some(sens => sens.sensorId === sensorId)) { // if already data for selected sensor in memory
-            //GraphLoader.getAnalyticsGraph(sensorId, this.analyticsData.find(sens => sens.sensorId === sensorId).data,
+            // GraphLoader.getAnalyticsGraph(sensorId, this.analyticsData.find(sens => sens.sensorId === sensorId).data,
             // this.analyticsData.find((sens => sens.sensorId === sensorId).interval, sensorGroupElement);
             GraphLoader.getGraph(this.selectedSensors, this.analyticsData, this.filteredSensorsInfos(groupId), sensorGroupElement, true);
 
@@ -195,7 +195,7 @@ export class UnitComponent implements OnInit {
             this.showGraph(false, sensorId);
           }
         } else { // remove sensor from graph
-          //GraphLoader.getAnalyticsGraph(sensorId, this.analyticsData.find(sens => sens.sensorId === sensorId).data,
+          // GraphLoader.getAnalyticsGraph(sensorId, this.analyticsData.find(sens => sens.sensorId === sensorId).data,
           // this.analyticsData.find(sens => sens.sensorId === sensorId).interval, sensorGroupElement);
           GraphLoader.getGraph(this.selectedSensors, this.analyticsData, this.filteredSensorsInfos(groupId), sensorGroupElement, true);
 
@@ -203,14 +203,16 @@ export class UnitComponent implements OnInit {
       } else { // use observations data
         if (event.checked) { // if checked > add to graph
           if (this.observationsData.some(sens => sens.sensorId.toString() === sensorId)) { // if already data for selected sensor in memory
-            GraphLoader.getGraph(this.filteredSelectedSensors(groupId), this.filteredObservationData(groupId), this.filteredSensorsInfos(groupId), sensorGroupElement, false);
-            //GraphLoader.getMultilineGraph(this.selectedSensors, this.filteredObservationData(groupId), sensorGroupElement)
+            GraphLoader.getGraph(this.filteredSelectedSensors(groupId), this.filteredObservationData(groupId),
+              this.filteredSensorsInfos(groupId), sensorGroupElement, false);
+            // GraphLoader.getMultilineGraph(this.selectedSensors, this.filteredObservationData(groupId), sensorGroupElement)
           } else { // get data from server for added sensor and show graph for selected sensors
             this.showGraph(false, sensorId);
           }
         } else { // remove sensor from graph
-          //GraphLoader.getMultilineGraph(this.selectedSensors, this.filteredObservationData(groupId), sensorGroupElement)
-          GraphLoader.getGraph(this.filteredSelectedSensors(groupId), this.filteredObservationData(groupId), this.filteredSensorsInfos(groupId), sensorGroupElement, false);
+          // GraphLoader.getMultilineGraph(this.selectedSensors, this.filteredObservationData(groupId), sensorGroupElement)
+          GraphLoader.getGraph(this.filteredSelectedSensors(groupId), this.filteredObservationData(groupId),
+            this.filteredSensorsInfos(groupId), sensorGroupElement, false);
 
         }
       }
@@ -236,12 +238,12 @@ export class UnitComponent implements OnInit {
 
 
   filteredSelectedSensors(sensorGroupId: string): any {
-    return this.selectedSensors.filter(sen => sen.toString().slice(0, 5) == sensorGroupId );
+    return this.selectedSensors.filter(sen => sen.toString().slice(0, 5) === sensorGroupId );
   }
 
   filteredSensorsInfos(sensorGroupId: string): any {
     return this.sensors.filter(sen => this.selectedSensors.includes(sen.sensorId.toString()) &&
-      sen.sensorId.toString().slice(0, 5) == sensorGroupId);
+      sen.sensorId.toString().slice(0, 5) === sensorGroupId);
   }
 
   private getObservations(range: Date[], changedDate: boolean, changedSensorId: string) {
@@ -276,8 +278,9 @@ export class UnitComponent implements OnInit {
               const view = '#vega_container_' + selectSens.toString().slice(0, 5);
               setTimeout(() => {
                 console.log(this.selectedSensors);
-                //GraphLoader.getMultilineGraph(this.selectedSensors, this.filteredObservationData(selectSens.toString().slice(0, 5)), view);
-                GraphLoader.getGraph(this.filteredSelectedSensors(groupId),  this.filteredObservationData(groupId), this.filteredSensorsInfos(groupId), view, false);
+             // GraphLoader.getMultilineGraph(this.selectedSensors, this.filteredObservationData(selectSens.toString().slice(0, 5)), view);
+                GraphLoader.getGraph(this.filteredSelectedSensors(groupId),  this.filteredObservationData(groupId),
+                  this.filteredSensorsInfos(groupId), view, false);
               }, 10);
             }
           })
@@ -305,8 +308,8 @@ export class UnitComponent implements OnInit {
           this.observationsData.push({sensorId: changedSensorId, sensor:
               this.sensors.find(sens => sens.sensorId.toString() === changedSensorId.toString()), data: observations});
           const view = '#vega_container_' + changedSensorId.toString().slice(0, 5);
-
-            GraphLoader.getGraph(this.filteredSelectedSensors(groupId),  this.filteredObservationData(groupId), this.filteredSensorsInfos(groupId), view, false);
+          GraphLoader.getGraph(this.filteredSelectedSensors(groupId),  this.filteredObservationData(groupId),
+            this.filteredSensorsInfos(groupId), view, false);
         }, err => this.toastService.showError(err.error.message));
     }
   }
