MOBILE-3754 quiz: Display grade to pass

main
Dani Palou 2021-05-17 09:23:46 +02:00
parent 2f8333d516
commit 9fa3e77436
5 changed files with 20 additions and 8 deletions

View File

@ -1645,6 +1645,7 @@
"core.grades.feedback": "grades", "core.grades.feedback": "grades",
"core.grades.grade": "grades", "core.grades.grade": "grades",
"core.grades.gradeitem": "grades", "core.grades.gradeitem": "grades",
"core.grades.gradepass": "grades",
"core.grades.grades": "grades", "core.grades.grades": "grades",
"core.grades.lettergrade": "grades", "core.grades.lettergrade": "grades",
"core.grades.manualitem": "grades", "core.grades.manualitem": "grades",

View File

@ -49,6 +49,15 @@
<p>{{ gradeMethodReadable }}</p> <p>{{ gradeMethodReadable }}</p>
</ion-label> </ion-label>
</ion-item> </ion-item>
<ion-item class="ion-text-wrap" *ngIf="bestGrade && bestGrade.gradetopass && quiz && quiz.gradeFormatted">
<ion-label>
<h3>{{ 'core.grades.gradepass' | translate }}</h3>
<p>{{ 'addon.mod_quiz.outof' | translate: { $a: {
grade: bestGrade.gradetopass,
maxgrade: quiz.gradeFormatted
} } }}</p>
</ion-label>
</ion-item>
<ion-item class="ion-text-wrap" *ngIf="syncTime"> <ion-item class="ion-text-wrap" *ngIf="syncTime">
<ion-label> <ion-label>
<h3>{{ 'core.lastsync' | translate }}</h3> <h3>{{ 'core.lastsync' | translate }}</h3>

View File

@ -79,6 +79,7 @@ export class AddonModQuizIndexComponent extends CoreCourseModuleMainActivityComp
gradeMethodReadable?: string; // Grade method in a readable format. gradeMethodReadable?: string; // Grade method in a readable format.
showReviewColumn = false; // Whether to show the review column. showReviewColumn = false; // Whether to show the review column.
attempts: AddonModQuizAttempt[] = []; // List of attempts the user has made. attempts: AddonModQuizAttempt[] = []; // List of attempts the user has made.
bestGrade?: AddonModQuizGetUserBestGradeWSResponse; // Best grade data.
protected fetchContentDefaultError = 'addon.mod_quiz.errorgetquiz'; // Default error to show when loading contents. protected fetchContentDefaultError = 'addon.mod_quiz.errorgetquiz'; // Default error to show when loading contents.
protected syncEventName = AddonModQuizSyncProvider.AUTO_SYNCED; protected syncEventName = AddonModQuizSyncProvider.AUTO_SYNCED;
@ -89,7 +90,6 @@ export class AddonModQuizIndexComponent extends CoreCourseModuleMainActivityComp
protected attemptAccessInfo?: AddonModQuizGetAttemptAccessInformationWSResponse; // Last attempt access info. protected attemptAccessInfo?: AddonModQuizGetAttemptAccessInformationWSResponse; // Last attempt access info.
protected moreAttempts = false; // Whether user can create/continue attempts. protected moreAttempts = false; // Whether user can create/continue attempts.
protected options?: AddonModQuizCombinedReviewOptions; // Combined review options. protected options?: AddonModQuizCombinedReviewOptions; // Combined review options.
protected bestGrade?: AddonModQuizGetUserBestGradeWSResponse; // Best grade data.
protected gradebookData?: { grade?: number; feedback?: string }; // The gradebook grade and feedback. protected gradebookData?: { grade?: number; feedback?: string }; // The gradebook grade and feedback.
protected overallStats = false; // Equivalent to overallstats in mod_quiz_view_object in Moodle. protected overallStats = false; // Equivalent to overallstats in mod_quiz_view_object in Moodle.
protected finishedObserver?: CoreEventObserver; // It will observe attempt finished events. protected finishedObserver?: CoreEventObserver; // It will observe attempt finished events.
@ -264,6 +264,8 @@ export class AddonModQuizIndexComponent extends CoreCourseModuleMainActivityComp
* @return Promise resolved when done. * @return Promise resolved when done.
*/ */
protected async getAttempts(quiz: AddonModQuizQuizData): Promise<void> { protected async getAttempts(quiz: AddonModQuizQuizData): Promise<void> {
// Always get the best grade because it includes the grade to pass.
this.bestGrade = await AddonModQuiz.getUserBestGrade(quiz.id, { cmId: this.module.id });
// Get access information of last attempt (it also works if no attempts made). // Get access information of last attempt (it also works if no attempts made).
this.attemptAccessInfo = await AddonModQuiz.getAttemptAccessInformation(quiz.id, 0, { cmId: this.module.id }); this.attemptAccessInfo = await AddonModQuiz.getAttemptAccessInformation(quiz.id, 0, { cmId: this.module.id });
@ -343,7 +345,6 @@ export class AddonModQuizIndexComponent extends CoreCourseModuleMainActivityComp
* @return Promise resolved when done. * @return Promise resolved when done.
*/ */
protected async getResultInfo(quiz: AddonModQuizQuizData): Promise<void> { protected async getResultInfo(quiz: AddonModQuizQuizData): Promise<void> {
if (!this.attempts.length || !quiz.showGradeColumn || !this.bestGrade?.hasgrade || if (!this.attempts.length || !quiz.showGradeColumn || !this.bestGrade?.hasgrade ||
this.gradebookData?.grade === undefined) { this.gradebookData?.grade === undefined) {
this.showResults = false; this.showResults = false;
@ -584,6 +585,8 @@ export class AddonModQuizIndexComponent extends CoreCourseModuleMainActivityComp
): Promise<AddonModQuizAttempt[]> { ): Promise<AddonModQuizAttempt[]> {
if (!attempts || !attempts.length) { if (!attempts || !attempts.length) {
// There are no attempts to treat. // There are no attempts to treat.
quiz.gradeFormatted = AddonModQuiz.formatGrade(quiz.grade, quiz.decimalpoints);
return []; return [];
} }
@ -607,7 +610,7 @@ export class AddonModQuizIndexComponent extends CoreCourseModuleMainActivityComp
})); }));
// Get best grade. // Get best grade.
promises.push(this.getQuizGrade(quiz)); promises.push(this.getQuizGrade());
await Promise.all(promises); await Promise.all(promises);
@ -635,12 +638,9 @@ export class AddonModQuizIndexComponent extends CoreCourseModuleMainActivityComp
/** /**
* Get quiz grade data. * Get quiz grade data.
* *
* @param quiz Quiz.
* @return Promise resolved when done. * @return Promise resolved when done.
*/ */
protected async getQuizGrade(quiz: AddonModQuizQuizData): Promise<void> { protected async getQuizGrade(): Promise<void> {
this.bestGrade = await AddonModQuiz.getUserBestGrade(quiz.id, { cmId: this.module.id });
try { try {
// Get gradebook grade. // Get gradebook grade.
const data = await AddonModQuiz.getGradeFromGradebook(this.courseId, this.module.id); const data = await AddonModQuiz.getGradeFromGradebook(this.courseId, this.module.id);
@ -654,7 +654,7 @@ export class AddonModQuizIndexComponent extends CoreCourseModuleMainActivityComp
} catch { } catch {
// Fallback to quiz best grade if failure or not found. // Fallback to quiz best grade if failure or not found.
this.gradebookData = { this.gradebookData = {
grade: this.bestGrade.grade, grade: this.bestGrade?.grade,
}; };
} }
} }

View File

@ -2295,6 +2295,7 @@ export type AddonModQuizGetUserBestGradeWSParams = {
export type AddonModQuizGetUserBestGradeWSResponse = { export type AddonModQuizGetUserBestGradeWSResponse = {
hasgrade: boolean; // Whether the user has a grade on the given quiz. hasgrade: boolean; // Whether the user has a grade on the given quiz.
grade?: number; // The grade (only if the user has a grade). grade?: number; // The grade (only if the user has a grade).
gradetopass?: number; // @since 3.11. The grade to pass the quiz (only if set).
warnings?: CoreWSExternalWarning[]; warnings?: CoreWSExternalWarning[];
}; };

View File

@ -9,6 +9,7 @@
"feedback": "Feedback", "feedback": "Feedback",
"grade": "Grade", "grade": "Grade",
"gradeitem": "Grade item", "gradeitem": "Grade item",
"gradepass": "Grade to pass",
"grades": "Grades", "grades": "Grades",
"lettergrade": "Letter grade", "lettergrade": "Letter grade",
"manualitem": "Manual item", "manualitem": "Manual item",