From ffb4ce6767c247dfa6b8bc61cf6b2734df57b660 Mon Sep 17 00:00:00 2001 From: stefan-hoehn Date: Sun, 6 Aug 2023 19:08:46 +0200 Subject: [PATCH 1/5] [blockly] Add Quantity support to round block (#2000) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Round block now also takes a Qty block as input. Output type changes according to input. Also-by: Florian Hotze Signed-off-by: Stefan Höhn --- .../assets/definitions/blockly/blocks-math.js | 30 +++++++++++++++++-- .../src/assets/definitions/blockly/utils.js | 2 +- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/bundles/org.openhab.ui/web/src/assets/definitions/blockly/blocks-math.js b/bundles/org.openhab.ui/web/src/assets/definitions/blockly/blocks-math.js index 7171a62637..0756241d4b 100644 --- a/bundles/org.openhab.ui/web/src/assets/definitions/blockly/blocks-math.js +++ b/bundles/org.openhab.ui/web/src/assets/definitions/blockly/blocks-math.js @@ -4,6 +4,7 @@ import Blockly from 'blockly' import { javascriptGenerator } from 'blockly/javascript' +import { blockGetCheckedInputType } from './utils' export default function (f7, isGraalJs) { Blockly.Blocks['oh_bit_not'] = { @@ -88,13 +89,25 @@ export default function (f7, isGraalJs) { block.updateType(operation) }) this.appendValueInput('NUM') - .setCheck('Number') + .setCheck(['Number', 'oh_quantity']) .appendField(dropDown, 'op') + this.setColour('%{BKY_MATH_HUE}') this.setInputsInline(false) this.setTooltip('Round a number up or down') this.setHelpUrl('https://www.openhab.org/docs/configuration/blockly/rules-blockly-math.html#round') - this.setOutput(true, 'Number') + this.setOutput(true, null) + }, + updateShape_: function () { + if (this.getInput('NUM')) { + let type = blockGetCheckedInputType(this, 'NUM') + if (type) { + this.setOutput(true, type) + } + } + }, + onchange: function () { + this.updateShape_() }, updateType: function (type) { if (type === 'toFixed') { @@ -111,13 +124,20 @@ export default function (f7, isGraalJs) { this.removeInput('declabel') this.setInputsInline(false) } + this.updateShape_() } } javascriptGenerator['math_round'] = function (block) { - const math_number = javascriptGenerator.valueToCode(block, 'NUM', javascriptGenerator.ORDER_FUNCTION_CALL) + const inputType = blockGetCheckedInputType(block, 'NUM') + const math_number_input = javascriptGenerator.valueToCode(block, 'NUM', javascriptGenerator.ORDER_FUNCTION_CALL) + let math_number = math_number_input + if (inputType === 'oh_quantity') { + math_number = math_number_input + '.float' + } const decimals = javascriptGenerator.valueToCode(block, 'DECIMALS', javascriptGenerator.ORDER_NONE) const operand = block.getFieldValue('op') + let code = '' if (operand !== 'toFixed') { let method = '' @@ -136,6 +156,10 @@ export default function (f7, isGraalJs) { } else { code = `(${math_number}).toFixed(${decimals})` } + + if (inputType === 'oh_quantity') { + code = `Quantity((${code}).toString() + ' ' + ${math_number_input}.symbol)` + } return [code, 0] } } diff --git a/bundles/org.openhab.ui/web/src/assets/definitions/blockly/utils.js b/bundles/org.openhab.ui/web/src/assets/definitions/blockly/utils.js index 53df72e677..0f5ac2e57e 100644 --- a/bundles/org.openhab.ui/web/src/assets/definitions/blockly/utils.js +++ b/bundles/org.openhab.ui/web/src/assets/definitions/blockly/utils.js @@ -230,7 +230,7 @@ export function blockGetCheckedInputType (block, inputName) { // Get the input type checks for this block const thisBlock = block.getInput(inputName).connection.getCheck() // Get the output type checks for the connected block - const connectedBlock = block.getInput(inputName).connection.targetBlock().outputConnection.getCheck() + const connectedBlock = block.getInput(inputName).connection.targetBlock()?.outputConnection.getCheck() // Skip if no checks are available if (!thisBlock || !connectedBlock) return '' // Find any intersection in the checklist From 0d34818112bb84ff6da1734745b1f246a2936d18 Mon Sep 17 00:00:00 2001 From: Florian Hotze Date: Sun, 6 Aug 2023 21:59:00 +0200 Subject: [PATCH 2/5] Widget editor: Add note that properties are not evaluated in the editor (#2007) Signed-off-by: Florian Hotze --- .../web/src/pages/developer/widgets/widget-edit.vue | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bundles/org.openhab.ui/web/src/pages/developer/widgets/widget-edit.vue b/bundles/org.openhab.ui/web/src/pages/developer/widgets/widget-edit.vue index 61dcb853df..75655c29db 100644 --- a/bundles/org.openhab.ui/web/src/pages/developer/widgets/widget-edit.vue +++ b/bundles/org.openhab.ui/web/src/pages/developer/widgets/widget-edit.vue @@ -55,6 +55,9 @@ + + Please note that expressions in properties are not evaluated inside the widget editor, but are evaluated when the widget is used on pages. + Date: Sun, 13 Aug 2023 19:37:29 +0200 Subject: [PATCH 3/5] =?UTF-8?q?[BasicUI]=20Upgrade=20frontend-maven-plugin?= =?UTF-8?q?,=20node=20and=20npm=20to=20most=20recent=20=E2=80=A6=20(#2012)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …versions Signed-off-by: Laurent Garnier --- bundles/org.openhab.ui.basic/pom.xml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/bundles/org.openhab.ui.basic/pom.xml b/bundles/org.openhab.ui.basic/pom.xml index e8db58a628..1a96221879 100644 --- a/bundles/org.openhab.ui.basic/pom.xml +++ b/bundles/org.openhab.ui.basic/pom.xml @@ -32,14 +32,13 @@ com.github.eirslett frontend-maven-plugin - 1.9.0 + 1.13.4 - v16.14.2 - 8.6.0 + v18.17.0 + 9.8.1 ${project.basedir}/npm_cache - ${project.basedir}/npm_tmp From 034d8b931869aae276d06d2461303aee91e77e8d Mon Sep 17 00:00:00 2001 From: lolodomo Date: Sun, 13 Aug 2023 21:53:13 +0200 Subject: [PATCH 4/5] [BasicUI] Add a new setting to choose the nb of columns (#2018) Also allow 3 columns on desktop. Possible number of columns on desktop: 1 or 2 or 3. Possible number of columns on tablet: 1 or 2 Possible number of columns on phone: 1 New default is 3 columns on desktop and 2 on tablet. Closes #1836 Signed-off-by: Laurent Garnier --- .../ui/basic/internal/WebAppConfig.java | 34 +++++++++++++++++++ .../render/AbstractWidgetRenderer.java | 2 ++ .../main/resources/OH-INF/config/config.xml | 13 +++++++ .../resources/OH-INF/i18n/basic.properties | 7 ++++ .../src/main/resources/snippets/buttons.html | 2 +- .../main/resources/snippets/colorpicker.html | 2 +- .../src/main/resources/snippets/group.html | 2 +- .../src/main/resources/snippets/input.html | 2 +- .../src/main/resources/snippets/mapview.html | 2 +- .../main/resources/snippets/rollerblind.html | 2 +- .../main/resources/snippets/selection.html | 2 +- .../src/main/resources/snippets/setpoint.html | 2 +- .../src/main/resources/snippets/slider.html | 2 +- .../src/main/resources/snippets/switch.html | 2 +- .../src/main/resources/snippets/text.html | 2 +- .../main/resources/snippets/text_link.html | 2 +- .../src/main/resources/snippets/webview.html | 2 +- .../org.openhab.ui.basic/web-src/_layout.scss | 3 ++ 18 files changed, 72 insertions(+), 13 deletions(-) diff --git a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/WebAppConfig.java b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/WebAppConfig.java index 44d27b905c..8edc6fa05b 100644 --- a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/WebAppConfig.java +++ b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/WebAppConfig.java @@ -40,8 +40,14 @@ public class WebAppConfig { private static final String DEFAULT_INLINE_SVG = "false"; private static final String DEFAULT_WEB_AUDIO = "false"; + private static final String DEFAULT_CONFIG_NB_COLUMNS = "3-2"; + private static final int DEFAULT_NB_COLUMNS_DESKTOP = 3; + private static final int DEFAULT_NB_COLUMNS_TABLET = 2; + private String defaultSitemap = DEFAULT_SITEMAP; private String theme = DEFAULT_THEME; + private int nbColsDesktop = DEFAULT_NB_COLUMNS_DESKTOP; + private int nbColsTablet = DEFAULT_NB_COLUMNS_TABLET; private boolean iconify = Boolean.parseBoolean(DEFAULT_ICONIFY); private boolean inlineSvg = Boolean.parseBoolean(DEFAULT_INLINE_SVG); private boolean webAudio = Boolean.parseBoolean(DEFAULT_WEB_AUDIO); @@ -53,6 +59,7 @@ public class WebAppConfig { private static final String CONFIG_ENABLE_ICONS = "enableIcons"; private static final String CONFIG_CONDENSED_LAYOUT = "condensedLayout"; + private static final String CONFIG_NB_COLUMNS = "nbColumns"; private static final String CONFIG_CAPITALIZE = "capitalizeValues"; static { @@ -81,6 +88,9 @@ private void applyCssClasses(Map configProps) { cssClassList.add(entry.getValue()); } } + if (nbColsDesktop == 3) { + cssClassList.add("ui-large-window"); + } } public void applyConfig(Map configProps) { @@ -90,6 +100,22 @@ public void applyConfig(Map configProps) { if ("default".equals(theme)) { theme = DEFAULT_THEME; } + String nbColumns = (String) configProps.getOrDefault(CONFIG_NB_COLUMNS, DEFAULT_CONFIG_NB_COLUMNS); + if (nbColumns.length() == 3) { + try { + nbColsDesktop = Integer.parseInt(nbColumns.substring(0, 1)); + } catch (NumberFormatException e) { + nbColsDesktop = DEFAULT_NB_COLUMNS_DESKTOP; + } + try { + nbColsTablet = Integer.parseInt(nbColumns.substring(2, 3)); + } catch (NumberFormatException e) { + nbColsTablet = DEFAULT_NB_COLUMNS_TABLET; + } + } else { + nbColsDesktop = DEFAULT_NB_COLUMNS_DESKTOP; + nbColsTablet = DEFAULT_NB_COLUMNS_TABLET; + } iconify = "true".equalsIgnoreCase((String) configProps.getOrDefault("enableIconify", DEFAULT_ICONIFY)); inlineSvg = "true".equalsIgnoreCase((String) configProps.getOrDefault("inlineSvg", DEFAULT_INLINE_SVG)); webAudio = "true".equalsIgnoreCase((String) configProps.getOrDefault("webAudio", DEFAULT_WEB_AUDIO)); @@ -113,6 +139,14 @@ public String getCssClassList() { return result; } + public int getNbColsDesktop() { + return nbColsDesktop; + } + + public int getNbColsTablet() { + return nbColsTablet; + } + public boolean isIconifyEnabled() { return iconify; } diff --git a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/AbstractWidgetRenderer.java b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/AbstractWidgetRenderer.java index 7134570c0d..96be74dfe1 100644 --- a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/AbstractWidgetRenderer.java +++ b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/AbstractWidgetRenderer.java @@ -124,6 +124,8 @@ protected String preprocessSnippet(String originalSnippet, Widget w) { protected String preprocessSnippet(String originalSnippet, Widget w, boolean ignoreStateForIcon) { String snippet = preprocessIcon(originalSnippet, w, ignoreStateForIcon); + snippet = snippet.replace("%cells%", String.valueOf(12 / config.getNbColsDesktop())); + snippet = snippet.replace("%cells_tablet%", String.valueOf(8 / config.getNbColsTablet())); snippet = snippet.replace("%widget_id%", itemUIRegistry.getWidgetId(w)); snippet = snippet.replace("%item%", w.getItem() != null ? w.getItem() : ""); // Optimization: avoid calling 3 times itemUIRegistry.getLabel(w) diff --git a/bundles/org.openhab.ui.basic/src/main/resources/OH-INF/config/config.xml b/bundles/org.openhab.ui.basic/src/main/resources/OH-INF/config/config.xml index f045147678..c4e8f01391 100644 --- a/bundles/org.openhab.ui.basic/src/main/resources/OH-INF/config/config.xml +++ b/bundles/org.openhab.ui.basic/src/main/resources/OH-INF/config/config.xml @@ -59,6 +59,19 @@ false + + + The number of columns to consider to fill the grid in large screen width (desktop) and medium screen + width (tablet). + + + + + + + + 3-2 + Displays all widget states in uppercase. diff --git a/bundles/org.openhab.ui.basic/src/main/resources/OH-INF/i18n/basic.properties b/bundles/org.openhab.ui.basic/src/main/resources/OH-INF/i18n/basic.properties index 9973707d63..1e8422ee25 100644 --- a/bundles/org.openhab.ui.basic/src/main/resources/OH-INF/i18n/basic.properties +++ b/bundles/org.openhab.ui.basic/src/main/resources/OH-INF/i18n/basic.properties @@ -20,6 +20,13 @@ ui.config.basic.inlineSvg.label = Inline SVG ui.config.basic.inlineSvg.description = If enabled, any SVG icon provided by the openHAB icon server will automatically be converted to an inline SVG in the WEB page, allowing control of its color with the sitemap widget property "iconcolor" in the case where the SVG icon sets "currentColor" as the fill color. Note that this will work with custom SVG icons but not with all the packaged icons from the classic iconset since they are defined with a hard-coded color palette. This feature is disabled by default. ui.config.basic.inlineSvg.option.true = Enable ui.config.basic.inlineSvg.option.false = Disable +ui.config.basic.nbColumns.label = Number Columns +ui.config.basic.nbColumns.description = The number of columns to consider to fill the grid in large screen width (desktop) and medium screen width (tablet). +ui.config.basic.nbColumns.option.1-1 = 1 column on desktop and tablet +ui.config.basic.nbColumns.option.2-1 = 2 columns on desktop but only 1 on tablet +ui.config.basic.nbColumns.option.2-2 = 2 columns on desktop and tablet +ui.config.basic.nbColumns.option.3-1 = 3 columns on desktop but only 1 on tablet +ui.config.basic.nbColumns.option.3-2 = 3 columns on desktop but only 2 on tablet ui.config.basic.theme.label = Theme ui.config.basic.theme.description = Defines the UI theme. ui.config.basic.theme.option.bright = Bright diff --git a/bundles/org.openhab.ui.basic/src/main/resources/snippets/buttons.html b/bundles/org.openhab.ui.basic/src/main/resources/snippets/buttons.html index c3d563f151..8ad90b5fd9 100644 --- a/bundles/org.openhab.ui.basic/src/main/resources/snippets/buttons.html +++ b/bundles/org.openhab.ui.basic/src/main/resources/snippets/buttons.html @@ -1,4 +1,4 @@ -
+
%icon_snippet% diff --git a/bundles/org.openhab.ui.basic/src/main/resources/snippets/colorpicker.html b/bundles/org.openhab.ui.basic/src/main/resources/snippets/colorpicker.html index 6e53aece7e..d0af3637ff 100644 --- a/bundles/org.openhab.ui.basic/src/main/resources/snippets/colorpicker.html +++ b/bundles/org.openhab.ui.basic/src/main/resources/snippets/colorpicker.html @@ -1,4 +1,4 @@ -
+
%icon_snippet% diff --git a/bundles/org.openhab.ui.basic/src/main/resources/snippets/group.html b/bundles/org.openhab.ui.basic/src/main/resources/snippets/group.html index 75485cd201..64c190c1dd 100644 --- a/bundles/org.openhab.ui.basic/src/main/resources/snippets/group.html +++ b/bundles/org.openhab.ui.basic/src/main/resources/snippets/group.html @@ -1,4 +1,4 @@ -