summaryrefslogtreecommitdiff
path: root/src/containers/map
diff options
context:
space:
mode:
authorGeorgios Andreadis <g.andreadis@student.tudelft.nl>2017-09-05 09:30:42 +0200
committerGeorgios Andreadis <g.andreadis@student.tudelft.nl>2017-09-23 10:05:57 +0200
commit42778e8be409b97059fa519b53c303cdba502e01 (patch)
tree23d03a1f8a9f8d137bf723c72086a6d79406874f /src/containers/map
parent6f3afd0317a8e549f77ad6764f6dbe4d4953b67c (diff)
Implement rack creation
Diffstat (limited to 'src/containers/map')
-rw-r--r--src/containers/map/RoomContainer.js2
-rw-r--r--src/containers/map/layers/ObjectHoverLayer.js35
-rw-r--r--src/containers/map/layers/RoomHoverLayer.js (renamed from src/containers/map/layers/HoverTileLayer.js)19
3 files changed, 48 insertions, 8 deletions
diff --git a/src/containers/map/RoomContainer.js b/src/containers/map/RoomContainer.js
index 2d078e09..9edcb096 100644
--- a/src/containers/map/RoomContainer.js
+++ b/src/containers/map/RoomContainer.js
@@ -5,7 +5,7 @@ import RoomGroup from "../../components/map/groups/RoomGroup";
const mapStateToProps = (state, ownProps) => {
return {
interactionLevel: state.interactionLevel,
- currentRoomInConstruction: state.currentRoomInConstruction,
+ currentRoomInConstruction: state.construction.currentRoomInConstruction,
room: state.objects.room[ownProps.roomId],
};
};
diff --git a/src/containers/map/layers/ObjectHoverLayer.js b/src/containers/map/layers/ObjectHoverLayer.js
new file mode 100644
index 00000000..e9df0384
--- /dev/null
+++ b/src/containers/map/layers/ObjectHoverLayer.js
@@ -0,0 +1,35 @@
+import {connect} from "react-redux";
+import {addRackToTile} from "../../../actions/topology";
+import ObjectHoverLayerComponent from "../../../components/map/layers/ObjectHoverLayerComponent";
+import {findTileWithPosition} from "../../../util/tile-calculations";
+
+const mapStateToProps = state => {
+ return {
+ isEnabled: () => state.construction.inObjectConstructionMode,
+ isValid: (x, y) => {
+ if (state.interactionLevel.mode !== "ROOM") {
+ return false;
+ }
+
+ const currentRoom = state.objects.room[state.interactionLevel.roomId];
+ const tiles = currentRoom.tileIds.map(tileId => state.objects.tile[tileId]);
+ const tile = findTileWithPosition(tiles, x, y);
+
+ return !(tile === null || tile.objectType);
+
+ },
+ };
+};
+
+const mapDispatchToProps = dispatch => {
+ return {
+ onClick: (x, y) => dispatch(addRackToTile(x, y)),
+ };
+};
+
+const ObjectHoverLayer = connect(
+ mapStateToProps,
+ mapDispatchToProps
+)(ObjectHoverLayerComponent);
+
+export default ObjectHoverLayer;
diff --git a/src/containers/map/layers/HoverTileLayer.js b/src/containers/map/layers/RoomHoverLayer.js
index d8a1d983..188ee51a 100644
--- a/src/containers/map/layers/HoverTileLayer.js
+++ b/src/containers/map/layers/RoomHoverLayer.js
@@ -1,6 +1,6 @@
import {connect} from "react-redux";
import {toggleTileAtLocation} from "../../../actions/topology";
-import HoverTileLayerComponent from "../../../components/map/layers/HoverTileLayerComponent";
+import RoomHoverLayerComponent from "../../../components/map/layers/RoomHoverLayerComponent";
import {
deriveValidNextTilePositions,
findPositionInPositions,
@@ -9,12 +9,17 @@ import {
const mapStateToProps = state => {
return {
- currentRoomInConstruction: state.currentRoomInConstruction,
+ isEnabled: () => state.construction.currentRoomInConstruction !== -1,
isValid: (x, y) => {
- const newRoom = Object.assign({}, state.objects.room[state.currentRoomInConstruction]);
+ if (state.interactionLevel.mode !== "BUILDING") {
+ return false;
+ }
+
+ const newRoom = Object.assign({}, state.objects.room[state.construction.currentRoomInConstruction]);
const oldRooms = Object.keys(state.objects.room)
.map(id => Object.assign({}, state.objects.room[id]))
- .filter(room => room.id !== state.currentRoomInConstruction);
+ .filter(room => room.datacenterId === state.currentDatacenterId
+ && room.id !== state.construction.currentRoomInConstruction);
[...oldRooms, newRoom].forEach(room => {
room.tiles = room.tileIds.map(tileId => state.objects.tile[tileId]);
@@ -35,9 +40,9 @@ const mapDispatchToProps = dispatch => {
};
};
-const HoverTileLayer = connect(
+const RoomHoverLayer = connect(
mapStateToProps,
mapDispatchToProps
-)(HoverTileLayerComponent);
+)(RoomHoverLayerComponent);
-export default HoverTileLayer;
+export default RoomHoverLayer;