commit 773d3c89df3bd418fd8aa29c16d17eca29099733
Author: hlavja <hlavjah@gmail.com>
Date:   Mon May 3 23:45:27 2021 +0200

    Re #8791 - Odstranění sensor - endpoint
    
    + adding error catchup on requests
    + toast message upon request

diff --git a/src/app/app.component.ts b/src/app/app.component.ts
index 98757d1..c638881 100644
--- a/src/app/app.component.ts
+++ b/src/app/app.component.ts
@@ -3,7 +3,7 @@ import {faCoffee} from '@fortawesome/free-solid-svg-icons';
 
 @Component({
   selector: 'app-root',
-  template: `<router-outlet></router-outlet><p-toast position="bottom-center" key="mainToast"></p-toast>`
+  template: `<router-outlet></router-outlet><p-toast [baseZIndex]="20000" position="bottom-center" key="mainToast"></p-toast>`
 })
 export class AppComponent {
   title = 'SensLog';
diff --git a/src/app/dashboard/components/dashboard.component.html b/src/app/dashboard/components/dashboard.component.html
index 114df43..71f0330 100644
--- a/src/app/dashboard/components/dashboard.component.html
+++ b/src/app/dashboard/components/dashboard.component.html
@@ -14,8 +14,8 @@
           <div class="col-md-4">{{ unit.unit.description}}</div>
           <div class="col-md-8 text-right">
             <p-button label="Sensors graph" icon="pi pi-chart-line" [routerLink]="['/dashboard/unit', unit.unit.unitId]"></p-button>
-            <p-button label="Add sensor" icon="pi pi-cog" (onClick)="addSensor($event, unit.unit)"></p-button>
-            <p-button label="Edit unit" icon="pi pi-cog" (onClick)="editUnit($event, unit.unit)"></p-button>
+            <p-button label="Add sensor" icon="pi pi-cog" (onClick)="insertSensorPopup($event, unit.unit)"></p-button>
+            <p-button label="Edit unit" icon="pi pi-cog" (onClick)="editUnitPopup($event, unit.unit)"></p-button>
             <p-button label="Delete unit" icon="pi pi-cog" (onClick)="deleteUnit($event, unit.unit)"></p-button>
           </div>
         </div>
diff --git a/src/app/dashboard/components/dashboard.component.ts b/src/app/dashboard/components/dashboard.component.ts
index 9a6095f..414c476 100644
--- a/src/app/dashboard/components/dashboard.component.ts
+++ b/src/app/dashboard/components/dashboard.component.ts
@@ -6,12 +6,14 @@ import {Lastpos} from '../../shared/api/endpoints/models/lastpos';
 import {Sensor} from '../../shared/api/endpoints/models/sensor';
 import {Unit} from '../../shared/api/endpoints/models/unit';
 import {DataService} from '../../shared/api/endpoints/services/data.service';
-import {tap} from 'rxjs/operators';
 import {Phenomenon} from '../../shared/api/endpoints/models/phenomenon';
 import {SensorsService} from '../../shared/api/endpoints/services/sensors.service';
-import {ConfirmationService, ConfirmEventType, MessageService} from 'primeng/api';
+import {ConfirmationService, MessageService} from 'primeng/api';
 import {ManagementService} from '../../shared/api/endpoints/services/management.service';
 import {InsertUnit} from '../../shared/api/endpoints/models/insert-unit';
+import {ToastService} from '../../shared/services/toast.service';
+import {map} from 'rxjs/operators';
+import {HttpResponse} from '@angular/common/http';
 
 @Component({
   selector: 'app-dashboard',
@@ -34,7 +36,8 @@ export class DashboardComponent implements OnInit {
     private sensorService: SensorsService,
     private confirmationService: ConfirmationService,
     private messageService: MessageService,
-    private managementService: ManagementService
+    private managementService: ManagementService,
+    private toastService: ToastService
   ) {
     this.sensorService.getPhenomenons().subscribe(
       response => this.phenomenons = response
@@ -46,15 +49,13 @@ export class DashboardComponent implements OnInit {
   }
 
   getUnits() {
-    this.dataService.getData().pipe(
-      tap(data => {
-        this.units = data;
-        this.units.forEach(unit => unit.sensors.sort((a, b)  => a.sensorId - b.sensorId));
-      })
-    ).subscribe();
+    this.dataService.getData().subscribe(data => {
+      this.units = data;
+      this.units.forEach(unit => unit.sensors.sort((a, b)  => a.sensorId - b.sensorId));
+    }, err => this.toastService.showError(err.error.message));
   }
 
-  editUnit($event: MouseEvent, unit: Unit) {
+  editUnitPopup($event: MouseEvent, unit: Unit) {
     $event.stopPropagation();
     this.editedUnit = unit;
     this.showEditUnitPopup = true;
@@ -64,11 +65,7 @@ export class DashboardComponent implements OnInit {
     this.showInsertUnitPopup = true;
   }
 
-  getEditedUnit(): Unit {
-    return this.editedUnit;
-  }
-
-  addSensor($event: any, unit: Unit) {
+  insertSensorPopup($event: any, unit: Unit) {
     $event.stopPropagation();
     this.showInsertSensorPopup = true;
     this.editedUnit = unit;
@@ -81,18 +78,23 @@ export class DashboardComponent implements OnInit {
       header: 'Delete Unit Confirmation',
       icon: 'pi pi-info-circle',
       accept: () => {
-        console.log('ACCEPTED');
         // TODO this.processUnitDeletion(unit);
-        // this.messageService.add({severity:'info', summary:'Confirmed', detail:'Record deleted'});
       },
       reject: () => {
-        console.log('REJECTED');
+        this.toastService.operationRejected();
       },
       key: 'positionDialog'
     });
   }
 
   processUnitDeletion(insertUnit: InsertUnit) {
-    this.managementService.deleteUnit({body: {unit: insertUnit}});
+    this.managementService.deleteUnit$Response({body: {unit: insertUnit}}).pipe(
+      map((response: HttpResponse<any>) => {
+        if (response.status === 200) {
+          this.toastService.showSuccessMessage(response.body.message);
+        } else {
+        }
+      })
+    ).toPromise().then().catch(err => this.toastService.showError(err.error.message));
   }
 }
diff --git a/src/app/dashboard/components/sensors/sensors.component.ts b/src/app/dashboard/components/sensors/sensors.component.ts
index c143234..7be6d27 100644
--- a/src/app/dashboard/components/sensors/sensors.component.ts
+++ b/src/app/dashboard/components/sensors/sensors.component.ts
@@ -1,8 +1,10 @@
 import {Component, Input, OnInit} from '@angular/core';
 import {Sensor} from '../../../shared/api/endpoints/models/sensor';
 import {ConfirmationService} from 'primeng/api';
-import {InsertUnit} from '../../../shared/api/endpoints/models/insert-unit';
 import {ManagementService} from '../../../shared/api/endpoints/services/management.service';
+import {map} from 'rxjs/operators';
+import {HttpResponse} from '@angular/common/http';
+import {ToastService} from '../../../shared/services/toast.service';
 
 @Component({
   selector: 'app-sensors',
@@ -18,7 +20,8 @@ export class SensorsComponent implements OnInit {
   editedSensor: Sensor;
   constructor(
     private confirmationService: ConfirmationService,
-    private managementService: ManagementService
+    private managementService: ManagementService,
+    private toastService: ToastService
   ) { }
 
   ngOnInit(): void {
@@ -38,7 +41,6 @@ export class SensorsComponent implements OnInit {
       accept: () => {
         console.log('ACCEPTED');
         // TODO this.processSensorDeletion(sensor);
-        // this.messageService.add({severity:'info', summary:'Confirmed', detail:'Record deleted'});
       },
       reject: () => {
         console.log('REJECTED');
@@ -48,7 +50,7 @@ export class SensorsComponent implements OnInit {
   }
 
   processSensorDeletion(sensor: Sensor) {
-    this.managementService.deleteSensor({body: {
+    this.managementService.deleteSensor$Response({body: {
       unit: {
         unit_id: this.unitId
       },
@@ -57,6 +59,13 @@ export class SensorsComponent implements OnInit {
             sensor_id: sensor.sensorId
           }
         ]
-      }});
+      }}).pipe(
+      map((response: HttpResponse<any>) => {
+        if (response.status === 200) {
+          this.toastService.showSuccessMessage(response.body.message);
+        } else {
+        }
+      })
+    ).toPromise().then().catch(err => this.toastService.showError(err.error.message));
   }
 }
