switch and smart-plug update and fixed warnings
This commit is contained in:
parent
e81b5a9553
commit
8dad01d633
10 changed files with 59 additions and 36 deletions
|
@ -233,7 +233,7 @@ export var call = {
|
||||||
let promiseRes = axios.put(config + url, data, {
|
let promiseRes = axios.put(config + url, data, {
|
||||||
headers: { Authorization: "Bearer " + tkn },
|
headers: { Authorization: "Bearer " + tkn },
|
||||||
});
|
});
|
||||||
|
// also for btn/knob dimmer
|
||||||
if (typeDevice === "switch/operate") {
|
if (typeDevice === "switch/operate") {
|
||||||
promiseRes = promiseRes.then((e) => {
|
promiseRes = promiseRes.then((e) => {
|
||||||
if (e.status === 200) {
|
if (e.status === 200) {
|
||||||
|
|
|
@ -1,12 +1,7 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { Dropdown, Icon, Grid, Divider } from "semantic-ui-react";
|
import { Dropdown, Icon, Grid, Divider } from "semantic-ui-react";
|
||||||
import { Segment, Image } from "semantic-ui-react";
|
import { Segment, Image } from "semantic-ui-react";
|
||||||
import {
|
import { BrowserView, MobileView } from "react-device-detect";
|
||||||
BrowserView,
|
|
||||||
MobileView,
|
|
||||||
isBrowser,
|
|
||||||
isMobile,
|
|
||||||
} from "react-device-detect";
|
|
||||||
|
|
||||||
const AvatarImage = () => (
|
const AvatarImage = () => (
|
||||||
<Image src="avatar3.png" style={{ width: "25px", height: "auto" }} centered />
|
<Image src="avatar3.png" style={{ width: "25px", height: "auto" }} centered />
|
||||||
|
@ -22,16 +17,6 @@ const IconHomeImage = () => (
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
const IconHomeImageMobile = () => (
|
|
||||||
<Image
|
|
||||||
src="smart-home.png"
|
|
||||||
style={{ width: "10px", height: "auto" }}
|
|
||||||
centered
|
|
||||||
as="a"
|
|
||||||
href="/"
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
|
|
||||||
const TitleImage = () => <Image src="title7.png" size="medium" centered />;
|
const TitleImage = () => <Image src="title7.png" size="medium" centered />;
|
||||||
|
|
||||||
const BrowserStructure = (props) => (
|
const BrowserStructure = (props) => (
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import React, { Component } from "react";
|
import React, { Component } from "react";
|
||||||
import { Button, Grid, Responsive } from "semantic-ui-react";
|
import { Button, Grid } from "semantic-ui-react";
|
||||||
|
|
||||||
export default class SelectIcons extends Component {
|
export default class SelectIcons extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
|
|
|
@ -56,7 +56,7 @@ export default class DevicePanel extends Component {
|
||||||
this.forceUpdate();
|
this.forceUpdate();
|
||||||
};
|
};
|
||||||
|
|
||||||
getDevices() {
|
getDevices = () => {
|
||||||
if (this.props.activeItem === -1) {
|
if (this.props.activeItem === -1) {
|
||||||
call
|
call
|
||||||
.getAllDevices()
|
.getAllDevices()
|
||||||
|
@ -82,7 +82,7 @@ export default class DevicePanel extends Component {
|
||||||
})
|
})
|
||||||
.catch((err) => {});
|
.catch((err) => {});
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
async addDevice(data) {
|
async addDevice(data) {
|
||||||
const ds = await this.props.addDevice(data);
|
const ds = await this.props.addDevice(data);
|
||||||
|
@ -96,10 +96,8 @@ export default class DevicePanel extends Component {
|
||||||
const roomId = this.props.devices.filter(
|
const roomId = this.props.devices.filter(
|
||||||
(d) => d.id === this.state.settingsDeviceId
|
(d) => d.id === this.state.settingsDeviceId
|
||||||
)[0].roomId;
|
)[0].roomId;
|
||||||
console.log(roomId);
|
|
||||||
data["id"] = this.state.settingsDeviceId;
|
data["id"] = this.state.settingsDeviceId;
|
||||||
data["roomId"] = roomId;
|
data["roomId"] = roomId;
|
||||||
console.log(data);
|
|
||||||
call
|
call
|
||||||
.deviceUpdate(data)
|
.deviceUpdate(data)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
|
@ -159,6 +157,7 @@ export default class DevicePanel extends Component {
|
||||||
return (
|
return (
|
||||||
<Grid.Column key={i}>
|
<Grid.Column key={i}>
|
||||||
<DeviceType
|
<DeviceType
|
||||||
|
updateDev={this.props.updateDeviceUi}
|
||||||
type={e.kind}
|
type={e.kind}
|
||||||
onChangeData={this.changeDeviceData}
|
onChangeData={this.changeDeviceData}
|
||||||
device={e}
|
device={e}
|
||||||
|
|
|
@ -10,6 +10,7 @@ const DeviceType = (props) => {
|
||||||
case "regularLight":
|
case "regularLight":
|
||||||
return (
|
return (
|
||||||
<Light
|
<Light
|
||||||
|
updateDev={props.updateDeviceUi}
|
||||||
onChangeData={props.changeDeviceData}
|
onChangeData={props.changeDeviceData}
|
||||||
device={props.device}
|
device={props.device}
|
||||||
edit={props.edit}
|
edit={props.edit}
|
||||||
|
@ -18,6 +19,7 @@ const DeviceType = (props) => {
|
||||||
case "sensor":
|
case "sensor":
|
||||||
return (
|
return (
|
||||||
<Sensor
|
<Sensor
|
||||||
|
updateDev={props.updateDeviceUi}
|
||||||
onChangeData={props.changeDeviceData}
|
onChangeData={props.changeDeviceData}
|
||||||
device={props.device}
|
device={props.device}
|
||||||
edit={props.edit}
|
edit={props.edit}
|
||||||
|
@ -26,6 +28,7 @@ const DeviceType = (props) => {
|
||||||
case "buttonDimmer":
|
case "buttonDimmer":
|
||||||
return (
|
return (
|
||||||
<DefaultDimmer
|
<DefaultDimmer
|
||||||
|
updateDev={props.updateDeviceUi}
|
||||||
onChangeData={props.changeDeviceData}
|
onChangeData={props.changeDeviceData}
|
||||||
device={props.device}
|
device={props.device}
|
||||||
edit={props.edit}
|
edit={props.edit}
|
||||||
|
@ -34,6 +37,7 @@ const DeviceType = (props) => {
|
||||||
case "smartPlug":
|
case "smartPlug":
|
||||||
return (
|
return (
|
||||||
<SmartPlug
|
<SmartPlug
|
||||||
|
updateDev={props.updateDeviceUi}
|
||||||
onChangeData={props.changeDeviceData}
|
onChangeData={props.changeDeviceData}
|
||||||
device={props.device}
|
device={props.device}
|
||||||
edit={props.edit}
|
edit={props.edit}
|
||||||
|
@ -42,6 +46,7 @@ const DeviceType = (props) => {
|
||||||
case "switch":
|
case "switch":
|
||||||
return (
|
return (
|
||||||
<Switcher
|
<Switcher
|
||||||
|
updateDev={props.updateDeviceUi}
|
||||||
onChangeData={props.changeDeviceData}
|
onChangeData={props.changeDeviceData}
|
||||||
device={props.device}
|
device={props.device}
|
||||||
edit={props.edit}
|
edit={props.edit}
|
||||||
|
@ -50,6 +55,7 @@ const DeviceType = (props) => {
|
||||||
case "dimmableLight":
|
case "dimmableLight":
|
||||||
return (
|
return (
|
||||||
<Light
|
<Light
|
||||||
|
updateDev={props.updateDeviceUi}
|
||||||
onChangeData={props.changeDeviceData}
|
onChangeData={props.changeDeviceData}
|
||||||
device={props.device}
|
device={props.device}
|
||||||
edit={props.edit}
|
edit={props.edit}
|
||||||
|
|
|
@ -38,7 +38,9 @@ export default class Sensor extends Component {
|
||||||
value: 0,
|
value: 0,
|
||||||
};
|
};
|
||||||
this.units = "";
|
this.units = "";
|
||||||
this.stateCallback = (e) => this.setState(Object.assign(this.state, e));
|
this.stateCallback = (e) => {
|
||||||
|
this.setState(Object.assign(this.state, e));
|
||||||
|
};
|
||||||
|
|
||||||
call.socketSubscribe(this.props.device.id, this.stateCallback);
|
call.socketSubscribe(this.props.device.id, this.stateCallback);
|
||||||
}
|
}
|
||||||
|
@ -95,7 +97,7 @@ export default class Sensor extends Component {
|
||||||
dy="0.3em"
|
dy="0.3em"
|
||||||
fontWeight="bold"
|
fontWeight="bold"
|
||||||
>
|
>
|
||||||
{Math.round(this.state.value)}
|
{+(Math.round(this.state.value + "e+2") + "e-2")}
|
||||||
{this.units}
|
{this.units}
|
||||||
</text>
|
</text>
|
||||||
<text
|
<text
|
||||||
|
|
|
@ -20,6 +20,21 @@ export default class SmartPlug extends Component {
|
||||||
};
|
};
|
||||||
this.iconOn = "/img/smart-plug.svg";
|
this.iconOn = "/img/smart-plug.svg";
|
||||||
this.iconOff = "/img/smart-plug-off.svg";
|
this.iconOff = "/img/smart-plug-off.svg";
|
||||||
|
|
||||||
|
this.stateCallback = (e) => {
|
||||||
|
this.setState(
|
||||||
|
Object.assign(this.state, {
|
||||||
|
energyConsumed: (e.totalConsumption / 1000).toFixed(3),
|
||||||
|
turnedOn: e.on,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
call.socketSubscribe(this.props.device.id, this.stateCallback);
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
call.socketUnsubscribe(this.props.device.id, this.stateCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
onClickDevice = () => {
|
onClickDevice = () => {
|
||||||
|
|
|
@ -108,16 +108,6 @@ export default class ModalWindow extends Component {
|
||||||
<Icon name="pencil" size="small" onClick={this.openModal} />
|
<Icon name="pencil" size="small" onClick={this.openModal} />
|
||||||
)}
|
)}
|
||||||
</Responsive>
|
</Responsive>
|
||||||
<Responsive maxWidth={768}>
|
|
||||||
{this.props.type === "new" ? (
|
|
||||||
<Button icon fluid labelPosition="left" onClick={this.openModal}>
|
|
||||||
<Icon name="plus" size="small" />
|
|
||||||
ADD ROOM
|
|
||||||
</Button>
|
|
||||||
) : (
|
|
||||||
<Icon name="pencil" size="small" onClick={this.openModal} />
|
|
||||||
)}
|
|
||||||
</Responsive>
|
|
||||||
<Responsive maxWidth={768}>
|
<Responsive maxWidth={768}>
|
||||||
{this.props.type === "new" ? (
|
{this.props.type === "new" ? (
|
||||||
<Button icon fluid labelPosition="left" onClick={this.openModal}>
|
<Button icon fluid labelPosition="left" onClick={this.openModal}>
|
||||||
|
|
|
@ -21,6 +21,7 @@ export default class Dashboard extends Component {
|
||||||
rooms: [],
|
rooms: [],
|
||||||
activeItem: -1,
|
activeItem: -1,
|
||||||
devices: [],
|
devices: [],
|
||||||
|
image: "",
|
||||||
tkn: this.props.tkn,
|
tkn: this.props.tkn,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -51,6 +52,7 @@ export default class Dashboard extends Component {
|
||||||
.getAllDevicesByRoom(this.state.activeItem)
|
.getAllDevicesByRoom(this.state.activeItem)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
|
console.log(res.data);
|
||||||
this.setState({
|
this.setState({
|
||||||
devices: res.data,
|
devices: res.data,
|
||||||
});
|
});
|
||||||
|
@ -98,6 +100,7 @@ export default class Dashboard extends Component {
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
//remove room in state.rooms
|
//remove room in state.rooms
|
||||||
this.getRooms();
|
this.getRooms();
|
||||||
|
this.handleItemClick(-1);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
|
@ -118,8 +121,6 @@ export default class Dashboard extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
handleItemClick(id) {
|
handleItemClick(id) {
|
||||||
// el -> obj of name and id
|
|
||||||
//da fare richiesta get della room e settare activeItem
|
|
||||||
this.setState({
|
this.setState({
|
||||||
activeItem: id,
|
activeItem: id,
|
||||||
});
|
});
|
||||||
|
@ -166,6 +167,20 @@ export default class Dashboard extends Component {
|
||||||
.catch((err) => {});
|
.catch((err) => {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateDeviceUi = (data) => {
|
||||||
|
let ds = this.state.devices;
|
||||||
|
ds.forEach((e) => {
|
||||||
|
if (e.id === data.id) {
|
||||||
|
e = data;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.setState({
|
||||||
|
devices: ds,
|
||||||
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div style={{ height: "110vh", background: "#1b1c1d" }}>
|
<div style={{ height: "110vh", background: "#1b1c1d" }}>
|
||||||
|
@ -179,6 +194,7 @@ export default class Dashboard extends Component {
|
||||||
<Grid.Row color="black">
|
<Grid.Row color="black">
|
||||||
<Grid.Column width={3}>
|
<Grid.Column width={3}>
|
||||||
<Navbar
|
<Navbar
|
||||||
|
activeItem={this.state.activeItem}
|
||||||
addRoom={this.addRoom}
|
addRoom={this.addRoom}
|
||||||
updateRoom={this.updateRoom}
|
updateRoom={this.updateRoom}
|
||||||
deleteRoom={this.deleteRoom}
|
deleteRoom={this.deleteRoom}
|
||||||
|
@ -208,7 +224,9 @@ export default class Dashboard extends Component {
|
||||||
<Grid.Row color="black">
|
<Grid.Row color="black">
|
||||||
<Grid.Column color="black">
|
<Grid.Column color="black">
|
||||||
<Navbar
|
<Navbar
|
||||||
|
activeItem={this.state.activeItem}
|
||||||
addRoom={this.addRoom}
|
addRoom={this.addRoom}
|
||||||
|
updateRoom={this.updateRoom}
|
||||||
deleteRoom={this.deleteRoom}
|
deleteRoom={this.deleteRoom}
|
||||||
rooms={this.state.rooms}
|
rooms={this.state.rooms}
|
||||||
handleItemClick={this.handleItemClick}
|
handleItemClick={this.handleItemClick}
|
||||||
|
@ -218,10 +236,12 @@ export default class Dashboard extends Component {
|
||||||
<Grid.Row>
|
<Grid.Row>
|
||||||
<Grid.Column>
|
<Grid.Column>
|
||||||
<DevicePanel
|
<DevicePanel
|
||||||
|
img={this.state.image}
|
||||||
tkn={this.props.tkn}
|
tkn={this.props.tkn}
|
||||||
activeItem={this.state.activeItem}
|
activeItem={this.state.activeItem}
|
||||||
addDevice={this.addDevice}
|
addDevice={this.addDevice}
|
||||||
devices={this.state.devices}
|
devices={this.state.devices}
|
||||||
|
updateDev={this.updateDeviceUi}
|
||||||
/>
|
/>
|
||||||
</Grid.Column>
|
</Grid.Column>
|
||||||
</Grid.Row>
|
</Grid.Row>
|
||||||
|
|
|
@ -21,6 +21,12 @@ class Navbar extends Component {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
this.setState({
|
||||||
|
activeItem: this.props.activeItem,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
editModeController = (e) =>
|
editModeController = (e) =>
|
||||||
this.setState((prevState) => ({ editMode: !prevState.editMode }));
|
this.setState((prevState) => ({ editMode: !prevState.editMode }));
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue