X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2FImageBrowserPage.java;h=a6d3dafc429c47dd78e758d884dad5329953de54;hp=a53ccc70247613385646ee59e396bc8d2f458a7c;hb=6f87b531e0bf13a96f4b596a36a098e9b8d3878a;hpb=7034cd9a2616e1c377d4db35371a8056bd29e120 diff --git a/src/main/java/net/pterodactylus/sone/web/ImageBrowserPage.java b/src/main/java/net/pterodactylus/sone/web/ImageBrowserPage.java index a53ccc7..a6d3daf 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 David Roden + * Sone - ImageBrowserPage.java - Copyright © 2011–2012 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,10 +17,19 @@ package net.pterodactylus.sone.web; +import java.net.URI; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + import net.pterodactylus.sone.data.Album; import net.pterodactylus.sone.data.Image; -import net.pterodactylus.util.template.DataProvider; +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; /** * The image browser page is the entry page for the image management. @@ -49,20 +58,53 @@ public class ImageBrowserPage extends SoneTemplatePage { * {@inheritDoc} */ @Override - protected void processTemplate(Request request, DataProvider dataProvider) throws RedirectException { - super.processTemplate(request, dataProvider); + protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { + super.processTemplate(request, templateContext); String albumId = request.getHttpRequest().getParam("album", null); if (albumId != null) { Album album = webInterface.getCore().getAlbum(albumId, false); - dataProvider.set("wantedItem", "album"); - dataProvider.set("album", album); + templateContext.set("albumRequested", true); + templateContext.set("album", album); return; } String imageId = request.getHttpRequest().getParam("image", null); if (imageId != null) { Image image = webInterface.getCore().getImage(imageId, false); - dataProvider.set("wantedItem", "image"); - dataProvider.set("image", image); + templateContext.set("imageRequested", true); + templateContext.set("image", image); + return; + } + String soneId = request.getHttpRequest().getParam("sone", null); + if (soneId != null) { + Sone sone = webInterface.getCore().getSone(soneId, false); + templateContext.set("soneRequested", true); + templateContext.set("sone", sone); + return; } + String mode = request.getHttpRequest().getParam("mode", null); + if ("gallery".equals(mode)) { + templateContext.set("galleryRequested", true); + List albums = new ArrayList(); + for (Sone sone : webInterface.getCore().getSones()) { + albums.addAll(sone.getAllAlbums()); + } + Collections.sort(albums, Album.TITLE_COMPARATOR); + Pagination albumPagination = new Pagination(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); + templateContext.set("soneRequested", true); + templateContext.set("sone", sone); } + + /** + * {@inheritDoc} + */ + @Override + public boolean isLinkExcepted(URI link) { + return true; + } + }