mirror of
https://git.rwth-aachen.de/acs/public/villas/web/
synced 2025-03-09 00:00:01 +01:00
Input widgets (button, number input, slider) consider scaling factor of signal #130 , fix for widget parameter update upon signal value change
This commit is contained in:
parent
ec99815eb1
commit
547d6c3877
4 changed files with 20 additions and 16 deletions
|
@ -88,13 +88,13 @@ class Widget extends React.Component {
|
|||
};
|
||||
}
|
||||
|
||||
inputDataChanged(widget, data, controlID) {
|
||||
inputDataChanged(widget, data, controlID, controlValue) {
|
||||
// controlID is the path to the widget customProperty that is changed (for example 'value')
|
||||
|
||||
// modify the widget customProperty
|
||||
if (controlID !== '') {
|
||||
let updatedWidget = JSON.parse(JSON.stringify(widget));
|
||||
updatedWidget.customProperties[controlID] = data;
|
||||
updatedWidget.customProperties[controlID] = controlValue;
|
||||
AppDispatcher.dispatch({
|
||||
type: 'widgets/start-edit',
|
||||
token: this.state.sessionToken,
|
||||
|
@ -118,7 +118,7 @@ class Widget extends React.Component {
|
|||
type: 'icData/inputChanged',
|
||||
ic: icID,
|
||||
signal: signal[0].index,
|
||||
data
|
||||
data: signal[0].scalingFactor * data
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -179,14 +179,14 @@ class Widget extends React.Component {
|
|||
return <WidgetButton
|
||||
widget={widget}
|
||||
editing={this.props.editing}
|
||||
onInputChanged={(value, controlID) => this.inputDataChanged(widget, value, controlID)}
|
||||
onInputChanged={(value, controlID, controlValue) => this.inputDataChanged(widget, value, controlID, controlValue)}
|
||||
signals={this.state.signals}
|
||||
/>
|
||||
} else if (widget.type === 'NumberInput') {
|
||||
return <WidgetInput
|
||||
widget={widget}
|
||||
editing={this.props.editing}
|
||||
onInputChanged={(value, controlID) => this.inputDataChanged(widget, value, controlID)}
|
||||
onInputChanged={(value, controlID, controlValue) => this.inputDataChanged(widget, value, controlID, controlValue)}
|
||||
signals={this.state.signals}
|
||||
/>
|
||||
} else if (widget.type === 'Slider') {
|
||||
|
@ -194,7 +194,7 @@ class Widget extends React.Component {
|
|||
widget={widget}
|
||||
editing={this.props.editing}
|
||||
onWidgetChange={(w) => this.props.onWidgetStatusChange(w, this.props.index) }
|
||||
onInputChanged={(value, controlID) => this.inputDataChanged(widget, value, controlID)}
|
||||
onInputChanged={(value, controlID, controlValue) => this.inputDataChanged(widget, value, controlID, controlValue)}
|
||||
signals={this.state.signals}
|
||||
/>
|
||||
} else if (widget.type === 'Gauge') {
|
||||
|
|
|
@ -28,11 +28,16 @@ class WidgetButton extends Component {
|
|||
}
|
||||
}
|
||||
|
||||
static getDerivedStateFromProps(props, state){
|
||||
return {
|
||||
pressed: props.widget.customProperties.pressed
|
||||
}
|
||||
}
|
||||
|
||||
onPress(e) {
|
||||
|
||||
if (e.button === 0 && !this.props.widget.customProperties.toggle) {
|
||||
this.setState({ pressed: true });
|
||||
this.valueChanged(this.props.widget.customProperties.on_value);
|
||||
this.valueChanged(this.props.widget.customProperties.on_value, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,15 +48,14 @@ class WidgetButton extends Component {
|
|||
if (this.props.widget.customProperties.toggle) {
|
||||
nextState = !this.state.pressed;
|
||||
}
|
||||
this.props.widget.customProperties.pressed = nextState;
|
||||
this.setState({pressed: nextState});
|
||||
this.valueChanged(nextState ? this.props.widget.customProperties.on_value : this.props.widget.customProperties.off_value);
|
||||
this.valueChanged(nextState ? this.props.widget.customProperties.on_value : this.props.widget.customProperties.off_value, nextState);
|
||||
}
|
||||
}
|
||||
|
||||
valueChanged(newValue) {
|
||||
if (this.props.onInputChanged)
|
||||
this.props.onInputChanged(newValue, 'pressed');
|
||||
valueChanged(newValue, pressed) {
|
||||
if (this.props.onInputChanged) {
|
||||
this.props.onInputChanged(newValue, 'pressed', pressed);
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
|
|
|
@ -71,7 +71,7 @@ class WidgetInput extends Component {
|
|||
|
||||
valueChanged(newValue) {
|
||||
if (this.props.onInputChanged) {
|
||||
this.props.onInputChanged(Number(newValue), 'value');
|
||||
this.props.onInputChanged(Number(newValue), 'value', Number(newValue));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -105,7 +105,7 @@ class WidgetSlider extends Component {
|
|||
|
||||
valueChanged(newValue) {
|
||||
if (this.props.onInputChanged) {
|
||||
this.props.onInputChanged(newValue, 'value');
|
||||
this.props.onInputChanged(newValue, 'value', newValue);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue