Use generic page template for bookmark and lazy chat lists.
Change-Id: I86cc78c8164d6672d8b5cfbc2a3433954068967e
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/Bookmark.java b/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/Bookmark.java
index 8beda97..ea62af3 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/Bookmark.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/Bookmark.java
@@ -56,4 +56,14 @@
@CheckForNull Integer count) {
return findViewable(Bookmark.class, session, viewer, owner, cursor, count);
}
+
+ @Override
+ public boolean isBookmark() {
+ return true;
+ }
+
+ @Override
+ public boolean isLazychatMessage() {
+ return false;
+ }
}
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/BookmarkResource.java b/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/BookmarkResource.java
index 1f57c74..d026a1a 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/BookmarkResource.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/BookmarkResource.java
@@ -75,9 +75,9 @@
@ConfigProperty(name = "mulkcms.bookmarks.default-max-results")
int defaultMaxResults;
- @ResourcePath("benki/bookmarks/bookmarkList.html")
+ @ResourcePath("benki/posts/postList.html")
@Inject
- Template bookmarkList;
+ Template postList;
@ResourcePath("benki/bookmarks/newBookmark.html")
@Inject
@@ -104,9 +104,11 @@
var session = entityManager.unwrap(Session.class);
var q = Bookmark.findViewable(session, identity, null, cursor, maxResults);
- return bookmarkList
+ return postList
.data("posts", q.posts)
.data("feedUri", "/bookmarks/feed")
+ .data("pageTitle", "Bookmarks")
+ .data("showBookmarkForm", false)
.data("authenticated", !identity.isAnonymous())
.data("hasPreviousPage", q.prevCursor != null)
.data("hasNextPage", q.nextCursor != null)
@@ -129,9 +131,11 @@
var session = entityManager.unwrap(Session.class);
var q = Bookmark.findViewable(session, identity, owner, cursor, maxResults);
- return bookmarkList
+ return postList
.data("posts", q.posts)
.data("feedUri", String.format("/bookmarks/~%s/feed", ownerName))
+ .data("pageTitle", "Bookmarks")
+ .data("showBookmarkForm", false)
.data("authenticated", !identity.isAnonymous())
.data("hasPreviousPage", q.prevCursor != null)
.data("hasNextPage", q.nextCursor != null)
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/generic/Post.java b/src/main/java/eu/mulk/mulkcms2/benki/generic/Post.java
index 898eeb4..7d75bb4 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/generic/Post.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/generic/Post.java
@@ -75,6 +75,10 @@
inverseJoinColumns = @JoinColumn(name = "target"))
public Set<Role> targets;
+ public abstract boolean isBookmark();
+
+ public abstract boolean isLazychatMessage();
+
protected static <T extends Post> CriteriaQuery<T> queryViewable(
Class<T> entityClass,
SecurityIdentity readerIdentity,
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatMessage.java b/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatMessage.java
index 4e58259..4c7f6a0 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatMessage.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatMessage.java
@@ -46,4 +46,14 @@
@CheckForNull Integer count) {
return findViewable(LazychatMessage.class, session, viewer, owner, cursor, count);
}
+
+ @Override
+ public boolean isBookmark() {
+ return false;
+ }
+
+ @Override
+ public boolean isLazychatMessage() {
+ return true;
+ }
}
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatResource.java b/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatResource.java
index 4284d96..cb89e71 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatResource.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatResource.java
@@ -40,9 +40,9 @@
@ConfigProperty(name = "mulkcms.lazychat.default-max-results")
int defaultMaxResults;
- @ResourcePath("benki/lazychat/lazychatList.html")
+ @ResourcePath("benki/posts/postList.html")
@Inject
- Template lazychatList;
+ Template postList;
@Inject SecurityIdentity identity;
@@ -59,9 +59,10 @@
var session = entityManager.unwrap(Session.class);
var q = LazychatMessage.findViewable(session, identity, null, cursor, maxResults);
- return lazychatList
+ return postList
.data("posts", q.posts)
- .data("authenticated", !identity.isAnonymous())
+ .data("pageTitle", "Lazy Chat")
+ .data("showBookmarkForm", false)
.data("hasPreviousPage", q.prevCursor != null)
.data("hasNextPage", q.nextCursor != null)
.data("previousCursor", q.prevCursor)
@@ -83,9 +84,10 @@
var session = entityManager.unwrap(Session.class);
var q = LazychatMessage.findViewable(session, identity, owner, cursor, maxResults);
- return lazychatList
+ return postList
.data("posts", q.posts)
- .data("authenticated", !identity.isAnonymous())
+ .data("pageTitle", "Lazy Chat")
+ .data("showBookmarkForm", false)
.data("hasPreviousPage", q.prevCursor != null)
.data("hasNextPage", q.nextCursor != null)
.data("previousCursor", q.prevCursor)
diff --git a/src/main/resources/templates/base.html b/src/main/resources/templates/base.html
index 0d4408c..9a1ba04 100644
--- a/src/main/resources/templates/base.html
+++ b/src/main/resources/templates/base.html
@@ -18,12 +18,7 @@
</header>
<nav>
- <ol>
- <li class="{#insert bookmarksClass}{/}" data-site-section="Book Marx"><a href="/bookmarks">Bookmarks</a></li>
- <li class="{#insert lazychatClass}{/}" data-site-section="Lafargue"><a href="/lazychat">Lazy Chat</a></li>
- <li class="{#insert wikiClass}{/}" data-site-section="Wiki"><a href="/wiki/Home">Wiki</a></li>
- <li class="{#insert aboutClass}{/}" data-site-section="About"><a href="/about">Contact Info</a></li>
- </ol>
+ {#insert nav}{/}
</nav>
<main>
diff --git a/src/main/resources/templates/benki/about/index.html b/src/main/resources/templates/benki/about/index.html
index 520644e..edfd82e 100644
--- a/src/main/resources/templates/benki/about/index.html
+++ b/src/main/resources/templates/benki/about/index.html
@@ -6,6 +6,8 @@
{#siteSection}About This Site{/siteSection}
{#aboutClass}this-page{/aboutClass}
+{#nav}{#navbar siteSection="About" /}{/nav}
+
{#head}{/head}
{#body}
diff --git a/src/main/resources/templates/benki/bookmarks/bookmarkList.html b/src/main/resources/templates/benki/bookmarks/bookmarkList.html
deleted file mode 100644
index 8c87a55..0000000
--- a/src/main/resources/templates/benki/bookmarks/bookmarkList.html
+++ /dev/null
@@ -1,68 +0,0 @@
-{@java.util.List<eu.mulk.mulkcms2.benki.bookmarks.Bookmark> posts}
-{@java.lang.Boolean authenticated}
-{@java.lang.Boolean hasPreviousPage}
-{@java.lang.Boolean hasNextPage}
-{@java.lang.Integer previousCursor}
-{@java.lang.Integer nextCursor}
-{@java.lang.Integer pageSize}
-
-{#include base.html}
-
-{#title}Benki Bookmarks{/title}
-{#siteSection}Bookmarks{/siteSection}
-{#bookmarksClass}this-page{/bookmarksClass}
-
-{#head}
- <link href="{feedUri}" rel="alternate" type="application/atom+xml" />
-
- <script type="module" src="/web_modules/elix/define/ExpandableSection.js"></script>
- <script type="module" src="/bookmarks/MlkBookmarkSubmissionForm.js"></script>
- <script type="module" src="/bookmarks/bookmarkList.js" defer></script>
-{/head}
-
-{#body}
-
-{! #if authenticated !}
- <elix-expandable-section id="bookmark-submission-pane">
- <h2 slot="header" class="small-title expandable-section-title"><button class="pure-button">Create New Bookmark</button></h2>
- <section id="bookmark-submission">
- <mlk-bookmark-submission-form id="bookmark-submission-form"></mlk-bookmark-submission-form>
- </section>
- </elix-expandable-section>
-{! /if !}
-
-<div class="paging">
- {#if hasPreviousPage}<a href="?i={previousCursor}&n={pageSize}" class="pure-button">⇠ previous page</a>{/if}
- <span class="filler"></span>
- {#if hasNextPage}<a href="?i={nextCursor}&n={pageSize}" class="pure-button">next page ⇢</a>{/if}
-</div>
-
-<section id="main-content">
- {#for post in posts}
- {#with post}
- <article class="bookmark">
- <header>
- <a href="{uri}"><h1 class="bookmark-title">{title}</h1></a>
- <div class="bookmark-info">
- <time datetime="{date.htmlDateTime}">{date.humanDateTime}</time>
- <span class="bookmark-owner">{owner.firstName} {owner.lastName}</span>
- </div>
- </header>
-
- <section class="bookmark-description">
- {descriptionHtml.raw}
- </section>
- </article>
- {/with}
- {/for}
-</section>
-
-<div class="paging">
- {#if hasPreviousPage}<a href="?i={previousCursor}&n={pageSize}" class="pure-button">⇠ previous page</a>{/if}
- <span class="filler"></span>
- {#if hasNextPage}<a href="?i={nextCursor}&n={pageSize}" class="pure-button">next page ⇢</a>{/if}
-</div>
-
-{/body}
-
-{/include}
diff --git a/src/main/resources/templates/benki/lazychat/lazychatList.html b/src/main/resources/templates/benki/lazychat/lazychatList.html
deleted file mode 100644
index b644662..0000000
--- a/src/main/resources/templates/benki/lazychat/lazychatList.html
+++ /dev/null
@@ -1,52 +0,0 @@
-{@java.util.List<eu.mulk.mulkcms2.benki.lazychat.LazychatMessage> posts}
-{@java.lang.Boolean authenticated}
-{@java.lang.Boolean hasPreviousPage}
-{@java.lang.Boolean hasNextPage}
-{@java.lang.Integer previousCursor}
-{@java.lang.Integer nextCursor}
-{@java.lang.Integer pageSize}
-
-{#include base.html}
-
-{#title}Benki Lazychat{/title}
-{#siteSection}Lazychat{/siteSection}
-{#lazychatClass}this-page{/lazychatClass}
-
-{#head}{/head}
-
-{#body}
-
-<div class="paging">
- {#if hasPreviousPage}<a href="?i={previousCursor}&n={pageSize}" class="pure-button">⇠ previous page</a>{/if}
- <span class="filler"></span>
- {#if hasNextPage}<a href="?i={nextCursor}&n={pageSize}" class="pure-button">next page ⇢</a>{/if}
-</div>
-
-<section id="main-content">
- {#for post in posts}
- {#with post}
- <article class="lazychat-message">
- <header>
- <div class="lazychat-message-info">
- <time datetime="{date.htmlDateTime}">{date.humanDateTime}</time>
- <span class="lazychat-message-owner">{owner.firstName} {owner.lastName}</span>
- </div>
- </header>
-
- <section class="lazychat-message-content">
- {contentHtml.raw}
- </section>
- </article>
- {/with}
- {/for}
-</section>
-
-<div class="paging">
- {#if hasPreviousPage}<a href="?i={previousCursor}&n={pageSize}" class="pure-button">⇠ previous page</a>{/if}
- <span class="filler"></span>
- {#if hasNextPage}<a href="?i={nextCursor}&n={pageSize}" class="pure-button">next page ⇢</a>{/if}
-</div>
-
-{/body}
-
-{/include}
diff --git a/src/main/resources/templates/benki/posts/postList.html b/src/main/resources/templates/benki/posts/postList.html
new file mode 100644
index 0000000..b68f796
--- /dev/null
+++ b/src/main/resources/templates/benki/posts/postList.html
@@ -0,0 +1,85 @@
+{@java.util.List<eu.mulk.mulkcms2.benki.bookmarks.Bookmark> posts}
+{@java.lang.String pageTitle}
+{@java.lang.Boolean showBookmarkForm}
+{@java.lang.Boolean hasPreviousPage}
+{@java.lang.Boolean hasNextPage}
+{@java.lang.Integer previousCursor}
+{@java.lang.Integer nextCursor}
+{@java.lang.Integer pageSize}
+
+{#include base.html}
+
+{#title}Benki {pageTitle}{/title}
+{#siteSection}{pageTitle}{/siteSection}
+
+{#nav}{#navbar siteSection=pageTitle /}{/nav}
+
+{#head}
+ <link href="{feedUri}" rel="alternate" type="application/atom+xml" />
+
+ <script type="module" src="/web_modules/elix/define/ExpandableSection.js"></script>
+ <script type="module" src="/bookmarks/MlkBookmarkSubmissionForm.js"></script>
+ <script type="module" src="/bookmarks/bookmarkList.js" defer></script>
+{/head}
+
+{#body}
+
+{#if showBookmarkForm}
+ <elix-expandable-section id="bookmark-submission-pane">
+ <h2 slot="header" class="small-title expandable-section-title"><button class="pure-button">Create New Bookmark</button></h2>
+ <section id="bookmark-submission">
+ <mlk-bookmark-submission-form id="bookmark-submission-form"></mlk-bookmark-submission-form>
+ </section>
+ </elix-expandable-section>
+{/if}
+
+<div class="paging">
+ {#if hasPreviousPage}<a href="?i={previousCursor}&n={pageSize}" class="pure-button">⇠ previous page</a>{/if}
+ <span class="filler"></span>
+ {#if hasNextPage}<a href="?i={nextCursor}&n={pageSize}" class="pure-button">next page ⇢</a>{/if}
+</div>
+
+<section id="main-content">
+ {#for post in posts}
+ {#with post}
+ {#if post.isBookmark}
+ <article class="bookmark">
+ <header>
+ <a href="{uri}"><h1 class="bookmark-title">{title}</h1></a>
+ <div class="bookmark-info">
+ <time datetime="{date.htmlDateTime}">{date.humanDateTime}</time>
+ <span class="bookmark-owner">{owner.firstName} {owner.lastName}</span>
+ </div>
+ </header>
+
+ <section class="bookmark-description">
+ {descriptionHtml.raw}
+ </section>
+ </article>
+ {#else}
+ <article class="lazychat-message">
+ <header>
+ <div class="lazychat-message-info">
+ <time datetime="{date.htmlDateTime}">{date.humanDateTime}</time>
+ <span class="lazychat-message-owner">{owner.firstName} {owner.lastName}</span>
+ </div>
+ </header>
+
+ <section class="lazychat-message-content">
+ {contentHtml.raw}
+ </section>
+ </article>
+ {/if}
+ {/with}
+ {/for}
+</section>
+
+<div class="paging">
+ {#if hasPreviousPage}<a href="?i={previousCursor}&n={pageSize}" class="pure-button">⇠ previous page</a>{/if}
+ <span class="filler"></span>
+ {#if hasNextPage}<a href="?i={nextCursor}&n={pageSize}" class="pure-button">next page ⇢</a>{/if}
+</div>
+
+{/body}
+
+{/include}
diff --git a/src/main/resources/templates/benki/wiki/wikiPage.html b/src/main/resources/templates/benki/wiki/wikiPage.html
index c5155bc..a98b147 100644
--- a/src/main/resources/templates/benki/wiki/wikiPage.html
+++ b/src/main/resources/templates/benki/wiki/wikiPage.html
@@ -6,6 +6,8 @@
{#siteSection}Wiki{/siteSection}
{#wikiClass}this-page{/wikiClass}
+{#nav}{#navbar siteSection="Wiki" /}{/nav}
+
{#head}
<link rel="stylesheet" type="text/css" href="/web_modules/ContentTools/build/content-tools.min.css" />
<script type="module" src="/web_modules/elix/define/ExpandablePanel.js" defer></script>
diff --git a/src/main/resources/templates/benki/wiki/wikiPageRevisionList.html b/src/main/resources/templates/benki/wiki/wikiPageRevisionList.html
index 2fd04eb..91e5058 100644
--- a/src/main/resources/templates/benki/wiki/wikiPageRevisionList.html
+++ b/src/main/resources/templates/benki/wiki/wikiPageRevisionList.html
@@ -7,6 +7,8 @@
{#siteSection}Wiki{/siteSection}
{#wikiClass}this-page{/wikiClass}
+{#nav}{#navbar siteSection="Wiki" /}{/nav}
+
{#body}
<header>
<h1>Revisions — <a href="/wiki/{title}">{title}</a></h1>
diff --git a/src/main/resources/templates/tags/navbar.html b/src/main/resources/templates/tags/navbar.html
new file mode 100644
index 0000000..b3d12d8
--- /dev/null
+++ b/src/main/resources/templates/tags/navbar.html
@@ -0,0 +1,6 @@
+<ol>
+ <li class='{#if siteSection == "Bookmarks"}this-page{/}' data-site-section="Bookmarks"><a href="/bookmarks">Bookmarks</a></li>
+ <li class='{#if siteSection == "Lazy Chat"}this-page{/}' data-site-section="Lazy Chat"><a href="/lazychat">Lazy Chat</a></li>
+ <li class='{#if siteSection == "Wiki"}this-page{/}' data-site-section="Wiki"><a href="/wiki/Home">Wiki</a></li>
+ <li class='{#if siteSection == "About"}this-page{/}' data-site-section="About"><a href="/about">Contact Info</a></li>
+</ol>