Skip to content

Commit

Permalink
fixed ambiguous filter for 'unapproved' questions and moved it to the…
Browse files Browse the repository at this point in the history
… filter drawer on the questions page, closes #424
  • Loading branch information
albogdano committed Feb 23, 2024
1 parent a9e8278 commit c3c317d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public String get(@RequestParam(required = false) String sortby, HttpServletRequ
model.addAttribute("path", "questions.vm");
model.addAttribute("title", utils.getLang(req).get("questions.title"));
model.addAttribute("questionsSelected", "navbtn-hover");
model.addAttribute("questionsTypeFilter", HttpUtils.getCookieValue(req, "questions-type-filter"));
return "base";
}

Expand Down Expand Up @@ -170,18 +171,24 @@ public String getSorted(@RequestParam(required = false) String sortby, HttpServl
}

@PostMapping("/questions/apply-filter")
public String applyFilter(@RequestParam(required = false) String sortby, @RequestParam(required = false) String tab,
public String applyFilter(@RequestParam(required = false) String sortby,
@RequestParam(required = false) String typeFilter, @RequestParam(required = false) String tab,
@RequestParam(required = false, defaultValue = "false") String compactViewEnabled,
HttpServletRequest req, HttpServletResponse res, Model model) {
if (req.getParameter("clear") != null) {
HttpUtils.removeStateParam("questions-filter", req, res);
HttpUtils.removeStateParam("questions-type-filter", req, res);
HttpUtils.removeStateParam("questions-view-compact", req, res);
} else {
Pager p = utils.pagerFromParams(req);
if (!StringUtils.isBlank(req.getParameter(Config._TAGS))) {
boolean matchAll = "true".equals(req.getParameter("matchAllTags"));
p.setName("with_tags:" + (matchAll ? "+" : "") + req.getParameter(Config._TAGS));
}
if (!StringUtils.isBlank(typeFilter)) {
HttpUtils.setRawCookie("questions-type-filter", typeFilter,
req, res, "Strict", (int) TimeUnit.DAYS.toSeconds(365));
}
savePagerToCookie(req, res, p);
HttpUtils.setRawCookie("questions-view-compact", compactViewEnabled,
req, res, "Strict", (int) TimeUnit.DAYS.toSeconds(365));
Expand Down Expand Up @@ -423,13 +430,6 @@ private String getQuestionsQuery(HttpServletRequest req, Profile authUser, Strin
}
String q = "properties.answercount:0";
query = utils.getSpaceFilteredQuery(req, spaceFiltered, spaceFilter + q, q);
} else if ("unapproved".equals(sortby)) {
p.setSortby("timestamp");
if ("default_pager".equals(p.getName()) && p.isDesc()) {
p.setDesc(false);
}
String q = "properties.answercount:[1 TO *] NOT properties.answerid:[* TO *]";
query = utils.getSpaceFilteredQuery(req, spaceFiltered, spaceFilter + q, q);
}
String tags = StringUtils.trimToEmpty(StringUtils.removeStart(p.getName(), "with_tags:"));
if (StringUtils.startsWith(p.getName(), "with_tags:") && !StringUtils.isBlank(tags)) {
Expand All @@ -445,7 +445,9 @@ private String getQuestionsQuery(HttpServletRequest req, Profile authUser, Strin

private String getQueryWithPossibleExtension(String query, HttpServletRequest req) {
String queryExt = req.getParameter("q");
queryExt = StringUtils.isBlank(queryExt) || queryExt.startsWith("*") ? "" : queryExt;
if (StringUtils.isBlank(queryExt) || queryExt.startsWith("*")) {
queryExt = StringUtils.trimToEmpty(HttpUtils.getCookieValue(req, "questions-type-filter"));
}
if (!queryExt.isBlank()) {
return query.equals("*") ? queryExt : query + " AND (" + queryExt + ")";
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/lang_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,10 @@ posts.image = Attach file
posts.locationtxt = You can ask local questions in your native language.
posts.unanswered = Unanswered
posts.unapproved = Unapproved
posts.unaccepted = Questions with no accepted answer
posts.unapprovedq = Unapproved questions
posts.sticky = Pinned questions
posts.lastedited = Last edited
posts.approve = Approve
posts.mostpopular = Most popular
posts.tagged = Questions with tag
Expand Down
31 changes: 23 additions & 8 deletions src/main/resources/templates/questions.vm
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@
<a href="${questionslink}$!{filter}?sortby=activity" class="chip $sortarr.activity">$!lang.get("posts.updated")</a>
<a href="${questionslink}$!{filter}?sortby=answered" class="chip $sortarr.answered">$!lang.get("posts.answered")</a>
<a href="${questionslink}$!{filter}?sortby=unanswered" class="chip $sortarr.unanswered">$!lang.get("posts.unanswered")</a>
<a href="${questionslink}$!{filter}?sortby=unapproved" class="chip $sortarr.unapproved">$!lang.get("posts.unapproved")</a>

#if ($authenticated)
#if($request.getParameter('sortby'))#set($sortby = "?sortby=$request.getParameter('sortby')")#else#set($sortby = "")#end
Expand Down Expand Up @@ -170,7 +169,7 @@
<option value="properties.answercount" #sortselected("properties.answercount")>$!lang.get('answers.title')</option>
<option value="properties.viewcount" #sortselected("properties.viewcount")>$!lang.get('posts.views')</option>
<option value="properties.lastactivity" #sortselected("properties.lastactivity")>$!lang.get('profile.about.lastseen')</option>
<option value="properties.lastedited" #sortselected("properties.lastedited")>Last edited</option>
<option value="properties.lastedited" #sortselected("properties.lastedited")>$!lang.get('posts.lastedited')</option>
</select>
</div>
<div>
Expand Down Expand Up @@ -210,15 +209,31 @@
</label>
</div>
<div class="col l2 m4 s12">
<div class="center-align pvm">
<button type="submit" class="btn small waves-effect waves-light">$!lang.get('apply')</button>
</div>
<div class="center-align pvm">
<input id="question-filter-clear-btn" type="submit" class="btn btn-flat white"
name="clear" value="$!lang.get('clear')">
<strong>$!lang.get('filter')</strong>
<div class="input-field">
#macro(filterselected $prop)
#if($questionsTypeFilter == $prop)selected#end
#end
#set($unacceptedQuery = "properties.answercount:[1 TO *] NOT properties.answerid:[* TO *]" )
<select name="typeFilter">
<option value="" #filterselected("")>$!lang.get('showall')</option>
<option value="type:question" #filterselected("type:question")>$!lang.get('questions.title')</option>
<option value="type:sticky" #filterselected("type:sticky")>$!lang.get('posts.sticky')</option>
<option value="type:unapprovedquestion" #filterselected("type:unapprovedquestion")>$!lang.get('posts.unapprovedq')</option>
<option value="$unacceptedQuery" #filterselected($unacceptedQuery)>$!lang.get('posts.unaccepted')</option>
</select>
</div>
</div>
</div>

<div class="center">
<hr>
<div class="pvs">
<button type="submit" class="btn small waves-effect waves-light">$!lang.get('apply')</button> &nbsp; &nbsp;
<input id="question-filter-clear-btn" type="submit" class="btn btn-flat white"
name="clear" value="$!lang.get('clear')">
</div>
</div>
</form>
</div>

Expand Down

0 comments on commit c3c317d

Please sign in to comment.