MOBILE-4550 quiz: Rename isAttemptFinished to isAttemptCompleted

It's a bit weird that isAttemptFinished would return true for an attempt with state different than 'finished', using the word complete reduces the confusion.
main
Dani Palou 2024-04-18 16:04:54 +02:00
parent 08797cc9d5
commit ec195696e0
8 changed files with 32 additions and 32 deletions

View File

@ -264,7 +264,7 @@ export class AddonModQuizIndexComponent extends CoreCourseModuleMainActivityComp
// Check if user can create/continue attempts.
if (this.attempts.length) {
const last = this.attempts[this.attempts.length - 1];
this.moreAttempts = !AddonModQuiz.isAttemptFinished(last.state) || !this.attemptAccessInfo.isfinished;
this.moreAttempts = !AddonModQuiz.isAttemptCompleted(last.state) || !this.attemptAccessInfo.isfinished;
} else {
this.moreAttempts = !this.attemptAccessInfo.isfinished;
}
@ -283,7 +283,7 @@ export class AddonModQuizIndexComponent extends CoreCourseModuleMainActivityComp
this.buttonText = '';
if (quiz.hasquestions !== 0) {
if (this.attempts.length && !AddonModQuiz.isAttemptFinished(this.attempts[this.attempts.length - 1].state)) {
if (this.attempts.length && !AddonModQuiz.isAttemptCompleted(this.attempts[this.attempts.length - 1].state)) {
// Last attempt is unfinished.
if (this.quizAccessInfo?.canattempt) {
this.buttonText = 'addon.mod_quiz.continueattemptquiz';
@ -591,10 +591,10 @@ export class AddonModQuizIndexComponent extends CoreCourseModuleMainActivityComp
return [];
}
const lastFinished = AddonModQuiz.getLastFinishedAttemptFromList(attempts);
const lastCompleted = AddonModQuiz.getLastCompletedAttemptFromList(attempts);
let openReview = false;
if (this.autoReview && lastFinished && lastFinished.id >= this.autoReview.attemptId) {
if (this.autoReview && lastCompleted && lastCompleted.id >= this.autoReview.attemptId) {
// User just finished an attempt in offline and it seems it's been synced, since it's finished in online.
// Go to the review of this attempt if the user hasn't left this view.
if (!this.isDestroyed && this.isCurrentView) {
@ -615,7 +615,7 @@ export class AddonModQuizIndexComponent extends CoreCourseModuleMainActivityComp
// Calculate data to construct the header of the attempts table.
AddonModQuizHelper.setQuizCalculatedData(quiz, this.options);
this.overallStats = !!lastFinished && this.options.alloptions.marks >= QuestionDisplayOptionsMarks.MARK_AND_MAX;
this.overallStats = !!lastCompleted && this.options.alloptions.marks >= QuestionDisplayOptionsMarks.MARK_AND_MAX;
// Calculate data to show for each attempt.
const formattedAttempts = await Promise.all(attempts.map((attempt, index) => {

View File

@ -30,7 +30,7 @@
<p *ngFor="let sentence of attempt.readableState">{{ sentence }}</p>
</ion-label>
</ion-item>
<ng-container *ngIf="attempt.finished && attempt.sumgrades !== null">
<ng-container *ngIf="attempt.completed && attempt.sumgrades !== null">
<ion-item *ngFor="let gradeItemMark of attempt.gradeitemmarks ?? []" class="ion-text-wrap">
<ion-label>
<p class="item-heading">{{ gradeItemMark.name }} / {{ gradeItemMark.maxgrade }}</p>
@ -67,7 +67,7 @@
</ion-item>
</ion-list>
<div collapsible-footer appearOnBottom *ngIf="loaded && attempt && showReviewColumn && attempt.finished" slot="fixed">
<div collapsible-footer appearOnBottom *ngIf="loaded && attempt && showReviewColumn && attempt.completed" slot="fixed">
<div class="list-item-limited-width">
<ion-button class="ion-margin ion-text-wrap" expand="block" (click)="reviewAttempt()">
<ion-icon name="fas-magnifying-glass" slot="start" aria-hidden="true" />

View File

@ -114,7 +114,7 @@ export class AddonModQuizAttemptPage implements OnInit {
// Check if the feedback should be displayed.
const grade = Number(this.attempt.rescaledGrade);
if (this.quiz.showFeedbackColumn && AddonModQuiz.isAttemptFinished(this.attempt.state) &&
if (this.quiz.showFeedbackColumn && AddonModQuiz.isAttemptCompleted(this.attempt.state) &&
options.someoptions.overallfeedback && isSafeNumber(grade)) {
// Feedback should be displayed, get the feedback for the grade.

View File

@ -390,7 +390,7 @@ export class AddonModQuizPlayerPage implements OnInit, OnDestroy, CanLeave {
true,
);
this.newAttempt = AddonModQuiz.isAttemptFinished(this.lastAttempt.state);
this.newAttempt = AddonModQuiz.isAttemptCompleted(this.lastAttempt.state);
}
/**

View File

@ -115,8 +115,8 @@ export class AddonModQuizPrefetchHandlerService extends CoreCourseActivityPrefet
let files: CoreWSFile[] = [];
await Promise.all(attempts.map(async (attempt) => {
if (!AddonModQuiz.isAttemptFinished(attempt.state)) {
// Attempt not finished, no feedback files.
if (!AddonModQuiz.isAttemptCompleted(attempt.state)) {
// Attempt not completed, no feedback files.
return;
}
@ -241,9 +241,9 @@ export class AddonModQuizPrefetchHandlerService extends CoreCourseActivityPrefet
siteId,
});
const isLastFinished = !attempts.length || AddonModQuiz.isAttemptFinished(attempts[attempts.length - 1].state);
const isLastCompleted = !attempts.length || AddonModQuiz.isAttemptCompleted(attempts[attempts.length - 1].state);
return quiz.attempts === 0 || (quiz.attempts ?? 0) > attempts.length || !isLastFinished;
return quiz.attempts === 0 || (quiz.attempts ?? 0) > attempts.length || !isLastCompleted;
}
/**
@ -330,7 +330,7 @@ export class AddonModQuizPrefetchHandlerService extends CoreCourseActivityPrefet
let startAttempt = false;
if (canStart || attempt) {
if (canStart && (!attempt || AddonModQuiz.isAttemptFinished(attempt.state))) {
if (canStart && (!attempt || AddonModQuiz.isAttemptCompleted(attempt.state))) {
// Check if the user can attempt the quiz.
if (attemptAccessInfo.preventnewattemptreasons.length) {
throw new CoreError(CoreTextUtils.buildMessage(attemptAccessInfo.preventnewattemptreasons));
@ -420,7 +420,7 @@ export class AddonModQuizPrefetchHandlerService extends CoreCourseActivityPrefet
siteId,
};
if (AddonModQuiz.isAttemptFinished(attempt.state)) {
if (AddonModQuiz.isAttemptCompleted(attempt.state)) {
// Attempt is finished, get feedback and review data.
const attemptGrade = AddonModQuiz.rescaleGrade(attempt.sumgrades, quiz, false);
const attemptGradeNumber = attemptGrade !== undefined && Number(attemptGrade);
@ -611,8 +611,8 @@ export class AddonModQuizPrefetchHandlerService extends CoreCourseActivityPrefet
// Quiz was downloaded, set the new status.
// If no attempts or last is finished we'll mark it as not downloaded to show download icon.
const lastAttempt = attempts[attempts.length - 1];
const isLastFinished = !lastAttempt || AddonModQuiz.isAttemptFinished(lastAttempt.state);
const newStatus = isLastFinished ? DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED : DownloadStatus.DOWNLOADED;
const isLastCompleted = !lastAttempt || AddonModQuiz.isAttemptCompleted(lastAttempt.state);
const newStatus = isLastCompleted ? DownloadStatus.DOWNLOADABLE_NOT_DOWNLOADED : DownloadStatus.DOWNLOADED;
await CoreFilepool.storePackageStatus(options.siteId, newStatus, this.component, quiz.coursemodule);
}

View File

@ -64,8 +64,8 @@ export class AddonModQuizHelperProvider {
return this.canReviewOtherUserAttempt(quiz, accessInfo, attempt);
}
if (!AddonModQuiz.isAttemptFinished(attempt.state)) {
// Cannot review own unfinished attempts.
if (!AddonModQuiz.isAttemptCompleted(attempt.state)) {
// Cannot review own uncompleted attempts.
return false;
}
@ -379,16 +379,16 @@ export class AddonModQuizHelperProvider {
const formattedAttempt = <AddonModQuizAttempt> attempt;
formattedAttempt.rescaledGrade = AddonModQuiz.rescaleGrade(attempt.sumgrades, quiz, false);
formattedAttempt.finished = AddonModQuiz.isAttemptFinished(attempt.state);
formattedAttempt.completed = AddonModQuiz.isAttemptCompleted(attempt.state);
formattedAttempt.readableState = AddonModQuiz.getAttemptReadableState(quiz, attempt);
if (quiz.showMarkColumn && formattedAttempt.finished) {
if (quiz.showMarkColumn && formattedAttempt.completed) {
formattedAttempt.readableMark = AddonModQuiz.formatGrade(attempt.sumgrades, quiz.decimalpoints);
} else {
formattedAttempt.readableMark = '';
}
if (quiz.showGradeColumn && formattedAttempt.finished) {
if (quiz.showGradeColumn && formattedAttempt.completed) {
formattedAttempt.readableGrade = AddonModQuiz.formatGrade(
Number(formattedAttempt.rescaledGrade),
quiz.decimalpoints,
@ -535,7 +535,7 @@ export type AddonModQuizQuizData = AddonModQuizQuizWSData & {
export type AddonModQuizAttempt = AddonModQuizAttemptWSData & {
finishedOffline?: boolean;
rescaledGrade?: string;
finished?: boolean;
completed?: boolean;
readableState?: string[];
readableMark?: string;
readableGrade?: string;

View File

@ -105,13 +105,13 @@ export class AddonModQuizSyncProvider extends CoreCourseActivitySyncBaseProvider
// Check if online attempt was finished because of the sync.
let attemptFinished = false;
if (options.onlineAttempt && !AddonModQuiz.isAttemptFinished(options.onlineAttempt.state)) {
if (options.onlineAttempt && !AddonModQuiz.isAttemptCompleted(options.onlineAttempt.state)) {
// Attempt wasn't finished at start. Check if it's finished now.
const attempts = await AddonModQuiz.getUserAttempts(quiz.id, { cmId: quiz.coursemodule, siteId });
const attempt = attempts.find(attempt => attempt.id == options?.onlineAttempt?.id);
attemptFinished = attempt ? AddonModQuiz.isAttemptFinished(attempt.state) : false;
attemptFinished = attempt ? AddonModQuiz.isAttemptCompleted(attempt.state) : false;
}
return { warnings, attemptFinished, updated: !!options.updated || !!options.removeAttempt };
@ -324,7 +324,7 @@ export class AddonModQuizSyncProvider extends CoreCourseActivitySyncBaseProvider
const lastAttemptId = onlineAttempts.length ? onlineAttempts[onlineAttempts.length - 1].id : undefined;
const onlineAttempt = onlineAttempts.find((attempt) => attempt.id == offlineAttempt.id);
if (!onlineAttempt || AddonModQuiz.isAttemptFinished(onlineAttempt.state)) {
if (!onlineAttempt || AddonModQuiz.isAttemptCompleted(onlineAttempt.state)) {
// Attempt not found or it's finished in online. Discard it.
warnings.push(Translate.instant('addon.mod_quiz.warningattemptfinished'));

View File

@ -754,12 +754,12 @@ export class AddonModQuizProvider {
}
/**
* Given a list of attempts, returns the last finished attempt.
* Given a list of attempts, returns the last completed attempt.
*
* @param attempts Attempts sorted. First attempt should be the first on the list.
* @returns Last finished attempt.
* @returns Last completed attempt.
*/
getLastFinishedAttemptFromList(attempts?: AddonModQuizAttemptWSData[]): AddonModQuizAttemptWSData | undefined {
getLastCompletedAttemptFromList(attempts?: AddonModQuizAttemptWSData[]): AddonModQuizAttemptWSData | undefined {
if (!attempts) {
return;
}
@ -767,7 +767,7 @@ export class AddonModQuizProvider {
for (let i = attempts.length - 1; i >= 0; i--) {
const attempt = attempts[i];
if (this.isAttemptFinished(attempt.state)) {
if (this.isAttemptCompleted(attempt.state)) {
return attempt;
}
}
@ -1514,12 +1514,12 @@ export class AddonModQuizProvider {
}
/**
* Check if an attempt is finished based on its state.
* Check if an attempt is "completed": finished or abandoned.
*
* @param state Attempt's state.
* @returns Whether it's finished.
*/
isAttemptFinished(state?: string): boolean {
isAttemptCompleted(state?: string): boolean {
return state === AddonModQuizAttemptStates.FINISHED || state === AddonModQuizAttemptStates.ABANDONED;
}