diff options
| author | Georgios Andreadis <g.andreadis@student.tudelft.nl> | 2017-09-14 14:07:21 +0200 |
|---|---|---|
| committer | Georgios Andreadis <g.andreadis@student.tudelft.nl> | 2017-09-23 10:06:02 +0200 |
| commit | f604406453f95c82c3e5e4294a51245661868bbe (patch) | |
| tree | 6282cc3eb3164ddd94052175f872c8fc2ee2f623 /src/sagas/experiments.js | |
| parent | 7151ae60cf587a502a7e09d19ebd0fd33e761bf2 (diff) | |
First attempt at experiment list UI
Diffstat (limited to 'src/sagas/experiments.js')
| -rw-r--r-- | src/sagas/experiments.js | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/sagas/experiments.js b/src/sagas/experiments.js new file mode 100644 index 00000000..0ac919f4 --- /dev/null +++ b/src/sagas/experiments.js @@ -0,0 +1,73 @@ +import {call, put, select} from "redux-saga/effects"; +import {addPropToStoreObject, addToStore} from "../actions/objects"; +import {deleteExperiment} from "../api/routes/experiments"; +import {addExperiment, getExperimentsOfSimulation} from "../api/routes/simulations"; +import { + fetchAndStoreAllJobs, + fetchAndStoreAllSchedulers, + fetchAndStoreAllTasks, + fetchAndStoreAllTraces, + fetchAndStorePathsOfSimulation +} from "./objects"; + +export function* onFetchExperimentsOfSimulation() { + try { + const currentSimulationId = yield select(state => state.currentSimulationId); + + yield fetchExperimentSpecifications(); + const experiments = yield call(getExperimentsOfSimulation, currentSimulationId); + for (let i in experiments) { + yield put(addToStore("experiment", experiments[i])); + } + yield put(addPropToStoreObject("simulation", currentSimulationId, + {experimentIds: experiments.map(experiment => experiment.id)})); + } catch (error) { + console.log(error); + } +} + +function* fetchExperimentSpecifications() { + try { + const currentSimulationId = yield select(state => state.currentSimulationId); + + yield fetchAndStorePathsOfSimulation(currentSimulationId); + yield fetchAndStoreAllTasks(); + yield fetchAndStoreAllJobs(); + yield fetchAndStoreAllTraces(); + yield fetchAndStoreAllSchedulers(); + } catch (error) { + console.log(error); + } +} + +export function* onAddExperiment(action) { + try { + const currentSimulationId = yield select(state => state.currentSimulationId); + + const experiment = yield call(addExperiment, currentSimulationId, Object.assign({}, action.experiment, { + id: -1, + simulationId: currentSimulationId + })); + yield put(addToStore("experiment", experiment)); + + const experimentIds = yield select(state => state.objects.simulation[currentSimulationId]); + yield put(addPropToStoreObject("simulation", currentSimulationId, + {experimentIds: experimentIds.concat([experiment.id])})); + } catch (error) { + console.log(error); + } +} + +export function* onDeleteExperiment(action) { + try { + yield call(deleteExperiment, action.id); + + const currentSimulationId = yield select(state => state.currentSimulationId); + const experimentIds = yield select(state => state.objects.simulation[currentSimulationId]); + + yield put(addPropToStoreObject("simulation", currentSimulationId, + {experimentIds: experimentIds.filter(id => id !== action.id)})); + } catch (error) { + console.log(error); + } +} |
