X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FImageBrowserPage.java;h=60b22d5731ab9211a4cf26730d1648295230e0cd;hp=93d35b9b75bc26ac9f4f9685cf20825c4e2a758b;hb=0e8f7804ce344bdd69f5ecc7febe25a60a53561d;hpb=a47643aed43d118ca68044f95451bb5374cdb332 diff --git a/src/main/java/net/pterodactylus/sone/web/ImageBrowserPage.java b/src/main/java/net/pterodactylus/sone/web/ImageBrowserPage.java index 93d35b9..60b22d5 100644 --- a/src/main/java/net/pterodactylus/sone/web/ImageBrowserPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ImageBrowserPage.java @@ -1,5 +1,5 @@ /* - * Sone - ImageBrowserPage.java - Copyright © 2011–2012 David Roden + * Sone - ImageBrowserPage.java - Copyright © 2011–2013 David Roden * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,15 +17,24 @@ package net.pterodactylus.sone.web; +import static com.google.common.collect.FluentIterable.from; +import static net.pterodactylus.sone.data.Album.FLATTENER; +import static net.pterodactylus.sone.data.Album.NOT_EMPTY; +import static net.pterodactylus.sone.data.Album.TITLE_COMPARATOR; +import static net.pterodactylus.sone.utils.NumberParsers.parseInt; + import java.net.URI; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import com.google.common.base.Optional; + 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.template.Template; import net.pterodactylus.util.template.TemplateContext; @@ -60,9 +69,10 @@ public class ImageBrowserPage extends SoneTemplatePage { super.processTemplate(request, templateContext); String albumId = request.getHttpRequest().getParam("album", null); if (albumId != null) { - Album album = webInterface.getCore().getAlbum(albumId, false); + Album album = webInterface.getCore().getAlbum(albumId); templateContext.set("albumRequested", true); templateContext.set("album", album); + templateContext.set("page", request.getHttpRequest().getParam("page")); return; } String imageId = request.getHttpRequest().getParam("image", null); @@ -74,9 +84,9 @@ public class ImageBrowserPage extends SoneTemplatePage { } String soneId = request.getHttpRequest().getParam("sone", null); if (soneId != null) { - Sone sone = webInterface.getCore().getSone(soneId, false); + Optional sone = webInterface.getCore().getSone(soneId); templateContext.set("soneRequested", true); - templateContext.set("sone", sone); + templateContext.set("sone", sone.orNull()); return; } String mode = request.getHttpRequest().getParam("mode", null); @@ -84,10 +94,12 @@ public class ImageBrowserPage extends SoneTemplatePage { templateContext.set("galleryRequested", true); List albums = new ArrayList(); for (Sone sone : webInterface.getCore().getSones()) { - albums.addAll(sone.getAllAlbums()); + albums.addAll(from(sone.getRootAlbum().getAlbums()).transformAndConcat(FLATTENER).filter(NOT_EMPTY).toList()); } - Collections.sort(albums, Album.TITLE_COMPARATOR); - templateContext.set("albums", albums); + Collections.sort(albums, TITLE_COMPARATOR); + Pagination albumPagination = new Pagination(albums, 12).setPage(parseInt(request.getHttpRequest().getParam("page"), 0)); + templateContext.set("albumPagination", albumPagination); + templateContext.set("albums", albumPagination.getItems()); return; } Sone sone = getCurrentSone(request.getToadletContext(), false);