Skip to content

Commit

Permalink
LMSA-9028 fix issue with identical start dates
Browse files Browse the repository at this point in the history
  • Loading branch information
mrw-iu committed Oct 17, 2023
1 parent 56d9a81 commit ebcbf85
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
Expand Down Expand Up @@ -671,12 +670,11 @@ public String doTermLoad(@PathVariable("courseId") String courseId, @PathVariabl

// Make sure the sections are still sorted
Comparator<SectionUIDisplay> nameComparator = Comparator.comparing(SectionUIDisplay::getSectionName, Comparator.nullsFirst(Comparator.naturalOrder()));
Collection<List<SectionUIDisplay>> sectionUIDisplays = rebuiltTermMap.values();
for (List<SectionUIDisplay> uiDisplay : sectionUIDisplays) {
if (uiDisplay != null) {
uiDisplay.sort(nameComparator);
rebuiltTermMap.values().forEach(sectionUIDisplays -> {
if (sectionUIDisplays != null) {
sectionUIDisplays.sort(nameComparator);
}
}
});

model.addAttribute("activeCourseSections", rebuiltTermMap.get(currentCourse.getTerm()));
model.addAttribute("sectionsMap", rebuiltTermMap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ public class CanvasTermComparator implements Comparator<CanvasTerm>, Serializabl

@Override
public int compare(CanvasTerm ct1, CanvasTerm ct2) {
// This comparator is used for sorting terms in a map. We don't want it to ever return equal because
// that entry would not be added to the map. In case of equality, return in ABC order.
if (TermHelper.getStartDate(ct1) == null && TermHelper.getStartDate(ct2) == null) {
return 0;
// if start dates are the same, return in ABC order
return ct1.getName().compareTo(ct2.getName());
} else if (TermHelper.getStartDate(ct1) == null && TermHelper.getStartDate(ct2) != null) {
return 1;
} else if (TermHelper.getStartDate(ct1) != null && TermHelper.getStartDate(ct2) == null) {
Expand All @@ -54,7 +57,8 @@ public int compare(CanvasTerm ct1, CanvasTerm ct2) {
} else if (TermHelper.getStartDate(ct1).after(TermHelper.getStartDate(ct2))) {
return -1;
} else {
return 0;
// if start dates are the same, return in ABC order
return ct1.getName().compareTo(ct2.getName());
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/fragments/termData.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<body>
<div th:fragment="termData">
<h3 id="active-term" th:data-active-term-id = "${activeTerm.id}" th:text="${activeTerm.name}">(Active Term Name)</h3>
<div class="rvt-p-left-md rvt-p-bottom-sm rvt-prose">
<div class="rvt-p-left-md rvt-prose">
<p th:if="${#lists.isEmpty(activeCourseSections)}">None available</p>
<ul th:unless="${#lists.isEmpty(activeCourseSections)}" class="sectionsList rvt-list-plain">
<li th:id="'row_' + ${section.sectionId}" th:each="section : ${activeCourseSections}" th:class="${section.getAppropriateCssClass()}"
Expand Down

0 comments on commit ebcbf85

Please sign in to comment.