summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-ui/src/redux/actions
diff options
context:
space:
mode:
Diffstat (limited to 'opendc-web/opendc-web-ui/src/redux/actions')
-rw-r--r--opendc-web/opendc-web-ui/src/redux/actions/interaction-level.js50
-rw-r--r--opendc-web/opendc-web-ui/src/redux/actions/map.js83
-rw-r--r--opendc-web/opendc-web-ui/src/redux/actions/objects.js41
-rw-r--r--opendc-web/opendc-web-ui/src/redux/actions/portfolios.js41
-rw-r--r--opendc-web/opendc-web-ui/src/redux/actions/prefabs.js32
-rw-r--r--opendc-web/opendc-web-ui/src/redux/actions/projects.js55
-rw-r--r--opendc-web/opendc-web-ui/src/redux/actions/scenarios.js43
-rw-r--r--opendc-web/opendc-web-ui/src/redux/actions/topologies.js17
-rw-r--r--opendc-web/opendc-web-ui/src/redux/actions/topology/building.js105
-rw-r--r--opendc-web/opendc-web-ui/src/redux/actions/topology/machine.js25
-rw-r--r--opendc-web/opendc-web-ui/src/redux/actions/topology/rack.js23
-rw-r--r--opendc-web/opendc-web-ui/src/redux/actions/topology/room.js48
12 files changed, 563 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..ff6b1fa3
--- /dev/null
+++ b/opendc-web/opendc-web-ui/src/redux/actions/interaction-level.js
@@ -0,0 +1,50 @@
+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 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/map.js b/opendc-web/opendc-web-ui/src/redux/actions/map.js
new file mode 100644
index 00000000..aa14cacd
--- /dev/null
+++ b/opendc-web/opendc-web-ui/src/redux/actions/map.js
@@ -0,0 +1,83 @@
+import {
+ MAP_MAX_SCALE,
+ MAP_MIN_SCALE,
+ MAP_SCALE_PER_EVENT,
+ MAP_SIZE_IN_PIXELS,
+} from '../../components/app/map/MapConstants'
+
+export const SET_MAP_POSITION = 'SET_MAP_POSITION'
+export const SET_MAP_DIMENSIONS = 'SET_MAP_DIMENSIONS'
+export const SET_MAP_SCALE = 'SET_MAP_SCALE'
+
+export function setMapPosition(x, y) {
+ return {
+ type: SET_MAP_POSITION,
+ x,
+ y,
+ }
+}
+
+export function setMapDimensions(width, height) {
+ return {
+ type: SET_MAP_DIMENSIONS,
+ width,
+ height,
+ }
+}
+
+export function setMapScale(scale) {
+ return {
+ type: SET_MAP_SCALE,
+ scale,
+ }
+}
+
+export function zoomInOnCenter(zoomIn) {
+ return (dispatch, getState) => {
+ const state = getState()
+
+ dispatch(zoomInOnPosition(zoomIn, state.map.dimensions.width / 2, state.map.dimensions.height / 2))
+ }
+}
+
+export function zoomInOnPosition(zoomIn, x, y) {
+ return (dispatch, getState) => {
+ const state = getState()
+
+ const centerPoint = {
+ x: x / state.map.scale - state.map.position.x / state.map.scale,
+ y: y / state.map.scale - state.map.position.y / state.map.scale,
+ }
+ const newScale = zoomIn ? state.map.scale * MAP_SCALE_PER_EVENT : state.map.scale / MAP_SCALE_PER_EVENT
+ const boundedScale = Math.min(Math.max(MAP_MIN_SCALE, newScale), MAP_MAX_SCALE)
+
+ const newX = -(centerPoint.x - x / boundedScale) * boundedScale
+ const newY = -(centerPoint.y - y / boundedScale) * boundedScale
+
+ dispatch(setMapPositionWithBoundsCheck(newX, newY))
+ dispatch(setMapScale(boundedScale))
+ }
+}
+
+export function setMapPositionWithBoundsCheck(x, y) {
+ return (dispatch, getState) => {
+ const state = getState()
+
+ const scaledMapSize = MAP_SIZE_IN_PIXELS * state.map.scale
+
+ const updatedX =
+ x > 0
+ ? 0
+ : x < -scaledMapSize + state.map.dimensions.width
+ ? -scaledMapSize + state.map.dimensions.width
+ : x
+ const updatedY =
+ y > 0
+ ? 0
+ : y < -scaledMapSize + state.map.dimensions.height
+ ? -scaledMapSize + state.map.dimensions.height
+ : y
+
+ dispatch(setMapPosition(updatedX, updatedY))
+ }
+}
diff --git a/opendc-web/opendc-web-ui/src/redux/actions/objects.js b/opendc-web/opendc-web-ui/src/redux/actions/objects.js
new file mode 100644
index 00000000..7b648b18
--- /dev/null
+++ b/opendc-web/opendc-web-ui/src/redux/actions/objects.js
@@ -0,0 +1,41 @@
+export const ADD_TO_STORE = 'ADD_TO_STORE'
+export const ADD_PROP_TO_STORE_OBJECT = 'ADD_PROP_TO_STORE_OBJECT'
+export const ADD_ID_TO_STORE_OBJECT_LIST_PROP = 'ADD_ID_TO_STORE_OBJECT_LIST_PROP'
+export const REMOVE_ID_FROM_STORE_OBJECT_LIST_PROP = 'REMOVE_ID_FROM_STORE_OBJECT_LIST_PROP'
+
+export function addToStore(objectType, object) {
+ return {
+ type: ADD_TO_STORE,
+ objectType,
+ object,
+ }
+}
+
+export function addPropToStoreObject(objectType, objectId, propObject) {
+ return {
+ type: ADD_PROP_TO_STORE_OBJECT,
+ objectType,
+ objectId,
+ propObject,
+ }
+}
+
+export function addIdToStoreObjectListProp(objectType, objectId, propName, id) {
+ return {
+ type: ADD_ID_TO_STORE_OBJECT_LIST_PROP,
+ objectType,
+ objectId,
+ propName,
+ id,
+ }
+}
+
+export function removeIdFromStoreObjectListProp(objectType, objectId, propName, id) {
+ return {
+ type: REMOVE_ID_FROM_STORE_OBJECT_LIST_PROP,
+ objectType,
+ objectId,
+ propName,
+ id,
+ }
+}
diff --git a/opendc-web/opendc-web-ui/src/redux/actions/portfolios.js b/opendc-web/opendc-web-ui/src/redux/actions/portfolios.js
new file mode 100644
index 00000000..d37886d8
--- /dev/null
+++ b/opendc-web/opendc-web-ui/src/redux/actions/portfolios.js
@@ -0,0 +1,41 @@
+export const ADD_PORTFOLIO = 'ADD_PORTFOLIO'
+export const UPDATE_PORTFOLIO = 'UPDATE_PORTFOLIO'
+export const DELETE_PORTFOLIO = 'DELETE_PORTFOLIO'
+export const OPEN_PORTFOLIO_SUCCEEDED = 'OPEN_PORTFOLIO_SUCCEEDED'
+export const SET_CURRENT_PORTFOLIO = 'SET_CURRENT_PORTFOLIO'
+
+export function addPortfolio(portfolio) {
+ return {
+ type: ADD_PORTFOLIO,
+ portfolio,
+ }
+}
+
+export function updatePortfolio(portfolio) {
+ return {
+ type: UPDATE_PORTFOLIO,
+ portfolio,
+ }
+}
+
+export function deletePortfolio(id) {
+ return {
+ type: DELETE_PORTFOLIO,
+ id,
+ }
+}
+
+export function openPortfolioSucceeded(projectId, portfolioId) {
+ return {
+ type: OPEN_PORTFOLIO_SUCCEEDED,
+ projectId,
+ portfolioId,
+ }
+}
+
+export function setCurrentPortfolio(portfolioId) {
+ return {
+ type: SET_CURRENT_PORTFOLIO,
+ portfolioId,
+ }
+}
diff --git a/opendc-web/opendc-web-ui/src/redux/actions/prefabs.js b/opendc-web/opendc-web-ui/src/redux/actions/prefabs.js
new file mode 100644
index 00000000..c112feed
--- /dev/null
+++ b/opendc-web/opendc-web-ui/src/redux/actions/prefabs.js
@@ -0,0 +1,32 @@
+export const ADD_PREFAB = 'ADD_PREFAB'
+export const DELETE_PREFAB = 'DELETE_PREFAB'
+export const DELETE_PREFAB_SUCCEEDED = 'DELETE_PREFAB_SUCCEEDED'
+export const OPEN_PREFAB_SUCCEEDED = 'OPEN_PREFAB_SUCCEEDED'
+
+export function addPrefab(name) {
+ return {
+ type: ADD_PREFAB,
+ name,
+ }
+}
+
+export function deletePrefab(id) {
+ return {
+ type: DELETE_PREFAB,
+ id,
+ }
+}
+
+export function deletePrefabSucceeded(id) {
+ return {
+ type: DELETE_PREFAB_SUCCEEDED,
+ id,
+ }
+}
+
+export function openPrefabSucceeded(id) {
+ return {
+ type: OPEN_PREFAB_SUCCEEDED,
+ id,
+ }
+}
diff --git a/opendc-web/opendc-web-ui/src/redux/actions/projects.js b/opendc-web/opendc-web-ui/src/redux/actions/projects.js
new file mode 100644
index 00000000..a6324c43
--- /dev/null
+++ b/opendc-web/opendc-web-ui/src/redux/actions/projects.js
@@ -0,0 +1,55 @@
+export const FETCH_PROJECTS = 'FETCH_PROJECTS'
+export const FETCH_PROJECTS_SUCCEEDED = 'FETCH_PROJECTS_SUCCEEDED'
+export const ADD_PROJECT = 'ADD_PROJECT'
+export const ADD_PROJECT_SUCCEEDED = 'ADD_PROJECT_SUCCEEDED'
+export const DELETE_PROJECT = 'DELETE_PROJECT'
+export const DELETE_PROJECT_SUCCEEDED = 'DELETE_PROJECT_SUCCEEDED'
+export const OPEN_PROJECT_SUCCEEDED = 'OPEN_PROJECT_SUCCEEDED'
+
+export function fetchProjects() {
+ return {
+ type: FETCH_PROJECTS,
+ }
+}
+
+export function fetchProjectsSucceeded(projects) {
+ return {
+ type: FETCH_PROJECTS_SUCCEEDED,
+ projects,
+ }
+}
+
+export function addProject(name) {
+ return {
+ type: ADD_PROJECT,
+ name,
+ }
+}
+
+export function addProjectSucceeded(project) {
+ return {
+ type: ADD_PROJECT_SUCCEEDED,
+ project,
+ }
+}
+
+export function deleteProject(id) {
+ return {
+ type: DELETE_PROJECT,
+ id,
+ }
+}
+
+export function deleteProjectSucceeded(id) {
+ return {
+ type: DELETE_PROJECT_SUCCEEDED,
+ id,
+ }
+}
+
+export function openProjectSucceeded(id) {
+ return {
+ type: OPEN_PROJECT_SUCCEEDED,
+ id,
+ }
+}
diff --git a/opendc-web/opendc-web-ui/src/redux/actions/scenarios.js b/opendc-web/opendc-web-ui/src/redux/actions/scenarios.js
new file mode 100644
index 00000000..c8a90762
--- /dev/null
+++ b/opendc-web/opendc-web-ui/src/redux/actions/scenarios.js
@@ -0,0 +1,43 @@
+export const ADD_SCENARIO = 'ADD_SCENARIO'
+export const UPDATE_SCENARIO = 'UPDATE_SCENARIO'
+export const DELETE_SCENARIO = 'DELETE_SCENARIO'
+export const OPEN_SCENARIO_SUCCEEDED = 'OPEN_SCENARIO_SUCCEEDED'
+export const SET_CURRENT_SCENARIO = 'SET_CURRENT_SCENARIO'
+
+export function addScenario(scenario) {
+ return {
+ type: ADD_SCENARIO,
+ scenario,
+ }
+}
+
+export function updateScenario(scenario) {
+ return {
+ type: UPDATE_SCENARIO,
+ scenario,
+ }
+}
+
+export function deleteScenario(id) {
+ return {
+ type: DELETE_SCENARIO,
+ id,
+ }
+}
+
+export function openScenarioSucceeded(projectId, portfolioId, scenarioId) {
+ return {
+ type: OPEN_SCENARIO_SUCCEEDED,
+ projectId,
+ portfolioId,
+ scenarioId,
+ }
+}
+
+export function setCurrentScenario(portfolioId, scenarioId) {
+ return {
+ type: SET_CURRENT_SCENARIO,
+ portfolioId,
+ scenarioId,
+ }
+}
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..dcce3b7d
--- /dev/null
+++ b/opendc-web/opendc-web-ui/src/redux/actions/topologies.js
@@ -0,0 +1,17 @@
+export const ADD_TOPOLOGY = 'ADD_TOPOLOGY'
+export const DELETE_TOPOLOGY = 'DELETE_TOPOLOGY'
+
+export function addTopology(name, duplicateId) {
+ return {
+ type: ADD_TOPOLOGY,
+ name,
+ duplicateId,
+ }
+}
+
+export function deleteTopology(id) {
+ return {
+ type: DELETE_TOPOLOGY,
+ id,
+ }
+}
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..72deda6f
--- /dev/null
+++ b/opendc-web/opendc-web-ui/src/redux/actions/topology/building.js
@@ -0,0 +1,105 @@
+export const SET_CURRENT_TOPOLOGY = 'SET_CURRENT_TOPOLOGY'
+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 setCurrentTopology(topologyId) {
+ return {
+ type: SET_CURRENT_TOPOLOGY,
+ topologyId,
+ }
+}
+
+export function startNewRoomConstruction() {
+ return {
+ type: START_NEW_ROOM_CONSTRUCTION,
+ }
+}
+
+export function startNewRoomConstructionSucceeded(roomId) {
+ return {
+ type: START_NEW_ROOM_CONSTRUCTION_SUCCEEDED,
+ roomId,
+ }
+}
+
+export function finishNewRoomConstruction() {
+ return (dispatch, getState) => {
+ const { objects, construction } = getState()
+ if (objects.room[construction.currentRoomInConstruction].tileIds.length === 0) {
+ dispatch(cancelNewRoomConstruction())
+ return
+ }
+
+ dispatch({
+ type: FINISH_NEW_ROOM_CONSTRUCTION,
+ })
+ }
+}
+
+export function cancelNewRoomConstruction() {
+ return {
+ type: CANCEL_NEW_ROOM_CONSTRUCTION,
+ }
+}
+
+export function cancelNewRoomConstructionSucceeded() {
+ return {
+ type: CANCEL_NEW_ROOM_CONSTRUCTION_SUCCEEDED,
+ }
+}
+
+export function startRoomEdit() {
+ return (dispatch, getState) => {
+ const { interactionLevel } = getState()
+ dispatch({
+ type: START_ROOM_EDIT,
+ roomId: interactionLevel.roomId,
+ })
+ }
+}
+
+export function finishRoomEdit() {
+ return {
+ type: FINISH_ROOM_EDIT,
+ }
+}
+
+export function toggleTileAtLocation(positionX, positionY) {
+ return (dispatch, getState) => {
+ const { objects, construction } = getState()
+
+ const tileIds = objects.room[construction.currentRoomInConstruction].tileIds
+ for (let index in tileIds) {
+ if (
+ objects.tile[tileIds[index]].positionX === positionX &&
+ objects.tile[tileIds[index]].positionY === positionY
+ ) {
+ dispatch(deleteTile(tileIds[index]))
+ return
+ }
+ }
+ dispatch(addTile(positionX, positionY))
+ }
+}
+
+export function addTile(positionX, positionY) {
+ return {
+ type: ADD_TILE,
+ 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..17ccce5d
--- /dev/null
+++ b/opendc-web/opendc-web-ui/src/redux/actions/topology/machine.js
@@ -0,0 +1,25 @@
+export const DELETE_MACHINE = 'DELETE_MACHINE'
+export const ADD_UNIT = 'ADD_UNIT'
+export const DELETE_UNIT = 'DELETE_UNIT'
+
+export function deleteMachine() {
+ return {
+ type: DELETE_MACHINE,
+ }
+}
+
+export function addUnit(unitType, id) {
+ return {
+ type: ADD_UNIT,
+ unitType,
+ id,
+ }
+}
+
+export function deleteUnit(unitType, index) {
+ return {
+ type: DELETE_UNIT,
+ unitType,
+ index,
+ }
+}
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..b117402e
--- /dev/null
+++ b/opendc-web/opendc-web-ui/src/redux/actions/topology/rack.js
@@ -0,0 +1,23 @@
+export const EDIT_RACK_NAME = 'EDIT_RACK_NAME'
+export const DELETE_RACK = 'DELETE_RACK'
+export const ADD_MACHINE = 'ADD_MACHINE'
+
+export function editRackName(name) {
+ return {
+ type: EDIT_RACK_NAME,
+ name,
+ }
+}
+
+export function deleteRack() {
+ return {
+ type: DELETE_RACK,
+ }
+}
+
+export function addMachine(position) {
+ return {
+ type: ADD_MACHINE,
+ position,
+ }
+}
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..61eea7fe
--- /dev/null
+++ b/opendc-web/opendc-web-ui/src/redux/actions/topology/room.js
@@ -0,0 +1,48 @@
+import { findTileWithPosition } from '../../../util/tile-calculations'
+
+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 editRoomName(name) {
+ return {
+ type: EDIT_ROOM_NAME,
+ name,
+ }
+}
+
+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 { objects, interactionLevel } = getState()
+ const currentRoom = objects.room[interactionLevel.roomId]
+ const tiles = currentRoom.tileIds.map((tileId) => objects.tile[tileId])
+ const tile = findTileWithPosition(tiles, positionX, positionY)
+
+ if (tile !== null) {
+ dispatch({
+ type: ADD_RACK_TO_TILE,
+ tileId: tile._id,
+ })
+ }
+ }
+}
+
+export function deleteRoom() {
+ return {
+ type: DELETE_ROOM,
+ }
+}