Commit 6acaf007 authored by Laura Fuentes Grau's avatar Laura Fuentes Grau

NumberInput, Button and Slider now keep their value after changing to layout mode or back

parent f23bdcff
...@@ -262,6 +262,16 @@ class Dashboard extends Component { ...@@ -262,6 +262,16 @@ class Dashboard extends Component {
startEditing(){ startEditing(){
this.state.widgets.forEach( widget => {
if(widget.type === 'Slider' || widget.type === 'NumberInput' || widget.type === 'Button'){
console.log("we should move in here");
AppDispatcher.dispatch({
type: 'widgets/start-edit',
token: this.state.sessionToken,
data: widget
});
}
});
this.setState({ editing: true }); this.setState({ editing: true });
}; };
......
...@@ -134,6 +134,7 @@ class WidgetFactory { ...@@ -134,6 +134,7 @@ class WidgetFactory {
widget.customProperties.on_value = 1; widget.customProperties.on_value = 1;
widget.customProperties.off_value = 0; widget.customProperties.off_value = 0;
widget.customProperties.toggle = false; widget.customProperties.toggle = false;
widget.customProperties.pressed = false;
break; break;
case 'NumberInput': case 'NumberInput':
widget.minWidth = 150; widget.minWidth = 150;
...@@ -142,6 +143,7 @@ class WidgetFactory { ...@@ -142,6 +143,7 @@ class WidgetFactory {
widget.height = 50; widget.height = 50;
widget.customProperties.showUnit = false; widget.customProperties.showUnit = false;
widget.customProperties.resizeTopBottomLock = true; widget.customProperties.resizeTopBottomLock = true;
widget.customProperties.value = '';
break; break;
case 'Slider': case 'Slider':
widget.minWidth = 380; widget.minWidth = 380;
...@@ -154,7 +156,8 @@ class WidgetFactory { ...@@ -154,7 +156,8 @@ class WidgetFactory {
widget.customProperties.rangeUseMinMax = true; widget.customProperties.rangeUseMinMax = true;
widget.customProperties.showUnit = true; widget.customProperties.showUnit = true;
widget.customProperties.continous_update = false; widget.customProperties.continous_update = false;
widget.customProperties.default_value = 0; widget.customProperties.default_value = '0';
widget.customProperties.value = '';
widget.customProperties.resizeLeftRightLock = false; widget.customProperties.resizeLeftRightLock = false;
widget.customProperties.resizeTopBottomLock = true; widget.customProperties.resizeTopBottomLock = true;
......
...@@ -24,12 +24,12 @@ class WidgetButton extends Component { ...@@ -24,12 +24,12 @@ class WidgetButton extends Component {
super(props); super(props);
this.state = { this.state = {
pressed: false pressed: props.widget.customProperties.pressed
} }
} }
onPress(e) { onPress(e) {
console.log("button was pressed!");
if (!this.props.widget.customProperties.toggle) { if (!this.props.widget.customProperties.toggle) {
this.setState({ pressed: true }); this.setState({ pressed: true });
this.valueChanged(this.props.widget.customProperties.on_value); this.valueChanged(this.props.widget.customProperties.on_value);
...@@ -37,12 +37,12 @@ class WidgetButton extends Component { ...@@ -37,12 +37,12 @@ class WidgetButton extends Component {
} }
onRelease(e) { onRelease(e) {
console.log("button was released!");
let nextState = false; let nextState = false;
if (this.props.widget.customProperties.toggle) { if (this.props.widget.customProperties.toggle) {
nextState = !this.state.pressed; nextState = !this.state.pressed;
} }
this.props.widget.customProperties.pressed = nextState;
this.setState({ 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);
} }
......
...@@ -31,14 +31,27 @@ class WidgetInput extends Component { ...@@ -31,14 +31,27 @@ class WidgetInput extends Component {
static getDerivedStateFromProps(props, state){ static getDerivedStateFromProps(props, state){
if(props.widget.signalIDs.length === 0){ let returnState = {};
return null;
if(props.widget.customProperties.value !== ''){
returnState["value"] = props.widget.customProperties.value;
} }
let returnState = {}; if(props.widget.signalIDs.length === 0){
if (props.widget.customProperties.default_value && state.value === undefined && props.widget.customProperties.value === '') {
returnState["value"] = props.widget.customProperties.default_value;
} else { // if no default available
if (returnState !== {}){
return returnState;
}
else{
return null;
}
}
}
// Update value // Update value
if (props.widget.customProperties.default_value && this.state.value === undefined) { if (props.widget.customProperties.default_value && this.state.value === undefined && props.widget.customProperties.value === '') {
returnState["value"] = props.widget.customProperties.default_value; returnState["value"] = props.widget.customProperties.default_value;
} }
...@@ -59,6 +72,7 @@ class WidgetInput extends Component { ...@@ -59,6 +72,7 @@ class WidgetInput extends Component {
valueIsChanging(newValue) { valueIsChanging(newValue) {
this.setState({ value: newValue }); this.setState({ value: newValue });
this.props.widget.customProperties.value = newValue;
} }
valueChanged(newValue) { valueChanged(newValue) {
......
...@@ -42,19 +42,28 @@ class WidgetSlider extends Component { ...@@ -42,19 +42,28 @@ class WidgetSlider extends Component {
static getDerivedStateFromProps(props, state){ static getDerivedStateFromProps(props, state){
let returnState = {}; let returnState = {};
if(props.widget.customProperties.value !== ''){
returnState["value"] = props.widget.customProperties.value;
}
if(props.widget.signalIDs.length === 0){ if(props.widget.signalIDs.length === 0){
// set value to default // set value to default
if (props.widget.customProperties.default_value && state.value === undefined) { if (props.widget.customProperties.default_value && state.value === undefined && props.widget.customProperties.value === '') {
returnState["value"] = props.widget.customProperties.default_value; returnState["value"] = props.widget.customProperties.default_value;
} else { // if no default available } else { // if no default available
return null; if (returnState !== {}){
return returnState;
}
else{
return null;
}
} }
} }
// Update value // Update value
if (props.widget.customProperties.default_value && state.value === undefined) { if (props.widget.customProperties.default_value && state.value === undefined && props.widget.customProperties.value === '') {
returnState["value"] = props.widget.customProperties.default_value; returnState["value"] = props.widget.customProperties.default_value;
} }
...@@ -96,6 +105,7 @@ class WidgetSlider extends Component { ...@@ -96,6 +105,7 @@ class WidgetSlider extends Component {
} }
valueIsChanging(newValue) { valueIsChanging(newValue) {
this.props.widget.customProperties.value = newValue;
if (this.props.widget.continous_update) if (this.props.widget.continous_update)
this.valueChanged(newValue); this.valueChanged(newValue);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment