mirror of
https://git.rwth-aachen.de/acs/public/villas/web/
synced 2025-03-16 00:00:03 +01:00
rename simulation model to component configuration
This commit is contained in:
parent
37af564975
commit
27d7ee0172
20 changed files with 188 additions and 287 deletions
|
@ -6,7 +6,6 @@ import EditWidgetTextControl from '../../widget/edit-widget/edit-widget-text-con
|
|||
import EditWidgetColorControl from '../../widget/edit-widget/edit-widget-color-control';
|
||||
import EditWidgetTimeControl from '../../widget/edit-widget/edit-widget-time-control';
|
||||
import EditImageWidgetControl from '../../widget/edit-widget/edit-widget-image-control';
|
||||
import EditWidgetSimulationControl from '../../widget/edit-widget/edit-widget-simulation-control';
|
||||
import EditWidgetSignalControl from '../../widget/edit-widget/edit-widget-signal-control';
|
||||
import EditWidgetSignalsControl from '../../widget/edit-widget/edit-widget-signals-control';
|
||||
import EditWidgetOrientation from '../../widget/edit-widget/edit-widget-orientation';
|
||||
|
@ -25,23 +24,23 @@ describe('edit widget control creator', () => {
|
|||
});
|
||||
|
||||
var runs = [
|
||||
{ args: { widgetType: 'Lamp' }, result: { controlNumber: 5, controlTypes: [EditWidgetSimulationControl, EditWidgetSignalControl, EditWidgetTextControl, EditWidgetColorControl, EditWidgetColorControl] } },
|
||||
{ args: { widgetType: 'Value' }, result: { controlNumber: 5, controlTypes: [EditWidgetTextControl, EditWidgetSimulationControl, EditWidgetSignalControl, EditWidgetTextSizeControl, EditWidgetCheckboxControl] } },
|
||||
{ args: { widgetType: 'Plot' }, result: { controlNumber: 5, controlTypes: [EditWidgetTimeControl, EditWidgetSimulationControl, EditWidgetSignalsControl, EditWidgetTextControl, EditWidgetMinMaxControl] } },
|
||||
{ args: { widgetType: 'Table' }, result: { controlNumber: 2, controlTypes: [EditWidgetSimulationControl, EditWidgetCheckboxControl] } },
|
||||
{ args: { widgetType: 'Lamp' }, result: { controlNumber: 5, controlTypes: [EditWidgetSignalControl, EditWidgetTextControl, EditWidgetColorControl, EditWidgetColorControl] } },
|
||||
{ args: { widgetType: 'Value' }, result: { controlNumber: 5, controlTypes: [EditWidgetTextControl, EditWidgetSignalControl, EditWidgetTextSizeControl, EditWidgetCheckboxControl] } },
|
||||
{ args: { widgetType: 'Plot' }, result: { controlNumber: 5, controlTypes: [EditWidgetTimeControl, EditWidgetSignalsControl, EditWidgetTextControl, EditWidgetMinMaxControl] } },
|
||||
{ args: { widgetType: 'Table' }, result: { controlNumber: 2, controlTypes: [EditWidgetCheckboxControl] } },
|
||||
{ args: { widgetType: 'Image' }, result: { controlNumber: 2, controlTypes: [EditImageWidgetControl, EditWidgetAspectControl] } },
|
||||
{ args: { widgetType: 'Gauge' }, result: { controlNumber: 6, controlTypes: [EditWidgetTextControl, EditWidgetSimulationControl, EditWidgetSignalControl, EditWidgetCheckboxControl, EditWidgetColorZonesControl, EditWidgetMinMaxControl] } },
|
||||
{ args: { widgetType: 'PlotTable' }, result: { controlNumber: 5, controlTypes: [EditWidgetSimulationControl, EditWidgetSignalsControl, EditWidgetTextControl, EditWidgetTimeControl, EditWidgetMinMaxControl] } },
|
||||
{ args: { widgetType: 'Slider' }, result: { controlNumber: 9, controlTypes: [EditWidgetTextControl, EditWidgetOrientation, EditWidgetSimulationControl, EditWidgetSignalControl, EditWidgetCheckboxControl, EditWidgetCheckboxControl, EditWidgetMinMaxControl, EditWidgetNumberControl, EditWidgetNumberControl] } },
|
||||
{ args: { widgetType: 'Button' }, result: { controlNumber: 6, controlTypes: [EditWidgetTextControl, EditWidgetSimulationControl, EditWidgetSignalControl, EditWidgetCheckboxControl, EditWidgetNumberControl, EditWidgetNumberControl] } },
|
||||
{ args: { widgetType: 'Gauge' }, result: { controlNumber: 6, controlTypes: [EditWidgetTextControl, EditWidgetSignalControl, EditWidgetCheckboxControl, EditWidgetColorZonesControl, EditWidgetMinMaxControl] } },
|
||||
{ args: { widgetType: 'PlotTable' }, result: { controlNumber: 5, controlTypes: [EditWidgetSignalsControl, EditWidgetTextControl, EditWidgetTimeControl, EditWidgetMinMaxControl] } },
|
||||
{ args: { widgetType: 'Slider' }, result: { controlNumber: 9, controlTypes: [EditWidgetTextControl, EditWidgetOrientation, EditWidgetSignalControl, EditWidgetCheckboxControl, EditWidgetCheckboxControl, EditWidgetMinMaxControl, EditWidgetNumberControl, EditWidgetNumberControl] } },
|
||||
{ args: { widgetType: 'Button' }, result: { controlNumber: 6, controlTypes: [EditWidgetTextControl, EditWidgetSignalControl, EditWidgetCheckboxControl, EditWidgetNumberControl, EditWidgetNumberControl] } },
|
||||
{ args: { widgetType: 'Box' }, result: { controlNumber: 2, controlTypes: [EditWidgetColorControl, EditWidgetColorControl] } },
|
||||
{ args: { widgetType: 'Label' }, result: { controlNumber: 3, controlTypes: [EditWidgetTextControl, EditWidgetTextSizeControl, EditWidgetColorControl] } },
|
||||
{ args: { widgetType: 'HTML' }, result: { controlNumber: 1, controlTypes: [EditWidgetHTMLContent] } },
|
||||
{ args: { widgetType: 'Input'}, result: { controlNumber: 3, controlTypes: [EditWidgetTextControl, EditWidgetSimulationControl, EditWidgetSignalControl] } }
|
||||
{ args: { widgetType: 'Input'}, result: { controlNumber: 3, controlTypes: [EditWidgetTextControl, EditWidgetSignalControl] } }
|
||||
];
|
||||
|
||||
runs.forEach( (run) => {
|
||||
let itMsg = run.args.widgetType + ' widget edit model should have correct controls';
|
||||
let itMsg = run.args.widgetType + ' widget edit should have correct controls';
|
||||
it(itMsg, () => {
|
||||
let controls = createControls(run.args.widgetType, null, null, null, null, null, null);
|
||||
|
||||
|
|
|
@ -18,10 +18,10 @@
|
|||
class NotificationsFactory {
|
||||
|
||||
// This is an example
|
||||
static get NO_SIM_MODEL_AVAILABLE() {
|
||||
static get EXAMPLE_NOTIFICATION() {
|
||||
return {
|
||||
title: 'No simulation model available',
|
||||
message: 'Consider defining a simulation model in the simulators section.',
|
||||
title: 'Example notification',
|
||||
message: 'Write something here that describes what happend.',
|
||||
level: 'warning'
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,8 +1,4 @@
|
|||
/**
|
||||
* File: simulation-model-store.js
|
||||
* Author: Markus Grigull <mgrigull@eonerc.rwth-aachen.de>
|
||||
* Date: 20.04.2018
|
||||
*
|
||||
* This file is part of VILLASweb.
|
||||
*
|
||||
* VILLASweb is free software: you can redistribute it and/or modify
|
||||
|
@ -20,21 +16,21 @@
|
|||
******************************************************************************/
|
||||
|
||||
import ArrayStore from '../common/array-store';
|
||||
import SimulationModelsDataManager from './simulation-models-data-manager';
|
||||
import ConfigsDataManager from './configs-data-manager';
|
||||
|
||||
class SimulationModelStore extends ArrayStore {
|
||||
class ConfigStore extends ArrayStore {
|
||||
|
||||
constructor() {
|
||||
super('simulationModels', SimulationModelsDataManager);
|
||||
super('configs', ConfigsDataManager);
|
||||
}
|
||||
|
||||
reduce(state, action) {
|
||||
switch (action.type) {
|
||||
|
||||
case 'simulationModels/loaded':
|
||||
case 'configs/loaded':
|
||||
|
||||
SimulationModelsDataManager.loadSignals(action.token, action.data);
|
||||
SimulationModelsDataManager.loadFiles(action.token, action.data);
|
||||
ConfigsDataManager.loadSignals(action.token, action.data);
|
||||
ConfigsDataManager.loadFiles(action.token, action.data);
|
||||
return super.reduce(state, action);
|
||||
|
||||
default:
|
||||
|
@ -44,4 +40,4 @@ class SimulationModelStore extends ArrayStore {
|
|||
}
|
||||
}
|
||||
|
||||
export default new SimulationModelStore();
|
||||
export default new ConfigStore();
|
|
@ -19,35 +19,35 @@ import RestDataManager from '../common/data-managers/rest-data-manager';
|
|||
import AppDispatcher from '../common/app-dispatcher';
|
||||
import RestAPI from "../common/api/rest-api";
|
||||
|
||||
class SimulationModelDataManager extends RestDataManager {
|
||||
class ConfigDataManager extends RestDataManager {
|
||||
constructor() {
|
||||
super('simulationModel', '/models');
|
||||
super('config', '/configs');
|
||||
|
||||
this.onLoad = this.onModelsLoad;
|
||||
this.onLoad = this.onConfigsLoad;
|
||||
}
|
||||
|
||||
onModelsLoad(data) {
|
||||
onConfigsLoad(data) {
|
||||
if (!Array.isArray(data))
|
||||
data = [ data ];
|
||||
|
||||
for (let model of data)
|
||||
this.loadModelData(model);
|
||||
for (let config of data)
|
||||
this.loadICData(config);
|
||||
}
|
||||
|
||||
loadModelData(model) {
|
||||
loadICData(config) {
|
||||
AppDispatcher.dispatch({
|
||||
type: 'icData/prepare',
|
||||
inputLength: parseInt(model.inputLength, 10),
|
||||
outputLength: parseInt(model.outputLength, 10),
|
||||
id: model.icID
|
||||
inputLength: parseInt(config.inputLength, 10),
|
||||
outputLength: parseInt(config.outputLength, 10),
|
||||
id: config.icID
|
||||
});
|
||||
}
|
||||
|
||||
loadSignals(token, models){
|
||||
loadSignals(token, configs){
|
||||
|
||||
for (let model of models) {
|
||||
for (let config of configs) {
|
||||
// request in signals
|
||||
RestAPI.get(this.makeURL('/signals?direction=in&modelID=' + model.id), token).then(response => {
|
||||
RestAPI.get(this.makeURL('/signals?direction=in&configID=' + config.id), token).then(response => {
|
||||
AppDispatcher.dispatch({
|
||||
type: 'signals/loaded',
|
||||
data: response.signals
|
||||
|
@ -55,7 +55,7 @@ class SimulationModelDataManager extends RestDataManager {
|
|||
});
|
||||
|
||||
// request out signals
|
||||
RestAPI.get(this.makeURL('/signals?direction=out&modelID=' + model.id), token).then(response => {
|
||||
RestAPI.get(this.makeURL('/signals?direction=out&configID=' + config.id), token).then(response => {
|
||||
AppDispatcher.dispatch({
|
||||
type: 'signals/loaded',
|
||||
data: response.signals
|
||||
|
@ -65,10 +65,10 @@ class SimulationModelDataManager extends RestDataManager {
|
|||
}
|
||||
}
|
||||
|
||||
loadFiles(token, models){
|
||||
for (let model of models) {
|
||||
// request files of simulation model
|
||||
RestAPI.get(this.makeURL('/files?objectType=model&objectID=' + model.id), token).then(response => {
|
||||
loadFiles(token, configs){
|
||||
for (let config of configs) {
|
||||
// request files of config
|
||||
RestAPI.get(this.makeURL('/files?objectType=config&objectID=' + config.id), token).then(response => {
|
||||
AppDispatcher.dispatch({
|
||||
type: 'files/loaded',
|
||||
data: response.files
|
||||
|
@ -78,4 +78,4 @@ class SimulationModelDataManager extends RestDataManager {
|
|||
}
|
||||
}
|
||||
|
||||
export default new SimulationModelDataManager();
|
||||
export default new ConfigDataManager();
|
|
@ -23,7 +23,7 @@ import Dialog from '../common/dialogs/dialog';
|
|||
import ParametersEditor from '../common/parameters-editor';
|
||||
import SelectFile from "../file/select-file";
|
||||
|
||||
class EditSimulationModelDialog extends React.Component {
|
||||
class EditConfigDialog extends React.Component {
|
||||
valid = false;
|
||||
|
||||
constructor(props) {
|
||||
|
@ -35,7 +35,7 @@ class EditSimulationModelDialog extends React.Component {
|
|||
icID: '',
|
||||
configuration: null,
|
||||
startParameters: {},
|
||||
selectedModelFileID:0
|
||||
selectedFileID:0
|
||||
|
||||
};
|
||||
}
|
||||
|
@ -44,22 +44,22 @@ class EditSimulationModelDialog extends React.Component {
|
|||
onClose(canceled) {
|
||||
if (canceled === false) {
|
||||
if (this.valid) {
|
||||
let data = this.props.simulationModel;
|
||||
if (this.state.name !== '' && this.props.simulationModel.name !== this.state.name) {
|
||||
let data = this.props.config;
|
||||
if (this.state.name !== '' && this.props.config.name !== this.state.name) {
|
||||
data.name = this.state.name;
|
||||
}
|
||||
if (this.state.icID !== '' && this.props.simulationModel.icID !== parseInt(this.state.icID)) {
|
||||
if (this.state.icID !== '' && this.props.config.icID !== parseInt(this.state.icID)) {
|
||||
data.icID = parseInt(this.state.icID, 10);
|
||||
}
|
||||
if(this.state.startParameters !== {} && this.props.simulationModel.startParameters !== this.state.startParameters){
|
||||
if(this.state.startParameters !== {} && this.props.config.startParameters !== this.state.startParameters){
|
||||
data.startParameters = this.state.startParameters;
|
||||
}
|
||||
if (parseInt(this.state.selectedModelFileID, 10) !== 0 &&
|
||||
this.props.simulationModel.selectedModelFileID !== parseInt(this.state.selectedModelFileID)) {
|
||||
data.selectedModelFileID = parseInt(this.state.selectedModelFileID, 10);
|
||||
if (parseInt(this.state.selectedFileID, 10) !== 0 &&
|
||||
this.props.config.selectedFileID !== parseInt(this.state.selectedFileID)) {
|
||||
data.selectedFileID = parseInt(this.state.selectedFileID, 10);
|
||||
}
|
||||
|
||||
//forward modified simulation model to callback function
|
||||
//forward modified config to callback function
|
||||
this.props.onClose(data)
|
||||
}
|
||||
} else {
|
||||
|
@ -81,9 +81,9 @@ class EditSimulationModelDialog extends React.Component {
|
|||
this.valid = this.isValid()
|
||||
}
|
||||
|
||||
handleSelectedModelFileChange(newFileID){
|
||||
handleSelectedFileChange(newFileID){
|
||||
console.log("Config file change to: ", newFileID);
|
||||
this.setState({selectedModelFileID: newFileID})
|
||||
this.setState({selectedFileID: newFileID})
|
||||
|
||||
this.valid = this.isValid()
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ class EditSimulationModelDialog extends React.Component {
|
|||
|| this.state.startParameters !== {}
|
||||
|| this.state.selectedFile != null
|
||||
|| this.state.configuration != null
|
||||
|| this.state.selectedModelFileID !== 0;
|
||||
|| this.state.selectedFileID !== 0;
|
||||
}
|
||||
|
||||
resetState() {
|
||||
|
@ -112,7 +112,7 @@ class EditSimulationModelDialog extends React.Component {
|
|||
<form>
|
||||
<FormGroup controlId="name">
|
||||
<FormLabel column={false}>Name</FormLabel>
|
||||
<FormControl type="text" placeholder={this.props.simulationModel.name} value={this.state.name} onChange={(e) => this.handleChange(e)} />
|
||||
<FormControl type="text" placeholder={this.props.config.name} value={this.state.name} onChange={(e) => this.handleChange(e)} />
|
||||
<FormControl.Feedback />
|
||||
</FormGroup>
|
||||
|
||||
|
@ -123,19 +123,11 @@ class EditSimulationModelDialog extends React.Component {
|
|||
</FormControl>
|
||||
</FormGroup>
|
||||
|
||||
|
||||
<SelectFile type='model' name='Configuration File' onChange={(e) => this.handleSelectedModelFileChange(e)} value={this.state.selectedModelFileID} objectID={this.props.simulationModel.id}/>
|
||||
|
||||
|
||||
{/*<SelectFile type='configuration' name='Configuration' onChange={(e) => this.handleChange(e)} value={this.state.configuration} />*/}
|
||||
|
||||
|
||||
|
||||
|
||||
<SelectFile type='config' name='Configuration File' onChange={(e) => this.handleSelectedFileChange(e)} value={this.state.selectedFileID} objectID={this.props.config.id}/>
|
||||
|
||||
<FormGroup controlId='startParameters'>
|
||||
<FormLabel> Start Parameters </FormLabel>
|
||||
<ParametersEditor content={this.props.simulationModel.startParameters} onChange={(data) => this.handleParameterChange(data)} />
|
||||
<ParametersEditor content={this.props.config.startParameters} onChange={(data) => this.handleParameterChange(data)} />
|
||||
</FormGroup>
|
||||
</form>
|
||||
</Dialog>
|
||||
|
@ -143,4 +135,4 @@ class EditSimulationModelDialog extends React.Component {
|
|||
}
|
||||
}
|
||||
|
||||
export default EditSimulationModelDialog;
|
||||
export default EditConfigDialog;
|
|
@ -1,8 +1,4 @@
|
|||
/**
|
||||
* File: import-simulation-model.js
|
||||
* Author: Markus Grigull <mgrigull@eonerc.rwth-aachen.de>
|
||||
* Date: 03.09.2017
|
||||
*
|
||||
* This file is part of VILLASweb.
|
||||
*
|
||||
* VILLASweb is free software: you can redistribute it and/or modify
|
||||
|
@ -25,14 +21,14 @@ import _ from 'lodash';
|
|||
|
||||
import Dialog from '../common/dialogs/dialog';
|
||||
|
||||
class ImportSimulationModelDialog extends React.Component {
|
||||
class ImportConfigDialog extends React.Component {
|
||||
imported = false;
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
this.state = {
|
||||
model: {}
|
||||
config: {}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -43,12 +39,12 @@ class ImportSimulationModelDialog extends React.Component {
|
|||
return;
|
||||
}
|
||||
|
||||
this.props.onClose(this.state.model);
|
||||
this.props.onClose(this.state.config);
|
||||
}
|
||||
|
||||
resetState = () => {
|
||||
this.setState({
|
||||
model: {}
|
||||
config: {}
|
||||
});
|
||||
|
||||
this.imported = false;
|
||||
|
@ -66,24 +62,24 @@ class ImportSimulationModelDialog extends React.Component {
|
|||
const self = this;
|
||||
|
||||
reader.onload = event => {
|
||||
const model = JSON.parse(event.target.result);
|
||||
const config = JSON.parse(event.target.result);
|
||||
|
||||
model.icID = this.props.ics.length > 0 ? this.props.ics[0]._id : null;
|
||||
config.icID = this.props.ics.length > 0 ? this.props.ics[0]._id : null;
|
||||
|
||||
self.imported = true;
|
||||
|
||||
this.setState({ model });
|
||||
this.setState({ config: config });
|
||||
};
|
||||
|
||||
reader.readAsText(file);
|
||||
}
|
||||
|
||||
handleICChange = event => {
|
||||
const model = this.state.model;
|
||||
const config = this.state.config;
|
||||
|
||||
model.icID = event.target.value;
|
||||
config.icID = event.target.value;
|
||||
|
||||
this.setState({ model });
|
||||
this.setState({ config: config });
|
||||
}
|
||||
|
||||
render() {
|
||||
|
@ -97,7 +93,7 @@ class ImportSimulationModelDialog extends React.Component {
|
|||
|
||||
<FormGroup controlId='IC'>
|
||||
<FormLabel>Infrastructure Component</FormLabel>
|
||||
<FormControl disabled={this.imported === false} as='select' placeholder='Select infrastructure component' value={this.state.model.icID} onChange={this.handleICChange}>
|
||||
<FormControl disabled={this.imported === false} as='select' placeholder='Select infrastructure component' value={this.state.config.icID} onChange={this.handleICChange}>
|
||||
{this.props.ics.map(ic => (
|
||||
<option key={ic.id} value={ic.id}>{_.get(ic, 'properties.name') || _.get(ic, 'rawProperties.name')}</option>
|
||||
))}
|
||||
|
@ -109,4 +105,4 @@ class ImportSimulationModelDialog extends React.Component {
|
|||
}
|
||||
}
|
||||
|
||||
export default ImportSimulationModelDialog;
|
||||
export default ImportConfigDialog;
|
|
@ -33,7 +33,6 @@ import DashboardButtonGroup from './dashboard-button-group';
|
|||
|
||||
import LoginStore from '../user/login-store';
|
||||
import DashboardStore from './dashboard-store';
|
||||
//import SimulationModelStore from '../simulationmodel/simulation-model-store';
|
||||
import SignalStore from '../signal/signal-store'
|
||||
import FileStore from '../file/file-store';
|
||||
import WidgetStore from '../widget/widget-store';
|
||||
|
@ -76,11 +75,6 @@ class Dashboard extends Component {
|
|||
return thisWidgetHeight > maxHeightSoFar? thisWidgetHeight : maxHeightSoFar;
|
||||
}, 0);
|
||||
|
||||
//let simulationModels = [];
|
||||
//if (prevState.simulation != null) {
|
||||
// simulationModels = SimulationModelStore.getState().filter(m => prevState.simulation.models.includes(m._id));
|
||||
//}
|
||||
|
||||
// TODO filter signals to the ones belonging to the scenario at hand!
|
||||
let signals = SignalStore.getState();
|
||||
|
||||
|
|
|
@ -68,8 +68,8 @@ class ImportDashboardDialog extends React.Component {
|
|||
const dashboard = JSON.parse(event.target.result);
|
||||
|
||||
/*let defaultIC = "";
|
||||
if (self.props.simulation.models != null) {
|
||||
defaultIC = self.props.simulation.models[0].icID;
|
||||
if (self.props.configs != null) {
|
||||
defaultIC = self.props.configs[0].icID;
|
||||
}
|
||||
|
||||
dashboard.widgets.forEach(widget => {
|
||||
|
|
|
@ -38,7 +38,7 @@ class SelectFile extends React.Component {
|
|||
static calculateState(prevState, props) {
|
||||
|
||||
let files = FileStore.getState().filter((file) => {
|
||||
return (file.simulationModelID === props.objectID)
|
||||
return (file.configID === props.objectID)
|
||||
});
|
||||
|
||||
console.log("props.objectID=", props.objectID)
|
||||
|
@ -111,7 +111,7 @@ class SelectFile extends React.Component {
|
|||
<option key={f.id} value={f.id}>{f.name}</option>
|
||||
);
|
||||
} else {
|
||||
fileOptions = <option >No files for this simulation model</option>
|
||||
fileOptions = <option >No files for this component config</option>
|
||||
}
|
||||
|
||||
/*const progressBarStyle = {
|
||||
|
|
|
@ -35,7 +35,7 @@ class ImportScenarioDialog extends React.Component {
|
|||
this.state = {
|
||||
name: '',
|
||||
running: '',
|
||||
simulationModels: [],
|
||||
configs: [],
|
||||
startParameters: {}
|
||||
};
|
||||
}
|
||||
|
@ -56,10 +56,10 @@ class ImportScenarioDialog extends React.Component {
|
|||
|
||||
handleChange(e, index) {
|
||||
/*if (e.target.id === 'icID') {
|
||||
const models = this.state.models;
|
||||
models[index].icID = JSON.parse(e.target.value);
|
||||
const configs = this.state.configs;
|
||||
configs[index].icID = JSON.parse(e.target.value);
|
||||
|
||||
this.setState({ models });
|
||||
this.setState({ configs: configs });
|
||||
|
||||
return;
|
||||
}*/
|
||||
|
@ -77,7 +77,7 @@ class ImportScenarioDialog extends React.Component {
|
|||
}
|
||||
|
||||
resetState = () => {
|
||||
this.setState({ name: '', models: [], startParameters: {} });
|
||||
this.setState({ name: '', configs: [], startParameters: {} });
|
||||
|
||||
this.imported = false;
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ class ImportScenarioDialog extends React.Component {
|
|||
|
||||
self.imported = true;
|
||||
self.valid = true;
|
||||
self.setState({ name: scenario.name, models: scenario.simulationModels, startParameters: scenario.startParameters, running: scenario.running });
|
||||
self.setState({ name: scenario.name, configs: scenario.configs, startParameters: scenario.startParameters, running: scenario.running });
|
||||
};
|
||||
|
||||
reader.readAsText(file);
|
||||
|
|
|
@ -24,7 +24,7 @@ import _ from 'lodash';
|
|||
import ScenarioStore from './scenario-store';
|
||||
import ICStore from '../ic/ic-store';
|
||||
import DashboardStore from '../dashboard/dashboard-store';
|
||||
import SimulationModelStore from '../simulationmodel/simulation-model-store';
|
||||
import ConfigStore from '../componentconfig/config-store';
|
||||
import LoginStore from '../user/login-store';
|
||||
import SignalStore from '../signal/signal-store'
|
||||
import AppDispatcher from '../common/app-dispatcher';
|
||||
|
@ -32,19 +32,19 @@ import AppDispatcher from '../common/app-dispatcher';
|
|||
import Icon from '../common/icon';
|
||||
import Table from '../common/table';
|
||||
import TableColumn from '../common/table-column';
|
||||
import ImportSimulationModelDialog from '../simulationmodel/import-simulation-model';
|
||||
import ImportConfigDialog from '../componentconfig/import-config';
|
||||
import ImportDashboardDialog from "../dashboard/import-dashboard";
|
||||
import NewDashboardDialog from "../dashboard/new-dashboard";
|
||||
|
||||
import ICAction from '../ic/ic-action';
|
||||
import DeleteDialog from '../common/dialogs/delete-dialog';
|
||||
import EditSimulationModelDialog from "../simulationmodel/edit-simulation-model";
|
||||
import EditConfigDialog from "../componentconfig/edit-config";
|
||||
import EditSignalMapping from "../signal/edit-signal-mapping";
|
||||
import FileStore from "../file/file-store"
|
||||
|
||||
class Scenario extends React.Component {
|
||||
static getStores() {
|
||||
return [ ScenarioStore, SimulationModelStore, DashboardStore, ICStore, LoginStore, SignalStore, FileStore];
|
||||
return [ ScenarioStore, ConfigStore, DashboardStore, ICStore, LoginStore, SignalStore, FileStore];
|
||||
}
|
||||
|
||||
static calculateState(prevState, props) {
|
||||
|
@ -63,8 +63,8 @@ class Scenario extends React.Component {
|
|||
// obtain all dashboards of a scenario
|
||||
let dashboards = DashboardStore.getState().filter(dashb => dashb.scenarioID === parseInt(props.match.params.scenario, 10));
|
||||
|
||||
// obtain all simulation models of a scenario
|
||||
let simulationModels = SimulationModelStore.getState().filter(simmodel => simmodel.scenarioID === parseInt(props.match.params.scenario, 10));
|
||||
// obtain all component configurations of a scenario
|
||||
let configs = ConfigStore.getState().filter(config => config.scenarioID === parseInt(props.match.params.scenario, 10));
|
||||
|
||||
let signals = SignalStore.getState();
|
||||
let files = FileStore.getState();
|
||||
|
@ -73,18 +73,18 @@ class Scenario extends React.Component {
|
|||
return {
|
||||
scenario,
|
||||
sessionToken,
|
||||
simulationModels,
|
||||
configs: configs,
|
||||
dashboards,
|
||||
signals,
|
||||
files,
|
||||
ics: ICStore.getState(),
|
||||
|
||||
deleteSimulationModelModal: false,
|
||||
importSimulationModelModal: false,
|
||||
editSimulationModelModal: false,
|
||||
modalSimulationModelData: {},
|
||||
selectedSimulationModels: [],
|
||||
modalSimulationModelIndex: 0,
|
||||
deleteConfigModal: false,
|
||||
importConfigModal: false,
|
||||
editConfigModal: false,
|
||||
modalConfigData: {},
|
||||
selectedConfigs: [],
|
||||
modalConfigIndex: 0,
|
||||
|
||||
editOutputSignalsModal: false,
|
||||
editInputSignalsModal: false,
|
||||
|
@ -105,9 +105,9 @@ class Scenario extends React.Component {
|
|||
token: this.state.sessionToken
|
||||
});
|
||||
|
||||
// load simulation models for selected scenario
|
||||
// load component configurations for selected scenario
|
||||
AppDispatcher.dispatch({
|
||||
type: 'simulationModels/start-load',
|
||||
type: 'configs/start-load',
|
||||
token: this.state.sessionToken,
|
||||
param: '?scenarioID='+this.state.scenario.id,
|
||||
});
|
||||
|
@ -119,7 +119,7 @@ class Scenario extends React.Component {
|
|||
param: '?scenarioID='+this.state.scenario.id,
|
||||
});
|
||||
|
||||
// load ICs to enable that simulation models work with them
|
||||
// load ICs to enable that component configs work with them
|
||||
AppDispatcher.dispatch({
|
||||
type: 'ics/start-load',
|
||||
token: this.state.sessionToken,
|
||||
|
@ -129,20 +129,20 @@ class Scenario extends React.Component {
|
|||
}
|
||||
|
||||
/* ##############################################
|
||||
* Simulation Model modification methods
|
||||
* Component Configuration modification methods
|
||||
############################################## */
|
||||
|
||||
addSimulationModel(){
|
||||
const simulationModel = {
|
||||
addConfig(){
|
||||
const config = {
|
||||
scenarioID: this.state.scenario.id,
|
||||
name: 'New Simulation Model',
|
||||
name: 'New Component Configuration',
|
||||
icID: this.state.ics.length > 0 ? this.state.ics[0].id : null,
|
||||
startParameters: {},
|
||||
};
|
||||
|
||||
AppDispatcher.dispatch({
|
||||
type: 'simulationModels/start-add',
|
||||
data: simulationModel,
|
||||
type: 'configs/start-add',
|
||||
data: config,
|
||||
token: this.state.sessionToken
|
||||
});
|
||||
|
||||
|
@ -155,44 +155,44 @@ class Scenario extends React.Component {
|
|||
});
|
||||
}
|
||||
|
||||
closeEditSimulationModelModal(data){
|
||||
this.setState({ editSimulationModelModal : false });
|
||||
closeEditConfigModal(data){
|
||||
this.setState({ editConfigModal : false });
|
||||
|
||||
if (data) {
|
||||
AppDispatcher.dispatch({
|
||||
type: 'simulationModels/start-edit',
|
||||
type: 'configs/start-edit',
|
||||
data: data,
|
||||
token: this.state.sessionToken,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
closeDeleteSimulationModelModal(confirmDelete) {
|
||||
this.setState({ deleteSimulationModelModal: false });
|
||||
closeDeleteConfigModal(confirmDelete) {
|
||||
this.setState({ deleteConfigModal: false });
|
||||
|
||||
if (confirmDelete === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
AppDispatcher.dispatch({
|
||||
type: 'simulationModels/start-remove',
|
||||
data: this.state.modalSimulationModelData,
|
||||
type: 'configs/start-remove',
|
||||
data: this.state.modalConfigData,
|
||||
token: this.state.sessionToken
|
||||
});
|
||||
}
|
||||
|
||||
importSimulationModel(simulationModel){
|
||||
this.setState({ importSimulationModelModal: false });
|
||||
importConfig(config){
|
||||
this.setState({ importConfigModal: false });
|
||||
|
||||
if (simulationModel == null) {
|
||||
if (config == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
simulationModel.scenario = this.state.scenario.id;
|
||||
config.scenario = this.state.scenario.id;
|
||||
|
||||
AppDispatcher.dispatch({
|
||||
type: 'simulationModels/start-add',
|
||||
data: simulationModel,
|
||||
type: 'configs/start-add',
|
||||
data: config,
|
||||
token: this.state.sessionToken
|
||||
});
|
||||
|
||||
|
@ -205,27 +205,27 @@ class Scenario extends React.Component {
|
|||
});
|
||||
}
|
||||
|
||||
exportModel(index) {
|
||||
exportConfig(index) {
|
||||
// filter properties
|
||||
const model = Object.assign({}, this.state.simulationModels[index]);
|
||||
const config = Object.assign({}, this.state.configs[index]);
|
||||
|
||||
// show save dialog
|
||||
const blob = new Blob([JSON.stringify(model, null, 2)], { type: 'application/json' });
|
||||
FileSaver.saveAs(blob, 'simulation model - ' + model.name + '.json');
|
||||
const blob = new Blob([JSON.stringify(config, null, 2)], { type: 'application/json' });
|
||||
FileSaver.saveAs(blob, 'config-' + config.name + '.json');
|
||||
}
|
||||
|
||||
onSimulationModelChecked(index, event) {
|
||||
const selectedSimulationModels = Object.assign([], this.state.selectedSimulationModels);
|
||||
for (let key in selectedSimulationModels) {
|
||||
if (selectedSimulationModels[key] === index) {
|
||||
onConfigChecked(index, event) {
|
||||
const selectedConfigs = Object.assign([], this.state.selectedConfigs);
|
||||
for (let key in selectedConfigs) {
|
||||
if (selectedConfigs[key] === index) {
|
||||
// update existing entry
|
||||
if (event.target.checked) {
|
||||
return;
|
||||
}
|
||||
|
||||
selectedSimulationModels.splice(key, 1);
|
||||
selectedConfigs.splice(key, 1);
|
||||
|
||||
this.setState({ selectedSimulationModels });
|
||||
this.setState({ selectedConfigs: selectedConfigs });
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -235,16 +235,16 @@ class Scenario extends React.Component {
|
|||
return;
|
||||
}
|
||||
|
||||
selectedSimulationModels.push(index);
|
||||
this.setState({ selectedSimulationModels });
|
||||
selectedConfigs.push(index);
|
||||
this.setState({ selectedConfigs: selectedConfigs });
|
||||
}
|
||||
|
||||
runAction = action => {
|
||||
for (let index of this.state.selectedSimulationModels) {
|
||||
// get IC for model
|
||||
for (let index of this.state.selectedConfigs) {
|
||||
// get IC for component config
|
||||
let ic = null;
|
||||
for (let component of this.state.ics) {
|
||||
if (component._id === this.state.simulationModels[index].icID) {
|
||||
if (component._id === this.state.configs[index].icID) {
|
||||
ic = component;
|
||||
}
|
||||
}
|
||||
|
@ -254,7 +254,7 @@ class Scenario extends React.Component {
|
|||
}
|
||||
|
||||
if (action.data.action === 'start') {
|
||||
action.data.parameters = this.state.simulationModels[index].startParameters;
|
||||
action.data.parameters = this.state.configs[index].startParameters;
|
||||
}
|
||||
|
||||
AppDispatcher.dispatch({
|
||||
|
@ -345,7 +345,7 @@ class Scenario extends React.Component {
|
|||
}
|
||||
|
||||
closeNewSignalModal(data){
|
||||
//data contains the new signal incl. simulationModelID and direction
|
||||
//data contains the new signal incl. configID and direction
|
||||
if (data) {
|
||||
AppDispatcher.dispatch({
|
||||
type: 'signals/start-add',
|
||||
|
@ -406,21 +406,21 @@ class Scenario extends React.Component {
|
|||
|
||||
{/*Component Configurations table*/}
|
||||
<h2>Component Configurations</h2>
|
||||
<Table data={this.state.simulationModels}>
|
||||
<TableColumn checkbox onChecked={(index, event) => this.onSimulationModelChecked(index, event)} width='30' />
|
||||
<Table data={this.state.configs}>
|
||||
<TableColumn checkbox onChecked={(index, event) => this.onConfigChecked(index, event)} width='30' />
|
||||
<TableColumn title='Name' dataKey='name' />
|
||||
<TableColumn title='Selected configuration file' dataKey='selectedModelFileID' modifier={(selectedModelFileID) => this.getFileName(selectedModelFileID)}/>
|
||||
<TableColumn title='Selected configuration file' dataKey='selectedFileID' modifier={(selectedFileID) => this.getFileName(selectedFileID)}/>
|
||||
<TableColumn
|
||||
title='# Output Signals'
|
||||
dataKey='outputLength'
|
||||
editButton
|
||||
onEdit={index => this.setState({ editOutputSignalsModal: true, modalSimulationModelData: this.state.simulationModels[index], modalSimulationModelIndex: index })}
|
||||
onEdit={index => this.setState({ editOutputSignalsModal: true, modalConfigData: this.state.configs[index], modalConfigIndex: index })}
|
||||
/>
|
||||
<TableColumn
|
||||
title='# Input Signals'
|
||||
dataKey='inputLength'
|
||||
editButton
|
||||
onEdit={index => this.setState({ editInputSignalsModal: true, modalSimulationModelData: this.state.simulationModels[index], modalSimulationModelIndex: index })}
|
||||
onEdit={index => this.setState({ editInputSignalsModal: true, modalConfigData: this.state.configs[index], modalConfigIndex: index })}
|
||||
/>
|
||||
<TableColumn title='Infrastructure Component' dataKey='icID' modifier={(icID) => this.getICName(icID)} />
|
||||
<TableColumn
|
||||
|
@ -429,15 +429,15 @@ class Scenario extends React.Component {
|
|||
editButton
|
||||
deleteButton
|
||||
exportButton
|
||||
onEdit={index => this.setState({ editSimulationModelModal: true, modalSimulationModelData: this.state.simulationModels[index], modalSimulationModelIndex: index })}
|
||||
onDelete={(index) => this.setState({ deleteSimulationModelModal: true, modalSimulationModelData: this.state.simulationModels[index], modalSimulationModelIndex: index })}
|
||||
onExport={index => this.exportModel(index)}
|
||||
onEdit={index => this.setState({ editConfigModal: true, modalConfigData: this.state.configs[index], modalConfigIndex: index })}
|
||||
onDelete={(index) => this.setState({ deleteConfigModal: true, modalConfigData: this.state.configs[index], modalConfigIndex: index })}
|
||||
onExport={index => this.exportConfig(index)}
|
||||
/>
|
||||
</Table>
|
||||
|
||||
<div style={{ float: 'left' }}>
|
||||
<ICAction
|
||||
runDisabled={this.state.selectedSimulationModels.length === 0}
|
||||
runDisabled={this.state.selectedConfigs.length === 0}
|
||||
runAction={this.runAction}
|
||||
actions={[
|
||||
{ id: '0', title: 'Start', data: { action: 'start' } },
|
||||
|
@ -448,15 +448,15 @@ class Scenario extends React.Component {
|
|||
</div>
|
||||
|
||||
<div style={{ float: 'right' }}>
|
||||
<Button onClick={() => this.addSimulationModel()} style={buttonStyle}><Icon icon="plus" /> Simulation Model</Button>
|
||||
<Button onClick={() => this.setState({ importSimulationModelModal: true })} style={buttonStyle}><Icon icon="upload" /> Import</Button>
|
||||
<Button onClick={() => this.addConfig()} style={buttonStyle}><Icon icon="plus" /> Component Configuration</Button>
|
||||
<Button onClick={() => this.setState({ importConfigModal: true })} style={buttonStyle}><Icon icon="upload" /> Import</Button>
|
||||
</div>
|
||||
|
||||
<div style={{ clear: 'both' }} />
|
||||
|
||||
<EditSimulationModelDialog show={this.state.editSimulationModelModal} onClose={data => this.closeEditSimulationModelModal(data)} simulationModel={this.state.modalSimulationModelData} ics={this.state.ics} />
|
||||
<ImportSimulationModelDialog show={this.state.importSimulationModelModal} onClose={data => this.importSimulationModel(data)} ics={this.state.ics} />
|
||||
<DeleteDialog title="component configuration" name={this.state.modalSimulationModelData.name} show={this.state.deleteSimulationModelModal} onClose={(c) => this.closeDeleteSimulationModelModal(c)} />
|
||||
<EditConfigDialog show={this.state.editConfigModal} onClose={data => this.closeEditConfigModal(data)} config={this.state.modalConfigData} ics={this.state.ics} />
|
||||
<ImportConfigDialog show={this.state.importConfigModal} onClose={data => this.importConfig(data)} ics={this.state.ics} />
|
||||
<DeleteDialog title="component configuration" name={this.state.modalConfigData.name} show={this.state.deleteConfigModal} onClose={(c) => this.closeDeleteConfigModal(c)} />
|
||||
|
||||
<EditSignalMapping
|
||||
show={this.state.editOutputSignalsModal}
|
||||
|
@ -465,7 +465,7 @@ class Scenario extends React.Component {
|
|||
onDelete={(data) => this.closeDeleteSignalModal(data)}
|
||||
direction="Output"
|
||||
signals={this.state.signals}
|
||||
simulationModelID={this.state.modalSimulationModelData.id} />
|
||||
configID={this.state.modalConfigData.id} />
|
||||
<EditSignalMapping
|
||||
show={this.state.editInputSignalsModal}
|
||||
onCloseEdit={(data, direction) => this.closeEditSignalsModal(data, direction)}
|
||||
|
@ -473,7 +473,7 @@ class Scenario extends React.Component {
|
|||
onDelete={(data) => this.closeDeleteSignalModal(data)}
|
||||
direction="Input"
|
||||
signals={this.state.signals}
|
||||
simulationModelID={this.state.modalSimulationModelData.id}/>
|
||||
configID={this.state.modalConfigData.id}/>
|
||||
|
||||
{/*Dashboard table*/}
|
||||
<h2>Dashboards</h2>
|
||||
|
|
|
@ -1,8 +1,4 @@
|
|||
/**
|
||||
* File: scenarios-data-manager.js
|
||||
* Author: Sonja Happ <sonja.happ@eonerc.rwth-aachen.de>
|
||||
* Date: 20.08.2019
|
||||
*
|
||||
* This file is part of VILLASweb.
|
||||
*
|
||||
* VILLASweb is free software: you can redistribute it and/or modify
|
||||
|
@ -25,18 +21,18 @@ import AppDispatcher from "../common/app-dispatcher";
|
|||
|
||||
class ScenariosDataManager extends RestDataManager {
|
||||
constructor() {
|
||||
super('scenario', '/scenarios', ['id', 'name', 'running', 'simulationModelIDs', 'userIDs', 'dashboardIDs', 'startParameters' ]);
|
||||
super('scenario', '/scenarios');
|
||||
}
|
||||
|
||||
getSimulationModels(token, id) {
|
||||
RestAPI.get(this.makeURL('/scenarios/' + id + '/models'), token).then(response => {
|
||||
getComponentConfigs(token, id) {
|
||||
RestAPI.get(this.makeURL('/scenarios/' + id + '/configs'), token).then(response => {
|
||||
AppDispatcher.dispatch({
|
||||
type: 'scenarios/simulationmodels',
|
||||
simulationmodels: response.models
|
||||
type: 'scenarios/configs',
|
||||
configs: response.configs
|
||||
});
|
||||
}).catch(error => {
|
||||
AppDispatcher.dispatch({
|
||||
type: 'scenarios/simulationmodels-error',
|
||||
type: 'scenarios/configs-error',
|
||||
error: error
|
||||
});
|
||||
});
|
||||
|
|
|
@ -158,7 +158,7 @@ class Scenarios extends Component {
|
|||
let scenario = Object.assign({}, this.state.scenarios[index]);
|
||||
delete scenario.id;
|
||||
|
||||
// TODO request missing scenario parameters (Dashboards and Simulation Modles) recursively for export
|
||||
// TODO request missing scenario parameters (Dashboards and component configs) recursively for export
|
||||
|
||||
// show save dialog
|
||||
const blob = new Blob([JSON.stringify(scenario, null, 2)], { type: 'application/json' });
|
||||
|
|
|
@ -52,9 +52,9 @@ class EditSignalMapping extends React.Component {
|
|||
|
||||
static getDerivedStateFromProps(props, state){
|
||||
|
||||
// filter all signals by Simulation Model ID and direction
|
||||
// filter all signals by configID and direction
|
||||
let signals = props.signals.filter((sig) => {
|
||||
return (sig.simulationModelID === props.simulationModelID) && (sig.direction === state.dir);
|
||||
return (sig.configID === props.configID) && (sig.direction === state.dir);
|
||||
});
|
||||
|
||||
return {
|
||||
|
@ -115,7 +115,7 @@ class EditSignalMapping extends React.Component {
|
|||
console.log("add signal");
|
||||
|
||||
let newSignal = {
|
||||
simulationModelID: this.props.simulationModelID,
|
||||
configID: this.props.configID,
|
||||
direction: this.state.dir,
|
||||
name: "PlaceholderName",
|
||||
unit: "PlaceholderUnit",
|
||||
|
@ -130,7 +130,7 @@ class EditSignalMapping extends React.Component {
|
|||
this.valid=false;
|
||||
|
||||
let signals = this.props.signals.filter((sig) => {
|
||||
return (sig.simulationModelID === this.props.simulationModelID) && (sig.direction === this.state.dir);
|
||||
return (sig.configID === this.props.configID) && (sig.direction === this.state.dir);
|
||||
});
|
||||
|
||||
this.setState({signals: signals})
|
||||
|
@ -173,7 +173,7 @@ EditSignalMapping.propTypes = {
|
|||
name: PropTypes.string.isRequired,
|
||||
unit: PropTypes.string.isRequired,
|
||||
direction: PropTypes.string.isRequired,
|
||||
simulationModelID: PropTypes.number.isRequired,
|
||||
configID: PropTypes.number.isRequired,
|
||||
index: PropTypes.number.isRequired
|
||||
|
||||
})
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
/**
|
||||
* File: signal-store.js
|
||||
*
|
||||
* This file is part of VILLASweb.
|
||||
*
|
||||
* VILLASweb is free software: you can redistribute it and/or modify
|
||||
|
@ -28,10 +26,10 @@ class SignalStore extends ArrayStore{
|
|||
reduce(state, action) {
|
||||
switch (action.type) {
|
||||
case 'signals/added':
|
||||
SignalsDataManager.reloadSimulationModel(action.token, action.data);
|
||||
SignalsDataManager.reloadConfig(action.token, action.data);
|
||||
return super.reduce(state, action);
|
||||
case 'signals/removed':
|
||||
SignalsDataManager.reloadSimulationModel(action.token, action.data);
|
||||
SignalsDataManager.reloadConfig(action.token, action.data);
|
||||
return super.reduce(state, action);
|
||||
|
||||
default:
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
/**
|
||||
* File: signals-data-manager.js
|
||||
*
|
||||
* This file is part of VILLASweb.
|
||||
*
|
||||
* VILLASweb is free software: you can redistribute it and/or modify
|
||||
|
@ -27,13 +25,13 @@ class SignalsDataManager extends RestDataManager{
|
|||
super('signal', '/signals');
|
||||
}
|
||||
|
||||
reloadSimulationModel(token, data){
|
||||
reloadConfig(token, data){
|
||||
// request in signals
|
||||
console.log("Reloading simulation model due to signal add/remove")
|
||||
RestAPI.get(this.makeURL('/models/' + data.simulationModelID), token).then(response => {
|
||||
console.log("Reloading component config due to signal add/remove")
|
||||
RestAPI.get(this.makeURL('/configs/' + data.configID), token).then(response => {
|
||||
AppDispatcher.dispatch({
|
||||
type: 'simulationModels/edited',
|
||||
data: response.simulationModel
|
||||
type: 'configs/edited',
|
||||
data: response.config
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -1,64 +0,0 @@
|
|||
/**
|
||||
* File: edit-widget-simulation-control.js
|
||||
* Author: Ricardo Hernandez-Montoya <rhernandez@gridhound.de>
|
||||
* Date: 03.04.2017
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
**********************************************************************************/
|
||||
|
||||
import React, { Component } from 'react';
|
||||
import { FormGroup, FormControl, FormLabel } from 'react-bootstrap';
|
||||
|
||||
class EditWidgetSimulationControl extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
this.state = {
|
||||
widget: {
|
||||
customProperties: {
|
||||
simulationModel: ''
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
static getDerivedStateFromProps(props, state){
|
||||
return{
|
||||
widget: props.widget
|
||||
};
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<FormGroup controlId="simulationModel">
|
||||
<FormLabel>Simulation Model</FormLabel>
|
||||
<FormControl as="select" placeholder="Select simulation model" value={this.state.widget.simulationModel || '' } onChange={(e) => this.props.handleChange(e)}>
|
||||
{
|
||||
this.props.simulationModels.length === 0 ? (
|
||||
<option disabled value style={{ display: 'none' }}> No simulation models available. </option>
|
||||
) : (
|
||||
this.props.simulationModels.map((model, index) => (
|
||||
<option key={index} value={model._id}>{model.name}</option>
|
||||
)))
|
||||
}
|
||||
</FormControl>
|
||||
</FormGroup>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default EditWidgetSimulationControl;
|
|
@ -25,7 +25,7 @@ import { Container } from 'flux/utils';
|
|||
import AppDispatcher from '../common/app-dispatcher';
|
||||
import LoginStore from '../user/login-store';
|
||||
import ICDataStore from '../ic/ic-data-store';
|
||||
import SimulationModelStore from '../simulationmodel/simulation-model-store';
|
||||
import ConfigsStore from '../componentconfig/config-store';
|
||||
import FileStore from '../file/file-store';
|
||||
import SignalStore from '../signal/signal-store'
|
||||
|
||||
|
@ -53,7 +53,7 @@ import '../styles/widgets.css';
|
|||
|
||||
class Widget extends React.Component {
|
||||
static getStores() {
|
||||
return [ ICDataStore, SimulationModelStore, FileStore, LoginStore, SignalStore];
|
||||
return [ ICDataStore, ConfigsStore, FileStore, LoginStore, SignalStore];
|
||||
}
|
||||
|
||||
static calculateState(prevState, props) {
|
||||
|
@ -69,15 +69,15 @@ class Widget extends React.Component {
|
|||
}
|
||||
|
||||
// Get the IC IDs and signal indexes for all signals of the widget
|
||||
let simulationModels = SimulationModelStore.getState();
|
||||
let configs = ConfigsStore.getState();
|
||||
// TODO make sure that the signals are only the signals that belong to the scenario at hand
|
||||
let signals = SignalStore.getState();
|
||||
let icIDs = [];
|
||||
if ( props.data.signalIDs.length > 0){
|
||||
for (let i in props.data.signalIDs.length){
|
||||
let signal = signals.find(s => s.id === props.data.signalIDs[i]);
|
||||
let model = simulationModels.find(m => m.id === signal.simulationModelID);
|
||||
icIDs[i] = model.icID;
|
||||
let config = configs.find(m => m.id === signal.configID);
|
||||
icIDs[i] = config.icID;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,10 +105,10 @@ class Widget extends React.Component {
|
|||
param: '?objectID=1&objectType=widget'
|
||||
});*/
|
||||
|
||||
// TODO no not load simulation models here, since they are loaded via the scenario, pass them as props
|
||||
// TODO no not load component congfigs here, since they are loaded via the scenario, pass them as props
|
||||
/*
|
||||
AppDispatcher.dispatch({
|
||||
type: 'simulationModels/start-load',
|
||||
type: 'configs/start-load',
|
||||
token: this.state.sessionToken,
|
||||
param: '?scenarioID=1' // TODO do not hardcode scenarioID!
|
||||
});
|
||||
|
|
|
@ -37,7 +37,7 @@ class WidgetPlotTable extends Component {
|
|||
}
|
||||
|
||||
componentDidUpdate(prevProps: Readonly<P>, prevState: Readonly<S>, snapshot: SS): void {
|
||||
if (this.props.simulationModel == null) {
|
||||
if (this.props.config == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -64,18 +64,18 @@ class WidgetPlotTable extends Component {
|
|||
}
|
||||
|
||||
updatePreselectedSignalsState(props) {
|
||||
// Create checkboxes using the signal indices from simulation model
|
||||
if(props.simulationModel.outputMapping){
|
||||
const preselectedSignals = props.simulationModel.outputMapping.reduce(
|
||||
// Loop through simulation model signals
|
||||
(accum, model_signal, signal_index) => {
|
||||
// Create checkboxes using the signal indices from component config
|
||||
if(props.config.outputMapping){
|
||||
const preselectedSignals = props.config.outputMapping.reduce(
|
||||
// Loop through component config signals
|
||||
(accum, signal, signal_index) => {
|
||||
// Append them if they belong to the current selected type
|
||||
if (props.widget.customProperties.preselectedSignals.indexOf(signal_index) > -1) {
|
||||
accum.push(
|
||||
{
|
||||
index: signal_index,
|
||||
name: model_signal.name,
|
||||
type: model_signal.type
|
||||
name: signal.name,
|
||||
type: signal.type
|
||||
}
|
||||
)
|
||||
}
|
||||
|
@ -98,11 +98,11 @@ class WidgetPlotTable extends Component {
|
|||
let checkBoxes = [];
|
||||
|
||||
// Data passed to plot
|
||||
if (this.props.simulationModel == null) {
|
||||
if (this.props.config == null) {
|
||||
return <div />;
|
||||
}
|
||||
|
||||
const ic = this.props.simulationModel.icID;
|
||||
const ic = this.props.config.icID;
|
||||
let icData = [];
|
||||
|
||||
if (this.props.data[ic] != null && this.props.data[ic].output != null && this.props.data[ic].output.values != null) {
|
||||
|
@ -112,7 +112,7 @@ class WidgetPlotTable extends Component {
|
|||
}
|
||||
|
||||
if (this.state.preselectedSignals && this.state.preselectedSignals.length > 0) {
|
||||
// Create checkboxes using the signal indices from simulation model
|
||||
// Create checkboxes using the signal indices from component config
|
||||
checkBoxes = this.state.preselectedSignals.map( (signal) => {
|
||||
var checked = this.state.signals.indexOf(signal.index) > -1;
|
||||
var chkBxClasses = classNames({
|
||||
|
|
|
@ -1,8 +1,4 @@
|
|||
/**
|
||||
* File: plot.js
|
||||
* Author: Markus Grigull <mgrigull@eonerc.rwth-aachen.de>
|
||||
* Date: 08.03.2017
|
||||
*
|
||||
* This file is part of VILLASweb.
|
||||
*
|
||||
* VILLASweb is free software: you can redistribute it and/or modify
|
||||
|
@ -37,16 +33,16 @@ class WidgetPlot extends React.Component {
|
|||
|
||||
static getDerivedStateFromProps(props, state){
|
||||
|
||||
if (props.simulationModel == null) {
|
||||
if (props.config == null) {
|
||||
return{
|
||||
data: [],
|
||||
legend: [],
|
||||
};
|
||||
}
|
||||
|
||||
const ic = props.simulationModel.icID;
|
||||
const ic = props.config.icID;
|
||||
|
||||
// Proceed if a simulation with models and a IC are available
|
||||
// Proceed if a config and a IC are available
|
||||
if (ic && props.data[ic] != null && props.data[ic] != null && props.data[ic].output != null && props.data[ic].output.values != null) {
|
||||
const chosenSignals = props.widget.customProperties.signals;
|
||||
|
||||
|
@ -55,9 +51,9 @@ class WidgetPlot extends React.Component {
|
|||
));
|
||||
|
||||
// Query the signals that will be displayed in the legend
|
||||
const legend = props.simulationModel.outputMapping.reduce( (accum, model_signal, signal_index) => {
|
||||
const legend = props.config.outputMapping.reduce( (accum, signal, signal_index) => {
|
||||
if (chosenSignals.includes(signal_index)) {
|
||||
accum.push({ index: signal_index, name: model_signal.name, type: model_signal.type });
|
||||
accum.push({ index: signal_index, name: signal.name, type: signal.type });
|
||||
}
|
||||
|
||||
return accum;
|
||||
|
|
Loading…
Add table
Reference in a new issue