From 7c40a9750dd97d77f57f4cbf83b9a13d8dfc1938 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 1 Apr 2011 22:51:05 +0200 Subject: [PATCH] Use better way to paginate the posts. --- .../net/pterodactylus/sone/web/ViewSonePage.java | 6 +++++- src/main/resources/templates/viewSone.html | 25 +++++++++++----------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/web/ViewSonePage.java b/src/main/java/net/pterodactylus/sone/web/ViewSonePage.java index 3f4d92d..cd79e43 100644 --- a/src/main/java/net/pterodactylus/sone/web/ViewSonePage.java +++ b/src/main/java/net/pterodactylus/sone/web/ViewSonePage.java @@ -65,6 +65,10 @@ public class ViewSonePage extends SoneTemplatePage { String soneId = request.getHttpRequest().getParam("sone"); Sone sone = webInterface.getCore().getSone(soneId, false); templateContext.set("sone", sone); + List sonePosts = sone.getPosts(); + Pagination postPagination = new Pagination(sonePosts, 10).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("postPage"), 0)); + templateContext.set("postPagination", postPagination); + templateContext.set("posts", postPagination.getItems()); Set replies = sone.getReplies(); final Map> repliedPosts = new HashMap>(); for (Reply reply : replies) { @@ -100,7 +104,7 @@ public class ViewSonePage extends SoneTemplatePage { return; } webInterface.getCore().markSoneKnown(sone); - List posts = sone.getPosts(); + List posts = (List) templateContext.get("posts"); posts.addAll((List) templateContext.get("repliedPosts")); for (Post post : posts) { if (post.getSone() != null) { diff --git a/src/main/resources/templates/viewSone.html b/src/main/resources/templates/viewSone.html index 830b999..066adef 100644 --- a/src/main/resources/templates/viewSone.html +++ b/src/main/resources/templates/viewSone.html @@ -60,18 +60,19 @@

<%= Page.ViewSone.PostList.Title|l10n|replace needle="{sone}" replacementKey=sone.niceName|html>

-
- <%:getpage parameter=postPage> - <%:paginate list=sone.posts pagesize=10> - <%= postPage|store key=pageParameter> - <%include include/pagination.html> - <%foreach pagination.items post> - <%include include/viewPost.html> - <%foreachelse> -
<%= Page.ViewSone.PostList.Text.NoPostYet|l10n|html>
- <%/foreach> - <%include include/pagination.html> -
+ <%foreach posts post> + <%first> +
+ <%include include/pagination.html pagination=postPagination pageParameter==postPage> + <%/first> + <%include include/viewPost.html> + <%last> + <%include include/pagination.html pagination=postPagination pageParameter==postPage> +
+ <%/last> + <%foreachelse> +
<%= Page.ViewSone.PostList.Text.NoPostYet|l10n|html>
+ <%/foreach> <%foreach repliedPosts post> <%first> -- 2.7.4