diff --git a/src/dashboard/dashboard.js b/src/dashboard/dashboard.js index bb67b97..763b827 100644 --- a/src/dashboard/dashboard.js +++ b/src/dashboard/dashboard.js @@ -34,8 +34,6 @@ import DashboardButtonGroup from './dashboard-button-group'; import LoginStore from '../user/login-store'; import DashboardStore from './dashboard-store'; -import ProjectStore from '../project/project-store'; -import SimulationStore from '../simulation/simulation-store'; import SimulationModelStore from '../simulationmodel/simulation-model-store'; import FileStore from '../file/file-store'; import WidgetStore from '../widget/widget-store'; @@ -47,7 +45,7 @@ class Dashboard extends Component { static lastWidgetKey = 0; static getStores() { - return [ DashboardStore, ProjectStore, SimulationStore, SimulationModelStore, FileStore, LoginStore, WidgetStore ]; + return [ DashboardStore, SimulationModelStore, FileStore, LoginStore, WidgetStore ]; } static calculateState(prevState, props) { diff --git a/src/project/edit-project.js b/src/project/edit-project.js deleted file mode 100644 index 918633d..0000000 --- a/src/project/edit-project.js +++ /dev/null @@ -1,101 +0,0 @@ -/** - * File: edit-project.js - * Author: Markus Grigull - * Date: 07.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, FormLabel } from 'react-bootstrap'; - -import Dialog from '../common/dialogs/dialog'; - -class EditProjectDialog extends React.Component { - valid: true; - - constructor(props) { - super(props); - - this.state = { - name: '', - simulation: '', - _id: '' - } - } - - onClose(canceled) { - if (canceled === false) { - if (this.valid) { - this.props.onClose(this.state); - } - } else { - this.props.onClose(); - } - } - - handleChange(e) { - this.setState({ [e.target.id]: e.target.value }); - } - - resetState() { - this.setState({ - name: this.props.project.name, - simulation: this.props.project.simulation, - _id: this.props.project._id - }); - } - - validateForm(target) { - // check all controls - var name = true; - - if (this.state.name === '') { - name = false; - } - - this.valid = name; - - // return state to control - if (target === 'name') return name ? "success" : "error"; - - return "success"; - } - - render() { - return ( - this.onClose(c)} onReset={() => this.resetState()} valid={this.valid}> -
- - Name - this.handleChange(e)} /> - - - - Simulation - this.handleChange(e)}> - {this.props.simulations.map(simulation => ( - - ))} - - -
-
- ); - } -} - -export default EditProjectDialog; diff --git a/src/project/new-project.js b/src/project/new-project.js deleted file mode 100644 index c18cd89..0000000 --- a/src/project/new-project.js +++ /dev/null @@ -1,103 +0,0 @@ -/** - * File: new-project.js - * Author: Markus Grigull - * Date: 07.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, FormLabel } from 'react-bootstrap'; - -import Dialog from '../common/dialogs/dialog'; - -class NewProjectDialog extends React.Component { - valid: false; - - constructor(props) { - super(props); - - this.state = { - name: '', - simulation: '' - }; - } - - onClose(canceled) { - if (canceled === false) { - if (this.valid) { - this.props.onClose(this.state); - } - } else { - this.props.onClose(); - } - } - - handleChange(e) { - this.setState({ [e.target.id]: e.target.value }); - } - - resetState() { - this.setState({ - name: '', - simulation: this.props.simulations[0] != null ? this.props.simulations[0]._id : '' - }); - } - - validateForm(target) { - // check all controls - var name = true; - var simulation = true; - - if (this.state.name === '') { - name = false; - } - - if (this.state.simulation === '') { - simulation = false; - } - - this.valid = name && simulation; - - // return state to control - if (target === 'name') return name ? "success" : "error"; - else if (target === 'simulation') return simulation ? "success" : "error"; - } - - render() { - return ( - this.onClose(c)} onReset={() => this.resetState()} valid={this.valid}> -
- - Name - this.handleChange(e)} /> - - - - Simulation - this.handleChange(e)}> - {this.props.simulations.map(simulation => ( - - ))} - - -
-
- ); - } -} - -export default NewProjectDialog; diff --git a/src/project/project-store.js b/src/project/project-store.js deleted file mode 100644 index 99b9bba..0000000 --- a/src/project/project-store.js +++ /dev/null @@ -1,25 +0,0 @@ -/** - * File: project-store.js - * Author: Markus Grigull - * Date: 07.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 ArrayStore from '../common/array-store'; -import ProjectsDataManager from './projects-data-manager'; - -export default new ArrayStore('projects', ProjectsDataManager); diff --git a/src/project/project.js b/src/project/project.js deleted file mode 100644 index 61bb390..0000000 --- a/src/project/project.js +++ /dev/null @@ -1,235 +0,0 @@ -/** - * File: project.js - * Author: Markus Grigull - * Date: 03.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, { Component } from 'react'; -import { Container } from 'flux/utils'; -import { Button } from 'react-bootstrap'; -import FileSaver from 'file-saver'; - -import AppDispatcher from '../common/app-dispatcher'; -import ProjectStore from './project-store'; -import LoginStore from '../user/login-store'; -import DashboardStore from '../dashboard/dashboard-store'; -import SimulationStore from '../simulation/simulation-store'; - -import Icon from '../common/icon'; -import CustomTable from '../common/table'; -import TableColumn from '../common/table-column'; -import NewVisualzationDialog from '../dashboard/new-dashboard'; -import EditDashboardDialog from '../dashboard/edit-dashboard'; -import ImportDashboardDialog from '../dashboard/import-dashboard'; - -import DeleteDialog from '../common/dialogs/delete-dialog'; - -class Dashboards extends Component { - static getStores() { - return [ ProjectStore, DashboardStore, LoginStore, SimulationStore ]; - } - - static calculateState(prevState, props) { - prevState = prevState || {}; - - // load project - const sessionToken = LoginStore.getState().token; - - let project = ProjectStore.getState().find(project => project._id === props.match.params.project); - if (project == null) { - AppDispatcher.dispatch({ - type: 'projects/start-load', - data: props.match.params.project, - token: sessionToken - }); - - project = {}; - } - - // load simulation - let simulation = {}; - - if (project.simulation != null) { - simulation = SimulationStore.getState().find(simulation => simulation._id === project.simulation); - } - - // load dashboards - let dashboards = []; - - if (project.dashboards != null) { - dashboards = DashboardStore.getState().filter(dashboard => project.dashboards.includes(dashboard._id)); - } - - return { - dashboards, - project, - simulation, - sessionToken, - - newModal: prevState.newModal || false, - deleteModal: prevState.deleteModal || false, - editModal: prevState.editModal || false, - importModal: prevState.importModal || false, - modalData: prevState.modalData || {} - }; - } - - componentDidMount() { - AppDispatcher.dispatch({ - type: 'dashboards/start-load', - token: this.state.sessionToken - }); - - AppDispatcher.dispatch({ - type: 'simulations/start-load', - token: this.state.sessionToken - }); - } - - closeNewModal(data) { - this.setState({ newModal: false }); - - if (data) { - // add project to dashboard - data.project = this.state.project._id; - - AppDispatcher.dispatch({ - type: 'dashboards/start-add', - data: data, - token: this.state.sessionToken - }); - - this.setState({ project: {} }, () => { - AppDispatcher.dispatch({ - type: 'projects/start-load', - data: this.props.match.params.project, - token: this.state.sessionToken - }); - }); - } - } - - closeDeleteModal = confirmDelete => { - this.setState({ deleteModal: false }); - - if (confirmDelete === false) { - return; - } - - AppDispatcher.dispatch({ - type: 'dashboards/start-remove', - data: this.state.modalData, - token: this.state.sessionToken - }); - } - - closeEditModal(data) { - this.setState({ editModal : false }); - - if (data) { - AppDispatcher.dispatch({ - type: 'dashboards/start-edit', - data: data, - token: this.state.sessionToken - }); - } - } - - closeImportModal(data) { - this.setState({ importModal: false }); - - if (data) { - data.project = this.state.project._id; - - AppDispatcher.dispatch({ - type: 'dashboards/start-add', - data, - token: this.state.sessionToken - }); - - this.setState({ project: {} }, () => { - AppDispatcher.dispatch({ - type: 'projects/start-load', - data: this.props.match.params.project, - token: this.state.sessionToken - }); - }); - } - } - - exportDashboard(index) { - // filter properties - let dashboard = Object.assign({}, this.state.dashboards[index]); - delete dashboard._id; - delete dashboard.project; - delete dashboard.user; - - dashboard.widgets.forEach(widget => { - delete widget.simulator; - }); - - // show save dialog - const blob = new Blob([JSON.stringify(dashboard, null, 2)], { type: 'application/json' }); - FileSaver.saveAs(blob, 'dashboard - ' + dashboard.name + '.json'); - } - - onModalKeyPress = (event) => { - if (event.key === 'Enter') { - event.preventDefault(); - - this.confirmDeleteModal(); - } - } - - render() { - const buttonStyle = { - marginRight: '10px' - }; - - return ( -
-

{this.state.project.name}

- - - - this.setState({ editModal: true, modalData: this.state.dashboards[index] })} - onDelete={(index) => this.setState({ deleteModal: true, modalData: this.state.dashboards[index] })} - onExport={index => this.exportDashboard(index)} - /> - - - - - - this.closeNewModal(data)} /> - this.closeEditModal(data)} dashboard={this.state.modalData} /> - this.closeImportModal(data)} simulation={this.state.simulation} /> - - -
- ); - } -} - -let fluxContainerConverter = require('../common/FluxContainerConverter'); -export default Container.create(fluxContainerConverter.convert(Dashboards), {withProps: true}); diff --git a/src/project/projects-data-manager.js b/src/project/projects-data-manager.js deleted file mode 100644 index 669e58a..0000000 --- a/src/project/projects-data-manager.js +++ /dev/null @@ -1,24 +0,0 @@ -/** - * File: projects-data-manager.js - * Author: Markus Grigull - * Date: 07.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 RestDataManager from '../common/data-managers/rest-data-manager'; - -export default new RestDataManager('project', '/projects'); diff --git a/src/project/projects.js b/src/project/projects.js deleted file mode 100644 index 0b50ecd..0000000 --- a/src/project/projects.js +++ /dev/null @@ -1,160 +0,0 @@ -/** - * File: projects.js - * Author: Markus Grigull - * Date: 02.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 { Container } from 'flux/utils'; -import { Button } from 'react-bootstrap'; - -import AppDispatcher from '../common/app-dispatcher'; -import ProjectStore from './project-store'; -import LoginStore from '../user/login-store'; -import SimulationStore from '../simulation/simulation-store'; - -import Icon from '../common/icon'; -import Table from '../common/table'; -import TableColumn from '../common/table-column'; -import NewProjectDialog from './new-project'; -import EditProjectDialog from './edit-project'; - -import DeleteDialog from '../common/dialogs/delete-dialog'; - -class Projects extends React.Component { - static getStores() { - return [ ProjectStore, SimulationStore, LoginStore ]; - } - - static calculateState() { - return { - projects: ProjectStore.getState(), - simulations: SimulationStore.getState(), - sessionToken: LoginStore.getState().token, - - newModal: false, - editModal: false, - deleteModal: false, - modalData: {} - }; - } - - componentDidMount() { - AppDispatcher.dispatch({ - type: 'projects/start-load', - token: this.state.sessionToken - }); - - AppDispatcher.dispatch({ - type: 'simulations/start-load', - token: this.state.sessionToken - }); - } - - closeNewModal(data) { - this.setState({ newModal: false }); - - if (data) { - AppDispatcher.dispatch({ - type: 'projects/start-add', - data, - token: this.state.sessionToken - }); - } - } - - closeDeleteModal = confirmDelete => { - this.setState({ deleteModal: false }); - - if (confirmDelete === false) { - return; - } - - AppDispatcher.dispatch({ - type: 'projects/start-remove', - data: this.state.modalData, - token: this.state.sessionToken - }); - } - - closeEditModal(data) { - this.setState({ editModal: false }); - - if (data) { - AppDispatcher.dispatch({ - type: 'projects/start-edit', - data: data, - token: this.state.sessionToken - }); - } - } - - getSimulationName(id) { - for (var i = 0; i < this.state.simulations.length; i++) { - if (this.state.simulations[i]._id === id) { - return this.state.simulations[i].name; - } - } - - return id; - } - - hasValidSimulation() { - const simulations = this.state.simulations.filter(simulation => { - return simulation.models.length > 0; - }); - - return simulations.length > 0; - } - - onModalKeyPress = (event) => { - if (event.key === 'Enter') { - event.preventDefault(); - - this.confirmDeleteModal(); - } - } - - render() { - return ( -
-

Projects

- - - - this.getSimulationName(id)} /> - this.setState({ editModal: true, modalData: this.state.projects[index] })} onDelete={index => this.setState({ deleteModal: true, modalData: this.state.projects[index] })} /> -
- - - - {!this.hasValidSimulation() && - Simulation with at least one simulation-model required! - } - - this.closeNewModal(data)} simulations={this.state.simulations} /> - this.closeEditModal(data)} project={this.state.modalData} simulations={this.state.simulations} /> - - -
- ); - } -} - -let fluxContainerConverter = require('../common/FluxContainerConverter'); -export default Container.create(fluxContainerConverter.convert(Projects)); diff --git a/src/simulation/edit-simulation.js b/src/simulation/edit-simulation.js deleted file mode 100644 index 7a99ab6..0000000 --- a/src/simulation/edit-simulation.js +++ /dev/null @@ -1,103 +0,0 @@ -/** - * File: new-simulation.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, FormLabel } from 'react-bootstrap'; - -import Dialog from '../common/dialogs/dialog'; -import ParametersEditor from '../common/parameters-editor'; - -class EditSimulationDialog extends React.Component { - valid = true; - - constructor(props) { - super(props); - - this.state = { - name: '', - _id: '', - startParameters: {} - }; - } - - onClose = canceled => { - if (canceled) { - if (this.props.onClose != null) { - this.props.onClose(); - } - - return; - } - - if (this.valid && this.props.onClose != null) { - this.props.onClose(this.state); - } - } - - handleChange = event => { - this.setState({ [event.target.id]: event.target.value }); - } - - resetState = () => { - this.setState({ - name: this.props.simulation.name, - _id: this.props.simulation._id, - startParameters: this.props.simulation.startParameters || {} - }); - } - - handleStartParametersChange = startParameters => { - this.setState({ startParameters }); - } - - validateForm(target) { - let name = true; - - if (this.state.name === '') { - name = false; - } - - this.valid = name; - - // return state to control - if (target === 'name') return name ? 'success' : 'error'; - } - - render() { - return -
- - Name - - - - - - Start Parameters - - - -
-
; - } -} - -export default EditSimulationDialog; diff --git a/src/simulation/import-simulation.js b/src/simulation/import-simulation.js deleted file mode 100644 index afb1438..0000000 --- a/src/simulation/import-simulation.js +++ /dev/null @@ -1,155 +0,0 @@ -/** - * File: import-simulation.js - * Author: Markus Grigull - * Date: 03.09.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, FormLabel } from 'react-bootstrap'; - -import Dialog from '../common/dialogs/dialog'; -import ParametersEditor from '../common/parameters-editor'; - -class ImportSimulationDialog extends React.Component { - valid = false; - imported = false; - - constructor(props) { - super(props); - - this.state = { - name: '', - models: [], - startParameters: {} - }; - } - - onClose = canceled => { - if (canceled) { - if (this.props.onClose != null) { - this.props.onClose(); - } - - return; - } - - if (this.valid && this.props.onClose != null) { - this.props.onClose(this.state); - } - } - - handleChange(e, index) { - if (e.target.id === 'simulator') { - const models = this.state.models; - models[index].simulator = JSON.parse(e.target.value); - - this.setState({ models }); - - return; - } - - this.setState({ [e.target.id]: e.target.value }); - } - - resetState = () => { - this.setState({ name: '', models: [], startParameters: {} }); - - this.imported = false; - } - - loadFile = event => { - const file = event.target.files[0]; - - if (!file.type.match('application/json')) { - return; - } - - // create file reader - const reader = new FileReader(); - const self = this; - - reader.onload = onloadEvent => { - const simulation = JSON.parse(onloadEvent.target.result); - - // simulation.models.forEach(model => { - // model.simulator = { - // node: self.props.nodes[0]._id, - // simulator: 0 - // }; - // }); - - self.imported = true; - self.valid = true; - self.setState({ name: simulation.name, models: simulation.models, startParameters: simulation.startParameters }); - }; - - reader.readAsText(file); - } - - validateForm(target) { - // check all controls - let name = true; - - if (this.state.name === '') { - name = false; - } - - this.valid = name; - - // return state to control - if (target === 'name') return name ? "success" : "error"; - } - - render() { - return -
- - Simulation File - - - - - Name - this.handleChange(e)} /> - - - - - Start Parameters - - - - - {/* {this.state.models.map((model, index) => ( - - {model.name} - Simulator - this.handleChange(e, index)}> - {this.props.nodes.map(node => ( - node.simulators.map((simulator, index) => ( - - )) - ))} - - - ))} */} -
-
; - } -} - -export default ImportSimulationDialog; diff --git a/src/simulation/new-simulation.js b/src/simulation/new-simulation.js deleted file mode 100644 index a6b1c8f..0000000 --- a/src/simulation/new-simulation.js +++ /dev/null @@ -1,99 +0,0 @@ -/** - * File: new-simulation.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, FormLabel } from 'react-bootstrap'; - -import Dialog from '../common/dialogs/dialog'; -import ParametersEditor from '../common/parameters-editor'; - -class NewSimulationDialog extends React.Component { - valid = false; - - constructor(props) { - super(props); - - this.state = { - name: '', - startParameters: {} - }; - } - - onClose = canceled => { - if (canceled) { - if (this.props.onClose != null) { - this.props.onClose(); - } - - return; - } - - if (this.valid && this.props.onClose != null) { - this.props.onClose(this.state); - } - } - - handleChange = event => { - this.setState({ [event.target.id]: event.target.value }); - } - - resetState = () => { - this.setState({ name: '', startParameters: {} }); - } - - handleStartParametersChange = startParameters => { - this.setState({ startParameters }); - } - - validateForm(target) { - // check all controls - let name = true; - - if (this.state.name === '') { - name = false; - } - - this.valid = name; - - // return state to control - if (target === 'name') return name ? "success" : "error"; - } - - render() { - return -
- - Name - - - - - - Start Parameters - - - -
-
; - } -} - -export default NewSimulationDialog; diff --git a/src/simulation/simulation-store.js b/src/simulation/simulation-store.js deleted file mode 100644 index fbc63eb..0000000 --- a/src/simulation/simulation-store.js +++ /dev/null @@ -1,25 +0,0 @@ -/** - * File: simulation-store.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 ArrayStore from '../common/array-store'; -import SimulationsDataManager from './simulations-data-manager'; - -export default new ArrayStore('simulations', SimulationsDataManager); diff --git a/src/simulation/simulation.js b/src/simulation/simulation.js deleted file mode 100644 index 83900a9..0000000 --- a/src/simulation/simulation.js +++ /dev/null @@ -1,289 +0,0 @@ -/** - * File: simulation.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 { Container } from 'flux/utils'; -import { Button } from 'react-bootstrap'; -import FileSaver from 'file-saver'; -import _ from 'lodash'; - -import SimulationStore from './simulation-store'; -import SimulatorStore from '../simulator/simulator-store'; -import SimulationModelStore from '../simulationmodel/simulation-model-store'; -import LoginStore from '../user/login-store'; -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 SimulatorAction from '../simulator/simulator-action'; -import DeleteDialog from '../common/dialogs/delete-dialog'; - -class Simulation extends React.Component { - static getStores() { - return [ SimulationStore, SimulatorStore, SimulationModelStore, LoginStore ]; - } - - static calculateState(prevState, props) { - // get selected simulation - const sessionToken = LoginStore.getState().token; - - let simulation = SimulationStore.getState().find(s => s._id === props.match.params.simulation); - if (simulation == null) { - AppDispatcher.dispatch({ - type: 'simulations/start-load', - data: props.match.params.simulation, - token: sessionToken - }); - - simulation = {}; - } - - // load models - let simulationModels = []; - if (simulation.models != null) { - simulationModels = SimulationModelStore.getState().filter(m => m != null && simulation.models.includes(m._id)); - } - - return { - simulationModels, - simulation, - - simulators: SimulatorStore.getState(), - sessionToken, - - deleteModal: false, - importModal: false, - modalData: {}, - - selectedSimulationModels: [] - } - } - - componentDidMount() { - AppDispatcher.dispatch({ - type: 'simulations/start-load', - token: this.state.sessionToken - }); - - AppDispatcher.dispatch({ - type: 'simulationModels/start-load', - token: this.state.sessionToken - }); - - AppDispatcher.dispatch({ - type: 'simulators/start-load', - token: this.state.sessionToken - }); - } - - 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' }] - }; - - AppDispatcher.dispatch({ - type: 'simulationModels/start-add', - data: simulationModel, - 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 => { - this.setState({ deleteModal: false }); - - if (confirmDelete === false) { - return; - } - - AppDispatcher.dispatch({ - type: 'simulationModels/start-remove', - data: this.state.modalData, - token: this.state.sessionToken - }); - } - - importSimulationModel = simulationModel => { - this.setState({ importModal: false }); - - if (simulationModel == null) { - return; - } - - simulationModel.simulation = this.state.simulation._id; - - console.log(simulationModel); - - AppDispatcher.dispatch({ - type: 'simulationModels/start-add', - data: simulationModel, - token: this.state.sessionToken - }); - - this.setState({ simulation: {} }, () => { - AppDispatcher.dispatch({ - type: 'simulations/start-load', - data: this.props.match.params.simulation, - token: this.state.sessionToken - }); - }); - } - - getSimulatorName(simulatorId) { - for (let simulator of this.state.simulators) { - if (simulator.id === simulatorId) { - return _.get(simulator, 'properties.name') || _.get(simulator, 'rawProperties.name') || simulator.uuid; - } - } - } - - exportModel(index) { - // filter properties - const model = Object.assign({}, this.state.simulationModels[index]); - - delete model.simulator; - delete model.simulation; - - // show save dialog - const blob = new Blob([JSON.stringify(model, null, 2)], { type: 'application/json' }); - FileSaver.saveAs(blob, 'simulation model - ' + model.name + '.json'); - } - - onSimulationModelChecked(index, event) { - const selectedSimulationModels = Object.assign([], this.state.selectedSimulationModels); - for (let key in selectedSimulationModels) { - if (selectedSimulationModels[key] === index) { - // update existing entry - if (event.target.checked) { - return; - } - - selectedSimulationModels.splice(key, 1); - - this.setState({ selectedSimulationModels }); - return; - } - } - - // add new entry - if (event.target.checked === false) { - return; - } - - selectedSimulationModels.push(index); - this.setState({ selectedSimulationModels }); - } - - runAction = action => { - for (let index of this.state.selectedSimulationModels) { - // get simulator for model - let simulator = null; - for (let sim of this.state.simulators) { - if (sim._id === this.state.simulationModels[index].simulator) { - simulator = sim; - } - } - - if (simulator == null) { - continue; - } - - if (action.data.action === 'start') { - action.data.parameters = this.state.simulationModels[index].startParameters; - } - - AppDispatcher.dispatch({ - type: 'simulators/start-action', - simulator, - data: action.data, - token: this.state.sessionToken - }); - } - } - - render() { - const buttonStyle = { - marginLeft: '10px' - }; - - 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)} - /> -
- -
- -
- -
- - -
- -
- - - - -
; - } -} - -let fluxContainerConverter = require('../common/FluxContainerConverter'); -export default Container.create(fluxContainerConverter.convert(Simulation), { withProps: true }); diff --git a/src/simulation/simulations-data-manager.js b/src/simulation/simulations-data-manager.js deleted file mode 100644 index 3090820..0000000 --- a/src/simulation/simulations-data-manager.js +++ /dev/null @@ -1,24 +0,0 @@ -/** - * File: simulation-data-manager.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 RestDataManager from '../common/data-managers/rest-data-manager'; - -export default new RestDataManager('simulation', '/simulations', [ '_id', 'name', 'projects', 'models', 'startParameters' ]); diff --git a/src/simulation/simulations.js b/src/simulation/simulations.js deleted file mode 100644 index 6a8879d..0000000 --- a/src/simulation/simulations.js +++ /dev/null @@ -1,329 +0,0 @@ -/** - * File: simulations.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, { Component } from 'react'; -import { Container } from 'flux/utils'; -import { Button } from 'react-bootstrap'; -import FileSaver from 'file-saver'; - -import AppDispatcher from '../common/app-dispatcher'; -import SimulationStore from './simulation-store'; -import LoginStore from '../user/login-store'; -import SimulatorStore from '../simulator/simulator-store'; -import SimulationModelStore from '../simulationmodel/simulation-model-store'; - -import Icon from '../common/icon'; -import Table from '../common/table'; -import TableColumn from '../common/table-column'; -import NewSimulationDialog from './new-simulation'; -import EditSimulationDialog from './edit-simulation'; -import ImportSimulationDialog from './import-simulation'; - -import SimulatorAction from '../simulator/simulator-action'; -import DeleteDialog from '../common/dialogs/delete-dialog'; - -class Simulations extends Component { - static getStores() { - return [ SimulationStore, LoginStore, SimulatorStore, SimulationModelStore ]; - } - - static calculateState() { - const simulations = SimulationStore.getState(); - const simulationModels = SimulationModelStore.getState(); - const simulators = SimulatorStore.getState(); - - const sessionToken = LoginStore.getState().token; - - return { - simulations, - simulationModels, - simulators, - sessionToken, - - newModal: false, - deleteModal: false, - editModal: false, - importModal: false, - modalSimulation: {}, - - selectedSimulations: [] - }; - } - - componentDidMount() { - AppDispatcher.dispatch({ - type: 'simulations/start-load', - token: this.state.sessionToken - }); - } - - componentDidUpdate() { - const simulationModelIds = []; - const simulatorIds = []; - - for (let simulation of this.state.simulations) { - for (let modelId of simulation.models) { - const model = this.state.simulationModels.find(m => m != null && m._id === modelId); - - if (model == null) { - simulationModelIds.push(modelId); - - continue; - } - - if (this.state.simulators.includes(s => s._id === model.simulator) === false) { - simulatorIds.push(model.simulator); - } - } - } - - if (simulationModelIds.length > 0) { - AppDispatcher.dispatch({ - type: 'simulationModels/start-load', - data: simulationModelIds, - token: this.state.sessionToken - }); - } - - if (simulatorIds.length > 0) { - AppDispatcher.dispatch({ - type: 'simulators/start-load', - data: simulatorIds, - token: this.state.sessionToken - }); - } - } - - closeNewModal(data) { - this.setState({ newModal : false }); - - if (data) { - AppDispatcher.dispatch({ - type: 'simulations/start-add', - data, - token: this.state.sessionToken - }); - } - } - - showDeleteModal(id) { - // get simulation by id - var deleteSimulation; - - this.state.simulations.forEach((simulation) => { - if (simulation._id === id) { - deleteSimulation = simulation; - } - }); - - this.setState({ deleteModal: true, modalSimulation: deleteSimulation }); - } - - closeDeleteModal = confirmDelete => { - this.setState({ deleteModal: false }); - - if (confirmDelete === false) { - return; - } - - AppDispatcher.dispatch({ - type: 'simulations/start-remove', - data: this.state.modalSimulation, - token: this.state.sessionToken - }); - } - - showEditModal(id) { - // get simulation by id - var editSimulation; - - this.state.simulations.forEach((simulation) => { - if (simulation._id === id) { - editSimulation = simulation; - } - }); - - this.setState({ editModal: true, modalSimulation: editSimulation }); - } - - closeEditModal(data) { - this.setState({ editModal : false }); - - if (data != null) { - AppDispatcher.dispatch({ - type: 'simulations/start-edit', - data, - token: this.state.sessionToken - }); - } - } - - closeImportModal(data) { - this.setState({ importModal: false }); - - if (data) { - AppDispatcher.dispatch({ - type: 'simulations/start-add', - data, - token: this.state.sessionToken - }); - } - } - - onModalKeyPress = (event) => { - if (event.key === 'Enter') { - event.preventDefault(); - - this.confirmDeleteModal(); - } - } - - exportSimulation(index) { - // filter properties - let simulation = Object.assign({}, this.state.simulations[index]); - delete simulation._id; - delete simulation.projects; - delete simulation.running; - delete simulation.user; - - simulation.models.forEach(model => { - delete model.simulator; - }); - - // show save dialog - const blob = new Blob([JSON.stringify(simulation, null, 2)], { type: 'application/json' }); - FileSaver.saveAs(blob, 'simulation - ' + simulation.name + '.json'); - } - - onSimulationChecked(index, event) { - const selectedSimulations = Object.assign([], this.state.selectedSimulations); - for (let key in selectedSimulations) { - if (selectedSimulations[key] === index) { - // update existing entry - if (event.target.checked) { - return; - } - - selectedSimulations.splice(key, 1); - - this.setState({ selectedSimulations }); - return; - } - } - - // add new entry - if (event.target.checked === false) { - return; - } - - selectedSimulations.push(index); - this.setState({ selectedSimulations }); - } - - runAction = action => { - for (let index of this.state.selectedSimulations) { - for (let model of this.state.simulations[index].models) { - // get simulation model - const simulationModel = this.state.simulationModels.find(m => m != null && m._id === model); - if (simulationModel == null) { - continue; - } - - // get simulator for model - let simulator = null; - for (let sim of this.state.simulators) { - if (sim._id === simulationModel.simulator) { - simulator = sim; - } - } - - if (simulator == null) { - continue; - } - - if (action.data.action === 'start') { - action.data.parameters = Object.assign({}, this.state.simulations[index].startParameters, simulationModel.startParameters); - } - - AppDispatcher.dispatch({ - type: 'simulators/start-action', - simulator, - data: action.data, - token: this.state.sessionToken - }); - } - } - } - - render() { - const buttonStyle = { - marginLeft: '10px' - }; - - return ( -
-

Simulations

- - - this.onSimulationChecked(index, event)} width='30' /> - - this.setState({ editModal: true, modalSimulation: this.state.simulations[index] })} - onDelete={index => this.setState({ deleteModal: true, modalSimulation: this.state.simulations[index] })} - onExport={index => this.exportSimulation(index)} - /> -
- -
- -
- -
- - -
- -
- - this.closeNewModal(data)} /> - this.closeEditModal(data)} simulation={this.state.modalSimulation} /> - this.closeImportModal(data)} nodes={this.state.nodes} /> - - -
- ); - } -} - -let fluxContainerConverter = require('../common/FluxContainerConverter'); -export default Container.create(fluxContainerConverter.convert(Simulations));