From b8f8294a8b9f0c457c943223cf2eb106f44c4f7d Mon Sep 17 00:00:00 2001 From: Sonja Happ Date: Tue, 17 Sep 2019 15:33:15 +0200 Subject: [PATCH] clean up view that lists all scenarios --- src/scenario/edit-scenario.js | 10 ++- src/scenario/scenarios.js | 164 +++------------------------------- 2 files changed, 16 insertions(+), 158 deletions(-) diff --git a/src/scenario/edit-scenario.js b/src/scenario/edit-scenario.js index 4cebf47..6d22d07 100644 --- a/src/scenario/edit-scenario.js +++ b/src/scenario/edit-scenario.js @@ -34,6 +34,7 @@ class EditScenarioDialog extends React.Component { this.state = { name: '', id: '', + running: false, startParameters: {} }; } @@ -69,25 +70,26 @@ class EditScenarioDialog extends React.Component { this.setState({ name: this.props.scenario.name, id: this.props.scenario.id, + running: this.props.scenario.running, startParameters: this.props.scenario.startParameters || {} }); - } + }; handleStartParametersChange = startParameters => { this.setState({ startParameters }); - } + }; render() { return
- Name + Name - Start Parameters + Start Parameters diff --git a/src/scenario/scenarios.js b/src/scenario/scenarios.js index 9c8c59c..ab6e173 100644 --- a/src/scenario/scenarios.js +++ b/src/scenario/scenarios.js @@ -27,8 +27,6 @@ import FileSaver from 'file-saver'; import AppDispatcher from '../common/app-dispatcher'; import ScenarioStore from './scenario-store'; import UserStore from '../user/user-store'; -import SimulatorStore from '../simulator/simulator-store'; -import SimulationModelStore from '../simulationmodel/simulation-model-store'; import Icon from '../common/icon'; import Table from '../common/table'; @@ -37,27 +35,19 @@ import NewScenarioDialog from './new-scenario'; import EditScenarioDialog from './edit-scenario'; import ImportScenarioDialog from './import-scenario'; -import SimulatorAction from '../simulator/simulator-action'; import DeleteDialog from '../common/dialogs/delete-dialog'; class Scenarios extends Component { static getStores() { - return [ ScenarioStore, UserStore, SimulatorStore, SimulationModelStore ]; + return [ ScenarioStore, UserStore ]; } static calculateState() { const scenarios = ScenarioStore.getState(); - const simulationModels = SimulationModelStore.getState(); - const simulators = SimulatorStore.getState(); - const dashboards = []; // TODO get dashboards with DashboadStore.getState() here - const sessionToken = UserStore.getState().token; return { scenarios, - simulationModels, - simulators, - dashboards, sessionToken, newModal: false, @@ -77,67 +67,7 @@ class Scenarios extends Component { }); } - componentDidUpdate() { - const simulationModelIds = []; - const simulatorIds = []; - const dashboardIds = []; - - - for (let scenario of this.state.scenarios) { - // collect missing simulationModels - // TODO response of backend has to contain simulationModelIDs and dashboardIDs per scenario - for (let modelId of scenario.simulationModelIDs) { - const model = this.state.simulationModels.find(m => m != null && m.id === modelId); - - if (model == null) { - simulationModelIds.push(modelId); - - continue; - } - - // collect missing simulators - if (this.state.simulators.includes(s => s.id === model.simulatorID) === false) { - simulatorIds.push(model.simulatorID); - } - } - - // collect missing dashboards - for (let dashboardId of scenario.dashboardIDs) { - const dashboard = this.state.dashboards.find(d => d != null && d.id === dashboardId); - - if (dashboard == null) { - dashboardIds.push(dashboardId); - } - } - } - - // load missing simulationModels - if (simulationModelIds.length > 0) { - AppDispatcher.dispatch({ - type: 'simulationModels/start-load', - data: simulationModelIds, - token: this.state.sessionToken - }); - } - - // load missing simulators - if (simulatorIds.length > 0) { - AppDispatcher.dispatch({ - type: 'simulators/start-load', - data: simulatorIds, - token: this.state.sessionToken - }); - } - - // load missing dashboards - if (dashboardIds.length > 0) { - AppDispatcher.dispatch( { - type: 'dashboards/start-load', - data: dashboardIds, - token: this.state.sessionToken - }) - } - } + componentDidUpdate() {} closeNewModal(data) { this.setState({ newModal : false }); @@ -164,7 +94,7 @@ class Scenarios extends Component { this.setState({ deleteModal: true, modalScenario: deleteScenario }); } - closeDeleteModal = confirmDelete => { + closeDeleteModal(confirmDelete) { this.setState({ deleteModal: false }); if (confirmDelete === false) { @@ -176,7 +106,7 @@ class Scenarios extends Component { data: this.state.modalScenario, token: this.state.sessionToken }); - } + }; showEditModal(id) { // get scenario by id @@ -221,83 +151,20 @@ class Scenarios extends Component { this.confirmDeleteModal(); } - } + }; exportScenario(index) { // filter properties let scenario = Object.assign({}, this.state.scenarios[index]); delete scenario.id; - delete scenario.users; - delete scenario.dashboards; - scenario.simulationModels.forEach(model => { - delete model.simulator; - }); + // TODO request missing scenario parameters (Dashboards and Simulation Modles) recursively for export // show save dialog const blob = new Blob([JSON.stringify(scenario, null, 2)], { type: 'application/json' }); FileSaver.saveAs(blob, 'scenario - ' + scenario.name + '.json'); } - onScenarioChecked(index, event) { - const selectedScenarios = Object.assign([], this.state.selectedScenarios); - for (let key in selectedScenarios) { - if (selectedScenarios[key] === index) { - // update existing entry - if (event.target.checked) { - return; - } - - selectedScenarios.splice(key, 1); - - this.setState({ selectedScenarios }); - return; - } - } - - // add new entry - if (event.target.checked === false) { - return; - } - - selectedScenarios.push(index); - this.setState({ selectedScenarios }); - } - - runAction = action => { - for (let index of this.state.selectedScenarios) { - for (let model of this.state.scenarios[index].simulationModels) { - // 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.simulatorID) { - simulator = sim; - } - } - - if (simulator == null) { - continue; - } - - if (action.data.action === 'start') { - action.data.parameters = Object.assign({}, this.state.scenarios[index].startParameters, simulationModel.startParameters); - } - - AppDispatcher.dispatch({ - type: 'simulators/start-action', - simulator, - data: action.data, - token: this.state.sessionToken - }); - } - } - }; render() { const buttonStyle = { @@ -309,10 +176,11 @@ class Scenarios extends Component {

Scenarios

- this.onScenarioChecked(index, event)} width='30' /> + +
-
- -
-
@@ -345,7 +201,7 @@ class Scenarios extends Component { this.closeEditModal(data)} scenario={this.state.modalScenario} /> this.closeImportModal(data)} nodes={this.state.nodes} /> - + this.closeDeleteModal(e)} />
); }