diff --git a/front/src/components/boxs/room-humidity/RoomHumidity.jsx b/front/src/components/boxs/room-humidity/RoomHumidity.jsx index 3d6d174d48..1acdab102a 100644 --- a/front/src/components/boxs/room-humidity/RoomHumidity.jsx +++ b/front/src/components/boxs/room-humidity/RoomHumidity.jsx @@ -30,7 +30,7 @@ const RoomHumidityBox = ({ children, ...props }) => ( )} {!isNotNullOrUndefined(props.humidity) && ( - + )} diff --git a/front/src/components/boxs/room-temperature/EditRoomTemperatureBox.jsx b/front/src/components/boxs/room-temperature/EditRoomTemperatureBox.jsx index 0030b1a5c8..d118121bf5 100644 --- a/front/src/components/boxs/room-temperature/EditRoomTemperatureBox.jsx +++ b/front/src/components/boxs/room-temperature/EditRoomTemperatureBox.jsx @@ -2,14 +2,18 @@ import { Component } from 'preact'; import { connect } from 'unistore/preact'; import { Text } from 'preact-i18n'; import BaseEditBox from '../baseEditBox'; +import ReactSlider from 'react-slider'; +import { DEFAULT_VALUE_TEMPERATURE, DEVICE_FEATURE_UNITS } from '../../../../../server/utils/constants'; import RoomSelector from '../../house/RoomSelector'; +import cx from 'classnames'; +import { celsiusToFahrenheit, fahrenheitToCelsius } from '../../../../../server/utils/units'; const updateBoxRoom = (updateBoxRoomFunc, x, y) => room => { updateBoxRoomFunc(x, y, room.selector); }; -const EditRoomTemperatureBox = ({ children, ...props }) => ( +const EditRoomTemperatureBox = ({ children, unit, ...props }) => (
+
+ +
+
+ ( +
+ + +
+ )} + pearling + minDistance={10} + max={unit === DEVICE_FEATURE_UNITS.CELSIUS ? 50 : 122} + min={unit === DEVICE_FEATURE_UNITS.CELSIUS ? -20 : -4} + onAfterChange={props.updateBoxValue} + value={[props.temperatureMin, props.temperatureMax]} + disabled={!(props.box.temperature_use_custom_value || false)} + /> +
); @@ -29,9 +68,63 @@ class EditRoomTemperatureBoxComponent extends Component { room }); }; + + updateBoxUseCustomValue = e => { + this.props.updateBoxConfig(this.props.x, this.props.y, { + temperature_use_custom_value: e.target.checked + }); + }; + + updateBoxValue = values => { + let temperature_min = values[0]; + let temperature_max = values[1]; + + if (this.props.user.temperature_unit_preference === DEVICE_FEATURE_UNITS.FAHRENHEIT) { + temperature_min = fahrenheitToCelsius(temperature_min); + temperature_max = fahrenheitToCelsius(temperature_max); + } + + this.props.updateBoxConfig(this.props.x, this.props.y, { + temperature_min, + temperature_max + }); + }; + render(props, {}) { - return ; + let temperature_min = this.props.box.temperature_min; + let temperature_max = this.props.box.temperature_max; + + const unit = this.props.user.temperature_unit_preference; + + if (!this.props.box.temperature_use_custom_value) { + temperature_min = DEFAULT_VALUE_TEMPERATURE.MINIMUM; + temperature_max = DEFAULT_VALUE_TEMPERATURE.MAXIMUM; + } + + if (isNaN(temperature_min)) { + temperature_min = DEFAULT_VALUE_TEMPERATURE.MINIMUM; + } + if (isNaN(temperature_max)) { + temperature_max = DEFAULT_VALUE_TEMPERATURE.MAXIMUM; + } + + if (this.props.user.temperature_unit_preference === DEVICE_FEATURE_UNITS.FAHRENHEIT) { + temperature_min = celsiusToFahrenheit(temperature_min); + temperature_max = celsiusToFahrenheit(temperature_max); + } + + return ( + + ); } } -export default connect('', {})(EditRoomTemperatureBoxComponent); +export default connect('user', {})(EditRoomTemperatureBoxComponent); diff --git a/front/src/components/boxs/room-temperature/RoomTemperature.jsx b/front/src/components/boxs/room-temperature/RoomTemperature.jsx index 8702b3b58b..db0dd46c91 100644 --- a/front/src/components/boxs/room-temperature/RoomTemperature.jsx +++ b/front/src/components/boxs/room-temperature/RoomTemperature.jsx @@ -5,24 +5,49 @@ import get from 'get-value'; import actions from '../../../actions/dashboard/boxes/temperatureInRoom'; import { DASHBOARD_BOX_STATUS_KEY, DASHBOARD_BOX_DATA_KEY } from '../../../utils/consts'; -import { WEBSOCKET_MESSAGE_TYPES } from '../../../../../server/utils/constants'; +import { + DEFAULT_VALUE_TEMPERATURE, + DEVICE_FEATURE_UNITS, + WEBSOCKET_MESSAGE_TYPES +} from '../../../../../server/utils/constants'; +import { celsiusToFahrenheit } from '../../../../../server/utils/units'; const isNotNullOrUndefined = value => value !== undefined && value !== null; const RoomTemperatureBox = ({ children, ...props }) => (
- - - + {isNotNullOrUndefined(props.temperature) && + props.temperature >= props.temperatureMin && + props.temperature <= props.temperatureMax && ( + + + + )} + {isNotNullOrUndefined(props.temperature) && props.temperature < props.temperatureMin && ( + + + + )} + {isNotNullOrUndefined(props.temperature) && props.temperature > props.temperatureMax && ( + + + + )} + {!isNotNullOrUndefined(props.temperature) && ( + + + + )} +
- {props.valued && ( + {isNotNullOrUndefined(props.temperature) && (

)} - {!props.valued && ( + {!isNotNullOrUndefined(props.temperature) && (

@@ -64,7 +89,29 @@ class RoomTemperatureBoxComponent extends Component { const temperature = get(boxData, 'room.temperature.temperature'); const unit = get(boxData, 'room.temperature.unit'); const roomName = get(boxData, 'room.name'); - const valued = isNotNullOrUndefined(temperature); + + const temperature_use_custom_value = get(props, 'box.temperature_use_custom_value'); + let temperature_min = get(props, 'box.temperature_min'); + let temperature_max = get(props, 'box.temperature_max'); + + if (!temperature_use_custom_value) { + temperature_min = DEFAULT_VALUE_TEMPERATURE.MINIMUM; + temperature_max = DEFAULT_VALUE_TEMPERATURE.MAXIMUM; + } + + if (isNaN(temperature_min)) { + temperature_min = DEFAULT_VALUE_TEMPERATURE.MINIMUM; + } + if (isNaN(temperature_max)) { + temperature_max = DEFAULT_VALUE_TEMPERATURE.MAXIMUM; + } + + console.log('unit', unit); + + if (unit === DEVICE_FEATURE_UNITS.FAHRENHEIT) { + temperature_min = celsiusToFahrenheit(temperature_min); + temperature_max = celsiusToFahrenheit(temperature_min); + } return ( ); } diff --git a/front/src/config/i18n/en.json b/front/src/config/i18n/en.json index 2dc2add5dd..a2eb8c0e49 100644 --- a/front/src/config/i18n/en.json +++ b/front/src/config/i18n/en.json @@ -253,7 +253,8 @@ }, "temperatureInRoom": { "editRoomLabel": "Select the room you want to display here.", - "noTemperatureRecorded": "No temperature recorded recently." + "noTemperatureRecorded": "No temperature recorded recently.", + "thresholdsLabel": "Configure custom thresholds" }, "humidityInRoom": { "editRoomLabel": "Select the room you want to display here.", diff --git a/front/src/config/i18n/fr.json b/front/src/config/i18n/fr.json index 3288aa9514..9f36ee3ee0 100644 --- a/front/src/config/i18n/fr.json +++ b/front/src/config/i18n/fr.json @@ -253,7 +253,8 @@ }, "temperatureInRoom": { "editRoomLabel": "Sélectionnez la pièce que vous souhaitez afficher ici.", - "noTemperatureRecorded": "Aucune température enregistrée récemment." + "noTemperatureRecorded": "Aucune température enregistrée récemment.", + "thresholdsLabel": "Configurer des seuils personnalisés" }, "humidityInRoom": { "editRoomLabel": "Sélectionnez la pièce que vous souhaitez afficher ici.", diff --git a/front/src/style/index.css b/front/src/style/index.css index def1688683..80e315ecf0 100644 --- a/front/src/style/index.css +++ b/front/src/style/index.css @@ -323,7 +323,6 @@ body { font-size: 0.9em; text-align: center; background-color: #fafafa; - #color: white; cursor: pointer; border: 1px solid gray; border-radius: 10px; @@ -358,3 +357,49 @@ body { height: 24px; line-height: 22px; } + + +.temperature-slider { + width: 100%; + max-width: 500px; + height: 30px; +} + +.temperature-slider-thumb { + font-size: 0.9em; + text-align: center; + background-color: #fafafa; + cursor: pointer; + border: 1px solid gray; + border-radius: 10px; + box-sizing: border-box; +} + +.temperature-slider-thumb.active { + border: 1px solid #467fcf; +} + +.temperature-slider-track { + position: relative; + background: #467fcf; +} + +.temperature-slider-track-1 { + background: #5eba00; +} + +.temperature-slider-track-2 { + background: #cd201f; +} + +.temperature-slider .temperature-slider-track { + top: 10px; + height: 10px; +} + +.temperature-slider .temperature-slider-thumb { + top: 3px; + width: 41px; + height: 24px; + line-height: 22px; +} diff --git a/server/models/dashboard.js b/server/models/dashboard.js index e32929342d..3aa17a394f 100644 --- a/server/models/dashboard.js +++ b/server/models/dashboard.js @@ -32,6 +32,9 @@ const boxesSchema = Joi.array().items( humidity_use_custom_value: Joi.boolean(), humidity_min: Joi.number(), humidity_max: Joi.number(), + temperature_use_custom_value: Joi.boolean(), + temperature_min: Joi.number(), + temperature_max: Joi.number(), }), ), ); diff --git a/server/utils/constants.js b/server/utils/constants.js index ab4b91e31d..06d7c44e91 100644 --- a/server/utils/constants.js +++ b/server/utils/constants.js @@ -949,6 +949,11 @@ const DEFAULT_VALUE_HUMIDITY = { MAXIMUM: 60, }; +const DEFAULT_VALUE_TEMPERATURE = { + MINIMUM: 17, + MAXIMUM: 24, +}; + const createList = (obj) => { const list = []; Object.keys(obj).forEach((key) => { @@ -1046,3 +1051,4 @@ module.exports.JOB_ERROR_TYPES = JOB_ERROR_TYPES; module.exports.JOB_ERROR_TYPES_LIST = JOB_ERROR_TYPES_LIST; module.exports.DEFAULT_VALUE_HUMIDITY = DEFAULT_VALUE_HUMIDITY; +module.exports.DEFAULT_VALUE_TEMPERATURE = DEFAULT_VALUE_TEMPERATURE;