UI: added propertyName and propertyType for editing

This commit is contained in:
Patrick Haßel 2021-10-29 11:48:48 +02:00
parent df2b3ac01d
commit c17869caa4
7 changed files with 37 additions and 7 deletions

View File

@ -10,9 +10,18 @@
<table>
<tr class="header">
<ng-container *ngTemplateOutlet="boolean;context:{schedule: schedule, value: schedule.enabled, key:'enabled'}"></ng-container>
<td colspan="20">
<td colspan="8">
<app-edit-field [initial]="schedule.name" (valueChange)="set(null, 'name', $event)"></app-edit-field>
</td>
<td colspan="5">
<app-edit-field [initial]="schedule.propertyName" (valueChange)="set(null, 'propertyName', $event)"></app-edit-field>
</td>
<td colspan="9">
<select [(ngModel)]="schedule.propertyType" (ngModelChange)="set(null,'propertyType', schedule.propertyType)">
<option value="ON_OFF">An / Aus</option>
<option value="PERCENT">Prozent</option>
</select>
</td>
</tr>
<tr [class.disabled]="!schedule.enabled">
<th>&nbsp;</th>

View File

@ -1,5 +1,5 @@
<input *ngIf="editing" type="text" [(ngModel)]="value" (keypress)="keypress($event)" (blur)="finish()">
<div *ngIf="!editing" [class.empty]="initial == ''" (click)="editing=true">
<input #input *ngIf="editing" type="text" [(ngModel)]="value" (keypress)="keypress($event)" (blur)="finish()">
<div *ngIf="!editing" [class.empty]="initial == ''" (click)="start()">
<ng-container *ngIf="initial != ''">{{initial}}</ng-container>
<ng-container *ngIf="initial == ''">- LEER -</ng-container>
</div>

View File

@ -1,4 +1,4 @@
import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
import {Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild} from '@angular/core';
@Component({
selector: 'app-edit-field',
@ -7,6 +7,9 @@ import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
})
export class EditFieldComponent implements OnInit {
@ViewChild('input')
input?: ElementRef;
@Input()
initial!: string;
@ -38,4 +41,9 @@ export class EditFieldComponent implements OnInit {
this.finish();
}
}
start(): void {
this.editing = true;
setTimeout(() => this.input?.nativeElement.focus(), 0);
}
}

View File

@ -101,7 +101,6 @@ public class DemoDataService {
schedule.setEnabled(true);
schedule.setName(s);
schedule.setPropertyName(knxGroupDto.propertyName);
schedule.setPropertyType(knxGroupDto.getPropertyType());
return schedule;
}

View File

@ -27,11 +27,10 @@ public class Schedule {
@Column(nullable = false, unique = true)
private String name;
@Column(nullable = false)
private String propertyName;
@Column(nullable = false)
private PropertyType propertyType;
private PropertyType propertyType = PropertyType.ON_OFF;
@ToString.Exclude
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)

View File

@ -1,5 +1,6 @@
package de.ph87.homeautomation.schedule;
import de.ph87.homeautomation.property.PropertyType;
import de.ph87.homeautomation.schedule.entry.ScheduleNextExecutionDto;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
@ -50,4 +51,14 @@ public class ScheduleController {
return scheduleWriteService.set(id, Schedule::setName, name);
}
@PostMapping("set/{id}/propertyName")
public ScheduleDto setPropertyName(@PathVariable final long id, @RequestBody final String propertyName) {
return scheduleWriteService.set(id, Schedule::setPropertyName, propertyName);
}
@PostMapping("set/{id}/propertyType")
public ScheduleDto setPropertyType(@PathVariable final long id, @RequestBody final String propertyType) {
return scheduleWriteService.set(id, Schedule::setPropertyType, PropertyType.valueOf(propertyType));
}
}

View File

@ -29,6 +29,10 @@ public class ScheduleExecutionService {
}
private void executeLastDue(final Schedule schedule, final ZonedDateTime now) {
if (schedule.getPropertyName() == null || schedule.getPropertyName().isEmpty()) {
log.error("Cannot execute Schedule {}: No property set!", schedule);
return;
}
schedule.getEntries().stream()
.filter(entry -> entry.getNextFuzzyTimestamp() != null && !entry.getNextFuzzyTimestamp().isAfter(now))
.max(Comparator.comparing(ScheduleEntry::getNextFuzzyTimestamp))