diff --git a/src/scenario/scenarios-data-manager.js b/src/scenario/scenarios-data-manager.js index 3ab824a..a56a61e 100644 --- a/src/scenario/scenarios-data-manager.js +++ b/src/scenario/scenarios-data-manager.js @@ -25,7 +25,7 @@ import AppDispatcher from "../common/app-dispatcher"; class ScenariosDataManager extends RestDataManager { constructor() { - super('scenario', '/scenarios'); + super('scenario', '/scenarios', ['id', 'name', 'running', 'simulationModelIDs', 'userIDs', 'dashboardIDs', 'startParameters' ]); } getSimulationModels(token, id) { diff --git a/src/scenario/scenarios.js b/src/scenario/scenarios.js index 864e552..9c8c59c 100644 --- a/src/scenario/scenarios.js +++ b/src/scenario/scenarios.js @@ -49,6 +49,7 @@ class Scenarios extends Component { 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; @@ -56,6 +57,7 @@ class Scenarios extends Component { scenarios, simulationModels, simulators, + dashboards, sessionToken, newModal: false, @@ -78,9 +80,13 @@ class Scenarios extends Component { componentDidUpdate() { const simulationModelIds = []; const simulatorIds = []; + const dashboardIds = []; + for (let scenario of this.state.scenarios) { - for (let modelId of scenario.simulationModels) { + // 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) { @@ -89,12 +95,23 @@ class Scenarios extends Component { continue; } - if (this.state.simulators.includes(s => s._id === model.simulator) === false) { - simulatorIds.push(model.simulator); + // 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', @@ -103,6 +120,7 @@ class Scenarios extends Component { }); } + // load missing simulators if (simulatorIds.length > 0) { AppDispatcher.dispatch({ type: 'simulators/start-load', @@ -110,6 +128,15 @@ class Scenarios extends Component { token: this.state.sessionToken }); } + + // load missing dashboards + if (dashboardIds.length > 0) { + AppDispatcher.dispatch( { + type: 'dashboards/start-load', + data: dashboardIds, + token: this.state.sessionToken + }) + } } closeNewModal(data) { @@ -270,7 +297,7 @@ class Scenarios extends Component { }); } } - } + }; render() { const buttonStyle = {