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] Prefer sitemap label to name in sitemap selection #2110

Merged
merged 1 commit into from
Oct 6, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,16 @@ public void setConfig(WebAppConfig config) {
}

public CharSequence renderSitemapList(Set<SitemapProvider> sitemapProviders) throws RenderException {
List<String> sitemapList = new LinkedList<String>();
List<Sitemap> sitemapList = new LinkedList<>();

for (SitemapProvider sitemapProvider : sitemapProviders) {
Set<String> 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);
}
}
}
}
Expand All @@ -241,8 +244,31 @@ public CharSequence renderSitemapList(Set<SitemapProvider> 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));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</div>
</header>
<main class="mdl-layout__content">
<div class="page-content page-static__content mdl-color--white mdl-shadow--2dp mdl-grid">
<div class="page-content page-static__content mdl-shadow--2dp mdl-grid">
%content%
</div>
</main>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="welcome-sitemaps__sitemap">
<i class='material-icons'>&#xe85a;</i>
<a href='/basicui/app?sitemap=%sitemap%'>%sitemap%</a>
<a href='/basicui/app?sitemap=%name%'>%label%</a>
</div>
2 changes: 1 addition & 1 deletion bundles/org.openhab.ui.basic/web-src/_layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ $colorpicker-mobile-size: 270px;
padding-right: 6px;
}
a {
text-transform: capitalize;
// text-transform: capitalize;
}
}
&__empty {
Expand Down