Search in sources :

Example 1 with Feedback

use of com.erudika.scoold.core.Feedback in project scoold by Erudika.

the class SearchController method get.

@GetMapping({ "/search/{type}/{query}", "/search" })
public String get(@PathVariable(required = false) String type, @PathVariable(required = false) String query, @RequestParam(required = false) String q, HttpServletRequest req, Model model) {
    List<Profile> userlist = new ArrayList<Profile>();
    List<Post> questionlist = new ArrayList<Post>();
    List<Post> answerlist = new ArrayList<Post>();
    List<Post> feedbacklist = new ArrayList<Post>();
    Pager itemcount = utils.getPager("page", req);
    String queryString = StringUtils.isBlank(q) ? query : q;
    if ("questions".equals(type)) {
        questionlist = pc.findQuery(Utils.type(Question.class), queryString, itemcount);
    } else if ("answers".equals(type)) {
        answerlist = pc.findQuery(Utils.type(Reply.class), queryString, itemcount);
    } else if ("feedback".equals(type)) {
        feedbacklist = pc.findQuery(Utils.type(Feedback.class), queryString, itemcount);
    } else if ("people".equals(type)) {
        userlist = pc.findQuery(Utils.type(Profile.class), queryString, itemcount);
    } else {
        questionlist = pc.findQuery(Utils.type(Question.class), queryString);
        answerlist = pc.findQuery(Utils.type(Reply.class), queryString);
        feedbacklist = pc.findQuery(Utils.type(Feedback.class), queryString);
        userlist = pc.findQuery(Utils.type(Profile.class), queryString);
    }
    ArrayList<Post> list = new ArrayList<Post>();
    list.addAll(questionlist);
    list.addAll(answerlist);
    list.addAll(feedbacklist);
    utils.fetchProfiles(list);
    model.addAttribute("path", "search.vm");
    model.addAttribute("title", utils.getLang(req).get("search.title"));
    model.addAttribute("searchSelected", "navbtn-hover");
    model.addAttribute("showParam", type);
    model.addAttribute("searchQuery", queryString);
    model.addAttribute("itemcount", itemcount);
    model.addAttribute("userlist", userlist);
    model.addAttribute("questionlist", questionlist);
    model.addAttribute("answerlist", answerlist);
    model.addAttribute("feedbacklist", feedbacklist);
    return "base";
}
Also used : Feedback(com.erudika.scoold.core.Feedback) Post(com.erudika.scoold.core.Post) Pager(com.erudika.para.utils.Pager) ArrayList(java.util.ArrayList) Reply(com.erudika.scoold.core.Reply) Question(com.erudika.scoold.core.Question) Profile(com.erudika.scoold.core.Profile) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 2 with Feedback

use of com.erudika.scoold.core.Feedback in project scoold by Erudika.

the class FeedbackController method createAjax.

@PostMapping
public String createAjax(HttpServletRequest req, Model model) {
    model.addAttribute("path", "feedback.vm");
    if (utils.isAuthenticated(req)) {
        Profile authUser = utils.getAuthUser(req);
        Post post = utils.populate(req, new Feedback(), "title", "body", "tags|,");
        Map<String, String> error = utils.validate(post);
        if (error.isEmpty()) {
            post.setCreatorid(authUser.getId());
            post.create();
            authUser.setLastseen(System.currentTimeMillis());
            return "redirect:" + feedbacklink;
        } else {
            model.addAttribute("error", error);
            return "base";
        }
    }
    return "redirect:" + feedbacklink;
}
Also used : Feedback(com.erudika.scoold.core.Feedback) Post(com.erudika.scoold.core.Post) Profile(com.erudika.scoold.core.Profile) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 3 with Feedback

use of com.erudika.scoold.core.Feedback in project scoold by Erudika.

the class FeedbackController method getById.

@GetMapping({ "/{id}", "/{id}/{title}" })
public String getById(@PathVariable String id, @PathVariable(required = false) String title, HttpServletRequest req, Model model) {
    Feedback showPost = pc.read(id);
    if (showPost == null) {
        return "redirect:" + feedbacklink;
    }
    Pager itemcount = utils.getPager("page", req);
    model.addAttribute("path", "feedback.vm");
    model.addAttribute("title", utils.getLang(req).get("feedback.title") + " - " + showPost.getTitle());
    model.addAttribute("description", Utils.abbreviate(Utils.stripAndTrim(showPost.getBody(), " "), 195));
    model.addAttribute("showPost", showPost);
    model.addAttribute("answerslist", showPost.getAnswers(itemcount));
    model.addAttribute("itemcount", itemcount);
    return "base";
}
Also used : Feedback(com.erudika.scoold.core.Feedback) Pager(com.erudika.para.utils.Pager) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

Feedback (com.erudika.scoold.core.Feedback)3 Pager (com.erudika.para.utils.Pager)2 Post (com.erudika.scoold.core.Post)2 Profile (com.erudika.scoold.core.Profile)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 Question (com.erudika.scoold.core.Question)1 Reply (com.erudika.scoold.core.Reply)1 ArrayList (java.util.ArrayList)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1