diff --git a/src/main/java/com/erudika/scoold/controllers/QuestionsController.java b/src/main/java/com/erudika/scoold/controllers/QuestionsController.java index 90fb3e38..3044b0a7 100755 --- a/src/main/java/com/erudika/scoold/controllers/QuestionsController.java +++ b/src/main/java/com/erudika/scoold/controllers/QuestionsController.java @@ -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"; } @@ -170,11 +171,13 @@ 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); @@ -182,6 +185,10 @@ public String applyFilter(@RequestParam(required = false) String sortby, @Reques 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)); @@ -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)) { @@ -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 + ")"; } diff --git a/src/main/resources/lang_en.properties b/src/main/resources/lang_en.properties index 102feb0e..88d92d41 100644 --- a/src/main/resources/lang_en.properties +++ b/src/main/resources/lang_en.properties @@ -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 diff --git a/src/main/resources/templates/questions.vm b/src/main/resources/templates/questions.vm index bf000ff3..536a223c 100755 --- a/src/main/resources/templates/questions.vm +++ b/src/main/resources/templates/questions.vm @@ -83,7 +83,6 @@ $!lang.get("posts.updated") $!lang.get("posts.answered") $!lang.get("posts.unanswered") - $!lang.get("posts.unapproved") #if ($authenticated) #if($request.getParameter('sortby'))#set($sortby = "?sortby=$request.getParameter('sortby')")#else#set($sortby = "")#end @@ -170,7 +169,7 @@ - +
@@ -210,15 +209,31 @@
-
- -
-
- + $!lang.get('filter') +
+ #macro(filterselected $prop) + #if($questionsTypeFilter == $prop)selected#end + #end + #set($unacceptedQuery = "properties.answercount:[1 TO *] NOT properties.answerid:[* TO *]" ) +
+ +
+
+
+     + +
+