Skip to content

Commit

Permalink
SAK-49998 Assignments improve performance and UX in assignments by st…
Browse files Browse the repository at this point in the history
…udent view
  • Loading branch information
fadesta102 committed May 21, 2024
1 parent 10452d9 commit 58d6980
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,7 @@ public class AssignmentAction extends PagedResourceActionII {
private static final String CONTEXT_GO_NEXT_UNGRADED_ENABLED = "goNextUngradedEnabled";
private static final String CONTEXT_GO_PREV_UNGRADED_ENABLED = "goPrevUngradedEnabled";
private static final String PARAMS_VIEW_SUBS_ONLY_CHECKBOX = "chkSubsOnly1";
private static final String EXPANDED_USER_ID = "expandedUserId";
private static ResourceLoader rb = new ResourceLoader("assignment");
private boolean nextUngraded = false;
private boolean prevUngraded = false;
Expand Down Expand Up @@ -5732,17 +5733,9 @@ private String build_instructor_view_students_assignment_context(VelocityPortlet
"&searchFilterOnly=" + searchFilterOnly.toString() +
"&estimate=true";
context.put("accessPointUrl", accessPointUrl);

Collection<Assignment> assignments = assignmentService.getAssignmentsForContext(contextString);

boolean hasAtLeastOneAnonAssigment = false;
for (Assignment assignment : assignments) {
if (assignmentService.assignmentUsesAnonymousGrading(assignment)) {
hasAtLeastOneAnonAssigment = true;
break;
}
}
context.put("hasAtLeastOneAnonAssignment", hasAtLeastOneAnonAssigment);
Collection<Assignment> assignments = assignmentService.getAssignmentsForContext(contextString).stream()
.filter(Predicate.not(assignmentService::assignmentUsesAnonymousGrading))
.collect(Collectors.toSet());

List<String> nonSubmitterPermissions = serverConfigurationService.getStringList(AssignmentConstants.SAK_PROP_NON_SUBMITTER_PERMISSIONS,
AssignmentConstants.SAK_PROP_NON_SUBMITTER_PERMISSIONS_DEFAULT);
Expand Down Expand Up @@ -5784,6 +5777,8 @@ private String build_instructor_view_students_assignment_context(VelocityPortlet
}
}


context.put("expandedUserId", state.getAttribute(EXPANDED_USER_ID));
context.put("studentMembersMap", studentMembers);
context.put("studentMembers", new SortedIterator(studentMembers.values().iterator(), new AssignmentComparator(state, SORTED_USER_BY_SORTNAME, Boolean.TRUE.toString())));
context.put("viewGroup", state.getAttribute(VIEW_SUBMISSION_LIST_OPTION));
Expand Down Expand Up @@ -5814,17 +5809,6 @@ private String build_instructor_report_submissions(VelocityPortlet portlet, Cont
List submissions = prepPage(state);
context.put("submissions", submissions);

List<SubmitterSubmission> allSubmissions = (List<SubmitterSubmission>) state.getAttribute(STATE_PAGEING_TOTAL_ITEMS);
boolean hasAtLeastOneAnonAssigment = false;
for (SubmitterSubmission submission : allSubmissions) {
Assignment assignment = submission.getSubmission().getAssignment();
if (assignmentService.assignmentUsesAnonymousGrading(assignment)) {
hasAtLeastOneAnonAssigment = true;
break;
}
}
context.put("hasAtLeastOneAnonAssignment", hasAtLeastOneAnonAssigment);

context.put("sortedBy", state.getAttribute(SORTED_SUBMISSION_BY));
context.put("sortedAsc", state.getAttribute(SORTED_SUBMISSION_ASC));

Expand Down Expand Up @@ -11024,7 +11008,13 @@ public void doGrade_submission(RunData data) {
String assignmentId = params.getString("assignmentId");
state.setAttribute(EXPORT_ASSIGNMENT_REF, assignmentId);
String submissionId = params.getString("submissionId");

try {
String userId = params.getString("submitterId");
state.setAttribute(EXPANDED_USER_ID, userId);
} catch (Exception ex) {
log.error(ex.getMessage(), ex);
}

// SAK-29314 - put submission information into state
boolean viewSubsOnlySelected = stringToBool((String) data.getParameters().getString(PARAMS_VIEW_SUBS_ONLY_CHECKBOX));
putSubmissionInfoIntoState(state, assignmentId, submissionId, viewSubsOnlySelected);
Expand Down Expand Up @@ -11231,6 +11221,12 @@ public void doShow_student_submission(RunData data) {
ParameterParser params = data.getParameters();

String id = params.getString("studentId");
try {
User expandedUser = userDirectoryService.getUser(id);
state.setAttribute(EXPANDED_USER_ID, id);
} catch (Exception ex) {
log.error(ex.getMessage(), ex);
}
// add the student id into the table
t.add(id);

Expand All @@ -11247,6 +11243,7 @@ public void doHide_student_submission(RunData data) {
ParameterParser params = data.getParameters();

String id = params.getString("studentId");
state.removeAttribute(EXPANDED_USER_ID);
// remove the student id from the table
t.remove(id);

Expand Down
14 changes: 11 additions & 3 deletions assignment/tool/src/webapp/js/assignmentsByStudent.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ window.includeWebjarLibrary('datatables');
window.includeWebjarLibrary('datatables-rowgroup');

// Make sure assignments namespace exists
let currentExpandedUserId = window.currentExpandedUser;
window.assignments = window.assignments ?? {};
let itChanged = false;

// Assignments By Students "global" namespace
window.assignments.byStudent = {
Expand Down Expand Up @@ -55,21 +57,27 @@ function parseDataCell(html) {
};
}

function renderGrouping({ studentName, actionLink, expanded }) {
function renderGrouping({ studentName, actionLink, expanded, studentUserId }) {
const template = document.createElement('template');
template.innerHTML = `
<tr>
<td class="border-0">
<a href="${actionLink}">
<a href="${actionLink}" id="${studentUserId}">
<span class="expand-icon si ${expanded ? "si-expanded" : "si-collapsed"}"
aria-hidden="true"></span>
<span>${studentName}</span>
</a>
</td>
</tr>
`;

if (!itChanged && currentExpandedUserId != "") {
changeCurrentExpanded();
}
return template.content;
}
function changeCurrentExpanded() {
itChanged = true;
window.location.href = window.location.href + "#" + currentExpandedUserId;
}

})();
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
<!-- start: chef_assignments_instructor_student_list_submissions.vm -->
<script>
#if ($expandedUserId)
window.currentExpandedUser = "$expandedUserId";
#else
window.currentExpandedUser = "";
#end
</script>
#javascript("/sakai-assignment-tool/js/assignmentsByStudent.js")
<script>
window.addEventListener("load", () => {
Expand Down Expand Up @@ -46,7 +53,7 @@
#else
<div class="sakai-table-toolBar">
<div class="sakai-table-filterContainer">
#if ($!groups.hasNext() || !$hasAtLeastOneAnonAssignment)
#if ($!groups.hasNext())
#define($viewSelectOptions)
#if (!$showSubmissionByFilterSearchOnly)
<option value="all" #if($!viewGroup.equals("all"))selected="selected"#end >$tlang.getString('gen.viewallgroupssections')</option>
Expand Down Expand Up @@ -137,9 +144,13 @@
#set($assignments=$!studentAssignmentsTable.get($member))
#foreach ($assignment in $!assignments)
#set ($assignmentReference = $!service.assignmentReference($assignment.Id))
#set ($isAnon = $!service.assignmentUsesAnonymousGrading($assignment))
#set($assignmentTitle = $formattedText.escapeHtml($assignment.Title))
#if (!$assignment.Draft)
#if ($assignment.IsGroup)
#set($displayAssignment = $service.canSubmit($assignment, $member.id))
#else
#set($displayAssignment = true)
#end
#if (!$assignment.Draft && $displayAssignment)
## do not show draft assignments
#set($submission = false)
#set($submission=$service.getSubmission($assignment.Id, $member))
Expand All @@ -158,9 +169,8 @@
</span>
</td>
<td headers="assignment" data-order="$assignmentTitle">
#if (!$isAnon)
<a href="#toolLinkParam("AssignmentAction" "doGrade_submission" "assignmentId=$formattedText.escapeUrl($assignmentReference)&submissionId=$formattedText.escapeUrl($submissionReference)&option=lisofass2")">$assignmentTitle</a>
#if ($allowAddAssignment && $allowSubmitByInstructor)
<a href="#toolLinkParam("AssignmentAction" "doGrade_submission" "assignmentId=$formattedText.escapeUrl($assignmentReference)&submissionId=$formattedText.escapeUrl($submissionReference)&option=lisofass2")">$assignmentTitle</a>
#if ($allowAddAssignment && $allowSubmitByInstructor)
#set( $submitSpinnerID = "submitFor_" + $member.Id + "_" + $formattedText.escapeUrl($assignmentReference) )
<div class="itemAction spinnerBesideContainer">
#if ($assignment.DueDate.isAfter($currentTime))
Expand All @@ -172,29 +182,25 @@
#end
<div id="$submitSpinnerID" class="allocatedSpinPlaceholder"></div>
</div>
#end
#else
$assignmentTitle ($tlang.getString("grading.anonymous.title"))
#end
</td>
<td headers="submitted">
#if ($!submission.submitted)
#if (!$isAnon)
#if ($!submission.DateSubmitted)
$!service.getUsersLocalDateTimeString($!submission.DateSubmitted)
#if ($submission.DateSubmitted.isAfter($assignment.DueDate))
<span class="highlight">$tlang.getString("gen.late2")</span>
#end
#if ($!submission.DateSubmitted)
$!service.getUsersLocalDateTimeString($!submission.DateSubmitted)
#if ($submission.DateSubmitted.isAfter($assignment.DueDate))
<span class="highlight">$tlang.getString("gen.late2")</span>
#end
#set ($submissionSubmitter = $!service.getSubmissionSubmittee($submission))
#if ($!submissionSubmitter.isPresent())
#set ($submitterId = $!submissionSubmitter.get().getSubmitter())
<br />$tlang.getString("listsub.submitted.by") $formattedText.escapeHtml($studentMembersMap.get($submitterId).getDisplayName())
#if($member.getId() != $submitterId)
($tlang.getString("listsub.submitted.on.behalf") $formattedText.escapeHtml($member.sortName))
#end
#end
#set ($submissionSubmitter = $!service.getSubmissionSubmittee($submission))
#if ($!submissionSubmitter.isPresent())
#set ($submitterId = $!submissionSubmitter.get().getSubmitter())
<br />$tlang.getString("listsub.submitted.by") $formattedText.escapeHtml($studentMembersMap.get($submitterId).getDisplayName())
#if($member.getId() != $submitterId)
($tlang.getString("listsub.submitted.on.behalf") $formattedText.escapeHtml($member.sortName))
#end
#elseif ($!submission.DateSubmitted)
#end
#if ($!submission.DateSubmitted)
$tlang.getString("gen.subm4") $tlang.getString("submitted.date.redacted")
#end
#end
Expand Down

0 comments on commit 58d6980

Please sign in to comment.