MOBILE-3787 assign: Improve submission list filtering

main
Pau Ferrer Ocaña 2022-01-13 10:57:36 +01:00
parent 7cdafca794
commit c5ef18183b
2 changed files with 55 additions and 49 deletions

View File

@ -170,26 +170,28 @@ export class AddonModAssignSubmissionsSource extends CoreRoutedItemsManagerSourc
: [];
// Filter the submissions to get only the ones with the right status and add some extra data.
const getNeedGrading = this.SELECTED_STATUS == AddonModAssignListFilterName.NEED_GRADING;
const searchStatus = getNeedGrading ? AddonModAssignSubmissionStatusValues.SUBMITTED : this.SELECTED_STATUS;
const showSubmissions: AddonModAssignSubmissionForList[] = [];
if (searchStatus) {
submissions = submissions.filter((submission: AddonModAssignSubmissionForList) => searchStatus == submission.status);
}
if (this.SELECTED_STATUS == AddonModAssignListFilterName.NEED_GRADING) {
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);
submission.needsGrading = await AddonModAssign.needsSubmissionToBeGraded(submission, assign.id);
});
if (!add) {
return;
}
await Promise.all(promises);
submissions = submissions.filter((submission: AddonModAssignSubmissionForList) => submission.needsGrading);
} else if (this.SELECTED_STATUS) {
const searchStatus = this.SELECTED_STATUS == AddonModAssignListFilterName.DRAFT
? AddonModAssignSubmissionStatusValues.DRAFT
: AddonModAssignSubmissionStatusValues.SUBMITTED;
submissions = submissions.filter((submission: AddonModAssignSubmissionForList) => submission.status == searchStatus);
}
const showSubmissions: AddonModAssignSubmissionForList[] = await Promise.all(
submissions.map(async (submission: AddonModAssignSubmissionForList) => {
const gradeData =
await CoreUtils.ignoreErrors(AddonModAssignOffline.getSubmissionGrade(assign.id, submission.userid));
// Load offline grades.
const notSynced = !!gradeData && submission.timemodified < gradeData.timemodified;
@ -228,10 +230,9 @@ export class AddonModAssignSubmissionsSource extends CoreRoutedItemsManagerSourc
submission.gradingStatusTranslationId = '';
}
showSubmissions.push(submission);
});
await Promise.all(promises);
return submission;
}),
);
return { items: showSubmissions };
}
@ -246,6 +247,7 @@ export type AddonModAssignSubmissionForList = AddonModAssignSubmissionFormatted
gradingColor?: string; // Calculated in the app. Color of the submission grading status.
statusTranslated?: string; // Calculated in the app. Translated text of the submission status.
gradingStatusTranslationId?: string; // Calculated in the app. Key of the text of the submission grading status.
needsGrading?: boolean; // Calculated in the app. If submission and grading status means that it needs grading.
};
/**

View File

@ -955,6 +955,10 @@ export class AddonModAssignProvider {
* @return Promise resolved with boolean: whether it needs to be graded or not.
*/
async needsSubmissionToBeGraded(submission: AddonModAssignSubmissionFormatted, assignId: number): Promise<boolean> {
if (submission.status != AddonModAssignSubmissionStatusValues.SUBMITTED) {
return false;
}
if (!submission.gradingstatus) {
// This should not happen, but it's better to show rather than not showing any of the submissions.
return true;