Search in sources :

Example 1 with Emoji

use of ai.elimu.model.content.Emoji in project webapp by elimu-ai.

the class AudioEditController method getEmojisByWordId.

private Map<Long, String> getEmojisByWordId() {
    logger.info("getEmojisByWordId");
    Map<Long, String> emojisByWordId = new HashMap<>();
    for (Word word : wordDao.readAll()) {
        String emojiGlyphs = "";
        List<Emoji> emojis = emojiDao.readAllLabeled(word);
        for (Emoji emoji : emojis) {
            emojiGlyphs += emoji.getGlyph();
        }
        if (StringUtils.isNotBlank(emojiGlyphs)) {
            emojisByWordId.put(word.getId(), emojiGlyphs);
        }
    }
    return emojisByWordId;
}
Also used : Word(ai.elimu.model.content.Word) HashMap(java.util.HashMap) Emoji(ai.elimu.model.content.Emoji)

Example 2 with Emoji

use of ai.elimu.model.content.Emoji in project webapp by elimu-ai.

the class ImageEditController method getEmojisByWordId.

private Map<Long, String> getEmojisByWordId() {
    logger.info("getEmojisByWordId");
    Map<Long, String> emojisByWordId = new HashMap<>();
    for (Word word : wordDao.readAll()) {
        String emojiGlyphs = "";
        List<Emoji> emojis = emojiDao.readAllLabeled(word);
        for (Emoji emoji : emojis) {
            emojiGlyphs += emoji.getGlyph();
        }
        if (StringUtils.isNotBlank(emojiGlyphs)) {
            emojisByWordId.put(word.getId(), emojiGlyphs);
        }
    }
    return emojisByWordId;
}
Also used : Word(ai.elimu.model.content.Word) HashMap(java.util.HashMap) Emoji(ai.elimu.model.content.Emoji)

Example 3 with Emoji

use of ai.elimu.model.content.Emoji in project webapp by elimu-ai.

the class EmojiEditController method handleRemoveContentLabelRequest.

@RequestMapping(value = "/{id}/remove-content-label", method = RequestMethod.POST)
@ResponseBody
public String handleRemoveContentLabelRequest(HttpServletRequest request, @PathVariable Long id) {
    logger.info("handleRemoveContentLabelRequest");
    logger.info("id: " + id);
    Emoji emoji = emojiDao.read(id);
    String wordIdParameter = request.getParameter("wordId");
    logger.info("wordIdParameter: " + wordIdParameter);
    if (StringUtils.isNotBlank(wordIdParameter)) {
        Long wordId = Long.valueOf(wordIdParameter);
        Word word = wordDao.read(wordId);
        Set<Word> words = emoji.getWords();
        Iterator<Word> iterator = words.iterator();
        while (iterator.hasNext()) {
            Word existingWord = iterator.next();
            if (existingWord.getId().equals(word.getId())) {
                iterator.remove();
            }
        }
        emoji.setRevisionNumber(emoji.getRevisionNumber() + 1);
        emojiDao.update(emoji);
    }
    return "success";
}
Also used : Word(ai.elimu.model.content.Word) Emoji(ai.elimu.model.content.Emoji) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with Emoji

use of ai.elimu.model.content.Emoji in project webapp by elimu-ai.

the class EmojiEditController method handleSubmit.

@RequestMapping(value = "/{id}", method = RequestMethod.POST)
public String handleSubmit(@Valid Emoji emoji, BindingResult result, Model model) {
    logger.info("handleSubmit");
    Emoji existingEmoji = emojiDao.readByGlyph(emoji.getGlyph());
    if ((existingEmoji != null) && !existingEmoji.getId().equals(emoji.getId())) {
        result.rejectValue("glyph", "NonUnique");
    }
    if (emoji.getUnicodeVersion() > 9) {
        result.rejectValue("glyph", "emoji.unicode.version");
    }
    if (result.hasErrors()) {
        model.addAttribute("emoji", emoji);
        List<Word> words = wordDao.readAllOrdered();
        model.addAttribute("words", words);
        model.addAttribute("emojisByWordId", getEmojisByWordId());
        return "content/emoji/edit";
    } else {
        emoji.setTimeLastUpdate(Calendar.getInstance());
        emoji.setRevisionNumber(emoji.getRevisionNumber() + 1);
        emojiDao.update(emoji);
        return "redirect:/content/emoji/list#" + emoji.getId();
    }
}
Also used : Word(ai.elimu.model.content.Word) Emoji(ai.elimu.model.content.Emoji) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with Emoji

use of ai.elimu.model.content.Emoji in project webapp by elimu-ai.

the class EmojiEditController method handleRequest.

@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public String handleRequest(Model model, @PathVariable Long id) {
    logger.info("handleRequest");
    Emoji emoji = emojiDao.read(id);
    model.addAttribute("emoji", emoji);
    List<Word> words = wordDao.readAllOrdered();
    model.addAttribute("words", words);
    model.addAttribute("emojisByWordId", getEmojisByWordId());
    return "content/emoji/edit";
}
Also used : Word(ai.elimu.model.content.Word) Emoji(ai.elimu.model.content.Emoji) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Emoji (ai.elimu.model.content.Emoji)25 Word (ai.elimu.model.content.Word)22 HashMap (java.util.HashMap)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 JSONArray (org.json.JSONArray)3 StoryBookParagraph (ai.elimu.model.content.StoryBookParagraph)2 Image (ai.elimu.model.content.multimedia.Image)2 WordContributionEvent (ai.elimu.model.contributor.WordContributionEvent)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 CSVFormat (org.apache.commons.csv.CSVFormat)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 StoryBookLearningEvent (ai.elimu.model.analytics.StoryBookLearningEvent)1 Letter (ai.elimu.model.content.Letter)1 LetterSoundCorrespondence (ai.elimu.model.content.LetterSoundCorrespondence)1 Number (ai.elimu.model.content.Number)1 Sound (ai.elimu.model.content.Sound)1 StoryBook (ai.elimu.model.content.StoryBook)1 StoryBookChapter (ai.elimu.model.content.StoryBookChapter)1 Syllable (ai.elimu.model.content.Syllable)1