Search in sources :

Example 1 with Pager

use of com.erudika.para.utils.Pager in project scoold by Erudika.

the class RevisionsController method get.

@GetMapping("/{postid}")
public String get(@PathVariable String postid, HttpServletRequest req, Model model) {
    Post showPost = utils.getParaClient().read(postid);
    if (showPost == null) {
        return "redirect:" + questionslink;
    }
    Pager itemcount = utils.getPager("page", req);
    List<Revision> revisionslist = showPost.getRevisions(itemcount);
    // we need the first revision on the next page for diffing
    List<Revision> nextPage = showPost.getRevisions(new Pager(itemcount.getPage() + 1, itemcount.getLimit()));
    utils.fetchProfiles(revisionslist);
    model.addAttribute("path", "revisions.vm");
    model.addAttribute("title", utils.getLang(req).get("revisions.title"));
    model.addAttribute("showPost", showPost);
    model.addAttribute("itemcount", itemcount);
    model.addAttribute("revisionslist", revisionslist);
    model.addAttribute("lastOnPage", nextPage.isEmpty() ? null : nextPage.get(0));
    return "base";
}
Also used : Revision(com.erudika.scoold.core.Revision) Post(com.erudika.scoold.core.Post) Pager(com.erudika.para.utils.Pager) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 2 with Pager

use of com.erudika.para.utils.Pager in project scoold by Erudika.

the class Post method createTags.

private void createTags() {
    if (getTags() == null || getTags().isEmpty())
        return;
    ArrayList<Tag> tagz = new ArrayList<Tag>();
    for (int i = 0; i < getTags().size(); i++) {
        String ntag = getTags().get(i);
        Tag t = new Tag(StringUtils.truncate(Utils.noSpaces(Utils.stripAndTrim(ntag, " "), "-"), 35));
        if (!StringUtils.isBlank(t.getTag())) {
            Pager tagged = new Pager(1);
            client().findTagged(getType(), new String[] { t.getTag() }, tagged);
            t.setCount((int) tagged.getCount() + 1);
            getTags().set(i, t.getTag());
            tagz.add(t);
        }
    }
    client().createAll(tagz);
}
Also used : Pager(com.erudika.para.utils.Pager) ArrayList(java.util.ArrayList) Tag(com.erudika.para.core.Tag)

Example 3 with Pager

use of com.erudika.para.utils.Pager in project scoold by Erudika.

the class TranslateController method translate.

@GetMapping({ "/{locale}", "/{locale}/{index}" })
public String translate(@PathVariable String locale, @PathVariable(required = false) String index, HttpServletRequest req, Model model) {
    Locale showLocale = utils.getLangutils().getProperLocale(locale);
    if (showLocale == null || "en".equals(showLocale.getLanguage())) {
        // can't translate default language
        return "redirect:" + languageslink;
    }
    int showIndex = -1;
    List<Translation> translationslist = Collections.emptyList();
    Pager itemcount = utils.getPager("page", req);
    if (!StringUtils.isBlank(index)) {
        showIndex = getIndex(index, langkeys);
        // this is what is currently shown for translation
        translationslist = utils.getLangutils().readAllTranslationsForKey(showLocale.getLanguage(), langkeys.get(showIndex), itemcount);
    }
    String title = utils.getLang(req).get("translate.title") + " - " + showLocale.getDisplayName(showLocale);
    int showLocaleProgress = utils.getLangutils().getTranslationProgressMap().get(showLocale.getLanguage());
    model.addAttribute("path", "translate.vm");
    model.addAttribute("title", title);
    model.addAttribute("showIndex", showIndex);
    model.addAttribute("showLocale", showLocale);
    model.addAttribute("langkeys", langkeys);
    model.addAttribute("deflang", deflang);
    model.addAttribute("showLocaleProgress", showLocaleProgress);
    model.addAttribute("translationslist", translationslist);
    model.addAttribute("itemcount", itemcount);
    return "base";
}
Also used : Locale(java.util.Locale) Translation(com.erudika.para.core.Translation) Pager(com.erudika.para.utils.Pager) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 4 with Pager

use of com.erudika.para.utils.Pager 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

Pager (com.erudika.para.utils.Pager)4 GetMapping (org.springframework.web.bind.annotation.GetMapping)3 Tag (com.erudika.para.core.Tag)1 Translation (com.erudika.para.core.Translation)1 Feedback (com.erudika.scoold.core.Feedback)1 Post (com.erudika.scoold.core.Post)1 Revision (com.erudika.scoold.core.Revision)1 ArrayList (java.util.ArrayList)1 Locale (java.util.Locale)1