Skip to content

Commit

Permalink
[BasicUI] Handle the new parameter "staticIcon"
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 committed Aug 9, 2023
1 parent edc124e commit b89df6d
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public EList<Widget> renderWidget(Widget w, StringBuilder sb, String sitemap) th
}

String snippet = getSnippet("chart");
snippet = preprocessSnippet(snippet, w);
snippet = preprocessSnippet(snippet, w, true);

if (chart.getRefresh() > 0) {
snippet = snippet.replace("%update_interval%", Integer.toString(chart.getRefresh()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public EList<Widget> renderWidget(Widget w, StringBuilder sb, String sitemap) th

String widgetId = itemUIRegistry.getWidgetId(w);
snippet = snippet.replace("%id%", widgetId);
snippet = preprocessSnippet(snippet, w);
snippet = preprocessSnippet(snippet, w, true);

boolean validUrl = isValidURL(image.getUrl());
String proxiedUrl = "../proxy?sitemap=" + sitemap + "&amp;widgetId=" + widgetId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public EList<Widget> renderWidget(Widget w, StringBuilder sb, String sitemap) th
&& videoWidget.getEncoding().toLowerCase().contains("mjpeg")) ? "image" : "video";

snippet = getSnippet(snippetName);
snippet = preprocessSnippet(snippet, w);
snippet = preprocessSnippet(snippet, w, true);

State state = itemUIRegistry.getState(w);
String url;
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<img data-icon="%icon_set%:%icon_name%" src="../icon/%icon_name_in_url%?state=%state_in_url%&iconset=%icon_set_in_url%&format=%icon_type%&anyFormat=true" />
<img data-icon="%icon_set%:%icon_name%" data-static="false" src="../icon/%icon_name_in_url%?state=%state_in_url%&iconset=%icon_set_in_url%&format=%icon_type%&anyFormat=true" />
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<img data-icon="%icon_set%:%icon_name%" src="../icon/%icon_name_in_url%?iconset=%icon_set_in_url%&format=%icon_type%&anyFormat=true" />
<img data-icon="%icon_set%:%icon_name%" data-static="true" src="../icon/%icon_name_in_url%?iconset=%icon_set_in_url%&format=%icon_type%&anyFormat=true" />
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 @@ -375,6 +375,7 @@
}

if (_t.icon !== null) {
_t.staticIcon = _t.icon.getAttribute(o.staticAttribute) === "true";
splittedIconAttr = _t.icon.getAttribute(o.iconAttribute).split(":");
_t.iconSet = splittedIconAttr[0];
_t.iconName = splittedIconAttr[1];
Expand Down Expand Up @@ -432,7 +433,7 @@
src;

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

0 comments on commit b89df6d

Please sign in to comment.