1 package net.pterodactylus.sone.web.pages
3 import net.pterodactylus.sone.data.Album
4 import net.pterodactylus.sone.data.Sone
5 import net.pterodactylus.sone.main.*
6 import net.pterodactylus.sone.utils.paginate
7 import net.pterodactylus.sone.utils.parameters
8 import net.pterodactylus.sone.web.WebInterface
9 import net.pterodactylus.sone.web.page.*
10 import net.pterodactylus.util.template.Template
11 import net.pterodactylus.util.template.TemplateContext
13 import javax.inject.Inject
16 * The image browser page is the entry page for the image management.
18 @MenuName("ImageBrowser")
19 class ImageBrowserPage @Inject constructor(template: Template, webInterface: WebInterface, loaders: Loaders):
20 LoggedInPage("imageBrowser.html", template, "Page.ImageBrowser.Title", webInterface, loaders) {
22 override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
23 if ("album" in soneRequest.parameters) {
24 templateContext["albumRequested"] = true
25 templateContext["album"] = soneRequest.core.getAlbum(soneRequest.parameters["album"]!!)
26 templateContext["page"] = soneRequest.parameters["page"]
27 } else if ("image" in soneRequest.parameters) {
28 templateContext["imageRequested"] = true
29 templateContext["image"] = soneRequest.core.getImage(soneRequest.parameters["image"])
30 } else if (soneRequest.parameters["mode"] == "gallery") {
31 templateContext["galleryRequested"] = true
32 soneRequest.core.sones
33 .map(Sone::getRootAlbum)
34 .flatMap(Album::getAlbums)
35 .flatMap { Album.FLATTENER.apply(it)!! }
36 .filterNot(Album::isEmpty)
37 .sortedBy(Album::getTitle)
39 albums.paginate(soneRequest.core.preferences.imagesPerPage)
40 .turnTo(soneRequest.parameters["page"]?.toIntOrNull() ?: 0)
42 templateContext["albumPagination"] = pagination
43 templateContext["albums"] = pagination.items
47 templateContext["soneRequested"] = true
48 templateContext["sone"] = soneRequest.core.getSone(soneRequest.httpRequest.getParam("sone")) ?: currentSone
52 override fun isLinkExcepted(link: URI) = true