From b94f602b4bee45128234fbae94a98519b8de394a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Ha=C3=9Fel?= Date: Wed, 27 Nov 2024 13:25:35 +0100 Subject: [PATCH] CrudList and Filter FIXES --- src/main/angular/src/app/api/Device/Device.ts | 2 +- .../angular/src/app/api/Shutter/Shutter.ts | 2 +- .../src/app/api/Shutter/ShutterFilter.ts | 8 +++--- .../angular/src/app/api/Tunable/Tunable.ts | 2 +- .../src/app/api/common/CrudLiveList.ts | 26 +++++++++-------- .../pages/dashboard/dashboard.component.html | 6 ++-- .../tunable-list-page.component.ts | 2 +- .../tunable-list/tunable-list.component.html | 4 +-- .../tunable-list/tunable-list.component.ts | 5 ++-- .../java/de/ph87/home/demo/DemoService.java | 27 ++++++++++-------- .../de/ph87/home/device/DeviceFilter.java | 8 +++--- .../de/ph87/home/shutter/ShutterFilter.java | 28 +++++++++++-------- .../de/ph87/home/tunable/TunableFilter.java | 8 +++--- 13 files changed, 70 insertions(+), 58 deletions(-) diff --git a/src/main/angular/src/app/api/Device/Device.ts b/src/main/angular/src/app/api/Device/Device.ts index 718bba9..1defc1a 100644 --- a/src/main/angular/src/app/api/Device/Device.ts +++ b/src/main/angular/src/app/api/Device/Device.ts @@ -28,7 +28,7 @@ export class Device { } static equals(a: Device, b: Device): boolean { - return a.uuid !== b.uuid; + return a.uuid === b.uuid; } } diff --git a/src/main/angular/src/app/api/Shutter/Shutter.ts b/src/main/angular/src/app/api/Shutter/Shutter.ts index ed304af..1197e4e 100644 --- a/src/main/angular/src/app/api/Shutter/Shutter.ts +++ b/src/main/angular/src/app/api/Shutter/Shutter.ts @@ -28,7 +28,7 @@ export class Shutter { } static equals(a: Shutter, b: Shutter): boolean { - return a.uuid !== b.uuid; + return a.uuid === b.uuid; } } diff --git a/src/main/angular/src/app/api/Shutter/ShutterFilter.ts b/src/main/angular/src/app/api/Shutter/ShutterFilter.ts index d8e1662..f8ce5b3 100644 --- a/src/main/angular/src/app/api/Shutter/ShutterFilter.ts +++ b/src/main/angular/src/app/api/Shutter/ShutterFilter.ts @@ -2,12 +2,12 @@ export class ShutterFilter { search: string = ""; - positionOpen: boolean | null = null; + positionOpen: boolean = true; - positionBetween: boolean | null = null; + positionBetween: boolean = true; - positionClosed: boolean | null = null; + positionClosed: boolean = true; - stateNull: boolean | null = null; + stateNull: boolean = true; } diff --git a/src/main/angular/src/app/api/Tunable/Tunable.ts b/src/main/angular/src/app/api/Tunable/Tunable.ts index bc1523a..268d2cd 100644 --- a/src/main/angular/src/app/api/Tunable/Tunable.ts +++ b/src/main/angular/src/app/api/Tunable/Tunable.ts @@ -36,7 +36,7 @@ export class Tunable { } static equals(a: Tunable, b: Tunable): boolean { - return a.uuid !== b.uuid; + return a.uuid === b.uuid; } } diff --git a/src/main/angular/src/app/api/common/CrudLiveList.ts b/src/main/angular/src/app/api/common/CrudLiveList.ts index adba169..7b56397 100644 --- a/src/main/angular/src/app/api/common/CrudLiveList.ts +++ b/src/main/angular/src/app/api/common/CrudLiveList.ts @@ -10,33 +10,37 @@ export class CrudLiveList extends Subscription { filtered: ENTITY[] = []; constructor( - crudService: CrudService, + readonly crudService: CrudService, readonly equals: (a: ENTITY, b: ENTITY) => boolean, readonly filter: (item: ENTITY) => boolean = _ => true, ) { super(() => { this.subs.forEach(sub => sub.unsubscribe()); }); - crudService.all(list => this.unfiltered = list); + this.fetchAll(); + this.subs.push(crudService.api.connected(_ => this.fetchAll())); this.subs.push(crudService.subscribe(item => this.update(item))); } + private fetchAll() { + this.crudService.all(list => { + this.unfiltered = list; + this.updateFiltered(); + }); + } + private update(item: ENTITY) { const index = this.unfiltered.findIndex(i => this.equals(i, item)); if (index >= 0) { - this.unfiltered.splice(index, 1, item); + this.unfiltered[index] = item; } else { this.unfiltered.push(item); } + this.updateFiltered(); + } + + private updateFiltered() { this.filtered = this.unfiltered.filter(this.filter); } - get hasUnfiltered(): boolean { - return this.unfiltered.length > 0; - } - - get hasFiltered(): boolean { - return this.filtered.length > 0; - } - } diff --git a/src/main/angular/src/app/pages/dashboard/dashboard.component.html b/src/main/angular/src/app/pages/dashboard/dashboard.component.html index 9e7fb27..c11e3ab 100644 --- a/src/main/angular/src/app/pages/dashboard/dashboard.component.html +++ b/src/main/angular/src/app/pages/dashboard/dashboard.component.html @@ -2,19 +2,19 @@
Eingeschaltete Geräte: - {{ deviceList.filtered.length }} + {{ deviceList.filtered.length }} / {{ deviceList.unfiltered.length }}
Eingeschaltete Lichter: - {{ tunableList.filtered.length }} + {{ tunableList.filtered.length }} / {{ tunableList.unfiltered.length }}
{{ shutterSubheading }} Rollläden: - {{ shutterList.filtered.length }} + {{ shutterList.filtered.length }} / {{ shutterList.unfiltered.length }}
diff --git a/src/main/angular/src/app/pages/tunable-list-page/tunable-list-page.component.ts b/src/main/angular/src/app/pages/tunable-list-page/tunable-list-page.component.ts index c7dca62..9d306fa 100644 --- a/src/main/angular/src/app/pages/tunable-list-page/tunable-list-page.component.ts +++ b/src/main/angular/src/app/pages/tunable-list-page/tunable-list-page.component.ts @@ -36,8 +36,8 @@ export class TunableListPageComponent implements OnInit, OnDestroy { ngOnInit(): void { this.fetch(); - this.subs.push(this.tunableService.subscribe(tunable => this.updateTunable(tunable))); this.apiService.connected(() => this.fetch()); + this.subs.push(this.tunableService.subscribe(tunable => this.updateTunable(tunable))); } ngOnDestroy(): void { diff --git a/src/main/angular/src/app/shared/tunable-list/tunable-list.component.html b/src/main/angular/src/app/shared/tunable-list/tunable-list.component.html index 9c22ff2..62cb35d 100644 --- a/src/main/angular/src/app/shared/tunable-list/tunable-list.component.html +++ b/src/main/angular/src/app/shared/tunable-list/tunable-list.component.html @@ -13,10 +13,10 @@
-
+
-
+
diff --git a/src/main/angular/src/app/shared/tunable-list/tunable-list.component.ts b/src/main/angular/src/app/shared/tunable-list/tunable-list.component.ts index 86407bf..28ce9e6 100644 --- a/src/main/angular/src/app/shared/tunable-list/tunable-list.component.ts +++ b/src/main/angular/src/app/shared/tunable-list/tunable-list.component.ts @@ -1,5 +1,5 @@ import {Component, Input, OnDestroy, OnInit} from '@angular/core'; -import {NgClass, NgForOf} from '@angular/common'; +import {NgClass, NgForOf, NgIf} from '@angular/common'; import {Tunable} from '../../api/Tunable/Tunable'; import {TunableService} from '../../api/Tunable/tunable.service'; import {RelativePipe} from '../../api/common/relative.pipe'; @@ -13,7 +13,8 @@ import {FormsModule} from '@angular/forms'; NgForOf, NgClass, RelativePipe, - FormsModule + FormsModule, + NgIf ], templateUrl: './tunable-list.component.html', styleUrl: './tunable-list.component.less' diff --git a/src/main/java/de/ph87/home/demo/DemoService.java b/src/main/java/de/ph87/home/demo/DemoService.java index 1254d76..e6f8ec9 100644 --- a/src/main/java/de/ph87/home/demo/DemoService.java +++ b/src/main/java/de/ph87/home/demo/DemoService.java @@ -31,14 +31,14 @@ public class DemoService { @EventListener(ApplicationStartedEvent.class) public void startup() { - device("eg_ambiente", "EG Ambiente", 849, 848); device("fernseher", "Wohnzimmer Fernseher", 20, 4); device("verstaerker", "Wohnzimmer Verstärker", 825, 824); - device("fensterdeko", "Wohnzimmer Fenster", 1823, 1822); - device("haengelampe", "Wohnzimmer Hängelampe", 1794, 1799); device("receiver", "Receiver", 2561, 2560); + tunable("wohnzimmer_haengelampe", "Wohnzimmer Hängelampe", 1794, 1799, null, null, null, null); + tunable("wohnzimmer_fensterdeko", "Wohnzimmer Fenster", 1823, 1822, null, null, null, null); tunable("wohnzimmer_spots", "Wohnzimmer", 28, 828, 2344, 2343, 1825, 1824); + tunable("eg_ambiente", "EG Ambiente", 849, 848, null, null, null, null); tunable("kueche_spots", "Küche", 2311, 2304, 2342, 2341, 2321, 2317); tunable("arbeitszimmer_spots", "Arbeitszimmer", 2058, 2057, 2067, 2069, 2049, 2054); @@ -78,18 +78,21 @@ public class DemoService { @Nullable final Integer coldnessRead, @Nullable final Integer coldnessWrite ) { - final String stateProperty = slug + "_state"; - knxPropertyService.create(stateProperty, KnxPropertyType.BOOLEAN, adr(stateRead), adr(stateWrite)); - - final String brightnessProperty = slug + "_brightness"; - knxPropertyService.create(brightnessProperty, KnxPropertyType.DOUBLE, adr(brightnessRead), adr(brightnessWrite)); - - final String coldnessProperty = slug + "_coldness"; - knxPropertyService.create(coldnessProperty, KnxPropertyType.DOUBLE, adr(coldnessRead), adr(coldnessWrite)); - + final String stateProperty = knxProperty(slug + "_state", KnxPropertyType.BOOLEAN, stateRead, stateWrite); + final String brightnessProperty = knxProperty(slug + "_brightness", KnxPropertyType.DOUBLE, brightnessRead, brightnessWrite); + final String coldnessProperty = knxProperty(slug + "_coldness", KnxPropertyType.DOUBLE, coldnessRead, coldnessWrite); tunableService.create(name, slug, stateProperty, brightnessProperty, coldnessProperty); } + @NonNull + private String knxProperty(@NonNull final String id, @NonNull final KnxPropertyType type, @Nullable final Integer stateRead, @Nullable final Integer stateWrite) { + if (stateRead == null && stateWrite == null) { + return ""; + } + knxPropertyService.create(id, type, adr(stateRead), adr(stateWrite)); + return id; + } + private static GroupAddress adr(final Integer rawGroupAddress) { if (rawGroupAddress == null) { return null; diff --git a/src/main/java/de/ph87/home/device/DeviceFilter.java b/src/main/java/de/ph87/home/device/DeviceFilter.java index 9ab3f79..04c05ba 100644 --- a/src/main/java/de/ph87/home/device/DeviceFilter.java +++ b/src/main/java/de/ph87/home/device/DeviceFilter.java @@ -12,13 +12,13 @@ import lombok.ToString; public class DeviceFilter extends AbstractSearchFilter { @JsonProperty - private boolean stateNull; + private boolean stateNull = true; @JsonProperty - private boolean stateTrue; + private boolean stateTrue = true; @JsonProperty - private boolean stateFalse; + private boolean stateFalse = true; public boolean filter(@NonNull final DeviceDto dto) throws PropertyTypeMismatch { final Boolean value = dto.getStateValue(); @@ -28,7 +28,7 @@ public class DeviceFilter extends AbstractSearchFilter { if (!stateTrue && Boolean.TRUE.equals(value)) { return false; } - if (!stateFalse == Boolean.FALSE.equals(value)) { + if (!stateFalse && Boolean.FALSE.equals(value)) { return false; } return search(dto.getName()); diff --git a/src/main/java/de/ph87/home/shutter/ShutterFilter.java b/src/main/java/de/ph87/home/shutter/ShutterFilter.java index 2096d3f..a04b5bc 100644 --- a/src/main/java/de/ph87/home/shutter/ShutterFilter.java +++ b/src/main/java/de/ph87/home/shutter/ShutterFilter.java @@ -3,36 +3,40 @@ package de.ph87.home.shutter; import com.fasterxml.jackson.annotation.JsonProperty; import de.ph87.home.common.crud.AbstractSearchFilter; import de.ph87.home.property.PropertyTypeMismatch; -import jakarta.annotation.Nullable; import lombok.Getter; import lombok.NonNull; import lombok.ToString; +import java.util.Objects; + @Getter @ToString public class ShutterFilter extends AbstractSearchFilter { - @Nullable @JsonProperty - private Boolean positionNull; + private boolean positionNull = true; - @Nullable @JsonProperty - private Double positionMin; + private boolean positionOpen = true; - @Nullable @JsonProperty - private Double positionMax; + private boolean positionBetween = true; + + @JsonProperty + private boolean positionClosed = true; public boolean filter(@NonNull final ShutterDto dto) throws PropertyTypeMismatch { - if (positionNull != null && positionNull != (dto.getPositionProperty() == null)) { - return false; - } final Double value = dto.getPositionValue(); - if (positionMin != null && value != null && positionMin <= value) { + if (!positionNull && value == null) { return false; } - if (positionMax != null && value != null && positionMax >= value) { + if (!positionOpen && Objects.equals(value, 0.0)) { + return false; + } + if (!positionBetween && !Objects.equals(value, 0.0) && !Objects.equals(value, 100.0)) { + return false; + } + if (!positionClosed && Objects.equals(value, 100.0)) { return false; } return search(dto.getName()); diff --git a/src/main/java/de/ph87/home/tunable/TunableFilter.java b/src/main/java/de/ph87/home/tunable/TunableFilter.java index 558cb8c..e39987d 100644 --- a/src/main/java/de/ph87/home/tunable/TunableFilter.java +++ b/src/main/java/de/ph87/home/tunable/TunableFilter.java @@ -12,13 +12,13 @@ import lombok.ToString; public class TunableFilter extends AbstractSearchFilter { @JsonProperty - private boolean stateNull; + private boolean stateNull = true; @JsonProperty - private boolean stateTrue; + private boolean stateTrue = true; @JsonProperty - private boolean stateFalse; + private boolean stateFalse = true; public boolean filter(@NonNull final TunableDto dto) throws PropertyTypeMismatch { final Boolean value = dto.getStateValue(); @@ -28,7 +28,7 @@ public class TunableFilter extends AbstractSearchFilter { if (!stateTrue && Boolean.TRUE.equals(value)) { return false; } - if (!stateFalse == Boolean.FALSE.equals(value)) { + if (!stateFalse && Boolean.FALSE.equals(value)) { return false; } return search(dto.getName());