Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List the letter-sound correspondences where a letter is used #1701 #1782

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
package ai.elimu.web.content.letter;

import java.util.Calendar;
import javax.validation.Valid;

import org.apache.logging.log4j.Logger;
import ai.elimu.dao.LetterContributionEventDao;
import ai.elimu.dao.LetterDao;
import ai.elimu.model.content.Letter;
import ai.elimu.model.contributor.Contributor;
import ai.elimu.model.contributor.LetterContributionEvent;
import ai.elimu.util.DiscordHelper;
import ai.elimu.web.context.EnvironmentContextLoaderListener;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.validation.Valid;

import org.apache.commons.lang.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
Expand All @@ -23,6 +17,15 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import ai.elimu.dao.LetterContributionEventDao;
import ai.elimu.dao.LetterDao;
import ai.elimu.dao.LetterSoundDao;
import ai.elimu.model.content.Letter;
import ai.elimu.model.contributor.Contributor;
import ai.elimu.model.contributor.LetterContributionEvent;
import ai.elimu.util.DiscordHelper;
import ai.elimu.web.context.EnvironmentContextLoaderListener;

@Controller
@RequestMapping("/content/letter/edit")
public class LetterEditController {
Expand All @@ -31,6 +34,9 @@ public class LetterEditController {

@Autowired
private LetterDao letterDao;

@Autowired
private LetterSoundDao letterSoundDao;

@Autowired
private LetterContributionEventDao letterContributionEventDao;
Expand All @@ -46,7 +52,9 @@ public String handleRequest(
model.addAttribute("timeStart", System.currentTimeMillis());

model.addAttribute("letterContributionEvents", letterContributionEventDao.readAll(letter));


model.addAttribute("letterSounds", letterSoundDao.readAll());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addition of letterSounds model attribute.

The letterSounds attribute is added to the model, which is fetched using letterSoundDao.readAll(). This is a straightforward implementation but consider adding error handling or checking the result of readAll() to ensure it does not return null or an unexpected result.

Consider adding null checks or error handling around the DAO call to improve robustness.


return "content/letter/edit";
}

Expand Down
44 changes: 44 additions & 0 deletions src/main/webapp/WEB-INF/jsp/content/letter/edit.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,48 @@
</li>
</ol>
</div>
<h5 class="center"><fmt:message key="letter.sound.correspondences" /></h5>

<table class="bordered highlight">
<thead>
<th><fmt:message key="frequency" /></th>
<th><fmt:message key="letters" /></th>
<th></th>
<th><fmt:message key="sounds" /></th>
</thead>
<tbody>
<c:forEach var="letterSound" items="${letterSounds}">
<%-- Check if the current letter is used by the letter-sound. --%>
<c:set var="isUsedByLetterSound" value="false" />
<c:forEach var="l" items="${letterSound.letters}">
<c:if test="${letter.id == l.id}">
<c:set var="isUsedByLetterSound" value="true" />
</c:if>
</c:forEach>
<c:if test="${isUsedByLetterSound}">
<tr>
<td>
${letterSound.usageCount}
</td>
<td>
" <c:forEach var="letter" items="${letterSound.letters}">
<a href="<spring:url value='/content/letter/edit/${letter.id}' />">${letter.text} </a>
</c:forEach> "
</td>
<td>
</td>
<td>
/ <c:forEach var="s" items="${letterSound.sounds}">
<a href="<spring:url value='/content/sound/edit/${s.id}' />">
<c:if test="${s.id == sound.id}">
<span class='diff-highlight'></c:if>${s.valueIpa}<c:if test="${s.id == sound.id}"></span></c:if>
</a>
</c:forEach> /
</td>
</tr>
</c:if>
</c:forEach>
</tbody>
</table>
Comment on lines +188 to +231
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review the new table for letter sound correspondences.

The new table is well-structured with appropriate headers and data bindings. The nested loops and conditionals are correctly used to display data based on the letterSounds model attribute. However, ensure that the data fetched (letterSounds) is not empty to avoid rendering an empty table.

Add checks to ensure letterSounds is not empty before rendering the table to enhance user experience and prevent potential errors.

</content:aside>