Merge pull request #100 from stvnhrlnd/OUR-441

Our 441
This commit is contained in:
Niels Hartvig
2017-06-23 12:03:02 +02:00
committed by GitHub
3 changed files with 27 additions and 8 deletions
+2 -1
View File
@@ -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;
@@ -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))
@@ -40,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;
@@ -168,19 +171,22 @@
<nav class="pagination" role="navigation">
@if (page > 1)
{
<a class="prev" href="?page=@(page - 1)">Prev</a>
queryString["page"] = (page - 1).ToString();
<a class="prev" href="?@queryString">Prev</a>
<span>&hellip;</span>
}
@for (var i = (page - 1 > 0 ? page - 1 : 1); i < (page + (pagesToShowLeft - (page - 1 > 0 ? 1 : 0))) && i <= pages; i++)
{
<a class="@Umbraco.If(i == page, "active")" href="?page=@i">@i</a>
queryString["page"] = i.ToString();
<a class="@Umbraco.If(i == page, "active")" href="?@queryString">@i</a>
}
@if (page < (pages - 3))
@if (page < pages)
{
queryString["page"] = (page + 1).ToString();
<span>&hellip;</span>
<a class="next" href="?page=@(page + 1)">Next</a>
<a class="next" href="?@queryString">Next</a>
}
</nav>
+13 -1
View File
@@ -123,7 +123,7 @@ FETCH NEXT @count ROWS ONLY";
/// </summary>
/// <param name="category"></param>
/// <returns></returns>
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<int>(sql, new { category = category });
}