Skip to content

Commit

Permalink
Add a new data value in snippets
Browse files Browse the repository at this point in the history
Signed-off-by: Laurent Garnier <[email protected]>
  • Loading branch information
lolodomo committed Aug 15, 2023
1 parent 8ecddbc commit 9ccc90a
Show file tree
Hide file tree
Showing 17 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
@@ -1 +1 @@
<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" />
<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" />
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<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" />
<img data-icon="%icon_set%:%icon_name%" src="../icon/%icon_name_in_url%?iconset=%icon_set_in_url%&format=%icon_type%&anyFormat=true" />
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%"
>
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
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="webview"
data-widget-id="%widget_id%"
data-icon-with-state="%icon_with_state%"
>
<iframe src="%url%" height="%height%"></iframe>
</div>
Expand Down
6 changes: 3 additions & 3 deletions bundles/org.openhab.ui.basic/web-src/smarthome.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@
_t.formRow = parentNode.parentNode;
_t.item = _t.parentNode.getAttribute(o.itemAttribute);
_t.id = _t.parentNode.getAttribute(o.idAttribute);
_t.iconWithState = _t.parentNode.getAttribute(o.iconWithStateAttribute) === "true";
_t.iconContainer = _t.parentNode.parentNode.querySelector(o.formIcon);
_t.icon = _t.parentNode.parentNode.querySelector(o.formIconImg);
_t.visible = !_t.formRow.classList.contains(o.formRowHidden);
Expand All @@ -375,7 +376,6 @@
}

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 @@ -433,7 +433,7 @@
src;

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

0 comments on commit 9ccc90a

Please sign in to comment.