UI: Create + Modify Property
This commit is contained in:
parent
de95a6aed1
commit
644e6ed213
@ -36,4 +36,8 @@ export class PropertyService implements ISearchService {
|
|||||||
this.api.postReturnItem("property/set/" + property.id + "/" + key, value, Property.fromJson, next, error);
|
this.api.postReturnItem("property/set/" + property.id + "/" + key, value, Property.fromJson, next, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
create(next: (item: Property) => void, error: (error: any) => void = NO_OP): void {
|
||||||
|
this.api.getItem("property/create/", Property.fromJson, next, error);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -69,8 +69,3 @@
|
|||||||
.shutterUnknown {
|
.shutterUnknown {
|
||||||
background-color: gray;
|
background-color: gray;
|
||||||
}
|
}
|
||||||
|
|
||||||
.config {
|
|
||||||
clear: both;
|
|
||||||
margin-bottom: 5px;
|
|
||||||
}
|
|
||||||
|
|||||||
@ -2,6 +2,10 @@
|
|||||||
<td class="empty">-</td>
|
<td class="empty">-</td>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
|
|
||||||
|
<div class="config">
|
||||||
|
<button (click)="create()">+ Hinzufügen</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Bezeichnung</th>
|
<th>Bezeichnung</th>
|
||||||
|
|||||||
@ -73,7 +73,11 @@ export class PropertyListComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
set(property: Property, key: string, value: any): void {
|
set(property: Property, key: string, value: any): void {
|
||||||
|
this.propertyService.set(property, key, value, property => this.updateProperty(property, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
create(): void {
|
||||||
|
this.propertyService.create(property => this.updateProperty(property, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -106,3 +106,7 @@ table.vertical {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.config {
|
||||||
|
clear: both;
|
||||||
|
margin-bottom: 5px;
|
||||||
|
}
|
||||||
|
|||||||
@ -4,4 +4,6 @@ import org.springframework.data.repository.CrudRepository;
|
|||||||
|
|
||||||
public interface ChannelRepository extends CrudRepository<Channel, Long> {
|
public interface ChannelRepository extends CrudRepository<Channel, Long> {
|
||||||
|
|
||||||
|
Channel getById(long id);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -60,4 +60,8 @@ public class ChannelService {
|
|||||||
return channelRepository.findById(id).map(this::toDto);
|
return channelRepository.findById(id).map(this::toDto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Channel getById(final long id) {
|
||||||
|
return channelRepository.getById(id);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static de.ph87.homeautomation.shared.Helpers.mapIfNotNull;
|
import static de.ph87.homeautomation.shared.Helpers.mapOrNull;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("device")
|
@RequestMapping("device")
|
||||||
@ -53,22 +53,22 @@ public class DeviceController {
|
|||||||
|
|
||||||
@PostMapping("set/{id}/DeviceSwitch/stateProperty")
|
@PostMapping("set/{id}/DeviceSwitch/stateProperty")
|
||||||
public DeviceDto setDeviceSwitchStateProperty(@PathVariable final long id, @RequestBody(required = false) final Long propertyId) {
|
public DeviceDto setDeviceSwitchStateProperty(@PathVariable final long id, @RequestBody(required = false) final Long propertyId) {
|
||||||
return deviceWriteService.setDeviceSwitch(id, (device, v) -> device.setStateProperty(mapIfNotNull(v, propertyReadService::getById)), propertyId);
|
return deviceWriteService.setDeviceSwitch(id, (device, v) -> device.setStateProperty(mapOrNull(v, propertyReadService::getById)), propertyId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("set/{id}/DeviceStateScene/stateProperty")
|
@PostMapping("set/{id}/DeviceStateScene/stateProperty")
|
||||||
public DeviceDto setDeviceStateSceneStateProperty(@PathVariable final long id, @RequestBody(required = false) final Long propertyId) {
|
public DeviceDto setDeviceStateSceneStateProperty(@PathVariable final long id, @RequestBody(required = false) final Long propertyId) {
|
||||||
return deviceWriteService.setDeviceStateScene(id, (device, v) -> device.setStateProperty(mapIfNotNull(v, propertyReadService::getById)), propertyId);
|
return deviceWriteService.setDeviceStateScene(id, (device, v) -> device.setStateProperty(mapOrNull(v, propertyReadService::getById)), propertyId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("set/{id}/DeviceStateScene/sceneProperty")
|
@PostMapping("set/{id}/DeviceStateScene/sceneProperty")
|
||||||
public DeviceDto setDeviceStateSceneSceneProperty(@PathVariable final long id, @RequestBody(required = false) final Long propertyId) {
|
public DeviceDto setDeviceStateSceneSceneProperty(@PathVariable final long id, @RequestBody(required = false) final Long propertyId) {
|
||||||
return deviceWriteService.setDeviceStateScene(id, (device, v) -> device.setSceneProperty(mapIfNotNull(v, propertyReadService::getById)), propertyId);
|
return deviceWriteService.setDeviceStateScene(id, (device, v) -> device.setSceneProperty(mapOrNull(v, propertyReadService::getById)), propertyId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("set/{id}/DeviceShutter/positionProperty")
|
@PostMapping("set/{id}/DeviceShutter/positionProperty")
|
||||||
public DeviceDto setDeviceShutterPositionProperty(@PathVariable final long id, @RequestBody(required = false) final Long propertyId) {
|
public DeviceDto setDeviceShutterPositionProperty(@PathVariable final long id, @RequestBody(required = false) final Long propertyId) {
|
||||||
return deviceWriteService.setDeviceShutter(id, (device, v) -> device.setPositionProperty(mapIfNotNull(v, propertyReadService::getById)), propertyId);
|
return deviceWriteService.setDeviceShutter(id, (device, v) -> device.setPositionProperty(mapOrNull(v, propertyReadService::getById)), propertyId);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,7 +11,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static de.ph87.homeautomation.shared.Helpers.mapIfNotNull;
|
import static de.ph87.homeautomation.shared.Helpers.mapOrNull;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@ -30,13 +30,13 @@ public class DeviceReadService {
|
|||||||
public DeviceDto toDto(final Device device) {
|
public DeviceDto toDto(final Device device) {
|
||||||
if (device instanceof DeviceSwitch) {
|
if (device instanceof DeviceSwitch) {
|
||||||
final DeviceSwitch deviceSwitch = (DeviceSwitch) device;
|
final DeviceSwitch deviceSwitch = (DeviceSwitch) device;
|
||||||
return new DeviceSwitchDto(deviceSwitch, mapIfNotNull(deviceSwitch.getStateProperty(), propertyMapper::toDto));
|
return new DeviceSwitchDto(deviceSwitch, mapOrNull(deviceSwitch.getStateProperty(), propertyMapper::toDto));
|
||||||
} else if (device instanceof DeviceStateScene) {
|
} else if (device instanceof DeviceStateScene) {
|
||||||
final DeviceStateScene deviceStateScene = (DeviceStateScene) device;
|
final DeviceStateScene deviceStateScene = (DeviceStateScene) device;
|
||||||
return new DeviceStateSceneDto(deviceStateScene, mapIfNotNull(deviceStateScene.getStateProperty(), propertyMapper::toDto), mapIfNotNull(deviceStateScene.getSceneProperty(), propertyMapper::toDto));
|
return new DeviceStateSceneDto(deviceStateScene, mapOrNull(deviceStateScene.getStateProperty(), propertyMapper::toDto), mapOrNull(deviceStateScene.getSceneProperty(), propertyMapper::toDto));
|
||||||
} else if (device instanceof DeviceShutter) {
|
} else if (device instanceof DeviceShutter) {
|
||||||
final DeviceShutter deviceShutter = (DeviceShutter) device;
|
final DeviceShutter deviceShutter = (DeviceShutter) device;
|
||||||
return new DeviceShutterDto(deviceShutter, mapIfNotNull(deviceShutter.getPositionProperty(), propertyMapper::toDto));
|
return new DeviceShutterDto(deviceShutter, mapOrNull(deviceShutter.getPositionProperty(), propertyMapper::toDto));
|
||||||
}
|
}
|
||||||
throw new RuntimeException();
|
throw new RuntimeException();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package de.ph87.homeautomation.property;
|
package de.ph87.homeautomation.property;
|
||||||
|
|
||||||
|
import de.ph87.homeautomation.channel.ChannelService;
|
||||||
import de.ph87.homeautomation.shared.ISearchController;
|
import de.ph87.homeautomation.shared.ISearchController;
|
||||||
import de.ph87.homeautomation.shared.SearchResult;
|
import de.ph87.homeautomation.shared.SearchResult;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@ -17,6 +18,13 @@ public class PropertyController implements ISearchController {
|
|||||||
|
|
||||||
private final PropertyReadService propertyReadService;
|
private final PropertyReadService propertyReadService;
|
||||||
|
|
||||||
|
private final ChannelService channelService;
|
||||||
|
|
||||||
|
@GetMapping("create")
|
||||||
|
public PropertyDto create() {
|
||||||
|
return propertyWriteService.create();
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("findAll")
|
@GetMapping("findAll")
|
||||||
public List<PropertyDto> findAll() {
|
public List<PropertyDto> findAll() {
|
||||||
return propertyReadService.findAllDto();
|
return propertyReadService.findAllDto();
|
||||||
@ -37,6 +45,16 @@ public class PropertyController implements ISearchController {
|
|||||||
return propertyWriteService.set(id, propertyWriteService::write, value);
|
return propertyWriteService.set(id, propertyWriteService::write, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("set/{id}/readChannel")
|
||||||
|
public PropertyDto setReadChannel(@PathVariable final long id, @RequestBody(required = false) final Long channelId) {
|
||||||
|
return propertyWriteService.set(id, Property::setReadChannel, channelService.getById(channelId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("set/{id}/writeChannel")
|
||||||
|
public PropertyDto setWriteChannel(@PathVariable final long id, @RequestBody(required = false) final Long channelId) {
|
||||||
|
return propertyWriteService.set(id, Property::setWriteChannel, channelService.getById(channelId));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@GetMapping("getById/{id}")
|
@GetMapping("getById/{id}")
|
||||||
public SearchResult getById(@PathVariable final long id) {
|
public SearchResult getById(@PathVariable final long id) {
|
||||||
|
|||||||
@ -47,9 +47,10 @@ public class PropertyWriteService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public PropertyDto create() {
|
public PropertyDto create() {
|
||||||
final Property entry = new Property();
|
final Property property = new Property();
|
||||||
entry.setTitle(generateUnusedTitle());
|
property.setTitle(generateUnusedTitle());
|
||||||
return publish(propertyRepository.save(entry), true);
|
property.setType(PropertyType.BOOLEAN);
|
||||||
|
return publish(propertyRepository.save(property), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String generateUnusedTitle() {
|
private String generateUnusedTitle() {
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static de.ph87.homeautomation.shared.Helpers.mapIfNotNull;
|
import static de.ph87.homeautomation.shared.Helpers.mapOrNull;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("schedule")
|
@RequestMapping("schedule")
|
||||||
@ -51,7 +51,7 @@ public class ScheduleController {
|
|||||||
|
|
||||||
@PostMapping("set/{id}/property")
|
@PostMapping("set/{id}/property")
|
||||||
public ScheduleDto setPropertyName(@PathVariable final long id, @RequestBody(required = false) final Long propertyId) {
|
public ScheduleDto setPropertyName(@PathVariable final long id, @RequestBody(required = false) final Long propertyId) {
|
||||||
return scheduleWriteService.set(id, (schedule, v) -> schedule.setProperty(mapIfNotNull(v, propertyReadService::getById)), propertyId);
|
return scheduleWriteService.set(id, Schedule::setProperty, mapOrNull(propertyId, propertyReadService::getById));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import static de.ph87.homeautomation.shared.Helpers.mapIfNotNull;
|
import static de.ph87.homeautomation.shared.Helpers.mapOrNull;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@ -17,7 +17,7 @@ public class ScheduleMapper {
|
|||||||
private final PropertyMapper propertyMapper;
|
private final PropertyMapper propertyMapper;
|
||||||
|
|
||||||
public ScheduleDto toDto(final Schedule schedule) {
|
public ScheduleDto toDto(final Schedule schedule) {
|
||||||
return new ScheduleDto(schedule, mapIfNotNull(schedule.getProperty(), propertyMapper::toDto));
|
return new ScheduleDto(schedule, mapOrNull(schedule.getProperty(), propertyMapper::toDto));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,7 +21,7 @@ public class Helpers {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T, U> U mapIfNotNull(final T value, final Function<T, U> map) {
|
public static <T, U> U mapOrNull(final T value, final Function<T, U> map) {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user