CrudList and Filter FIXES

This commit is contained in:
Patrick Haßel 2024-11-27 13:25:35 +01:00
parent 73926b13e6
commit b94f602b4b
13 changed files with 70 additions and 58 deletions

View File

@ -28,7 +28,7 @@ export class Device {
}
static equals(a: Device, b: Device): boolean {
return a.uuid !== b.uuid;
return a.uuid === b.uuid;
}
}

View File

@ -28,7 +28,7 @@ export class Shutter {
}
static equals(a: Shutter, b: Shutter): boolean {
return a.uuid !== b.uuid;
return a.uuid === b.uuid;
}
}

View File

@ -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;
}

View File

@ -36,7 +36,7 @@ export class Tunable {
}
static equals(a: Tunable, b: Tunable): boolean {
return a.uuid !== b.uuid;
return a.uuid === b.uuid;
}
}

View File

@ -10,33 +10,37 @@ export class CrudLiveList<ENTITY> extends Subscription {
filtered: ENTITY[] = [];
constructor(
crudService: CrudService<ENTITY>,
readonly crudService: CrudService<ENTITY>,
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;
}
}

View File

@ -2,19 +2,19 @@
<div class="subheading">
Eingeschaltete Geräte:
{{ deviceList.filtered.length }}
{{ deviceList.filtered.length }} / {{ deviceList.unfiltered.length }}
</div>
<app-device-list [list]="deviceList.filtered"></app-device-list>
<div class="subheading">
Eingeschaltete Lichter:
{{ tunableList.filtered.length }}
{{ tunableList.filtered.length }} / {{ tunableList.unfiltered.length }}
</div>
<app-tunable-list [list]="tunableList.filtered"></app-tunable-list>
<div class="subheading">
{{ shutterSubheading }} Rollläden:
{{ shutterList.filtered.length }}
{{ shutterList.filtered.length }} / {{ shutterList.unfiltered.length }}
</div>
<app-shutter-list [list]="shutterList.filtered"></app-shutter-list>

View File

@ -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 {

View File

@ -13,10 +13,10 @@
</div>
<div class="sliders">
<div class="slider">
<div class="slider" *ngIf="tunable.brightnessPropertyId !== ''">
<input type="range" [ngModel]="tunable.brightnessProperty?.state?.value" (ngModelChange)="tunableService.setBrightness(tunable, $event)">
</div>
<div class="slider">
<div class="slider" *ngIf="tunable.coldnessPropertyId !== ''">
<input type="range" [ngModel]="tunable.coldnessProperty?.state?.value" (ngModelChange)="tunableService.setColdness(tunable, $event)">
</div>
</div>

View File

@ -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'

View File

@ -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;

View File

@ -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());

View File

@ -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());

View File

@ -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());