From 1abfc14fff9c94a4022fae6232a8feee235a8b3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Ch=C5=82odnicki?= Date: Sun, 18 Oct 2020 22:16:47 +0200 Subject: [PATCH 1/3] fix(LIGHT): show color picker based on feature check This is a behavior change since now even if the user doesn't define sliders and light supports color change then picker will still show up on long press. We maybe should leave support for "item.colorpicker" to be able to override it to "false" but not sure if it's worth it. --- README.md | 5 ----- TILE_EXAMPLES.md | 1 - index.html.ejs | 2 +- scripts/controllers/main.js | 2 +- scripts/globals/constants.js | 7 +++++++ 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index e3d87cf3..8447bf7d 100644 --- a/README.md +++ b/README.md @@ -357,11 +357,6 @@ Tile Object. [Click here for some real-life examples](TILE_EXAMPLES.md) /* sliders: list of slider object. See slider documentation below */ sliders: [{}], - /* colorpicker: whether or not the color picker should be used. - * Only works with lights that have the rgb_color attribute - * Valid options: true, false - */ - colorpicker: true, /** type: POPUP_IFRAME **/ url: String || Function, /* optional */ diff --git a/TILE_EXAMPLES.md b/TILE_EXAMPLES.md index a4bbfc95..7262a974 100644 --- a/TILE_EXAMPLES.md +++ b/TILE_EXAMPLES.md @@ -414,7 +414,6 @@ Light switch. You can optionally define sliders to control colour temperature or } } ], - colorpicker: true } ``` diff --git a/index.html.ejs b/index.html.ejs index b24931f9..91229936 100644 --- a/index.html.ejs +++ b/index.html.ejs @@ -582,7 +582,7 @@ -
+
Color: Date: Mon, 19 Oct 2020 20:36:00 +0200 Subject: [PATCH 2/3] merge tile defaults --- .eslintrc.yaml | 2 +- README.md | 5 ++- index.html.ejs | 2 +- scripts/controllers/main-utilities.js | 41 ++++++++++++++++++++ scripts/controllers/main.js | 54 +++++---------------------- scripts/globals/constants.js | 24 +++++++++++- scripts/globals/utils.js | 10 +++++ 7 files changed, 90 insertions(+), 48 deletions(-) create mode 100644 scripts/controllers/main-utilities.js diff --git a/.eslintrc.yaml b/.eslintrc.yaml index c2ad69b4..9d36705c 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -1,6 +1,6 @@ env: browser: true - es2017: true + es2020: true node: true parserOptions: sourceType: module diff --git a/README.md b/README.md index 8447bf7d..18e9088c 100644 --- a/README.md +++ b/README.md @@ -356,7 +356,10 @@ Tile Object. [Click here for some real-life examples](TILE_EXAMPLES.md) /** type: LIGHT **/ /* sliders: list of slider object. See slider documentation below */ sliders: [{}], - + /* colorpicker: whether or not the color picker should be shown. + * Valid options: true, false, function. Default: auto-detected + */ + colorpicker: true, /** type: POPUP_IFRAME **/ url: String || Function, /* optional */ diff --git a/index.html.ejs b/index.html.ejs index 91229936..ec27e76f 100644 --- a/index.html.ejs +++ b/index.html.ejs @@ -582,7 +582,7 @@
-
+
Color: supportsFeature(FEATURES.LIGHT.COLOR, entity), + }, +}; diff --git a/scripts/globals/utils.js b/scripts/globals/utils.js index 15f1287d..61272eba 100644 --- a/scripts/globals/utils.js +++ b/scripts/globals/utils.js @@ -129,3 +129,13 @@ export const toAbsoluteServerURL = function (path) { // Replace extra forward slashes but not in protocol. return url.replace(/([^:])\/+/g, '$1/'); }; + +export function supportsFeature (feature, entity) { + if (!('supported_features' in entity.attributes)) { + return false; + } + + const features = entity.attributes.supported_features; + + return (features | feature) === features; +} From 6b86ee71980114bbdaf439adc86d35d666b7a879 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Ch=C5=82odnicki?= Date: Tue, 20 Oct 2020 23:07:43 +0200 Subject: [PATCH 3/3] Address review issues --- README.md | 4 ++-- scripts/controllers/main-utilities.js | 11 +++++++---- scripts/controllers/main.js | 2 +- scripts/globals/utils.js | 9 ++------- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 18e9088c..8724bcf0 100644 --- a/README.md +++ b/README.md @@ -356,10 +356,10 @@ Tile Object. [Click here for some real-life examples](TILE_EXAMPLES.md) /** type: LIGHT **/ /* sliders: list of slider object. See slider documentation below */ sliders: [{}], - /* colorpicker: whether or not the color picker should be shown. + /* colorpicker: whether or not the color picker should be shown. * Valid options: true, false, function. Default: auto-detected */ - colorpicker: true, + colorpicker: false, /** type: POPUP_IFRAME **/ url: String || Function, /* optional */ diff --git a/scripts/controllers/main-utilities.js b/scripts/controllers/main-utilities.js index b10e093c..3a3dabb8 100644 --- a/scripts/controllers/main-utilities.js +++ b/scripts/controllers/main-utilities.js @@ -15,10 +15,10 @@ function mergeTileListDefaults (tiles) { return; } for (const [index, tile] of tiles.entries()) { - if (tile.type in TILE_DEFAULTS) { - tiles[index] = mergeTileDefaults(tile); - } + tiles[index] = mergeTileDefaults(tile); switch (tile.type) { + case TYPES.CAMERA: + case TYPES.CAMERA_STREAM: case TYPES.CAMERA_THUMBNAIL: tile.fullscreen = mergeTileDefaults(tile.fullscreen); break; @@ -37,5 +37,8 @@ function mergeTileListDefaults (tiles) { } function mergeTileDefaults (tile) { - return angular.merge({}, TILE_DEFAULTS[tile.type], tile); + if (tile && tile.type in TILE_DEFAULTS) { + return angular.merge({}, TILE_DEFAULTS[tile.type], tile); + } + return tile; } diff --git a/scripts/controllers/main.js b/scripts/controllers/main.js index 318e3408..8faf6feb 100755 --- a/scripts/controllers/main.js +++ b/scripts/controllers/main.js @@ -919,7 +919,7 @@ App.controller('Main', function ($scope, $timeout, $location, Api) { }; $scope.getGaugeField = function (field, item, entity) { - return parseFieldValue(item.settings[field], item, entity); + return getItemFieldValue(`settings.${field}`, item, entity); }; $scope.itemURL = function (item, entity) { diff --git a/scripts/globals/utils.js b/scripts/globals/utils.js index 61272eba..c3359117 100644 --- a/scripts/globals/utils.js +++ b/scripts/globals/utils.js @@ -131,11 +131,6 @@ export const toAbsoluteServerURL = function (path) { }; export function supportsFeature (feature, entity) { - if (!('supported_features' in entity.attributes)) { - return false; - } - - const features = entity.attributes.supported_features; - - return (features | feature) === features; + return 'supported_features' in entity.attributes + && (entity.attributes.supported_features & feature) !== 0; }