points 2,3,4

This commit is contained in:
britea 2020-05-05 15:53:07 +02:00
parent af7d93b44a
commit 246fdb1de8
4 changed files with 62 additions and 2 deletions

View File

@ -1,5 +1,12 @@
import React from "react"; import React from "react";
import { Grid, Divider, Button, Label, Responsive } from "semantic-ui-react"; import {
Grid,
Divider,
Button,
Label,
Responsive,
Checkbox,
} from "semantic-ui-react";
import { Segment, Image } from "semantic-ui-react"; import { Segment, Image } from "semantic-ui-react";
import { RemoteService } from "../remote"; import { RemoteService } from "../remote";
import { withRouter } from "react-router-dom"; import { withRouter } from "react-router-dom";
@ -35,6 +42,16 @@ export class MyHeader extends React.Component {
.catch((err) => console.error("MyHeader fetch user info error", err)); .catch((err) => console.error("MyHeader fetch user info error", err));
} }
setCameraEnabled(val) {
let enabled = {
cameraEnabled: val,
};
this.props
.userPermissions(enabled)
.then(() => this.getInfo())
.catch((err) => console.error("Camera enabled", err));
}
render() { render() {
return ( return (
<div> <div>
@ -60,6 +77,11 @@ export class MyHeader extends React.Component {
<Button basic inverted onClick={this.logout}> <Button basic inverted onClick={this.logout}>
Logout Logout
</Button> </Button>
<Checkbox
checked={this.props.cameraEnabled}
toggle
onChange={(e, val) => this.setCameraEnabled(val.checked)}
/>
</Grid.Column> </Grid.Column>
</Grid.Row> </Grid.Row>
</Grid> </Grid>
@ -94,6 +116,7 @@ export class MyHeader extends React.Component {
const mapStateToProps = (state, _) => ({ const mapStateToProps = (state, _) => ({
username: username:
state.userInfo && state.userInfo.username ? state.userInfo.username : "", state.userInfo && state.userInfo.username ? state.userInfo.username : "",
cameraEnabled: state.userInfo ? state.userInfo.cameraEnabled : false,
}); });
const LoginContainer = connect( const LoginContainer = connect(
mapStateToProps, mapStateToProps,

View File

@ -8,6 +8,7 @@ import {
Form, Form,
Input, Input,
Dropdown, Dropdown,
Checkbox,
} from "semantic-ui-react"; } from "semantic-ui-react";
import SelectIcons from "./SelectIcons"; import SelectIcons from "./SelectIcons";
import { connect } from "react-redux"; import { connect } from "react-redux";
@ -23,6 +24,7 @@ class SceneModal extends Component {
this.modifySceneModal = this.modifySceneModal.bind(this); this.modifySceneModal = this.modifySceneModal.bind(this);
this.deleteScene = this.deleteScene.bind(this); this.deleteScene = this.deleteScene.bind(this);
this.updateIcon = this.updateIcon.bind(this); this.updateIcon = this.updateIcon.bind(this);
this.setGuestAccessEnabled = this.setGuestAccessEnabled.bind(this);
this.setCopyFrom = this.setCopyFrom.bind(this); this.setCopyFrom = this.setCopyFrom.bind(this);
} }
@ -41,6 +43,8 @@ class SceneModal extends Component {
selectedIcon: "home", selectedIcon: "home",
scenes: this.scenes, scenes: this.scenes,
copyFrom: null, copyFrom: null,
guestAccessEnabled:
this.type === "new" ? null : this.props.scene.guestAccessEnabled,
}; };
} }
@ -79,7 +83,9 @@ class SceneModal extends Component {
let data = { let data = {
name: this.state.name, name: this.state.name,
icon: this.state.selectedIcon, icon: this.state.selectedIcon,
guestAccessEnabled: this.state.guestAccessEnabled,
}; };
console.log(data);
this.props this.props
.saveScene(data, this.props.id) .saveScene(data, this.props.id)
@ -119,6 +125,11 @@ class SceneModal extends Component {
this.setState({ ...this.state, copyFrom: copyFrom.value }); this.setState({ ...this.state, copyFrom: copyFrom.value });
} }
setGuestAccessEnabled(val) {
console.log(this.state, val);
this.setState({ guestAccessEnabled: val });
}
render() { render() {
const spaceDiv = { const spaceDiv = {
background: "#f4f4f4", background: "#f4f4f4",
@ -210,6 +221,17 @@ class SceneModal extends Component {
/> />
</Form.Field> </Form.Field>
)} )}
{this.type === "modify" ? (
<Form.Field>
<Checkbox
checked={this.state.guestAccessEnabled}
toggle
onChange={(e, val) =>
this.setGuestAccessEnabled(val.checked)
}
/>
</Form.Field>
) : null}
</Form> </Form>
{this.type === "modify" ? ( {this.type === "modify" ? (

View File

@ -31,7 +31,7 @@ class Videocam extends Component {
setOnOff(onOff) { setOnOff(onOff) {
const turn = onOff; const turn = onOff;
if (this.props.tab === "Devices") { if (this.props.tab === "Devices" || this.props.tab === "Hosts") {
this.props this.props
.saveDevice({ ...this.props.device, on: turn }) .saveDevice({ ...this.props.device, on: turn })
.then((res) => .then((res) =>

View File

@ -242,6 +242,20 @@ export const RemoteService = {
}); });
}, },
/**
* Fetches user information via REST calls, if it is logged in
* @returns {Promise<Undefined, RemoteError>} promise that resolves to void and rejects
* with user-fiendly errors as a RemoteError
*/
userPermissions: (data) => {
return (dispatch) => {
return Endpoint.put("/user/permissions", {}, data).catch((err) => {
console.warn("Fetch user info error", err);
throw new RemoteError(["Network error"]);
});
};
},
/** /**
* Fetches user information via REST calls, if it is logged in * Fetches user information via REST calls, if it is logged in
* @returns {Promise<Undefined, RemoteError>} promise that resolves to void and rejects * @returns {Promise<Undefined, RemoteError>} promise that resolves to void and rejects
@ -458,6 +472,7 @@ export const RemoteService = {
data = { data = {
name: data.name, name: data.name,
icon: data.icon, icon: data.icon,
guestAccessEnabled: sceneId ? data.guestAccessEnabled : false,
}; };
return (sceneId return (sceneId