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

Improve scene view #649

Merged
merged 36 commits into from
Feb 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
948cf04
Improve scene view by making it vertical
Pierre-Gilles Jan 13, 2020
b164282
Add trigger UI edition
Pierre-Gilles Jan 20, 2020
180b090
Improve display of trigger with units
Pierre-Gilles Jan 20, 2020
0d2d2d5
Use react-select in choose trigger card
Pierre-Gilles Jan 23, 2020
ff27631
Translate add trigger card
Pierre-Gilles Jan 23, 2020
d07d9fb
Migrate triggers to the scene table
Pierre-Gilles Jan 23, 2020
9f12cdb
Fix device.get filtered by name
Pierre-Gilles Jan 23, 2020
793e7fd
Remove trigger table tests
Pierre-Gilles Jan 23, 2020
9d00eda
Remove triggers controllers`
Pierre-Gilles Jan 23, 2020
7529c9f
Translate chooseActionCard and use react-select
Pierre-Gilles Jan 23, 2020
1101203
Improve responsive of device state change trigger card
Pierre-Gilles Jan 23, 2020
2813d5a
Add action icon in config variable
Pierre-Gilles Jan 23, 2020
b715f2a
Display room in device state trigger select
Pierre-Gilles Jan 23, 2020
a5052d2
Improve responsive & sort device feature name
Pierre-Gilles Jan 23, 2020
c442ef7
Delay action box working
Pierre-Gilles Jan 31, 2020
4a13ef4
Telegram card in scene view
Pierre-Gilles Feb 10, 2020
18fb4ea
Add loading state on scene view
Pierre-Gilles Feb 10, 2020
32bf91b
Translate and bugfix delay card
Pierre-Gilles Feb 10, 2020
69f01c8
Translate & make send message work
Pierre-Gilles Feb 10, 2020
69bb557
Add explanation text and placeholder
Pierre-Gilles Feb 10, 2020
93e9b13
Clean actions group if needed
Pierre-Gilles Feb 10, 2020
d71ea7a
Add an error message in case saving the scene fail
Pierre-Gilles Feb 10, 2020
1d835ce
Add all translations
Pierre-Gilles Feb 10, 2020
b75b0db
Fix server-side code for lights.turn-on
Pierre-Gilles Feb 10, 2020
7ef3602
Fix scenes tests
Pierre-Gilles Feb 17, 2020
7ef410e
Remove trigger folder
Pierre-Gilles Feb 17, 2020
2cf7c72
Handle triggers + add tests
Pierre-Gilles Feb 17, 2020
fba52e1
Fix scenes tests
Pierre-Gilles Feb 17, 2020
889ea42
Add listener on EVENTS.ACTION.TRIGGERED
Pierre-Gilles Feb 17, 2020
7fed34c
Improve demo mode
Pierre-Gilles Feb 17, 2020
a8ba1b0
Add test on executeSingleAction
Pierre-Gilles Feb 17, 2020
6d6bcfd
Fix links active state
Pierre-Gilles Feb 17, 2020
0bef0bc
Add send message action + tests
Pierre-Gilles Feb 17, 2020
e119f4f
Add more tests to room.get
Pierre-Gilles Feb 17, 2020
660be1e
Improve code coverage on device.get
Pierre-Gilles Feb 17, 2020
41ca02c
Add more tests on scene.get
Pierre-Gilles Feb 17, 2020
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
323 changes: 294 additions & 29 deletions front/package-lock.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions front/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@
"leaflet": "^1.4.0",
"linkstate": "^1.1.1",
"moment": "^2.24.0",
"preact": "^10.0.5",
"preact": "^10.2.1",
"preact-cli-plugin-fast-async": "^1.0.1",
"preact-i18n": "^2.0.0-preactx.2",
"preact-router": "^3.1.0",
"preact-router": "^3.2.1",
"qrcode": "^1.4.2",
"react-big-calendar": "^0.22.1",
"react-select": "^3.0.8",
"react-stripe-elements": "^5.0.1",
"set-value": "^3.0.0",
"tabler-ui": "0.0.32",
Expand Down
89 changes: 65 additions & 24 deletions front/src/actions/scene.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { RequestStatus } from '../utils/consts';
import update from 'immutability-helper';
import update, { extend } from 'immutability-helper';
import debounce from 'debounce';
import { route } from 'preact-router';

extend('$auto', function(value, object) {
return object ? update(object, value) : update({}, value);
});

function createActions(store) {
const actions = {
async getScenes(state) {
Expand Down Expand Up @@ -49,6 +53,9 @@ function createActions(store) {
if (scene.actions[scene.actions.length - 1].length > 0) {
scene.actions.push([]);
}
if (!scene.triggers) {
scene.triggers = [];
}
store.setState({
scene,
SceneGetStatus: RequestStatus.Success
Expand All @@ -75,31 +82,16 @@ function createActions(store) {
}
},
async saveScene(state) {
store.setState({
SceneSaveStatus: RequestStatus.Getting
});
try {
await state.httpClient.patch(`/api/v1/scene/${state.scene.selector}`, state.scene);
store.setState({
SceneSaveStatus: RequestStatus.Success
});
} catch (e) {
store.setState({
SceneSaveStatus: RequestStatus.Error
});
}
await state.httpClient.patch(`/api/v1/scene/${state.scene.selector}`, state.scene);
},
addAction(state, columnIndex) {
if (!state.selectedNewAction) {
return null;
}
let newState = update(state, {
scene: {
actions: {
[columnIndex]: {
$push: [
{
type: state.selectedNewAction
type: null
}
]
}
Expand All @@ -118,7 +110,7 @@ function createActions(store) {
store.setState(newState);
},
deleteAction(state, columnIndex, rowIndex) {
const newState = update(state, {
let newState = update(state, {
scene: {
actions: {
[columnIndex]: {
Expand All @@ -127,6 +119,21 @@ function createActions(store) {
}
}
});
// if necessary, we remove the last action group
if (newState.scene.actions.length >= 2) {
if (
newState.scene.actions[newState.scene.actions.length - 1].length === 0 &&
newState.scene.actions[newState.scene.actions.length - 2].length === 0
) {
newState = update(newState, {
scene: {
actions: {
$splice: [[newState.scene.actions.length - 1, 1]]
}
}
});
}
}
store.setState(newState);
},
updateActionProperty(state, columnIndex, rowIndex, property, value) {
Expand All @@ -145,11 +152,6 @@ function createActions(store) {
});
store.setState(newState);
},
updateSelectedNewAction(state, e) {
store.setState({
selectedNewAction: e.target.value
});
},
highlighCurrentlyExecutedAction(state, { columnIndex, rowIndex }) {
store.setState({
highLightedActions: {
Expand Down Expand Up @@ -200,6 +202,45 @@ function createActions(store) {
GetUsersStatus: RequestStatus.Error
});
}
},
addTrigger(state) {
const newState = update(state, {
scene: {
triggers: {
$push: [
{
type: null
}
]
}
}
});
store.setState(newState);
},
deleteTrigger(state, index) {
const newState = update(state, {
scene: {
triggers: {
$splice: [[index, 1]]
}
}
});
store.setState(newState);
},
updateTriggerProperty(state, index, property, value) {
console.log({ index, property, value });
const newState = update(state, {
scene: {
triggers: {
[index]: {
[property]: {
$set: value
}
}
}
}
});
store.setState(newState);
}
};
actions.debouncedSearch = debounce(actions.search, 200);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const BinaryDeviceType = ({ children, ...props }) => {
props.deviceFeature,
props.deviceIndex,
props.deviceFeatureIndex,
!props.deviceFeature.last_value
props.deviceFeature.last_value === 0 ? 1 : 0
);
}

Expand Down
37 changes: 26 additions & 11 deletions front/src/components/header/index.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Text } from 'preact-i18n';
import classnames from 'classnames';
import { h } from 'preact';
import { Link } from 'preact-router/match';
import { isUrlInArray } from '../../utils/url';
Expand Down Expand Up @@ -80,22 +81,25 @@ const Header = ({ ...props }) => {
<div class="col-lg order-lg-first">
<ul class="nav nav-tabs border-0 flex-column flex-lg-row">
<li class="nav-item">
<Link activeClassName="active" href="/dashboard" class="nav-link">
<Link
href="/dashboard"
class={classnames('nav-link', {
active: props.currentUrl === '/dashboard'
})}
>
<i class="fe fe-home" /> <Text id="header.home" />
</Link>
</li>
<li class="nav-item">
<Link activeClassName="active" href="/dashboard/chat" class="nav-link">
<Link
href="/dashboard/chat"
class={classnames('nav-link', {
active: props.currentUrl === '/dashboard/chat'
})}
>
<i class="fe fe-message-square" /> <Text id="header.chat" />
</Link>
</li>
{false && (
<li class="nav-item">
<Link activeClassName="active" href="/dashboard/device" class="nav-link">
<i class="fe fe-toggle-right" /> <Text id="header.devices" />
</Link>
</li>
)}
<li class="nav-item">
<Link
href="/dashboard/integration/device"
Expand All @@ -105,12 +109,23 @@ const Header = ({ ...props }) => {
</Link>
</li>
<li class="nav-item">
<Link activeClassName="active" href="/dashboard/calendar" class="nav-link">
<Link
href="/dashboard/calendar"
class={classnames('nav-link', {
active: props.currentUrl === '/dashboard/calendar'
})}
>
<i class="fe fe-calendar" /> <Text id="header.calendar" />
</Link>
</li>
<li class="nav-item">
<Link activeClassName="active" href="/dashboard/maps" class="nav-link">
<Link
activeClassName="active"
href="/dashboard/maps"
class={classnames('nav-link', {
active: props.currentUrl === '/dashboard/maps'
})}
>
<i class="fe fe-map" /> <Text id="header.maps" />
</Link>
</li>
Expand Down
43 changes: 33 additions & 10 deletions front/src/config/demo.json
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@
"features": [
{
"name": "Temperature",
"selector": "main-lamp-binary",
"selector": "temperature-sensor",
"category": "temperature-sensor",
"type": "",
"min": -20,
Expand All @@ -350,7 +350,7 @@
},
{
"name": "Humidity",
"selector": "main-lamp-binary",
"selector": "humidity-sensor",
"category": "humidity-sensor",
"type": "",
"min": 0,
Expand All @@ -362,7 +362,7 @@
},
{
"name": "Door",
"selector": "main-lamp-binary",
"selector": "door-opening-sensor",
"category": "door-opening-sensor",
"type": "",
"min": 0,
Expand All @@ -387,7 +387,7 @@
"features": [
{
"name": "Humidity",
"selector": "main-lamp-binary",
"selector": "kitchen-humidity-sensor",
"category": "humidity-sensor",
"type": "",
"min": 0,
Expand All @@ -400,8 +400,8 @@
{
"name": "Light",
"selector": "main-lamp-binary",
"category": "light-sensor",
"type": "",
"category": "light",
"type": "binary",
"min": 0,
"max": 100,
"read_only": true,
Expand Down Expand Up @@ -495,18 +495,26 @@
"selector": "wake-up",
"icon": "fe fe-bell",
"name": "Wake Up",
"triggers": [
{
"type": "device.new-state",
"device_feature": "main-lamp-binary",
"operator": "=",
"value": 1
}
],
"actions": [
[
{
"type": "delay",
"seconds": 2
"value": 2,
"unit": "seconds"
}
],
[
{
"type": "telegram.send",
"user": "tony",
"text": "Time to wake up!"
"type": "light.turn-on",
"devices": ["light"]
}
]
]
Expand Down Expand Up @@ -950,6 +958,21 @@
]
}
],
"get /api/v1/device": [
{
"id": "06e735a3-ac62-4a05-85b6-855f2c556d7b",
"name": "Living room lamp",
"selector": "light",
"features": [
{
"name": "Living room lamp",
"type": "binary",
"selector": "light.binary",
"category": "light"
}
]
}
],
"get /api/v1/service/xiaomi": {
"id": "70cb1e17-3b17-4886-83ab-45b00a9e03b1",
"name": "Xiaomi",
Expand Down
Loading