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 {
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 });
};
......
......@@ -134,6 +134,7 @@ class WidgetFactory {
widget.customProperties.on_value = 1;
widget.customProperties.off_value = 0;
widget.customProperties.toggle = false;
widget.customProperties.pressed = false;
break;
case 'NumberInput':
widget.minWidth = 150;
......@@ -142,6 +143,7 @@ class WidgetFactory {
widget.height = 50;
widget.customProperties.showUnit = false;
widget.customProperties.resizeTopBottomLock = true;
widget.customProperties.value = '';
break;
case 'Slider':
widget.minWidth = 380;
......@@ -154,7 +156,8 @@ class WidgetFactory {
widget.customProperties.rangeUseMinMax = true;
widget.customProperties.showUnit = true;
widget.customProperties.continous_update = false;
widget.customProperties.default_value = 0;
widget.customProperties.default_value = '0';
widget.customProperties.value = '';
widget.customProperties.resizeLeftRightLock = false;
widget.customProperties.resizeTopBottomLock = true;
......
......@@ -24,12 +24,12 @@ class WidgetButton extends Component {
super(props);
this.state = {
pressed: false
pressed: props.widget.customProperties.pressed
}
}
onPress(e) {
console.log("button was pressed!");
if (!this.props.widget.customProperties.toggle) {
this.setState({ pressed: true });
this.valueChanged(this.props.widget.customProperties.on_value);
......@@ -37,12 +37,12 @@ class WidgetButton extends Component {
}
onRelease(e) {
console.log("button was released!");
let nextState = false;
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);
}
......
......@@ -31,14 +31,27 @@ class WidgetInput extends Component {
static getDerivedStateFromProps(props, state){
if(props.widget.signalIDs.length === 0){
return null;
let returnState = {};
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
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;
}
......@@ -59,6 +72,7 @@ class WidgetInput extends Component {
valueIsChanging(newValue) {
this.setState({ value: newValue });
this.props.widget.customProperties.value = newValue;
}
valueChanged(newValue) {
......
......@@ -42,19 +42,28 @@ class WidgetSlider extends Component {
static getDerivedStateFromProps(props, state){
let returnState = {};
if(props.widget.customProperties.value !== ''){
returnState["value"] = props.widget.customProperties.value;
}
if(props.widget.signalIDs.length === 0){
// 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;
} else { // if no default available
return null;
if (returnState !== {}){
return returnState;
}
else{
return null;
}
}
}
// 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;
}
......@@ -96,6 +105,7 @@ class WidgetSlider extends Component {
}
valueIsChanging(newValue) {
this.props.widget.customProperties.value = newValue;
if (this.props.widget.continous_update)
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