From 90fae26aa4bd0e0eb3272ff6e6524060e9004fbb Mon Sep 17 00:00:00 2001 From: Georgios Andreadis Date: Mon, 29 Jun 2020 15:47:09 +0200 Subject: Prepare frontend repository for monorepo This change prepares the frontend Git repository for the monorepo residing at https://github.com/atlarge-research.com/opendc. To accomodate for this, we move all files into a frontend subdirectory. --- frontend/src/actions/auth.js | 23 +++++ frontend/src/actions/experiments.js | 34 +++++++ frontend/src/actions/interaction-level.js | 50 +++++++++++ frontend/src/actions/map.js | 93 ++++++++++++++++++++ frontend/src/actions/modals/experiments.js | 14 +++ frontend/src/actions/modals/profile.js | 14 +++ frontend/src/actions/modals/simulations.js | 14 +++ frontend/src/actions/modals/topology.js | 70 +++++++++++++++ frontend/src/actions/objects.js | 48 ++++++++++ frontend/src/actions/profile.js | 0 frontend/src/actions/simulation/load-metric.js | 8 ++ frontend/src/actions/simulation/playback.js | 15 ++++ frontend/src/actions/simulation/tick.js | 49 +++++++++++ frontend/src/actions/simulations.js | 52 +++++++++++ frontend/src/actions/states.js | 9 ++ frontend/src/actions/topology/building.js | 117 +++++++++++++++++++++++++ frontend/src/actions/topology/machine.js | 25 ++++++ frontend/src/actions/topology/rack.js | 23 +++++ frontend/src/actions/topology/room.js | 48 ++++++++++ frontend/src/actions/users.js | 41 +++++++++ 20 files changed, 747 insertions(+) create mode 100644 frontend/src/actions/auth.js create mode 100644 frontend/src/actions/experiments.js create mode 100644 frontend/src/actions/interaction-level.js create mode 100644 frontend/src/actions/map.js create mode 100644 frontend/src/actions/modals/experiments.js create mode 100644 frontend/src/actions/modals/profile.js create mode 100644 frontend/src/actions/modals/simulations.js create mode 100644 frontend/src/actions/modals/topology.js create mode 100644 frontend/src/actions/objects.js create mode 100644 frontend/src/actions/profile.js create mode 100644 frontend/src/actions/simulation/load-metric.js create mode 100644 frontend/src/actions/simulation/playback.js create mode 100644 frontend/src/actions/simulation/tick.js create mode 100644 frontend/src/actions/simulations.js create mode 100644 frontend/src/actions/states.js create mode 100644 frontend/src/actions/topology/building.js create mode 100644 frontend/src/actions/topology/machine.js create mode 100644 frontend/src/actions/topology/rack.js create mode 100644 frontend/src/actions/topology/room.js create mode 100644 frontend/src/actions/users.js (limited to 'frontend/src/actions') diff --git a/frontend/src/actions/auth.js b/frontend/src/actions/auth.js new file mode 100644 index 00000000..45e2eb35 --- /dev/null +++ b/frontend/src/actions/auth.js @@ -0,0 +1,23 @@ +export const LOG_IN = "LOG_IN"; +export const LOG_IN_SUCCEEDED = "LOG_IN_SUCCEEDED"; +export const LOG_OUT = "LOG_OUT"; + +export function logIn(payload) { + return { + type: LOG_IN, + payload + }; +} + +export function logInSucceeded(payload) { + return { + type: LOG_IN_SUCCEEDED, + payload + }; +} + +export function logOut() { + return { + type: LOG_OUT + }; +} diff --git a/frontend/src/actions/experiments.js b/frontend/src/actions/experiments.js new file mode 100644 index 00000000..b5709981 --- /dev/null +++ b/frontend/src/actions/experiments.js @@ -0,0 +1,34 @@ +export const FETCH_EXPERIMENTS_OF_SIMULATION = + "FETCH_EXPERIMENTS_OF_SIMULATION"; +export const ADD_EXPERIMENT = "ADD_EXPERIMENT"; +export const DELETE_EXPERIMENT = "DELETE_EXPERIMENT"; +export const OPEN_EXPERIMENT_SUCCEEDED = "OPEN_EXPERIMENT_SUCCEEDED"; + +export function fetchExperimentsOfSimulation(simulationId) { + return { + type: FETCH_EXPERIMENTS_OF_SIMULATION, + simulationId + }; +} + +export function addExperiment(experiment) { + return { + type: ADD_EXPERIMENT, + experiment + }; +} + +export function deleteExperiment(id) { + return { + type: DELETE_EXPERIMENT, + id + }; +} + +export function openExperimentSucceeded(simulationId, experimentId) { + return { + type: OPEN_EXPERIMENT_SUCCEEDED, + simulationId, + experimentId + }; +} diff --git a/frontend/src/actions/interaction-level.js b/frontend/src/actions/interaction-level.js new file mode 100644 index 00000000..31120146 --- /dev/null +++ b/frontend/src/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/frontend/src/actions/map.js b/frontend/src/actions/map.js new file mode 100644 index 00000000..82546c00 --- /dev/null +++ b/frontend/src/actions/map.js @@ -0,0 +1,93 @@ +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/frontend/src/actions/modals/experiments.js b/frontend/src/actions/modals/experiments.js new file mode 100644 index 00000000..df939fa5 --- /dev/null +++ b/frontend/src/actions/modals/experiments.js @@ -0,0 +1,14 @@ +export const OPEN_NEW_EXPERIMENT_MODAL = "OPEN_NEW_EXPERIMENT_MODAL"; +export const CLOSE_NEW_EXPERIMENT_MODAL = "CLOSE_EXPERIMENT_MODAL"; + +export function openNewExperimentModal() { + return { + type: OPEN_NEW_EXPERIMENT_MODAL + }; +} + +export function closeNewExperimentModal() { + return { + type: CLOSE_NEW_EXPERIMENT_MODAL + }; +} diff --git a/frontend/src/actions/modals/profile.js b/frontend/src/actions/modals/profile.js new file mode 100644 index 00000000..ee52610c --- /dev/null +++ b/frontend/src/actions/modals/profile.js @@ -0,0 +1,14 @@ +export const OPEN_DELETE_PROFILE_MODAL = "OPEN_DELETE_PROFILE_MODAL"; +export const CLOSE_DELETE_PROFILE_MODAL = "CLOSE_DELETE_PROFILE_MODAL"; + +export function openDeleteProfileModal() { + return { + type: OPEN_DELETE_PROFILE_MODAL + }; +} + +export function closeDeleteProfileModal() { + return { + type: CLOSE_DELETE_PROFILE_MODAL + }; +} diff --git a/frontend/src/actions/modals/simulations.js b/frontend/src/actions/modals/simulations.js new file mode 100644 index 00000000..b11d356c --- /dev/null +++ b/frontend/src/actions/modals/simulations.js @@ -0,0 +1,14 @@ +export const OPEN_NEW_SIMULATION_MODAL = "OPEN_NEW_SIMULATION_MODAL"; +export const CLOSE_NEW_SIMULATION_MODAL = "CLOSE_SIMULATION_MODAL"; + +export function openNewSimulationModal() { + return { + type: OPEN_NEW_SIMULATION_MODAL + }; +} + +export function closeNewSimulationModal() { + return { + type: CLOSE_NEW_SIMULATION_MODAL + }; +} diff --git a/frontend/src/actions/modals/topology.js b/frontend/src/actions/modals/topology.js new file mode 100644 index 00000000..7ee16522 --- /dev/null +++ b/frontend/src/actions/modals/topology.js @@ -0,0 +1,70 @@ +export const OPEN_EDIT_ROOM_NAME_MODAL = "OPEN_EDIT_ROOM_NAME_MODAL"; +export const CLOSE_EDIT_ROOM_NAME_MODAL = "CLOSE_EDIT_ROOM_NAME_MODAL"; +export const OPEN_DELETE_ROOM_MODAL = "OPEN_DELETE_ROOM_MODAL"; +export const CLOSE_DELETE_ROOM_MODAL = "CLOSE_DELETE_ROOM_MODAL"; +export const OPEN_EDIT_RACK_NAME_MODAL = "OPEN_EDIT_RACK_NAME_MODAL"; +export const CLOSE_EDIT_RACK_NAME_MODAL = "CLOSE_EDIT_RACK_NAME_MODAL"; +export const OPEN_DELETE_RACK_MODAL = "OPEN_DELETE_RACK_MODAL"; +export const CLOSE_DELETE_RACK_MODAL = "CLOSE_DELETE_RACK_MODAL"; +export const OPEN_DELETE_MACHINE_MODAL = "OPEN_DELETE_MACHINE_MODAL"; +export const CLOSE_DELETE_MACHINE_MODAL = "CLOSE_DELETE_MACHINE_MODAL"; + +export function openEditRoomNameModal() { + return { + type: OPEN_EDIT_ROOM_NAME_MODAL + }; +} + +export function closeEditRoomNameModal() { + return { + type: CLOSE_EDIT_ROOM_NAME_MODAL + }; +} + +export function openDeleteRoomModal() { + return { + type: OPEN_DELETE_ROOM_MODAL + }; +} + +export function closeDeleteRoomModal() { + return { + type: CLOSE_DELETE_ROOM_MODAL + }; +} + +export function openEditRackNameModal() { + return { + type: OPEN_EDIT_RACK_NAME_MODAL + }; +} + +export function closeEditRackNameModal() { + return { + type: CLOSE_EDIT_RACK_NAME_MODAL + }; +} + +export function openDeleteRackModal() { + return { + type: OPEN_DELETE_RACK_MODAL + }; +} + +export function closeDeleteRackModal() { + return { + type: CLOSE_DELETE_RACK_MODAL + }; +} + +export function openDeleteMachineModal() { + return { + type: OPEN_DELETE_MACHINE_MODAL + }; +} + +export function closeDeleteMachineModal() { + return { + type: CLOSE_DELETE_MACHINE_MODAL + }; +} diff --git a/frontend/src/actions/objects.js b/frontend/src/actions/objects.js new file mode 100644 index 00000000..80b56c0c --- /dev/null +++ b/frontend/src/actions/objects.js @@ -0,0 +1,48 @@ +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/frontend/src/actions/profile.js b/frontend/src/actions/profile.js new file mode 100644 index 00000000..e69de29b diff --git a/frontend/src/actions/simulation/load-metric.js b/frontend/src/actions/simulation/load-metric.js new file mode 100644 index 00000000..c59e3596 --- /dev/null +++ b/frontend/src/actions/simulation/load-metric.js @@ -0,0 +1,8 @@ +export const CHANGE_LOAD_METRIC = "CHANGE_LOAD_METRIC"; + +export function changeLoadMetric(metric) { + return { + type: CHANGE_LOAD_METRIC, + metric + }; +} diff --git a/frontend/src/actions/simulation/playback.js b/frontend/src/actions/simulation/playback.js new file mode 100644 index 00000000..8e913914 --- /dev/null +++ b/frontend/src/actions/simulation/playback.js @@ -0,0 +1,15 @@ +export const SET_PLAYING = "SET_PLAYING"; + +export function playSimulation() { + return { + type: SET_PLAYING, + playing: true + }; +} + +export function pauseSimulation() { + return { + type: SET_PLAYING, + playing: false + }; +} diff --git a/frontend/src/actions/simulation/tick.js b/frontend/src/actions/simulation/tick.js new file mode 100644 index 00000000..a629b340 --- /dev/null +++ b/frontend/src/actions/simulation/tick.js @@ -0,0 +1,49 @@ +import { getDatacenterIdOfTick } from "../../util/timeline"; +import { setCurrentDatacenter } from "../topology/building"; + +export const GO_TO_TICK = "GO_TO_TICK"; +export const SET_LAST_SIMULATED_TICK = "SET_LAST_SIMULATED_TICK"; + +export function incrementTick() { + return (dispatch, getState) => { + const { currentTick } = getState(); + dispatch(goToTick(currentTick + 1)); + }; +} + +export function goToTick(tick) { + return (dispatch, getState) => { + const state = getState(); + + let sections = []; + if (state.currentExperimentId !== -1) { + const sectionIds = + state.objects.path[ + state.objects.experiment[state.currentExperimentId].pathId + ].sectionIds; + + if (sectionIds) { + sections = sectionIds.map( + sectionId => state.objects.section[sectionId] + ); + } + } + + const newDatacenterId = getDatacenterIdOfTick(tick, sections); + if (state.currentDatacenterId !== newDatacenterId) { + dispatch(setCurrentDatacenter(newDatacenterId)); + } + + dispatch({ + type: GO_TO_TICK, + tick + }); + }; +} + +export function setLastSimulatedTick(tick) { + return { + type: SET_LAST_SIMULATED_TICK, + tick + }; +} diff --git a/frontend/src/actions/simulations.js b/frontend/src/actions/simulations.js new file mode 100644 index 00000000..6da7aa3a --- /dev/null +++ b/frontend/src/actions/simulations.js @@ -0,0 +1,52 @@ +export const SET_AUTH_VISIBILITY_FILTER = "SET_AUTH_VISIBILITY_FILTER"; +export const ADD_SIMULATION = "ADD_SIMULATION"; +export const ADD_SIMULATION_SUCCEEDED = "ADD_SIMULATION_SUCCEEDED"; +export const DELETE_SIMULATION = "DELETE_SIMULATION"; +export const DELETE_SIMULATION_SUCCEEDED = "DELETE_SIMULATION_SUCCEEDED"; +export const OPEN_SIMULATION_SUCCEEDED = "OPEN_SIMULATION_SUCCEEDED"; + +export function setAuthVisibilityFilter(filter) { + return { + type: SET_AUTH_VISIBILITY_FILTER, + filter + }; +} + +export function addSimulation(name) { + return (dispatch, getState) => { + const { auth } = getState(); + dispatch({ + type: ADD_SIMULATION, + name, + userId: auth.userId + }); + }; +} + +export function addSimulationSucceeded(authorization) { + return { + type: ADD_SIMULATION_SUCCEEDED, + authorization + }; +} + +export function deleteSimulation(id) { + return { + type: DELETE_SIMULATION, + id + }; +} + +export function deleteSimulationSucceeded(id) { + return { + type: DELETE_SIMULATION_SUCCEEDED, + id + }; +} + +export function openSimulationSucceeded(id) { + return { + type: OPEN_SIMULATION_SUCCEEDED, + id + }; +} diff --git a/frontend/src/actions/states.js b/frontend/src/actions/states.js new file mode 100644 index 00000000..b3a355a2 --- /dev/null +++ b/frontend/src/actions/states.js @@ -0,0 +1,9 @@ +export const ADD_BATCH_TO_STATES = "ADD_BATCH_TO_STATES"; + +export function addBatchToStates(objectType, objects) { + return { + type: ADD_BATCH_TO_STATES, + objectType, + objects + }; +} diff --git a/frontend/src/actions/topology/building.js b/frontend/src/actions/topology/building.js new file mode 100644 index 00000000..c6381a07 --- /dev/null +++ b/frontend/src/actions/topology/building.js @@ -0,0 +1,117 @@ +export const SET_CURRENT_DATACENTER = "SET_CURRENT_DATACENTER"; +export const RESET_CURRENT_DATACENTER = "RESET_CURRENT_DATACENTER"; +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 setCurrentDatacenter(datacenterId) { + return { + type: SET_CURRENT_DATACENTER, + datacenterId + }; +} + +export function resetCurrentDatacenter() { + return { + type: RESET_CURRENT_DATACENTER + }; +} + +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/frontend/src/actions/topology/machine.js b/frontend/src/actions/topology/machine.js new file mode 100644 index 00000000..56968b7d --- /dev/null +++ b/frontend/src/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/frontend/src/actions/topology/rack.js b/frontend/src/actions/topology/rack.js new file mode 100644 index 00000000..06988424 --- /dev/null +++ b/frontend/src/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/frontend/src/actions/topology/room.js b/frontend/src/actions/topology/room.js new file mode 100644 index 00000000..4e0fc3a2 --- /dev/null +++ b/frontend/src/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 + }; +} diff --git a/frontend/src/actions/users.js b/frontend/src/actions/users.js new file mode 100644 index 00000000..dc393df9 --- /dev/null +++ b/frontend/src/actions/users.js @@ -0,0 +1,41 @@ +export const FETCH_AUTHORIZATIONS_OF_CURRENT_USER = + "FETCH_AUTHORIZATIONS_OF_CURRENT_USER"; +export const FETCH_AUTHORIZATIONS_OF_CURRENT_USER_SUCCEEDED = + "FETCH_AUTHORIZATIONS_OF_CURRENT_USER_SUCCEEDED"; +export const DELETE_CURRENT_USER = "DELETE_CURRENT_USER"; +export const DELETE_CURRENT_USER_SUCCEEDED = "DELETE_CURRENT_USER_SUCCEEDED"; + +export function fetchAuthorizationsOfCurrentUser() { + return (dispatch, getState) => { + const { auth } = getState(); + dispatch({ + type: FETCH_AUTHORIZATIONS_OF_CURRENT_USER, + userId: auth.userId + }); + }; +} + +export function fetchAuthorizationsOfCurrentUserSucceeded( + authorizationsOfCurrentUser +) { + return { + type: FETCH_AUTHORIZATIONS_OF_CURRENT_USER_SUCCEEDED, + authorizationsOfCurrentUser + }; +} + +export function deleteCurrentUser() { + return (dispatch, getState) => { + const { auth } = getState(); + dispatch({ + type: DELETE_CURRENT_USER, + userId: auth.userId + }); + }; +} + +export function deleteCurrentUserSucceeded() { + return { + type: DELETE_CURRENT_USER_SUCCEEDED + }; +} -- cgit v1.2.3