Revize 773d3c89
Přidáno uživatelem Jakub Hlaváč před více než 3 roky(ů)
src/app/app.component.ts | ||
---|---|---|
3 | 3 |
|
4 | 4 |
@Component({ |
5 | 5 |
selector: 'app-root', |
6 |
template: `<router-outlet></router-outlet><p-toast position="bottom-center" key="mainToast"></p-toast>` |
|
6 |
template: `<router-outlet></router-outlet><p-toast [baseZIndex]="20000" position="bottom-center" key="mainToast"></p-toast>`
|
|
7 | 7 |
}) |
8 | 8 |
export class AppComponent { |
9 | 9 |
title = 'SensLog'; |
src/app/dashboard/components/dashboard.component.html | ||
---|---|---|
14 | 14 |
<div class="col-md-4">{{ unit.unit.description}}</div> |
15 | 15 |
<div class="col-md-8 text-right"> |
16 | 16 |
<p-button label="Sensors graph" icon="pi pi-chart-line" [routerLink]="['/dashboard/unit', unit.unit.unitId]"></p-button> |
17 |
<p-button label="Add sensor" icon="pi pi-cog" (onClick)="addSensor($event, unit.unit)"></p-button>
|
|
18 |
<p-button label="Edit unit" icon="pi pi-cog" (onClick)="editUnit($event, unit.unit)"></p-button> |
|
17 |
<p-button label="Add sensor" icon="pi pi-cog" (onClick)="insertSensorPopup($event, unit.unit)"></p-button>
|
|
18 |
<p-button label="Edit unit" icon="pi pi-cog" (onClick)="editUnitPopup($event, unit.unit)"></p-button>
|
|
19 | 19 |
<p-button label="Delete unit" icon="pi pi-cog" (onClick)="deleteUnit($event, unit.unit)"></p-button> |
20 | 20 |
</div> |
21 | 21 |
</div> |
src/app/dashboard/components/dashboard.component.ts | ||
---|---|---|
6 | 6 |
import {Sensor} from '../../shared/api/endpoints/models/sensor'; |
7 | 7 |
import {Unit} from '../../shared/api/endpoints/models/unit'; |
8 | 8 |
import {DataService} from '../../shared/api/endpoints/services/data.service'; |
9 |
import {tap} from 'rxjs/operators'; |
|
10 | 9 |
import {Phenomenon} from '../../shared/api/endpoints/models/phenomenon'; |
11 | 10 |
import {SensorsService} from '../../shared/api/endpoints/services/sensors.service'; |
12 |
import {ConfirmationService, ConfirmEventType, MessageService} from 'primeng/api';
|
|
11 |
import {ConfirmationService, MessageService} from 'primeng/api'; |
|
13 | 12 |
import {ManagementService} from '../../shared/api/endpoints/services/management.service'; |
14 | 13 |
import {InsertUnit} from '../../shared/api/endpoints/models/insert-unit'; |
14 |
import {ToastService} from '../../shared/services/toast.service'; |
|
15 |
import {map} from 'rxjs/operators'; |
|
16 |
import {HttpResponse} from '@angular/common/http'; |
|
15 | 17 |
|
16 | 18 |
@Component({ |
17 | 19 |
selector: 'app-dashboard', |
... | ... | |
34 | 36 |
private sensorService: SensorsService, |
35 | 37 |
private confirmationService: ConfirmationService, |
36 | 38 |
private messageService: MessageService, |
37 |
private managementService: ManagementService |
|
39 |
private managementService: ManagementService, |
|
40 |
private toastService: ToastService |
|
38 | 41 |
) { |
39 | 42 |
this.sensorService.getPhenomenons().subscribe( |
40 | 43 |
response => this.phenomenons = response |
... | ... | |
46 | 49 |
} |
47 | 50 |
|
48 | 51 |
getUnits() { |
49 |
this.dataService.getData().pipe( |
|
50 |
tap(data => { |
|
51 |
this.units = data; |
|
52 |
this.units.forEach(unit => unit.sensors.sort((a, b) => a.sensorId - b.sensorId)); |
|
53 |
}) |
|
54 |
).subscribe(); |
|
52 |
this.dataService.getData().subscribe(data => { |
|
53 |
this.units = data; |
|
54 |
this.units.forEach(unit => unit.sensors.sort((a, b) => a.sensorId - b.sensorId)); |
|
55 |
}, err => this.toastService.showError(err.error.message)); |
|
55 | 56 |
} |
56 | 57 |
|
57 |
editUnit($event: MouseEvent, unit: Unit) { |
|
58 |
editUnitPopup($event: MouseEvent, unit: Unit) {
|
|
58 | 59 |
$event.stopPropagation(); |
59 | 60 |
this.editedUnit = unit; |
60 | 61 |
this.showEditUnitPopup = true; |
... | ... | |
64 | 65 |
this.showInsertUnitPopup = true; |
65 | 66 |
} |
66 | 67 |
|
67 |
getEditedUnit(): Unit { |
|
68 |
return this.editedUnit; |
|
69 |
} |
|
70 |
|
|
71 |
addSensor($event: any, unit: Unit) { |
|
68 |
insertSensorPopup($event: any, unit: Unit) { |
|
72 | 69 |
$event.stopPropagation(); |
73 | 70 |
this.showInsertSensorPopup = true; |
74 | 71 |
this.editedUnit = unit; |
... | ... | |
81 | 78 |
header: 'Delete Unit Confirmation', |
82 | 79 |
icon: 'pi pi-info-circle', |
83 | 80 |
accept: () => { |
84 |
console.log('ACCEPTED'); |
|
85 | 81 |
// TODO this.processUnitDeletion(unit); |
86 |
// this.messageService.add({severity:'info', summary:'Confirmed', detail:'Record deleted'}); |
|
87 | 82 |
}, |
88 | 83 |
reject: () => { |
89 |
console.log('REJECTED');
|
|
84 |
this.toastService.operationRejected();
|
|
90 | 85 |
}, |
91 | 86 |
key: 'positionDialog' |
92 | 87 |
}); |
93 | 88 |
} |
94 | 89 |
|
95 | 90 |
processUnitDeletion(insertUnit: InsertUnit) { |
96 |
this.managementService.deleteUnit({body: {unit: insertUnit}}); |
|
91 |
this.managementService.deleteUnit$Response({body: {unit: insertUnit}}).pipe( |
|
92 |
map((response: HttpResponse<any>) => { |
|
93 |
if (response.status === 200) { |
|
94 |
this.toastService.showSuccessMessage(response.body.message); |
|
95 |
} else { |
|
96 |
} |
|
97 |
}) |
|
98 |
).toPromise().then().catch(err => this.toastService.showError(err.error.message)); |
|
97 | 99 |
} |
98 | 100 |
} |
src/app/dashboard/components/sensors/sensors.component.ts | ||
---|---|---|
1 | 1 |
import {Component, Input, OnInit} from '@angular/core'; |
2 | 2 |
import {Sensor} from '../../../shared/api/endpoints/models/sensor'; |
3 | 3 |
import {ConfirmationService} from 'primeng/api'; |
4 |
import {InsertUnit} from '../../../shared/api/endpoints/models/insert-unit'; |
|
5 | 4 |
import {ManagementService} from '../../../shared/api/endpoints/services/management.service'; |
5 |
import {map} from 'rxjs/operators'; |
|
6 |
import {HttpResponse} from '@angular/common/http'; |
|
7 |
import {ToastService} from '../../../shared/services/toast.service'; |
|
6 | 8 |
|
7 | 9 |
@Component({ |
8 | 10 |
selector: 'app-sensors', |
... | ... | |
18 | 20 |
editedSensor: Sensor; |
19 | 21 |
constructor( |
20 | 22 |
private confirmationService: ConfirmationService, |
21 |
private managementService: ManagementService |
|
23 |
private managementService: ManagementService, |
|
24 |
private toastService: ToastService |
|
22 | 25 |
) { } |
23 | 26 |
|
24 | 27 |
ngOnInit(): void { |
... | ... | |
38 | 41 |
accept: () => { |
39 | 42 |
console.log('ACCEPTED'); |
40 | 43 |
// TODO this.processSensorDeletion(sensor); |
41 |
// this.messageService.add({severity:'info', summary:'Confirmed', detail:'Record deleted'}); |
|
42 | 44 |
}, |
43 | 45 |
reject: () => { |
44 | 46 |
console.log('REJECTED'); |
... | ... | |
48 | 50 |
} |
49 | 51 |
|
50 | 52 |
processSensorDeletion(sensor: Sensor) { |
51 |
this.managementService.deleteSensor({body: { |
|
53 |
this.managementService.deleteSensor$Response({body: {
|
|
52 | 54 |
unit: { |
53 | 55 |
unit_id: this.unitId |
54 | 56 |
}, |
... | ... | |
57 | 59 |
sensor_id: sensor.sensorId |
58 | 60 |
} |
59 | 61 |
] |
60 |
}}); |
|
62 |
}}).pipe( |
|
63 |
map((response: HttpResponse<any>) => { |
|
64 |
if (response.status === 200) { |
|
65 |
this.toastService.showSuccessMessage(response.body.message); |
|
66 |
} else { |
|
67 |
} |
|
68 |
}) |
|
69 |
).toPromise().then().catch(err => this.toastService.showError(err.error.message)); |
|
61 | 70 |
} |
62 | 71 |
} |
Také k dispozici: Unified diff
Re #8791 - Odstranění sensor - endpoint
+ adding error catchup on requests
+ toast message upon request