Commit 8bfefcad authored by Jean-Baptiste Nizet's avatar Jean-Baptiste Nizet
Browse files

feat: add entries to the navbar

parent d37a30e3
......@@ -2,9 +2,11 @@ package fr.inra.urgi.faidare.web.thymeleaf;
import java.nio.charset.StandardCharsets;
import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.Base64;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.function.Function;
......@@ -24,7 +26,9 @@ public class FaidareExpressions {
private static final Map<String, Function<String, String>> TAXON_ID_URL_FACTORIES_BY_SOURCE_NAME =
createTaxonIdUrlFactories();
private static final ObjectMapper objectMapper = new ObjectMapper();
private static final List<NavbarEntry> NAVBAR_ENTRIES =
createNavbarEntries();
private static Map<String, Function<String, String>> createTaxonIdUrlFactories() {
Map<String, Function<String, String>> result = new HashMap<>();
......@@ -35,6 +39,23 @@ public class FaidareExpressions {
return Collections.unmodifiableMap(result);
}
private static List<NavbarEntry> createNavbarEntries() {
return Arrays.asList(
NavbarEntry.menu("URGI", Arrays.asList(
NavbarEntry.link("Home", "https://urgi.versailles.inra.fr"),
NavbarEntry.link("News", "https://urgi.versailles.inra.fr/About-us/News"),
NavbarEntry.link("About us", "https://urgi.versailles.inra.fr/About-us")
)),
NavbarEntry.menu("More...", Arrays.asList(
NavbarEntry.link("About", "https://urgi.versailles.inrae.fr/faidare/about"),
NavbarEntry.link("Join us", "https://urgi.versailles.inra.fr/faidare/join"),
NavbarEntry.link("Terms of use", "https://urgi.versailles.inra.fr/faidare/legal"),
NavbarEntry.link("Help", "https://urgi.versailles.inra.fr/faidare/help"),
NavbarEntry.link("News/Perspectives", "https://urgi.versailles.inra.fr/faidare/news")
))
);
}
private final Locale locale;
public FaidareExpressions(Locale locale) {
......@@ -59,13 +80,8 @@ public class FaidareExpressions {
return urlFactory != null ? urlFactory.apply(taxonSource.getTaxonId()) : null;
}
public String toJson(Object value) {
try {
return objectMapper.writeValueAsString(value);
}
catch (JsonProcessingException e) {
throw new IllegalArgumentException(e);
}
public List<NavbarEntry> navbarEntries() {
return NAVBAR_ENTRIES;
}
private String collPopTitle(CollPopVO collPopVO, Function<String, String> nameTransformer) {
......
package fr.inra.urgi.faidare.web.thymeleaf;
import java.util.Collections;
import java.util.List;
/**
* A navbar link
* @author JB Nizet
*/
public final class NavbarEntry {
private final String label;
private final String url;
private final List<NavbarEntry> subMenu;
private NavbarEntry(String label, String url, List<NavbarEntry> subMenu) {
this.label = label;
this.url = url;
this.subMenu = subMenu;
}
public static NavbarEntry link(String label, String url) {
return new NavbarEntry(label, url, Collections.emptyList());
}
public static NavbarEntry menu(String label, List<NavbarEntry> subMenu) {
return new NavbarEntry(label, null, subMenu);
}
public String getLabel() {
return label;
}
public String getUrl() {
return url;
}
public List<NavbarEntry> getSubMenu() {
return subMenu;
}
}
......@@ -14,7 +14,7 @@
<link
rel="shortcut icon"
th:href="@{/static/assets/images/favicon.ico}"
th:href="@{/assets/images/favicon.ico}"
type="image/x-icon"
/>
</head>
......@@ -22,9 +22,63 @@
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container">
<span class="navbar-brand py-0">
<a
class="navbar-brand py-0"
href="https://urgi.versailles.inrae.fr/faidare"
>
<img th:src="@{/assets/images/logo.png}" style="height: 40px" />
</span>
</a>
<button
class="navbar-toggler"
type="button"
data-bs-toggle="collapse"
data-bs-target="#navbarContent"
aria-controls="navbarContent"
aria-expanded="false"
aria-label="Toggle navigation"
>
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarContent">
<ul class="navbar-nav me-auto">
<th:block th:each="topEntry : ${#faidare.navbarEntries}">
<li class="nav-item" th:if="${#lists.isEmpty(topEntry.subMenu)}">
<a
class="nav-link"
th:href="${topEntry.url}"
th:text="${topEntry.label}"
></a>
</li>
<li
class="nav-item dropdown"
th:if="${not #lists.isEmpty(topEntry.subMenu)}"
>
<a
class="nav-link dropdown-toggle"
th:id="${'navbar-dropdown-' + topEntry.label}"
href="#"
role="button"
data-bs-toggle="dropdown"
aria-expanded="false"
th:text="${topEntry.label}"
>
</a>
<ul
class="dropdown-menu bg-light"
th:aria-labelledby="${'navbar-dropdown-' + topEntry.label}"
>
<li th:each="subEntry : ${topEntry.subMenu}" class="bg-light">
<a
class="dropdown-item"
th:href="${subEntry.url}"
th:text="${subEntry.label}"
></a>
</li>
</ul>
</li>
</th:block>
</ul>
</div>
</div>
</nav>
<div class="container mt-3">
......
......@@ -16,7 +16,7 @@
"license": "MIT",
"dependencies": {
"@types/leaflet": "1.7.5",
"bootstrap": "5.1.0",
"bootstrap": "5.1.1",
"leaflet": "1.7.1"
},
"devDependencies": {
......
import { Popover } from 'bootstrap';
import Popover from 'bootstrap/js/dist/popover';
export function initializePopovers() {
const popoverTriggerList: Array<HTMLElement> = [].slice.call(document.querySelectorAll('[data-bs-toggle="popover"]'));
......
import { initializePopovers } from './bootstrap/popovers';
import { initializeMap } from './map/map';
import 'bootstrap/js/dist/dropdown';
import 'bootstrap/js/dist/collapse';
(window as any).faidare = {
initializePopovers,
......
......@@ -372,10 +372,10 @@ boolbase@^1.0.0:
resolved "https://registry.yarnpkg.com/boolbase/-/boolbase-1.0.0.tgz#68dff5fbe60c51eb37725ea9e3ed310dcc1e776e"
integrity sha1-aN/1++YMUes3cl6p4+0xDcwed24=
bootstrap@5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/bootstrap/-/bootstrap-5.1.0.tgz#543ef8f44f4b9af67b0230f19508542fec38ef55"
integrity sha512-bs74WNI9BgBo3cEovmdMHikSKoXnDgA6VQjJ7TyTotU6L7d41ZyCEEelPwkYEzsG/Zjv3ie9IE3EMAje0W9Xew==
bootstrap@5.1.1:
version "5.1.1"
resolved "https://registry.yarnpkg.com/bootstrap/-/bootstrap-5.1.1.tgz#9d6eed81e08feaccedf3adaca51fe4b73a2871df"
integrity sha512-/jUa4sSuDZWlDLQ1gwQQR8uoYSvLJzDd8m5o6bPKh3asLAMYVZKdRCjb1joUd5WXf0WwCNzd2EjwQQhupou0dA==
brace-expansion@^1.1.7:
version "1.1.11"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment