diff --git a/smart-hut/src/components/AutomationModal.js b/smart-hut/src/components/AutomationModal.js
new file mode 100644
index 0000000..626a6c5
--- /dev/null
+++ b/smart-hut/src/components/AutomationModal.js
@@ -0,0 +1,190 @@
+import React, { Component } from "react";
+import { Button, Header, Modal, Icon, Responsive } from "semantic-ui-react";
+import { connect } from "react-redux";
+import { RemoteService } from "../remote";
+import { appActions } from "../storeActions";
+//import { update } from "immutability-helper";
+
+class AutomationModal extends Component {
+ constructor(props) {
+ super(props);
+ this.state = this.initialState;
+ this.setInitialState();
+
+ this.addAutomationModal = this.addAutomationModal.bind(this);
+ this.modifyAutomationModal = this.modifyAutomationModal.bind(this);
+ this.deleteAutomation = this.deleteAutomation.bind(this);
+ }
+
+ get initialState() {
+ return {
+ //INITIAL STATE HERE
+ };
+ }
+
+ setInitialState() {
+ this.setState(this.initialState);
+ }
+
+ get type() {
+ return !this.props.id ? "new" : "modify";
+ }
+
+ addAutomationModal = (e) => {
+ /*let data = {
+ // DATA HERE
+ };*/
+ // TODO CALL TO REMOTE SERVER TO ADD SCENE
+ /*this.props
+ .saveRoom(data, null)
+ .then(() => {
+ this.setInitialState();
+ this.closeModal();
+ })
+ .catch((err) => console.error("error in creating room", err));*/
+ };
+
+ modifyAutomationModal = (e) => {
+ /* let data = {
+ // DATA HERE
+ };*/
+ // TODO CALL TO REMOTE SERVER TO MODIFY SCENE
+ /*this.props
+ .saveRoom(data, this.props.id)
+ .then(() => {
+ this.setInitialState();
+ this.closeModal();
+ })
+ .catch((err) => console.error("error in updating room", err));*/
+ };
+
+ deleteAutomation = (e) => {
+ // TODO CALL TO REMOTE SERVER TO DELETE SCENE
+ /*
+ this.props
+ .deleteRoom(this.props.id)
+ .then(() => this.closeModal())
+ .catch((err) => console.error("error in deleting room", err));*/
+ };
+
+ changeSomething = (event) => {
+ let nam = event.target.name;
+ let val = event.target.value;
+ this.setState({ [nam]: val });
+ };
+
+ closeModal = (e) => {
+ this.setState({ openModal: false });
+ };
+
+ openModal = (e) => {
+ this.setState({ openModal: true });
+ };
+
+ render() {
+ return (
+
+ {!this.props.nicolaStop ? (
+
+
+ {this.type === "new" ? (
+
+ ) : (
+
+ )}
+
+
+ {this.type === "new" ? (
+
+ ) : (
+
+ )}
+
+
+ ) : null}
+
+
+
+ {this.type === "new" ? "Add new automation" : "Modify automation"}
+
+
+ {
+ //TODO FORM TO ADD OR MODIFY SCENE
+ }
+
+ {this.type === "modify" ? (
+
+ ) : null}
+
+
+
+
+
+
+
+
+ );
+ }
+}
+
+const setActiveAutomation = (activeAutomation) => {
+ return (dispatch) =>
+ dispatch(appActions.setActiveAutomation(activeAutomation));
+};
+
+const mapStateToProps = (state, ownProps) => ({
+ automations: ownProps.id ? state.automations[ownProps.id] : null,
+});
+const AutomationModalContainer = connect(
+ mapStateToProps,
+ { ...RemoteService, setActiveAutomation },
+ null,
+ { forwardRef: true }
+)(AutomationModal);
+export default AutomationModalContainer;
diff --git a/smart-hut/src/components/HeaderController.js b/smart-hut/src/components/HeaderController.js
index d6ef4c5..1d84c6b 100644
--- a/smart-hut/src/components/HeaderController.js
+++ b/smart-hut/src/components/HeaderController.js
@@ -57,7 +57,9 @@ export class MyHeader extends React.Component {
{this.props.username}
-
+
diff --git a/smart-hut/src/components/SceneModal.js b/smart-hut/src/components/SceneModal.js
new file mode 100644
index 0000000..9183a58
--- /dev/null
+++ b/smart-hut/src/components/SceneModal.js
@@ -0,0 +1,204 @@
+import React, { Component } from "react";
+import {
+ Button,
+ Header,
+ Modal,
+ Icon,
+ Responsive,
+ Form,
+ Input,
+} from "semantic-ui-react";
+import { connect } from "react-redux";
+import { RemoteService } from "../remote";
+import { appActions } from "../storeActions";
+//import { update } from "immutability-helper";
+
+class SceneModal extends Component {
+ constructor(props) {
+ super(props);
+ this.state = this.initialState;
+ this.setInitialState();
+
+ this.addSceneModal = this.addSceneModal.bind(this);
+ this.modifySceneModal = this.modifySceneModal.bind(this);
+ this.deleteScene = this.deleteScene.bind(this);
+ }
+
+ get initialState() {
+ return {
+ name: this.type === "new" ? "New Scene" : this.props.scene.name,
+ openModal: false,
+ };
+ }
+
+ setInitialState() {
+ this.setState(this.initialState);
+ }
+
+ get type() {
+ return !this.props.id ? "new" : "modify";
+ }
+
+ addSceneModal = (e) => {
+ let data = {
+ name: this.state.name,
+ };
+
+ this.props
+ .saveScene(data, null)
+ .then(() => {
+ this.setInitialState();
+ this.closeModal();
+ })
+ .catch((err) => console.error("error in creating room", err));
+ };
+
+ modifySceneModal = (e) => {
+ let data = {
+ name: this.state.name,
+ };
+
+ this.props
+ .saveScene(data, this.props.id)
+ .then(() => {
+ this.setInitialState();
+ this.closeModal();
+ })
+ .catch((err) => console.error("error in updating room", err));
+ };
+
+ deleteScene = (e) => {
+ this.props
+ .deleteScene(this.props.id)
+ .then(() => this.closeModal())
+ .catch((err) => console.error("error in deleting room", err));
+ };
+
+ changeSomething = (event) => {
+ let nam = event.target.name;
+ let val = event.target.value;
+ this.setState({ [nam]: val });
+ };
+
+ closeModal = (e) => {
+ this.setState({ openModal: false });
+ };
+
+ openModal = (e) => {
+ this.setState({ openModal: true });
+ };
+
+ render() {
+ return (
+
+ {!this.props.nicolaStop ? (
+
+
+ {this.type === "new" ? (
+
+ ) : (
+
+ )}
+
+
+ {this.type === "new" ? (
+
+ ) : (
+
+ )}
+
+
+ ) : null}
+
+
+
+ {this.type === "new" ? "Add new scene" : "Modify scene"}
+
+
+
+
+
+
+
+ {this.type === "modify" ? (
+
+ ) : null}
+
+
+
+
+
+
+
+
+ );
+ }
+}
+
+const setActiveScene = (activeScene) => {
+ return (dispatch) => dispatch(appActions.setActiveScene(activeScene));
+};
+
+const mapStateToProps = (state, ownProps) => ({
+ scene: ownProps.id ? state.scenes[ownProps.id] : null,
+});
+const SceneModalContainer = connect(
+ mapStateToProps,
+ { ...RemoteService, setActiveScene },
+ null,
+ { forwardRef: true }
+)(SceneModal);
+export default SceneModalContainer;
diff --git a/smart-hut/src/components/dashboard/AutomationsPanel.js b/smart-hut/src/components/dashboard/AutomationsPanel.js
new file mode 100644
index 0000000..4fbf809
--- /dev/null
+++ b/smart-hut/src/components/dashboard/AutomationsPanel.js
@@ -0,0 +1,23 @@
+import React, { Component } from "react";
+import { connect } from "react-redux";
+import { RemoteService } from "../../remote";
+
+class AutomationsPanel extends Component {
+ constructor(props) {
+ super(props);
+ }
+
+ render() {
+ return AUTOMATIONS
;
+ }
+}
+
+const mapStateToProps = (state, _) => ({
+ activeRoom: state.active.activeRoom,
+ activeTab: state.active.activeTab,
+});
+const AutomationsPanelContainer = connect(
+ mapStateToProps,
+ RemoteService
+)(AutomationsPanel);
+export default AutomationsPanelContainer;
diff --git a/smart-hut/src/components/dashboard/DevicePanel.js b/smart-hut/src/components/dashboard/DevicePanel.js
index 5e0fb17..449642e 100644
--- a/smart-hut/src/components/dashboard/DevicePanel.js
+++ b/smart-hut/src/components/dashboard/DevicePanel.js
@@ -2,7 +2,6 @@
import React, { Component } from "react";
import { Grid } from "semantic-ui-react";
-import { panelStyle } from "./devices/styleComponents";
import Device from "./devices/Device";
import NewDevice from "./devices/NewDevice";
import { connect } from "react-redux";
@@ -16,29 +15,29 @@ class DevicePanel extends Component {
}
getDevices() {
- this.props
- .fetchDevices()
- .catch((err) => console.error(`error fetching devices:`, err));
+ if (this.props.tab === "Devices") {
+ this.props
+ .fetchDevices()
+ .catch((err) => console.error(`error fetching devices:`, err));
+ }
}
render() {
return (
-
-
- {this.props.devices.map((e, i) => {
- return (
-
-
-
- );
- })}
- {!this.props.isActiveRoomHome ? (
-
-
+
+ {this.props.devices.map((e, i) => {
+ return (
+
+
- ) : null}
-
-
+ );
+ })}
+ {!this.props.isActiveRoomHome ? (
+
+
+
+ ) : null}
+
);
}
}
diff --git a/smart-hut/src/components/dashboard/NewSceneDevice.js b/smart-hut/src/components/dashboard/NewSceneDevice.js
new file mode 100644
index 0000000..7ea1664
--- /dev/null
+++ b/smart-hut/src/components/dashboard/NewSceneDevice.js
@@ -0,0 +1,142 @@
+import React, { Component } from "react";
+import { Button, Modal, Icon, Image, Form, Dropdown } from "semantic-ui-react";
+import { connect } from "react-redux";
+import { RemoteService } from "../../remote";
+import styled from "styled-components";
+//import { appActions } from "../../storeActions";
+
+const StyledDiv = styled.div`
+ background-color: #505bda;
+ padding: 3rem;
+ width: 10rem;
+ height: 10rem;
+ border-radius: 100%;
+ border: none;
+ position: relative;
+ box-shadow: 3px 2px 10px 5px #ccc;
+ transition: all 0.3s ease-out;
+ :hover {
+ background-color: #4345d9;
+ }
+ :active {
+ transform: translate(0.3px, 0.8px);
+ box-shadow: 0.5px 0.5px 7px 3.5px #ccc;
+ }
+`;
+
+class NewSceneDevice extends Component {
+ constructor(props) {
+ super(props);
+
+ this.state = {
+ openModal: false,
+ sceneDevices: this.props.scene ? this.props.scene.sceneStates : {},
+ deviceName: "",
+ };
+ this.getDevices();
+
+ this.setSceneState = this.setSceneState.bind(this);
+ this.createState = this.createState.bind(this);
+ }
+
+ getDevices() {
+ this.props
+ .fetchDevices()
+ .catch((err) => console.error(`error fetching devices:`, err));
+ }
+
+ handleOpen = () => {
+ this.setState({ openModal: true });
+ };
+ handleClose = () => {
+ this.setState({ openModal: false });
+ };
+
+ resetState = () => {
+ this.setState(this.baseState);
+ this.handleClose();
+ };
+
+ setSceneState(e, d) {
+ this.setState({ devicesAttached: d.value });
+ }
+
+ createState() {
+ const device = this.props.devices.filter(
+ (e) => this.state.devicesAttached[0] === e.id
+ );
+ let data = {
+ sceneId: this.props.activeScene,
+ id: device[0].id,
+ kind: device[0].kind,
+ };
+ this.props
+ .saveState(data)
+ .catch((err) => console.error("error in creating state", err));
+ this.resetState();
+ }
+
+ render() {
+ const availableDevices = [];
+ this.props.devices.forEach((e) => {
+ if (!Object.keys(this.state.sceneDevices).find((d) => e.id === d)) {
+ availableDevices.push({
+ key: e.id,
+ text: e.name,
+ value: e.id,
+ });
+ }
+ });
+ return (
+
+
+
+ }
+ centered={true}
+ >
+ Add a New Scene State
+
+
+
+
+
+
+
+
+
+
+
+ );
+ }
+}
+
+const mapStateToProps = (state, _) => ({
+ devices: Object.values(state.devices),
+ activeScene: state.active.activeScene,
+});
+const NewSceneDeviceContainer = connect(
+ mapStateToProps,
+ RemoteService
+)(NewSceneDevice);
+export default NewSceneDeviceContainer;
diff --git a/smart-hut/src/components/dashboard/ScenesPanel.js b/smart-hut/src/components/dashboard/ScenesPanel.js
new file mode 100644
index 0000000..2c5c726
--- /dev/null
+++ b/smart-hut/src/components/dashboard/ScenesPanel.js
@@ -0,0 +1,57 @@
+import React, { Component } from "react";
+import { connect } from "react-redux";
+import { RemoteService } from "../../remote";
+import Device from "./devices/Device";
+import NewSceneDevice from "./NewSceneDevice";
+import { Grid } from "semantic-ui-react";
+
+class ScenesPanel extends Component {
+ constructor(props) {
+ super(props);
+ }
+
+ render() {
+ return (
+
+ {!this.props.isActiveDefaultScene
+ ? this.props.sceneStates.map((e, i) => {
+ return (
+
+
+
+ );
+ })
+ : null}
+ {!this.props.isActiveDefaultScene ? (
+
+
+
+ ) : (
+ Welcome to the Scene View, you add a Scene
+ )}
+
+ );
+ }
+}
+
+const mapStateToProps = (state, _) => ({
+ get sceneStates() {
+ if (state.active.activeScene !== -1) {
+ const stateArray = [
+ ...state.scenes[state.active.activeScene].sceneStates,
+ ].sort();
+ return stateArray.map((id) => state.sceneStates[id]);
+ } else {
+ return [];
+ }
+ },
+ get isActiveDefaultScene() {
+ return state.active.activeScene === -1;
+ },
+ activeScene: state.active.activeScene,
+});
+const ScenesPanelContainer = connect(
+ mapStateToProps,
+ RemoteService
+)(ScenesPanel);
+export default ScenesPanelContainer;
diff --git a/smart-hut/src/components/dashboard/devices/Device.js b/smart-hut/src/components/dashboard/devices/Device.js
index 5ee6399..d71c79e 100644
--- a/smart-hut/src/components/dashboard/devices/Device.js
+++ b/smart-hut/src/components/dashboard/devices/Device.js
@@ -34,19 +34,19 @@ class Device extends React.Component {
console.log(this.props.device)
switch (this.props.device.kind) {
case "regularLight":
- return ;
+ return ;
case "sensor":
- return ;
+ return ;
case "motionSensor":
- return ;
+ return ;
case "buttonDimmer":
- return ;
+ return ;
case "knobDimmer":
- return ;
+ return ;
case "smartPlug":
- return ;
+ return ;
case "switch":
- return ;
+ return ;
case "dimmableLight":
return ;
case "securityCamera":
@@ -61,24 +61,36 @@ class Device extends React.Component {
{this.renderDeviceComponent()}
-
-
-
- {this.props.device.kind === "smartPlug" ? (
+ {this.props.tab === "Devices" ? (
+
+ {this.props.stateOrDevice.name}
- ) : null}
-
+ {this.props.stateOrDevice.kind === "smartPlug" ? (
+
+ ) : null}
+
+ ) : (
+
+ {this.props.stateOrDevice.name}
+
+ )}
+
@@ -87,7 +99,14 @@ class Device extends React.Component {
}
const mapStateToProps = (state, ownProps) => ({
- device: state.devices[ownProps.id],
+ get stateOrDevice() {
+ if (state.active.activeTab === "Devices") {
+ return state.devices[ownProps.id];
+ } else {
+ const sceneState = state.sceneStates[ownProps.id];
+ return state.devices[sceneState];
+ }
+ },
});
const DeviceContainer = connect(mapStateToProps, RemoteService)(Device);
export default DeviceContainer;
diff --git a/smart-hut/src/components/dashboard/devices/DeviceSettingsModal.js b/smart-hut/src/components/dashboard/devices/DeviceSettingsModal.js
index fcf29a0..ebb2d91 100644
--- a/smart-hut/src/components/dashboard/devices/DeviceSettingsModal.js
+++ b/smart-hut/src/components/dashboard/devices/DeviceSettingsModal.js
@@ -1,10 +1,18 @@
import React, { Component, useState } from "react";
-import { Button, Form, Icon, Header, Modal } from "semantic-ui-react";
+import { Button, Form, Icon, Header, Modal, Input } from "semantic-ui-react";
import { connect } from "react-redux";
import { RemoteService } from "../../../remote";
const DeleteModal = (props) => (
- Remove} closeIcon>
+
+
+ Delete device
+
+ }
+ closeIcon
+ >