From 3bf073f46e74667df4d2be9488a9f8f44ac84421 Mon Sep 17 00:00:00 2001 From: Georgios Andreadis Date: Fri, 22 Sep 2017 08:48:38 +0200 Subject: Make timeline clickable --- src/actions/simulation/tick.js | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'src/actions') diff --git a/src/actions/simulation/tick.js b/src/actions/simulation/tick.js index 68f226d7..06066662 100644 --- a/src/actions/simulation/tick.js +++ b/src/actions/simulation/tick.js @@ -1,3 +1,6 @@ +import {getDatacenterIdOfTick} from "../../util/timeline"; +import {setCurrentDatacenter} from "../topology/building"; + export const GO_TO_TICK = "GO_TO_TICK"; export const SET_LAST_SIMULATED_TICK = "SET_LAST_SIMULATED_TICK"; @@ -9,9 +12,27 @@ export function incrementTick() { } export function goToTick(tick) { - return { - type: GO_TO_TICK, - tick + return (dispatch, getState) => { + const state = getState(); + + let sections = []; + if (state.currentExperimentId !== -1) { + const sectionIds = state.objects.path[state.objects.experiment[state.currentExperimentId].pathId].sectionIds; + + if (sectionIds) { + sections = sectionIds.map(sectionId => state.objects.section[sectionId]); + } + } + + const newDatacenterId = getDatacenterIdOfTick(tick, sections); + if (state.currentDatacenterId !== newDatacenterId) { + dispatch(setCurrentDatacenter(newDatacenterId)); + } + + dispatch({ + type: GO_TO_TICK, + tick + }); } } -- cgit v1.2.3