X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fpages%2FKnownSonesPage.kt;h=92a856aca2043d40fe14ca4152bfb07a54f86b1b;hp=9d6930d84d81e4ded76fda3bb305713c2124d7c1;hb=1557106d0e373f7efc15faed65f69eb567613a45;hpb=3cb0e2c78bb37f2d70ecde92ad4fcf642de788a3 diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/KnownSonesPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/KnownSonesPage.kt index 9d6930d..92a856a 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/KnownSonesPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/KnownSonesPage.kt @@ -1,22 +1,23 @@ package net.pterodactylus.sone.web.pages 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 javax.inject.Inject /** * This page shows all known Sones. */ -class KnownSonesPage(template: Template, webInterface: WebInterface): - SoneTemplatePage("knownSones.html", template, "Page.KnownSones.Title", webInterface, false) { +class KnownSonesPage @Inject constructor(template: Template, webInterface: WebInterface): + SoneTemplatePage("knownSones.html", webInterface, template, "Page.KnownSones.Title") { override fun handleRequest(freenetRequest: FreenetRequest, templateContext: TemplateContext) { getCurrentSone(freenetRequest.toadletContext).let { currentSone -> - Pagination(webInterface.core.sones + webInterface.core.sones.asSequence() .filterNot { freenetRequest.parameters["filter"] == "followed" && currentSone != null && !currentSone.hasFriend(it.id) } .filterNot { freenetRequest.parameters["filter"] == "not-followed" && currentSone != null && currentSone.hasFriend(it.id) } .filterNot { freenetRequest.parameters["filter"] == "new" && it.isKnown } @@ -35,7 +36,8 @@ class KnownSonesPage(template: Template, webInterface: WebInterface): else -> comparator } } - ), 25).apply { page = freenetRequest.parameters["page"]?.toIntOrNull() ?: 0 } + ).paginate(25) + .turnTo(freenetRequest.parameters["page"]?.toIntOrNull() ?: 0) .let { pagination -> templateContext["pagination"] = pagination templateContext["knownSones"] = pagination.items