Merge branch '48-add-update-lights' into 'dev'
added update on lights Closes #48 See merge request sa4-2020/the-sanmarinoes/frontend!49
This commit is contained in:
commit
52b1e12d73
7 changed files with 29 additions and 11 deletions
|
@ -31,8 +31,12 @@ class App extends Component {
|
|||
let userJsonString = localStorage.getItem("token");
|
||||
let exp = localStorage.getItem("exp");
|
||||
let date = new Date().getTime();
|
||||
console.log(exp > date, date)
|
||||
if (userJsonString && exp && date < exp) {
|
||||
loggedIn = true;
|
||||
} else {
|
||||
localStorage.removeItem("token");
|
||||
localStorage.removeItem("exp");
|
||||
}
|
||||
}catch(exception) {
|
||||
|
||||
|
@ -64,8 +68,9 @@ class App extends Component {
|
|||
return call.login(data.params)
|
||||
.then(res => {
|
||||
if (res.data && res.status === 200) {
|
||||
let expire = new Date().getTime()+60*60*5*1000;
|
||||
localStorage.setItem("token", res.data.jwttoken);
|
||||
localStorage.setItem("exp", new Date().getTime() + (60*60*5))
|
||||
localStorage.setItem("exp", expire)
|
||||
call.setToken(res.data.jwttoken);
|
||||
this.setState(
|
||||
{
|
||||
|
@ -94,6 +99,7 @@ class App extends Component {
|
|||
});
|
||||
|
||||
localStorage.removeItem("token");
|
||||
localStorage.removeItem("exp");
|
||||
};
|
||||
|
||||
render() {
|
||||
|
|
|
@ -94,6 +94,7 @@ export default class DevicePanel extends Component {
|
|||
console.log(roomId)
|
||||
data["id"] = this.state.settingsDeviceId;
|
||||
data["roomId"] = roomId;
|
||||
console.log(data);
|
||||
call.deviceUpdate(data)
|
||||
.then(res => {
|
||||
if (res.status === 200) {
|
||||
|
|
|
@ -8,7 +8,7 @@ import Switcher from "./Switch";
|
|||
|
||||
const DeviceType = (props) => {
|
||||
switch(props.type) {
|
||||
case "regular-light":
|
||||
case "regularLight":
|
||||
return (<Light onChangeData={props.changeDeviceData} device={props.device} edit={props.edit} />)
|
||||
case "sensor":
|
||||
return <Sensor onChangeData={props.changeDeviceData} device={props.device} edit={props.edit} />
|
||||
|
@ -18,7 +18,7 @@ const DeviceType = (props) => {
|
|||
return <SmartPlug onChangeData={props.changeDeviceData} device={props.device} edit={props.edit} />
|
||||
case "switch":
|
||||
return <Switcher onChangeData={props.changeDeviceData} device={props.device} edit={props.edit} />
|
||||
case "light":
|
||||
case "dimmableLight":
|
||||
return (<Light onChangeData={props.changeDeviceData} device={props.device} edit={props.edit} />)
|
||||
default:
|
||||
return ""
|
||||
|
|
|
@ -25,11 +25,17 @@ export default class Light extends Component {
|
|||
}
|
||||
|
||||
onClickDevice = () => {
|
||||
this.setState((prevState) => ({turnedOn: !prevState.turnedOn}));
|
||||
this.props.device.on = !this.state.turnedOn;
|
||||
call.deviceUpdate(this.props.device, 'regularLight')
|
||||
.then(res => {
|
||||
if (res.status === 200 ){
|
||||
this.setState((prevState) => ({turnedOn: !prevState.turnedOn}));
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
setIntensity = (newValue) => {
|
||||
this.props.device.intensity = Math.round(newValue) <= 1 ? 1 : Math.round(newValue );
|
||||
this.props.device.intensity = Math.round(newValue * 100) <= 1 ? 1 : Math.round(newValue * 100);
|
||||
console.log(this.props.device.intensity)
|
||||
call.deviceUpdate(this.props.device, 'dimmableLight')
|
||||
.then(res => {
|
||||
|
@ -52,6 +58,9 @@ export default class Light extends Component {
|
|||
intensity: this.props.device.intensity
|
||||
});
|
||||
}
|
||||
this.setState({
|
||||
turnedOn: this.props.device.on
|
||||
});
|
||||
// Get the state and update it
|
||||
|
||||
}
|
||||
|
@ -60,7 +69,7 @@ export default class Light extends Component {
|
|||
render() {
|
||||
const intensityLightView = (
|
||||
<CircularInput
|
||||
value={this.props.device.intensity}
|
||||
value={Math.round(this.props.device.intensity/100)}
|
||||
onChange={this.setIntensity}
|
||||
style={style}
|
||||
>
|
||||
|
|
|
@ -108,12 +108,12 @@ export default class ModalWindow extends Component {
|
|||
<p>Insert the name of the room:</p>
|
||||
<Form.Field>
|
||||
<Input label='Room name' placeholder='Room Name' name="name" type='text' onChange={this.changeSomething}
|
||||
value={this.props.type === "new" && this.props.idRoom !== -1 ? null : this.props.idRoom.name }/>
|
||||
value={this.props.type === "new" && this.props.idRoom !== -1 ? "" : "" }/>
|
||||
</Form.Field>
|
||||
<p>Insert an image of the room:</p>
|
||||
<Form.Field>
|
||||
<Input label='Room image' type='file' name="img" onChange={this.changeSomething}
|
||||
value={this.props.type === "new" && this.props.idRoom !== -1 ? null : this.props.idRoom.images }/>
|
||||
value={this.props.type === "new" && this.props.idRoom !== -1 ? "" : this.props.idRoom.images }/>
|
||||
</Form.Field>
|
||||
</Form>
|
||||
|
||||
|
@ -126,7 +126,7 @@ export default class ModalWindow extends Component {
|
|||
<Button icon labelPosition='left' inverted color='red' onClick={this.deleteRoom}>
|
||||
<Icon name='trash alternate' />
|
||||
Delete room
|
||||
</Button> : null }
|
||||
</Button> : "" }
|
||||
|
||||
</Modal.Content>
|
||||
<Modal.Actions>
|
||||
|
|
|
@ -36,6 +36,7 @@ export default class Dashboard extends Component{
|
|||
call.getAllDevices()
|
||||
.then(res => {
|
||||
if ( res.status === 200) {
|
||||
console.log(res.data)
|
||||
this.setState({
|
||||
devices: res.data
|
||||
});
|
||||
|
|
|
@ -120,6 +120,7 @@ class Navbar extends Component {
|
|||
|
||||
<Dropdown.Item
|
||||
key={-1}
|
||||
id={-1}
|
||||
name='Home'
|
||||
active={this.state.activeItem === 'Home'}
|
||||
onClick={this.handleClick}>
|
||||
|
@ -168,10 +169,10 @@ class Navbar extends Component {
|
|||
<Grid>
|
||||
<Grid.Row>
|
||||
<Grid.Column width={8}>
|
||||
<ModalWindow type="new" idRoom={this.state.activeItem === -1? -1 : this.state.activeRoom} updateRoom={this.props.updateRoom} deleteRoom={this.props.deleteRoom}/>
|
||||
<ModalWindow type="new" idRoom={this.state.activeRoom} updateRoom={this.props.updateRoom} deleteRoom={this.props.deleteRoom}/>
|
||||
</Grid.Column>
|
||||
<Grid.Column width={8}>
|
||||
<ModalWindow type="modify" idRoom={this.state.activeItem === -1? -1 : this.state.activeRoom} updateRoom={this.props.updateRoom} deleteRoom={this.props.deleteRoom}/>
|
||||
<ModalWindow type="modify" idRoom={this.state.activeRoom} updateRoom={this.props.updateRoom} deleteRoom={this.props.deleteRoom}/>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
</Grid>
|
||||
|
|
Loading…
Reference in a new issue