From 686e3deb6cd9606aca0a57ff3600f953f33036de Mon Sep 17 00:00:00 2001 From: Steven Date: Sat, 4 Mar 2017 14:23:19 +0000 Subject: [PATCH 1/4] Update forum pagination links Preserve query string parameters in pagination links so that topic filters do not get reset when switching between pages. --- OurUmbraco.Site/Views/Partials/Forum/Forum.cshtml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/OurUmbraco.Site/Views/Partials/Forum/Forum.cshtml b/OurUmbraco.Site/Views/Partials/Forum/Forum.cshtml index 3b73f808..34772fae 100644 --- a/OurUmbraco.Site/Views/Partials/Forum/Forum.cshtml +++ b/OurUmbraco.Site/Views/Partials/Forum/Forum.cshtml @@ -5,6 +5,9 @@ @inherits OurUmbraco.Our.Models.OurUmbracoTemplatePage @{ + // Save query string for use in pagination links + var queryString = HttpUtility.ParseQueryString(Request.QueryString.ToString()); + const int pagesToShowLeft = 4; int page; if (!int.TryParse(Request["page"], out page)) @@ -168,19 +171,22 @@ From c93e4d1e2d0dc73b471c2fc1a75a755748e76e5f Mon Sep 17 00:00:00 2001 From: Steven Date: Sat, 4 Mar 2017 14:50:46 +0000 Subject: [PATCH 2/4] Update topic service and forum partial to fix pagination issue Add new parameters to count method for unsolved and no reply filters. Update view to pass in these parameters. --- OurUmbraco.Site/Views/Partials/Forum/Forum.cshtml | 4 ++-- OurUmbraco/Forum/Services/TopicService.cs | 14 +++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/OurUmbraco.Site/Views/Partials/Forum/Forum.cshtml b/OurUmbraco.Site/Views/Partials/Forum/Forum.cshtml index 34772fae..cd809d31 100644 --- a/OurUmbraco.Site/Views/Partials/Forum/Forum.cshtml +++ b/OurUmbraco.Site/Views/Partials/Forum/Forum.cshtml @@ -43,9 +43,9 @@ TimeSpan.FromSeconds(4)); } - var totalCountKey = "OurForumForumThreadCount[" + cat + "]"; + var totalCountKey = "OurForumForumThreadCount[" + cat + unsolved + noreplies + "]"; var totalTopics = (int)cache.GetCacheItem(totalCountKey, - () => topicService.GetAllTopicsCount(cat), + () => topicService.GetAllTopicsCount(cat, unsolved, noreplies), TimeSpan.FromMinutes(1)); var pages = (totalTopics / pageSize) + 1; diff --git a/OurUmbraco/Forum/Services/TopicService.cs b/OurUmbraco/Forum/Services/TopicService.cs index 4b23fad7..ac3a8fe3 100644 --- a/OurUmbraco/Forum/Services/TopicService.cs +++ b/OurUmbraco/Forum/Services/TopicService.cs @@ -123,7 +123,7 @@ FETCH NEXT @count ROWS ONLY"; /// /// /// - public int GetAllTopicsCount(int category = -1) + public int GetAllTopicsCount(int category = -1, bool unsolved = false, bool noreplies = false) { const string sql1 = @"SELECT COUNT(*) as forumTopicCount FROM forumTopics @@ -135,6 +135,18 @@ LEFT OUTER JOIN umbracoNode u2 ON (forumTopics.memberId = u2.id AND u2.nodeObjec var sql = (category > 0 ? sqlic : sqlix); + if (unsolved) + if (sql.Contains("WHERE")) + sql = sql + " AND answer = 0"; + else + sql = sql + " WHERE answer = 0"; + + if (noreplies) + if (sql.Contains("WHERE")) + sql = sql + " AND replies = 0"; + else + sql = sql + " WHERE replies = 0"; + return _databaseContext.Database.ExecuteScalar(sql, new { category = category }); } From 49c50046c9c008ac4a6a00bfedadd037a5e5a528 Mon Sep 17 00:00:00 2001 From: Steven Date: Sat, 4 Mar 2017 15:11:22 +0000 Subject: [PATCH 3/4] Update search JavaScript Reset page number to 1 when search filters are changed. --- OurUmbraco.Client/src/js/search.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/OurUmbraco.Client/src/js/search.js b/OurUmbraco.Client/src/js/search.js index 7b364901..84cd2bba 100644 --- a/OurUmbraco.Client/src/js/search.js +++ b/OurUmbraco.Client/src/js/search.js @@ -365,7 +365,8 @@ $('#search-options input[type=checkbox]').click(function () { newUri = updateQueryString("order", orderValue, window.location.href); } } else { - newUri = updateQueryString(this.name, this.checked, window.location.href); + newUri = updateQueryString(this.name, this.checked, window.location.href); + newUri = updateQueryString("page", 1, newUri); } console.log(newUri); window.location = newUri; From 87847769ce80632f9fd57cd2956bc85142cb914d Mon Sep 17 00:00:00 2001 From: Steven Date: Sat, 4 Mar 2017 15:43:46 +0000 Subject: [PATCH 4/4] Update forum partial Show next page link when current page is less than the total number of pages. Keeps pagination consistent with projects list. --- OurUmbraco.Site/Views/Partials/Forum/Forum.cshtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OurUmbraco.Site/Views/Partials/Forum/Forum.cshtml b/OurUmbraco.Site/Views/Partials/Forum/Forum.cshtml index cd809d31..42e903af 100644 --- a/OurUmbraco.Site/Views/Partials/Forum/Forum.cshtml +++ b/OurUmbraco.Site/Views/Partials/Forum/Forum.cshtml @@ -182,7 +182,7 @@ @i } - @if (page < (pages - 3)) + @if (page < pages) { queryString["page"] = (page + 1).ToString();