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] Create header row only when needed #2344

Merged
merged 2 commits into from
Mar 17, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,10 @@ public EList<Widget> renderWidget(Widget w, StringBuilder sb, String sitemap) th
return ECollections.emptyEList();
}

String snippet = getSnippet("buttongrid");

boolean showHeaderRow = grid.getLabel() != null;
snippet = snippet.replace("%header_visibility_class%",
showHeaderRow ? "%visibility_class%" : "mdl-form__row--hidden");
snippet = snippet.replace("%header_row%", Boolean.valueOf(showHeaderRow).toString());
String snippet = (showHeaderRow ? getSnippet("header_row") : "") + getSnippet("buttongrid");

snippet = snippet.replace("%header_row%", showHeaderRow ? "true" : "");

snippet = preprocessSnippet(snippet, w, true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,10 @@ public boolean canRender(Widget w) {
@Override
public EList<Widget> renderWidget(Widget w, StringBuilder sb, String sitemap) throws RenderException {
Mapview mapview = (Mapview) w;
String snippet = getSnippet("mapview");

boolean showHeaderRow = w.getLabel() != null;
snippet = snippet.replace("%header_visibility_class%",
showHeaderRow ? "%visibility_class%" : "mdl-form__row--hidden");
snippet = snippet.replace("%header_row%", Boolean.valueOf(showHeaderRow).toString());
String snippet = (showHeaderRow ? getSnippet("header_row") : "") + getSnippet("mapview");

snippet = snippet.replace("%header_row%", showHeaderRow ? "true" : "");

snippet = preprocessSnippet(snippet, mapview, true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,19 @@ public boolean canRender(Widget w) {
@Override
public EList<Widget> renderWidget(Widget w, StringBuilder sb, String sitemap) throws RenderException {
Video videoWidget = (Video) w;
String snippet = null;

String widgetId = itemUIRegistry.getWidgetId(w);

// we handle mjpeg streams as an html image as browser can usually handle this
String snippetName = (videoWidget.getEncoding() != null
&& videoWidget.getEncoding().toLowerCase().contains("mjpeg")) ? "image" : "video";

snippet = getSnippet(snippetName);

boolean showHeaderRow = w.getLabel() != null;
snippet = snippet.replace("%header_visibility_class%",
showHeaderRow ? "%visibility_class%" : "mdl-form__row--hidden");
snippet = snippet.replace("%header_row%", Boolean.valueOf(showHeaderRow).toString());
String snippet = (("video".equals(snippetName) && showHeaderRow) ? getSnippet("header_row") : "")
+ getSnippet(snippetName);

snippet = snippet.replace("%header_row%",
("image".equals(snippetName) || showHeaderRow) ? Boolean.valueOf(showHeaderRow).toString() : "");

snippet = preprocessSnippet(snippet, w, true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,10 @@ public boolean canRender(Widget w) {
@Override
public EList<Widget> renderWidget(Widget w, StringBuilder sb, String sitemap) throws RenderException {
Webview webview = (Webview) w;
String snippet = getSnippet("webview");

boolean showHeaderRow = w.getLabel() != null;
snippet = snippet.replace("%header_visibility_class%",
showHeaderRow ? "%visibility_class%" : "mdl-form__row--hidden");
snippet = snippet.replace("%header_row%", Boolean.valueOf(showHeaderRow).toString());
String snippet = (showHeaderRow ? getSnippet("header_row") : "") + getSnippet("webview");

snippet = snippet.replace("%header_row%", showHeaderRow ? "true" : "");

snippet = preprocessSnippet(snippet, webview, true);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
<div class="mdl-form__row mdl-form__row--header mdl-cell mdl-cell--12-col %header_visibility_class%">
<span %iconstyle% class="mdl-form__icon">
%icon_snippet%
</span>
<span %labelstyle% class="mdl-form__label">
%label%
</span>
</div>
<div class="mdl-form__row mdl-cell mdl-cell--12-col mdl-form__row--height-auto %visibility_class%">
<div
class="mdl-form__control mdl-form__buttongrid mdl-grid"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div class="mdl-form__row mdl-form__row--header mdl-cell mdl-cell--12-col %visibility_class%">
<span %iconstyle% class="mdl-form__icon">
%icon_snippet%
</span>
<span %labelstyle% class="mdl-form__label">
%label%
</span>
</div>
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
<div class="mdl-form__row mdl-form__row--header mdl-cell mdl-cell--12-col %header_visibility_class%">
<span %iconstyle% class="mdl-form__icon">
%icon_snippet%
</span>
<span %labelstyle% class="mdl-form__label">
%label%
</span>
</div>
<div class="mdl-form__row mdl-form__row--height-auto mdl-cell mdl-cell--12-col %visibility_class%">
<div
class="mdl-form__control mdl-form__webview"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
<div class="mdl-form__row mdl-form__row--header mdl-cell mdl-cell--12-col %header_visibility_class%">
<span %iconstyle% class="mdl-form__icon">
%icon_snippet%
</span>
<span %labelstyle% class="mdl-form__label">
%label%
</span>
</div>
<div class="mdl-form__row mdl-form__row--height-auto mdl-cell mdl-cell--12-col %visibility_class%">
<div
class="mdl-form__control mdl-form__video"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
<div class="mdl-form__row mdl-form__row--header mdl-cell mdl-cell--12-col %header_visibility_class%">
<span %iconstyle% class="mdl-form__icon">
%icon_snippet%
</span>
<span %labelstyle% class="mdl-form__label">
%label%
</span>
</div>
<div class="mdl-form__row mdl-form__row--height-auto mdl-cell mdl-cell--12-col %visibility_class%">
<div
class="mdl-form__control mdl-form__webview"
Expand Down
16 changes: 10 additions & 6 deletions bundles/org.openhab.ui.basic/web-src/smarthome.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@
_t.cellSizeTablet = 4;
_t.cellSizeDesktop = 4;
_t.headerRow = _t.parentNode.getAttribute("data-header-row");
if (_t.headerRow !== null) {
if (_t.headerRow !== null && _t.headerRow !== "") {
_t.formHeaderRow = _t.formRow.previousElementSibling;
_t.iconContainer = _t.formHeaderRow.querySelector(o.formIcon);
_t.label = _t.formHeaderRow.querySelector(o.formLabel);
Expand All @@ -380,6 +380,10 @@
formRow = _t.formHeaderRow !== null ? _t.formHeaderRow : _t.formRow;

_t.iconSource = null;
if (_t.iconContainer === null) {
_t.icon = null;
return;
}
_t.icon = formRow.querySelector(o.formIconImg);
if (_t.icon !== null) {
_t.iconSource = "oh";
Expand Down Expand Up @@ -757,7 +761,7 @@
this.parentNode = parentNode;
this.id = this.parentNode.getAttribute(o.idAttribute);
this.headerRow = this.parentNode.getAttribute("data-header-row");
if (this.headerRow !== null) {
if (this.headerRow !== null && this.headerRow !== "") {
this.formHeaderRow = this.parentNode.parentNode.previousElementSibling;
} else {
this.formHeaderRow = null;
Expand All @@ -778,7 +782,7 @@
_t.upscaleButton = null;
_t.refreshButton = null;

if (_t.headerRow !== null) {
if (_t.headerRow !== null && _t.headerRow !== "") {
_t.upscaleButton = _t.formHeaderRow.querySelector(o.image.upscaleButton);
_t.refreshButton = _t.formHeaderRow.querySelector(o.image.refreshButton);
if (_t.upscaleButton !== null) {
Expand Down Expand Up @@ -893,7 +897,7 @@
componentHandler.downgradeElements([ _t.refreshButton ]);
_t.refreshButton.removeEventListener("click", onRefreshClick);
}
if (_t.headerRow !== null) {
if (_t.headerRow !== null && _t.headerRow !== "") {
_t.parentNode.parentNode.removeEventListener("click", toggleHeaderRow);
}

Expand All @@ -908,7 +912,7 @@
if (_t.refreshButton !== null) {
_t.refreshButton.addEventListener("click", onRefreshClick);
}
if (_t.headerRow !== null) {
if (_t.headerRow !== null && _t.headerRow !== "") {
_t.parentNode.parentNode.addEventListener("click", toggleHeaderRow);
}

Expand All @@ -927,7 +931,7 @@
_t.legendButton = null;
_t.periodButton = null;

if (_t.headerRow !== null) {
if (_t.headerRow !== null && _t.headerRow !== "") {
_t.legendButton = _t.formHeaderRow.querySelector(o.image.legendButton);
_t.periodButton = _t.formHeaderRow.querySelector(o.image.periodButton);
if (_t.legendButton !== null) {
Expand Down