Merge branch '103-temperature-sensor-color-circle-change-with-temperature-value' into 'dev'

Resolve "temperature sensor - color circle change with temperature value"

Closes #103

See merge request sa4-2020/the-sanmarinoes/frontend!131
This commit is contained in:
Claudio Maggioni 2020-05-08 15:41:46 +02:00
commit 3132204872
6 changed files with 85 additions and 12170 deletions

View file

@ -94,12 +94,12 @@ class RoomModal extends Component {
}; };
setSureTrue = () => { setSureTrue = () => {
this.setState({sure: true}) this.setState({ sure: true });
} };
setSureFalse = () => { setSureFalse = () => {
this.setState({sure: false}) this.setState({ sure: false });
} };
changeSomething = (event) => { changeSomething = (event) => {
let nam = event.target.name; let nam = event.target.name;
@ -239,13 +239,14 @@ class RoomModal extends Component {
onClick={this.setSureTrue} onClick={this.setSureTrue}
> >
<Icon name="trash alternate" /> <Icon name="trash alternate" />
Delete Room </Button> Delete Room{" "}
</Button>
<Confirm <Confirm
open={this.state.sure} open={this.state.sure}
onCancel={this.setSureFalse} onCancel={this.setSureFalse}
onConfirm={this.deleteRoom}/> onConfirm={this.deleteRoom}
/>
</div> </div>
) : null} ) : null}
</Modal.Content> </Modal.Content>
<Modal.Actions> <Modal.Actions>

View file

@ -141,9 +141,13 @@ class NewDevice extends Component {
case "buttonDimmer": case "buttonDimmer":
case "knobDimmer": case "knobDimmer":
outputs = this.state.lightsAttached; outputs = this.state.lightsAttached;
if (this.state.lightsAttached === undefined || if (
this.state.lightsAttached.length === 0) { this.state.lightsAttached === undefined ||
alert("No lights attached to this switch! Please, add a light a first."); this.state.lightsAttached.length === 0
) {
alert(
"No lights attached to this switch! Please, add a light a first."
);
return; return;
} }
break; break;
@ -165,11 +169,17 @@ class NewDevice extends Component {
render() { render() {
const deviceOptions = [ const deviceOptions = [
//stuff //stuff
{ key: "thermostat", text: "Thermostat", value: "thermostat", {
image: {avatar: true, src: "/img/thermostat-icon.png"} key: "thermostat",
text: "Thermostat",
value: "thermostat",
image: { avatar: true, src: "/img/thermostat-icon.png" },
}, },
{ key: "curtains", text: "Curtain", value: "curtains", {
image: {avatar: true, src: "/img/curtains-icon.png"} key: "curtains",
text: "Curtain",
value: "curtains",
image: { avatar: true, src: "/img/curtains-icon.png" },
}, },
//stuff ends //stuff ends
{ {

View file

@ -123,6 +123,18 @@ class Sensor extends Component {
return this.iconOff; return this.iconOff;
}; };
temperatureColor = (value) => {
let hue = 100;
const min = 16;
const max = 20;
if (value >= min && value < max) {
hue = 100 - ((value - min) * 100) / (max - min);
} else if (value >= max) {
hue = 0;
}
return `hsl(${hue}, 100%, 50%)`;
};
render() { render() {
const MotionSensor = (props) => { const MotionSensor = (props) => {
return ( return (
@ -161,11 +173,18 @@ class Sensor extends Component {
> >
<CircularProgress <CircularProgress
strokeWidth="2rem" strokeWidth="2rem"
stroke={this.colors.progress} stroke={
this.props.stateOrDevice.sensor === "TEMPERATURE"
? this.temperatureColor(this.state.value)
: this.colors.progress
}
fill={this.colors.circle} fill={this.colors.circle}
/> />
<text <text
style={{ ...valueStyle, fill: this.colors.text }} style={{
...valueStyle,
fill: this.colors.text,
}}
x={100} x={100}
y={110} y={110}
textAnchor="middle" textAnchor="middle"
@ -177,7 +196,10 @@ class Sensor extends Component {
{this.units} {this.units}
</text> </text>
<text <text
style={{ ...sensorText, fill: this.colors.text }} style={{
...sensorText,
fill: this.colors.text,
}}
x={100} x={100}
y={150} y={150}
textAnchor="middle" textAnchor="middle"

View file

@ -8,10 +8,7 @@ import ScenesNavbar from "./ScenesNavbar";
import HostsNavbar from "./HostsNavbar"; import HostsNavbar from "./HostsNavbar";
import MyHeader from "../components/HeaderController"; import MyHeader from "../components/HeaderController";
import { Grid, Responsive, Button, Menu } from "semantic-ui-react"; import { Grid, Responsive, Button, Menu } from "semantic-ui-react";
import { import { mobilePanelStyle } from "../components/dashboard/devices/styleComponents";
panelStyle,
mobilePanelStyle,
} from "../components/dashboard/devices/styleComponents";
import { RemoteService } from "../remote"; import { RemoteService } from "../remote";
import { connect } from "react-redux"; import { connect } from "react-redux";
@ -85,7 +82,7 @@ class Dashboard extends Component {
//in case a room has one. //in case a room has one.
let backgroundImageHelper; let backgroundImageHelper;
if (this.activeTab === "Devices") { if (this.activeTab === "Devices") {
backgroundImageHelper=this.props.allRooms; backgroundImageHelper = this.props.backgroundImage;
} else { } else {
backgroundImageHelper = null; backgroundImageHelper = null;
} }
@ -135,15 +132,19 @@ class Dashboard extends Component {
</Grid.Column> </Grid.Column>
)} )}
<Grid.Column width={this.hasNavbar ? 13 : 16}> <Grid.Column width={this.hasNavbar ? 13 : 16}>
<div style={ <div
{backgroundImage:"url("+ backgroundImageHelper+")", style={{
backgroundImage: "url(" + backgroundImageHelper + ")",
backgroundColor: "#fafafa", backgroundColor: "#fafafa",
height: "85vh", height: "85vh",
padding: "0rem 3rem", padding: "0rem 3rem",
color: "#000000", color: "#000000",
overflow: "auto", overflow: "auto",
maxHeight: "75vh",} maxHeight: "75vh",
}>{this.renderTab(this.activeTab)}</div> }}
>
{this.renderTab(this.activeTab)}
</div>
</Grid.Column> </Grid.Column>
</Grid.Row> </Grid.Row>
</Grid> </Grid>
@ -219,23 +220,13 @@ const mapStateToProps = (state, _) => ({
get currentRoom() { get currentRoom() {
return state.active.activeRoom; return state.active.activeRoom;
}, },
//this took me way longer to figure out than it should have get backgroundImage() {
get allRooms(){ if (state.active.activeRoom === -1) {
if(state.active.activeRoom==-1){
return null;
}
for(let i in state.rooms){
if(i==state.active.activeRoom){
//console.log("check",state.rooms[i].image)
if(state.rooms[i].image===undefined){
return null; return null;
} else { } else {
return state.rooms[i].image; return state.rooms[state.active.activeRoom].image;
}
}
} }
}, },
}); });
const setActiveTab = (activeTab) => { const setActiveTab = (activeTab) => {

File diff suppressed because it is too large Load diff

4
yarn.lock Normal file
View file

@ -0,0 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1