Paginate images in gallery mode.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 30 May 2012 11:39:49 +0000 (13:39 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 30 May 2012 11:39:49 +0000 (13:39 +0200)
src/main/java/net/pterodactylus/sone/web/ImageBrowserPage.java
src/main/resources/templates/imageBrowser.html

index 93d35b9..a6d3daf 100644 (file)
@@ -26,6 +26,8 @@ import net.pterodactylus.sone.data.Album;
 import net.pterodactylus.sone.data.Image;
 import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.web.page.FreenetRequest;
+import net.pterodactylus.util.collection.Pagination;
+import net.pterodactylus.util.number.Numbers;
 import net.pterodactylus.util.template.Template;
 import net.pterodactylus.util.template.TemplateContext;
 
@@ -87,7 +89,9 @@ public class ImageBrowserPage extends SoneTemplatePage {
                                albums.addAll(sone.getAllAlbums());
                        }
                        Collections.sort(albums, Album.TITLE_COMPARATOR);
-                       templateContext.set("albums", albums);
+                       Pagination<Album> albumPagination = new Pagination<Album>(albums, 12).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("page"), 0));
+                       templateContext.set("albumPagination", albumPagination);
+                       templateContext.set("albums", albumPagination.getItems());
                        return;
                }
                Sone sone = getCurrentSone(request.getToadletContext(), false);
index 55705e1..2d94de0 100644 (file)
        <%elseif galleryRequested>
 
                <%foreach albums album>
-                       <%first><h2><%= Page.ImageBrowser.Header.Albums|l10n|html></h2><%/first>
+                       <%first>
+                               <h2><%= Page.ImageBrowser.Header.Albums|l10n|html></h2>
+                               <%include include/pagination.html pagination=albumPagination pageParameter=="page">
+                       <%/first>
                        <%if loop.count|mod divisor=3><div class="album-row"><%/if>
                        <div id="album-<% album.id|html>" class="album">
                                <div class="album-id hidden"><% album.id|html></div>
                        <%= false|store key=endRow>
                        <%if loop.count|mod divisor=3 offset=1><%= true|store key=endRow><%/if>
                        <%last><%= true|store key=endRow><%/last>
-                       <%if endRow></div><%/if>
+                       <%if endRow>
+                               </div>
+                               <%include include/pagination.html pagination=albumPagination pageParameter=="page">
+                       <%/if>
                <%/foreach>
 
        <%/if>