Skip to content

Commit

Permalink
[BasicUI] Add version number to resource requests
Browse files Browse the repository at this point in the history
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
  • Loading branch information
jimtng committed Aug 11, 2024
1 parent 77d42c1 commit d7a0290
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.openhab.ui.basic.render.RenderException;
import org.openhab.ui.basic.render.WidgetRenderer;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
Expand Down Expand Up @@ -63,11 +64,13 @@ public class PageRenderer extends AbstractWidgetRenderer {
private final Logger logger = LoggerFactory.getLogger(PageRenderer.class);

private List<WidgetRenderer> widgetRenderers = new ArrayList<>();
private final String bundleVersion;

@Activate
public PageRenderer(final BundleContext bundleContext, final @Reference TranslationProvider i18nProvider,
final @Reference ItemUIRegistry itemUIRegistry, final @Reference LocaleProvider localeProvider) {
super(bundleContext, i18nProvider, itemUIRegistry, localeProvider);
bundleVersion = FrameworkUtil.getBundle(PageRenderer.class).getVersion().toString();
}

@Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
Expand All @@ -93,11 +96,6 @@ public void removeWidgetRenderer(WidgetRenderer widgetRenderer) {
*/
public StringBuilder processPage(String id, String sitemap, String label, EList<Widget> children, boolean async)
throws RenderException {
String snippet = getSnippet(async ? "layer" : "main");
snippet = snippet.replaceAll("%main.offline-msg%", localizeText("@text/main.offline-msg"));
snippet = snippet.replaceAll("%main.long-polling-mode-msg%", localizeText("@text/main.long-polling-mode-msg"));
snippet = snippet.replaceAll("%id%", id);

// if the label contains a value span, we remove this span as
// the title of a page/layer cannot deal with this
// Note: we can have a span here, if the parent widget had a label
Expand All @@ -107,12 +105,17 @@ public StringBuilder processPage(String id, String sitemap, String label, EList<
if (labelPlain.contains("[") && labelPlain.endsWith("]")) {
labelPlain = labelPlain.replace("[", "").replace("]", "");
}
snippet = snippet.replace("%label%", escapeHtml(labelPlain));
snippet = snippet.replace("%servletname%", WebAppServlet.SERVLET_PATH);
snippet = snippet.replace("%sitemap%", sitemap);
snippet = snippet.replace("%icon_type%", ICON_TYPE);
snippet = snippet.replace("%inline%", config.isInlineSvgEnabled() ? "true" : "false");
snippet = snippet.replace("%sitemapquery%", String.format("?sitemap=%s", sitemap));
String snippet = getSnippet(async ? "layer" : "main") //
.replaceAll("%main.offline-msg%", localizeText("@text/main.offline-msg")) //
.replaceAll("%main.long-polling-mode-msg%", localizeText("@text/main.long-polling-mode-msg")) //
.replaceAll("%id%", id) //
.replaceAll("%version%", bundleVersion) //
.replace("%label%", escapeHtml(labelPlain)) //
.replace("%servletname%", WebAppServlet.SERVLET_PATH) //
.replace("%sitemap%", sitemap) //
.replace("%icon_type%", ICON_TYPE) //
.replace("%inline%", config.isInlineSvgEnabled() ? "true" : "false") //
.replace("%sitemapquery%", String.format("?sitemap=%s", sitemap));

String[] parts = snippet.split("%children%");

Expand Down Expand Up @@ -268,6 +271,7 @@ public CharSequence renderSitemapList(Set<SitemapProvider> sitemapProviders) thr
listSnippet = listSnippet.replace("%items%", sb.toString());

return getSnippet("main_static") //
.replaceAll("%version%", bundleVersion) //
.replace("%title%", "Basic UI") //
.replace("%htmlclass%", "page-welcome-sitemaps") //
.replace("%relpath%", "") //
Expand Down Expand Up @@ -367,6 +371,7 @@ public CharSequence renderSettings() throws RenderException {
"enabled", "", false, sb);

return getSnippet("main_static") //
.replaceAll("%version%", bundleVersion) //
.replace("%title%", localizeText("@text/preferences.title")) //
.replace("%htmlclass%", "") //
.replace("%relpath%", "../") //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
<link rel="stylesheet" type="text/css" href="mdl/material.min.css" />
<link rel="stylesheet" type="text/css" href="material-icons.css" />
<link rel="stylesheet" type="text/css" href="framework7-icons.css" />
<link rel="stylesheet" type="text/css" href="smarthome.css" />
<link rel="stylesheet" type="text/css" href="smarthome.css?v=%version%" />

<script src="smarthome.js"></script>
<script src="smarthome.js?v=%version%"></script>
<script src="mdl/material.min.js"></script>
<script type="text/html" id="template-modal">
<div class="mdl-modal">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

<link rel="stylesheet" type="text/css" href="%relpath%mdl/material.min.css" />
<link rel="stylesheet" type="text/css" href="%relpath%material-icons.css" />
<link rel="stylesheet" type="text/css" href="%relpath%smarthome.css" />
<link rel="stylesheet" type="text/css" href="%relpath%smarthome.css?v=%version%" />

<script src="%relpath%%script%"></script>
<script src="%relpath%%script%?v=%version%"></script>
<script src="%relpath%mdl/material.min.js"></script>
<script type="text/html" id="template-modal">
<div class="mdl-modal">
Expand Down

0 comments on commit d7a0290

Please sign in to comment.