Mark Sones as known on “view Sone” and “known Sones” pages, move pagination out of...
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 17 Jan 2011 09:55:52 +0000 (10:55 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 17 Jan 2011 09:55:52 +0000 (10:55 +0100)
src/main/java/net/pterodactylus/sone/web/KnownSonesPage.java
src/main/java/net/pterodactylus/sone/web/ViewSonePage.java
src/main/resources/templates/knownSones.html

index 774f410..a2ebc66 100644 (file)
@@ -22,6 +22,8 @@ import java.util.Collections;
 import java.util.List;
 
 import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.util.collection.Pagination;
+import net.pterodactylus.util.number.Numbers;
 import net.pterodactylus.util.template.DataProvider;
 import net.pterodactylus.util.template.Template;
 
@@ -56,7 +58,22 @@ public class KnownSonesPage extends SoneTemplatePage {
                super.processTemplate(request, dataProvider);
                List<Sone> knownSones = new ArrayList<Sone>(webInterface.getCore().getSones());
                Collections.sort(knownSones, Sone.NICE_NAME_COMPARATOR);
-               dataProvider.set("knownSones", knownSones);
+               Pagination<Sone> sonePagination = new Pagination<Sone>(knownSones, 25).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("page"), 0));
+               dataProvider.set("pagination", sonePagination);
+               dataProvider.set("knownSones", sonePagination.getItems());
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       protected void postProcess(Request request, DataProvider dataProvider) {
+               super.postProcess(request, dataProvider);
+               @SuppressWarnings("unchecked")
+               List<Sone> sones = (List<Sone>) dataProvider.get("knownSones");
+               for (Sone sone : sones) {
+                       webInterface.getCore().markSoneKnown(sone);
+               }
        }
 
 }
index 9746afd..e9810a6 100644 (file)
@@ -68,6 +68,7 @@ public class ViewSonePage extends SoneTemplatePage {
                if (sone == null) {
                        return;
                }
+               webInterface.getCore().markSoneKnown(sone);
                List<Post> posts = sone.getPosts();
                for (Post post : posts) {
                        webInterface.getCore().markPostKnown(post);
index f5907a0..33f0e27 100644 (file)
@@ -5,8 +5,6 @@
        <h1><%= Page.KnownSones.Page.Title|l10n|html></h1>
 
        <div id="known-sones">
-               <%getpage parameter=page>
-               <%paginate list=knownSones pagesize=25>
                <%= page|store key=pageParameter>
                <%include include/pagination.html>
                <%foreach pagination.items sone>