2020-05-26 11:45:06 +00:00
|
|
|
import React, { Component } from 'react';
|
2020-05-09 07:57:04 +00:00
|
|
|
import {
|
|
|
|
Grid,
|
|
|
|
Divider,
|
2020-05-09 15:46:57 +00:00
|
|
|
Image,
|
2020-05-26 11:45:06 +00:00
|
|
|
Modal,
|
2020-05-27 10:04:16 +00:00
|
|
|
Button,
|
2020-05-23 14:11:25 +00:00
|
|
|
} from 'semantic-ui-react';
|
2020-05-26 11:45:06 +00:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { RemoteService } from '../remote';
|
|
|
|
import SimulationPanelSlider from './SimulationPanelSlider.js';
|
2020-05-09 07:13:26 +00:00
|
|
|
|
2020-05-26 11:45:06 +00:00
|
|
|
/*
|
2020-05-09 07:13:26 +00:00
|
|
|
const SimulationPanel = (props) => (
|
|
|
|
<Modal
|
|
|
|
isOpen={!!props.simulationPanel}
|
|
|
|
contentLabel="Simulation Panel"
|
|
|
|
onRequestClose={props.closeSimulationPanel}
|
2020-05-09 07:57:04 +00:00
|
|
|
// style={ReactModalPortal,ReactModal__Overlay, modal}
|
|
|
|
style={{
|
|
|
|
overlay: {
|
|
|
|
position: 'fixed',
|
|
|
|
top: 0,
|
|
|
|
left: 0,
|
|
|
|
right: 0,
|
|
|
|
bottom: 0,
|
2020-05-23 14:11:25 +00:00
|
|
|
backgroundColor: 'rgba(0,0,0,0.5)',
|
2020-05-09 07:57:04 +00:00
|
|
|
},
|
|
|
|
content: {
|
|
|
|
position: 'absolute',
|
|
|
|
top: '40px',
|
|
|
|
left: '40px',
|
|
|
|
right: '40px',
|
|
|
|
bottom: '40px',
|
|
|
|
border: '1px solid #ccc',
|
|
|
|
background: '#fff',
|
|
|
|
overflow: 'auto',
|
|
|
|
WebkitOverflowScrolling: 'touch',
|
|
|
|
borderRadius: '4px',
|
|
|
|
outline: 'none',
|
|
|
|
padding: '20px',
|
2020-05-23 14:11:25 +00:00
|
|
|
backgroundColor: 'rgb(65, 67, 69)',
|
|
|
|
},
|
2020-05-09 07:57:04 +00:00
|
|
|
}}
|
2020-05-09 07:13:26 +00:00
|
|
|
>
|
2020-05-09 07:57:04 +00:00
|
|
|
{props.simulationPanel}
|
2020-05-09 15:46:57 +00:00
|
|
|
<Grid celled>
|
|
|
|
|
2020-05-26 11:45:06 +00:00
|
|
|
{/* TITLE }
|
2020-05-23 14:11:25 +00:00
|
|
|
<Grid.Row textAlign="center">
|
|
|
|
<h1 style={{ color: 'white', padding: '1rem', fontFamily: 'Arial' }}>
|
2020-05-09 15:46:57 +00:00
|
|
|
Welcome in the Simulation Panel
|
2020-05-23 14:11:25 +00:00
|
|
|
</h1>
|
|
|
|
</Grid.Row>
|
2020-05-09 07:57:04 +00:00
|
|
|
|
2020-05-26 11:45:06 +00:00
|
|
|
{/* TEMPERATURE SENSOR }
|
2020-05-23 14:11:25 +00:00
|
|
|
<Grid.Row>
|
|
|
|
<Grid.Column width={6} textAlign="center">
|
|
|
|
<Divider
|
|
|
|
style={{
|
|
|
|
marginTop: '3rem',
|
|
|
|
marginBottom: 'auto',
|
2020-05-18 08:54:31 +00:00
|
|
|
}}
|
2020-05-23 14:11:25 +00:00
|
|
|
/>
|
|
|
|
<Image
|
|
|
|
src="./../img/thermo-simulation.png"
|
|
|
|
style={{
|
|
|
|
width: '60px',
|
|
|
|
height: 'auto',
|
|
|
|
display: 'block',
|
|
|
|
marginLeft: 'auto',
|
|
|
|
marginRight: 'auto',
|
|
|
|
marginTop: '1rem',
|
|
|
|
marginBottom: '1rem',
|
2020-05-09 15:46:57 +00:00
|
|
|
}}
|
2020-05-23 14:11:25 +00:00
|
|
|
/>
|
|
|
|
<p style={{ color: 'white', padding: '0.5rem' }}>
|
2020-05-18 08:54:31 +00:00
|
|
|
Temperature Sensor
|
2020-05-23 14:11:25 +00:00
|
|
|
</p>
|
|
|
|
<Divider />
|
|
|
|
</Grid.Column>
|
|
|
|
|
|
|
|
|
|
|
|
<Grid.Column width={10} textAlign="center">
|
2020-05-09 15:46:57 +00:00
|
|
|
|
2020-05-23 14:11:25 +00:00
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
display: 'block',
|
|
|
|
marginLeft: '30%',
|
2020-05-18 08:54:31 +00:00
|
|
|
}}
|
2020-05-23 14:11:25 +00:00
|
|
|
>
|
2020-05-26 11:45:06 +00:00
|
|
|
<SimulationPanelSlider />
|
2020-05-23 14:11:25 +00:00
|
|
|
</div>
|
|
|
|
<Divider />
|
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
display: 'block',
|
|
|
|
marginLeft: '30%',
|
2020-05-18 08:54:31 +00:00
|
|
|
}}
|
2020-05-23 14:11:25 +00:00
|
|
|
>
|
2020-05-26 11:45:06 +00:00
|
|
|
<SimulationPanelSlider />
|
2020-05-23 14:11:25 +00:00
|
|
|
</div>
|
|
|
|
</Grid.Column>
|
|
|
|
</Grid.Row>
|
2020-05-18 08:54:31 +00:00
|
|
|
|
2020-05-26 11:45:06 +00:00
|
|
|
{/* HUMIDTY SENSOR }
|
2020-05-23 14:11:25 +00:00
|
|
|
<Grid.Row>
|
|
|
|
<Grid.Column width={6} textAlign="center">
|
|
|
|
<Divider
|
|
|
|
style={{
|
|
|
|
marginTop: '3rem',
|
|
|
|
marginBottom: 'auto',
|
2020-05-18 08:54:31 +00:00
|
|
|
}}
|
2020-05-23 14:11:25 +00:00
|
|
|
/>
|
|
|
|
<Image
|
|
|
|
src="./../img/humidity-simulation.png"
|
|
|
|
style={{
|
|
|
|
width: '60px',
|
|
|
|
height: 'auto',
|
|
|
|
display: 'block',
|
|
|
|
marginLeft: 'auto',
|
|
|
|
marginRight: 'auto',
|
|
|
|
marginTop: '1rem',
|
|
|
|
marginBottom: '1rem',
|
2020-05-09 15:46:57 +00:00
|
|
|
}}
|
2020-05-23 14:11:25 +00:00
|
|
|
/>
|
|
|
|
<p style={{ color: 'white', padding: '0.5rem' }}>
|
2020-05-18 08:54:31 +00:00
|
|
|
Humidity Sensor
|
2020-05-23 14:11:25 +00:00
|
|
|
</p>
|
|
|
|
<Divider />
|
|
|
|
</Grid.Column>
|
|
|
|
|
|
|
|
|
|
|
|
<Grid.Column width={10} textAlign="center">
|
2020-05-09 15:46:57 +00:00
|
|
|
|
2020-05-23 14:11:25 +00:00
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
display: 'block',
|
|
|
|
marginLeft: '30%',
|
2020-05-18 08:54:31 +00:00
|
|
|
}}
|
2020-05-23 14:11:25 +00:00
|
|
|
>
|
2020-05-26 11:45:06 +00:00
|
|
|
<SimulationPanelSlider />
|
2020-05-23 14:11:25 +00:00
|
|
|
</div>
|
|
|
|
<Divider />
|
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
display: 'block',
|
|
|
|
marginLeft: '30%',
|
2020-05-09 15:46:57 +00:00
|
|
|
}}
|
2020-05-23 14:11:25 +00:00
|
|
|
>
|
2020-05-26 11:45:06 +00:00
|
|
|
<SimulationPanelSlider />
|
2020-05-23 14:11:25 +00:00
|
|
|
</div>
|
|
|
|
</Grid.Column>
|
|
|
|
</Grid.Row>
|
2020-05-18 08:54:31 +00:00
|
|
|
|
2020-05-26 11:45:06 +00:00
|
|
|
{/* LIGHT SENSOR }
|
2020-05-23 14:11:25 +00:00
|
|
|
<Grid.Row>
|
|
|
|
<Grid.Column width={6} textAlign="center">
|
|
|
|
<Divider
|
|
|
|
style={{
|
|
|
|
marginTop: '3rem',
|
|
|
|
marginBottom: 'auto',
|
2020-05-18 08:54:31 +00:00
|
|
|
}}
|
2020-05-23 14:11:25 +00:00
|
|
|
/>
|
|
|
|
<Image
|
|
|
|
src="./../img/light-simulation.png"
|
|
|
|
style={{
|
|
|
|
width: '60px',
|
|
|
|
height: 'auto',
|
|
|
|
display: 'block',
|
|
|
|
marginLeft: 'auto',
|
|
|
|
marginRight: 'auto',
|
|
|
|
marginTop: '1rem',
|
|
|
|
marginBottom: '1rem',
|
2020-05-18 08:54:31 +00:00
|
|
|
}}
|
2020-05-23 14:11:25 +00:00
|
|
|
/>
|
|
|
|
<p style={{ color: 'white', padding: '0.5rem' }}>
|
2020-05-18 08:54:31 +00:00
|
|
|
Light Sensor
|
2020-05-23 14:11:25 +00:00
|
|
|
</p>
|
|
|
|
<Divider />
|
|
|
|
</Grid.Column>
|
2020-05-09 15:46:57 +00:00
|
|
|
|
2020-05-23 14:11:25 +00:00
|
|
|
|
|
|
|
<Grid.Column width={10} textAlign="center">
|
|
|
|
|
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
display: 'block',
|
|
|
|
marginLeft: '30%',
|
2020-05-09 15:46:57 +00:00
|
|
|
}}
|
2020-05-23 14:11:25 +00:00
|
|
|
>
|
2020-05-26 11:45:06 +00:00
|
|
|
<SimulationPanelSlider />
|
2020-05-23 14:11:25 +00:00
|
|
|
</div>
|
|
|
|
<Divider />
|
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
display: 'block',
|
|
|
|
marginLeft: '30%',
|
2020-05-18 08:54:31 +00:00
|
|
|
}}
|
2020-05-23 14:11:25 +00:00
|
|
|
>
|
2020-05-26 11:45:06 +00:00
|
|
|
<SimulationPanelSlider />
|
2020-05-23 14:11:25 +00:00
|
|
|
</div>
|
|
|
|
</Grid.Column>
|
|
|
|
</Grid.Row>
|
2020-05-09 15:46:57 +00:00
|
|
|
|
2020-05-26 11:45:06 +00:00
|
|
|
{/* MOTION SENSOR }
|
2020-05-23 14:11:25 +00:00
|
|
|
<Grid.Row>
|
|
|
|
<Grid.Column width={6} textAlign="center">
|
|
|
|
<Divider
|
|
|
|
style={{
|
|
|
|
marginTop: '3rem',
|
|
|
|
marginBottom: 'auto',
|
2020-05-18 08:54:31 +00:00
|
|
|
}}
|
2020-05-23 14:11:25 +00:00
|
|
|
/>
|
|
|
|
<Image
|
|
|
|
src="./../img/motion-simulation.png"
|
|
|
|
style={{
|
|
|
|
width: '60px',
|
|
|
|
height: 'auto',
|
|
|
|
display: 'block',
|
|
|
|
marginLeft: 'auto',
|
|
|
|
marginRight: 'auto',
|
|
|
|
marginTop: '1rem',
|
|
|
|
marginBottom: '1rem',
|
2020-05-18 08:54:31 +00:00
|
|
|
}}
|
2020-05-23 14:11:25 +00:00
|
|
|
/>
|
|
|
|
<p style={{ color: 'white', padding: '0.5rem' }}>
|
2020-05-18 08:54:31 +00:00
|
|
|
Motion Sensor
|
2020-05-23 14:11:25 +00:00
|
|
|
</p>
|
|
|
|
<Divider />
|
|
|
|
</Grid.Column>
|
|
|
|
|
2020-05-18 08:54:31 +00:00
|
|
|
|
2020-05-23 14:11:25 +00:00
|
|
|
<Grid.Column width={10} textAlign="center">
|
|
|
|
|
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
display: 'block',
|
|
|
|
marginLeft: '30%',
|
2020-05-18 08:54:31 +00:00
|
|
|
}}
|
2020-05-23 14:11:25 +00:00
|
|
|
>
|
2020-05-26 11:45:06 +00:00
|
|
|
<SimulationPanelSlider />
|
2020-05-23 14:11:25 +00:00
|
|
|
</div>
|
|
|
|
<Divider />
|
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
display: 'block',
|
|
|
|
marginLeft: '30%',
|
2020-05-18 08:54:31 +00:00
|
|
|
}}
|
2020-05-23 14:11:25 +00:00
|
|
|
>
|
2020-05-26 11:45:06 +00:00
|
|
|
<SimulationPanelSlider />
|
2020-05-23 14:11:25 +00:00
|
|
|
</div>
|
|
|
|
</Grid.Column>
|
|
|
|
</Grid.Row>
|
|
|
|
|
2020-05-09 15:46:57 +00:00
|
|
|
|
2020-05-09 07:57:04 +00:00
|
|
|
</Grid>
|
2020-05-09 07:13:26 +00:00
|
|
|
</Modal>
|
|
|
|
);
|
2020-05-26 11:45:06 +00:00
|
|
|
*/
|
|
|
|
class SimulationPanel extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
console.log(this.props.devices);
|
|
|
|
this.state = {
|
|
|
|
value: null,
|
|
|
|
error: null,
|
|
|
|
};
|
2020-05-27 10:04:16 +00:00
|
|
|
this.updateSliderValues = this.updateSliderValues.bind(this);
|
|
|
|
this.saveChanges = this.saveChanges.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
updateSliderValues(type, data, motion) {
|
|
|
|
console.log(data, motion);
|
|
|
|
this.setState({
|
|
|
|
[type ? 'error' : 'value']: data,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
saveChanges(device) {
|
|
|
|
console.log(this.state);
|
|
|
|
const { value } = this.state;
|
|
|
|
const { error } = this.state;
|
|
|
|
if (device.kind === 'sensor') {
|
|
|
|
this.props
|
|
|
|
.updateSimulation(
|
|
|
|
{ ...device, typical: value, err: error },
|
|
|
|
)
|
|
|
|
.catch((err) => console.error('Simulation panel update error', err));
|
|
|
|
} else {
|
|
|
|
const val = device.kind === 'motionSensor' ? 'detected' : 'typical';
|
|
|
|
this.props
|
|
|
|
.saveDevice(
|
|
|
|
{ ...device, [val]: value, err: error },
|
|
|
|
null,
|
|
|
|
)
|
|
|
|
.catch((err) => console.error('Simulation panel update error', err));
|
|
|
|
}
|
2020-05-26 11:45:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
renderImage(device) {
|
|
|
|
let image = './../img/';
|
|
|
|
switch (device.kind) {
|
|
|
|
case 'thermostat':
|
|
|
|
image += 'thermo-simulation.png';
|
|
|
|
break;
|
|
|
|
case 'motionSensor':
|
|
|
|
image += 'motion-simulation.png';
|
|
|
|
break;
|
|
|
|
case 'sensor':
|
|
|
|
if (device.sensorType === 'TEMPERATURE') {
|
|
|
|
image += 'thermo-simulation.png';
|
|
|
|
} else if (device.sensorType === 'HUMIDITY') {
|
|
|
|
image += 'humidity-simulation.png';
|
|
|
|
} else {
|
|
|
|
image += 'light-simulation.png';
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Image
|
|
|
|
src={image}
|
|
|
|
style={{
|
|
|
|
width: '60px',
|
|
|
|
height: 'auto',
|
|
|
|
display: 'block',
|
|
|
|
marginLeft: 'auto',
|
|
|
|
marginRight: 'auto',
|
|
|
|
marginTop: '1rem',
|
|
|
|
marginBottom: '1rem',
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<Modal
|
|
|
|
closeIcon
|
|
|
|
open={!!this.props.simulationPanel}
|
|
|
|
onClose={this.props.closeSimulationPanel}
|
|
|
|
>
|
|
|
|
<Grid celled>
|
|
|
|
<Grid.Row textAlign="center">
|
|
|
|
<h1 style={{ padding: '1rem', fontFamily: 'Arial' }}>
|
|
|
|
Welcome in the Simulation Panel
|
|
|
|
</h1>
|
|
|
|
</Grid.Row>
|
|
|
|
{
|
|
|
|
this.props.devices
|
2020-05-27 10:04:16 +00:00
|
|
|
? this.props.devices.map((d, i) => (
|
|
|
|
<Grid.Row key={i}>
|
2020-05-26 11:45:06 +00:00
|
|
|
<Grid.Column width={6} textAlign="center">
|
2020-05-27 10:04:16 +00:00
|
|
|
{this.renderImage(d)}
|
2020-05-26 11:45:06 +00:00
|
|
|
<p style={{ padding: '0.5rem' }}>
|
2020-05-27 10:04:16 +00:00
|
|
|
{d.name}
|
2020-05-26 11:45:06 +00:00
|
|
|
</p>
|
|
|
|
<Divider />
|
2020-05-27 10:04:16 +00:00
|
|
|
<Button
|
|
|
|
color="green"
|
|
|
|
id={d.id}
|
|
|
|
onClick={(e, { id }) => this.saveChanges(d, id)}
|
|
|
|
>
|
|
|
|
Save
|
|
|
|
</Button>
|
2020-05-26 11:45:06 +00:00
|
|
|
</Grid.Column>
|
|
|
|
|
|
|
|
|
|
|
|
<Grid.Column width={10} textAlign="center">
|
|
|
|
|
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
display: 'block',
|
|
|
|
marginLeft: '30%',
|
|
|
|
}}
|
|
|
|
>
|
2020-05-27 10:04:16 +00:00
|
|
|
<SimulationPanelSlider update={this.updateSliderValues} error={false} device={d} id={d.id} />
|
2020-05-26 11:45:06 +00:00
|
|
|
</div>
|
2020-05-26 15:20:56 +00:00
|
|
|
{
|
2020-05-27 10:04:16 +00:00
|
|
|
d.kind === 'motionSensor'
|
2020-05-26 15:20:56 +00:00
|
|
|
? null
|
|
|
|
: (
|
|
|
|
<>
|
|
|
|
<Divider />
|
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
display: 'block',
|
|
|
|
marginLeft: '30%',
|
|
|
|
}}
|
|
|
|
>
|
2020-05-27 10:04:16 +00:00
|
|
|
<SimulationPanelSlider update={this.updateSliderValues} error device={d} id={d.id} />
|
2020-05-26 15:20:56 +00:00
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
2020-05-26 11:45:06 +00:00
|
|
|
</Grid.Column>
|
|
|
|
</Grid.Row>
|
|
|
|
))
|
|
|
|
: null
|
|
|
|
}
|
|
|
|
</Grid>
|
|
|
|
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2020-05-09 07:13:26 +00:00
|
|
|
|
2020-05-26 11:45:06 +00:00
|
|
|
const mapStateToProps = (state, _) => ({
|
|
|
|
get devices() {
|
|
|
|
const deviceInternalSensor = {
|
|
|
|
thermostat: 'Thermostat',
|
|
|
|
sensor: 'Sensor',
|
|
|
|
motionSensor: 'Sensor',
|
|
|
|
};
|
|
|
|
const deviceArray = [
|
|
|
|
...Object.values(state.devices),
|
|
|
|
].filter((e) => e.kind in deviceInternalSensor);
|
|
|
|
return deviceArray;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
const SimulationPanelContainer = connect(
|
|
|
|
mapStateToProps,
|
|
|
|
RemoteService,
|
|
|
|
)(SimulationPanel);
|
|
|
|
export default SimulationPanelContainer;
|