summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-server/src/main/webui/redux
diff options
context:
space:
mode:
Diffstat (limited to 'opendc-web/opendc-web-server/src/main/webui/redux')
-rw-r--r--opendc-web/opendc-web-server/src/main/webui/redux/reducers/construction-mode.js7
-rw-r--r--opendc-web/opendc-web-server/src/main/webui/redux/reducers/interaction-level.js3
-rw-r--r--opendc-web/opendc-web-server/src/main/webui/redux/reducers/topology/index.js26
3 files changed, 32 insertions, 4 deletions
diff --git a/opendc-web/opendc-web-server/src/main/webui/redux/reducers/construction-mode.js b/opendc-web/opendc-web-server/src/main/webui/redux/reducers/construction-mode.js
index 8520e794..61265b1e 100644
--- a/opendc-web/opendc-web-server/src/main/webui/redux/reducers/construction-mode.js
+++ b/opendc-web/opendc-web-server/src/main/webui/redux/reducers/construction-mode.js
@@ -1,5 +1,6 @@
import { combineReducers } from 'redux'
import { GO_DOWN_ONE_INTERACTION_LEVEL } from '../actions/interaction-level'
+import { OPEN_TOPOLOGY } from '../actions/topology'
import {
CANCEL_NEW_ROOM_CONSTRUCTION_SUCCEEDED,
FINISH_NEW_ROOM_CONSTRUCTION,
@@ -11,6 +12,8 @@ import { DELETE_ROOM, START_RACK_CONSTRUCTION, STOP_RACK_CONSTRUCTION } from '..
export function currentRoomInConstruction(state = '-1', action) {
switch (action.type) {
+ case OPEN_TOPOLOGY:
+ return '-1'
case START_NEW_ROOM_CONSTRUCTION_SUCCEEDED:
return action.roomId
case START_ROOM_EDIT:
@@ -27,6 +30,8 @@ export function currentRoomInConstruction(state = '-1', action) {
export function inRackConstructionMode(state = false, action) {
switch (action.type) {
+ case OPEN_TOPOLOGY:
+ return false
case START_RACK_CONSTRUCTION:
return true
case STOP_RACK_CONSTRUCTION:
@@ -39,6 +44,8 @@ export function inRackConstructionMode(state = false, action) {
export function currentRackPrefab(state = null, action) {
switch (action.type) {
+ case OPEN_TOPOLOGY:
+ return null
case START_RACK_CONSTRUCTION:
return action.rackPrefab || null
case STOP_RACK_CONSTRUCTION:
diff --git a/opendc-web/opendc-web-server/src/main/webui/redux/reducers/interaction-level.js b/opendc-web/opendc-web-server/src/main/webui/redux/reducers/interaction-level.js
index b30c68b9..d1342d3d 100644
--- a/opendc-web/opendc-web-server/src/main/webui/redux/reducers/interaction-level.js
+++ b/opendc-web/opendc-web-server/src/main/webui/redux/reducers/interaction-level.js
@@ -4,12 +4,15 @@ import {
GO_FROM_RACK_TO_MACHINE,
GO_FROM_ROOM_TO_RACK,
} from '../actions/interaction-level'
+import { OPEN_TOPOLOGY } from '../actions/topology'
import { DELETE_MACHINE } from '../actions/topology/machine'
import { DELETE_RACK } from '../actions/topology/rack'
import { DELETE_ROOM } from '../actions/topology/room'
export function interactionLevel(state = { mode: 'BUILDING' }, action) {
switch (action.type) {
+ case OPEN_TOPOLOGY:
+ return { mode: 'BUILDING' }
case GO_FROM_BUILDING_TO_ROOM:
return {
mode: 'ROOM',
diff --git a/opendc-web/opendc-web-server/src/main/webui/redux/reducers/topology/index.js b/opendc-web/opendc-web-server/src/main/webui/redux/reducers/topology/index.js
index 2c849387..18d6cde4 100644
--- a/opendc-web/opendc-web-server/src/main/webui/redux/reducers/topology/index.js
+++ b/opendc-web/opendc-web-server/src/main/webui/redux/reducers/topology/index.js
@@ -21,18 +21,36 @@
*/
import { CPU_UNITS, GPU_UNITS, MEMORY_UNITS, STORAGE_UNITS } from '../../../util/unit-specifications'
+import { STORE_TOPOLOGY } from '../../actions/topology'
+import { ADD_RACK_TO_TILE } from '../../actions/topology/room'
import machine from './machine'
import rack from './rack'
import room from './room'
import tile from './tile'
import topology from './topology'
+function unitReducer(defaultUnits, entityType) {
+ return (state = defaultUnits, action) => {
+ if (action.type === STORE_TOPOLOGY) {
+ return { ...defaultUnits, ...((action.entities && action.entities[entityType]) || {}) }
+ } else if (action.type === ADD_RACK_TO_TILE) {
+ return { ...state, ...((action.entities && action.entities[entityType]) || {}) }
+ }
+ return state
+ }
+}
+
+const cpus = unitReducer(CPU_UNITS, 'cpus')
+const gpus = unitReducer(GPU_UNITS, 'gpus')
+const memories = unitReducer(MEMORY_UNITS, 'memories')
+const storages = unitReducer(STORAGE_UNITS, 'storages')
+
function objects(state = {}, action) {
return {
- cpus: CPU_UNITS,
- gpus: GPU_UNITS,
- memories: MEMORY_UNITS,
- storages: STORAGE_UNITS,
+ cpus: cpus(state.cpus, action),
+ gpus: gpus(state.gpus, action),
+ memories: memories(state.memories, action),
+ storages: storages(state.storages, action),
machines: machine(state.machines, action, state),
racks: rack(state.racks, action, state),
tiles: tile(state.tiles, action),