Revize f3995ee4
Přidáno uživatelem Jakub Hlaváč před téměř 4 roky(ů)
src/app/dashboard/components/dashboard.component.html | ||
---|---|---|
19 | 19 |
<ng-container *ngIf="i > 0 && unit.sensors[i].sensorId.toString().slice(0, 5) !== unit.sensors[i-1].sensorId.toString().slice(0, 5)"> |
20 | 20 |
<hr> |
21 | 21 |
</ng-container> |
22 |
<app-sensors *ngIf="sensor" [sensor]="sensor" [unitId]="unit.unit.unitId" [phenomenons]="phenomenons" [loggedUser]="loggedUser" (emitSensorDeletion)="deleteSensor(unit.unit.unitId, $event)" [sensorTypes]="sensorTypes"></app-sensors>
|
|
22 |
<app-sensors *ngIf="sensor" [sensor]="sensor" [unit]="unit.unit" [phenomenons]="phenomenons" [loggedUser]="loggedUser" (emitSensorDeletion)="deleteSensor(unit.unit.unitId, $event)" [sensorTypes]="sensorTypes"></app-sensors>
|
|
23 | 23 |
</ng-container> |
24 | 24 |
</div> |
25 | 25 |
</p-accordionTab> |
src/app/dashboard/components/sensors/sensors.component.html | ||
---|---|---|
5 | 5 |
</div> |
6 | 6 |
</div> |
7 | 7 |
<div class="col-md-7 text-right"> |
8 |
<button pButton type="button" label="View graph" [routerLink]="['/dashboard/unit', unitId, 'sensor', sensor.sensorId]" title="Sensor" icon="pi pi-chart-line"></button>
|
|
8 |
<button pButton type="button" label="View graph" [routerLink]="['/dashboard/unit', unit.unitId, 'sensor', sensor.sensorId]" [queryParams]="{unitName: unit.description}" title="Sensor" icon="pi pi-chart-line"></button>
|
|
9 | 9 |
<ng-container *ngIf="loggedUser?.userInfo?.rightsId == 0 || loggedUser?.userInfo?.rightsId == 1"> |
10 | 10 |
<div class="dashboard-button-separator"></div> |
11 | 11 |
<button pButton type="button" label="Edit sensor" icon="pi pi-cog" (click)="editSensor($event, sensor)" [className]="'p-button-warning'"></button> |
... | ... | |
14 | 14 |
</div> |
15 | 15 |
</div> |
16 | 16 |
|
17 |
<app-sensor-popup *ngIf="editedSensor" [(isVisible)]="showSensorPopup" [sensor]="editedSensor" [phenomenons]="phenomenons" [unitId]="unitId" [sensorTypes]="sensorTypes"></app-sensor-popup> |
|
17 |
<app-sensor-popup *ngIf="editedSensor" [(isVisible)]="showSensorPopup" [sensor]="editedSensor" [phenomenons]="phenomenons" [unitId]="unit.unitId" [sensorTypes]="sensorTypes"></app-sensor-popup> |
src/app/dashboard/components/sensors/sensors.component.ts | ||
---|---|---|
7 | 7 |
import {ToastService} from '../../../shared/services/toast.service'; |
8 | 8 |
import {User} from '../../../auth/models/user'; |
9 | 9 |
import {SensorType} from '../../../shared/api/endpoints/models/sensor-type'; |
10 |
import {Unit} from '../../../shared/api/endpoints/models/unit'; |
|
10 | 11 |
|
11 | 12 |
@Component({ |
12 | 13 |
selector: 'app-sensors', |
... | ... | |
16 | 17 |
export class SensorsComponent implements OnInit { |
17 | 18 |
|
18 | 19 |
@Input() sensor: Sensor; |
19 |
@Input() unitId: number;
|
|
20 |
@Input() unit: Unit;
|
|
20 | 21 |
@Input() phenomenons; |
21 | 22 |
@Input() loggedUser: User; |
22 | 23 |
@Output() emitSensorDeletion: EventEmitter<Sensor> = new EventEmitter<Sensor>(); |
... | ... | |
56 | 57 |
processSensorDeletion(sensor: Sensor) { |
57 | 58 |
this.managementService.deleteSensor$Response({body: { |
58 | 59 |
unit: { |
59 |
unit_id: this.unitId |
|
60 |
unit_id: this.unit.unitId
|
|
60 | 61 |
}, |
61 | 62 |
sensors: [ |
62 | 63 |
{ |
src/app/sensor/components/dummysensor.json | ||
---|---|---|
1 |
[ |
|
2 |
{ |
|
3 |
"firstObservationTime": "2019-03-07 06:10:16+02", |
|
4 |
"lastObservationTime": "2021-05-12 18:00:06+03", |
|
5 |
"phenomenon": { |
|
6 |
"phenomenonId": "1", |
|
7 |
"phenomenonName": "Temperature", |
|
8 |
"unit": "°C" |
|
9 |
}, |
|
10 |
"sensorId": 340400000, |
|
11 |
"sensorName": "iMetos HC Air temp", |
|
12 |
"sensorType": "Thermometer" |
|
13 |
} |
|
14 |
] |
src/app/sensor/components/sensor.component.html | ||
---|---|---|
3 | 3 |
<div class="container graph"> |
4 | 4 |
<div class="row-2"> |
5 | 5 |
<div class="col-xs-3"> |
6 |
<h5><span class="text-color-sensor-unit">Sensor ID: {{sensorId}}</span></h5>
|
|
6 |
<h5><span class="text-color-sensor-unit">Unit name: <a [routerLink]="['/dashboard/unit', unitId]">{{unitName}}</a></span></h5>
|
|
7 | 7 |
</div> |
8 |
<div class="col-1"></div> |
|
9 | 8 |
<div class="col-xs-3"> |
10 |
<h5><span class="text-color-sensor-unit">Unit ID: <a [routerLink]="['/dashboard/unit', unitId]">{{unitId}}</a></span></h5> |
|
9 |
<h5><span class="text-color-sensor-unit">Sensor name: {{sensor?.sensorName}}</span></h5> |
|
10 |
</div> |
|
11 |
<div class="col-xs-3"> |
|
12 |
<h5><span class="text-color-sensor-unit">Sensor type: {{sensor?.sensorType}}</span></h5> |
|
13 |
</div> |
|
14 |
<div class="col-xs-3"> |
|
15 |
<h5><span class="text-color-sensor-unit">Phenomenon: {{sensor?.phenomenon?.phenomenonName}} ({{sensor?.phenomenon?.unit}})</span></h5> |
|
11 | 16 |
</div> |
12 |
<div class="col-1"></div> |
|
13 | 17 |
</div> |
14 | 18 |
<div class="row"> |
15 | 19 |
<div class="col-xs-3"> |
... | ... | |
17 | 21 |
<div class="input-group-prepend"> |
18 | 22 |
<span class="input-group-text text-color-date background-date-color"><i class="fa fa-calendar-alt" aria-hidden="false"></i>From</span> |
19 | 23 |
</div> |
20 |
<p-calendar [style]="{'width':'100%'}" [inputStyle]="{'width':'100%'}" [(ngModel)]="from" [showTime]="true" (onSelect)="showGraph()" [maxDate]="today" showButtonBar="true"></p-calendar>
|
|
24 |
<p-calendar [style]="{'width':'100%'}" [inputStyle]="{'width':'100%'}" [(ngModel)]="from" [showTime]="true" (onSelect)="aggregationShow()" [maxDate]="today" showButtonBar="true"></p-calendar>
|
|
21 | 25 |
</div> |
22 | 26 |
</div> |
23 | 27 |
<div class="col-1"></div> |
... | ... | |
26 | 30 |
<div class="input-group-prepend"> |
27 | 31 |
<span class="input-group-text text-color-date background-date-color"><i class="fa fa-calendar-alt" aria-hidden="false"></i>To</span> |
28 | 32 |
</div> |
29 |
<p-calendar [style]="{'width':'100%'}" [inputStyle]="{'width':'100%'}" [(ngModel)]="to" [showTime]="true" (onSelect)="showGraph()" [maxDate]="today" showButtonBar="true"></p-calendar>
|
|
33 |
<p-calendar [style]="{'width':'100%'}" [inputStyle]="{'width':'100%'}" [(ngModel)]="to" [showTime]="true" (onSelect)="aggregationShow()" [maxDate]="today" showButtonBar="true"></p-calendar>
|
|
30 | 34 |
</div> |
31 | 35 |
</div> |
32 | 36 |
<div class="col-1"></div> |
... | ... | |
35 | 39 |
<!--<div class="input-group-prepend"> |
36 | 40 |
<span class="input-group-text">Aggregation</span> |
37 | 41 |
</div>--> |
38 |
<p-listbox [options]="aggregationFunction" [(ngModel)]="selectedAggregationFunction" optionLabel="name" optionValue="code" (onClick)="showGraph()" ></p-listbox>
|
|
42 |
<p-listbox [options]="aggregationFunction" [(ngModel)]="selectedAggregationFunction" optionLabel="name" optionValue="code"></p-listbox> |
|
39 | 43 |
</div> |
40 | 44 |
</div> |
45 |
<div class="col-1"></div> |
|
46 |
<div class="col-xs-3"> |
|
47 |
<p-button *ngIf="dateChanged" label="Get data" icon="pi pi-cog" styleClass="p-button-success" (click)="showGraph()"></p-button> |
|
48 |
</div> |
|
41 | 49 |
</div> |
42 | 50 |
<div class="row"> |
43 | 51 |
<div class="col-10"> |
src/app/sensor/components/sensor.component.ts | ||
---|---|---|
11 | 11 |
import {Sensor} from '../../shared/api/endpoints/models/sensor'; |
12 | 12 |
import {SensorsService} from '../../shared/api/endpoints/services/sensors.service'; |
13 | 13 |
|
14 |
declare var require: any |
|
15 |
|
|
16 | 14 |
@Component({ |
17 | 15 |
selector: 'app-sensor', |
18 | 16 |
templateUrl: './sensor.component.html', |
... | ... | |
27 | 25 |
unitId: number; |
28 | 26 |
data = []; |
29 | 27 |
time = []; |
30 |
from: Date; |
|
31 |
to: Date; |
|
32 |
today: Date; |
|
28 |
from: Date = moment().hour(0).minutes(0).subtract(7, 'days').toDate(); |
|
29 |
to: Date = moment().toDate(); |
|
33 | 30 |
showAggregation = false; |
34 | 31 |
aggregationFunction: AggregationModel[]; |
35 | 32 |
selectedAggregationFunction = 'HOUR'; |
36 | 33 |
sensor: Sensor; |
34 |
dateChanged = false; |
|
35 |
unitName: string; |
|
36 |
today: Date = moment().toDate(); |
|
37 | 37 |
|
38 | 38 |
constructor( |
39 | 39 |
private activatedRoute: ActivatedRoute, |
40 | 40 |
private analyticsService: AnalyticsService, |
41 | 41 |
private observationService: ObservationService, |
42 | 42 |
private toastService: ToastService, |
43 |
private sensorsService: SensorsService |
|
43 |
private sensorsService: SensorsService, |
|
44 |
private route: ActivatedRoute, |
|
44 | 45 |
) { |
46 |
this.getInitData(); |
|
47 |
this.sensorsService.getUnitSensors({unit_id: this.unitId}).subscribe(sensors => { |
|
48 |
if (sensors) { |
|
49 |
this.sensor = sensors.filter(value => value.sensorId === this.sensorId)[0]; |
|
50 |
this.showGraph(); // show default graph |
|
51 |
} |
|
52 |
}); |
|
53 |
} |
|
54 |
|
|
55 |
/** |
|
56 |
* Sets up default data |
|
57 |
*/ |
|
58 |
getInitData() { |
|
59 |
this.route.queryParams.subscribe(params => { |
|
60 |
if(params.unitName) { |
|
61 |
this.unitName = params.unitName; |
|
62 |
} |
|
63 |
}); |
|
45 | 64 |
this.sensorId = parseInt(this.activatedRoute.snapshot.paramMap.get('sensorId'), 10); |
46 | 65 |
this.unitId = parseInt(this.activatedRoute.snapshot.paramMap.get('unitId'), 10); |
47 | 66 |
this.aggregationFunction = [ |
... | ... | |
50 | 69 |
{name: 'Month', code: 'MONTH'}, |
51 | 70 |
{name: 'Year', code: 'YEAR'} |
52 | 71 |
]; |
53 |
this.today = moment().toDate(); |
|
54 | 72 |
} |
55 | 73 |
|
56 | 74 |
ngOnInit(): void { |
57 |
this.sensorsService.getUnitSensors({unit_id: this.unitId}).subscribe(sensors => { |
|
58 |
if (sensors) { |
|
59 |
this.sensor = sensors.filter(value => value.sensorId === this.sensorId)[0]; |
|
60 |
this.showGraph(); |
|
61 |
} |
|
62 |
}); |
|
63 | 75 |
} |
64 | 76 |
|
65 |
showGraph() { |
|
66 |
const range: Date[] = [moment().subtract(7, 'days').toDate(), moment().toDate()]; |
|
67 |
|
|
68 |
if (this.from && !this.to || !this.from && this.to) { |
|
69 |
return; |
|
70 |
} |
|
71 |
|
|
72 |
if (this.from && this.to) { |
|
73 |
range[0] = this.from; |
|
74 |
range[1] = this.to; |
|
75 |
} |
|
77 |
/** |
|
78 |
* Shows aggregation select box and get data button |
|
79 |
*/ |
|
80 |
aggregationShow() { |
|
81 |
this.dateChanged = true; |
|
82 |
this.showAggregation = moment(this.to).diff(moment(this.from), 'days') > 7; |
|
83 |
} |
|
76 | 84 |
|
77 |
if (moment(range[1]).diff(moment(range[0]), 'days') > 7) { |
|
85 |
/** |
|
86 |
* Gets data based on selected time range |
|
87 |
*/ |
|
88 |
showGraph() { |
|
89 |
if (moment(this.to).diff(moment(this.from), 'days') > 7) { |
|
78 | 90 |
this.showAggregation = true; |
91 |
const range: Date[] = [this.from, this.to]; |
|
79 | 92 |
this.getAnalytics(range); |
80 | 93 |
} else { |
81 | 94 |
this.showAggregation = false; |
95 |
const range: Date[] = [this.from, this.to]; |
|
82 | 96 |
this.getObservations(range); |
83 | 97 |
} |
84 | 98 |
} |
85 | 99 |
|
100 |
/** |
|
101 |
* Get data from analytics endpoint |
|
102 |
* @param range from and to interval |
|
103 |
*/ |
|
86 | 104 |
getAnalytics(range: Date[]) { |
87 | 105 |
this.analyticsService.getAnalytics$Response({ |
88 | 106 |
unit_id: this.unitId, sensor_id: this.sensorId, |
... | ... | |
102 | 120 |
).subscribe( |
103 | 121 |
observations => { |
104 | 122 |
if (observations) { |
105 |
// GraphLoader.getGraph(this.sensorId, observations[this.sensorId].data, observations[this.sensorId].interval, '#view'); |
|
106 | 123 |
GraphLoader.getGraph(this.sensorId, observations, this.sensor, '#view', true); |
107 | 124 |
} else { |
108 | 125 |
GraphLoader.getGraph(null, null, null, '#view', null); |
... | ... | |
110 | 127 |
}, err => this.toastService.showError(err.error.message)); |
111 | 128 |
} |
112 | 129 |
|
130 |
/** |
|
131 |
* Get data from observation endpoint |
|
132 |
* @param range from and to interval |
|
133 |
*/ |
|
113 | 134 |
getObservations(range: Date[]) { |
114 | 135 |
this.observationService.getObservation$Response({ |
115 | 136 |
unit_id: this.unitId, |
... | ... | |
130 | 151 |
).subscribe( |
131 | 152 |
observations => { |
132 | 153 |
if (observations) { |
133 |
// GraphLoader.getObservationGraph(this.sensorId, observations, '#view'); |
|
134 | 154 |
GraphLoader.getGraph(this.sensorId, observations, this.sensor, '#view', false); |
135 | 155 |
} else { |
136 |
// GraphLoader.getObservationGraph(null, null, null); |
|
137 | 156 |
GraphLoader.getGraph(null, null, null,'#view', null); |
138 | 157 |
} |
139 | 158 |
}, err => this.toastService.showError(err.error.message)); |
140 | 159 |
} |
141 |
|
|
142 |
getDummySensor() { |
|
143 |
return require('/src/app/sensor/components/dummysensor.json'); |
|
144 |
} |
|
145 | 160 |
} |
Také k dispozici: Unified diff
Re #8915 - Zapracování požadavků ze schůzky
+ show all information of sensor and unit