From: David ‘Bombe’ Roden Date: Sat, 22 Jul 2017 15:55:09 +0000 (+0200) Subject: Fix pagination in gallery X-Git-Tag: 0.9.7^2~107 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=6f92f856b4b0afddc207d44a101eff41a403c933;p=Sone.git Fix pagination in gallery --- 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 2f165fc..5e8701b 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/ImageBrowserPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/ImageBrowserPage.kt @@ -33,8 +33,10 @@ class ImageBrowserPage(template: Template, webInterface: WebInterface): .filterNot(Album::isEmpty) .sortedBy(Album::getTitle) .also { albums -> - templateContext["albums"] = albums - templateContext["albumPagination"] = Pagination(albums, 12).apply { page = request.parameters["page"]?.toIntOrNull() ?: 0 } + Pagination(albums, webInterface.core.preferences.imagesPerPage).apply { page = request.parameters["page"]?.toIntOrNull() ?: 0 }.also { pagination -> + templateContext["albumPagination"] = pagination + templateContext["albums"] = pagination.items + } } } else { templateContext["soneRequested"] = true diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/ImageBrowserPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/ImageBrowserPageTest.kt index 2c581ac..4d0b2c7 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/ImageBrowserPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/ImageBrowserPageTest.kt @@ -85,6 +85,25 @@ class ImageBrowserPageTest: WebPageTest(::ImageBrowserPage) { } } + @Test + fun `get request for gallery can show second page`() { + core.preferences.imagesPerPage = 2 + val firstSone = createSone("first album", "second album") + addSone("sone1", firstSone) + val secondSone = createSone("third album", "fourth album") + addSone("sone2", secondSone) + addHttpRequestParameter("mode", "gallery") + addHttpRequestParameter("page", "1") + verifyNoRedirect { + assertThat(templateContext["galleryRequested"], equalTo(true)) + @Suppress("UNCHECKED_CAST") + assertThat(templateContext["albums"] as Iterable, contains( + firstSone.rootAlbum.albums[1], + secondSone.rootAlbum.albums[0] + )) + } + } + private fun createSone(firstAlbumTitle: String, secondAlbumTitle: String): Sone { return mock().apply { val rootAlbum = mock()