From 28344301a799f5dfaf0813304c9b5b9830d0653b Mon Sep 17 00:00:00 2001 From: Laurent Garnier Date: Wed, 14 Jul 2021 18:32:08 +0200 Subject: [PATCH] [basicUI] Fix handling of buttons when only 1 button Fix #1131 Signed-off-by: Laurent Garnier --- .../ui/basic/internal/render/SwitchRenderer.java | 11 +++++------ bundles/org.openhab.ui.basic/web-src/smarthome.js | 10 ++-------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/SwitchRenderer.java b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/SwitchRenderer.java index 4ff5abc3a5..711165e9dd 100644 --- a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/SwitchRenderer.java +++ b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/SwitchRenderer.java @@ -126,13 +126,12 @@ public EList renderWidget(Widget w, StringBuilder sb, String sitemap) th if (commandDescription != null) { for (CommandOption option : commandDescription.getCommandOptions()) { // Truncate the button label to MAX_LABEL_SIZE characters - buildButton(s, option.getLabel(), option.getCommand(), MAX_LABEL_SIZE, nbButtons > 1, item, - state, buttons); + buildButton(s, option.getLabel(), option.getCommand(), MAX_LABEL_SIZE, item, state, buttons); } } } else { for (Mapping mapping : s.getMappings()) { - buildButton(s, mapping.getLabel(), mapping.getCmd(), -1, nbButtons > 1, item, state, buttons); + buildButton(s, mapping.getLabel(), mapping.getCmd(), -1, item, state, buttons); } } snippet = snippet.replace("%buttons%", buttons.toString()); @@ -146,8 +145,8 @@ public EList renderWidget(Widget w, StringBuilder sb, String sitemap) th return ECollections.emptyEList(); } - private void buildButton(Switch w, @Nullable String lab, String cmd, int maxLabelSize, boolean severalButtons, - @Nullable Item item, @Nullable State state, StringBuilder buttons) throws RenderException { + private void buildButton(Switch w, @Nullable String lab, String cmd, int maxLabelSize, @Nullable Item item, + @Nullable State state, StringBuilder buttons) throws RenderException { String button = getSnippet("button"); String command = cmd; @@ -176,7 +175,7 @@ private void buildButton(Switch w, @Nullable String lab, String cmd, int maxLabe compareMappingState = convertStateToLabelUnit((QuantityType) state, command); } - if (severalButtons && compareMappingState != null && compareMappingState.toString().equals(command)) { + if (compareMappingState != null && compareMappingState.toString().equals(command)) { buttonClass = "mdl-button--accent"; } else { buttonClass = "mdl-button"; diff --git a/bundles/org.openhab.ui.basic/web-src/smarthome.js b/bundles/org.openhab.ui.basic/web-src/smarthome.js index 3b3ce1f686..605d791115 100644 --- a/bundles/org.openhab.ui.basic/web-src/smarthome.js +++ b/bundles/org.openhab.ui.basic/web-src/smarthome.js @@ -638,10 +638,8 @@ var value = this.getAttribute("data-value") + ""; - if (_t.count !== 1) { - _t.reset(); - this.classList.add(o.buttonActiveClass); - } + _t.reset(); + this.classList.add(o.buttonActiveClass); _t.parentNode.dispatchEvent(createEvent( "control-change", { @@ -657,10 +655,6 @@ _t.value.innerHTML = value; } - if (_t.count === 1) { - return; - } - if (_t.suppressUpdateButtons) { _t.suppressUpdateButtons = false; return;