Add pagination to index page.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 21 Oct 2010 21:13:24 +0000 (23:13 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 21 Oct 2010 21:13:24 +0000 (23:13 +0200)
src/main/java/net/pterodactylus/sone/web/IndexPage.java
src/main/resources/static/css/sone.css
src/main/resources/templates/include/pagination.html [new file with mode: 0644]
src/main/resources/templates/index.html

index 47f2715..67d11c6 100644 (file)
@@ -24,6 +24,7 @@ import java.util.List;
 
 import net.pterodactylus.sone.data.Post;
 import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.util.collection.Pagination;
 import net.pterodactylus.util.template.Template;
 
 /**
@@ -68,7 +69,11 @@ public class IndexPage extends SoneTemplatePage {
                        }
 
                });
-               template.set("posts", allPosts);
+               int page = request.getHttpRequest().getIntParam("page", 0);
+               Pagination<Post> postPagination = new Pagination<Post>(allPosts, 25).setPage(page);
+               List<Post> postsOnPage = postPagination.getItems();
+               template.set("posts", postsOnPage);
+               template.set("pagination", postPagination);
        }
 
        //
index ea508ea..b2c5ff0 100644 (file)
@@ -333,6 +333,36 @@ textarea {
        position: absolute;
 }
 
+#sone .navigation {
+       text-align: center;
+}
+
+#sone .navigation .first a, #sone .navigation .previous a, #sone .navigation .next a, #sone .navigation .last a, #sone .navigation .first span, #sone .navigation .previous span, #sone .navigation .next span, #sone .navigation .last span {
+       display: block;
+       height: 1.5em;
+       padding: 0.5ex;
+       width: 3em;
+       border: solid 1px #ccc;
+       background-color: #f0f0ff;
+}
+
+#sone .navigation .first, #sone .navigation .previous {
+       float: left;
+}
+
+#sone .navigation .current-page, #sone .navigation .total-pages {
+       margin-top: 0.5ex;
+       display: inline;
+}
+
+#sone .navigation .total-pages:before {
+       content: '/ ';
+}
+
+#sone .navigation .next, #sone .navigation .last {
+       float: right;
+}
+
 #sone h1 {
        font-family: inherit;
        font-size: 200%;
diff --git a/src/main/resources/templates/include/pagination.html b/src/main/resources/templates/include/pagination.html
new file mode 100644 (file)
index 0000000..5601d97
--- /dev/null
@@ -0,0 +1,10 @@
+<%if pagination.necessary>
+       <div class="navigation">
+               <div class="first"><%if ! pagination.first><a href="<% request|change name=page value=0>">«</a><%else><span>«</span><%/if></div>
+               <div class="previous"><%if ! pagination.first><a href="<% request|change name=page key=pagination.previousPage>">‹</a><%else><span>‹</span><%/if></div>
+               <div class="current-page"><% pagination.pageNumber></div>
+               <div class="total-pages"><% pagination.pageCount></div>
+               <div class="last"><%if ! pagination.last><a href="<% request|change name=page key=pagination.lastPage>">»</a><%else><span>»</span><%/if></div>
+               <div class="next"><%if ! pagination.last><a href="<% request|change name=page key=pagination.nextPage>">›</a><%else><span>›</span><%/if></div>
+       </div>
+<%/if>
index 3bd914f..888cdb2 100644 (file)
@@ -3,11 +3,13 @@
        <h1><%= Page.Index.PostList.Title|l10n|html></h1>
 
        <div id="posts">
+               <%include include/pagination.html>
                <%foreach posts post postLoop>
                        <%include include/viewPost.html>
                <%foreachelse>
                        <div><%= Page.Index.PostList.Text.NoPostYet|l10n|html></div>
                <%/foreach>
+               <%include include/pagination.html>
        </div>
 
 <%include include/tail.html>