From eb208a7e2fd020ab5d07d11cc6d52d1e3dcfcc7c Mon Sep 17 00:00:00 2001 From: Georgios Andreadis Date: Sun, 17 Sep 2017 17:55:04 +0200 Subject: Add simulation mode framework Includes object states in the store (by tick), charting, and progress bars. --- src/components/sidebars/Sidebar.js | 5 +- .../sidebars/elements/LoadBarComponent.js | 19 +++++ .../sidebars/elements/LoadChartComponent.js | 16 +++++ .../sidebars/topology/TopologySidebarComponent.js | 8 +-- .../topology/building/BuildingSidebarComponent.js | 15 ++-- .../building/CancelNewRoomConstructionComponent.js | 9 --- .../building/FinishNewRoomConstructionComponent.js | 9 --- .../building/NewRoomConstructionComponent.js | 24 +++++++ .../building/StartNewRoomConstructionComponent.js | 9 --- .../topology/machine/MachineSidebarComponent.js | 12 +++- .../sidebars/topology/rack/MachineComponent.js | 80 ++++++++++++---------- .../sidebars/topology/rack/RackSidebarComponent.js | 14 +++- .../sidebars/topology/room/RoomSidebarComponent.js | 18 +++-- 13 files changed, 153 insertions(+), 85 deletions(-) create mode 100644 src/components/sidebars/elements/LoadBarComponent.js create mode 100644 src/components/sidebars/elements/LoadChartComponent.js delete mode 100644 src/components/sidebars/topology/building/CancelNewRoomConstructionComponent.js delete mode 100644 src/components/sidebars/topology/building/FinishNewRoomConstructionComponent.js create mode 100644 src/components/sidebars/topology/building/NewRoomConstructionComponent.js delete mode 100644 src/components/sidebars/topology/building/StartNewRoomConstructionComponent.js (limited to 'src/components/sidebars') diff --git a/src/components/sidebars/Sidebar.js b/src/components/sidebars/Sidebar.js index 2f4d77a7..ce743b17 100644 --- a/src/components/sidebars/Sidebar.js +++ b/src/components/sidebars/Sidebar.js @@ -3,7 +3,10 @@ import React from "react"; import "./Sidebar.css"; const Sidebar = ({isRight, children}) => ( -
+
e.stopPropagation()} + > {children}
); diff --git a/src/components/sidebars/elements/LoadBarComponent.js b/src/components/sidebars/elements/LoadBarComponent.js new file mode 100644 index 00000000..5a39b188 --- /dev/null +++ b/src/components/sidebars/elements/LoadBarComponent.js @@ -0,0 +1,19 @@ +import classNames from "classnames"; +import React from "react"; + +const LoadBarComponent = ({percent, disabled}) => ( +
+
+ {percent}% +
+
+); + +export default LoadBarComponent; diff --git a/src/components/sidebars/elements/LoadChartComponent.js b/src/components/sidebars/elements/LoadChartComponent.js new file mode 100644 index 00000000..54a20116 --- /dev/null +++ b/src/components/sidebars/elements/LoadChartComponent.js @@ -0,0 +1,16 @@ +import React from "react"; +import {VictoryChart, VictoryLine, VictoryScatter} from "victory"; + +const LoadChartComponent = ({data, tick}) => ( + + + + +); + +export default LoadChartComponent; diff --git a/src/components/sidebars/topology/TopologySidebarComponent.js b/src/components/sidebars/topology/TopologySidebarComponent.js index 36f2ecc1..b61c7e3c 100644 --- a/src/components/sidebars/topology/TopologySidebarComponent.js +++ b/src/components/sidebars/topology/TopologySidebarComponent.js @@ -1,9 +1,9 @@ import React from "react"; import BuildingSidebarContainer from "../../../containers/sidebars/topology/building/BuildingSidebarContainer"; +import MachineSidebarContainer from "../../../containers/sidebars/topology/machine/MachineSidebarContainer"; +import RackSidebarContainer from "../../../containers/sidebars/topology/rack/RackSidebarContainer"; import RoomSidebarContainer from "../../../containers/sidebars/topology/room/RoomSidebarContainer"; import Sidebar from "../Sidebar"; -import MachineSidebarComponent from "./machine/MachineSidebarComponent"; -import RackSidebarComponent from "./rack/RackSidebarComponent"; const TopologySidebarComponent = ({interactionLevel}) => { let sidebarContent; @@ -16,10 +16,10 @@ const TopologySidebarComponent = ({interactionLevel}) => { sidebarContent = ; break; case "RACK": - sidebarContent = ; + sidebarContent = ; break; case "MACHINE": - sidebarContent = ; + sidebarContent = ; break; default: sidebarContent = "Missing Content"; diff --git a/src/components/sidebars/topology/building/BuildingSidebarComponent.js b/src/components/sidebars/topology/building/BuildingSidebarComponent.js index 002184ae..835943f2 100644 --- a/src/components/sidebars/topology/building/BuildingSidebarComponent.js +++ b/src/components/sidebars/topology/building/BuildingSidebarComponent.js @@ -1,18 +1,13 @@ import React from "react"; -import CancelNewRoomConstructionButton from "../../../../containers/sidebars/topology/building/CancelNewRoomConstructionButton"; -import FinishNewRoomConstructionButton from "../../../../containers/sidebars/topology/building/FinishNewRoomConstructionButton"; -import StartNewRoomConstructionButton from "../../../../containers/sidebars/topology/building/StartNewRoomConstructionButton"; +import NewRoomConstructionContainer from "../../../../containers/sidebars/topology/building/NewRoomConstructionContainer"; -const BuildingSidebarComponent = ({currentRoomInConstruction}) => { +const BuildingSidebarComponent = ({inSimulation}) => { return (

Building

- {currentRoomInConstruction === -1 ? - : -
- - -
+ {inSimulation ? + undefined : + }
); diff --git a/src/components/sidebars/topology/building/CancelNewRoomConstructionComponent.js b/src/components/sidebars/topology/building/CancelNewRoomConstructionComponent.js deleted file mode 100644 index 15f199a6..00000000 --- a/src/components/sidebars/topology/building/CancelNewRoomConstructionComponent.js +++ /dev/null @@ -1,9 +0,0 @@ -import React from "react"; - -const CancelNewRoomConstructionComponent = ({onClick}) => ( -
- Cancel construction -
-); - -export default CancelNewRoomConstructionComponent; diff --git a/src/components/sidebars/topology/building/FinishNewRoomConstructionComponent.js b/src/components/sidebars/topology/building/FinishNewRoomConstructionComponent.js deleted file mode 100644 index d9edbb61..00000000 --- a/src/components/sidebars/topology/building/FinishNewRoomConstructionComponent.js +++ /dev/null @@ -1,9 +0,0 @@ -import React from "react"; - -const FinishNewRoomConstructionComponent = ({onClick}) => ( -
- Finalize new room -
-); - -export default FinishNewRoomConstructionComponent; diff --git a/src/components/sidebars/topology/building/NewRoomConstructionComponent.js b/src/components/sidebars/topology/building/NewRoomConstructionComponent.js new file mode 100644 index 00000000..581330ab --- /dev/null +++ b/src/components/sidebars/topology/building/NewRoomConstructionComponent.js @@ -0,0 +1,24 @@ +import React from "react"; + +const NewRoomConstructionComponent = ({onStart, onFinish, onCancel, currentRoomInConstruction}) => { + if (currentRoomInConstruction === -1) { + return ( +
+ Construct a new room +
+ ); + } + return ( +
+
+ Finalize new room +
+
+ Cancel construction +
+
+ ); + +}; + +export default NewRoomConstructionComponent; diff --git a/src/components/sidebars/topology/building/StartNewRoomConstructionComponent.js b/src/components/sidebars/topology/building/StartNewRoomConstructionComponent.js deleted file mode 100644 index 60573532..00000000 --- a/src/components/sidebars/topology/building/StartNewRoomConstructionComponent.js +++ /dev/null @@ -1,9 +0,0 @@ -import React from "react"; - -const StartNewRoomConstructionComponent = ({onClick}) => ( -
- Construct a new room -
-); - -export default StartNewRoomConstructionComponent; diff --git a/src/components/sidebars/topology/machine/MachineSidebarComponent.js b/src/components/sidebars/topology/machine/MachineSidebarComponent.js index 218e4f41..0f85f0f9 100644 --- a/src/components/sidebars/topology/machine/MachineSidebarComponent.js +++ b/src/components/sidebars/topology/machine/MachineSidebarComponent.js @@ -1,15 +1,23 @@ import React from "react"; +import LoadBarContainer from "../../../../containers/sidebars/elements/LoadBarContainer"; +import LoadChartContainer from "../../../../containers/sidebars/elements/LoadChartContainer"; import BackToRackContainer from "../../../../containers/sidebars/topology/machine/BackToRackContainer"; import DeleteMachineContainer from "../../../../containers/sidebars/topology/machine/DeleteMachineContainer"; import MachineNameContainer from "../../../../containers/sidebars/topology/machine/MachineNameContainer"; import UnitTabsComponent from "./UnitTabsComponent"; -const MachineSidebarComponent = () => { +const MachineSidebarComponent = ({inSimulation, machineId}) => { return (
- + {inSimulation ? +
+ + +
: + + }
); diff --git a/src/components/sidebars/topology/rack/MachineComponent.js b/src/components/sidebars/topology/rack/MachineComponent.js index 4854456c..b6e9791d 100644 --- a/src/components/sidebars/topology/rack/MachineComponent.js +++ b/src/components/sidebars/topology/rack/MachineComponent.js @@ -1,5 +1,6 @@ import React from "react"; import Shapes from "../../../../shapes"; +import {convertLoadToSimulationColor} from "../../../../util/simulation-load"; const UnitIcon = ({id, type}) => (
@@ -12,41 +13,50 @@ const UnitIcon = ({id, type}) => (
); -const MachineComponent = ({position, machine, onClick}) => ( -
  • - - {position} - -
    - {machine.cpuIds.length > 0 ? - : - undefined - } - {machine.gpuIds.length > 0 ? - : - undefined - } - {machine.memoryIds.length > 0 ? - : - undefined - } - {machine.storageIds.length > 0 ? - : - undefined - } - {machine.cpuIds.length + machine.gpuIds.length + machine.memoryIds.length - + machine.storageIds.length === 0 ? - - Machine with no units - : - undefined - } -
    -
  • -); +const MachineComponent = ({position, machine, inSimulation, machineLoad, onClick}) => { + let color = "white"; + if (inSimulation) { + color = convertLoadToSimulationColor(machineLoad); + } + const hasNoUnits = machine.cpuIds.length + machine.gpuIds.length + machine.memoryIds.length + + machine.storageIds.length === 0; + + return ( +
  • + + {position} + +
    + {machine.cpuIds.length > 0 ? + : + undefined + } + {machine.gpuIds.length > 0 ? + : + undefined + } + {machine.memoryIds.length > 0 ? + : + undefined + } + {machine.storageIds.length > 0 ? + : + undefined + } + {hasNoUnits ? + + Machine with no units + : + undefined + } +
    +
  • + ); +}; MachineComponent.propTypes = { machine: Shapes.Machine diff --git a/src/components/sidebars/topology/rack/RackSidebarComponent.js b/src/components/sidebars/topology/rack/RackSidebarComponent.js index 007add6e..bfcc7e32 100644 --- a/src/components/sidebars/topology/rack/RackSidebarComponent.js +++ b/src/components/sidebars/topology/rack/RackSidebarComponent.js @@ -1,14 +1,24 @@ import React from "react"; +import LoadBarContainer from "../../../../containers/sidebars/elements/LoadBarContainer"; +import LoadChartContainer from "../../../../containers/sidebars/elements/LoadChartContainer"; import DeleteRackContainer from "../../../../containers/sidebars/topology/rack/DeleteRackContainer"; import MachineListContainer from "../../../../containers/sidebars/topology/rack/MachineListContainer"; import RackNameContainer from "../../../../containers/sidebars/topology/rack/RackNameContainer"; import "./RackSidebarComponent.css"; -const RackSidebarComponent = () => { +const RackSidebarComponent = ({inSimulation, rackId}) => { return (
    - + {inSimulation ? +
    + + +
    : +
    + +
    + }
    diff --git a/src/components/sidebars/topology/room/RoomSidebarComponent.js b/src/components/sidebars/topology/room/RoomSidebarComponent.js index a15351f9..59c5fc8f 100644 --- a/src/components/sidebars/topology/room/RoomSidebarComponent.js +++ b/src/components/sidebars/topology/room/RoomSidebarComponent.js @@ -1,12 +1,14 @@ import React from "react"; +import LoadBarContainer from "../../../../containers/sidebars/elements/LoadBarContainer"; +import LoadChartContainer from "../../../../containers/sidebars/elements/LoadChartContainer"; import DeleteRoomContainer from "../../../../containers/sidebars/topology/room/DeleteRoomContainer"; import RackConstructionContainer from "../../../../containers/sidebars/topology/room/RackConstructionContainer"; import RoomNameContainer from "../../../../containers/sidebars/topology/room/RoomNameContainer"; import RoomTypeContainer from "../../../../containers/sidebars/topology/room/RoomTypeContainer"; -const RoomSidebarComponent = ({roomType}) => { +const RoomSidebarComponent = ({roomId, roomType, inSimulation}) => { let allowedObjects; - if (roomType === "SERVER") { + if (!inSimulation && roomType === "SERVER") { allowedObjects = ; } @@ -14,8 +16,16 @@ const RoomSidebarComponent = ({roomType}) => {
    - {allowedObjects} - + {inSimulation ? +
    + + +
    : +
    + {allowedObjects} + +
    + }
    ); }; -- cgit v1.2.3