From cf05ab9564c578ce05d33cb48fec9cc14a33969b Mon Sep 17 00:00:00 2001 From: Laura Fuentes Grau Date: Sun, 6 Dec 2020 14:28:08 +0100 Subject: [PATCH] Time Offset Widget: IC now changeable #208 --- src/dashboard/dashboard.js | 1 + src/styles/widgets.css | 3 +- .../edit-widget-control-creator.js | 4 +- .../edit-widget/edit-widget-ic-control.js | 74 +++++++++++++++++++ src/widget/edit-widget/edit-widget.js | 3 +- src/widget/widget-factory.js | 7 +- src/widget/widgets/time-offset.js | 11 +-- 7 files changed, 91 insertions(+), 12 deletions(-) create mode 100644 src/widget/edit-widget/edit-widget-ic-control.js diff --git a/src/dashboard/dashboard.js b/src/dashboard/dashboard.js index 19bfd36..56b9880 100644 --- a/src/dashboard/dashboard.js +++ b/src/dashboard/dashboard.js @@ -557,6 +557,7 @@ class Dashboard extends Component { widget={this.state.modalData} signals={this.state.signals} files={this.state.files} + ics={this.state.ics} /> handleChange(e)}/>, handleChange(e)} />, handleChange(e)} />, handleChange(e)} />, diff --git a/src/widget/edit-widget/edit-widget-ic-control.js b/src/widget/edit-widget/edit-widget-ic-control.js new file mode 100644 index 0000000..7e90f81 --- /dev/null +++ b/src/widget/edit-widget/edit-widget-ic-control.js @@ -0,0 +1,74 @@ +/** + * This file is part of VILLASweb. + * + * VILLASweb is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * VILLASweb is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with VILLASweb. If not, see . + ******************************************************************************/ + +import React from 'react'; +import {FormGroup, FormControl, FormLabel} from 'react-bootstrap'; + +class EditWidgetICControl extends React.Component { + + constructor(props) { + super(props); + + this.state = { + ics: [], + }; + } + + static getDerivedStateFromProps(props, state){ + return { + ics: props.ics + }; + } + + handleICChange(e) { + let value = e.target.value === "Select IC" ? (-1) : (e.target.value); + this.props.handleChange({ target: { id: this.props.controlId, value: value } }); + } + + render() { + + let parts = this.props.controlId.split('.'); + let isCustomProperty = true; + if(parts.length === 1){ + isCustomProperty = false; + } + + let icOptions = []; + if (this.state.ics !== null && this.state.ics.length > 0){ + icOptions.push( + + ) + icOptions.push(this.state.ics.map((ic, index) => ( + + ))) + } else { + icOptions = + } + + return
+ + IC + this.handleICChange(e)}>{icOptions} + +
; + } +} + +export default EditWidgetICControl; diff --git a/src/widget/edit-widget/edit-widget.js b/src/widget/edit-widget/edit-widget.js index d416e24..5d0d601 100644 --- a/src/widget/edit-widget/edit-widget.js +++ b/src/widget/edit-widget/edit-widget.js @@ -141,7 +141,7 @@ class EditWidgetDialog extends React.Component { customProperty ? changeObject[parts[0]][parts[1]]= 'default' : changeObject[e.target.id] = 'default'; } changeObject = this.setMaxWidth(changeObject); - } else if (parts[1]= 'horizontal'){ + } else if (parts[1] === 'horizontal'){ customProperty ? changeObject[parts[0]][parts[1]] = e.target.value : changeObject[e.target.id] = e.target.value ; let tempWidth = changeObject.width; changeObject.width = changeObject.height; @@ -168,6 +168,7 @@ class EditWidgetDialog extends React.Component { this.state.temporal, this.props.sessionToken, this.props.files, + this.props.ics, this.props.signals, (e) => this.handleChange(e)); } diff --git a/src/widget/widget-factory.js b/src/widget/widget-factory.js index ab26514..2f6ac6a 100644 --- a/src/widget/widget-factory.js +++ b/src/widget/widget-factory.js @@ -199,12 +199,13 @@ class WidgetFactory { widget.minWidth = 20; widget.minHeight = 20; widget.width = 100; - widget.height = 100; + widget.height = 40; widget.customProperties.threshold_yellow = 1; widget.customProperties.threshold_red = 2; - widget.customProperties.icID = 1; - widget.customProperties.horizontal = false; + widget.customProperties.icID = -1; + widget.customProperties.horizontal = true; widget.customProperties.showOffset = true; + widget.customProperties.lockAspect = true; break; default: diff --git a/src/widget/widgets/time-offset.js b/src/widget/widgets/time-offset.js index 65b642c..819ecde 100644 --- a/src/widget/widgets/time-offset.js +++ b/src/widget/widgets/time-offset.js @@ -39,7 +39,7 @@ class WidgetTimeOffset extends Component { || props.data[state.icID] == null || props.data[state.icID].output == null || props.data[state.icID].output.timestamp == null) { - return {timeOffset: ''}; + return {timeOffset: -1}; } let serverTime = props.data[state.icID].output.timestamp; @@ -49,20 +49,21 @@ class WidgetTimeOffset extends Component { } render() { - return (
- IC: {this.state.icID} + {this.props.widget.customProperties.icID !== -1 ? + (IC: {this.state.icID}) : (no IC) + } - {this.props.widget.customProperties.showOffset ? + {this.props.widget.customProperties.showOffset && this.props.widget.customProperties.icID !== -1 ? ( {this.state.timeOffset}s) : - (
) + (selected) }
);