From 371164a188b93b24f33cb5badb0362ac2544d33d Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Mon, 23 Mar 2020 06:21:25 +0100 Subject: Use generic page template for bookmark and lazy chat lists. Change-Id: I86cc78c8164d6672d8b5cfbc2a3433954068967e --- .../java/eu/mulk/mulkcms2/benki/bookmarks/Bookmark.java | 10 ++++++++++ .../eu/mulk/mulkcms2/benki/bookmarks/BookmarkResource.java | 12 ++++++++---- src/main/java/eu/mulk/mulkcms2/benki/generic/Post.java | 4 ++++ .../eu/mulk/mulkcms2/benki/lazychat/LazychatMessage.java | 10 ++++++++++ .../eu/mulk/mulkcms2/benki/lazychat/LazychatResource.java | 14 ++++++++------ 5 files changed, 40 insertions(+), 10 deletions(-) (limited to 'src/main/java/eu') 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 @@ public class Bookmark extends Post { @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 @@ public class BookmarkResource { @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 @@ public class BookmarkResource { 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 @@ public class BookmarkResource { 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 @@ public abstract class Post extends PanacheEntityBase { inverseJoinColumns = @JoinColumn(name = "target")) public Set targets; + public abstract boolean isBookmark(); + + public abstract boolean isLazychatMessage(); + protected static CriteriaQuery queryViewable( Class 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 @@ public class LazychatMessage extends Post { @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 @@ public class LazychatResource { @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 @@ public class LazychatResource { 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 @@ public class LazychatResource { 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) -- cgit v1.2.3