Revize 533869de
Přidáno uživatelem Jakub Hlaváč před téměř 4 roky(ů)
src/app/dashboard/components/dashboard.component.html | ||
---|---|---|
14 | 14 |
<div class="col-md-6">{{ unit.unit.description}}</div> |
15 | 15 |
<div class="col-md-6 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)="editUnit($event, unit.unit)"></p-button>
|
|
17 |
<p-button label="Add sensor" icon="pi pi-cog" (onClick)="addSensor($event, unit.unit)"></p-button>
|
|
18 | 18 |
<p-button label="Edit unit" icon="pi pi-cog" (onClick)="editUnit($event, unit.unit)"></p-button> |
19 | 19 |
</div> |
20 | 20 |
</div> |
... | ... | |
28 | 28 |
|
29 | 29 |
<app-unit-popup *ngIf="editedUnit" [(isVisible)]="showEditUnitPopup" [unit]="editedUnit"></app-unit-popup> |
30 | 30 |
<app-unit-insert-popup [(isVisible)]="showInsertUnitPopup" [phenomenons]="phenomenons"></app-unit-insert-popup> |
31 |
<app-sensor-insert-popup *ngIf="editedUnit" [unit]="editedUnit" [(isVisible)]="showInsertSensorPopup" [phenomenons]="phenomenons"></app-sensor-insert-popup> |
src/app/dashboard/components/dashboard.component.ts | ||
---|---|---|
23 | 23 |
showInsertUnitPopup = false; |
24 | 24 |
editedUnit: Unit; |
25 | 25 |
showEditUnitPopup = false; |
26 |
showInsertSensorPopup = false; |
|
26 | 27 |
phenomenons: Phenomenon[]; |
27 | 28 |
|
28 | 29 |
constructor( |
... | ... | |
60 | 61 |
getEditedUnit(): Unit { |
61 | 62 |
return this.editedUnit; |
62 | 63 |
} |
64 |
|
|
65 |
addSensor($event: any, unit: Unit) { |
|
66 |
$event.stopPropagation(); |
|
67 |
this.showInsertSensorPopup = true; |
|
68 |
this.editedUnit = unit; |
|
69 |
} |
|
63 | 70 |
} |
src/app/dashboard/components/sensor-insert-popup/sensor-insert-popup.component.html | ||
---|---|---|
1 |
<p-dialog [visible]="isVisible" [closable]="false" [draggable]="false" header="Add sensor to unit - {{unit?.unitId}}" [style]="{width: '70vw'}" |
|
2 |
[baseZIndex]="10000" (onShow)="clearFormArray()"> |
|
3 |
|
|
4 |
<form [formGroup]="insertForm"> |
|
5 |
<div class="input-group form-group"> |
|
6 |
<div formArrayName="sensors" *ngFor="let item of insertForm.get('sensors')['controls']; let i = index;"> |
|
7 |
<div [formGroupName]="i"> |
|
8 |
<div class="input-group form-group"> |
|
9 |
<div class="input-group-prepend"> |
|
10 |
<span class="input-group-text">Sensor ID</span> |
|
11 |
</div> |
|
12 |
<input type="text" formControlName="sensorId" class="form-control" id="sensorId" placeholder="sensorId"/> |
|
13 |
</div> |
|
14 |
<div class="input-group form-group"> |
|
15 |
<div class="input-group-prepend"> |
|
16 |
<span class="input-group-text">Sensor name</span> |
|
17 |
</div> |
|
18 |
<input type="text" formControlName="sensorName" class="form-control" id="sensorName" |
|
19 |
placeholder="sensorName"/> |
|
20 |
</div> |
|
21 |
<div class="input-group form-group"> |
|
22 |
<div class="input-group-prepend"> |
|
23 |
<span class="input-group-text">Sensor type</span> |
|
24 |
</div> |
|
25 |
<input type="text" formControlName="sensorType" class="form-control" id="sensorType" |
|
26 |
placeholder="sensorType"/> |
|
27 |
</div> |
|
28 |
<div class="input-group form-group"> |
|
29 |
<div class="input-group-prepend"> |
|
30 |
<span class="input-group-text">Sensor name</span> |
|
31 |
</div> |
|
32 |
<select formControlName="phenomenons" id="phenomenons"> |
|
33 |
<option *ngFor="let phenomenon of phenomenons; let i = index" [value]="phenomenons[i].phenomenonId"> |
|
34 |
{{phenomenons[i].phenomenonName}} ( {{ phenomenons[i].unit}}) |
|
35 |
</option> |
|
36 |
</select> |
|
37 |
</div> |
|
38 |
</div> |
|
39 |
<br> |
|
40 |
</div> |
|
41 |
</div> |
|
42 |
</form> |
|
43 |
|
|
44 |
<p-button type="button" (click)="addSensor()" class="pr-2">Add Sensor</p-button> |
|
45 |
<p-footer> |
|
46 |
<div class="row justify-content-end align-items-center"> |
|
47 |
<div> |
|
48 |
<p-button icon="pi pi-check" (click)="processInsertion()" type="submit" label="Uložit" class="pr-2"></p-button> |
|
49 |
<p-button icon="pi pi-times" (click)="close()" label="Zavřít" class="pr-2"></p-button> |
|
50 |
</div> |
|
51 |
</div> |
|
52 |
</p-footer> |
|
53 |
</p-dialog> |
src/app/dashboard/components/sensor-insert-popup/sensor-insert-popup.component.ts | ||
---|---|---|
1 |
import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core'; |
|
2 |
import {FormArray, FormBuilder, FormGroup, Validators} from '@angular/forms'; |
|
3 |
import {ManagementService} from '../../../shared/api/endpoints/services/management.service'; |
|
4 |
|
|
5 |
@Component({ |
|
6 |
selector: 'app-sensor-insert-popup', |
|
7 |
templateUrl: './sensor-insert-popup.component.html', |
|
8 |
styleUrls: ['./sensor-insert-popup.component.scss'] |
|
9 |
}) |
|
10 |
export class SensorInsertPopupComponent implements OnInit { |
|
11 |
|
|
12 |
insertForm: FormGroup; |
|
13 |
items: FormArray; |
|
14 |
|
|
15 |
@Input() phenomenons; |
|
16 |
@Input() isVisible; |
|
17 |
@Input() unit; |
|
18 |
@Output() isVisibleChange: EventEmitter<boolean> = new EventEmitter<boolean>(); |
|
19 |
|
|
20 |
constructor( |
|
21 |
private formBuilder: FormBuilder, |
|
22 |
private managementService: ManagementService |
|
23 |
) { |
|
24 |
this.initForm(); |
|
25 |
} |
|
26 |
|
|
27 |
ngOnInit(): void { |
|
28 |
} |
|
29 |
|
|
30 |
processInsertion() { |
|
31 |
// TODO endpoint |
|
32 |
} |
|
33 |
|
|
34 |
close() { |
|
35 |
this.isVisibleChange.emit(false); |
|
36 |
} |
|
37 |
|
|
38 |
initForm() { |
|
39 |
this.insertForm = this.formBuilder.group({ |
|
40 |
sensors: this.formBuilder.array([this.createSensor()]) |
|
41 |
}); |
|
42 |
} |
|
43 |
|
|
44 |
createSensor(): FormGroup { |
|
45 |
return this.formBuilder.group({ |
|
46 |
sensorId: ['', Validators.required], |
|
47 |
sensorName: ['', Validators.required], |
|
48 |
sensorType: ['', Validators.required], |
|
49 |
phenomenons: ['', Validators.required] |
|
50 |
}); |
|
51 |
} |
|
52 |
|
|
53 |
addSensor(): void { |
|
54 |
this.items = this.insertForm.get('sensors') as FormArray; |
|
55 |
this.items.push(this.createSensor()); |
|
56 |
} |
|
57 |
|
|
58 |
clearFormArray() { |
|
59 |
const frmArray = this.insertForm?.get('sensors') as FormArray; |
|
60 |
if (frmArray) { |
|
61 |
frmArray.clear(); |
|
62 |
} |
|
63 |
this.addSensor(); |
|
64 |
this.insertForm.reset(); |
|
65 |
} |
|
66 |
} |
src/app/dashboard/dashboard.module.ts | ||
---|---|---|
11 | 11 |
import { SensorPopupComponent } from './components/sensor-popup/sensor-popup.component'; |
12 | 12 |
import { UnitInsertPopupComponent } from './components/unit-insert-popup/unit-insert-popup.component'; |
13 | 13 |
import {ReactiveFormsModule} from '@angular/forms'; |
14 |
import { SensorInsertPopupComponent } from './components/sensor-insert-popup/sensor-insert-popup.component'; |
|
14 | 15 |
|
15 | 16 |
|
16 | 17 |
|
17 | 18 |
@NgModule({ |
18 |
declarations: [DashboardComponent, SensorsComponent, UnitPopupComponent, SensorPopupComponent, UnitInsertPopupComponent], |
|
19 |
declarations: [DashboardComponent, SensorsComponent, UnitPopupComponent, SensorPopupComponent, UnitInsertPopupComponent, SensorInsertPopupComponent],
|
|
19 | 20 |
imports: [ |
20 | 21 |
CommonModule, |
21 | 22 |
NavBarModule, |
Také k dispozici: Unified diff
Re #8789 - Přidat sensor - formulář, endpoint
+ form for adding sensor to unit
+ first styling form