Skip to content

Commit

Permalink
[basicUI] Fix handling of buttons when only 1 button
Browse files Browse the repository at this point in the history
Fix openhab#1131

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
  • Loading branch information
lolodomo committed Jul 14, 2021
1 parent ffbd450 commit 2834430
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,12 @@ public EList<Widget> 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());
Expand All @@ -146,8 +145,8 @@ public EList<Widget> 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;
Expand Down Expand Up @@ -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";
Expand Down
10 changes: 2 additions & 8 deletions bundles/org.openhab.ui.basic/web-src/smarthome.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand All @@ -657,10 +655,6 @@
_t.value.innerHTML = value;
}

if (_t.count === 1) {
return;
}

if (_t.suppressUpdateButtons) {
_t.suppressUpdateButtons = false;
return;
Expand Down

0 comments on commit 2834430

Please sign in to comment.