From cbbf61088afd1952966009e8a34f3e1741b3f1a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Wed, 10 Apr 2024 15:40:06 +0200 Subject: [PATCH 1/2] MOBILE-4483 types: Add some types available since 4.4 --- src/addons/mod/quiz/services/quiz.ts | 1 + src/core/features/course/services/course.ts | 4 ++++ src/core/features/question/services/question.ts | 5 +++-- src/core/features/user/services/user.ts | 1 + 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/addons/mod/quiz/services/quiz.ts b/src/addons/mod/quiz/services/quiz.ts index a80da3b48..b50123dbd 100644 --- a/src/addons/mod/quiz/services/quiz.ts +++ b/src/addons/mod/quiz/services/quiz.ts @@ -2105,6 +2105,7 @@ export type AddonModQuizGetAttemptSummaryWSParams = { */ export type AddonModQuizGetAttemptSummaryWSResponse = { questions: CoreQuestionQuestionWSData[]; + totalunanswered?: number; // @since 4.4. Total unanswered questions. warnings?: CoreWSExternalWarning[]; }; diff --git a/src/core/features/course/services/course.ts b/src/core/features/course/services/course.ts index 30ce7da75..f9122e912 100644 --- a/src/core/features/course/services/course.ts +++ b/src/core/features/course/services/course.ts @@ -1659,6 +1659,8 @@ export type CoreCourseCompletionActivityStatus = { description: string; // Completion description. }; }[]; + isoverallcomplete?: boolean; // @since 4.4. + // Whether the overall completion state of this course module should be marked as complete or not. offline?: boolean; // Whether the completions is offline and not yet synced. }; @@ -1840,6 +1842,8 @@ export type CoreCourseModuleWSCompletionData = { istrackeduser?: boolean; // @since 3.11. Whether completion is being tracked for this user. uservisible?: boolean; // @since 3.11. Whether this activity is visible to the user. details?: CoreCourseModuleWSRuleDetails[]; // @since 3.11. An array of completion details. + isoverallcomplete?: boolean; // @since 4.4. + // Whether the overall completion state of this course module should be marked as complete or not. }; /** diff --git a/src/core/features/question/services/question.ts b/src/core/features/question/services/question.ts index e65976006..54ab8e5f9 100644 --- a/src/core/features/question/services/question.ts +++ b/src/core/features/question/services/question.ts @@ -627,8 +627,9 @@ export type CoreQuestionQuestionWSData = { hasautosavedstep?: boolean; // Whether this question attempt has autosaved data. flagged: boolean; // Whether the question is flagged or not. questionnumber?: string; // @since 4.2. Question ordering number in the quiz. - state?: string; // The state where the question is in. It won't be returned if the user cannot see it. - status?: string; // Current formatted state of the question. + state?: string; // The state where the question is in terms of correctness. + // It will not be returned if the user cannot see it due to the quiz display correctness settings. + status?: string; // Human readable state of the question. stateclass?: // @since 4.4. A machine-readable class name for the state that this question attempt is in. typeof QUESTION_TODO_STATE_CLASSES[number] | typeof QUESTION_INVALID_STATE_CLASSES[number] | diff --git a/src/core/features/user/services/user.ts b/src/core/features/user/services/user.ts index e4734b160..000a5b0a1 100644 --- a/src/core/features/user/services/user.ts +++ b/src/core/features/user/services/user.ts @@ -1162,6 +1162,7 @@ type CoreEnrolSearchUsersWSParams = { searchanywhere: boolean; // Find a match anywhere, or only at the beginning. page: number; // Page number. perpage: number; // Number per page. + contextid?: number; // @since 4.4. Context ID. }; /** From 2d317e3857376a2f63f20b996f0f452fbd368c17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Wed, 10 Apr 2024 17:01:13 +0200 Subject: [PATCH 2/2] MOBILE-4483 completion: Check isoverallcomplete to mark as completed --- .../components/course-index/course-index.ts | 8 +++---- .../module-completion/module-completion.ts | 5 +--- .../features/course/services/course-helper.ts | 23 +++++++++++++++++++ 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/core/features/course/components/course-index/course-index.ts b/src/core/features/course/components/course-index/course-index.ts index a67118fde..92576c5c0 100644 --- a/src/core/features/course/components/course-index/course-index.ts +++ b/src/core/features/course/components/course-index/course-index.ts @@ -16,7 +16,6 @@ import { Component, ElementRef, Input, OnInit } from '@angular/core'; import { CoreCourse, CoreCourseModuleCompletionStatus, - CoreCourseModuleCompletionTracking, CoreCourseProvider, } from '@features/course/services/course'; import { CoreCourseHelper, CoreCourseModuleData, CoreCourseSection } from '@features/course/services/course-helper'; @@ -88,10 +87,9 @@ export class CoreCourseCourseIndexComponent implements OnInit { const modules = section.modules .filter((module) => this.renderModule(section, module)) .map((module) => { - const completionStatus = !completionEnabled || module.completiondata === undefined || - module.completiondata.tracking == CoreCourseModuleCompletionTracking.COMPLETION_TRACKING_NONE - ? undefined - : module.completiondata.state; + const completionStatus = completionEnabled + ? CoreCourseHelper.getCompletionStatus(module.completiondata) + : undefined; return { id: module.id, diff --git a/src/core/features/course/components/module-completion/module-completion.ts b/src/core/features/course/components/module-completion/module-completion.ts index 8f3b2eb29..eaf008b04 100644 --- a/src/core/features/course/components/module-completion/module-completion.ts +++ b/src/core/features/course/components/module-completion/module-completion.ts @@ -17,7 +17,6 @@ import { Component, Input, OnChanges, OnDestroy, OnInit, SimpleChange } from '@a import { CoreCourseModuleCompletionBaseComponent } from '@features/course/classes/module-completion'; import { CoreCourseModuleCompletionStatus, - CoreCourseModuleCompletionTracking, } from '@features/course/services/course'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreCourseModuleCompletionDetailsComponent } from '../module-completion-details/module-completion-details'; @@ -87,9 +86,7 @@ export class CoreCourseModuleCompletionComponent return; } - const completionStatus = this.completion.tracking == CoreCourseModuleCompletionTracking.COMPLETION_TRACKING_NONE - ? undefined - : this.completion.state; + const completionStatus = CoreCourseHelper.getCompletionStatus(this.completion); this.completed = completionStatus !== CoreCourseModuleCompletionStatus.COMPLETION_INCOMPLETE && completionStatus !== CoreCourseModuleCompletionStatus.COMPLETION_COMPLETE_FAIL; diff --git a/src/core/features/course/services/course-helper.ts b/src/core/features/course/services/course-helper.ts index 0b770a84d..dce4f5be3 100644 --- a/src/core/features/course/services/course-helper.ts +++ b/src/core/features/course/services/course-helper.ts @@ -2082,6 +2082,29 @@ export class CoreCourseHelperProvider { return !!adminOptions[courseId]?.['reports']; } + /** + * Get the completion status of a module. + * + * @param completion Completion data. + * @returns Completion status or undefined if not available. + */ + getCompletionStatus(completion?: CoreCourseModuleCompletionData): CoreCourseModuleCompletionStatus | undefined { + if (completion === undefined) { + return undefined; + } + + if (completion.tracking === CoreCourseModuleCompletionTracking.COMPLETION_TRACKING_NONE) { + return undefined; + } + + if (completion.isoverallcomplete === true) { + // If the module is marked as overall complete, we'll show it as complete. + return CoreCourseModuleCompletionStatus.COMPLETION_COMPLETE; + } + + return completion.state; + } + } export const CoreCourseHelper = makeSingleton(CoreCourseHelperProvider);