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

[basicui] Fix handling of buttons when only 1 button #1132

Merged
merged 1 commit into from
Jul 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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