1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/web/ synced 2025-03-09 00:00:01 +01:00

Extracted widget creation to separate factory

This commit is contained in:
Ricardo Hernandez-Montoya 2017-04-13 10:24:01 +02:00
parent fe543dee93
commit 279dc7b0f2
2 changed files with 112 additions and 75 deletions

View file

@ -0,0 +1,108 @@
/**
* File: widget-factory.js
* Description: A factory to create and pre-configure widgets
* Author: Ricardo Hernandez-Montoya <rhernandez@gridhound.de>
* 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;

View file

@ -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;