From 2e30c3a85e703696975bf47e7a43f8d8ed09b4a7 Mon Sep 17 00:00:00 2001 From: Laurent Garnier Date: Fri, 6 Oct 2023 08:30:10 +0200 Subject: [PATCH] [BasicUI] Prefer sitemap label to name in sitemap selection Sitemaps are now also sorted by label/name. Dark theme is now properly handled. Fix #2101 Signed-off-by: Laurent Garnier --- .../basic/internal/render/PageRenderer.java | 38 ++++++++++++++++--- .../main/resources/snippets/main_static.html | 2 +- .../snippets/sitemaps_list_item.html | 2 +- .../org.openhab.ui.basic/web-src/_layout.scss | 2 +- 4 files changed, 35 insertions(+), 9 deletions(-) diff --git a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/PageRenderer.java b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/PageRenderer.java index 5a5ef0be2c..19d85da26c 100644 --- a/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/PageRenderer.java +++ b/bundles/org.openhab.ui.basic/src/main/java/org/openhab/ui/basic/internal/render/PageRenderer.java @@ -217,13 +217,16 @@ public void setConfig(WebAppConfig config) { } public CharSequence renderSitemapList(Set sitemapProviders) throws RenderException { - List sitemapList = new LinkedList(); + List sitemapList = new LinkedList<>(); for (SitemapProvider sitemapProvider : sitemapProviders) { Set sitemaps = sitemapProvider.getSitemapNames(); - for (String sitemap : sitemaps) { - if (!"_default".equals(sitemap)) { - sitemapList.add(sitemap); + for (String sitemapName : sitemaps) { + if (!"_default".equals(sitemapName)) { + Sitemap sitemap = sitemapProvider.getSitemap(sitemapName); + if (sitemap != null) { + sitemapList.add(sitemap); + } } } } @@ -241,8 +244,31 @@ public CharSequence renderSitemapList(Set sitemapProviders) thr } sb.append(listEmptySnippet); } else { - for (String sitemap : sitemapList) { - sb.append(sitemapSnippet.replace("%sitemap%", sitemap)); + sitemapList.sort((s1, s2) -> { + String s1Label = s1.getLabel(); + String s2Label = s2.getLabel(); + s1Label = s1Label != null ? s1Label : s1.getName(); + s2Label = s2Label != null ? s2Label : s2.getName(); + int result = s1Label.compareTo(s2Label); + if (result == 0) { + result = s1.getName().compareTo(s2.getName()); + } + return result; + }); + + for (Sitemap sitemap : sitemapList) { + String label = sitemap.getLabel(); + final String name = sitemap.getName(); + if (label != null) { + if (sitemapList.stream() + .filter(s -> sitemap.getLabel().equals(s.getLabel() != null ? s.getLabel() : s.getName())) + .count() > 1) { + label = label + " (" + name + ")"; + } + } else { + label = name; + } + sb.append(sitemapSnippet.replace("%label%", label).replace("%name%", name)); } } diff --git a/bundles/org.openhab.ui.basic/src/main/resources/snippets/main_static.html b/bundles/org.openhab.ui.basic/src/main/resources/snippets/main_static.html index 077acdc6fe..e46c155a98 100644 --- a/bundles/org.openhab.ui.basic/src/main/resources/snippets/main_static.html +++ b/bundles/org.openhab.ui.basic/src/main/resources/snippets/main_static.html @@ -37,7 +37,7 @@
-
+
%content%
diff --git a/bundles/org.openhab.ui.basic/src/main/resources/snippets/sitemaps_list_item.html b/bundles/org.openhab.ui.basic/src/main/resources/snippets/sitemaps_list_item.html index 9748c653ee..a351249c8a 100644 --- a/bundles/org.openhab.ui.basic/src/main/resources/snippets/sitemaps_list_item.html +++ b/bundles/org.openhab.ui.basic/src/main/resources/snippets/sitemaps_list_item.html @@ -1,4 +1,4 @@ diff --git a/bundles/org.openhab.ui.basic/web-src/_layout.scss b/bundles/org.openhab.ui.basic/web-src/_layout.scss index 7631cd5495..f7635a4bd3 100644 --- a/bundles/org.openhab.ui.basic/web-src/_layout.scss +++ b/bundles/org.openhab.ui.basic/web-src/_layout.scss @@ -679,7 +679,7 @@ $colorpicker-mobile-size: 270px; padding-right: 6px; } a { - text-transform: capitalize; + // text-transform: capitalize; } } &__empty {