-
-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Scene: Add Pilot Wire Mode in trigger & device set value action (#2149)
- Loading branch information
1 parent
14151cc
commit d46ba5b
Showing
7 changed files
with
164 additions
and
2 deletions.
There are no files selected for viewing
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,62 @@ | ||
import { Component } from 'preact'; | ||
import { Text } from 'preact-i18n'; | ||
import Select from 'react-select'; | ||
import get from 'get-value'; | ||
|
||
import { PILOT_WIRE_MODE } from '../../../../server/utils/constants'; | ||
import withIntlAsProp from '../../utils/withIntlAsProp'; | ||
|
||
class SelectPilotWireMode extends Component { | ||
handleValueChange = ({ value }) => { | ||
this.props.updateValue(value); | ||
}; | ||
|
||
getOptions = () => { | ||
const deviceFeatureOptions = Object.keys(PILOT_WIRE_MODE).map(key => { | ||
const value = PILOT_WIRE_MODE[key]; | ||
return { | ||
label: get(this.props.intl.dictionary, `deviceFeatureValue.category.heater.pilot-wire-mode.${value}`, { | ||
default: value | ||
}), | ||
value | ||
}; | ||
}); | ||
|
||
this.setState({ deviceFeatureOptions }); | ||
}; | ||
|
||
getSelectedOption = () => { | ||
const value = this.props.value; | ||
|
||
if (value !== undefined) { | ||
return { | ||
label: get(this.props.intl.dictionary, `deviceFeatureValue.category.heater.pilot-wire-mode.${value}`, { | ||
default: value | ||
}), | ||
value | ||
}; | ||
} else { | ||
return; | ||
} | ||
}; | ||
|
||
componentDidMount() { | ||
this.getOptions(); | ||
} | ||
|
||
render(props, { deviceFeatureOptions }) { | ||
const selectedOption = this.getSelectedOption(); | ||
return ( | ||
<Select | ||
class="select-device-feature" | ||
defaultValue={''} | ||
value={selectedOption} | ||
onChange={this.handleValueChange} | ||
options={deviceFeatureOptions} | ||
placeholder={<Text id="global.selectPlaceholder" />} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
export default withIntlAsProp(SelectPilotWireMode); |
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
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
53 changes: 53 additions & 0 deletions
53
front/src/routes/scene/edit-scene/triggers/device-states/PilotWireModeDeviceState.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,53 @@ | ||
import { Component, Fragment } from 'preact'; | ||
import Select from 'react-select'; | ||
import get from 'get-value'; | ||
|
||
import { PILOT_WIRE_MODE } from '../../../../../../../server/utils/constants'; | ||
import withIntlAsProp from '../../../../../utils/withIntlAsProp'; | ||
|
||
class PilotWireModeDeviceState extends Component { | ||
handleValueChange = ({ value }) => { | ||
this.props.updateTriggerProperty(this.props.index, 'value', value); | ||
}; | ||
|
||
getOptions = () => { | ||
const options = Object.keys(PILOT_WIRE_MODE).map(key => { | ||
const value = PILOT_WIRE_MODE[key]; | ||
return { | ||
label: get(this.props.intl.dictionary, `deviceFeatureValue.category.heater.pilot-wire-mode.${value}`, { | ||
default: value | ||
}), | ||
value | ||
}; | ||
}); | ||
|
||
this.setState({ options }); | ||
}; | ||
|
||
componentWillMount() { | ||
this.props.updateTriggerProperty(this.props.index, 'operator', '='); | ||
|
||
this.getOptions(); | ||
} | ||
|
||
render({ trigger }, { options }) { | ||
const defaultValue = options.find(option => trigger.value === option.value); | ||
|
||
return ( | ||
<Fragment> | ||
<div class="col-2 col-md-1"> | ||
<div class="text-center" style={{ marginTop: '10px' }}> | ||
<i class="fe fe-arrow-right" style={{ fontSize: '20px' }} /> | ||
</div> | ||
</div> | ||
<div class="col-10 col-md-5"> | ||
<div class="form-group"> | ||
<Select defaultValue={defaultValue || ''} onChange={this.handleValueChange} options={options} /> | ||
</div> | ||
</div> | ||
</Fragment> | ||
); | ||
} | ||
} | ||
|
||
export default withIntlAsProp(PilotWireModeDeviceState); |