From a9394efc11893bb5027479ebc6b39c96dd07f399 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Ha=C3=9Fel?= Date: Fri, 29 Nov 2024 09:43:36 +0100 Subject: [PATCH] UI: tagList, tagConfirm --- src/main/angular/src/app/Device/Device.ts | 7 +++++-- .../Device/device-tile/device-tile.component.html | 6 +++--- .../app/Device/device-tile/device-tile.component.ts | 12 +++++++++--- src/main/angular/src/app/Shutter/Shutter.ts | 7 +++++-- src/main/angular/src/app/Tag/Tag.ts | 2 ++ src/main/angular/src/app/Thing/Thing.ts | 7 +++++++ src/main/angular/src/app/Tunable/Tunable.ts | 7 +++++-- src/main/angular/src/app/app.component.html | 1 + src/main/java/de/ph87/home/device/DeviceDto.java | 6 +++--- src/main/java/de/ph87/home/shutter/ShutterDto.java | 6 +++--- src/main/java/de/ph87/home/tag/TagDto.java | 4 ++++ src/main/java/de/ph87/home/tunable/TunableDto.java | 6 +++--- 12 files changed, 50 insertions(+), 21 deletions(-) diff --git a/src/main/angular/src/app/Device/Device.ts b/src/main/angular/src/app/Device/Device.ts index 9ddadcb..f93e5b6 100644 --- a/src/main/angular/src/app/Device/Device.ts +++ b/src/main/angular/src/app/Device/Device.ts @@ -1,7 +1,8 @@ import {Property} from "../Property/Property"; -import {orNull, validateString} from "../api/validators"; +import {orNull, validateList, validateString} from "../api/validators"; import {Area} from '../Area/Area'; import {Thing} from '../Thing/Thing'; +import {Tag} from '../Tag/Tag'; export class Device extends Thing { @@ -10,10 +11,11 @@ export class Device extends Thing { uuid: string, name: string, slug: string, + tagList: Tag[], readonly statePropertyId: string, readonly stateProperty: Property | null, ) { - super(area, uuid, name, slug); + super(area, uuid, name, slug, tagList); } static fromJson(json: any): Device { @@ -22,6 +24,7 @@ export class Device extends Thing { validateString(json.uuid), validateString(json.name), validateString(json.slug), + validateList(json.tagList, Tag.fromJson), validateString(json.statePropertyId), orNull(json.stateProperty, Property.fromJson), ); diff --git a/src/main/angular/src/app/Device/device-tile/device-tile.component.html b/src/main/angular/src/app/Device/device-tile/device-tile.component.html index fc370d1..dd5ae3d 100644 --- a/src/main/angular/src/app/Device/device-tile/device-tile.component.html +++ b/src/main/angular/src/app/Device/device-tile/device-tile.component.html @@ -1,14 +1,14 @@
-
+
{{ device.nameWithArea }}
-
-
+
+
diff --git a/src/main/angular/src/app/Device/device-tile/device-tile.component.ts b/src/main/angular/src/app/Device/device-tile/device-tile.component.ts index 08adcc2..4f24819 100644 --- a/src/main/angular/src/app/Device/device-tile/device-tile.component.ts +++ b/src/main/angular/src/app/Device/device-tile/device-tile.component.ts @@ -28,11 +28,17 @@ export class DeviceTileComponent { // } - ngClass(device: Device) { + ngClass() { return { - "stateOn": device.stateProperty?.state?.value === true, - "stateOff": device.stateProperty?.state?.value === false, + "stateOn": this.device.stateProperty?.state?.value === true, + "stateOff": this.device.stateProperty?.state?.value === false, }; } + setState(newState: boolean) { + if (!this.device.hasTagBySlug('confirm') || confirm("Sicher?")) { + this.deviceService.setState(this.device, newState); + } + } + } diff --git a/src/main/angular/src/app/Shutter/Shutter.ts b/src/main/angular/src/app/Shutter/Shutter.ts index 054b2a8..ff36c5c 100644 --- a/src/main/angular/src/app/Shutter/Shutter.ts +++ b/src/main/angular/src/app/Shutter/Shutter.ts @@ -1,8 +1,9 @@ import {Property} from "../Property/Property"; -import {orNull, validateString} from "../api/validators"; +import {orNull, validateList, validateString} from "../api/validators"; import {Area} from '../Area/Area'; import {Thing} from '../Thing/Thing'; +import {Tag} from '../Tag/Tag'; export class Shutter extends Thing { @@ -11,10 +12,11 @@ export class Shutter extends Thing { uuid: string, name: string, slug: string, + tagList: Tag[], readonly positionPropertyId: string, readonly positionProperty: Property | null, ) { - super(area, uuid, name, slug); + super(area, uuid, name, slug, tagList); } static fromJson(json: any): Shutter { @@ -23,6 +25,7 @@ export class Shutter extends Thing { validateString(json.uuid), validateString(json.name), validateString(json.slug), + validateList(json.tagList, Tag.fromJson), validateString(json.positionPropertyId), orNull(json.positionProperty, Property.fromJson), ); diff --git a/src/main/angular/src/app/Tag/Tag.ts b/src/main/angular/src/app/Tag/Tag.ts index 9635b39..2f13c18 100644 --- a/src/main/angular/src/app/Tag/Tag.ts +++ b/src/main/angular/src/app/Tag/Tag.ts @@ -4,6 +4,7 @@ export class Tag { constructor( readonly uuid: string, + readonly slug: string, readonly name: string, ) { // @@ -12,6 +13,7 @@ export class Tag { static fromJson(json: any): Tag { return new Tag( validateString(json.uuid), + validateString(json.slug), validateString(json.name), ); } diff --git a/src/main/angular/src/app/Thing/Thing.ts b/src/main/angular/src/app/Thing/Thing.ts index 954ac4b..ebe1c86 100644 --- a/src/main/angular/src/app/Thing/Thing.ts +++ b/src/main/angular/src/app/Thing/Thing.ts @@ -1,4 +1,5 @@ import {Area} from '../Area/Area'; +import {Tag} from '../Tag/Tag'; export abstract class Thing { @@ -7,6 +8,7 @@ export abstract class Thing { readonly uuid: string, readonly name: string, readonly slug: string, + readonly tagList: Tag[], ) { // } @@ -25,6 +27,11 @@ export abstract class Thing { return this.area.name + ' ' + this.name; } + hasTagBySlug(slug: string): boolean { + const slugLower = slug.toLowerCase(); + return this.tagList.some(t => t.slug.toLocaleLowerCase() === slugLower); + } + static trackBy(index: number, thing: Thing) { return thing.uuid; } diff --git a/src/main/angular/src/app/Tunable/Tunable.ts b/src/main/angular/src/app/Tunable/Tunable.ts index 83f8c46..578e76b 100644 --- a/src/main/angular/src/app/Tunable/Tunable.ts +++ b/src/main/angular/src/app/Tunable/Tunable.ts @@ -1,7 +1,8 @@ import {Property} from "../Property/Property"; -import {orNull, validateString} from "../api/validators"; +import {orNull, validateList, validateString} from "../api/validators"; import {Area} from '../Area/Area'; import {Thing} from '../Thing/Thing'; +import {Tag} from '../Tag/Tag'; export class Tunable extends Thing { @@ -10,6 +11,7 @@ export class Tunable extends Thing { uuid: string, name: string, slug: string, + tagList: Tag[], readonly statePropertyId: string, readonly stateProperty: Property | null, readonly brightnessPropertyId: string, @@ -17,7 +19,7 @@ export class Tunable extends Thing { readonly coldnessPropertyId: string, readonly coldnessProperty: Property | null, ) { - super(area, uuid, name, slug); + super(area, uuid, name, slug, tagList); } static fromJson(json: any): Tunable { @@ -26,6 +28,7 @@ export class Tunable extends Thing { validateString(json.uuid), validateString(json.name), validateString(json.slug), + validateList(json.tagList, Tag.fromJson), validateString(json.statePropertyId), orNull(json.stateProperty, Property.fromJson), validateString(json.brightnessPropertyId), diff --git a/src/main/angular/src/app/app.component.html b/src/main/angular/src/app/app.component.html index 2c97049..cdcabb6 100644 --- a/src/main/angular/src/app/app.component.html +++ b/src/main/angular/src/app/app.component.html @@ -3,6 +3,7 @@
Dash
Geräte
Licht
+
Deko
Rollladen
KNX
diff --git a/src/main/java/de/ph87/home/device/DeviceDto.java b/src/main/java/de/ph87/home/device/DeviceDto.java index f7e2d31..c717063 100644 --- a/src/main/java/de/ph87/home/device/DeviceDto.java +++ b/src/main/java/de/ph87/home/device/DeviceDto.java @@ -3,7 +3,7 @@ package de.ph87.home.device; import de.ph87.home.area.AreaDto; import de.ph87.home.property.PropertyDto; import de.ph87.home.property.PropertyTypeMismatch; -import de.ph87.home.tag.Tag; +import de.ph87.home.tag.TagDto; import de.ph87.home.web.IWebSocketMessage; import jakarta.annotation.Nullable; import lombok.Getter; @@ -39,7 +39,7 @@ public class DeviceDto implements IWebSocketMessage { private final PropertyDto stateProperty; @NonNull - private final List tagList; + private final List tagList; public DeviceDto(@NonNull final Device device, @Nullable final PropertyDto stateProperty) { this.area = new AreaDto(device.getArea()); @@ -48,7 +48,7 @@ public class DeviceDto implements IWebSocketMessage { this.slug = device.getSlug(); this.statePropertyId = device.getStatePropertyId(); this.stateProperty = stateProperty; - this.tagList = device.getTagList().stream().map(Tag::getName).toList(); + this.tagList = device.getTagList().stream().map(TagDto::new).toList(); } @Nullable diff --git a/src/main/java/de/ph87/home/shutter/ShutterDto.java b/src/main/java/de/ph87/home/shutter/ShutterDto.java index 7d8fdf8..aa06742 100644 --- a/src/main/java/de/ph87/home/shutter/ShutterDto.java +++ b/src/main/java/de/ph87/home/shutter/ShutterDto.java @@ -3,7 +3,7 @@ package de.ph87.home.shutter; import de.ph87.home.area.AreaDto; import de.ph87.home.property.PropertyDto; import de.ph87.home.property.PropertyTypeMismatch; -import de.ph87.home.tag.Tag; +import de.ph87.home.tag.TagDto; import de.ph87.home.web.IWebSocketMessage; import jakarta.annotation.Nullable; import lombok.Getter; @@ -39,7 +39,7 @@ public class ShutterDto implements IWebSocketMessage { private final PropertyDto positionProperty; @NonNull - private final List tagList; + private final List tagList; public ShutterDto(@NonNull final Shutter shutter, @Nullable final PropertyDto positionProperty) { this.area = new AreaDto(shutter.getArea()); @@ -48,7 +48,7 @@ public class ShutterDto implements IWebSocketMessage { this.slug = shutter.getSlug(); this.positionPropertyId = shutter.getPositionPropertyId(); this.positionProperty = positionProperty; - this.tagList = shutter.getTagList().stream().map(Tag::getName).toList(); + this.tagList = shutter.getTagList().stream().map(TagDto::new).toList(); } @Nullable diff --git a/src/main/java/de/ph87/home/tag/TagDto.java b/src/main/java/de/ph87/home/tag/TagDto.java index f933b98..5779e70 100644 --- a/src/main/java/de/ph87/home/tag/TagDto.java +++ b/src/main/java/de/ph87/home/tag/TagDto.java @@ -9,11 +9,15 @@ public class TagDto { @NonNull private final String uuid; + @NonNull + private final String slug; + @NonNull private final String name; public TagDto(@NonNull final Tag tag) { this.uuid = tag.getUuid(); + this.slug = tag.getSlug(); this.name = tag.getName(); } diff --git a/src/main/java/de/ph87/home/tunable/TunableDto.java b/src/main/java/de/ph87/home/tunable/TunableDto.java index c5e9ecb..1e1fdc1 100644 --- a/src/main/java/de/ph87/home/tunable/TunableDto.java +++ b/src/main/java/de/ph87/home/tunable/TunableDto.java @@ -3,7 +3,7 @@ package de.ph87.home.tunable; import de.ph87.home.area.AreaDto; import de.ph87.home.property.PropertyDto; import de.ph87.home.property.PropertyTypeMismatch; -import de.ph87.home.tag.Tag; +import de.ph87.home.tag.TagDto; import de.ph87.home.web.IWebSocketMessage; import jakarta.annotation.Nullable; import lombok.Getter; @@ -53,7 +53,7 @@ public class TunableDto implements IWebSocketMessage { private final PropertyDto coldnessProperty; @NonNull - private final List tagList; + private final List tagList; public TunableDto(@NonNull final Tunable tunable, @Nullable final PropertyDto stateProperty, @Nullable final PropertyDto brightnessProperty, @Nullable final PropertyDto coldnessProperty) { this.area = new AreaDto(tunable.getArea()); @@ -66,7 +66,7 @@ public class TunableDto implements IWebSocketMessage { this.stateProperty = stateProperty; this.brightnessProperty = brightnessProperty; this.coldnessProperty = coldnessProperty; - this.tagList = tunable.getTagList().stream().map(Tag::getName).toList(); + this.tagList = tunable.getTagList().stream().map(TagDto::new).toList(); } @Nullable