Revize cbb91c90
Přidáno uživatelem Jakub Hlaváč před téměř 4 roky(ů)
src/app/dashboard/components/dashboard.component.ts | ||
---|---|---|
1 |
import { Component, OnInit } from '@angular/core';
|
|
1 |
import {Component, OnDestroy, OnInit} from '@angular/core';
|
|
2 | 2 |
import {Group} from '../../shared/api/endpoints/models/group'; |
3 | 3 |
import {Drivers} from '../../shared/api/endpoints/models/drivers'; |
4 | 4 |
import {GeneralInfo} from '../../shared/api/endpoints/models/general-info'; |
... | ... | |
16 | 16 |
import {AuthService} from '../../auth/services/auth.service'; |
17 | 17 |
import {User} from '../../auth/models/user'; |
18 | 18 |
import {SensorType} from '../../shared/api/endpoints/models/sensor-type'; |
19 |
import {Subscription} from 'rxjs'; |
|
19 | 20 |
|
20 | 21 |
@Component({ |
21 | 22 |
selector: 'app-dashboard', |
22 | 23 |
templateUrl: './dashboard.component.html', |
23 | 24 |
styleUrls: ['./dashboard.component.scss'] |
24 | 25 |
}) |
25 |
export class DashboardComponent implements OnInit { |
|
26 |
export class DashboardComponent implements OnInit, OnDestroy {
|
|
26 | 27 |
|
27 | 28 |
loggedUser: User; |
28 | 29 |
items: MenuItem[] = []; |
... | ... | |
35 | 36 |
showInsertPositionPopup = false; |
36 | 37 |
phenomenons: Phenomenon[]; |
37 | 38 |
sensorTypes: SensorType[]; |
39 |
subscription: Subscription[] = []; |
|
38 | 40 |
|
39 | 41 |
constructor( |
40 | 42 |
private dataService: DataService, |
... | ... | |
45 | 47 |
private toastService: ToastService, |
46 | 48 |
private authService: AuthService |
47 | 49 |
) { |
50 |
this.initData(); |
|
51 |
} |
|
52 |
|
|
53 |
ngOnInit(): void { |
|
54 |
} |
|
55 |
|
|
56 |
/** |
|
57 |
* Unsubscribe after leaving |
|
58 |
*/ |
|
59 |
ngOnDestroy(): void { |
|
60 |
this.subscription.forEach(subs => subs.unsubscribe()); |
|
61 |
} |
|
62 |
|
|
63 |
/** |
|
64 |
* Get necessary data from backend |
|
65 |
*/ |
|
66 |
initData() { |
|
48 | 67 |
this.sensorService.getPhenomenons().subscribe( |
49 | 68 |
response => this.phenomenons = response |
50 | 69 |
); |
51 | 70 |
this.sensorService.getSensorTypes().subscribe( |
52 | 71 |
response => this.sensorTypes = response |
53 | 72 |
); |
54 |
} |
|
55 |
|
|
56 |
ngOnInit(): void { |
|
57 | 73 |
this.setUser(); |
58 | 74 |
this.getUnits(); |
59 | 75 |
} |
60 | 76 |
|
77 |
/** |
|
78 |
* Get user from user state |
|
79 |
*/ |
|
61 | 80 |
setUser(){ |
62 | 81 |
this.authService.getUserState().subscribe(res => { |
63 | 82 |
if(res){ |
... | ... | |
66 | 85 |
}); |
67 | 86 |
} |
68 | 87 |
|
88 |
/** |
|
89 |
* Get all units and theirs sensors from backend |
|
90 |
*/ |
|
69 | 91 |
getUnits() { |
70 | 92 |
this.dataService.getData().subscribe(data => { |
71 | 93 |
this.units = data; |
... | ... | |
73 | 95 |
}, err => this.toastService.showError(err.error.message)); |
74 | 96 |
} |
75 | 97 |
|
98 |
/** |
|
99 |
* Show edit unit |
|
100 |
* @param $event click event |
|
101 |
* @param unit edited unit |
|
102 |
*/ |
|
76 | 103 |
editUnitPopup($event: MouseEvent, unit: Unit) { |
77 | 104 |
this.editedUnit = unit; |
78 | 105 |
this.showEditUnitPopup = true; |
79 | 106 |
} |
80 | 107 |
|
108 |
/** |
|
109 |
* Show insert unit |
|
110 |
* @param $event click event |
|
111 |
* @param unit unit for sensor insert |
|
112 |
*/ |
|
81 | 113 |
insertSensorPopup($event: any, unit: Unit) { |
82 | 114 |
this.showInsertSensorPopup = true; |
83 | 115 |
this.editedUnit = unit; |
84 | 116 |
} |
85 | 117 |
|
118 |
/** |
|
119 |
* Detele unit confirmation |
|
120 |
* @param $event click event |
|
121 |
* @param unit unit to delete |
|
122 |
*/ |
|
86 | 123 |
deleteUnit($event: any, unit: Unit) { |
87 | 124 |
this.confirmationService.confirm({ |
88 | 125 |
message: 'Do you want to delete this unit?', |
... | ... | |
98 | 135 |
}); |
99 | 136 |
} |
100 | 137 |
|
138 |
/** |
|
139 |
* Send delete unit request to backend |
|
140 |
* @param unit to delete |
|
141 |
*/ |
|
101 | 142 |
processUnitDeletion(unit: Unit) { |
102 | 143 |
this.managementService.deleteUnit$Response({body: { |
103 | 144 |
unit: { |
... | ... | |
114 | 155 |
).toPromise().then().catch(err => this.toastService.showError(err.error.message)); |
115 | 156 |
} |
116 | 157 |
|
158 |
/** |
|
159 |
* Show menu items to manipulate with unit |
|
160 |
* @param $event click event |
|
161 |
* @param unit unit we want edit |
|
162 |
*/ |
|
117 | 163 |
showItems($event: any, unit: Unit) { |
118 | 164 |
$event.stopPropagation(); |
119 | 165 |
this.items = [ |
... | ... | |
132 | 178 |
] |
133 | 179 |
} |
134 | 180 |
|
181 |
/** |
|
182 |
* Add created unit to memory so we do not need call backend |
|
183 |
* @param inserted unit |
|
184 |
*/ |
|
135 | 185 |
addUnit(inserted: any) { |
136 | 186 |
const sensors: Sensor[] = []; |
137 | 187 |
inserted.sensors.forEach(sens => { |
... | ... | |
153 | 203 |
}) |
154 | 204 |
} |
155 | 205 |
|
206 |
/** |
|
207 |
* Add created sensors to unit in memory so we do not need call backend |
|
208 |
* @param inserted sensors |
|
209 |
*/ |
|
156 | 210 |
addSensors(inserted: any) { |
157 | 211 |
inserted.sensors.forEach(sens => { |
158 | 212 |
this.units.find(un => un.unit.unitId === inserted.unit.unit_id).sensors.push({ |
... | ... | |
166 | 220 |
}); |
167 | 221 |
} |
168 | 222 |
|
223 |
/** |
|
224 |
* Delete sensor from memory |
|
225 |
* @param unitId sensor unit |
|
226 |
* @param sensor sensor to delete |
|
227 |
*/ |
|
169 | 228 |
deleteSensor(unitId: number, sensor: Sensor) { |
170 | 229 |
this.units.find(unit => unit.unit.unitId === unitId).sensors = |
171 | 230 |
this.units.find(unit => unit.unit.unitId === unitId).sensors.filter(testedSensor => testedSensor.sensorId !== sensor.sensorId); |
172 | 231 |
} |
173 | 232 |
|
174 |
private insertPosition($event: any, unit: Unit) { |
|
233 |
/** |
|
234 |
* Show insert position popup |
|
235 |
* @param $event click event |
|
236 |
* @param unit unit to insert position for |
|
237 |
*/ |
|
238 |
insertPosition($event: any, unit: Unit) { |
|
175 | 239 |
$event.stopPropagation(); |
176 | 240 |
this.showInsertPositionPopup = true; |
177 | 241 |
this.editedUnit = unit; |
Také k dispozici: Unified diff
Re #8915 - Zapracování požadavků ze schůzky
+ sensor edit under edit button in menu+ sensor group names
+ adding information to unit and sensor
+ commenting
+ code refactor