From d240d5553bea918128471868ef0510790e0d52db Mon Sep 17 00:00:00 2001 From: Ricardo Hernandez-Montoya Date: Thu, 13 Apr 2017 10:03:30 +0200 Subject: [PATCH 1/4] Deal with undefined sim models and show notification --- src/components/widget-plot-table.js | 37 ++++++++++++--------- src/components/widget-plot.js | 38 ++++++++++++---------- src/containers/visualization.js | 20 +++++++++--- src/data-managers/notifications-factory.js | 24 ++++++++++++++ 4 files changed, 81 insertions(+), 38 deletions(-) create mode 100644 src/data-managers/notifications-factory.js diff --git a/src/components/widget-plot-table.js b/src/components/widget-plot-table.js index cbdee75..65de31e 100644 --- a/src/components/widget-plot-table.js +++ b/src/components/widget-plot-table.js @@ -58,22 +58,27 @@ class WidgetPlotTable extends Component { return (model.simulator === simulator); }); - // Create checkboxes using the signal indices from simulation model - const preselectedSignals = simulationModel.mapping.reduce( - // Loop through simulation model signals - (accum, model_signal, signal_index) => { - // Append them if they belong to the current selected type - if (nextProps.widget.preselectedSignals.indexOf(signal_index) > -1) { - accum.push( - { - index: signal_index, - name: model_signal.name - } - ) - } - return accum; - }, []); - this.setState({ preselectedSignals: preselectedSignals }); + let preselectedSignals = []; + // Proceed if a simulation model is available + if (simulationModel) { + // Create checkboxes using the signal indices from simulation model + preselectedSignals = simulationModel.mapping.reduce( + // Loop through simulation model signals + (accum, model_signal, signal_index) => { + // Append them if they belong to the current selected type + if (nextProps.widget.preselectedSignals.indexOf(signal_index) > -1) { + accum.push( + { + index: signal_index, + name: model_signal.name + } + ) + } + return accum; + }, []); + } + + this.setState({ preselectedSignals: preselectedSignals }); } updateSignalSelection(signal_index, checked) { diff --git a/src/components/widget-plot.js b/src/components/widget-plot.js index df901c9..e0c2662 100644 --- a/src/components/widget-plot.js +++ b/src/components/widget-plot.js @@ -15,25 +15,29 @@ import PlotLegend from './widget-plot/plot-legend'; class WidgetPlot extends Component { render() { - if (this.props.simulation == null) { - return (
Empty
); + + const simulator = this.props.widget.simulator; + const simulation = this.props.simulation; + let legendSignals = []; + let simulatorData = []; + + // Proceed if a simulation with models and a simulator are available + if (simulator && simulation && simulation.models.length > 0) { + + const model = simulation.models.find( (model) => model.simulator === simulator ); + const chosenSignals = this.props.widget.signals; + + simulatorData = this.props.data[simulator]; + + // Query the signals that will be displayed in the legend + legendSignals = model.mapping.reduce( (accum, model_signal, signal_index) => { + if (chosenSignals.includes(signal_index)) { + accum.push({ index: signal_index, name: model_signal.name }); + } + return accum; + }, []); } - let simulator = this.props.widget.simulator; - let simulation = this.props.simulation; - let model = simulation.models.find( (model) => model.simulator === simulator ); - let chosenSignals = this.props.widget.signals; - - let simulatorData = this.props.data[simulator]; - - // Query the signals that will be displayed in the legend - let legendSignals = model.mapping.reduce( (accum, model_signal, signal_index) => { - if (chosenSignals.includes(signal_index)) { - accum.push({ index: signal_index, name: model_signal.name }); - } - return accum; - }, []); - return (

{this.props.widget.name}

diff --git a/src/containers/visualization.js b/src/containers/visualization.js index 6085b06..c82d56d 100644 --- a/src/containers/visualization.js +++ b/src/containers/visualization.js @@ -22,6 +22,8 @@ import ProjectStore from '../stores/project-store'; import SimulationStore from '../stores/simulation-store'; import FileStore from '../stores/file-store'; import AppDispatcher from '../app-dispatcher'; +import NotificationsDataManager from '../data-managers/notifications-data-manager'; +import NotificationsFactory from '../data-managers/notifications-factory'; import WidgetSlider from '../components/widget-slider'; @@ -138,16 +140,24 @@ class Visualization extends Component { z: 0 }; + let defaultSimulator = null; + + if (this.state.simulation.models && this.state.simulation.models.length === 0) { + NotificationsDataManager.addNotification(NotificationsFactory.NO_SIM_MODEL_AVAILABLE); + } else { + defaultSimulator = this.state.simulation.models[0].simulator; + } + // set type specific properties if (item.name === 'Value') { - widget.simulator = this.state.simulation.models[0].simulator; + widget.simulator = defaultSimulator; widget.signal = 0; widget.minWidth = 70; widget.minHeight = 20; widget.width = 120; widget.height = 70; } else if (item.name === 'Plot') { - widget.simulator = this.state.simulation.models[0].simulator; + widget.simulator = defaultSimulator; widget.signals = [ 0 ]; widget.time = 60; widget.minWidth = 400; @@ -155,7 +165,7 @@ class Visualization extends Component { widget.width = 400; widget.height = 200; } else if (item.name === 'Table') { - widget.simulator = this.state.simulation.models[0].simulator; + widget.simulator = defaultSimulator; widget.minWidth = 300; widget.minHeight = 200; widget.width = 400; @@ -164,7 +174,7 @@ class Visualization extends Component { widget.minWidth = 70; widget.minHeight = 20; } else if (item.name === 'PlotTable') { - widget.simulator = this.state.simulation.models[0].simulator; + widget.simulator = defaultSimulator; widget.preselectedSignals = []; widget.signals = []; // initialize selected signals widget.minWidth = 400; @@ -194,7 +204,7 @@ class Visualization extends Component { widget.height = 50; widget.orientation = WidgetSlider.OrientationTypes.HORIZONTAL.value; // Assign default orientation } else if (item.name === 'Gauge') { - widget.simulator = this.state.simulation.models[0].simulator; + widget.simulator = defaultSimulator; widget.signal = 0; widget.minWidth = 200; widget.minHeight = 150; diff --git a/src/data-managers/notifications-factory.js b/src/data-managers/notifications-factory.js new file mode 100644 index 0000000..56c095c --- /dev/null +++ b/src/data-managers/notifications-factory.js @@ -0,0 +1,24 @@ +/** + * File: notifications-factory.js + * Description: An unique source of pre-defined notifications that are displayed + * throughout the application. + * Author: Ricardo Hernandez-Montoya + * Date: 13.04.2017 + * Copyright: 2017, Institute for Automation of Complex Power Systems, EONERC + * This file is part of VILLASweb. All Rights Reserved. Proprietary and confidential. + * Unauthorized copying of this file, via any medium is strictly prohibited. + **********************************************************************************/ + +class NotificationsFactory { + + static get NO_SIM_MODEL_AVAILABLE() { + return { + title: 'No simulation model available', + message: 'Consider defining a simulation model in the simulators section.', + level: 'warning' + }; + } + +} + +export default NotificationsFactory; \ No newline at end of file From fe543dee931b8d2131d3b8386932b1772e62dae5 Mon Sep 17 00:00:00 2001 From: Ricardo Hernandez-Montoya Date: Thu, 13 Apr 2017 10:05:57 +0200 Subject: [PATCH 2/4] Extracted controls in Widget Edit model and included proper message when no sim model is available --- ...-image.js => edit-widget-image-control.js} | 6 +- src/components/dialog/edit-widget-plot.js | 85 ------------------- .../dialog/edit-widget-signals-control.js | 31 ++++--- .../dialog/edit-widget-simulator-control.js | 11 ++- .../dialog/edit-widget-time-control.js | 40 +++++++++ src/components/dialog/edit-widget-value.js | 64 -------------- src/components/dialog/edit-widget.js | 32 ++++--- 7 files changed, 87 insertions(+), 182 deletions(-) rename src/components/dialog/{edit-widget-image.js => edit-widget-image-control.js} (94%) delete mode 100644 src/components/dialog/edit-widget-plot.js create mode 100644 src/components/dialog/edit-widget-time-control.js delete mode 100644 src/components/dialog/edit-widget-value.js diff --git a/src/components/dialog/edit-widget-image.js b/src/components/dialog/edit-widget-image-control.js similarity index 94% rename from src/components/dialog/edit-widget-image.js rename to src/components/dialog/edit-widget-image-control.js index f7b06e4..d484bee 100644 --- a/src/components/dialog/edit-widget-image.js +++ b/src/components/dialog/edit-widget-image-control.js @@ -1,5 +1,5 @@ /** - * File: edit-widget-value.js + * File: edit-widget-image-control.js * Author: Markus Grigull * Date: 04.03.2017 * Copyright: 2017, Institute for Automation of Complex Power Systems, EONERC @@ -12,7 +12,7 @@ import { FormGroup, FormControl, ControlLabel, Button } from 'react-bootstrap'; import AppDispatcher from '../../app-dispatcher'; -class EditImageWidget extends Component { +class EditImageWidgetControl extends Component { constructor(props) { super(props); @@ -68,4 +68,4 @@ class EditImageWidget extends Component { } } -export default EditImageWidget; +export default EditImageWidgetControl; diff --git a/src/components/dialog/edit-widget-plot.js b/src/components/dialog/edit-widget-plot.js deleted file mode 100644 index a2371e3..0000000 --- a/src/components/dialog/edit-widget-plot.js +++ /dev/null @@ -1,85 +0,0 @@ -/** - * File: edit-widget-plot.js - * Author: Markus Grigull - * Date: 13.03.2017 - * Copyright: 2017, Institute for Automation of Complex Power Systems, EONERC - * This file is part of VILLASweb. All Rights Reserved. Proprietary and confidential. - * Unauthorized copying of this file, via any medium is strictly prohibited. - **********************************************************************************/ - -import React, { Component } from 'react'; -import { FormGroup, FormControl, ControlLabel, Checkbox, HelpBlock } from 'react-bootstrap'; - -class EditPlotWidget extends Component { - constructor(props) { - super(props); - - this.state = { - widget: { - simulator: '', - signals: [], - time: 0 - } - }; - } - - componentWillReceiveProps(nextProps) { - this.setState({ widget: nextProps.widget }); - } - - handleSignalChange(e, index) { - var signals = this.state.widget.signals; - - if (e.target.checked) { - // add signal - signals.push(index); - } else { - // remove signal - const pos = signals.indexOf(index); - if (pos > -1) { - signals.splice(pos, 1); - } - } - - this.props.handleChange({ target: { id: 'signals', value: signals } }); - } - - render() { - // get selected simulation model - var simulationModel = {}; - - if (this.props.simulation) { - this.props.simulation.models.forEach((model) => { - if (model.simulation === this.state.widget.simulation) { - simulationModel = model; - } - }); - } - - return ( -
- - Time - this.props.handleChange(e)} /> - Time in seconds - - - Simulator - this.props.handleChange(e)}> - {this.props.simulation.models.map((model, index) => ( - - ))} - - - - Signals - {simulationModel.mapping.map((signal, index) => ( - this.handleSignalChange(e, index)}>{signal.name} - ))} - -
- ); - } -} - -export default EditPlotWidget; diff --git a/src/components/dialog/edit-widget-signals-control.js b/src/components/dialog/edit-widget-signals-control.js index 2842618..a7fcd07 100644 --- a/src/components/dialog/edit-widget-signals-control.js +++ b/src/components/dialog/edit-widget-signals-control.js @@ -8,7 +8,7 @@ **********************************************************************************/ import React, { Component } from 'react'; -import { FormGroup, Checkbox, ControlLabel } from 'react-bootstrap'; +import { FormGroup, Checkbox, ControlLabel, FormControl } from 'react-bootstrap'; class EditWidgetSignalsControl extends Component { constructor(props) { @@ -39,27 +39,32 @@ class EditWidgetSignalsControl extends Component { new_signals = signals.filter( (idx) => idx !== index ); } - this.props.handleChange({ target: { id: 'preselectedSignals', value: new_signals } }); + this.props.handleChange({ target: { id: this.props.controlId, value: new_signals } }); } render() { - // get selected simulation model - var simulationModel = {}; + let signalsToRender = []; if (this.props.simulation) { - this.props.simulation.models.forEach((model) => { - if (model.simulation === this.state.widget.simulation) { - simulationModel = model; - } - }); - } + // get selected simulation model + const simulationModel = this.props.simulation.models.find( model => model.simulation === this.state.widget.simulation ); + // If simulation model update the signals to render + signalsToRender = simulationModel? simulationModel.mapping : []; + } + return ( Signals - {simulationModel.mapping.map((signal, index) => ( - this.handleSignalChange(e.target.checked, index)}>{signal.name} - ))} + { + signalsToRender.length === 0 ? ( + No signals available. + ) : ( + signalsToRender.map((signal, index) => ( + this.handleSignalChange(e.target.checked, index)}>{signal.name} + )) + ) + } ); } diff --git a/src/components/dialog/edit-widget-simulator-control.js b/src/components/dialog/edit-widget-simulator-control.js index baa9679..23de386 100644 --- a/src/components/dialog/edit-widget-simulator-control.js +++ b/src/components/dialog/edit-widget-simulator-control.js @@ -31,10 +31,15 @@ class EditWidgetSimulatorControl extends Component { return ( Simulator - this.props.handleChange(e)}> - {this.props.simulation.models.map((model, index) => ( + this.props.handleChange(e)}> + { + this.props.simulation.models.length === 0? ( + + ) : ( + this.props.simulation.models.map((model, index) => ( - ))} + ))) + } ); diff --git a/src/components/dialog/edit-widget-time-control.js b/src/components/dialog/edit-widget-time-control.js new file mode 100644 index 0000000..5b8e234 --- /dev/null +++ b/src/components/dialog/edit-widget-time-control.js @@ -0,0 +1,40 @@ +/** + * File: edit-widget-time-control.js + * Author: Ricardo Hernandez-Montoya + * Date: 13.04.2017 + * Copyright: 2017, Institute for Automation of Complex Power Systems, EONERC + * This file is part of VILLASweb. All Rights Reserved. Proprietary and confidential. + * Unauthorized copying of this file, via any medium is strictly prohibited. + **********************************************************************************/ + +import React, { Component } from 'react'; +import { FormGroup, FormControl, ControlLabel, HelpBlock } from 'react-bootstrap'; + +class EditWidgetTimeControl extends Component { + constructor(props) { + super(props); + + this.state = { + widget: { + time: 0 + } + }; + } + + componentWillReceiveProps(nextProps) { + this.setState({ widget: nextProps.widget }); + } + + render() { + + return ( + + Time + this.props.handleChange(e)} /> + Time in seconds + + ); + } +} + +export default EditWidgetTimeControl; diff --git a/src/components/dialog/edit-widget-value.js b/src/components/dialog/edit-widget-value.js deleted file mode 100644 index 7f16a03..0000000 --- a/src/components/dialog/edit-widget-value.js +++ /dev/null @@ -1,64 +0,0 @@ -/** - * File: edit-widget-value.js - * Author: Markus Grigull - * Date: 04.03.2017 - * Copyright: 2017, Institute for Automation of Complex Power Systems, EONERC - * This file is part of VILLASweb. All Rights Reserved. Proprietary and confidential. - * Unauthorized copying of this file, via any medium is strictly prohibited. - **********************************************************************************/ - -import React, { Component } from 'react'; -import { FormGroup, FormControl, ControlLabel } from 'react-bootstrap'; - -class EditValueWidget extends Component { - constructor(props) { - super(props); - - this.state = { - widget: { - simulator: '', - signal: 0 - } - }; - } - - componentWillReceiveProps(nextProps) { - this.setState({ widget: nextProps.widget }); - } - - render() { - // get selected simulation model - var simulationModel = {}; - - if (this.props.simulation) { - this.props.simulation.models.forEach((model) => { - if (model.simulation === this.state.widget.simulation) { - simulationModel = model; - } - }); - } - - return ( -
- - Simulator - this.props.handleChange(e)}> - {this.props.simulation.models.map((model, index) => ( - - ))} - - - - Signal - this.props.handleChange(e)}> - {simulationModel.mapping.map((signal, index) => ( - - ))} - - -
- ); - } -} - -export default EditValueWidget; diff --git a/src/components/dialog/edit-widget.js b/src/components/dialog/edit-widget.js index a5a2daa..b90e75c 100644 --- a/src/components/dialog/edit-widget.js +++ b/src/components/dialog/edit-widget.js @@ -12,10 +12,8 @@ import { FormGroup, FormControl, ControlLabel } from 'react-bootstrap'; import Dialog from './dialog'; -import EditValueWidget from './edit-widget-value'; -import EditPlotWidget from './edit-widget-plot'; -import EditTableWidget from './edit-widget-table'; -import EditImageWidget from './edit-widget-image'; +import EditWidgetTimeControl from './edit-widget-time-control'; +import EditImageWidgetControl from './edit-widget-image-control'; import EditWidgetSimulatorControl from './edit-widget-simulator-control'; import EditWidgetSignalControl from './edit-widget-signal-control'; import EditWidgetSignalsControl from './edit-widget-signals-control'; @@ -53,8 +51,6 @@ class EditWidgetDialog extends Component { var update = this.state.temporal; update[e.target.id] = e.target.value; this.setState({ temporal: update }); - - //console.log(this.state.widget); } resetState() { @@ -77,20 +73,29 @@ class EditWidgetDialog extends Component { } render() { - // get widget part - var widgetDialog = null; // Use a list to concatenate the controls according to the widget type var dialogControls = []; if (this.props.widget) { if (this.props.widget.type === 'Value') { - widgetDialog = this.validateForm(id)} simulation={this.props.simulation} handleChange={(e) => this.handleChange(e)} />; + dialogControls.push( + this.validateForm(id)} simulation={this.props.simulation} handleChange={(e) => this.handleChange(e)} />, + this.validateForm(id)} simulation={this.props.simulation} handleChange={(e) => this.handleChange(e)} /> + ) } else if (this.props.widget.type === 'Plot') { - widgetDialog = this.validateForm(id)} simulation={this.props.simulation} handleChange={(e, index) => this.handleChange(e, index)} />; + dialogControls.push( + this.validateForm(id)} simulation={this.props.simulation} handleChange={(e, index) => this.handleChange(e, index)} />, + this.validateForm(id)} simulation={this.props.simulation} handleChange={(e) => this.handleChange(e)} />, + this.validateForm(id)} simulation={this.props.simulation} handleChange={(e) => this.handleChange(e)} /> + ) } else if (this.props.widget.type === 'Table') { - widgetDialog = this.validateForm(id)} simulation={this.props.simulation} handleChange={(e, index) => this.handleChange(e, index)} />; + dialogControls.push( + this.validateForm(id)} simulation={this.props.simulation} handleChange={(e) => this.handleChange(e)} /> + ) } else if (this.props.widget.type === 'Image') { - widgetDialog = this.validateForm(id)} simulation={this.props.simulation} handleChange={(e, index) => this.handleChange(e, index)} />; + dialogControls.push( + this.validateForm(id)} simulation={this.props.simulation} handleChange={(e, index) => this.handleChange(e, index)} /> + ) } else if (this.props.widget.type === 'Gauge') { dialogControls.push( this.validateForm(id)} simulation={this.props.simulation} handleChange={(e) => this.handleChange(e)} />, @@ -99,7 +104,7 @@ class EditWidgetDialog extends Component { } else if (this.props.widget.type === 'PlotTable') { dialogControls.push( this.validateForm(id)} simulation={this.props.simulation} handleChange={(e) => this.handleChange(e)} />, - this.validateForm(id)} simulation={this.props.simulation} handleChange={(e) => this.handleChange(e)} /> + this.validateForm(id)} simulation={this.props.simulation} handleChange={(e) => this.handleChange(e)} /> ) } else if (this.props.widget.type === 'Slider') { dialogControls.push( @@ -117,7 +122,6 @@ class EditWidgetDialog extends Component { { dialogControls } - {widgetDialog} ); From 279dc7b0f2e6690565b409590a87b25876d18836 Mon Sep 17 00:00:00 2001 From: Ricardo Hernandez-Montoya Date: Thu, 13 Apr 2017 10:24:01 +0200 Subject: [PATCH 3/4] Extracted widget creation to separate factory --- src/components/widget-factory.js | 108 +++++++++++++++++++++++++++++++ src/containers/visualization.js | 79 ++-------------------- 2 files changed, 112 insertions(+), 75 deletions(-) create mode 100644 src/components/widget-factory.js diff --git a/src/components/widget-factory.js b/src/components/widget-factory.js new file mode 100644 index 0000000..0f45052 --- /dev/null +++ b/src/components/widget-factory.js @@ -0,0 +1,108 @@ +/** + * File: widget-factory.js + * Description: A factory to create and pre-configure widgets + * Author: Ricardo Hernandez-Montoya + * Date: 02.03.2017 + * Copyright: 2017, Institute for Automation of Complex Power Systems, EONERC + * This file is part of VILLASweb. All Rights Reserved. Proprietary and confidential. + * Unauthorized copying of this file, via any medium is strictly prohibited. + **********************************************************************************/ + +import WidgetSlider from './widget-slider'; + +class WidgetFactory { + + static createWidgetOfType(type, position, defaultSimulator = null) { + + let widget = { + name: 'Name', + type: type, + width: 100, + height: 100, + x: position.x, + y: position.y, + z: 0 + }; + + // set type specific properties + switch(type) { + case 'Value': + widget.simulator = defaultSimulator; + widget.signal = 0; + widget.minWidth = 70; + widget.minHeight = 20; + widget.width = 120; + widget.height = 70; + break; + case 'Plot': + widget.simulator = defaultSimulator; + widget.signals = [ 0 ]; + widget.time = 60; + widget.minWidth = 400; + widget.minHeight = 200; + widget.width = 400; + widget.height = 200; + break; + case 'Table': + widget.simulator = defaultSimulator; + widget.minWidth = 300; + widget.minHeight = 200; + widget.width = 400; + widget.height = 200; + break; + case 'Label': + widget.minWidth = 70; + widget.minHeight = 20; + break; + case 'PlotTable': + widget.simulator = defaultSimulator; + widget.preselectedSignals = []; + widget.signals = []; // initialize selected signals + widget.minWidth = 400; + widget.minHeight = 300; + widget.width = 500; + widget.height = 500; + widget.time = 60; + break; + case 'Image': + widget.minWidth = 100; + widget.minHeight = 100; + widget.width = 200; + widget.height = 200; + break; + case 'Button': + widget.minWidth = 100; + widget.minHeight = 50; + widget.width = 100; + widget.height = 100; + break; + case 'NumberInput': + widget.minWidth = 200; + widget.minHeight = 50; + widget.width = 200; + widget.height = 50; + break; + case 'Slider': + widget.minWidth = 380; + widget.minHeight = 30; + widget.width = 400; + widget.height = 50; + widget.orientation = WidgetSlider.OrientationTypes.HORIZONTAL.value; // Assign default orientation + break; + case 'Gauge': + widget.simulator = defaultSimulator; + widget.signal = 0; + widget.minWidth = 200; + widget.minHeight = 150; + widget.width = 200; + widget.height = 150; + break; + default: + widget.width = 100; + widget.height = 100; + } + return widget; + } +} + +export default WidgetFactory; \ No newline at end of file diff --git a/src/containers/visualization.js b/src/containers/visualization.js index c82d56d..7328205 100644 --- a/src/containers/visualization.js +++ b/src/containers/visualization.js @@ -12,6 +12,7 @@ import { Container } from 'flux/utils'; import { Button } from 'react-bootstrap'; import { ContextMenu, MenuItem } from 'react-contextmenu'; +import WidgetFactory from '../components/widget-factory'; import ToolboxItem from '../components/toolbox-item'; import Dropzone from '../components/dropzone'; import Widget from './widget'; @@ -25,8 +26,6 @@ import AppDispatcher from '../app-dispatcher'; import NotificationsDataManager from '../data-managers/notifications-data-manager'; import NotificationsFactory from '../data-managers/notifications-factory'; -import WidgetSlider from '../components/widget-slider'; - class Visualization extends Component { static getStores() { return [ VisualizationStore, ProjectStore, SimulationStore, FileStore ]; @@ -129,17 +128,8 @@ class Visualization extends Component { } handleDrop(item, position) { - // add new widget - var widget = { - name: 'Name', - type: item.name, - width: 100, - height: 100, - x: position.x, - y: position.y, - z: 0 - }; + let widget = null; let defaultSimulator = null; if (this.state.simulation.models && this.state.simulation.models.length === 0) { @@ -148,69 +138,8 @@ class Visualization extends Component { defaultSimulator = this.state.simulation.models[0].simulator; } - // set type specific properties - if (item.name === 'Value') { - widget.simulator = defaultSimulator; - widget.signal = 0; - widget.minWidth = 70; - widget.minHeight = 20; - widget.width = 120; - widget.height = 70; - } else if (item.name === 'Plot') { - widget.simulator = defaultSimulator; - widget.signals = [ 0 ]; - widget.time = 60; - widget.minWidth = 400; - widget.minHeight = 200; - widget.width = 400; - widget.height = 200; - } else if (item.name === 'Table') { - widget.simulator = defaultSimulator; - widget.minWidth = 300; - widget.minHeight = 200; - widget.width = 400; - widget.height = 200; - } else if (item.name === 'Label') { - widget.minWidth = 70; - widget.minHeight = 20; - } else if (item.name === 'PlotTable') { - widget.simulator = defaultSimulator; - widget.preselectedSignals = []; - widget.signals = []; // initialize selected signals - widget.minWidth = 400; - widget.minHeight = 300; - widget.width = 500; - widget.height = 500; - widget.time = 60 - } else if (item.name === 'Image') { - widget.minWidth = 100; - widget.minHeight = 100; - widget.width = 200; - widget.height = 200; - } else if (item.name === 'Button') { - widget.minWidth = 100; - widget.minHeight = 50; - widget.width = 100; - widget.height = 100; - } else if (item.name === 'NumberInput') { - widget.minWidth = 200; - widget.minHeight = 50; - widget.width = 200; - widget.height = 50; - } else if (item.name === 'Slider') { - widget.minWidth = 380; - widget.minHeight = 30; - widget.width = 400; - widget.height = 50; - widget.orientation = WidgetSlider.OrientationTypes.HORIZONTAL.value; // Assign default orientation - } else if (item.name === 'Gauge') { - widget.simulator = defaultSimulator; - widget.signal = 0; - widget.minWidth = 200; - widget.minHeight = 150; - widget.width = 200; - widget.height = 150; - } + // create new widget + widget = WidgetFactory.createWidgetOfType(item.name, position, defaultSimulator); var new_widgets = this.state.visualization.widgets; From 00f6739241e950dbffa63b8ea551d209c59ee31b Mon Sep 17 00:00:00 2001 From: Ricardo Hernandez-Montoya Date: Thu, 13 Apr 2017 10:39:31 +0200 Subject: [PATCH 4/4] Missing sim model handling in signal edit control --- .../dialog/edit-widget-signal-control.js | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/components/dialog/edit-widget-signal-control.js b/src/components/dialog/edit-widget-signal-control.js index fd2cd5e..879052b 100644 --- a/src/components/dialog/edit-widget-signal-control.js +++ b/src/components/dialog/edit-widget-signal-control.js @@ -27,24 +27,29 @@ class EditWidgetSignalControl extends Component { } render() { - // get selected simulation model - var simulationModel = {}; + let signalsToRender = []; if (this.props.simulation) { - this.props.simulation.models.forEach((model) => { - if (model.simulation === this.state.widget.simulation) { - simulationModel = model; - } - }); + // get selected simulation model + const simulationModel = this.props.simulation.models.find( model => model.simulation === this.state.widget.simulation ); + + // If simulation model update the signals to render + signalsToRender = simulationModel? simulationModel.mapping : []; } return ( Signal this.props.handleChange(e)}> - {simulationModel.mapping.map((signal, index) => ( - - ))} + { + signalsToRender.length === 0 ? ( + + ) : ( + signalsToRender.map((signal, index) => ( + + )) + ) + } );