From 857679a89d17f86c94cb6cbb4eba4c111ce75058 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Fri, 4 Feb 2022 10:04:59 +0100 Subject: [PATCH] MOBILE-3814 course: Fix empty course index --- .../components/course-index/course-index.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 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 b33f61ee3..bbc2601c1 100644 --- a/src/core/features/course/components/course-index/course-index.ts +++ b/src/core/features/course/components/course-index/course-index.ts @@ -55,18 +55,19 @@ export class CoreCourseCourseIndexComponent implements OnInit { * @inheritdoc */ async ngOnInit(): Promise { - - if (!this.course || !this.sections || !this.course.enablecompletion || !('courseformatoptions' in this.course) || - !this.course.courseformatoptions) { + if (!this.course || !this.sections) { this.closeModal(); return; } - const formatOptions = CoreUtils.objectToKeyValueMap(this.course.courseformatoptions, 'name', 'value'); + let completionEnabled = !!this.course.enablecompletion; + if (completionEnabled && 'courseformatoptions' in this.course && this.course.courseformatoptions) { + const formatOptions = CoreUtils.objectToKeyValueMap(this.course.courseformatoptions, 'name', 'value'); - if (!formatOptions || formatOptions.completionusertracked === false) { - return; + if (formatOptions) { + completionEnabled = !!formatOptions.completionusertracked; + } } const currentSection = await CoreCourseFormatDelegate.getCurrentSection(this.course, this.sections); @@ -85,7 +86,7 @@ export class CoreCourseCourseIndexComponent implements OnInit { const modules = section.modules .filter((module) => module.visibleoncoursepage !== 0 && !module.noviewlink) .map((module) => { - const completionStatus = module.completiondata === undefined || + const completionStatus = !completionEnabled || module.completiondata === undefined || module.completiondata.tracking == CoreCourseModuleCompletionTracking.COMPLETION_TRACKING_NONE ? undefined : module.completiondata.state;