OUR-124 Make it possible to sort/filter forum topics by status
#OUR-124 Fixed
This commit is contained in:
@@ -35,8 +35,10 @@ function redirectToSearch(ev){
|
||||
}
|
||||
newUri = updateQueryString("fid", filters.forumId, newUri);
|
||||
newUri = updateQueryString("order", filters.order, newUri);
|
||||
newUri = updateQueryString("noreplies", filters.noreplies, newUri);
|
||||
newUri = updateQueryString("replies", filters.replies, newUri);
|
||||
newUri = updateQueryString("solved", filters.solved, newUri);
|
||||
newUri = updateQueryString("unsolved", filters.unsolved, newUri);
|
||||
|
||||
window.location = newUri;
|
||||
}
|
||||
@@ -48,7 +50,9 @@ function GetSearchFilters(cssClass) {
|
||||
forumId: undefined,
|
||||
order: undefined,
|
||||
solved: undefined,
|
||||
replies: undefined
|
||||
unsolved: undefined,
|
||||
replies: undefined,
|
||||
noreplies: undefined
|
||||
};
|
||||
if(cssClass === undefined) {
|
||||
filters.category = undefined;
|
||||
@@ -65,7 +69,9 @@ function GetSearchFilters(cssClass) {
|
||||
filters.forumId = forumId;
|
||||
filters.order = getParameterByName('order');
|
||||
filters.solved = getParameterByName('solved');
|
||||
filters.unsolved = getParameterByName('unsolved');
|
||||
filters.replies = getParameterByName('replies');
|
||||
filters.noreplies = getParameterByName('noreplies');
|
||||
|
||||
return filters;
|
||||
}
|
||||
@@ -366,7 +372,9 @@ $('#search-options input[type=checkbox]').click(function () {
|
||||
});
|
||||
|
||||
initCheckbox('replies');
|
||||
initCheckbox('noreplies');
|
||||
initCheckbox('solved');
|
||||
initCheckbox('unsolved');
|
||||
initCheckbox('order');
|
||||
|
||||
});
|
||||
|
||||
@@ -283,6 +283,101 @@
|
||||
}
|
||||
}
|
||||
|
||||
.search-options {
|
||||
padding: 0 10px;
|
||||
margin: 10px 0 40px;
|
||||
width: 100%;
|
||||
|
||||
label {
|
||||
font-size: .9rem;
|
||||
color: #4f5f63;
|
||||
text-transform: uppercase;
|
||||
font-weight: 700;
|
||||
letter-spacing: .2px;
|
||||
display: block;
|
||||
margin-bottom: .5rem;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.options {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
|
||||
span {
|
||||
position: relative;
|
||||
flex: 1 1 auto;
|
||||
margin-right: 20px;
|
||||
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
|
||||
text-align: center;
|
||||
|
||||
&:last-child {
|
||||
margin-right: 0;
|
||||
}
|
||||
|
||||
min-height: 50px;
|
||||
|
||||
input {
|
||||
position: absolute;
|
||||
z-index: 20;
|
||||
top: 0;
|
||||
left: 0;
|
||||
appearance: none;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
|
||||
padding: 15px 0;
|
||||
|
||||
cursor: pointer;
|
||||
|
||||
border: 2px solid rgba($color-space, .22);
|
||||
|
||||
transition: border 150ms ease;
|
||||
|
||||
outline: none;
|
||||
|
||||
&:hover {
|
||||
border-color: rgba($color-space, .44);
|
||||
|
||||
+ small {
|
||||
color: darken($color-space, 2%);
|
||||
}
|
||||
}
|
||||
|
||||
&:checked {
|
||||
border-color: $color-green;
|
||||
background: rgba($color-green, .22);
|
||||
|
||||
+ small {
|
||||
color: $color-green;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
border-color: $color-green;
|
||||
background: rgba($color-green, .15);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
small {
|
||||
color: rgba($color-space, .66);
|
||||
transition: color 150ms ease;
|
||||
font-size: .7rem;
|
||||
|
||||
transform: translate(0, 3px);
|
||||
|
||||
|
||||
@media(min-width: $md) {
|
||||
font-size: .9rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,10 @@
|
||||
{
|
||||
page = 1;
|
||||
}
|
||||
bool unsolved;
|
||||
bool.TryParse(Request["unsolved"], out unsolved);
|
||||
bool noreplies;
|
||||
bool.TryParse(Request["noreplies"], out noreplies);
|
||||
|
||||
var cat = -1;
|
||||
if (CurrentPage.Level > 3)
|
||||
@@ -26,13 +30,13 @@
|
||||
var pageSize = 50;
|
||||
if (page > 1)
|
||||
{
|
||||
topics = topicService.GetLatestTopics(pageSize, page, true, cat);
|
||||
topics = topicService.GetLatestTopics(pageSize, page, true, cat, unsolved, noreplies);
|
||||
}
|
||||
else
|
||||
{
|
||||
var key = "OurForumForum[" + cat + "]";
|
||||
var key = "OurForumForum[" + cat + unsolved + noreplies + "]";
|
||||
topics = (IEnumerable<ReadOnlyTopic>)cache.GetCacheItem(key,
|
||||
() => topicService.GetLatestTopics(pageSize, page, true, cat).ToArray(),
|
||||
() => topicService.GetLatestTopics(pageSize, page, true, cat, unsolved, noreplies).ToArray(),
|
||||
TimeSpan.FromSeconds(4));
|
||||
}
|
||||
|
||||
@@ -87,16 +91,30 @@
|
||||
{
|
||||
<option class="all" value="@categories.Id">All categories</option>
|
||||
foreach (var main in categories.Children)
|
||||
{
|
||||
foreach (var tag in main.Children)
|
||||
{
|
||||
<option class="@tag.Name.ToLower().Replace(" ", "")" value="@tag.Id" @(CurrentPage.Id == tag.Id ? "selected" : null)>@tag.Parent.Name - @tag.Name</option>
|
||||
}
|
||||
}
|
||||
{
|
||||
foreach (var tag in main.Children)
|
||||
{
|
||||
<option class="@tag.Name.ToLower().Replace(" ", "")" value="@tag.Id" @(CurrentPage.Id == tag.Id ? "selected" : null)>@tag.Parent.Name - @tag.Name</option>
|
||||
}
|
||||
}
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div id="search-options" class="search-options">
|
||||
<label>Filter by</label>
|
||||
<div class="options">
|
||||
<span>
|
||||
<input type="checkbox" name="unsolved" />
|
||||
<small>show only unsolved topics</small>
|
||||
</span>
|
||||
<br />
|
||||
<span>
|
||||
<input type="checkbox" name="noreplies" />
|
||||
<small>show only topics with no replies</small>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- FORUM HEADER END -->
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace OurUmbraco.Forum.Services
|
||||
/// <param name="page"></param>
|
||||
/// <param name="ignoreSpam"></param>
|
||||
/// <param name="category"></param>
|
||||
/// <returns></returns>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<ReadOnlyTopic> GetLatestTopics(long take = 50, long page = 1, bool ignoreSpam = true, int category = -1)
|
||||
{
|
||||
const string sql1 = @"SELECT forumTopics.*, u1.[text] as LastReplyAuthorName, u2.[text] as AuthorName
|
||||
@@ -57,6 +57,50 @@ FETCH NEXT @count ROWS ONLY";
|
||||
});
|
||||
}
|
||||
|
||||
public IEnumerable<ReadOnlyTopic> GetLatestTopics(long take = 50, long page = 1, bool ignoreSpam = true,
|
||||
int category = -1, bool unsolved = false, bool noreplies = false)
|
||||
{
|
||||
const string sql1 = @"SELECT forumTopics.*, u1.[text] as LastReplyAuthorName, u2.[text] as AuthorName
|
||||
FROM forumTopics
|
||||
LEFT OUTER JOIN umbracoNode u1 ON (forumTopics.latestReplyAuthor = u1.id AND u1.nodeObjectType = '39EB0F98-B348-42A1-8662-E7EB18487560')
|
||||
LEFT OUTER JOIN umbracoNode u2 ON (forumTopics.memberId = u2.id AND u2.nodeObjectType = '39EB0F98-B348-42A1-8662-E7EB18487560')
|
||||
";
|
||||
const string sql2 = @"
|
||||
ORDER BY updated DESC
|
||||
OFFSET @offset ROWS
|
||||
FETCH NEXT @count ROWS ONLY";
|
||||
|
||||
const string sqlix = sql1 + "WHERE isSpam=0";
|
||||
const string sqlxc = sql1 + "WHERE forumTopics.parentId=@category";
|
||||
const string sqlic = sql1 + "WHERE isSpam=0 AND forumTopics.parentId=@category";
|
||||
|
||||
var sql = ignoreSpam
|
||||
? (category > 0 ? sqlic : sqlix)
|
||||
: (category > 0 ? sqlxc : sql1);
|
||||
|
||||
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";
|
||||
|
||||
sql = sql + sql2;
|
||||
|
||||
// probably as fast as PetaPoco can be...
|
||||
return _databaseContext.Database.Fetch<ReadOnlyTopic>(sql, new
|
||||
{
|
||||
offset = (page - 1) * take,
|
||||
count = take,
|
||||
category = category
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a set of topics for a specific author
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user