-
-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First version of improved Z-Wave integration UI
- Loading branch information
1 parent
5bf6928
commit 4281c50
Showing
24 changed files
with
532 additions
and
180 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
front/src/routes/integration/all/zwave/node-operation-page/AddRemoveNode.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Text } from 'preact-i18n'; | ||
|
||
const AddNode = ({ children, ...props }) => ( | ||
<div class="card"> | ||
<div class="card-header"> | ||
<h3 class="card-title"> | ||
{props.action === 'remove' ? ( | ||
<Text id="integration.zwave.nodeOperation.removeNodeTitle" /> | ||
) : ( | ||
<Text id="integration.zwave.nodeOperation.addNodeTitle" /> | ||
)} | ||
</h3> | ||
<div class="card-options"> | ||
<button class="btn btn-danger" onClick={props.cancel}> | ||
<Text id="integration.zwave.nodeOperation.cancelButton" /> | ||
</button> | ||
</div> | ||
</div> | ||
<div class="card-body"> | ||
<div class="text-center"> | ||
<h1> | ||
{props.remainingTimeInSeconds} <Text id="integration.zwave.nodeOperation.seconds" /> | ||
</h1> | ||
<p> | ||
{props.action === 'remove' ? ( | ||
<Text id="integration.zwave.nodeOperation.removeNodeInstructions" /> | ||
) : ( | ||
<Text id="integration.zwave.nodeOperation.addNodeInstructions" /> | ||
)} | ||
</p> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
|
||
export default AddNode; |
63 changes: 63 additions & 0 deletions
63
front/src/routes/integration/all/zwave/node-operation-page/actions.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { RequestStatus } from '../../../../../utils/consts'; | ||
|
||
const actions = store => { | ||
const actions = { | ||
async addNode(state, e, secure = false) { | ||
if (e) { | ||
e.preventDefault(); | ||
} | ||
store.setState({ | ||
zwaveAddNodeStatus: RequestStatus.Getting | ||
}); | ||
try { | ||
await state.httpClient.post('/api/v1/service/zwave/node/add', { | ||
secure | ||
}); | ||
store.setState({ | ||
zwaveAddNodeStatus: RequestStatus.Success | ||
}); | ||
} catch (e) { | ||
store.setState({ | ||
zwaveAddNodeStatus: RequestStatus.Error | ||
}); | ||
} | ||
}, | ||
async addNodeSecure(state, e) { | ||
actions.addNode(state, e, true); | ||
}, | ||
async cancelZwaveCommand(state) { | ||
store.setState({ | ||
zwaveCancelZwaveCommandStatus: RequestStatus.Getting | ||
}); | ||
try { | ||
await state.httpClient.post('/api/v1/service/zwave/cancel'); | ||
store.setState({ | ||
zwaveCancelZwaveCommandStatus: RequestStatus.Success | ||
}); | ||
} catch (e) { | ||
store.setState({ | ||
zwaveCancelZwaveCommandStatus: RequestStatus.Error | ||
}); | ||
} | ||
}, | ||
async removeNode(state, secure = false) { | ||
store.setState({ | ||
zwaveRemoveNodeStatus: RequestStatus.Getting | ||
}); | ||
try { | ||
await state.httpClient.post('/api/v1/service/zwave/node/remove'); | ||
store.setState({ | ||
zwaveRemoveNodeStatus: RequestStatus.Success | ||
}); | ||
} catch (e) { | ||
store.setState({ | ||
zwaveRemoveNodeStatus: RequestStatus.Error | ||
}); | ||
} | ||
} | ||
}; | ||
|
||
return actions; | ||
}; | ||
|
||
export default actions; |
65 changes: 65 additions & 0 deletions
65
front/src/routes/integration/all/zwave/node-operation-page/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { Component } from 'preact'; | ||
import { connect } from 'unistore/preact'; | ||
import { route } from 'preact-router'; | ||
import actions from './actions'; | ||
import ZwavePage from '../ZwavePage'; | ||
import NodeOperationPage from './AddRemoveNode'; | ||
|
||
@connect('session,user,zwaveDevices,houses,getZwaveDevicesStatus', actions) | ||
class ZwaveNodeOperationPage extends Component { | ||
decrementTimer = () => { | ||
this.setState(prevState => { | ||
return { remainingTimeInSeconds: prevState.remainingTimeInSeconds - 1 }; | ||
}); | ||
if (this.state.remainingTimeInSeconds > 1) { | ||
setTimeout(this.decrementTimer, 1000); | ||
} else { | ||
route('/dashboard/integration/device/zwave/setup'); | ||
} | ||
}; | ||
addNode = () => { | ||
this.props.addNode(); | ||
setTimeout(this.decrementTimer, 1000); | ||
}; | ||
addNodeSecure = () => { | ||
this.props.addNodeSecure(); | ||
setTimeout(this.decrementTimer, 1000); | ||
}; | ||
removeNode = () => { | ||
this.props.removeNode(); | ||
setTimeout(this.decrementTimer, 1000); | ||
}; | ||
cancel = () => { | ||
this.props.cancelZwaveCommand(); | ||
route('/dashboard/integration/device/zwave/setup'); | ||
}; | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
remainingTimeInSeconds: 60 | ||
}; | ||
} | ||
componentWillMount() { | ||
switch (this.props.action) { | ||
case 'add': | ||
this.addNode(); | ||
break; | ||
case 'add-secure': | ||
this.addNodeSecure(); | ||
break; | ||
case 'remove': | ||
this.removeNode(); | ||
break; | ||
} | ||
} | ||
|
||
render(props, { remainingTimeInSeconds }) { | ||
return ( | ||
<ZwavePage> | ||
<NodeOperationPage {...props} remainingTimeInSeconds={remainingTimeInSeconds} cancel={this.cancel} /> | ||
</ZwavePage> | ||
); | ||
} | ||
} | ||
|
||
export default ZwaveNodeOperationPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 33 additions & 4 deletions
37
front/src/routes/integration/all/zwave/settings-page/SettingsTab.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.