MOBILE-3787 assign: Fix submission and grading status on groups

main
Pau Ferrer Ocaña 2022-01-13 08:54:33 +01:00
parent 59e1a4fcf5
commit 03ccd02636
2 changed files with 83 additions and 102 deletions

View File

@ -157,7 +157,7 @@ export class AddonModAssignSubmissionsSource extends CoreRoutedItemsManagerSourc
}
// Fetch submissions and grades.
const submissions =
let submissions =
await AddonModAssignHelper.getSubmissionsUserData(
assign,
this.submissionsData.submissions,
@ -172,67 +172,61 @@ export class AddonModAssignSubmissionsSource extends CoreRoutedItemsManagerSourc
const getNeedGrading = this.SELECTED_STATUS == AddonModAssignProvider.NEED_GRADING;
const searchStatus = getNeedGrading ? AddonModAssignProvider.SUBMISSION_STATUS_SUBMITTED : this.SELECTED_STATUS;
const promises: Promise<void>[] = [];
const showSubmissions: AddonModAssignSubmissionForList[] = [];
submissions.forEach((submission: AddonModAssignSubmissionForList) => {
if (!searchStatus || searchStatus == submission.status) {
promises.push(
CoreUtils.ignoreErrors(
AddonModAssignOffline.getSubmissionGrade(assign.id, submission.userid),
).then(async (data) => {
if (getNeedGrading) {
// Only show the submissions that need to be graded.
const add = await AddonModAssign.needsSubmissionToBeGraded(submission, assign.id);
if (searchStatus) {
submissions = submissions.filter((submission: AddonModAssignSubmissionForList) => searchStatus == submission.status);
}
if (!add) {
return;
}
}
const promises: Promise<void>[] = submissions.map(async (submission: AddonModAssignSubmissionForList) => {
const gradeData = await CoreUtils.ignoreErrors(AddonModAssignOffline.getSubmissionGrade(assign.id, submission.userid));
if (getNeedGrading) {
// Only show the submissions that need to be graded.
const add = await AddonModAssign.needsSubmissionToBeGraded(submission, assign.id);
// Load offline grades.
const notSynced = !!data && submission.timemodified < data.timemodified;
if (submission.gradingstatus == 'graded' && !assign.markingworkflow) {
// Get the last grade of the submission.
const grade = grades
.filter((grade) => grade.userid == submission.userid)
.reduce(
(a, b) => (a && a.timemodified > b.timemodified ? a : b),
<AddonModAssignGrade | undefined> undefined,
);
if (grade && grade.timemodified < submission.timemodified) {
submission.gradingstatus = AddonModAssignProvider.GRADED_FOLLOWUP_SUBMIT;
}
}
submission.statusColor = AddonModAssign.getSubmissionStatusColor(submission.status);
submission.gradingColor = AddonModAssign.getSubmissionGradingStatusColor(
submission.gradingstatus,
);
submission.statusTranslated = Translate.instant(
'addon.mod_assign.submissionstatus_' + submission.status,
);
if (notSynced) {
submission.gradingStatusTranslationId = 'addon.mod_assign.gradenotsynced';
submission.gradingColor = '';
} else if (submission.statusColor != 'danger' || submission.gradingColor != 'danger') {
// Show grading status if one of the statuses is not done.
submission.gradingStatusTranslationId = AddonModAssign.getSubmissionGradingStatusTranslationId(
submission.gradingstatus,
);
} else {
submission.gradingStatusTranslationId = '';
}
showSubmissions.push(submission);
return;
}),
);
if (!add) {
return;
}
}
// Load offline grades.
const notSynced = !!gradeData && submission.timemodified < gradeData.timemodified;
if (submission.gradingstatus == 'graded' && !assign.markingworkflow) {
// Get the last grade of the submission.
const grade = grades
.filter((grade) => grade.userid == submission.userid)
.reduce(
(a, b) => (a && a.timemodified > b.timemodified ? a : b),
<AddonModAssignGrade | undefined> undefined,
);
if (grade && grade.timemodified < submission.timemodified) {
submission.gradingstatus = AddonModAssignProvider.GRADED_FOLLOWUP_SUBMIT;
}
}
submission.statusColor = AddonModAssign.getSubmissionStatusColor(submission.status);
submission.gradingColor = AddonModAssign.getSubmissionGradingStatusColor(
submission.gradingstatus,
);
submission.statusTranslated = Translate.instant(
'addon.mod_assign.submissionstatus_' + submission.status,
);
if (notSynced) {
submission.gradingStatusTranslationId = 'addon.mod_assign.gradenotsynced';
submission.gradingColor = '';
} else if (submission.statusColor != 'danger' || submission.gradingColor != 'danger') {
// Show grading status if one of the statuses is not done.
submission.gradingStatusTranslationId = AddonModAssign.getSubmissionGradingStatusTranslationId(
submission.gradingstatus,
);
} else {
submission.gradingStatusTranslationId = '';
}
showSubmissions.push(submission);
});
await Promise.all(promises);

View File

@ -398,48 +398,34 @@ export class AddonModAssignHelperProvider {
groupId?: number,
options: CoreSitesCommonWSOptions = {},
): Promise<AddonModAssignSubmissionFormatted[]> {
const parts = await this.getParticipants(assign, groupId, options);
const participants = await this.getParticipants(assign, groupId, options);
const blind = assign.blindmarking && !assign.revealidentities;
const result: AddonModAssignSubmissionFormatted[] = [];
const participants: {[id: number]: AddonModAssignParticipant} = CoreUtils.arrayToObject(parts, 'id');
const blind = !!assign.blindmarking && !assign.revealidentities;
const teamsubmission = !!assign.teamsubmission;
submissions.forEach((submission) => {
submission.submitid = submission.userid && submission.userid > 0 ? submission.userid : submission.blindid;
if (submission.submitid === undefined || submission.submitid <= 0) {
return;
return participants.map((participant) => {
const groupId = participant.groupid ??
(participant.groups && participant.groups[0] ? participant.groups[0].id : 0);
const foundSubmission = submissions.find((submission) => {
if (teamsubmission) {
return submission.userid == 0 && submission.groupid == groupId;
}
const submitId = submission.userid && submission.userid > 0 ? submission.userid : submission.blindid;
return participant.id == submitId;
});
let submission: AddonModAssignSubmissionFormatted | undefined;
if (!foundSubmission) {
// Create submission if none.
submission = this.createEmptySubmission();
submission.groupid = groupId;
} else {
submission = Object.assign({}, foundSubmission);
}
const participant = participants[submission.submitid];
if (!participant) {
// Avoid permission denied error. Participant not found on list.
return;
}
delete participants[submission.submitid];
if (!blind) {
submission.userfullname = participant.fullname;
submission.userprofileimageurl = participant.profileimageurl;
}
submission.manyGroups = !!participant.groups && participant.groups.length > 1;
submission.noGroups = !!participant.groups && participant.groups.length == 0;
if (participant.groupname) {
submission.groupid = participant.groupid!;
submission.groupname = participant.groupname;
}
// Add to the list.
if (submission.userfullname || submission.blindid) {
result.push(submission);
}
});
// Create a submission for each participant left in the list (the participants already treated were removed).
CoreUtils.objectToArray(participants).forEach((participant: AddonModAssignParticipant) => {
const submission = this.createEmptySubmission();
submission.submitid = participant.id;
if (!blind) {
@ -453,16 +439,16 @@ export class AddonModAssignHelperProvider {
submission.manyGroups = !!participant.groups && participant.groups.length > 1;
submission.noGroups = !!participant.groups && participant.groups.length == 0;
if (participant.groupname) {
submission.groupid = participant.groupid!;
submission.groupid = participant.groupid;
submission.groupname = participant.groupname;
}
submission.status = participant.submitted ? AddonModAssignProvider.SUBMISSION_STATUS_SUBMITTED :
AddonModAssignProvider.SUBMISSION_STATUS_NEW;
result.push(submission);
submission.status = submission.status ?? (participant.submitted ? AddonModAssignProvider.SUBMISSION_STATUS_SUBMITTED :
AddonModAssignProvider.SUBMISSION_STATUS_NEW);
return submission;
});
return result;
}
/**
@ -714,8 +700,9 @@ export const AddonModAssignHelper = makeSingleton(AddonModAssignHelperProvider);
* Assign submission with some calculated data.
*/
export type AddonModAssignSubmissionFormatted =
Omit<AddonModAssignSubmission, 'userid'> & {
Omit<AddonModAssignSubmission, 'userid'|'groupid'> & {
userid?: number; // Student id.
groupid?: number; // Group id.
blindid?: number; // Calculated in the app. Blindid of the user that did the submission.
submitid?: number; // Calculated in the app. Userid or blindid of the user that did the submission.
userfullname?: string; // Calculated in the app. Full name of the user that did the submission.