Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1277: Should be able to slide brightness on a touchscreen #1284

Merged
merged 7 commits into from
Sep 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions front/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion front/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
},
"dependencies": {
"@gladysassistant/gladys-gateway-js": "^3.5.0",
"@gladysassistant/theme-optimized": "^1.0.2",
"@gladysassistant/theme-optimized": "^1.0.3",
"@jaames/iro": "^5.5.2",
"@yaireo/tagify": "^4.5.0",
"axios": "^0.21.1",
Expand Down
35 changes: 34 additions & 1 deletion front/src/actions/dashboard/boxes/devicesInRoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import createBoxActions from '../boxActions';
import createDeviceActions from '../../device';
import update from 'immutability-helper';
import get from 'get-value';
import debounce from 'debounce';
const { DEVICE_FEATURE_TYPES, DEVICE_FEATURE_CATEGORIES } = require('../../../../../server/utils/constants');

const BOX_KEY = 'DevicesInRoom';
Expand Down Expand Up @@ -76,8 +77,38 @@ function createActions(store) {
});
await Promise.all(promises);
},
async setValueDevice(state, deviceFeatureSelector, action) {
await deviceActions.setValue(state, deviceFeatureSelector, action);
},
async updateValueWithDebounce(state, x, y, device, deviceFeature, deviceIndex, featureIndex, action) {
const data = boxActions.getBoxData(state, BOX_KEY, x, y);
const newData = update(data, {
room: {
devices: {
[deviceIndex]: {
features: {
[featureIndex]: {
last_value: {
$set: action
},
last_value_changed: {
$set: new Date()
}
}
}
}
}
}
});
const { hasBinaryLightDeviceFeature, roomLightStatus } = getLightStatus(newData.room);
boxActions.mergeBoxData(state, BOX_KEY, x, y, {
room: newData.room,
hasBinaryLightDeviceFeature,
roomLightStatus
});
await actions.setValueDeviceDebounce(state, deviceFeature.selector, action);
},
async updateValue(state, x, y, device, deviceFeature, deviceIndex, featureIndex, action) {
await deviceActions.setValue(state, deviceFeature.selector, action);
const data = boxActions.getBoxData(state, BOX_KEY, x, y);
const newData = update(data, {
room: {
Expand All @@ -103,6 +134,7 @@ function createActions(store) {
hasBinaryLightDeviceFeature,
roomLightStatus
});
await deviceActions.setValue(state, deviceFeature.selector, action);
},
deviceFeatureWebsocketEvent(state, x, y, payload) {
const data = boxActions.getBoxData(state, BOX_KEY, x, y);
Expand Down Expand Up @@ -150,6 +182,7 @@ function createActions(store) {
}
}
};
actions.setValueDeviceDebounce = debounce(actions.setValueDevice, 500);
return Object.assign({}, actions, boxActions);
}

Expand Down
8 changes: 7 additions & 1 deletion front/src/components/boxs/device-in-room/DeviceList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ import RoomCard from './RoomCard';
const DeviceList = ({ children, ...props }) => (
<div class="card-columns">
{props.rooms.map((room, index) => (
<RoomCard room={room} roomIndex={index} updateValue={props.updateValue} collapseRoom={props.collapseRoom} />
<RoomCard
room={room}
roomIndex={index}
updateValue={props.updateValue}
updateValueWithDebounce={props.updateValueWithDebounce}
collapseRoom={props.collapseRoom}
/>
))}
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ import get from 'get-value';

import DeviceRow from './DeviceRow';

const cardStyle = {
maxHeight: '20rem'
};

const minHeight = {
minHeight: '6rem'
};
Expand Down Expand Up @@ -42,14 +38,14 @@ const RoomCard = ({ children, ...props }) => {
)}
</div>
{props.loading && (
<div class="card-body o-auto" style={cardStyle}>
<div class="card-body o-auto">
<div class={props.loading ? 'dimmer active' : 'dimmer'}>
<div class="loader" />
<div class="dimmer-content">{props.loading && <div style={minHeight} />}</div>
</div>
</div>
)}
<div class="table-responsive" style={cardStyle}>
<div class="table-responsive">
<table class="table card-table table-vcenter">
<tbody>
{props.devices &&
Expand All @@ -69,6 +65,7 @@ const RoomCard = ({ children, ...props }) => {
deviceIndex={deviceIndex}
deviceFeatureIndex={deviceFeatureIndex}
updateValue={props.updateValue}
updateValueWithDebounce={props.updateValueWithDebounce}
/>
)
)
Expand Down
1 change: 1 addition & 0 deletions front/src/components/boxs/device-in-room/RoomCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const RoomCard = ({ children, ...props }) => {
deviceIndex={deviceIndex}
deviceFeatureIndex={deviceFeatureIndex}
updateValue={props.updateValue}
updateValueWithDebounce={props.updateValueWithDebounce}
/>
))
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { getDeviceName } from './utils';

const LightTemperatureDeviceType = ({ children, ...props }) => {
function updateValue(e) {
props.updateValue(
props.updateValueWithDebounce(
props.x,
props.y,
props.device,
Expand Down Expand Up @@ -30,7 +30,7 @@ const LightTemperatureDeviceType = ({ children, ...props }) => {
type="range"
value={props.deviceFeature.last_value}
onChange={updateValue}
class="form-control custom-range light-temperature"
class="custom-range light-temperature"
step="1"
min={props.deviceFeature.min}
max={props.deviceFeature.max}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { DeviceFeatureCategoriesIcon } from '../../../../utils/consts';

const MultiLevelDeviceType = ({ children, ...props }) => {
function updateValue(e) {
props.updateValue(
props.updateValueWithDebounce(
props.x,
props.y,
props.device,
Expand Down Expand Up @@ -39,7 +39,7 @@ const MultiLevelDeviceType = ({ children, ...props }) => {
type="range"
value={props.deviceFeature.last_value}
onChange={updateValue}
class="form-control custom-range"
class="custom-range"
step="1"
min={props.deviceFeature.min}
max={props.deviceFeature.max}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
.deviceRowPopover {
top: auto;
top: auto;
}

/* Chrome */
input[type=range][class~=light-temperature]::-webkit-slider-runnable-track {
background: linear-gradient(to right, rgb(178, 212, 251), rgb(243, 166, 60));
input[type='range'][class~='light-temperature']::-webkit-slider-runnable-track {
background: linear-gradient(to right, rgb(178, 212, 251), rgb(243, 166, 60));
}

/* Firefox */
input[type=range][class~=light-temperature]::-moz-range-progress {
background: linear-gradient(to right, rgb(178, 212, 251), rgb(243, 166, 60));
input[type='range'][class~='light-temperature']::-moz-range-progress {
background: linear-gradient(to right, rgb(178, 212, 251), rgb(243, 166, 60));
}

/* Edge */
input[type=range][class~=light-temperature]::-ms-fill-lower {
background: linear-gradient(to right, rgb(178, 212, 251), rgb(243, 166, 60));
}
input[type='range'][class~='light-temperature']::-ms-fill-lower {
background: linear-gradient(to right, rgb(178, 212, 251), rgb(243, 166, 60));
}