X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fpages%2FImageBrowserPage.kt;h=84634fc10922d744b1c6a2fa7e14eb9a76edbad0;hp=5e8701bbb6fb5803ecd15c58dff5948db662fd21;hb=369ba7692f167e5b7f9a27898a06a5d7920904ed;hpb=6f92f856b4b0afddc207d44a101eff41a403c933 diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/ImageBrowserPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/ImageBrowserPage.kt index 5e8701b..84634fc 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/ImageBrowserPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/ImageBrowserPage.kt @@ -2,29 +2,30 @@ package net.pterodactylus.sone.web.pages import net.pterodactylus.sone.data.Album import net.pterodactylus.sone.data.Sone -import net.pterodactylus.sone.utils.Pagination +import net.pterodactylus.sone.utils.paginate import net.pterodactylus.sone.utils.parameters import net.pterodactylus.sone.web.WebInterface import net.pterodactylus.sone.web.page.FreenetRequest import net.pterodactylus.util.template.Template import net.pterodactylus.util.template.TemplateContext import java.net.URI +import javax.inject.Inject /** * The image browser page is the entry page for the image management. */ -class ImageBrowserPage(template: Template, webInterface: WebInterface): - SoneTemplatePage("imageBrowser.html", template, "Page.ImageBrowser.Title", webInterface, true) { +class ImageBrowserPage @Inject constructor(template: Template, webInterface: WebInterface): + LoggedInPage("imageBrowser.html", template, "Page.ImageBrowser.Title", webInterface) { - override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) { - if ("album" in request.parameters) { + override fun handleRequest(freenetRequest: FreenetRequest, currentSone: Sone, templateContext: TemplateContext) { + if ("album" in freenetRequest.parameters) { templateContext["albumRequested"] = true - templateContext["album"] = webInterface.core.getAlbum(request.parameters["album"]!!) - templateContext["page"] = request.parameters["page"] - } else if ("image" in request.parameters) { + templateContext["album"] = webInterface.core.getAlbum(freenetRequest.parameters["album"]!!) + templateContext["page"] = freenetRequest.parameters["page"] + } else if ("image" in freenetRequest.parameters) { templateContext["imageRequested"] = true - templateContext["image"] = webInterface.core.getImage(request.parameters["image"]) - } else if (request.parameters["mode"] == "gallery") { + templateContext["image"] = webInterface.core.getImage(freenetRequest.parameters["image"]) + } else if (freenetRequest.parameters["mode"] == "gallery") { templateContext["galleryRequested"] = true webInterface.core.sones .map(Sone::getRootAlbum) @@ -33,17 +34,19 @@ class ImageBrowserPage(template: Template, webInterface: WebInterface): .filterNot(Album::isEmpty) .sortedBy(Album::getTitle) .also { albums -> - Pagination(albums, webInterface.core.preferences.imagesPerPage).apply { page = request.parameters["page"]?.toIntOrNull() ?: 0 }.also { pagination -> + albums.paginate(webInterface.core.preferences.imagesPerPage) + .turnTo(freenetRequest.parameters["page"]?.toIntOrNull() ?: 0) + .also { pagination -> templateContext["albumPagination"] = pagination templateContext["albums"] = pagination.items } } } else { templateContext["soneRequested"] = true - templateContext["sone"] = webInterface.core.getSone(request.httpRequest.getParam("sone")).orNull() ?: getCurrentSone(request.toadletContext) + templateContext["sone"] = webInterface.core.getSone(freenetRequest.httpRequest.getParam("sone")) ?: currentSone } } - override fun isLinkExcepted(link: URI?) = true + override fun isLinkExcepted(link: URI) = true }