From 0aac7c559d87de940238c91ff06c1d225d489ec5 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Sun, 26 Jan 2020 08:05:27 +0100 Subject: Add wiki page revision list. Change-Id: I21a6ff469ef4dbf64a8d77eb4626765ae43ed37e --- .../java/eu/mulk/mulkcms2/benki/wiki/WikiPage.java | 6 ++-- .../eu/mulk/mulkcms2/benki/wiki/WikiResource.java | 31 +++++++++++++++--- .../templates/benki/wiki/wikiPageRevisionList.html | 38 ++++++++++++++++++++++ 3 files changed, 68 insertions(+), 7 deletions(-) create mode 100644 src/main/resources/templates/benki/wiki/wikiPageRevisionList.html (limited to 'src/main') diff --git a/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiPage.java b/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiPage.java index dff7e69..9b40d5d 100644 --- a/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiPage.java +++ b/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiPage.java @@ -1,12 +1,13 @@ package eu.mulk.mulkcms2.benki.wiki; import io.quarkus.hibernate.orm.panache.PanacheEntityBase; -import java.util.Collection; +import java.util.List; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.Id; import javax.persistence.OneToMany; +import javax.persistence.OrderBy; import javax.persistence.Table; @Entity @@ -18,5 +19,6 @@ public class WikiPage extends PanacheEntityBase { public int id; @OneToMany(mappedBy = "page", fetch = FetchType.LAZY) - public Collection revisions; + @OrderBy("date desc") + public List revisions; } diff --git a/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiResource.java b/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiResource.java index 714b785..a8d7db4 100644 --- a/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiResource.java +++ b/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiResource.java @@ -13,7 +13,6 @@ import io.smallrye.jwt.auth.principal.JWTCallerPrincipal; import java.time.format.DateTimeFormatter; import java.time.format.FormatStyle; import java.time.temporal.TemporalAccessor; -import java.util.Map; import java.util.Optional; import javax.inject.Inject; import javax.ws.rs.GET; @@ -39,6 +38,10 @@ public class WikiResource { @Inject Template wikiPage; + @ResourcePath("benki/wiki/wikiPageRevisionList.html") + @Inject + Template wikiPageRevisionList; + @Inject SecurityIdentity identity; @GET @@ -47,9 +50,7 @@ public class WikiResource { public TemplateInstance getPage(@PathParam("pageName") String pageName) { Optional maybePage = WikiPageRevision.find( - "from WikiPageRevision rev" - + " join fetch rev.author" - + " where rev.title = ?1", + "from WikiPageRevision rev" + " join fetch rev.author" + " where rev.title = ?1", Sort.by("date").descending(), pageName) .firstResultOptional(); @@ -75,7 +76,27 @@ public class WikiResource { @Path("/{pageName}/revisions") @Produces(TEXT_HTML) public TemplateInstance getPageRevisions(@PathParam("pageName") String pageName) { - throw new NotImplementedYetException(); + Optional maybePrimaryRevision = + WikiPageRevision.find( + "from WikiPageRevision rev" + " join fetch rev.author" + " where rev.title = ?1", + Sort.by("date").descending(), + pageName) + .firstResultOptional(); + if (maybePrimaryRevision.isEmpty()) { + throw new NotFoundException(); + } + var primaryRevision = maybePrimaryRevision.get(); + + WikiPage page = + WikiPageRevision.find( + "from WikiPage p" + + " join fetch p.revisions rev" + + " join fetch rev.author" + + " where p.id = ?1", + primaryRevision.page.id) + .singleResult(); + + return wikiPageRevisionList.data("page", page).data("title", pageName); } @TemplateExtension diff --git a/src/main/resources/templates/benki/wiki/wikiPageRevisionList.html b/src/main/resources/templates/benki/wiki/wikiPageRevisionList.html new file mode 100644 index 0000000..c44a6e5 --- /dev/null +++ b/src/main/resources/templates/benki/wiki/wikiPageRevisionList.html @@ -0,0 +1,38 @@ +{@eu.mulk.mulkcms2.benki.wiki.WikiPage page} +{@java.lang.String title} + +{#include base.html} + +{#title}Revisions — {title} — Benki Wiki{/title} + +{#body} +
+

Revisions — {title}

+
+ +
+ + + + + + + + + + + {#with page} + {#for revision in revisions} + {#with revision} + {date.humanDateTime} + {title} + {author.firstName} + {/with} + {/for} + {/with} + +
DateTitleAuthor
+
+{/body} + +{/include} -- cgit v1.2.3