From 9213c20116d29adfe84ff72538f97acaf2a8fb36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Ha=C3=9Fel?= Date: Fri, 21 Nov 2025 10:52:38 +0100 Subject: [PATCH] better energy change detection --- .../app/location/detail/location-detail.html | 30 +++++++------------ .../app/location/detail/location-detail.ts | 12 ++++++-- .../location/energy/charts/energy-charts.ts | 7 +++-- .../app/location/energy/location-energy.html | 4 +-- .../app/location/energy/location-energy.ts | 17 +++-------- 5 files changed, 29 insertions(+), 41 deletions(-) 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 f1f4c03..fac948c 100644 --- a/src/main/angular/src/app/location/detail/location-detail.html +++ b/src/main/angular/src/app/location/detail/location-detail.html @@ -3,29 +3,19 @@ - -
-   -
-   -
-   -
{{ offsetDayTitle() }}
-
-
+
+
+
+
{{ offsetDayTitle() }}
+
- -
-   -
-   -
-   -
{{ offsetMonthTitle() }}
-
-
+
+
+
+
{{ offsetMonthTitle() }}
+
@if (configService.locationConfig) { 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 536a337..57ddc6c 100644 --- a/src/main/angular/src/app/location/detail/location-detail.ts +++ b/src/main/angular/src/app/location/detail/location-detail.ts @@ -92,9 +92,7 @@ export class LocationDetail implements OnInit, OnDestroy { private readonly onLocationChange = (location: Location | null): void => { this.location = location; - if (this.location) { - this.menuService.title = this.location.name; - } + this.menuService.title = this.location?.name || ""; }; ngOnDestroy(): void { @@ -122,4 +120,12 @@ export class LocationDetail implements OnInit, OnDestroy { return this.datePipe.transform(d, 'yyyy MMMM') || ''; } + protected offsetDayAdd(delta: number) { + this.offsetDay = Math.max(0, this.offsetDay + delta); + } + + protected offsetMonthAdd(delta: number) { + this.offsetMonth = Math.max(0, this.offsetMonth + delta); + } + } diff --git a/src/main/angular/src/app/location/energy/charts/energy-charts.ts b/src/main/angular/src/app/location/energy/charts/energy-charts.ts index 9d8a169..2b9fb6b 100644 --- a/src/main/angular/src/app/location/energy/charts/energy-charts.ts +++ b/src/main/angular/src/app/location/energy/charts/energy-charts.ts @@ -1,4 +1,4 @@ -import {AfterViewInit, Component, Inject, Input, LOCALE_ID, ViewChild} from '@angular/core'; +import {Component, Inject, Input, LOCALE_ID, OnChanges, SimpleChanges, ViewChild} from '@angular/core'; import {Interval} from '../../../series/Interval'; import {PointService} from '../../../point/point-service'; import {Location} from '../../Location'; @@ -22,7 +22,7 @@ const COLOR_BACK_CONSUME = "#ffc07a"; templateUrl: './energy-charts.html', styleUrl: './energy-charts.less', }) -export class EnergyCharts implements AfterViewInit { +export class EnergyCharts implements OnChanges { @ViewChild(BaseChartDirective) chart?: BaseChartDirective; @@ -118,7 +118,8 @@ export class EnergyCharts implements AfterViewInit { // } - ngAfterViewInit(): void { + ngOnChanges(changes: SimpleChanges): void { + console.log("ngOnChanges", changes); const series = [ this.location.energyPurchase, this.location.energyDeliver, diff --git a/src/main/angular/src/app/location/energy/location-energy.html b/src/main/angular/src/app/location/energy/location-energy.html index ad7f964..abd8272 100644 --- a/src/main/angular/src/app/location/energy/location-energy.html +++ b/src/main/angular/src/app/location/energy/location-energy.html @@ -2,7 +2,7 @@
{{ heading }} - +
@@ -86,6 +86,6 @@
- + diff --git a/src/main/angular/src/app/location/energy/location-energy.ts b/src/main/angular/src/app/location/energy/location-energy.ts index eed8513..bb1a19a 100644 --- a/src/main/angular/src/app/location/energy/location-energy.ts +++ b/src/main/angular/src/app/location/energy/location-energy.ts @@ -1,4 +1,4 @@ -import {AfterViewInit, Component, Input, OnDestroy, OnInit} from '@angular/core'; +import {Component, Input, OnChanges, OnDestroy, OnInit, SimpleChanges} from '@angular/core'; import {Location} from '../Location'; import {Series} from '../../series/Series'; import {Next} from '../../common'; @@ -18,7 +18,7 @@ import {EnergyCharts} from './charts/energy-charts'; templateUrl: './location-energy.html', styleUrl: './location-energy.less', }) -export class LocationEnergy implements OnInit, AfterViewInit, OnDestroy { +export class LocationEnergy implements OnInit, OnChanges, OnDestroy { protected readonly Interval = Interval; @@ -49,17 +49,8 @@ export class LocationEnergy implements OnInit, AfterViewInit, OnDestroy { @Input() heading!: string; - private _o_: number = 0; - @Input() - set offset(value: number) { - this._o_ = value; - this.ngAfterViewInit(); - } - - get offset(): number { - return this._o_; - } + offset: number = 0; @Input() unit: string = ""; @@ -94,7 +85,7 @@ export class LocationEnergy implements OnInit, AfterViewInit, OnDestroy { this.subs.push(this.serieService.subscribe(this.update)); } - ngAfterViewInit(): void { + ngOnChanges(changes: SimpleChanges): void { this.fetch(null, this.location?.energyPurchase, history => this.purchase = history); this.fetch(null, this.location?.energyDeliver, history => this.deliver = history); this.fetch(null, this.location?.energyProduce, history => this.produce = history);