Skip to content

Commit

Permalink
improved sorting of basic queries, ability to reverse order when sort…
Browse files Browse the repository at this point in the history
… buttons are clicked again
  • Loading branch information
albogdano committed Feb 3, 2020
1 parent cd27e42 commit dd73bfd
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ public String get(@RequestParam(required = false, defaultValue = "count") String
HttpServletRequest req, Model model) {
Pager itemcount = utils.getPager("page", req);
itemcount.setSortby(sortby);
itemcount.setDesc(!"tag".equals(sortby));

Profile authUser = utils.getAuthUser(req);
String currentSpace = utils.getSpaceIdFromCookie(authUser, req);
Expand Down
14 changes: 7 additions & 7 deletions src/main/resources/templates/feedback.vm
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@
#set($sortarr = {'votes': "", 'newest': ""} )
#setsortbyselection($sortarr 'votes')
<span class="right">
<a href="$questionlink/$showPost.id/#stripstr($showPost.title)" title="Most voted answers"
class="chip $sortarr.votes">$!lang.get("votes")</a>
<a href="$questionlink/$showPost.id/#stripstr($showPost.title)?sortby=newest" title="Newest answers"
class="chip $sortarr.newest">$!lang.get("newest")</a>
<a href="$questionlink/$showPost.id/#stripstr($showPost.title)#sortorderparam('?')" title="Most voted answers"
class="chip $sortarr.votes">#sortordericon() $!lang.get("votes")</a>
<a href="$questionlink/$showPost.id/#stripstr($showPost.title)?sortby=newest#sortorderparam('&' 'newest')" title="Newest answers"
class="chip $sortarr.newest">#sortordericon("newest") $!lang.get("newest")</a>
</span>
<h4 class="grey-text">$!lang.get("answers.title") #showcount($itemcount.count)</h4>
</div>
Expand Down Expand Up @@ -133,9 +133,9 @@
<div class="chips-container">
#set($sortarr = {'votes': "", 'newest': "", 'updated': ""} )
#setsortbyselection($sortarr 'newest')
<a href="$feedbacklink" class="chip $sortarr.newest">$!lang.get("newest")</a>
<a href="$feedbacklink?sortby=votes" class="chip $sortarr.votes">$!lang.get("votes")</a>
<a href="$feedbacklink?sortby=updated" class="chip $sortarr.updated">$!lang.get("posts.updated")</a>
<a href="$feedbacklink#sortorderparam('?')" class="chip $sortarr.newest">#sortordericon() $!lang.get("newest")</a>
<a href="$feedbacklink?sortby=votes#sortorderparam('&' 'votes')" class="chip $sortarr.votes">#sortordericon("votes") $!lang.get("votes")</a>
<a href="$feedbacklink?sortby=updated#sortorderparam('&' 'updated')" class="chip $sortarr.updated">#sortordericon("updated") $!lang.get("posts.updated")</a>
</div>

<h2 class="hide-on-med-and-down">#feedbackTitle()</h2>
Expand Down
12 changes: 12 additions & 0 deletions src/main/resources/templates/macro.vm
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,18 @@ $utils.formatDate($date, $format, $currentLocale)
#if ($sbparam && !$sbparam.isEmpty()) #set($paramMap[$sbparam] = $sbclazz) #else #set($paramMap[$defkey] = $sbclazz) #end
#end
#####################################
#macro(sortorderparam $prefix $sortparam)
#if ("false" != $request.getParameter("desc") && $sortparam == $request.getParameter("sortby"))$!{prefix}desc=false#end
#end
#####################################
#macro(sortorderparamasc $prefix $sortparam)
#if ("false" == $request.getParameter("desc") && $sortparam == $request.getParameter("sortby"))$!{prefix}desc=true#else$!{prefix}desc=false#end
#end
#####################################
#macro(sortordericon $sortparam)
#if ("false" == $request.getParameter("desc") && $sortparam == $request.getParameter("sortby"))<i class="fa fa-sort-amount-asc phs" title="Ascending order"></i>#end
#end
#####################################
#macro(sectoken $bare $formId)
## RESERVED FOR FUTURE USE
#end
Expand Down
12 changes: 6 additions & 6 deletions src/main/resources/templates/people.vm
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
<div class="chips-container">
#set($sortarr = {'votes': "", 'newest': "", 'properties.yearlyVotes': "", 'properties.quarterlyVotes': "", 'properties.montlyVotes': "", 'properties.weeklyVotes': ""} )
#setsortbyselection($sortarr 'newest')
<a href="$peoplelink" class="chip $sortarr.newest">$!lang.get("newest")</a>
<a href="$peoplelink?sortby=votes" class="chip $sortarr.votes">$!lang.get("reputation")</a>
<a href="$peoplelink?sortby=properties.yearlyVotes" class="chip $sortarr['properties.yearlyVotes']">$!lang.get('year')</a>
<a href="$peoplelink?sortby=properties.quarterlyVotes" class="chip $sortarr['properties.quarterlyVotes']">$!lang.get('quarter')</a>
<a href="$peoplelink?sortby=properties.montlyVotes" class="chip $sortarr['properties.montlyVotes']">$!lang.get('month')</a>
<a href="$peoplelink?sortby=properties.weeklyVotes" class="chip $sortarr['properties.weeklyVotes']">$!lang.get('week')</a>
<a href="$peoplelink#sortorderparam('?')" class="chip $sortarr.newest">#sortordericon() $!lang.get("newest")</a>
<a href="$peoplelink?sortby=votes#sortorderparam('&' 'votes')" class="chip $sortarr.votes">#sortordericon("votes") $!lang.get("reputation")</a>
<a href="$peoplelink?sortby=properties.yearlyVotes#sortorderparam('&' 'properties.yearlyVotes')" class="chip $sortarr['properties.yearlyVotes']">#sortordericon("properties.yearlyVotes") $!lang.get('year')</a>
<a href="$peoplelink?sortby=properties.quarterlyVotes#sortorderparam('&' 'properties.quarterlyVotes')" class="chip $sortarr['properties.quarterlyVotes']">#sortordericon("properties.quarterlyVotes") $!lang.get('quarter')</a>
<a href="$peoplelink?sortby=properties.montlyVotes#sortorderparam('&' 'properties.monthlyVotes')" class="chip $sortarr['properties.montlyVotes']">#sortordericon("properties.monthlyVotes") $!lang.get('month')</a>
<a href="$peoplelink?sortby=properties.weeklyVotes#sortorderparam('&' 'properties.weeklyVotes')" class="chip $sortarr['properties.weeklyVotes']">#sortordericon("properties.weeklyVotes") $!lang.get('week')</a>
#if($isAdmin)
#if($request.getParameter("bulkedit"))
<a href="$peoplelink" class="chip grey darken-2 white-text">$!lang.get('bulkeditspaces')</a>
Expand Down
8 changes: 4 additions & 4 deletions src/main/resources/templates/question.vm
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
#set($sortarr = {'votes': "", 'newest': ""} )
#setsortbyselection($sortarr 'votes')
<span class="right">
<a href="$questionlink/$showPost.id/#stripstr($showPost.title)" title="Most voted answers"
class="chip $sortarr.votes">$!lang.get("votes")</a>
<a href="$questionlink/$showPost.id/#stripstr($showPost.title)?sortby=newest" title="Newest answers"
class="chip $sortarr.newest">$!lang.get("newest")</a>
<a href="$questionlink/$showPost.id/#stripstr($showPost.title)#sortorderparam('?')" title="Most voted answers"
class="chip $sortarr.votes">#sortordericon() $!lang.get("votes")</a>
<a href="$questionlink/$showPost.id/#stripstr($showPost.title)?sortby=newest#sortorderparam('&' 'newest')" title="Newest answers"
class="chip $sortarr.newest">#sortordericon("newest") $!lang.get("newest")</a>
</span>
<h4 class="grey-text">$!lang.get("answers.title") #showcount($itemcount.count)</h4>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/templates/tags.vm
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<div class="chips-container">
#set($sortarr = {'popular': "", 'tag': ""} )
#setsortbyselection($sortarr 'popular')
<a href="$tagslink" title="Most used tags" class="chip $sortarr.popular">$!lang.get("posts.mostpopular")</a>
<a href="$tagslink?sortby=tag" title="Tags by name" class="chip $sortarr.tag">$!lang.get("name")</a>
<a href="$tagslink#sortorderparam('?')" title="Most used tags" class="chip $sortarr.popular">#sortordericon() $!lang.get("posts.mostpopular")</a>
<a href="$tagslink?sortby=tag#sortorderparamasc('&' 'tag')" title="Tags by name" class="chip $sortarr.tag">#sortordericon("tag") $!lang.get("name")</a>
</div>

<h2 class="hide-on-med-and-down">$!lang.get("tags.title") #showcount($itemcount.count)</h2>
Expand Down

0 comments on commit dd73bfd

Please sign in to comment.