diff options
Diffstat (limited to 'frontend/src/sagas/objects.js')
| -rw-r--r-- | frontend/src/sagas/objects.js | 83 |
1 files changed, 55 insertions, 28 deletions
diff --git a/frontend/src/sagas/objects.js b/frontend/src/sagas/objects.js index 83d71a42..ebce1f0a 100644 --- a/frontend/src/sagas/objects.js +++ b/frontend/src/sagas/objects.js @@ -148,8 +148,50 @@ export const updateTopologyOnServer = function* (id) { export const getTopologyAsObject = function* (id, keepIds) { const topologyStore = yield select(OBJECT_SELECTORS['topology']) + const rooms = yield getAllRooms(topologyStore[id].roomIds, keepIds) + return { + _id: keepIds ? id : undefined, + name: topologyStore[id].name, + rooms: rooms, + } +} + +export const getAllRooms = function* (roomIds, keepIds) { const roomStore = yield select(OBJECT_SELECTORS['room']) + + let rooms = [] + + for (let i in roomIds) { + let tiles = yield getAllRoomTiles(roomStore[roomIds[i]], keepIds) + rooms.push({ + _id: keepIds ? i : undefined, + name: roomStore[roomIds[i]].name, + tiles: tiles, + }) + } + return rooms +} + +export const getAllRoomTiles = function* (roomStore, keepIds) { + let tiles = [] + + for (let i in roomStore.tileIds) { + tiles.push(yield getTileById(roomStore.tileIds[i], keepIds)) + } + return tiles +} + +export const getTileById = function* (id, keepIds) { const tileStore = yield select(OBJECT_SELECTORS['tile']) + return { + _id: keepIds ? id : undefined, + positionX: tileStore[id].positionX, + positionY: tileStore[id].positionY, + rack: !tileStore[id].rackId ? undefined : yield getRackById(tileStore[id].rackId, keepIds), + } +} + +export const getRackById = function* (id, keepIds) { const rackStore = yield select(OBJECT_SELECTORS['rack']) const machineStore = yield select(OBJECT_SELECTORS['machine']) const cpuStore = yield select(OBJECT_SELECTORS['cpu']) @@ -158,35 +200,20 @@ export const getTopologyAsObject = function* (id, keepIds) { const storageStore = yield select(OBJECT_SELECTORS['storage']) return { - _id: keepIds ? id : undefined, - name: topologyStore[id].name, - rooms: topologyStore[id].roomIds.map((roomId) => ({ - _id: keepIds ? roomId : undefined, - name: roomStore[roomId].name, - tiles: roomStore[roomId].tileIds.map((tileId) => ({ - _id: keepIds ? tileId : undefined, - positionX: tileStore[tileId].positionX, - positionY: tileStore[tileId].positionY, - rack: !tileStore[tileId].rackId - ? undefined - : { - _id: keepIds ? rackStore[tileStore[tileId].rackId]._id : undefined, - name: rackStore[tileStore[tileId].rackId].name, - capacity: rackStore[tileStore[tileId].rackId].capacity, - powerCapacityW: rackStore[tileStore[tileId].rackId].powerCapacityW, - machines: rackStore[tileStore[tileId].rackId].machineIds - .filter((m) => m !== null) - .map((machineId) => ({ - _id: keepIds ? machineId : undefined, - position: machineStore[machineId].position, - cpus: machineStore[machineId].cpuIds.map((id) => cpuStore[id]), - gpus: machineStore[machineId].gpuIds.map((id) => gpuStore[id]), - memories: machineStore[machineId].memoryIds.map((id) => memoryStore[id]), - storages: machineStore[machineId].storageIds.map((id) => storageStore[id]), - })), - }, + _id: keepIds ? rackStore[id]._id : undefined, + name: rackStore[id].name, + capacity: rackStore[id].capacity, + powerCapacityW: rackStore[id].powerCapacityW, + machines: rackStore[id].machineIds + .filter((m) => m !== null) + .map((machineId) => ({ + _id: keepIds ? machineId : undefined, + position: machineStore[machineId].position, + cpus: machineStore[machineId].cpuIds.map((id) => cpuStore[id]), + gpus: machineStore[machineId].gpuIds.map((id) => gpuStore[id]), + memories: machineStore[machineId].memoryIds.map((id) => memoryStore[id]), + storages: machineStore[machineId].storageIds.map((id) => storageStore[id]), })), - })), } } |
