diff --git a/src/components/dialog/edit-simulation-model.js b/src/components/dialog/edit-simulation-model.js deleted file mode 100644 index a194ea6..0000000 --- a/src/components/dialog/edit-simulation-model.js +++ /dev/null @@ -1,186 +0,0 @@ -/** - * File: edit-simulation-model.js - * Author: Markus Grigull - * Date: 04.03.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 . - ******************************************************************************/ - -import React from 'react'; -import { FormGroup, FormControl, ControlLabel, HelpBlock } from 'react-bootstrap'; -import _ from 'lodash'; - -import Table from '../table'; -import TableColumn from '../table-column'; -import Dialog from './dialog'; - -class EditSimulationModelDialog extends React.Component { - valid = false; - - constructor(props) { - super(props); - - this.state = { - _id: '', - name: '', - simulator: '', - simulation: '', - outputLength: 1, - inputLength: 1, - outputMapping: [{ name: 'Signal', type: 'Type' }], - inputMapping: [{ name: 'Signal', type: 'Type' }] - } - } - - onClose(canceled) { - if (canceled === false) { - if (this.valid) { - this.props.onClose(this.state); - } - } else { - this.props.onClose(); - } - } - - handleChange(e) { - let mapping = null; - - if (e.target.id === 'outputLength') { - mapping = this.state.outputMapping; - } else if (e.target.id === 'inputLength') { - mapping = this.state.inputMapping; - } - - if (mapping != null) { - // change mapping size - if (e.target.value > mapping.length) { - // add missing signals - while (mapping.length < e.target.value) { - mapping.push({ name: 'Signal', type: 'Type' }); - } - } else { - // remove signals - mapping.splice(e.target.value, mapping.length - e.target.value); - } - } - - this.setState({ [e.target.id]: e.target.value }); - } - - handleMappingChange(key, event, row, column) { - const mapping = this.state[key]; - - if (column === 1) { - mapping[row].name = event.target.value; - } else if (column === 2) { - mapping[row].type = event.target.value; - } - - this.setState({ [key]: mapping }); - } - - resetState() { - this.setState({ - _id: this.props.data._id, - simulation: this.props.data.simulation, - name: this.props.data.name, - simulator: this.props.data.simulator, - outputLength: this.props.data.outputLength, - inputLength: this.props.data.inputLength, - outputMapping: this.props.data.outputMapping, - inputMapping: this.props.data.inputMapping - }); - } - - validateForm(target) { - // check all controls - var name = true; - let inputLength = true; - let outputLength = true; - - if (this.state.name === '') { - name = false; - } - - // test if simulatorid is a number (in a string, not type of number) - if (!/^\d+$/.test(this.state.outputLength)) { - outputLength = false; - } - - if (!/^\d+$/.test(this.state.inputLength)) { - inputLength = false; - } - - this.valid = name && inputLength && outputLength; - - // return state to control - if (target === 'name') return name ? "success" : "error"; - else if (target === 'outputLength') return outputLength ? "success" : "error"; - else if (target === 'inputLength') return inputLength ? "success" : "error"; - } - - render() { - return ( - this.onClose(c)} onReset={() => this.resetState()} valid={this.valid}> -
- - Name - this.handleChange(e)} /> - - - - Simulator - this.handleChange(e)}> - {this.props.simulators.map(simulator => ( - - ))} - - - - Output Length - this.handleChange(e)} /> - - - - Output Mapping - Click Name or Type cell to edit - - - this.handleMappingChange('outputMapping', event, row, column)} /> - this.handleMappingChange('outputMapping', event, row, column)} /> -
-
- - Input Length - this.handleChange(e)} /> - - - - Input Mapping - Click Name or Type cell to edit - - - this.handleMappingChange('inputMapping', event, row, column)} /> - this.handleMappingChange('inputMapping', event, row, column)} /> -
-
-
-
- ); - } -} - -export default EditSimulationModelDialog; diff --git a/src/components/dialog/new-simulation-model.js b/src/components/dialog/new-simulation-model.js deleted file mode 100644 index 40daf9c..0000000 --- a/src/components/dialog/new-simulation-model.js +++ /dev/null @@ -1,182 +0,0 @@ -/** - * File: new-simulation-model.js - * Author: Markus Grigull - * Date: 04.03.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 . - ******************************************************************************/ - -import React from 'react'; -import { FormGroup, FormControl, ControlLabel, HelpBlock } from 'react-bootstrap'; -import _ from 'lodash'; - -import Table from '../table'; -import TableColumn from '../table-column'; -import Dialog from './dialog'; - -class NewSimulationModelDialog extends React.Component { - valid = false; - - constructor(props) { - super(props); - - this.state = { - name: '', - simulator: '', - outputLength: '1', - inputLength: '1', - outputMapping: [ { name: 'Signal', type: 'Type' } ], - inputMapping: [ { name: 'Signal', type: 'Type' } ] - }; - } - - onClose(canceled) { - if (canceled === false) { - if (this.valid) { - this.props.onClose(this.state); - } - } else { - this.props.onClose(); - } - } - - handleChange(e) { - let mapping = null; - - if (e.target.id === 'outputLength') { - mapping = this.state.outputMapping; - } else if (e.target.id === 'inputLength') { - mapping = this.state.inputMapping; - } - - if (mapping != null) { - // change mapping size - if (e.target.value > mapping.length) { - // add missing signals - while (mapping.length < e.target.value) { - mapping.push({ name: 'Signal', type: 'Type' }); - } - } else { - // remove signals - mapping.splice(e.target.value, mapping.length - e.target.value); - } - } - - this.setState({ [e.target.id]: e.target.value }); - } - - handleMappingChange(key, event, row, column) { - const mapping = this.state[key]; - - if (column === 1) { - mapping[row].name = event.target.value; - } else if (column === 2) { - mapping[row].type = event.target.value; - } - - this.setState({ [key]: mapping }); - } - - resetState() { - this.setState({ - name: '', - simulator: this.props.simulators[0]._id || '', - outputLength: '1', - inputLength: '1', - outputMapping: [{ name: 'Signal', type: 'Type' }], - inputMapping: [{ name: 'Signal', type: 'Type' }] - }); - } - - validateForm(target) { - // check all controls - let name = true; - let inputLength = true; - let outputLength = true; - - if (this.state.name === '') { - name = false; - } - - // test if simulatorid is a number (in a string, not type of number) - if (!/^\d+$/.test(this.state.outputLength)) { - outputLength = false; - } - - if (!/^\d+$/.test(this.state.inputLength)) { - inputLength = false; - } - - this.valid = name && inputLength && outputLength; - - // return state to control - if (target === 'name') return name ? "success" : "error"; - else if (target === 'outputLength') return outputLength ? "success" : "error"; - else if (target === 'inputLength') return inputLength ? "success" : "error"; - } - - render() { - return ( - this.onClose(c)} onReset={() => this.resetState()} valid={this.valid}> -
- - Name - this.handleChange(e)} /> - - - - Simulator - this.handleChange(e)}> - {this.props.simulators.map(simulator => ( - - ))} - - - - Output Length - this.handleChange(e)} /> - - - - Output Mapping - Click Name or Type cell to edit - - - this.handleMappingChange('outputMapping', event, row, column)} /> - this.handleMappingChange('outputMapping', event, row, column)} /> -
-
- - Input Length - this.handleChange(e)} /> - - - - Input Mapping - Click Name or Type cell to edit - - - this.handleMappingChange('inputMapping', event, row, column)} /> - this.handleMappingChange('inputMapping', event, row, column)} /> -
-
-
-
- ); - } -} - -export default NewSimulationModelDialog; diff --git a/src/containers/simulation.js b/src/containers/simulation.js index 74e5702..181b7a5 100644 --- a/src/containers/simulation.js +++ b/src/containers/simulation.js @@ -33,8 +33,6 @@ import AppDispatcher from '../app-dispatcher'; import Table from '../components/table'; import TableColumn from '../components/table-column'; -import NewSimulationModelDialog from '../components/dialog/new-simulation-model'; -import EditSimulationModelDialog from '../components/dialog/edit-simulation-model'; import ImportSimulationModelDialog from '../components/dialog/import-simulation-model'; import SimulatorAction from '../components/simulator-action'; @@ -73,12 +71,9 @@ class Simulation extends React.Component { simulators: SimulatorStore.getState(), sessionToken, - newModal: false, deleteModal: false, - editModal: false, importModal: false, modalData: {}, - modalIndex: null, selectedSimulationModels: [] } @@ -101,26 +96,30 @@ class Simulation extends React.Component { }); } - closeNewModal(data) { - this.setState({ newModal : false }); + addSimulationModel = () => { + const simulationModel = { + simulation: this.state.simulation._id, + name: 'New Simulation Model', + simulator: this.state.simulators.length > 0 ? this.state.simulators[0]._id : null, + outputLength: 1, + outputMapping: [{ name: 'Signal', type: 'Type' }], + inputLength: 1, + inputMapping: [{ name: 'Signal', type: 'Type' }] + }; - if (data) { - data.simulation = this.state.simulation._id; + AppDispatcher.dispatch({ + type: 'simulationModels/start-add', + data: simulationModel, + token: this.state.sessionToken + }); + this.setState({ simulation: {} }, () => { AppDispatcher.dispatch({ - type: 'simulationModels/start-add', - data, + type: 'simulations/start-load', + data: this.props.match.params.simulation, token: this.state.sessionToken }); - - this.setState({ simulation: {} }, () => { - AppDispatcher.dispatch({ - type: 'simulations/start-load', - data: this.props.match.params.simulation, - token: this.state.sessionToken - }); - }); - } + }); } closeDeleteModal = confirmDelete => { @@ -137,18 +136,6 @@ class Simulation extends React.Component { }); } - closeEditModal(data) { - this.setState({ editModal : false }); - - if (data) { - AppDispatcher.dispatch({ - type: 'simulationModels/start-edit', - data, - token: this.state.sessionToken - }); - } - } - closeImportModal(data) { this.setState({ importModal: false }); @@ -239,52 +226,52 @@ class Simulation extends React.Component { } render() { - return ( -
-

{this.state.simulation.name}

+ const buttonStyle = { + marginLeft: '10px' + }; - - this.onSimulationModelChecked(index, event)} width='30' /> - - this.getSimulatorName(simulator)} /> - - - this.setState({ editModal: true, modalData: this.state.simulationModels[index], modalIndex: index })} - onDelete={(index) => this.setState({ deleteModal: true, modalData: this.state.simulationModels[index], modalIndex: index })} - onExport={index => this.exportModel(index)} - /> -
+ return
+

{this.state.simulation.name}

-
- -
+ + this.onSimulationModelChecked(index, event)} width='30' /> + + this.getSimulatorName(simulator)} /> + + + this.setState({ deleteModal: true, modalData: this.state.simulationModels[index], modalIndex: index })} + onExport={index => this.exportModel(index)} + /> +
-
- - -
- - this.closeNewModal(data)} simulators={this.state.simulators} /> - this.closeEditModal(data)} data={this.state.modalData} simulators={this.state.simulators} /> - this.closeImportModal(data)} simulators={this.state.simulators} /> - - +
+
- ); + +
+ + +
+ +
+ + this.closeImportModal(data)} simulators={this.state.simulators} /> + + +
; } }