diff --git a/src/main/angular/src/app/api/property/Property.ts b/src/main/angular/src/app/api/property/Property.ts index ffadb18..deb0891 100644 --- a/src/main/angular/src/app/api/property/Property.ts +++ b/src/main/angular/src/app/api/property/Property.ts @@ -1,18 +1,29 @@ -import {validateListOrEmpty, validateNumberNotNull, validateStringNotEmptyNotNull} from "../validators"; +import {validateListOrEmpty, validateNumberNotNull, validateStringEmptyToNull, validateStringNotEmptyNotNull} from "../validators"; import {Channel} from "../channel/Channel"; import {SearchResult} from "../SearchResult"; +import {environment} from "../../../environments/environment"; export class Property { + readonly hrefId: string | null; + + readonly hrefSlug: string | null; + constructor( public id: number, public type: string, public title: string, + public slug: string | null, public readChannel: Channel | null, public writeChannel: Channel | null, public usages: SearchResult[], ) { - // nothing + if (writeChannel || true) { + this.hrefId = environment.restBase + '/property/write/id/' + id + '/' + if (slug) { + this.hrefSlug = environment.restBase + '/property/write/slug/' + slug + '/'; + } + } } static fromJsonAllowNull(json: any): Property | null { @@ -27,6 +38,7 @@ export class Property { validateNumberNotNull(json['id']), validateStringNotEmptyNotNull(json['type']), validateStringNotEmptyNotNull(json['title']), + validateStringEmptyToNull(json['slug']), Channel.fromJsonAllowNull(json['readChannel']), Channel.fromJsonAllowNull(json['writeChannel']), validateListOrEmpty(json['usages'], SearchResult.fromJson), diff --git a/src/main/angular/src/app/pages/property/list/property-list.component.html b/src/main/angular/src/app/pages/property/list/property-list.component.html index b2f277c..9c713f9 100644 --- a/src/main/angular/src/app/pages/property/list/property-list.component.html +++ b/src/main/angular/src/app/pages/property/list/property-list.component.html @@ -9,6 +9,7 @@
| Bezeichnung | +Links | Typ | Wert | Zeitstempel | @@ -23,6 +24,20 @@
+
+ {{property.hrefId}}0
+ {{property.hrefId}}1
+ {{property.hrefSlug}}0
+ {{property.hrefSlug}}1
+
+
{{property.hrefId}}0
+ {{property.hrefId}}90
+ {{property.hrefId}}100
+ {{property.hrefSlug}}0
+ {{property.hrefSlug}}90
+ {{property.hrefSlug}}100
+ |
diff --git a/src/main/angular/src/app/pages/property/list/property-list.component.less b/src/main/angular/src/app/pages/property/list/property-list.component.less
index 1922e7f..20f1fc6 100644
--- a/src/main/angular/src/app/pages/property/list/property-list.component.less
+++ b/src/main/angular/src/app/pages/property/list/property-list.component.less
@@ -1,3 +1,8 @@
table {
width: 100%;
}
+
+.links {
+ color: gray;
+ font-size: 80%;
+}
diff --git a/src/main/angular/src/app/pages/property/list/property-list.component.ts b/src/main/angular/src/app/pages/property/list/property-list.component.ts
index cf3e54e..245531e 100644
--- a/src/main/angular/src/app/pages/property/list/property-list.component.ts
+++ b/src/main/angular/src/app/pages/property/list/property-list.component.ts
@@ -5,6 +5,7 @@ import {Scene} from "../../../api/scene/Scene";
import {SceneService} from "../../../api/scene/scene.service";
import {ChannelService} from "../../../api/channel/channel.service";
import {faTimesCircle} from "@fortawesome/free-regular-svg-icons";
+import {environment} from 'src/environments/environment';
@Component({
selector: 'app-property-list',
@@ -21,6 +22,8 @@ export class PropertyListComponent implements OnInit {
scenes: Scene[] = [];
+ readonly environment = environment;
+
constructor(
readonly propertyService: PropertyService,
readonly sceneService: SceneService,
diff --git a/src/main/java/de/ph87/homeautomation/DemoDataService.java b/src/main/java/de/ph87/homeautomation/DemoDataService.java
index 3dfbd69..cc6e724 100644
--- a/src/main/java/de/ph87/homeautomation/DemoDataService.java
+++ b/src/main/java/de/ph87/homeautomation/DemoDataService.java
@@ -43,11 +43,11 @@ public class DemoDataService {
if (!config.isInsertDemoData()) {
return;
}
- final Property propertyDirect = createProperty("propertyDirect", PropertyType.BOOLEAN, null, null);
- final Property propertyBulkBoolean = createProperty("propertyBulkBoolean", PropertyType.BOOLEAN, null, null);
- final Property propertyBulkShutter = createProperty("propertyBulkShutter", PropertyType.SHUTTER, null, null);
- final Property propertyBulkBrightness = createProperty("propertyBulkBrightness", PropertyType.BRIGHTNESS_PERCENT, null, null);
- final Property propertyBulkColorTemperature = createProperty("propertyBulkColorTemperature", PropertyType.COLOR_TEMPERATURE, null, null);
+ final Property propertyDirect = createProperty("propertyDirect", "direct", PropertyType.BOOLEAN, null, null);
+ final Property propertyBulkBoolean = createProperty("propertyBulkBoolean", null, PropertyType.BOOLEAN, null, null);
+ final Property propertyBulkShutter = createProperty("propertyBulkShutter", null, PropertyType.SHUTTER, null, null);
+ final Property propertyBulkBrightness = createProperty("propertyBulkBrightness", null, PropertyType.BRIGHTNESS_PERCENT, null, null);
+ final Property propertyBulkColorTemperature = createProperty("propertyBulkColorTemperature", null, PropertyType.COLOR_TEMPERATURE, null, null);
final BulkDto bulk = bulkController.create(new BulkCreateDto("bulk", true));
bulkEntryController.create(new BulkEntryCreateDto(bulk.getId(), propertyBulkBoolean.getId(), 1, 0));
bulkEntryController.create(new BulkEntryCreateDto(bulk.getId(), propertyBulkShutter.getId(), 35, 0));
@@ -58,8 +58,9 @@ public class DemoDataService {
createTime(scheduleId, true, now.getHour(), now.getMinute(), now.getSecond(), 0, propertyDirect, 1, bulk);
}
- private Property createProperty(final String title, final PropertyType type, final Channel readChannel, final Channel writeChannel) {
+ private Property createProperty(final String title, final String slug, final PropertyType type, final Channel readChannel, final Channel writeChannel) {
final Property property = propertyRepository.findByTitle(title).orElseGet(() -> propertyRepository.save(new Property(title, type)));
+ property.setSlug(slug == null || slug.isEmpty() ? null : slug);
property.setReadChannel(readChannel);
property.setWriteChannel(writeChannel);
return property;
diff --git a/src/main/java/de/ph87/homeautomation/property/Property.java b/src/main/java/de/ph87/homeautomation/property/Property.java
index ef5c4ff..1eb3fa8 100644
--- a/src/main/java/de/ph87/homeautomation/property/Property.java
+++ b/src/main/java/de/ph87/homeautomation/property/Property.java
@@ -24,6 +24,9 @@ public final class Property {
@Column(nullable = false, unique = true)
private String title;
+ @Column(unique = true)
+ private String slug;
+
@ManyToOne
private Channel readChannel;
diff --git a/src/main/java/de/ph87/homeautomation/property/PropertyController.java b/src/main/java/de/ph87/homeautomation/property/PropertyController.java
index 8d8d12a..a767e75 100644
--- a/src/main/java/de/ph87/homeautomation/property/PropertyController.java
+++ b/src/main/java/de/ph87/homeautomation/property/PropertyController.java
@@ -39,6 +39,11 @@ public class PropertyController implements ISearchController {
return propertyWriter.set(id, Property::setTitle, propertyTitle);
}
+ @PostMapping("set/{id}/slug")
+ public PropertyDto setPropertySlug(@PathVariable final long id, @RequestBody final String propertySlug) {
+ return propertyWriter.set(id, Property::setSlug, propertySlug);
+ }
+
@PostMapping("set/{id}/value")
public PropertyDto setValue(@PathVariable final long id, @RequestBody final double value) {
return propertyWriter.set(id, propertyWriter::writeToChannel, value);
@@ -89,4 +94,16 @@ public class PropertyController implements ISearchController {
return new SearchResult(Property.class, propertyDto.getId(), propertyDto.getTitle());
}
+ @PostMapping("write/id/{id}/{value}")
+ public void write(@PathVariable final long id, @PathVariable final double value) {
+ final Property property = propertyReader.getById(id);
+ propertyWriter.writeToChannel(property, value);
+ }
+
+ @PostMapping("write/slug/{slug}/{value}")
+ public void write(@PathVariable final String slug, @PathVariable final double value) {
+ final Property property = propertyReader.getBySlug(slug);
+ propertyWriter.writeToChannel(property, value);
+ }
+
}
diff --git a/src/main/java/de/ph87/homeautomation/property/PropertyDto.java b/src/main/java/de/ph87/homeautomation/property/PropertyDto.java
index fbff514..bb9c583 100644
--- a/src/main/java/de/ph87/homeautomation/property/PropertyDto.java
+++ b/src/main/java/de/ph87/homeautomation/property/PropertyDto.java
@@ -16,6 +16,8 @@ public final class PropertyDto implements Serializable {
private final String title;
+ private final String slug;
+
private final ChannelDto readChannel;
private final ChannelDto writeChannel;
@@ -26,6 +28,7 @@ public final class PropertyDto implements Serializable {
this.id = property.getId();
this.type = property.getType();
this.title = property.getTitle();
+ this.slug = property.getSlug();
this.readChannel = readChannel;
this.writeChannel = writeChannel;
this.usages = usages;
diff --git a/src/main/java/de/ph87/homeautomation/property/PropertyReader.java b/src/main/java/de/ph87/homeautomation/property/PropertyReader.java
index 1216e1d..7fa5e5f 100644
--- a/src/main/java/de/ph87/homeautomation/property/PropertyReader.java
+++ b/src/main/java/de/ph87/homeautomation/property/PropertyReader.java
@@ -1,5 +1,6 @@
package de.ph87.homeautomation.property;
+import de.ph87.homeautomation.web.NotFoundException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@@ -30,7 +31,11 @@ public class PropertyReader {
}
public Property getById(final long id) {
- return propertyRepository.findById(id).orElseThrow(RuntimeException::new);
+ return propertyRepository.findById(id).orElseThrow(() -> new NotFoundException("Property.id=%d", id));
+ }
+
+ public Property getBySlug(final String slug) {
+ return propertyRepository.findBySlug(slug).orElseThrow(() -> new NotFoundException("Property.slug=%s", slug));
}
public List |
|---|