Skip to content

Commit

Permalink
[BasicUI] Handle the new parameter "staticIcon" (#1998)
Browse files Browse the repository at this point in the history
When set on a sitemap element, Basic UI ignores the item state when
initially requesting the OH icon and do not request it again when the
item state is updated.

Depends on openhab/openhab-core#3735

Related to openhab/openhab-android#3404

Signed-off-by: Laurent Garnier <[email protected]>
  • Loading branch information
lolodomo authored Sep 9, 2023
1 parent 08a2d80 commit 07aacc9
Show file tree
Hide file tree
Showing 14 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public ItemUIRegistry getItemUIRegistry() {
* @return HTML code
*/
protected String preprocessSnippet(String originalSnippet, Widget w) {
return preprocessSnippet(originalSnippet, w, false);
return preprocessSnippet(originalSnippet, w, w.getStaticIcon() != null);
}

/**
Expand All @@ -128,6 +128,7 @@ protected String preprocessSnippet(String originalSnippet, Widget w, boolean ign
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("%icon_with_state%", Boolean.valueOf(!ignoreStateForIcon).toString());
snippet = snippet.replace("%item%", w.getItem() != null ? w.getItem() : "");
// Optimization: avoid calling 3 times itemUIRegistry.getLabel(w)
String text = itemUIRegistry.getLabel(w);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
data-has-value="%has_value%"
data-count="%count%"
data-widget-id="%widget_id%"
data-icon-with-state="%icon_with_state%"
>
%buttons%
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
data-item="%item%"
data-value="%state%"
data-widget-id="%widget_id%"
data-icon-with-state="%icon_with_state%"
>
<button class="mdl-button mdl-button--raised mdl-js-button mdl-js-ripple-effect mdl-form__colorpicker--up">
<!-- keyboard_arrow_up -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
data-item="%item%"
data-has-value="%has_value%"
data-widget-id="%widget_id%"
data-icon-with-state="%icon_with_state%"
>
<!-- chevron_right -->
<i class="material-icons">&#xE5CC;</i>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
data-control-type="input"
data-item="%item%"
data-widget-id="%widget_id%"
data-icon-with-state="%icon_with_state%"
data-item-type="%data_type%"
data-input-hint="%input_hint%"
data-item-state="%item_state%"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
class="mdl-form__control mdl-form__webview"
data-control-type="mapview"
data-widget-id="%widget_id%"
data-icon-with-state="%icon_with_state%"
data-map-url="%map_url%"
data-map-zoom="%map_zoom%"
data-header-row="%header_row%"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
data-item="%item%"
data-has-value="%has_value%"
data-widget-id="%widget_id%"
data-icon-with-state="%icon_with_state%"
>
<button class="mdl-button mdl-button--raised mdl-js-button mdl-js-ripple-effect mdl-form__rollerblind--up">
<!-- keyboard_arrow_up -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
data-has-value="%has_value%"
data-value-map="%value_map%"
data-widget-id="%widget_id%"
data-icon-with-state="%icon_with_state%"
>
<!-- arrow_drop_down -->
<i class="material-icons">&#xE5C5;</i>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
data-value="%state%"
data-unit="%unit%"
data-widget-id="%widget_id%"
data-icon-with-state="%icon_with_state%"
>
<button class="mdl-button mdl-button--raised mdl-js-button mdl-js-ripple-effect mdl-form__setpoint--up">
<!-- keyboard_arrow_up -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
data-unit="%unit%"
data-has-value="%has_value%"
data-widget-id="%widget_id%"
data-icon-with-state="%icon_with_state%"
>
<input
data-freq="%frequency%"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
data-item="%item%"
data-has-value="%has_value%"
data-widget-id="%widget_id%"
data-icon-with-state="%icon_with_state%"
for="oh-checkbox-%item%"
>
<input type="checkbox" %checked% id="oh-checkbox-%item%" class="mdl-switch__input" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
data-item="%item%"
data-has-value="%has_value%"
data-widget-id="%widget_id%"
data-icon-with-state="%icon_with_state%"
>
%value%
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
data-item="%item%"
data-has-value="%has_value%"
data-widget-id="%widget_id%"
data-icon-with-state="%icon_with_state%"
>
<!-- chevron_right -->
<i class="material-icons">&#xE5CC;</i>
Expand Down
4 changes: 3 additions & 1 deletion bundles/org.openhab.ui.basic/web-src/smarthome.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@
}
_t.item = _t.parentNode.getAttribute(o.itemAttribute);
_t.id = _t.parentNode.getAttribute(o.idAttribute);
_t.iconWithState = _t.parentNode.getAttribute(o.iconWithStateAttribute) === "true";
_t.visible = !_t.formRow.classList.contains(o.formRowHidden);
_t.headerRow = _t.parentNode.getAttribute("data-header-row");
if (_t.headerRow !== null) {
Expand Down Expand Up @@ -447,7 +448,7 @@
src;

// Some widgets don't have icons
if (_t.icon !== null) {
if (_t.icon !== null && _t.iconWithState) {
if (state.length < 200) {
src = "/icon/" + encodeURIComponent(_t.iconName) +
"?state=" + encodeURIComponent(state) +
Expand Down Expand Up @@ -2910,6 +2911,7 @@
idAttribute: "data-widget-id",
iconAttribute: "data-icon",
iconTypeAttribute: "data-icon-type",
iconWithStateAttribute: "data-icon-with-state",
inlineSvgAttribute: "data-inline-svg",
primaryColorAttribute: "data-primary-color",
secondaryColorAttribute: "data-secondary-color",
Expand Down

0 comments on commit 07aacc9

Please sign in to comment.