Skip to content

Commit

Permalink
SAK-33701 Assignments add submission log (sakaiproject#8936)
Browse files Browse the repository at this point in the history
  • Loading branch information
ern authored Jan 11, 2021
1 parent 8d0cbd0 commit df33890
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 52 deletions.
2 changes: 2 additions & 0 deletions assignment/api/src/resources/assignment.properties
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ listsub.sorbyrel = Sort by Released
listsub.sorbysub = Sort by Submission Times
listsub.submitted.by = by
listsub.submitted.on.behalf = on behalf of
listsub.submitted = submitted
listsub.submitted.draft = saved draft

new = Add
new.title = Add new assignment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2446,7 +2446,7 @@ public String escapeInvalidCharsEntry(String accentedString) {
@Override
public boolean assignmentUsesAnonymousGrading(Assignment assignment) {
if (assignment != null) {
return Boolean.valueOf(assignment.getProperties().get(AssignmentServiceConstants.NEW_ASSIGNMENT_CHECK_ANONYMOUS_GRADING));
return Boolean.parseBoolean(assignment.getProperties().get(AssignmentServiceConstants.NEW_ASSIGNMENT_CHECK_ANONYMOUS_GRADING));
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
import java.util.Enumeration;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.TreeMap;
import java.util.HashSet;
import java.util.Iterator;
Expand Down Expand Up @@ -1747,6 +1748,7 @@ private String build_student_view_submission_context(VelocityPortlet portlet, Co
// the attachments from the previous submission
Set<String> submittedAttachments = s.getAttachments();
newAttachments = areAttachmentsModified(submittedAttachments, currentAttachments);
putSubmissionLogMessagesInContext(context, s);
} else {
// There is no previous submission, attachments are modified if anything has been uploaded
newAttachments = CollectionUtils.isNotEmpty(currentAttachments);
Expand Down Expand Up @@ -2128,6 +2130,7 @@ private String build_student_view_submission_confirmation_context(VelocityPortle
.collect(Collectors.toMap(User::getId, Function.identity()));
context.put("submitterNames", getSubmitterFormattedNames(s, "build_student_view_submission_confirmation_context"));
}
putSubmissionLogMessagesInContext(context, s);
}
}

Expand Down Expand Up @@ -2543,6 +2546,7 @@ protected String build_student_view_grade_context(VelocityPortlet portlet, Conte
}
}
context.put("NamePropContentReviewOptoutUrl", ContentReviewConstants.URKUND_OPTOUT_URL);
putSubmissionLogMessagesInContext(context, submission);
}

if (taggingManager.isTaggable() && submission != null) {
Expand Down Expand Up @@ -3654,6 +3658,7 @@ protected String build_instructor_grade_submission_context(VelocityPortlet portl
s.getAttachments().forEach(r -> attachmentReferences.put(r, entityManager.newReference(r)));
context.put("submissionAttachmentReferences", attachmentReferences);

putSubmissionLogMessagesInContext(context, s);
rangeAndGroups.buildInstructorGradeSubmissionContextGroupCheck(assignment, s.getGroupId(), state);
}

Expand Down Expand Up @@ -4268,6 +4273,31 @@ private void putTimePropertiesInContext(Context context, SessionState state, Str
context.put("value_" + timeName + "Min", (Integer) state.getAttribute(min));
}

private void putSubmissionLogMessagesInContext(Context context, AssignmentSubmission submission) {
List<String> messages = new LinkedList<>();
Map<String, String> properties = submission.getProperties();
Map<Integer, String> orderedLogKeys = properties.keySet().stream()
.filter(k -> k.startsWith("log"))
.map(k -> new String[] {k, StringUtils.split(k, "log")[0]})
.collect(Collectors.toMap(a -> new Integer(a[1]), a -> a[0], (e1, e2) -> e1, TreeMap::new));

orderedLogKeys.values().stream().map(properties::get).map(formattedText::escapeHtml).forEach(messages::add);

context.put("submissionLog", messages);
}

private String getNextSubmissionLogKey(AssignmentSubmission submission) {
String keyPrefix = "log";
Map<String, String> properties = submission.getProperties();
List<Integer> keys = properties.keySet().stream()
.filter(k -> k.startsWith("log"))
.map(k -> new Integer(StringUtils.split(k, "log")[0]))
.sorted()
.collect(Collectors.toList());
int next = keys.isEmpty() ? 0 : keys.get(keys.size() - 1) + 1;
return keyPrefix + next;
}

private List getPrevFeedbackAttachments(Map<String, String> p) {
String attachmentsString = p.get(PROP_SUBMISSION_PREVIOUS_FEEDBACK_ATTACHMENTS);
String[] attachmentsReferences = attachmentsString.split(",");
Expand Down Expand Up @@ -6437,6 +6467,28 @@ private void post_save_submission(RunData data, boolean post) {
properties.remove(AssignmentConstants.SUBMITTER_USER_ID);
}

// submission log
StringBuilder logEntry = new StringBuilder();
DateTimeFormatter dtf = DateTimeFormatter.RFC_1123_DATE_TIME
.withZone(userTimeService.getLocalTimeZone(u.getId()).toZoneId())
.withLocale(preferencesService.getLocale(u.getId()));
logEntry.append(dtf.format(Instant.now()));
boolean anonymousGrading = Boolean.parseBoolean(a.getProperties().get(NEW_ASSIGNMENT_CHECK_ANONYMOUS_GRADING));
String subOrDraft = post ? rb.getString("listsub.submitted") : rb.getString("listsub.submitted.draft");
if (!anonymousGrading) {
if (submitter != null && !submitter.getEid().equals(u.getEid())) {
logEntry.append(" ").append(submitter.getDisplayName())
.append(" (").append(submitter.getEid()).append(") ").append(subOrDraft)
.append(" ").append(rb.getString("listsub.submitted.on.behalf"))
.append(" ").append(u.getDisplayName()).append(" (").append(u.getEid()).append(")");
} else {
logEntry.append(" ").append(u.getDisplayName())
.append(" (").append(u.getEid()).append(") ")
.append(subOrDraft);
}
}
submission.getProperties().put(getNextSubmissionLogKey(submission), logEntry.toString());

try {
assignmentService.updateSubmission(submission);
} catch (PermissionException e) {
Expand Down Expand Up @@ -8093,7 +8145,7 @@ private void post_save_assignment(RunData data, String postOrSave) {
* @param state
* @param params
* @param siteId
* @param a
* @param assignment
*/
private void saveAssignmentSupplementItem(SessionState state,
ParameterParser params, String siteId, Assignment assignment) {
Expand Down Expand Up @@ -8311,7 +8363,9 @@ private void setDefaultSort(SessionState state) {
* Add submission objects if necessary for non-electronic type of assignment
*
* @param state
* @param a
* @param submissions
* @param addSubmissionForUsers
* @param assignment
*/
private void addRemoveSubmissionsForNonElectronicAssignment(SessionState state, List submissions, HashSet<String> addSubmissionForUsers, HashSet<String> removeSubmissionForUsers, Assignment assignment) {
// create submission object for those user who doesn't have one yet
Expand Down Expand Up @@ -8630,7 +8684,7 @@ private void integrateWithCalendarTool(SessionState state, Assignment assignment
* Add event to calendar and then persist the event id to the assignment properties
*
* @param state
* @param a AssignmentEdit
* @param assignment Assignment
* @param title Event title
* @param dueTime Assignment due date/time
* @param c Calendar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,17 +207,16 @@
#end

## Submission Log
## TODO Submission Log
## #if ($!submission && $!submission.getSubmissionLog().size() > 0)
## <tr>
## <th>$tlang.getString('gen.history')</th>
## <td>
## #foreach ($entry in $submission.getSubmissionLog())
## $formattedText.escapeHtml($entry)<br/>
## #end
## </td>
## </tr>
## #end
#if ($!submissionLog && !$!submissionLog.isEmpty())
<tr>
<th>$tlang.getString('gen.history')</th>
<td>
#foreach ($message in $submissionLog)
$message<br/>
#end
</td>
</tr>
#end
</table>

## show or hide assignment instruction and attachment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,17 +175,18 @@
</tr>
#end

## TODO Submission Log
## #if ($!submission && $!submission.getSubmissionLog().size() > 0)
## <tr>
## <th>$tlang.getString("gen.history")</th>
## <td>
## #foreach ($entry in $submission.getSubmissionLog())
## $formattedText.escapeHtml($entry)<br>
## #end
## </td>
## </tr>
## #end
## Submission Log
#if ($!submissionLog && !$!submissionLog.isEmpty())
<tr>
<th>$tlang.getString('gen.history')</th>
<td>
#foreach ($message in $submissionLog)
$message<br/>
#end
</td>
</tr>
#end

</table>
## TODO Content Review Service
## #if($assignment.getContent().AllowReviewService && $assignment.getContent().AllowStudentViewReport)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,21 +295,23 @@ $(document).ready(function(){
</div>
</div>
#end
## TODO Submission Log
## #if ($!submission && $!submission.getSubmissionLog().size() > 0)
## <div class="row">
## <div class="col-lg-4 col-sm-6 col-xs-12">
## <div class="itemSummaryHeader">$tlang.getString("gen.history")</div>
## </div>
## <div class="col-lg-4 col-sm-6 col-xs-12">
## <div class="itemSummaryValue">
## #foreach ($entry in $submission.getSubmissionLog())
## $formattedText.escapeHtml($entry)<br>
## #end
## </div>
## </div>
## </div>
## #end

## Submission Log
#if ($!submissionLog && !$!submissionLog.isEmpty())
<div class="row">
<div class="col-lg-4 col-sm-6 col-xs-12">
<div class="itemSummaryHeader">$tlang.getString("gen.history")</div>
</div>
<div class="col-lg-4 col-sm-6 col-xs-12">
<div class="itemSummaryValue">
#foreach ($message in $submissionLog)
$message<br/>
#end
</div>
</div>
</div>
#end

</div>
<div class="clearfix"></div>
<h4>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,18 @@
</td>
</tr>
#end
## TODO Submission Log
## #if ($!submission && $!submission.getSubmissionLog().size() > 0)
## <tr>
## <th>$tlang.getString('gen.history')</th>
## <td>
## #foreach ($entry in $submission.getSubmissionLog())
## $formattedText.escapeHtml($entry)<br>
## #end
## </td>
## </tr>
## #end

## Submission Log
#if ($!submissionLog && !$!submissionLog.isEmpty())
<tr>
<th>$tlang.getString('gen.history')</th>
<td>
#foreach ($message in $submissionLog)
$message<br/>
#end
</td>
</tr>
#end
</table>
<h4>
#if ($!submission.Submitted)
Expand Down

0 comments on commit df33890

Please sign in to comment.