Search in sources :

Example 16 with Contributor

use of ai.elimu.model.Contributor in project webapp by elimu-ai.

the class NumberEditController method handleSubmit.

@RequestMapping(value = "/{id}", method = RequestMethod.POST)
public String handleSubmit(HttpSession session, @Valid Number number, BindingResult result, Model model) {
    logger.info("handleSubmit");
    if (number.getLocale() == Locale.AR) {
        if (StringUtils.isBlank(number.getSymbol())) {
            result.rejectValue("symbol", "NotNull");
        }
    }
    Number existingNumber = numberDao.readByValue(number.getLocale(), number.getValue());
    if ((existingNumber != null) && !existingNumber.getId().equals(number.getId())) {
        result.rejectValue("value", "NonUnique");
    }
    Contributor contributor = (Contributor) session.getAttribute("contributor");
    if (result.hasErrors()) {
        model.addAttribute("number", number);
        List<Word> words = wordDao.readAllOrdered(contributor.getLocale());
        model.addAttribute("words", words);
        return "content/number/edit";
    } else {
        number.setTimeLastUpdate(Calendar.getInstance());
        number.setRevisionNumber(number.getRevisionNumber() + 1);
        numberDao.update(number);
        return "redirect:/content/number/list#" + number.getId();
    }
}
Also used : Word(ai.elimu.model.content.Word) Number(ai.elimu.model.content.Number) Contributor(ai.elimu.model.Contributor) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 17 with Contributor

use of ai.elimu.model.Contributor in project webapp by elimu-ai.

the class NumberListController method handleRequest.

@RequestMapping(method = RequestMethod.GET)
public String handleRequest(Model model, HttpSession session) {
    logger.info("handleRequest");
    Contributor contributor = (Contributor) session.getAttribute("contributor");
    // To ease development/testing, auto-generate Numbers
    List<Number> numbersGenerated = generateNumbers(contributor.getLocale());
    for (Number number : numbersGenerated) {
        Number existingNumber = numberDao.readByValue(number.getLocale(), number.getValue());
        if (existingNumber == null) {
            numberDao.create(number);
        }
    }
    List<Number> numbers = numberDao.readAllOrdered(contributor.getLocale());
    model.addAttribute("numbers", numbers);
    return "content/number/list";
}
Also used : Number(ai.elimu.model.content.Number) Contributor(ai.elimu.model.Contributor) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 18 with Contributor

use of ai.elimu.model.Contributor in project webapp by elimu-ai.

the class StoryBookCreateController method handleRequest.

@RequestMapping(method = RequestMethod.GET)
public String handleRequest(Model model, HttpSession session) {
    logger.info("handleRequest");
    Contributor contributor = (Contributor) session.getAttribute("contributor");
    StoryBook storyBook = new StoryBook();
    model.addAttribute("storyBook", storyBook);
    model.addAttribute("contentLicenses", ContentLicense.values());
    List<Image> coverImages = imageDao.readAllOrdered(contributor.getLocale());
    model.addAttribute("coverImages", coverImages);
    model.addAttribute("gradeLevels", GradeLevel.values());
    return "content/storybook/create";
}
Also used : StoryBook(ai.elimu.model.content.StoryBook) Contributor(ai.elimu.model.Contributor) Image(ai.elimu.model.content.multimedia.Image) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 19 with Contributor

use of ai.elimu.model.Contributor in project webapp by elimu-ai.

the class StoryBookCreateController method handleSubmit.

@RequestMapping(method = RequestMethod.POST)
public String handleSubmit(HttpSession session, @Valid StoryBook storyBook, BindingResult result, Model model) {
    logger.info("handleSubmit");
    Contributor contributor = (Contributor) session.getAttribute("contributor");
    StoryBook existingStoryBook = storybookDao.readByTitle(storyBook.getLocale(), storyBook.getTitle());
    if (existingStoryBook != null) {
        result.rejectValue("title", "NonUnique");
    }
    List<String> paragraphs = storyBook.getParagraphs();
    logger.info("paragraphs: " + paragraphs);
    if (result.hasErrors()) {
        model.addAttribute("storybook", storyBook);
        model.addAttribute("contentLicenses", ContentLicense.values());
        List<Image> coverImages = imageDao.readAllOrdered(contributor.getLocale());
        model.addAttribute("coverImages", coverImages);
        model.addAttribute("gradeLevels", GradeLevel.values());
        return "content/storybook/create";
    } else {
        storyBook.setTimeLastUpdate(Calendar.getInstance());
        storybookDao.create(storyBook);
        if (EnvironmentContextLoaderListener.env == Environment.PROD) {
            String text = URLEncoder.encode(contributor.getFirstName() + " just added a new StoryBook:\n" + "• Language: \"" + storyBook.getLocale().getLanguage() + "\"\n" + "• Title: \"" + storyBook.getTitle() + "\"\n" + "• Grade level: " + storyBook.getGradeLevel() + "\n" + "• Paragraphs: " + storyBook.getParagraphs() + "\n" + "See ") + "http://elimu.ai/content/storybook/edit/" + storyBook.getId();
            String iconUrl = contributor.getImageUrl();
            SlackApiHelper.postMessage(SlackApiHelper.getChannelId(Team.CONTENT_CREATION), text, iconUrl, null);
        }
        return "redirect:/content/storybook/list#" + storyBook.getId();
    }
}
Also used : StoryBook(ai.elimu.model.content.StoryBook) Contributor(ai.elimu.model.Contributor) Image(ai.elimu.model.content.multimedia.Image) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 20 with Contributor

use of ai.elimu.model.Contributor in project webapp by elimu-ai.

the class SyllableListController method handleRequest.

@RequestMapping(method = RequestMethod.GET)
public String handleRequest(Model model, HttpSession session) {
    logger.info("handleRequest");
    Contributor contributor = (Contributor) session.getAttribute("contributor");
    // To ease development/testing, auto-generate Syllables
    List<Syllable> syllablesGenerated = generateSyllables(contributor.getLocale());
    for (Syllable syllable : syllablesGenerated) {
        logger.info("syllable.getText(): " + syllable.getText());
        Syllable existingSyllable = syllableDao.readByText(syllable.getLocale(), syllable.getText());
        if (existingSyllable == null) {
            syllableDao.create(syllable);
        }
    }
    List<Syllable> syllables = syllableDao.readAllOrdered(contributor.getLocale());
    logger.info("syllables.size(): " + syllables.size());
    model.addAttribute("syllables", syllables);
    return "content/syllable/list";
}
Also used : Contributor(ai.elimu.model.Contributor) Syllable(ai.elimu.model.content.Syllable) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Contributor (ai.elimu.model.Contributor)57 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)51 Project (ai.elimu.model.project.Project)12 IOException (java.io.IOException)10 Allophone (ai.elimu.model.content.Allophone)9 Word (ai.elimu.model.content.Word)8 Image (ai.elimu.model.content.multimedia.Image)8 Audio (ai.elimu.model.content.multimedia.Audio)6 Letter (ai.elimu.model.content.Letter)5 Number (ai.elimu.model.content.Number)5 AppCategory (ai.elimu.model.project.AppCategory)5 StoryBook (ai.elimu.model.content.StoryBook)4 Video (ai.elimu.model.content.multimedia.Video)4 Scheduled (org.springframework.scheduling.annotation.Scheduled)4 AppCollection (ai.elimu.model.project.AppCollection)3 AppGroup (ai.elimu.model.project.AppGroup)3 Locale (java.util.Locale)3 Application (ai.elimu.model.admin.Application)2 ApplicationVersion (ai.elimu.model.admin.ApplicationVersion)2 Syllable (ai.elimu.model.content.Syllable)2