mirror of
https://git.rwth-aachen.de/acs/public/villas/web/
synced 2025-03-09 00:00:01 +01:00
Deal with undefined sim models and show notification
This commit is contained in:
parent
bc8bdca839
commit
d240d5553b
4 changed files with 81 additions and 38 deletions
|
@ -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) {
|
||||
|
|
|
@ -15,25 +15,29 @@ import PlotLegend from './widget-plot/plot-legend';
|
|||
class WidgetPlot extends Component {
|
||||
|
||||
render() {
|
||||
if (this.props.simulation == null) {
|
||||
return (<div>Empty</div>);
|
||||
|
||||
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 (
|
||||
<div className="plot-widget" ref="wrapper">
|
||||
<h4>{this.props.widget.name}</h4>
|
||||
|
|
|
@ -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;
|
||||
|
|
24
src/data-managers/notifications-factory.js
Normal file
24
src/data-managers/notifications-factory.js
Normal file
|
@ -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 <rhernandez@gridhound.de>
|
||||
* 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;
|
Loading…
Add table
Reference in a new issue