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 |
|
|
import {tap} from 'rxjs/operators';
|
10 |
a3ae1cab
|
hlavja
|
import {Phenomenon} from '../../shared/api/endpoints/models/phenomenon';
|
11 |
|
|
import {SensorsService} from '../../shared/api/endpoints/services/sensors.service';
|
12 |
ea0e5344
|
hlavja
|
import {ConfirmationService, ConfirmEventType, MessageService} from 'primeng/api';
|
13 |
|
|
import {ManagementService} from '../../shared/api/endpoints/services/management.service';
|
14 |
|
|
import {InsertUnit} from '../../shared/api/endpoints/models/insert-unit';
|
15 |
675bbb8c
|
hlavja
|
|
16 |
|
|
@Component({
|
17 |
|
|
selector: 'app-dashboard',
|
18 |
|
|
templateUrl: './dashboard.component.html',
|
19 |
|
|
styleUrls: ['./dashboard.component.scss']
|
20 |
|
|
})
|
21 |
|
|
export class DashboardComponent implements OnInit {
|
22 |
|
|
|
23 |
ea0e5344
|
hlavja
|
position: 'bottom';
|
24 |
675bbb8c
|
hlavja
|
groups: Group[];
|
25 |
|
|
units: Array<{ drivers?: Drivers; generalInfo?: GeneralInfo; holder?: any; lastpos?: Lastpos; sensors?: Array<Sensor>; unit?: Unit }>;
|
26 |
a3ae1cab
|
hlavja
|
showInsertUnitPopup = false;
|
27 |
bb7795cd
|
hlavja
|
editedUnit: Unit;
|
28 |
a3ae1cab
|
hlavja
|
showEditUnitPopup = false;
|
29 |
533869de
|
hlavja
|
showInsertSensorPopup = false;
|
30 |
a3ae1cab
|
hlavja
|
phenomenons: Phenomenon[];
|
31 |
675bbb8c
|
hlavja
|
|
32 |
|
|
constructor(
|
33 |
a3ae1cab
|
hlavja
|
private dataService: DataService,
|
34 |
ea0e5344
|
hlavja
|
private sensorService: SensorsService,
|
35 |
|
|
private confirmationService: ConfirmationService,
|
36 |
|
|
private messageService: MessageService,
|
37 |
|
|
private managementService: ManagementService
|
38 |
675bbb8c
|
hlavja
|
) {
|
39 |
a3ae1cab
|
hlavja
|
this.sensorService.getPhenomenons().subscribe(
|
40 |
|
|
response => this.phenomenons = response
|
41 |
|
|
);
|
42 |
675bbb8c
|
hlavja
|
}
|
43 |
|
|
|
44 |
|
|
ngOnInit(): void {
|
45 |
8c28e5ab
|
hlavja
|
this.getUnits();
|
46 |
675bbb8c
|
hlavja
|
}
|
47 |
|
|
|
48 |
|
|
getUnits() {
|
49 |
|
|
this.dataService.getData().pipe(
|
50 |
25a20eec
|
hlavja
|
tap(data => {
|
51 |
|
|
this.units = data;
|
52 |
|
|
this.units.forEach(unit => unit.sensors.sort((a, b) => a.sensorId - b.sensorId));
|
53 |
|
|
})
|
54 |
|
|
).subscribe();
|
55 |
675bbb8c
|
hlavja
|
}
|
56 |
|
|
|
57 |
bb7795cd
|
hlavja
|
editUnit($event: MouseEvent, unit: Unit) {
|
58 |
|
|
$event.stopPropagation();
|
59 |
|
|
this.editedUnit = unit;
|
60 |
a3ae1cab
|
hlavja
|
this.showEditUnitPopup = true;
|
61 |
|
|
}
|
62 |
|
|
|
63 |
|
|
insertUnitPopup() {
|
64 |
|
|
this.showInsertUnitPopup = true;
|
65 |
|
|
}
|
66 |
|
|
|
67 |
|
|
getEditedUnit(): Unit {
|
68 |
|
|
return this.editedUnit;
|
69 |
bb7795cd
|
hlavja
|
}
|
70 |
533869de
|
hlavja
|
|
71 |
|
|
addSensor($event: any, unit: Unit) {
|
72 |
|
|
$event.stopPropagation();
|
73 |
|
|
this.showInsertSensorPopup = true;
|
74 |
|
|
this.editedUnit = unit;
|
75 |
|
|
}
|
76 |
ea0e5344
|
hlavja
|
|
77 |
|
|
deleteUnit($event: any, unit: Unit) {
|
78 |
|
|
$event.stopPropagation();
|
79 |
|
|
this.confirmationService.confirm({
|
80 |
|
|
message: 'Do you want to delete this unit?',
|
81 |
|
|
header: 'Delete Unit Confirmation',
|
82 |
|
|
icon: 'pi pi-info-circle',
|
83 |
|
|
accept: () => {
|
84 |
|
|
console.log('ACCEPTED');
|
85 |
03d22047
|
hlavja
|
// TODO this.processUnitDeletion(unit);
|
86 |
ea0e5344
|
hlavja
|
// this.messageService.add({severity:'info', summary:'Confirmed', detail:'Record deleted'});
|
87 |
|
|
},
|
88 |
|
|
reject: () => {
|
89 |
|
|
console.log('REJECTED');
|
90 |
|
|
},
|
91 |
|
|
key: 'positionDialog'
|
92 |
|
|
});
|
93 |
|
|
}
|
94 |
|
|
|
95 |
|
|
processUnitDeletion(insertUnit: InsertUnit) {
|
96 |
|
|
this.managementService.deleteUnit({body: {unit: insertUnit}});
|
97 |
|
|
}
|
98 |
675bbb8c
|
hlavja
|
}
|