Merge branch '77-fixe-major-bug' into 'dev'

Resolve "fixe-major-bug"

Closes #77

See merge request sa4-2020/the-sanmarinoes/frontend!85
This commit is contained in:
Matteo Omenetti 2020-04-18 16:29:37 +02:00
commit e9745bb5f0
20 changed files with 502 additions and 359 deletions

View file

@ -57,7 +57,9 @@ export class MyHeader extends React.Component {
{this.props.username} {this.props.username}
</Label> </Label>
<Divider /> <Divider />
<Button onClick={this.logout}>Logout</Button> <Button basic inverted onClick={this.logout}>
Logout
</Button>
</Grid.Column> </Grid.Column>
</Grid.Row> </Grid.Row>
</Grid> </Grid>

View file

@ -49,16 +49,7 @@ class RoomModal extends Component {
} }
setInitialState() { setInitialState() {
for (let key in this.initialState) { this.setState(this.initialState);
if (this.initialState.hasOwnProperty(key)) {
//console.log(key + " -> " + this.initialState[key]);
this.setState({
key: this.initialState[key],
});
}
}
console.log(this.initialState);
//this.setState(state);
} }
get type() { get type() {

View file

@ -7,7 +7,6 @@ import {
Responsive, Responsive,
Form, Form,
Input, Input,
Dropdown,
} from "semantic-ui-react"; } from "semantic-ui-react";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { RemoteService } from "../remote"; import { RemoteService } from "../remote";
@ -19,7 +18,6 @@ class SceneModal extends Component {
super(props); super(props);
this.state = this.initialState; this.state = this.initialState;
this.setInitialState(); this.setInitialState();
this.getDevices();
this.addSceneModal = this.addSceneModal.bind(this); this.addSceneModal = this.addSceneModal.bind(this);
this.modifySceneModal = this.modifySceneModal.bind(this); this.modifySceneModal = this.modifySceneModal.bind(this);
@ -28,8 +26,7 @@ class SceneModal extends Component {
get initialState() { get initialState() {
return { return {
name: this.type === "new" ? "New Scene" : this.props.room.name, name: this.type === "new" ? "New Scene" : this.props.scene.name,
sceneDevices: this.type === "new" ? [{}] : [this.props.scene.devices],
openModal: false, openModal: false,
}; };
} }
@ -42,47 +39,39 @@ class SceneModal extends Component {
return !this.props.id ? "new" : "modify"; return !this.props.id ? "new" : "modify";
} }
getDevices() {
this.props
.fetchDevices()
.catch((err) => console.error(`error fetching devices:`, err));
}
addSceneModal = (e) => { addSceneModal = (e) => {
/*let data = { let data = {
// DATA HERE name: this.state.name,
};*/ };
// TODO CALL TO REMOTE SERVER TO ADD SCENE
/*this.props this.props
.saveRoom(data, null) .saveScene(data, null)
.then(() => { .then(() => {
this.setInitialState(); this.setInitialState();
this.closeModal(); this.closeModal();
}) })
.catch((err) => console.error("error in creating room", err));*/ .catch((err) => console.error("error in creating room", err));
}; };
modifySceneModal = (e) => { modifySceneModal = (e) => {
/*let data = { let data = {
// DATA HERE name: this.state.name,
};*/ };
// TODO CALL TO REMOTE SERVER TO MODIFY SCENE
/*this.props this.props
.saveRoom(data, this.props.id) .saveScene(data, this.props.id)
.then(() => { .then(() => {
this.setInitialState(); this.setInitialState();
this.closeModal(); this.closeModal();
}) })
.catch((err) => console.error("error in updating room", err));*/ .catch((err) => console.error("error in updating room", err));
}; };
deleteScene = (e) => { deleteScene = (e) => {
// TODO CALL TO REMOTE SERVER TO DELETE SCENE
/*
this.props this.props
.deleteRoom(this.props.id) .deleteScene(this.props.id)
.then(() => this.closeModal()) .then(() => this.closeModal())
.catch((err) => console.error("error in deleting room", err));*/ .catch((err) => console.error("error in deleting room", err));
}; };
changeSomething = (event) => { changeSomething = (event) => {
@ -99,21 +88,7 @@ class SceneModal extends Component {
this.setState({ openModal: true }); this.setState({ openModal: true });
}; };
setSceneDevice(e, d) {
this.setState({ sceneDevices: d.value });
}
render() { render() {
const availableDevices = [];
this.props.devices.forEach((e) => {
if (!this.state.sceneDevices.includes(e)) {
availableDevices.push({
key: e.id,
text: e.name,
id: e.id,
});
}
});
return ( return (
<div> <div>
{!this.props.nicolaStop ? ( {!this.props.nicolaStop ? (
@ -176,17 +151,6 @@ class SceneModal extends Component {
value={this.state.name} value={this.state.name}
/> />
</Form.Field> </Form.Field>
<Form.Field>
<label>Select devices you want to attach: </label>
<Dropdown
name="scene devices"
placeholder="Select Devices"
fluid
multiple
onChange={this.setSceneDevice}
options={availableDevices}
/>
</Form.Field>
</Form> </Form>
{this.type === "modify" ? ( {this.type === "modify" ? (
@ -229,16 +193,6 @@ const setActiveScene = (activeScene) => {
}; };
const mapStateToProps = (state, ownProps) => ({ const mapStateToProps = (state, ownProps) => ({
get devices() {
if (state.active.activeRoom === -1) {
return Object.values(state.devices);
} else {
const deviceArray = [
...state.rooms[state.active.activeRoom].devices,
].sort();
return deviceArray.map((id) => state.devices[id]);
}
},
scene: ownProps.id ? state.scenes[ownProps.id] : null, scene: ownProps.id ? state.scenes[ownProps.id] : null,
}); });
const SceneModalContainer = connect( const SceneModalContainer = connect(

View file

@ -26,7 +26,7 @@ class DevicePanel extends Component {
{this.props.devices.map((e, i) => { {this.props.devices.map((e, i) => {
return ( return (
<Grid.Column key={i}> <Grid.Column key={i}>
<Device id={e.id} /> <Device tab={this.props.tab} id={e.id} />
</Grid.Column> </Grid.Column>
); );
})} })}

View file

@ -1,5 +1,5 @@
import React, { Component } from "react"; import React, { Component } from "react";
import { Button, Modal, Icon, Image } from "semantic-ui-react"; import { Button, Modal, Icon, Image, Form, Dropdown } from "semantic-ui-react";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { RemoteService } from "../../remote"; import { RemoteService } from "../../remote";
import styled from "styled-components"; import styled from "styled-components";
@ -30,7 +30,18 @@ class NewSceneDevice extends Component {
this.state = { this.state = {
openModal: false, openModal: false,
sceneDevices: this.props.scene ? this.props.scene.devices : {},
deviceName: "",
}; };
this.getDevices();
this.setSceneDevice = this.setSceneDevice.bind(this);
}
getDevices() {
this.props
.fetchDevices()
.catch((err) => console.error(`error fetching devices:`, err));
} }
handleOpen = () => { handleOpen = () => {
@ -45,7 +56,21 @@ class NewSceneDevice extends Component {
this.handleClose(); this.handleClose();
}; };
setSceneDevice(e, d) {
this.setState({ devicesAttached: d.value });
}
render() { 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 ( return (
<Modal <Modal
closeIcon closeIcon
@ -59,7 +84,21 @@ class NewSceneDevice extends Component {
centered={true} centered={true}
> >
<Modal.Header>Add a New Scene Device</Modal.Header> <Modal.Header>Add a New Scene Device</Modal.Header>
<Modal.Content></Modal.Content> <Modal.Content>
<Form>
<Form.Field style={{ marginTop: "1rem" }}>
<label>Select devices you want to attach: </label>
<Dropdown
name="scene devices"
placeholder="Select Devices"
fluid
multiple
onChange={this.setSceneDevice}
options={availableDevices}
/>
</Form.Field>
</Form>
</Modal.Content>
<Modal.Actions> <Modal.Actions>
<Button <Button
onClick={this.createDevice} onClick={this.createDevice}
@ -78,7 +117,7 @@ class NewSceneDevice extends Component {
const mapStateToProps = (state, _) => ({ const mapStateToProps = (state, _) => ({
devices: Object.values(state.devices), devices: Object.values(state.devices),
activeRoom: state.active.activeRoom, activeScene: state.active.activeScene,
}); });
const NewSceneDeviceContainer = connect( const NewSceneDeviceContainer = connect(
mapStateToProps, mapStateToProps,

View file

@ -7,7 +7,6 @@ import { Grid } from "semantic-ui-react";
class ScenesPanel extends Component { class ScenesPanel extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
console.log(this.props.activeScene);
} }
render() { render() {

View file

@ -32,21 +32,21 @@ class Device extends React.Component {
renderDeviceComponent() { renderDeviceComponent() {
switch (this.props.device.kind) { switch (this.props.device.kind) {
case "regularLight": case "regularLight":
return <Light id={this.props.id} />; return <Light tab={this.props.tab} id={this.props.id} />;
case "sensor": case "sensor":
return <Sensor id={this.props.id} />; return <Sensor tab={this.props.tab} id={this.props.id} />;
case "motionSensor": case "motionSensor":
return <Sensor id={this.props.id} />; return <Sensor tab={this.props.tab} id={this.props.id} />;
case "buttonDimmer": case "buttonDimmer":
return <ButtonDimmer id={this.props.id} />; return <ButtonDimmer tab={this.props.tab} id={this.props.id} />;
case "knobDimmer": case "knobDimmer":
return <KnobDimmer id={this.props.id} />; return <KnobDimmer tab={this.props.tab} id={this.props.id} />;
case "smartPlug": case "smartPlug":
return <SmartPlug id={this.props.id} />; return <SmartPlug tab={this.props.tab} id={this.props.id} />;
case "switch": case "switch":
return <Switcher id={this.props.id} />; return <Switcher tab={this.props.tab} id={this.props.id} />;
case "dimmableLight": case "dimmableLight":
return <Light id={this.props.id} />; return <Light tab={this.props.tab} id={this.props.id} />;
default: default:
throw new Error("Device type unknown"); throw new Error("Device type unknown");
} }

View file

@ -4,7 +4,15 @@ import { connect } from "react-redux";
import { RemoteService } from "../../../remote"; import { RemoteService } from "../../../remote";
const DeleteModal = (props) => ( const DeleteModal = (props) => (
<Modal trigger={<Button color="red">Remove</Button>} closeIcon> <Modal
trigger={
<Button icon labelPosition="left" inverted color="red">
<Icon name="trash alternate" />
Delete device
</Button>
}
closeIcon
>
<Header icon="archive" content="Are you sure ?" /> <Header icon="archive" content="Are you sure ?" />
<Modal.Actions> <Modal.Actions>
<Button color="red"> <Button color="red">
@ -28,13 +36,14 @@ const SettingsForm = (props) => {
return ( return (
<Form> <Form>
<Form.Field> <Form.Field>
<label>New Name: </label> <label>Edit Name: </label>
<input <input
autoComplete="off" autoComplete="off"
name="name" name="name"
onChange={handleInputChange} onChange={handleInputChange}
value={values.name} value={props.name}
placeholder="Device name" placeholder="Device name"
// {this.props.device.name}
/> />
</Form.Field> </Form.Field>
@ -43,10 +52,11 @@ const SettingsForm = (props) => {
</Form.Field> </Form.Field>
<Button <Button
onClick={() => props.saveFunction(values)} onClick={() => props.saveFunction(values)}
color="blue" color="green"
type="submit" type="submit"
> >
Save <Icon name="checkmark" />
Save changes
</Button> </Button>
</Form> </Form>
); );
@ -63,9 +73,13 @@ class DeviceSettingsModal extends Component {
this.deleteDevice = this.deleteDevice.bind(this); this.deleteDevice = this.deleteDevice.bind(this);
} }
openModal() { closeModal = (e) => {
this.setState({ open: true }); this.setState({ openModal: false });
} };
openModal = (e) => {
this.setState({ openModal: true });
};
updateDevice(values) { updateDevice(values) {
if (values.name.length === 0) return; if (values.name.length === 0) return;
@ -94,10 +108,11 @@ class DeviceSettingsModal extends Component {
render() { render() {
const SettingsModal = () => ( const SettingsModal = () => (
<Modal open={this.state.open}> <Modal closeIcon onClose={this.closeModal} open={this.state.openModal}>
<Modal.Header>Settings of {this.props.device.name}</Modal.Header> <Modal.Header>Settings of {this.props.device.name}</Modal.Header>
<Modal.Content> <Modal.Content>
<SettingsForm <SettingsForm
name={this.props.device.name}
type={this.props.device.type} type={this.props.device.type}
removeDevice={this.deleteDevice} removeDevice={this.deleteDevice}
saveFunction={this.updateDevice} saveFunction={this.updateDevice}

View file

@ -37,6 +37,7 @@ class Light extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { intensity: this.props.device.intensity, timeout: null }; this.state = { intensity: this.props.device.intensity, timeout: null };
console.log(this.props);
this.iconOn = "/img/lightOn.svg"; this.iconOn = "/img/lightOn.svg";
this.iconOff = "/img/lightOff.svg"; this.iconOff = "/img/lightOff.svg";

View file

@ -53,14 +53,15 @@ class Sensor extends Component {
this.colors = temperatureSensorColors; this.colors = temperatureSensorColors;
this.icon = "temperatureIcon.svg"; this.icon = "temperatureIcon.svg";
this.name = "Sensor";
} }
setName = () => { // setName = () => {
if (this.props.device.name.length > 15) { // if (this.props.device.name.length > 15) {
return this.props.device.name.slice(0, 12) + "..."; // return this.props.device.name.slice(0, 12) + "...";
} // }
return this.props.device.name; // return this.props.device.name;
}; // };
componentDidUpdate(prevProps) { componentDidUpdate(prevProps) {
if ( if (
@ -83,16 +84,19 @@ class Sensor extends Component {
this.units = "ºC"; this.units = "ºC";
this.colors = temperatureSensorColors; this.colors = temperatureSensorColors;
this.icon = "temperatureIcon.svg"; this.icon = "temperatureIcon.svg";
this.name = "Temperature Sensor";
break; break;
case "HUMIDITY": case "HUMIDITY":
this.units = "%"; this.units = "%";
this.colors = humiditySensorColors; this.colors = humiditySensorColors;
this.icon = "humidityIcon.svg"; this.icon = "humidityIcon.svg";
this.name = "Humidity Sensor";
break; break;
case "LIGHT": case "LIGHT":
this.units = "lm"; this.units = "lm";
this.colors = lightSensorColors; this.colors = lightSensorColors;
this.icon = "lightSensorIcon.svg"; this.icon = "lightSensorIcon.svg";
this.name = "Light Sensor";
break; break;
default: default:
this.units = ""; this.units = "";
@ -131,7 +135,7 @@ class Sensor extends Component {
}} }}
> >
<Image style={motionSensorIcon} src="/img/motionSensorIcon.svg" /> <Image style={motionSensorIcon} src="/img/motionSensorIcon.svg" />
<span style={nameMotionStyle}>{this.props.device.name}</span> <span style={nameMotionStyle}>Motion Sensor</span>
</div> </div>
</div> </div>
); );
@ -176,7 +180,7 @@ class Sensor extends Component {
dy="0.4em" dy="0.4em"
fontWeight="bold" fontWeight="bold"
> >
{this.setName()} ({this.props.device.id}) {this.name}
</text> </text>
</CircularInput> </CircularInput>
<Image style={iconSensorStyle} src={`/img/${this.icon}`} /> <Image style={iconSensorStyle} src={`/img/${this.icon}`} />

View file

@ -39,8 +39,8 @@ const Endpoint = {
* @param {[String]String} query query ('?') parameters (no params by default) * @param {[String]String} query query ('?') parameters (no params by default)
* @param {any} body the JSON request body * @param {any} body the JSON request body
*/ */
send: (method, route, query = {}, body = null, registration) => { send: (method, route, query = {}, body = null) => {
if (!registration && !Endpoint.token) { if (!Endpoint.token) {
throw new Error("No token while performing authenticated request"); throw new Error("No token while performing authenticated request");
} }
@ -48,11 +48,9 @@ const Endpoint = {
method: method, method: method,
params: query, params: query,
data: ["put", "post"].indexOf(method) !== -1 ? body : null, data: ["put", "post"].indexOf(method) !== -1 ? body : null,
headers: !registration headers: {
? { Authorization: `Bearer ${Endpoint.token}`,
Authorization: `Bearer ${Endpoint.token}`, },
}
: {},
}).then((res) => { }).then((res) => {
if (!res.data && method !== "delete") { if (!res.data && method !== "delete") {
console.error("Response body is empty"); console.error("Response body is empty");
@ -63,6 +61,28 @@ const Endpoint = {
}); });
}, },
/**
* Performs a non-authenticated post and put request for registration, reset-password
* @param {post} the desired method
* @param {String} route the desired route (e.g. "/rooms/1/devices")
* @param {[String]String} query query ('?') parameters (no params by default)
* @param {any} body the JSON request body
*/
sendNA: (method, route, query = {}, body = null) => {
return Endpoint.axiosInstance(route, {
method: method,
params: query,
data: ["put", "post"].indexOf(method) !== -1 ? body : null,
}).then((res) => {
if (!res.data) {
console.error("Response body is empty");
return null;
} else {
return res;
}
});
},
/** /**
* Performs login * Performs login
* @param {String} usernameOrEmail * @param {String} usernameOrEmail
@ -111,7 +131,18 @@ const Endpoint = {
* @returns {Promise<*, *>} The Axios-generated promise * @returns {Promise<*, *>} The Axios-generated promise
*/ */
post(route, query, body) { post(route, query, body) {
return this.send("post", route, query, body, true); return this.send("post", route, query, body);
},
/**
* Performs a non-authenticated POST request
* @param {String} route the desired route (e.g. "/rooms/1/devices")
* @param {[String]String} query query ('?') parameters (no params by default)
* @param {any} body the JSON request body
* @returns {Promise<*, *>} The Axios-generated promise
*/
postNA(route, query, body) {
return this.sendNA("post", route, query, body);
}, },
/** /**
@ -125,6 +156,17 @@ const Endpoint = {
return this.send("put", route, query, body); return this.send("put", route, query, body);
}, },
/**
* Performs a non-authenticated PUT request
* @param {String} route the desired route (e.g. "/rooms/1/devices")
* @param {[String]String} query query ('?') parameters (no params by default)
* @param {any} body the JSON request body
* @returns {Promise<*, *>} The Axios-generated promise
*/
putNA(route, query = {}, body = {}) {
return this.sendNA("put", route, query, body);
},
/** /**
* Performs an authenticated DELETE request * Performs an authenticated DELETE request
* @param {get|post|put|delete} the desired method * @param {get|post|put|delete} the desired method
@ -229,6 +271,23 @@ export const RemoteService = {
}; };
}, },
/**
* Fetches all scenes that belong to this user. This call does not
* populate the devices attribute in scenes.
* @returns {Promise<Undefined, RemoteError>} promise that resolves to void and rejects
* with user-fiendly errors as a RemoteError
*/
fetchAllScenes: () => {
return (dispatch) => {
return Endpoint.get("/scene")
.then((res) => void dispatch(actions.scenesUpdate(res.data)))
.catch((err) => {
console.error("Fetch all scenes error", err);
throw new RemoteError(["Network error"]);
});
};
},
/** /**
* Fetches all devices in a particular room, or fetches all devices. * Fetches all devices in a particular room, or fetches all devices.
* This also updates the devices attribute on values in the map rooms. * This also updates the devices attribute on values in the map rooms.
@ -248,6 +307,25 @@ export const RemoteService = {
}; };
}, },
/**
* Fetches all devices in a particular scene, or fetches all devices.
* This also updates the devices attribute on values in the map scenes.
* @param {Number} sceneId the scene to which fetch devices
* from, null to fetch from all scenes
* @returns {Promise<Undefined, RemoteError>} promise that resolves to void and rejects
* with user-fiendly errors as a RemoteError
*/
fetchStates: (sceneId) => {
return (dispatch) => {
return Endpoint.get(`/scene/${sceneId}/states`)
.then((res) => void dispatch(actions.statesUpdate(sceneId, res.data)))
.catch((err) => {
console.error(`Fetch devices sceneId=${sceneId} error`, err);
throw new RemoteError(["Network error"]);
});
};
},
/** /**
* Creates/Updates a room with the given data * Creates/Updates a room with the given data
* @param {String} data.name the room's name, * @param {String} data.name the room's name,
@ -274,6 +352,28 @@ export const RemoteService = {
}; };
}, },
/**
* Creates/Updates a scene with the given data
* @param {String} data.name the scene's name,
* @param {Number|null} sceneId the scene's id if update, null for creation
* @returns {Promise<Undefined, RemoteError>} promise that resolves to void and rejects
* with user-fiendly errors as a RemoteError
*/
saveScene: (data, sceneId = null) => {
return (dispatch) => {
data = {
name: data.name,
};
return (sceneId
? Endpoint.put(`/scene/${sceneId}`, {}, data)
: Endpoint.post(`/scene`, {}, data)
)
.then((res) => void dispatch(actions.sceneSave(res.data)))
.catch(parseValidationErrors);
};
},
/** /**
* Creates/Updates a device with the given data. If * Creates/Updates a device with the given data. If
* data.id is truthy, then a update call is performed, * data.id is truthy, then a update call is performed,
@ -454,6 +554,23 @@ export const RemoteService = {
}; };
}, },
/**
* Deletes a scene
* @param {Number} sceneId the id of the scene to delete
* @returns {Promise<Undefined, RemoteError>} promise that resolves to void and rejects
* with user-fiendly errors as a RemoteError
*/
deleteScene: (sceneId) => {
return (dispatch) => {
return Endpoint.delete(`/scene/${sceneId}`)
.then((_) => dispatch(actions.sceneDelete(sceneId)))
.catch((err) => {
console.warn("Scene deletion error", err);
throw new RemoteError(["Network error"]);
});
};
},
/** /**
* Deletes a device * Deletes a device
* @param {Device} device the device to delete * @param {Device} device the device to delete
@ -489,7 +606,7 @@ export class Forms {
* with validation errors as a String array * with validation errors as a String array
*/ */
static submitRegistration(data) { static submitRegistration(data) {
return Endpoint.post( return Endpoint.postNA(
"/register", "/register",
{}, {},
{ {
@ -512,7 +629,7 @@ export class Forms {
* with validation errors as a String array * with validation errors as a String array
*/ */
static submitInitResetPassword(email) { static submitInitResetPassword(email) {
return Endpoint.post( return Endpoint.postNA(
"/register/init-reset-password", "/register/init-reset-password",
{}, {},
{ {
@ -537,7 +654,7 @@ export class Forms {
* with validation errors as a String array * with validation errors as a String array
*/ */
static submitResetPassword(confirmationToken, password) { static submitResetPassword(confirmationToken, password) {
return Endpoint.post( return Endpoint.putNA(
"/register/reset-password", "/register/reset-password",
{}, {},
{ {

View file

@ -38,6 +38,35 @@ function reducer(previousState, action) {
} }
}; };
const createOrUpdateScene = (scene) => {
if (!newState.scenes[scene.id]) {
newState = update(newState, {
scenes: { [scene.id]: { $set: { ...scene, states: new Set() } } },
});
} else {
newState = update(newState, {
scenes: {
[scene.id]: {
name: { $set: scene.name },
},
},
});
}
if (newState.pendingJoins.scenes[scene.id]) {
newState = update(newState, {
pendingJoins: { scenes: { $unset: [scene.id] } },
scenes: {
[scene.id]: {
states: {
$add: [...newState.pendingJoins.scenes[scene.id]],
},
},
},
});
}
};
const updateDeviceProps = (device) => { const updateDeviceProps = (device) => {
// In some updates the information regarding a device is incomplete // In some updates the information regarding a device is incomplete
// due to a fault in the type system and JPA repository management // due to a fault in the type system and JPA repository management
@ -63,6 +92,13 @@ function reducer(previousState, action) {
createOrUpdateRoom(room); createOrUpdateRoom(room);
} }
break; break;
case "SCENES_UPDATE":
newState = previousState;
console.log(action.scenes);
for (const scene of action.scenes) {
createOrUpdateScene(scene);
}
break;
case "DEVICES_UPDATE": case "DEVICES_UPDATE":
change = null; change = null;
@ -156,6 +192,10 @@ function reducer(previousState, action) {
newState = previousState; newState = previousState;
createOrUpdateRoom(action.room); createOrUpdateRoom(action.room);
break; break;
case "SCENE_SAVE":
newState = previousState;
createOrUpdateScene(action.scene);
break;
case "DEVICE_SAVE": case "DEVICE_SAVE":
change = { change = {
devices: { [action.device.id]: { $set: action.device } }, devices: { [action.device.id]: { $set: action.device } },
@ -201,6 +241,30 @@ function reducer(previousState, action) {
change.active = { activeRoom: { $set: -1 } }; change.active = { activeRoom: { $set: -1 } };
} }
newState = update(previousState, change);
break;
case "SCENE_DELETE":
console.log("SCENE", action.sceneId);
if (!(action.sceneId in previousState.scenes)) {
console.warn(`Scene to delete ${action.sceneId} does not exist`);
break;
}
// This update does not ensure the consistent update of switchId/dimmerId properties
// on output devices connected to an input device in this room. Please manually request
// all devices again if consistent update is desired
change = { states: { $unset: [] } };
for (const id of previousState.scenes[action.sceneId].states) {
change.states.$unset.push(id);
}
change.scenes = { $unset: [action.sceneId] };
if (previousState.active.activeScene === action.sceneId) {
change.active = { activeScene: { $set: -1 } };
}
newState = update(previousState, change); newState = update(previousState, change);
break; break;
case "DEVICE_DELETE": case "DEVICE_DELETE":
@ -280,7 +344,6 @@ function reducer(previousState, action) {
} }
const initState = { const initState = {
errors: {},
pendingJoins: { pendingJoins: {
rooms: {}, rooms: {},
scenes: {}, scenes: {},
@ -299,9 +362,9 @@ const initState = {
userInfo: null, userInfo: null,
/** @type {[integer]Room} */ /** @type {[integer]Room} */
rooms: {}, rooms: {},
/** @type {[integer]Scenes} */ /** @type {[integer]Scene} */
scenes: {}, scenes: {},
/** @type {[integer]Automations} */ /** @type {[integer]Automation} */
automations: {}, automations: {},
/** @type {[integer]Device} */ /** @type {[integer]Device} */
devices: {}, devices: {},

View file

@ -17,6 +17,10 @@ const actions = {
type: "ROOM_SAVE", type: "ROOM_SAVE",
room, room,
}), }),
sceneSave: (scene) => ({
type: "SCENE_SAVE",
scene,
}),
deviceSave: (device) => ({ deviceSave: (device) => ({
type: "DEVICE_SAVE", type: "DEVICE_SAVE",
device, device,
@ -40,6 +44,14 @@ const actions = {
type: "ROOM_DELETE", type: "ROOM_DELETE",
roomId, roomId,
}), }),
sceneDelete: (sceneId) => ({
type: "SCENE_DELETE",
sceneId,
}),
scenesUpdate: (scenes) => ({
type: "SCENES_UPDATE",
scenes,
}),
deviceDelete: (deviceId) => ({ deviceDelete: (deviceId) => ({
type: "DEVICE_DELETE", type: "DEVICE_DELETE",
deviceId, deviceId,

View file

@ -1,79 +1,43 @@
import React, { Component } from "react"; import React, { Component } from "react";
import HomeNavbar from "./../components/HomeNavbar"; import HomeNavbar from "./../components/HomeNavbar";
import { Image, Divider, Message, Grid } from "semantic-ui-react"; import {
Image,
class Paragraph extends Component { Divider,
state = { visible: true }; Message,
Grid,
handleDismiss = () => { Button,
this.setState({ visible: false }); Icon,
Header,
setTimeout(() => { Container,
this.setState({ visible: true }); } from "semantic-ui-react";
}, 2000);
};
export default class ConfirmForgotPasswrod extends Component {
render() { render() {
if (this.state.visible) {
return (
<Message
onDismiss={this.handleDismiss}
header="Link has been sent!"
content="An e-mail has been sent your address, please follow the
instruction to create a new password"
/>
);
}
return ( return (
<p> <React.Fragment>
<br /> <Button circular style={{ margin: "2em" }} href="/">
<i>The message will return in 2s</i> <Icon name="arrow alternate circle left" />
<br /> Go Home{" "}
<br /> </Button>
</p> <Grid
textAlign="center"
style={{ height: "70vh" }}
verticalAlign="middle"
>
<Grid.Column style={{ maxWidth: 450 }}>
<Header as="h2" color="blue" textAlign="center">
<Image src="img/logo.png" /> Link has been sent!
</Header>
<Container textAlign="center">
<p>
An E-mail has been sent to your address, please follow the
instructions to create a new password. If you don't find the
E-mail please check also the spam folder.
</p>
</Container>
</Grid.Column>
</Grid>
</React.Fragment>
); );
} }
} }
const MessageReg = () => (
<Grid>
<HomeNavbar />
<Divider />
<Grid.Row height={3}></Grid.Row>
<Grid.Row height={3}></Grid.Row>
<Grid.Row height={3}></Grid.Row>
<Grid.Row height={3}>
<Grid.Column width={6}></Grid.Column>
<Grid.Column width={10}>
<Image src="title5.png" />
</Grid.Column>
<Grid.Column width={3}></Grid.Column>
</Grid.Row>
<Grid.Row height={3}></Grid.Row>
<Grid.Row height={3}></Grid.Row>
<Grid.Column width={3}></Grid.Column>
<Grid.Column width={4}>
<Image src="./img/logo.png" />
</Grid.Column>
<Grid.Column width={6}>
<Paragraph />
</Grid.Column>
<Grid.Column width={4}></Grid.Column>
<Grid.Row height={3}></Grid.Row>
<Grid.Row height={3}></Grid.Row>
<Grid.Row height={3}>
<Grid.Column width={3}></Grid.Column>
<Grid.Column width={10}>
<Divider />
</Grid.Column>
<Grid.Column width={3}></Grid.Column>
</Grid.Row>
</Grid>
);
export default class ConfirmForgotPasswrod extends React.Component {
render() {
return <MessageReg />;
}
}

View file

@ -1,79 +1,43 @@
import React, { Component } from "react"; import React, { Component } from "react";
import HomeNavbar from "./../components/HomeNavbar"; import HomeNavbar from "./../components/HomeNavbar";
import { Image, Divider, Message, Grid } from "semantic-ui-react"; import {
Image,
class Paragraph extends Component { Divider,
state = { visible: true }; Message,
Grid,
handleDismiss = () => { Button,
this.setState({ visible: false }); Icon,
Header,
setTimeout(() => { Container,
this.setState({ visible: true }); } from "semantic-ui-react";
}, 2000);
};
export default class ConfirmRegistration extends Component {
render() { render() {
if (this.state.visible) {
return (
<Message
onDismiss={this.handleDismiss}
header="Congratulation!"
content="An e-mail has been sent your address, please confirm
your registration by following the enclosed link"
/>
);
}
return ( return (
<p> <React.Fragment>
<br /> <Button circular style={{ margin: "2em" }} href="/">
<i>The message will return in 2s</i> <Icon name="arrow alternate circle left" />
<br /> Go Home{" "}
<br /> </Button>
</p> <Grid
textAlign="center"
style={{ height: "70vh" }}
verticalAlign="middle"
>
<Grid.Column style={{ maxWidth: 450 }}>
<Header as="h2" color="blue" textAlign="center">
<Image src="img/logo.png" /> Congratulation!
</Header>
<Container textAlign="center">
<p>
An E-mail has been sent to your address, confirm your
registration by following the enclosed link. If you don't find
the E-mail please check also the spam folder.
</p>
</Container>
</Grid.Column>
</Grid>
</React.Fragment>
); );
} }
} }
const MessageReg = () => (
<Grid>
<HomeNavbar />
<Divider />
<Grid.Row height={3}></Grid.Row>
<Grid.Row height={3}></Grid.Row>
<Grid.Row height={3}></Grid.Row>
<Grid.Row height={3}>
<Grid.Column width={6}></Grid.Column>
<Grid.Column width={10}>
<Image src="title5.png" />
</Grid.Column>
<Grid.Column width={3}></Grid.Column>
</Grid.Row>
<Grid.Row height={3}></Grid.Row>
<Grid.Row height={3}></Grid.Row>
<Grid.Column width={3}></Grid.Column>
<Grid.Column width={4}>
<Image src="./img/logo.png" />
</Grid.Column>
<Grid.Column width={6}>
<Paragraph />
</Grid.Column>
<Grid.Column width={4}></Grid.Column>
<Grid.Row height={3}></Grid.Row>
<Grid.Row height={3}></Grid.Row>
<Grid.Row height={3}>
<Grid.Column width={3}></Grid.Column>
<Grid.Column width={10}>
<Divider />
</Grid.Column>
<Grid.Column width={3}></Grid.Column>
</Grid.Row>
</Grid>
);
export default class ConfirmRegistration extends React.Component {
render() {
return <MessageReg />;
}
}

View file

@ -1,79 +1,39 @@
import React, { Component } from "react"; import React, { Component } from "react";
import HomeNavbar from "./../components/HomeNavbar"; import HomeNavbar from "./../components/HomeNavbar";
import { Image, Divider, Message, Grid } from "semantic-ui-react"; import {
Image,
class Paragraph extends Component { Divider,
state = { visible: true }; Message,
Grid,
handleDismiss = () => { Button,
this.setState({ visible: false }); Icon,
Header,
setTimeout(() => { Container,
this.setState({ visible: true }); } from "semantic-ui-react";
}, 2000);
};
render() {
if (this.state.visible) {
return (
<Message onDismiss={this.handleDismiss}>
<Message.Header>
Congratulation<ins>s</ins>!
</Message.Header>
Your password has been successfully reset
</Message>
);
}
return (
<p>
<br />
<i>The message will return in 2s</i>
<br />
<br />
</p>
);
}
}
const MessageReg = () => (
<Grid>
<HomeNavbar />
<Divider />
<Grid.Row height={3}></Grid.Row>
<Grid.Row height={3}></Grid.Row>
<Grid.Row height={3}></Grid.Row>
<Grid.Row height={3}>
<Grid.Column width={6}></Grid.Column>
<Grid.Column width={10}>
<Image src="title5.png" />
</Grid.Column>
<Grid.Column width={3}></Grid.Column>
</Grid.Row>
<Grid.Row height={3}></Grid.Row>
<Grid.Row height={3}></Grid.Row>
<Grid.Column width={3}></Grid.Column>
<Grid.Column width={4}>
<Image src="./img/logo.png" />
</Grid.Column>
<Grid.Column width={6}>
<Paragraph />
</Grid.Column>
<Grid.Column width={4}></Grid.Column>
<Grid.Row height={3}></Grid.Row>
<Grid.Row height={3}></Grid.Row>
<Grid.Row height={3}>
<Grid.Column width={3}></Grid.Column>
<Grid.Column width={10}>
<Divider />
</Grid.Column>
<Grid.Column width={3}></Grid.Column>
</Grid.Row>
</Grid>
);
export default class ConfirmResetPassword extends Component { export default class ConfirmResetPassword extends Component {
render() { render() {
return <MessageReg />; return (
<React.Fragment>
<Button circular style={{ margin: "2em" }} href="/">
<Icon name="arrow alternate circle left" />
Go Home{" "}
</Button>
<Grid
textAlign="center"
style={{ height: "70vh" }}
verticalAlign="middle"
>
<Grid.Column style={{ maxWidth: 450 }}>
<Header as="h2" color="blue" textAlign="center">
<Image src="img/logo.png" /> Congratulation!
</Header>
<Container textAlign="center">
<p>Your password has been successfully reset.</p>
</Container>
</Grid.Column>
</Grid>
</React.Fragment>
);
} }
} }

View file

@ -19,10 +19,22 @@ import { appActions } from "../storeActions";
class Dashboard extends Component { class Dashboard extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = this.initialState;
this.setInitialState();
this.selectTab = this.selectTab.bind(this); this.selectTab = this.selectTab.bind(this);
} }
get initialState() {
return {
activeTab: this.activeTab,
};
}
setInitialState() {
this.setState(this.initialState);
}
get activeTab() { get activeTab() {
return this.props.activeTab; return this.props.activeTab;
} }
@ -32,13 +44,14 @@ class Dashboard extends Component {
} }
selectTab(e, { name }) { selectTab(e, { name }) {
this.setState({ activeTab: name });
this.activeTab = name; this.activeTab = name;
} }
renderTab(tab) { renderTab(tab) {
switch (tab) { switch (tab) {
case "Devices": case "Devices":
return <DevicePanel />; return <DevicePanel tab={this.state.activeTab} />;
case "Scenes": case "Scenes":
return <ScenesPanel />; return <ScenesPanel />;
case "Automations": case "Automations":
@ -148,7 +161,7 @@ class Dashboard extends Component {
</Grid.Row> </Grid.Row>
<Grid.Row color="black"> <Grid.Row color="black">
<Grid.Column color="black"> <Grid.Column color="black">
<Navbar /> {this.renderNavbar(this.activeTab)}
</Grid.Column> </Grid.Column>
</Grid.Row> </Grid.Row>
<Grid.Row> <Grid.Row>

View file

@ -77,7 +77,7 @@ export default class ForgotPass extends Component {
<Form.Input <Form.Input
icon="address card outline" icon="address card outline"
iconPosition="left" iconPosition="left"
placeholder="Username or E-mail" placeholder="Enter your E-mail"
name="user" name="user"
type="text" type="text"
onChange={this.onChangeHandler} onChange={this.onChangeHandler}

View file

@ -82,7 +82,7 @@ class Navbar extends Component {
<Grid.Column> <Grid.Column>
<Icon name="home" size="small" /> <Icon name="home" size="small" />
</Grid.Column> </Grid.Column>
<Grid.Column>HOME</Grid.Column> <Grid.Column width={8}>House View</Grid.Column>
</Grid.Row> </Grid.Row>
</Grid> </Grid>
</Menu.Item> </Menu.Item>

View file

@ -2,8 +2,8 @@ import React, { Component } from "react";
import { import {
Menu, Menu,
Button, Button,
Grid,
Icon, Icon,
Grid,
Responsive, Responsive,
Dropdown, Dropdown,
} from "semantic-ui-react"; } from "semantic-ui-react";
@ -19,9 +19,12 @@ class ScenesNavbar extends Component {
this.state = { this.state = {
editMode: false, editMode: false,
}; };
console.log(this.props.scenes);
this.toggleEditMode = this.toggleEditMode.bind(this); this.toggleEditMode = this.toggleEditMode.bind(this);
this.openCurrentModalMobile = this.openCurrentModalMobile.bind(this); this.openCurrentModalMobile = this.openCurrentModalMobile.bind(this);
this.selectScene = this.selectScene.bind(this);
this.getScenes();
} }
get activeItemScene() { get activeItemScene() {
@ -33,13 +36,21 @@ class ScenesNavbar extends Component {
} }
get activeItemSceneName() { get activeItemSceneName() {
if (this.props.activeScene === -1) return "Home"; if (this.props.activeScene === -1) return "Scene";
return this.props.scenes[this.props.activeScene].name; return this.props.scenes[this.props.activeScene].name;
} }
getScenes() {
this.props
.fetchAllScenes()
.then(() => console.log(this.props.scenes))
.catch(console.error);
}
openCurrentModalMobile() { openCurrentModalMobile() {
console.log(this.activeItem, this.props.roomModalRefs); console.log(this.activeItemScene, this.props.sceneModalRefs);
const currentModal = this.props.roomModalRefs[this.activeItem].current; const currentModal = this.props.sceneModalRefs[this.activeItemScene]
.current;
currentModal.openModal(); currentModal.openModal();
} }
@ -47,6 +58,10 @@ class ScenesNavbar extends Component {
this.setState((prevState) => ({ editMode: !prevState.editMode })); this.setState((prevState) => ({ editMode: !prevState.editMode }));
} }
selectScene(e, { id }) {
this.activeItemScene = id || -1;
}
render() { render() {
return ( return (
<div style={{ background: "#1b1c1d!important", padding: "0 20px" }}> <div style={{ background: "#1b1c1d!important", padding: "0 20px" }}>
@ -66,18 +81,32 @@ class ScenesNavbar extends Component {
active={this.activeItemScene === -1} active={this.activeItemScene === -1}
onClick={this.selectScene} onClick={this.selectScene}
> >
<Grid> SCENES
<Grid.Row>
<Grid.Column>
<Icon name="home" size="small" />
</Grid.Column>
<Grid.Column>SCENES</Grid.Column>
</Grid.Row>
</Grid>
</Menu.Item> </Menu.Item>
{
//INSERT LIST OF SCENES HERE {Object.values(this.props.scenes).map((e, i) => {
} return (
<Menu.Item
id={e.id}
key={i}
name={e.name}
active={this.activeItemScene === e.id}
onClick={this.selectScene}
>
<Grid>
<Grid.Row>
<Grid.Column width={12}>{e.name}</Grid.Column>
<Grid.Column floated="right">
{this.state.editMode ? (
<SceneModal id={e.id} />
) : null}
</Grid.Column>
</Grid.Row>
</Grid>
</Menu.Item>
);
})}
<Menu.Item name="newM"> <Menu.Item name="newM">
<Grid> <Grid>
<Grid.Row centered name="new"> <Grid.Row centered name="new">
@ -103,17 +132,33 @@ class ScenesNavbar extends Component {
> >
<Grid> <Grid>
<Grid.Row> <Grid.Row>
<Grid.Column>
<Icon name="home" size="small" />
</Grid.Column>
<Grid.Column>Scene</Grid.Column> <Grid.Column>Scene</Grid.Column>
</Grid.Row> </Grid.Row>
</Grid> </Grid>
</Dropdown.Item> </Dropdown.Item>
{ {Object.values(this.props.scenes).map((e, i) => {
//INSERT LIST OF SCENES HERE return (
} <Dropdown.Item
id={e.id}
key={i}
name={e.name}
active={this.activeItemScene === e.id}
onClick={this.selectScene}
>
<Grid>
<Grid.Row>
<Grid.Column>{e.name}</Grid.Column>
</Grid.Row>
</Grid>
<SceneModal
ref={this.props.sceneModalRefs[e.id]}
nicolaStop={true}
id={e.id}
/>
</Dropdown.Item>
);
})}
</Dropdown.Menu> </Dropdown.Menu>
</Dropdown> </Dropdown>
</Menu> </Menu>
@ -131,7 +176,7 @@ class ScenesNavbar extends Component {
onClick={this.openCurrentModalMobile} onClick={this.openCurrentModalMobile}
> >
<Icon name="pencil" size="small" /> <Icon name="pencil" size="small" />
EDIT ROOM EDIT SCENE
</Button> </Button>
</Grid.Column> </Grid.Column>
) : null} ) : null}