From 3d7add5a42b36342395ea217a4cb3eaaac5f7708 Mon Sep 17 00:00:00 2001 From: Shukri Adams Date: Tue, 12 Dec 2023 12:27:43 +0100 Subject: [PATCH] fixes - paging for search results - tags alphabetically sorted --- src/Tetrifact.Web/Controllers/HomeController.cs | 13 ++++++++----- src/Tetrifact.Web/Core/Pager.cs | 8 +++++--- src/Tetrifact.Web/Views/Home/Package.cshtml | 2 +- src/Tetrifact.Web/Views/Shared/TagsList.cshtml | 2 +- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/Tetrifact.Web/Controllers/HomeController.cs b/src/Tetrifact.Web/Controllers/HomeController.cs index ca66c169..1d09b47f 100755 --- a/src/Tetrifact.Web/Controllers/HomeController.cs +++ b/src/Tetrifact.Web/Controllers/HomeController.cs @@ -83,8 +83,8 @@ public IActionResult UploadPackage() /// /// [ServiceFilter(typeof(ReadLevel))] - [Route("package/{packageId}/{pageIndex?}")] - public IActionResult Package(string packageId, int pageIndex) + [Route("package/{packageId}")] + public IActionResult Package(string packageId, [FromQuery(Name = "pageIndex")] int pageIndex) { ViewData["serverName"] = _settings.ServerName; ViewData["packageId"] = packageId; @@ -111,7 +111,7 @@ public IActionResult Package(string packageId, int pageIndex) /// [ServiceFilter(typeof(ReadLevel))] [Route("packages/{page?}")] - public IActionResult Packages(int page) + public IActionResult Packages([FromQuery(Name = "page")] int page) { // user-facing page values start at 1 instead of 0. reset if (page != 0) @@ -131,18 +131,21 @@ public IActionResult Packages(int page) /// [ServiceFilter(typeof(ReadLevel))] [Route("search/{search?}/{page?}")] - public IActionResult Search(string search, int page) + public IActionResult Search(string search, [FromQuery(Name = "page")] int page) { // user-facing page values start at 1 instead of 0. reset if (page != 0) page--; + if (search == null) + search = string.Empty; + PageableData results = _packageList.Find(search, page, _settings.ListPageSize); Pager pager = new Pager(); ViewData["serverName"] = _settings.ServerName; ViewData["search"] = search; ViewData["packages"] = results; - ViewData["pager"] = pager.Render(results, _settings.PagesPerPageGroup, "/search", "page"); + ViewData["pager"] = pager.Render(results, _settings.PagesPerPageGroup, $"/search/{search}", "page"); return View(); } diff --git a/src/Tetrifact.Web/Core/Pager.cs b/src/Tetrifact.Web/Core/Pager.cs index 2b974fb3..3a113948 100644 --- a/src/Tetrifact.Web/Core/Pager.cs +++ b/src/Tetrifact.Web/Core/Pager.cs @@ -123,12 +123,14 @@ private string RenderPageLinks(int currentPage, int pagesPerGroup, string baseur s.Append($"