summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-ui/src/redux/actions
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2021-10-25 14:53:54 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2021-10-25 14:53:54 +0200
commitaa9b32f8cd1467e9718959f400f6777e5d71737d (patch)
treeb88bbede15108c6855d7f94ded4c7054df186a72 /opendc-web/opendc-web-ui/src/redux/actions
parenteb0e0a3bc557c05a70eead388797ab850ea87366 (diff)
parentb7a71e5b4aa77b41ef41deec2ace42b67a5a13a7 (diff)
merge: Integrate v2.1 progress into public repository
This pull request integrates the changes planned for the v2.1 release of OpenDC into the public Github repository in order to sync the progress of both repositories.
Diffstat (limited to 'opendc-web/opendc-web-ui/src/redux/actions')
-rw-r--r--opendc-web/opendc-web-ui/src/redux/actions/interaction-level.js57
-rw-r--r--opendc-web/opendc-web-ui/src/redux/actions/topologies.js27
-rw-r--r--opendc-web/opendc-web-ui/src/redux/actions/topology/building.js113
-rw-r--r--opendc-web/opendc-web-ui/src/redux/actions/topology/machine.js28
-rw-r--r--opendc-web/opendc-web-ui/src/redux/actions/topology/rack.js36
-rw-r--r--opendc-web/opendc-web-ui/src/redux/actions/topology/room.js74
6 files changed, 335 insertions, 0 deletions
diff --git a/opendc-web/opendc-web-ui/src/redux/actions/interaction-level.js b/opendc-web/opendc-web-ui/src/redux/actions/interaction-level.js
new file mode 100644
index 00000000..8381eeef
--- /dev/null
+++ b/opendc-web/opendc-web-ui/src/redux/actions/interaction-level.js
@@ -0,0 +1,57 @@
+export const GO_FROM_BUILDING_TO_ROOM = 'GO_FROM_BUILDING_TO_ROOM'
+export const GO_FROM_ROOM_TO_RACK = 'GO_FROM_ROOM_TO_RACK'
+export const GO_FROM_RACK_TO_MACHINE = 'GO_FROM_RACK_TO_MACHINE'
+export const GO_DOWN_ONE_INTERACTION_LEVEL = 'GO_DOWN_ONE_INTERACTION_LEVEL'
+
+export function goToRoom(roomId) {
+ return {
+ type: GO_FROM_BUILDING_TO_ROOM,
+ roomId,
+ }
+}
+
+export function goFromBuildingToRoom(roomId) {
+ return (dispatch, getState) => {
+ const { interactionLevel } = getState()
+ if (interactionLevel.mode !== 'BUILDING') {
+ return
+ }
+
+ dispatch({
+ type: GO_FROM_BUILDING_TO_ROOM,
+ roomId,
+ })
+ }
+}
+
+export function goFromRoomToRack(tileId) {
+ return (dispatch, getState) => {
+ const { interactionLevel } = getState()
+ if (interactionLevel.mode !== 'ROOM') {
+ return
+ }
+ dispatch({
+ type: GO_FROM_ROOM_TO_RACK,
+ tileId,
+ })
+ }
+}
+
+export function goFromRackToMachine(position) {
+ return (dispatch, getState) => {
+ const { interactionLevel } = getState()
+ if (interactionLevel.mode !== 'RACK') {
+ return
+ }
+ dispatch({
+ type: GO_FROM_RACK_TO_MACHINE,
+ position,
+ })
+ }
+}
+
+export function goDownOneInteractionLevel() {
+ return {
+ type: GO_DOWN_ONE_INTERACTION_LEVEL,
+ }
+}
diff --git a/opendc-web/opendc-web-ui/src/redux/actions/topologies.js b/opendc-web/opendc-web-ui/src/redux/actions/topologies.js
new file mode 100644
index 00000000..fc697cc2
--- /dev/null
+++ b/opendc-web/opendc-web-ui/src/redux/actions/topologies.js
@@ -0,0 +1,27 @@
+export const OPEN_TOPOLOGY = 'OPEN_TOPOLOGY'
+export const ADD_TOPOLOGY = 'ADD_TOPOLOGY'
+export const STORE_TOPOLOGY = 'STORE_TOPOLOGY'
+
+export function openTopology(id) {
+ return {
+ type: OPEN_TOPOLOGY,
+ id,
+ }
+}
+
+export function addTopology(projectId, name, duplicateId) {
+ return {
+ type: ADD_TOPOLOGY,
+ projectId,
+ name,
+ duplicateId,
+ }
+}
+
+export function storeTopology(topology, entities) {
+ return {
+ type: STORE_TOPOLOGY,
+ topology,
+ entities,
+ }
+}
diff --git a/opendc-web/opendc-web-ui/src/redux/actions/topology/building.js b/opendc-web/opendc-web-ui/src/redux/actions/topology/building.js
new file mode 100644
index 00000000..939c24a4
--- /dev/null
+++ b/opendc-web/opendc-web-ui/src/redux/actions/topology/building.js
@@ -0,0 +1,113 @@
+import { uuid } from 'uuidv4'
+import { addRoom, deleteRoom } from './room'
+
+export const START_NEW_ROOM_CONSTRUCTION = 'START_NEW_ROOM_CONSTRUCTION'
+export const START_NEW_ROOM_CONSTRUCTION_SUCCEEDED = 'START_NEW_ROOM_CONSTRUCTION_SUCCEEDED'
+export const FINISH_NEW_ROOM_CONSTRUCTION = 'FINISH_NEW_ROOM_CONSTRUCTION'
+export const CANCEL_NEW_ROOM_CONSTRUCTION = 'CANCEL_NEW_ROOM_CONSTRUCTION'
+export const CANCEL_NEW_ROOM_CONSTRUCTION_SUCCEEDED = 'CANCEL_NEW_ROOM_CONSTRUCTION_SUCCEEDED'
+export const START_ROOM_EDIT = 'START_ROOM_EDIT'
+export const FINISH_ROOM_EDIT = 'FINISH_ROOM_EDIT'
+export const ADD_TILE = 'ADD_TILE'
+export const DELETE_TILE = 'DELETE_TILE'
+
+export function startNewRoomConstruction() {
+ return (dispatch, getState) => {
+ const { topology } = getState()
+ const topologyId = topology.root._id
+ const room = {
+ _id: uuid(),
+ name: 'Room',
+ topologyId,
+ tiles: [],
+ }
+
+ dispatch(addRoom(topologyId, room))
+ dispatch(startNewRoomConstructionSucceeded(room._id))
+ }
+}
+
+export function startNewRoomConstructionSucceeded(roomId) {
+ return {
+ type: START_NEW_ROOM_CONSTRUCTION_SUCCEEDED,
+ roomId,
+ }
+}
+
+export function finishNewRoomConstruction() {
+ return (dispatch, getState) => {
+ const { topology, construction } = getState()
+ if (topology.rooms[construction.currentRoomInConstruction].tiles.length === 0) {
+ dispatch(cancelNewRoomConstruction())
+ return
+ }
+
+ dispatch({
+ type: FINISH_NEW_ROOM_CONSTRUCTION,
+ })
+ }
+}
+
+export function cancelNewRoomConstruction() {
+ return (dispatch, getState) => {
+ const { construction } = getState()
+ const roomId = construction.currentRoomInConstruction
+ dispatch(deleteRoom(roomId))
+ dispatch(cancelNewRoomConstructionSucceeded())
+ }
+}
+
+export function cancelNewRoomConstructionSucceeded() {
+ return {
+ type: CANCEL_NEW_ROOM_CONSTRUCTION_SUCCEEDED,
+ }
+}
+
+export function startRoomEdit(roomId) {
+ return {
+ type: START_ROOM_EDIT,
+ roomId: roomId,
+ }
+}
+
+export function finishRoomEdit() {
+ return {
+ type: FINISH_ROOM_EDIT,
+ }
+}
+
+export function toggleTileAtLocation(positionX, positionY) {
+ return (dispatch, getState) => {
+ const { topology, construction } = getState()
+
+ const roomId = construction.currentRoomInConstruction
+ const tileIds = topology.rooms[roomId].tiles
+ for (const tileId of tileIds) {
+ if (topology.tiles[tileId].positionX === positionX && topology.tiles[tileId].positionY === positionY) {
+ dispatch(deleteTile(tileId))
+ return
+ }
+ }
+
+ dispatch(addTile(roomId, positionX, positionY))
+ }
+}
+
+export function addTile(roomId, positionX, positionY) {
+ return {
+ type: ADD_TILE,
+ tile: {
+ _id: uuid(),
+ roomId,
+ positionX,
+ positionY,
+ },
+ }
+}
+
+export function deleteTile(tileId) {
+ return {
+ type: DELETE_TILE,
+ tileId,
+ }
+}
diff --git a/opendc-web/opendc-web-ui/src/redux/actions/topology/machine.js b/opendc-web/opendc-web-ui/src/redux/actions/topology/machine.js
new file mode 100644
index 00000000..93320884
--- /dev/null
+++ b/opendc-web/opendc-web-ui/src/redux/actions/topology/machine.js
@@ -0,0 +1,28 @@
+export const DELETE_MACHINE = 'DELETE_MACHINE'
+export const ADD_UNIT = 'ADD_UNIT'
+export const DELETE_UNIT = 'DELETE_UNIT'
+
+export function deleteMachine(machineId) {
+ return {
+ type: DELETE_MACHINE,
+ machineId,
+ }
+}
+
+export function addUnit(machineId, unitType, unitId) {
+ return {
+ type: ADD_UNIT,
+ machineId,
+ unitType,
+ unitId,
+ }
+}
+
+export function deleteUnit(machineId, unitType, unitId) {
+ return {
+ type: DELETE_UNIT,
+ machineId,
+ unitType,
+ unitId,
+ }
+}
diff --git a/opendc-web/opendc-web-ui/src/redux/actions/topology/rack.js b/opendc-web/opendc-web-ui/src/redux/actions/topology/rack.js
new file mode 100644
index 00000000..c319d966
--- /dev/null
+++ b/opendc-web/opendc-web-ui/src/redux/actions/topology/rack.js
@@ -0,0 +1,36 @@
+import { uuid } from 'uuidv4'
+
+export const EDIT_RACK_NAME = 'EDIT_RACK_NAME'
+export const DELETE_RACK = 'DELETE_RACK'
+export const ADD_MACHINE = 'ADD_MACHINE'
+
+export function editRackName(rackId, name) {
+ return {
+ type: EDIT_RACK_NAME,
+ name,
+ rackId,
+ }
+}
+
+export function deleteRack(tileId, rackId) {
+ return {
+ type: DELETE_RACK,
+ rackId,
+ tileId,
+ }
+}
+
+export function addMachine(rackId, position) {
+ return {
+ type: ADD_MACHINE,
+ machine: {
+ _id: uuid(),
+ rackId,
+ position,
+ cpus: [],
+ gpus: [],
+ memories: [],
+ storages: [],
+ },
+ }
+}
diff --git a/opendc-web/opendc-web-ui/src/redux/actions/topology/room.js b/opendc-web/opendc-web-ui/src/redux/actions/topology/room.js
new file mode 100644
index 00000000..bd447db5
--- /dev/null
+++ b/opendc-web/opendc-web-ui/src/redux/actions/topology/room.js
@@ -0,0 +1,74 @@
+import { uuid } from 'uuidv4'
+import {
+ DEFAULT_RACK_SLOT_CAPACITY,
+ DEFAULT_RACK_POWER_CAPACITY,
+} from '../../../components/topologies/map/MapConstants'
+import { findTileWithPosition } from '../../../util/tile-calculations'
+
+export const ADD_ROOM = 'ADD_ROOM'
+export const EDIT_ROOM_NAME = 'EDIT_ROOM_NAME'
+export const DELETE_ROOM = 'DELETE_ROOM'
+export const START_RACK_CONSTRUCTION = 'START_RACK_CONSTRUCTION'
+export const STOP_RACK_CONSTRUCTION = 'STOP_RACK_CONSTRUCTION'
+export const ADD_RACK_TO_TILE = 'ADD_RACK_TO_TILE'
+
+export function addRoom(topologyId, room) {
+ return {
+ type: ADD_ROOM,
+ room: {
+ _id: uuid(),
+ topologyId,
+ ...room,
+ },
+ }
+}
+
+export function editRoomName(roomId, name) {
+ return {
+ type: EDIT_ROOM_NAME,
+ name,
+ roomId,
+ }
+}
+
+export function startRackConstruction() {
+ return {
+ type: START_RACK_CONSTRUCTION,
+ }
+}
+
+export function stopRackConstruction() {
+ return {
+ type: STOP_RACK_CONSTRUCTION,
+ }
+}
+
+export function addRackToTile(positionX, positionY) {
+ return (dispatch, getState) => {
+ const { topology, interactionLevel } = getState()
+ const currentRoom = topology.rooms[interactionLevel.roomId]
+ const tiles = currentRoom.tiles.map((tileId) => topology.tiles[tileId])
+ const tile = findTileWithPosition(tiles, positionX, positionY)
+
+ if (tile !== null) {
+ dispatch({
+ type: ADD_RACK_TO_TILE,
+ rack: {
+ _id: uuid(),
+ name: 'Rack',
+ tileId: tile._id,
+ capacity: DEFAULT_RACK_SLOT_CAPACITY,
+ powerCapacityW: DEFAULT_RACK_POWER_CAPACITY,
+ machines: [],
+ },
+ })
+ }
+ }
+}
+
+export function deleteRoom(roomId) {
+ return {
+ type: DELETE_ROOM,
+ roomId,
+ }
+}