Revize b5525aef
Přidáno uživatelem Jakub Hlaváč před více než 3 roky(ů)
src/app/dashboard/components/dashboard.component.ts | ||
---|---|---|
10 | 10 |
import {SensorsService} from '../../shared/api/endpoints/services/sensors.service'; |
11 | 11 |
import {ConfirmationService, MenuItem, MessageService} from 'primeng/api'; |
12 | 12 |
import {ManagementService} from '../../shared/api/endpoints/services/management.service'; |
13 |
import {InsertUnit} from '../../shared/api/endpoints/models/insert-unit'; |
|
14 | 13 |
import {ToastService} from '../../shared/services/toast.service'; |
15 | 14 |
import {map} from 'rxjs/operators'; |
16 | 15 |
import {HttpResponse} from '@angular/common/http'; |
17 | 16 |
import {AuthService} from '../../auth/services/auth.service'; |
18 | 17 |
import {User} from '../../auth/models/user'; |
18 |
import {SensorType} from '../../shared/api/endpoints/models/sensor-type'; |
|
19 | 19 |
|
20 | 20 |
@Component({ |
21 | 21 |
selector: 'app-dashboard', |
... | ... | |
32 | 32 |
editedUnit: Unit; |
33 | 33 |
showEditUnitPopup = false; |
34 | 34 |
showInsertSensorPopup = false; |
35 |
showInsertPositionPopup = false; |
|
35 | 36 |
phenomenons: Phenomenon[]; |
37 |
sensorTypes: SensorType[]; |
|
36 | 38 |
|
37 | 39 |
constructor( |
38 | 40 |
private dataService: DataService, |
... | ... | |
76 | 78 |
|
77 | 79 |
insertSensorPopup($event: any, unit: Unit) { |
78 | 80 |
$event.stopPropagation(); |
81 |
this.sensorService.getSensorTypes().subscribe( |
|
82 |
response => this.sensorTypes = response |
|
83 |
) |
|
79 | 84 |
this.showInsertSensorPopup = true; |
80 | 85 |
this.editedUnit = unit; |
81 | 86 |
} |
... | ... | |
87 | 92 |
header: 'Delete Unit Confirmation', |
88 | 93 |
icon: 'pi pi-info-circle', |
89 | 94 |
accept: () => { |
90 |
// TODO this.processUnitDeletion(unit);
|
|
95 |
this.processUnitDeletion(unit); |
|
91 | 96 |
}, |
92 | 97 |
reject: () => { |
93 | 98 |
this.toastService.operationRejected(); |
... | ... | |
96 | 101 |
}); |
97 | 102 |
} |
98 | 103 |
|
99 |
processUnitDeletion(insertUnit: InsertUnit) { |
|
100 |
this.managementService.deleteUnit$Response({body: {unit: insertUnit}}).pipe( |
|
104 |
processUnitDeletion(unit: Unit) { |
|
105 |
this.managementService.deleteUnit$Response({body: { |
|
106 |
unit: { |
|
107 |
unit_id: unit.unitId |
|
108 |
}} |
|
109 |
}).pipe( |
|
101 | 110 |
map((response: HttpResponse<any>) => { |
102 | 111 |
if (response.status === 200) { |
103 | 112 |
this.toastService.showSuccessMessage(response.body.message); |
113 |
this.units = this.units.filter(testedUnit => testedUnit.unit.unitId !== unit.unitId); |
|
104 | 114 |
} else { |
105 | 115 |
} |
106 | 116 |
}) |
... | ... | |
114 | 124 |
event.stopPropagation(); |
115 | 125 |
this.editUnitPopup($event, unit); |
116 | 126 |
}}, |
127 |
{label: 'Insert position', icon: 'pi pi-cog', command: () => { |
|
128 |
event.stopPropagation(); |
|
129 |
this.insertPosition($event, unit); |
|
130 |
}}, |
|
117 | 131 |
{label: 'Delete unit', icon: 'pi pi-times', command: () => { |
118 | 132 |
event.stopPropagation(); |
119 | 133 |
this.deleteUnit($event, unit); |
120 | 134 |
}} |
121 | 135 |
] |
122 | 136 |
} |
137 |
|
|
138 |
addUnit(inserted: any) { |
|
139 |
const sensors: Sensor[] = []; |
|
140 |
inserted.sensors.forEach(sens => { |
|
141 |
sensors.push({ |
|
142 |
sensorId: sens.sensor_id, |
|
143 |
sensorType: sens.sensor_type, |
|
144 |
sensorName: sens.sensor_name, |
|
145 |
phenomenon: { |
|
146 |
phenomenonId: sens.phenomenon.phenomenon_id.toString() |
|
147 |
} |
|
148 |
}) |
|
149 |
}); |
|
150 |
this.units.push({ |
|
151 |
unit: { |
|
152 |
unitId: inserted.unit.unit_id, |
|
153 |
description: inserted.unit.description |
|
154 |
}, |
|
155 |
sensors |
|
156 |
}) |
|
157 |
} |
|
158 |
|
|
159 |
addSensors(inserted: any) { |
|
160 |
inserted.sensors.forEach(sens => { |
|
161 |
this.units.find(un => un.unit.unitId === inserted.unit.unit_id).sensors.push({ |
|
162 |
sensorId: sens.sensor_id, |
|
163 |
sensorType: sens.sensor_type, |
|
164 |
sensorName: sens.sensor_name, |
|
165 |
phenomenon: { |
|
166 |
phenomenonId: sens.phenomenon.phenomenon_id.toString() |
|
167 |
} |
|
168 |
}) |
|
169 |
}); |
|
170 |
} |
|
171 |
|
|
172 |
deleteSensor(unitId: number, sensor: Sensor) { |
|
173 |
this.units.find(unit => unit.unit.unitId === unitId).sensors = |
|
174 |
this.units.find(unit => unit.unit.unitId === unitId).sensors.filter(testedSensor => testedSensor.sensorId !== sensor.sensorId); |
|
175 |
} |
|
176 |
|
|
177 |
private insertPosition($event: any, unit: Unit) { |
|
178 |
$event.stopPropagation(); |
|
179 |
this.showInsertPositionPopup = true; |
|
180 |
this.editedUnit = unit; |
|
181 |
} |
|
123 | 182 |
} |
Také k dispozici: Unified diff
Re #8850 - Ověření funkčnosti - implementované enpointy
+ new use case add position to unit+ adding sensor type enum from backend endpoint
+ some form validation :)
- removing all endpoints from /senslog1