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);