1 |
675bbb8c
|
hlavja
|
import { Component, OnInit } from '@angular/core';
|
2 |
|
|
import {Group} from '../../shared/api/endpoints/models/group';
|
3 |
|
|
import {Drivers} from '../../shared/api/endpoints/models/drivers';
|
4 |
|
|
import {GeneralInfo} from '../../shared/api/endpoints/models/general-info';
|
5 |
|
|
import {Lastpos} from '../../shared/api/endpoints/models/lastpos';
|
6 |
|
|
import {Sensor} from '../../shared/api/endpoints/models/sensor';
|
7 |
|
|
import {Unit} from '../../shared/api/endpoints/models/unit';
|
8 |
|
|
import {DataService} from '../../shared/api/endpoints/services/data.service';
|
9 |
a3ae1cab
|
hlavja
|
import {Phenomenon} from '../../shared/api/endpoints/models/phenomenon';
|
10 |
|
|
import {SensorsService} from '../../shared/api/endpoints/services/sensors.service';
|
11 |
c835a12d
|
hlavja
|
import {ConfirmationService, MenuItem, MessageService} from 'primeng/api';
|
12 |
ea0e5344
|
hlavja
|
import {ManagementService} from '../../shared/api/endpoints/services/management.service';
|
13 |
|
|
import {InsertUnit} from '../../shared/api/endpoints/models/insert-unit';
|
14 |
773d3c89
|
hlavja
|
import {ToastService} from '../../shared/services/toast.service';
|
15 |
|
|
import {map} from 'rxjs/operators';
|
16 |
|
|
import {HttpResponse} from '@angular/common/http';
|
17 |
278f83f2
|
Lukáš Moučka
|
import {AuthService} from '../../auth/services/auth.service';
|
18 |
|
|
import {User} from '../../auth/models/user';
|
19 |
675bbb8c
|
hlavja
|
|
20 |
|
|
@Component({
|
21 |
|
|
selector: 'app-dashboard',
|
22 |
|
|
templateUrl: './dashboard.component.html',
|
23 |
|
|
styleUrls: ['./dashboard.component.scss']
|
24 |
|
|
})
|
25 |
|
|
export class DashboardComponent implements OnInit {
|
26 |
|
|
|
27 |
278f83f2
|
Lukáš Moučka
|
loggedUser: User;
|
28 |
c835a12d
|
hlavja
|
items: MenuItem[] = [];
|
29 |
ea0e5344
|
hlavja
|
position: 'bottom';
|
30 |
675bbb8c
|
hlavja
|
groups: Group[];
|
31 |
|
|
units: Array<{ drivers?: Drivers; generalInfo?: GeneralInfo; holder?: any; lastpos?: Lastpos; sensors?: Array<Sensor>; unit?: Unit }>;
|
32 |
bb7795cd
|
hlavja
|
editedUnit: Unit;
|
33 |
a3ae1cab
|
hlavja
|
showEditUnitPopup = false;
|
34 |
533869de
|
hlavja
|
showInsertSensorPopup = false;
|
35 |
a3ae1cab
|
hlavja
|
phenomenons: Phenomenon[];
|
36 |
675bbb8c
|
hlavja
|
|
37 |
|
|
constructor(
|
38 |
a3ae1cab
|
hlavja
|
private dataService: DataService,
|
39 |
ea0e5344
|
hlavja
|
private sensorService: SensorsService,
|
40 |
|
|
private confirmationService: ConfirmationService,
|
41 |
|
|
private messageService: MessageService,
|
42 |
773d3c89
|
hlavja
|
private managementService: ManagementService,
|
43 |
278f83f2
|
Lukáš Moučka
|
private toastService: ToastService,
|
44 |
|
|
private authService: AuthService
|
45 |
675bbb8c
|
hlavja
|
) {
|
46 |
a3ae1cab
|
hlavja
|
this.sensorService.getPhenomenons().subscribe(
|
47 |
|
|
response => this.phenomenons = response
|
48 |
|
|
);
|
49 |
675bbb8c
|
hlavja
|
}
|
50 |
|
|
|
51 |
|
|
ngOnInit(): void {
|
52 |
278f83f2
|
Lukáš Moučka
|
this.setUser();
|
53 |
8c28e5ab
|
hlavja
|
this.getUnits();
|
54 |
675bbb8c
|
hlavja
|
}
|
55 |
|
|
|
56 |
278f83f2
|
Lukáš Moučka
|
setUser(){
|
57 |
|
|
this.authService.getUserState().subscribe(res => {
|
58 |
|
|
if(res){
|
59 |
|
|
this.loggedUser = res;
|
60 |
|
|
}
|
61 |
|
|
});
|
62 |
|
|
}
|
63 |
|
|
|
64 |
675bbb8c
|
hlavja
|
getUnits() {
|
65 |
773d3c89
|
hlavja
|
this.dataService.getData().subscribe(data => {
|
66 |
|
|
this.units = data;
|
67 |
|
|
this.units.forEach(unit => unit.sensors.sort((a, b) => a.sensorId - b.sensorId));
|
68 |
|
|
}, err => this.toastService.showError(err.error.message));
|
69 |
675bbb8c
|
hlavja
|
}
|
70 |
|
|
|
71 |
773d3c89
|
hlavja
|
editUnitPopup($event: MouseEvent, unit: Unit) {
|
72 |
bb7795cd
|
hlavja
|
$event.stopPropagation();
|
73 |
|
|
this.editedUnit = unit;
|
74 |
a3ae1cab
|
hlavja
|
this.showEditUnitPopup = true;
|
75 |
|
|
}
|
76 |
|
|
|
77 |
773d3c89
|
hlavja
|
insertSensorPopup($event: any, unit: Unit) {
|
78 |
533869de
|
hlavja
|
$event.stopPropagation();
|
79 |
|
|
this.showInsertSensorPopup = true;
|
80 |
|
|
this.editedUnit = unit;
|
81 |
|
|
}
|
82 |
ea0e5344
|
hlavja
|
|
83 |
|
|
deleteUnit($event: any, unit: Unit) {
|
84 |
|
|
$event.stopPropagation();
|
85 |
|
|
this.confirmationService.confirm({
|
86 |
|
|
message: 'Do you want to delete this unit?',
|
87 |
|
|
header: 'Delete Unit Confirmation',
|
88 |
|
|
icon: 'pi pi-info-circle',
|
89 |
|
|
accept: () => {
|
90 |
03d22047
|
hlavja
|
// TODO this.processUnitDeletion(unit);
|
91 |
ea0e5344
|
hlavja
|
},
|
92 |
|
|
reject: () => {
|
93 |
773d3c89
|
hlavja
|
this.toastService.operationRejected();
|
94 |
ea0e5344
|
hlavja
|
},
|
95 |
|
|
key: 'positionDialog'
|
96 |
|
|
});
|
97 |
|
|
}
|
98 |
|
|
|
99 |
|
|
processUnitDeletion(insertUnit: InsertUnit) {
|
100 |
773d3c89
|
hlavja
|
this.managementService.deleteUnit$Response({body: {unit: insertUnit}}).pipe(
|
101 |
|
|
map((response: HttpResponse<any>) => {
|
102 |
|
|
if (response.status === 200) {
|
103 |
|
|
this.toastService.showSuccessMessage(response.body.message);
|
104 |
|
|
} else {
|
105 |
|
|
}
|
106 |
|
|
})
|
107 |
|
|
).toPromise().then().catch(err => this.toastService.showError(err.error.message));
|
108 |
ea0e5344
|
hlavja
|
}
|
109 |
c835a12d
|
hlavja
|
|
110 |
|
|
showItems($event: any, unit: Unit) {
|
111 |
|
|
$event.stopPropagation();
|
112 |
|
|
this.items = [
|
113 |
278f83f2
|
Lukáš Moučka
|
{label: 'Edit unit', icon: 'pi pi-cog', command: () => {
|
114 |
c835a12d
|
hlavja
|
event.stopPropagation();
|
115 |
278f83f2
|
Lukáš Moučka
|
this.editUnitPopup($event, unit);
|
116 |
c835a12d
|
hlavja
|
}},
|
117 |
|
|
{label: 'Delete unit', icon: 'pi pi-times', command: () => {
|
118 |
|
|
event.stopPropagation();
|
119 |
|
|
this.deleteUnit($event, unit);
|
120 |
|
|
}}
|
121 |
|
|
]
|
122 |
|
|
}
|
123 |
675bbb8c
|
hlavja
|
}
|