diff --git a/src/components/dialogs/edit-widget-control-creator.js b/src/components/dialogs/edit-widget-control-creator.js index 50e5407..c686b34 100644 --- a/src/components/dialogs/edit-widget-control-creator.js +++ b/src/components/dialogs/edit-widget-control-creator.js @@ -36,12 +36,21 @@ import EditWidgetCheckboxControl from './edit-widget-checkbox-control'; import EditWidgetColorZonesControl from './edit-widget-color-zones-control'; import EditWidgetMinMaxControl from './edit-widget-min-max-control'; import EditWidgetHTMLContent from './edit-widget-html-content'; +import EditWidgetParametersControl from './edit-widget-parameters-control'; export default function createControls(widgetType = null, widget = null, sessionToken = null, files = null, validateForm, simulationModels, handleChange) { // Use a list to concatenate the controls according to the widget type var dialogControls = []; switch(widgetType) { + case 'CustomAction': + dialogControls.push( + validateForm(id)} handleChange={e => handleChange(e)} />, + validateForm(id)} handleChange={e => handleChange(e)} />, + validateForm(id)} simulationModels={simulationModels} handleChange={(e) => handleChange(e)} />, + handleChange(e)} /> + ) + break; case 'Action': dialogControls.push( validateForm(id)} simulationModels={simulationModels} handleChange={(e) => handleChange(e)} /> diff --git a/src/components/widget-factory.js b/src/components/widget-factory.js index b190f81..6169867 100644 --- a/src/components/widget-factory.js +++ b/src/components/widget-factory.js @@ -20,6 +20,7 @@ * You should have received a copy of the GNU General Public License * along with VILLASweb. If not, see . ******************************************************************************/ + import WidgetSlider from './widgets/slider'; class WidgetFactory { @@ -39,6 +40,22 @@ class WidgetFactory { // set type specific properties switch(type) { + case 'CustomAction': + widget.action = { + action: 'start', + model: { + url: 'ftp://user:pass@example.com/projectA/model.zip' + }, + parameters: { + timestep: 50e-6 + } + }; + widget.name = 'Action'; + widget.icon = 'star'; + widget.width = 100; + widget.height = 50; + widget.simulationModel = defaultSimulationModel; + break; case 'Action': widget.simulationModel = defaultSimulationModel; break; diff --git a/src/components/widgets/custom-action.js b/src/components/widgets/custom-action.js new file mode 100644 index 0000000..6434694 --- /dev/null +++ b/src/components/widgets/custom-action.js @@ -0,0 +1,69 @@ +/** + * File: action.js + * Author: Steffen Vogel + * Date: 21.11.2018 + * Copyright: 2018, Institute for Automation of Complex Power Systems, EONERC + * + * 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, { Component } from 'react'; +import { Button } from 'react-bootstrap'; +import Icon from '../icon'; +import UserStore from '../../stores/user-store'; +import SimulatorStore from '../../stores/simulator-store'; +import AppDispatcher from '../../app-dispatcher'; + +class WidgetCustomAction extends Component { + constructor(props) { + super(props); + + this.state = { + simulator: null + }; + } + + static getStores() { + return [ SimulatorStore ]; + } + + componentWillReceiveProps(props) { + if (props.simulationModel === null) + return; + + this.setState({ + simulator: SimulatorStore.getState().find(s => s._id === props.simulationModel.simulator), + sessionToken: UserStore.getState().token + }); + } + + onClick() { + AppDispatcher.dispatch({ + type: 'simulators/start-action', + simulator: this.state.simulator, + data: this.props.widget.action, + token: this.state.sessionToken + }); + } + + render() { + const btnStyle = { width: '100%', height: '100%' }; + + return ; + } +} + +export default WidgetCustomAction; diff --git a/src/containers/visualization.js b/src/containers/visualization.js index e522d16..a9e53ff 100644 --- a/src/containers/visualization.js +++ b/src/containers/visualization.js @@ -480,6 +480,7 @@ class Visualization extends React.Component { { editingControls } + diff --git a/src/containers/widget.js b/src/containers/widget.js index ebcf7d1..b4df992 100644 --- a/src/containers/widget.js +++ b/src/containers/widget.js @@ -31,6 +31,7 @@ import SimulatorDataStore from '../stores/simulator-data-store'; import SimulationModelStore from '../stores/simulation-model-store'; import FileStore from '../stores/file-store'; +import WidgetCustomAction from '../components/widgets/custom-action'; import WidgetAction from '../components/widgets/action'; import WidgetLamp from '../components/widgets/lamp'; import WidgetValue from '../components/widgets/value'; @@ -204,7 +205,9 @@ class Widget extends React.Component { } // dummy is passed to widgets to keep updating them while in edit mode - if (widget.type === 'Action') { + if (widget.type === 'CustomAction') { + element = + } else if (widget.type === 'Action') { element = } else if (widget.type === 'Lamp') { element =