diff --git a/src/main/angular/src/app/location/detail/location-detail.html b/src/main/angular/src/app/location/detail/location-detail.html
index fc0a571..03f35e0 100644
--- a/src/main/angular/src/app/location/detail/location-detail.html
+++ b/src/main/angular/src/app/location/detail/location-detail.html
@@ -1,11 +1,123 @@
@if (location) {
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
}
diff --git a/src/main/angular/src/app/location/detail/location-detail.ts b/src/main/angular/src/app/location/detail/location-detail.ts
index b22eca3..9efeb5a 100644
--- a/src/main/angular/src/app/location/detail/location-detail.ts
+++ b/src/main/angular/src/app/location/detail/location-detail.ts
@@ -1,12 +1,14 @@
-import {Component, OnInit} from '@angular/core';
+import {Component, OnDestroy, OnInit} from '@angular/core';
import {LocationService} from '../location-service';
import {ActivatedRoute} from '@angular/router';
import {Location} from '../Location';
import {Text} from '../../shared/text/text';
import {Number} from '../../shared/number/number';
-import {SeriesSelect, SeriesType} from '../../series/select/series-select';
+import {SeriesSelect} from '../../series/select/series-select';
import {Series} from '../../series/Series';
import {SeriesService} from '../../series/series-service';
+import {SeriesType} from '../../series/SeriesType';
+import {Subscription, timer} from 'rxjs';
@Component({
selector: 'app-location-detail',
@@ -18,11 +20,15 @@ import {SeriesService} from '../../series/series-service';
templateUrl: './location-detail.html',
styleUrl: './location-detail.less',
})
-export class LocationDetail implements OnInit {
+export class LocationDetail implements OnInit, OnDestroy {
+
+ private readonly subs: Subscription [] = [];
+
+ private series: Series[] = [];
protected location: Location | null = null;
- private series: Series[] = [];
+ protected now: Date = new Date();
constructor(
readonly locationService: LocationService,
@@ -37,14 +43,29 @@ export class LocationDetail implements OnInit {
this.locationService.getById(params['id'], location => this.location = location);
});
this.seriesService.findAll(list => this.series = list);
+ this.subs.push(this.seriesService.subscribe(this.updateSeries));
+ this.subs.push(timer(1000, 1000).subscribe(() => this.now = new Date()));
}
- protected readonly update = (location: Location): void => {
+ ngOnDestroy(): void {
+ this.subs.forEach(sub => sub.unsubscribe());
+ }
+
+ protected readonly updateLocation = (location: Location): void => {
if (this.location?.id === location.id) {
this.location = location;
}
};
+ protected readonly updateSeries = (fresh: Series): void => {
+ const index = this.series.findIndex(series => series.id === fresh.id);
+ if (index >= 0) {
+ this.series.splice(index, 1, fresh);
+ } else {
+ this.series.push(fresh);
+ }
+ };
+
protected readonly filterEnergy = (): Series[] => {
return this.series.filter(series => series.type === SeriesType.DELTA && series.unit === 'kWh');
};
diff --git a/src/main/angular/src/app/series/Series.ts b/src/main/angular/src/app/series/Series.ts
index 0d8c309..ca886e5 100644
--- a/src/main/angular/src/app/series/Series.ts
+++ b/src/main/angular/src/app/series/Series.ts
@@ -1,24 +1,44 @@
-import {validateEnum, validateNumber, validateString} from "../common";
-import {SeriesType} from "./select/series-select";
+import {or, validateDate, validateEnum, validateNumber, validateString} from "../common";
+
+import {SeriesType} from './SeriesType';
+import {formatNumber} from '@angular/common';
export class Series {
+ readonly valueString: string;
+
constructor(
readonly id: number,
readonly name: string,
+ readonly decimals: number,
+ readonly seconds: number,
+ readonly value: number | null,
+ readonly last: Date | null,
readonly unit: string,
readonly type: SeriesType,
) {
- //
+ this.valueString = (value === null ? '-' : formatNumber(value, "de-DE", `0.${decimals}-${decimals}`)) + ' ' + unit;
}
static fromJson(json: any): Series {
return new Series(
validateNumber(json.id),
validateString(json.name),
+ validateNumber(json.decimals),
+ validateNumber(json.seconds),
+ or(json.value, validateNumber, null),
+ or(json.last, validateDate, null),
validateString(json.unit),
validateEnum(json.type, SeriesType),
);
}
+ isOld(now: Date): boolean {
+ if (this.last === null) {
+ return true;
+ }
+ const ageSeconds = (now.getTime() - this.last.getTime()) / 1000;
+ return ageSeconds > this.seconds * 2.1;
+ }
+
}
diff --git a/src/main/angular/src/app/series/SeriesType.ts b/src/main/angular/src/app/series/SeriesType.ts
new file mode 100644
index 0000000..7fabbdc
--- /dev/null
+++ b/src/main/angular/src/app/series/SeriesType.ts
@@ -0,0 +1,5 @@
+export enum SeriesType {
+ BOOL = 'BOOL',
+ DELTA = 'DELTA',
+ VARYING = 'VARYING',
+}
diff --git a/src/main/angular/src/app/series/select/series-select.html b/src/main/angular/src/app/series/select/series-select.html
index 592c64a..f5e896d 100644
--- a/src/main/angular/src/app/series/select/series-select.html
+++ b/src/main/angular/src/app/series/select/series-select.html
@@ -4,15 +4,17 @@
(mouseenter)="showPen = true"
(mouseleave)="showPen = false"
>
-