diff options
| author | Georgios Andreadis <g.andreadis@student.tudelft.nl> | 2017-09-08 10:27:00 +0200 |
|---|---|---|
| committer | Georgios Andreadis <g.andreadis@student.tudelft.nl> | 2017-09-23 10:05:59 +0200 |
| commit | fc9c52a8f102202bd0e1a8a9dc4d8d68babe2304 (patch) | |
| tree | 0025827d791a3eeb5416bb89d4c36e777feabdd7 /src/actions/topology | |
| parent | 1b5d2658f9ec06308b2a5ed062f6f5b4798ed733 (diff) | |
Implement UI for unit addition and removal
Diffstat (limited to 'src/actions/topology')
| -rw-r--r-- | src/actions/topology/machine.js | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/actions/topology/machine.js b/src/actions/topology/machine.js index af258a6f..e11c7d1d 100644 --- a/src/actions/topology/machine.js +++ b/src/actions/topology/machine.js @@ -2,6 +2,8 @@ import {goDownOneInteractionLevel} from "../interaction-level"; import {addPropToStoreObject} from "../objects"; export const DELETE_MACHINE = "DELETE_MACHINE"; +export const ADD_UNIT = "ADD_UNIT"; +export const DELETE_UNIT = "DELETE_UNIT"; export function deleteMachine() { return { @@ -19,3 +21,40 @@ export function deleteMachineSucceeded() { dispatch(addPropToStoreObject("rack", rack.id, {machineIds})); }; } + +export function addUnit(unitType, id) { + return { + type: ADD_UNIT, + unitType, + id + }; +} + +export function addUnitSucceeded(unitType, id) { + return (dispatch, getState) => { + const {objects, interactionLevel} = getState(); + const machine = objects.machine[objects.rack[objects.tile[interactionLevel.tileId].objectId] + .machineIds[interactionLevel.position - 1]]; + const units = [...machine[unitType + "Ids"], id]; + dispatch(addPropToStoreObject("machine", machine.id, {[unitType + "Ids"]: units})); + }; +} + +export function deleteUnit(unitType, index) { + return { + type: DELETE_UNIT, + unitType, + index + }; +} + +export function deleteUnitSucceeded(unitType, index) { + return (dispatch, getState) => { + const {objects, interactionLevel} = getState(); + const machine = objects.machine[objects.rack[objects.tile[interactionLevel.tileId].objectId] + .machineIds[interactionLevel.position - 1]]; + const unitIds = machine[unitType + "Ids"].slice(); + unitIds.splice(index, 1); + dispatch(addPropToStoreObject("machine", machine.id, {[unitType + "Ids"]: unitIds})); + }; +} |
