Merge branch '102-scene-apply-button-in-hosts-view-does-not-work' into 'dev'
Resolve "Scene apply button in hosts view does not work" Closes #102 See merge request sa4-2020/the-sanmarinoes/frontend!138
This commit is contained in:
commit
122689c864
5 changed files with 27 additions and 6 deletions
|
@ -16,6 +16,13 @@ class HostsPanel extends Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
applyHostScene(id) {
|
||||||
|
this.props
|
||||||
|
.sceneApply(id, this.props.activeHost)
|
||||||
|
.then(() => console.log("SCCUESS"))
|
||||||
|
.catch((err) => console.error("sceneApply update error", err));
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
if (this.props.isActiveDefaultHost) {
|
if (this.props.isActiveDefaultHost) {
|
||||||
return (
|
return (
|
||||||
|
@ -46,9 +53,11 @@ class HostsPanel extends Component {
|
||||||
{scene.name} <Icon name={scene.icon} />
|
{scene.name} <Icon name={scene.icon} />
|
||||||
</Header>
|
</Header>
|
||||||
</Card.Header>
|
</Card.Header>
|
||||||
<Card.Content extras>
|
<Card.Content extras={true}>
|
||||||
<div className="ui two buttons">
|
<div className="ui two buttons">
|
||||||
<Button>Apply</Button>
|
<Button onClick={() => this.applyHostScene(scene.id)}>
|
||||||
|
Apply
|
||||||
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</Card.Content>
|
</Card.Content>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
|
@ -70,11 +70,12 @@ class Videocam extends Component {
|
||||||
/>
|
/>
|
||||||
</Grid.Column>
|
</Grid.Column>
|
||||||
</Grid.Row>
|
</Grid.Row>
|
||||||
<Grid.Row textAlign="center">
|
<Grid.Row>
|
||||||
<Grid.Column>
|
<Grid.Column>
|
||||||
<Checkbox
|
<Checkbox
|
||||||
checked={this.props.stateOrDevice.on}
|
checked={this.props.stateOrDevice.on}
|
||||||
toggle
|
toggle
|
||||||
|
label="Turn on/off"
|
||||||
onChange={(e, val) => this.setOnOff(val.checked)}
|
onChange={(e, val) => this.setOnOff(val.checked)}
|
||||||
/>
|
/>
|
||||||
</Grid.Column>
|
</Grid.Column>
|
||||||
|
|
|
@ -549,12 +549,21 @@ export const RemoteService = {
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
sceneApply: (id) => {
|
sceneApply: (id, hostId = null) => {
|
||||||
return (dispatch) => {
|
return (dispatch) => {
|
||||||
let url = `/scene/${id}/apply`;
|
let url = `/scene/${id}/apply`;
|
||||||
|
if (hostId) {
|
||||||
|
url = url + "?hostId=" + hostId;
|
||||||
|
}
|
||||||
|
|
||||||
return Endpoint.post(url)
|
return Endpoint.post(url)
|
||||||
.then((res) => dispatch(actions.deviceOperationUpdate(res.data)))
|
.then((res) =>
|
||||||
|
dispatch(
|
||||||
|
hostId
|
||||||
|
? actions.hostDevicesUpdate(hostId, res.data, true)
|
||||||
|
: actions.deviceOperationUpdate(res.data)
|
||||||
|
)
|
||||||
|
)
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.warn("scene apply error", err);
|
console.warn("scene apply error", err);
|
||||||
throw new RemoteError(["Network error"]);
|
throw new RemoteError(["Network error"]);
|
||||||
|
|
|
@ -49,6 +49,7 @@ function reducer(previousState, action) {
|
||||||
[scene.id]: {
|
[scene.id]: {
|
||||||
name: { $set: scene.name },
|
name: { $set: scene.name },
|
||||||
icon: { $set: scene.icon },
|
icon: { $set: scene.icon },
|
||||||
|
guestAccessEnabled: { $set: scene.guestAccessEnabled },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -63,9 +63,10 @@ const actions = {
|
||||||
devices,
|
devices,
|
||||||
partial,
|
partial,
|
||||||
}),
|
}),
|
||||||
hostDevicesUpdate: (hostId, devices) => ({
|
hostDevicesUpdate: (hostId, devices, partial = false) => ({
|
||||||
type: "HOST_DEVICES_UPDATE",
|
type: "HOST_DEVICES_UPDATE",
|
||||||
hostId,
|
hostId,
|
||||||
|
partial,
|
||||||
devices,
|
devices,
|
||||||
}),
|
}),
|
||||||
stateDelete: (stateId) => ({
|
stateDelete: (stateId) => ({
|
||||||
|
|
Loading…
Reference in a new issue