MOBILE-3814 course: Fix empty course index

main
Pau Ferrer Ocaña 2022-02-04 10:04:59 +01:00
parent b4b7ec2faf
commit 857679a89d
1 changed files with 8 additions and 7 deletions

View File

@ -55,18 +55,19 @@ export class CoreCourseCourseIndexComponent implements OnInit {
* @inheritdoc * @inheritdoc
*/ */
async ngOnInit(): Promise<void> { async ngOnInit(): Promise<void> {
if (!this.course || !this.sections) {
if (!this.course || !this.sections || !this.course.enablecompletion || !('courseformatoptions' in this.course) ||
!this.course.courseformatoptions) {
this.closeModal(); this.closeModal();
return; 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) { if (formatOptions) {
return; completionEnabled = !!formatOptions.completionusertracked;
}
} }
const currentSection = await CoreCourseFormatDelegate.getCurrentSection(this.course, this.sections); const currentSection = await CoreCourseFormatDelegate.getCurrentSection(this.course, this.sections);
@ -85,7 +86,7 @@ export class CoreCourseCourseIndexComponent implements OnInit {
const modules = section.modules const modules = section.modules
.filter((module) => module.visibleoncoursepage !== 0 && !module.noviewlink) .filter((module) => module.visibleoncoursepage !== 0 && !module.noviewlink)
.map((module) => { .map((module) => {
const completionStatus = module.completiondata === undefined || const completionStatus = !completionEnabled || module.completiondata === undefined ||
module.completiondata.tracking == CoreCourseModuleCompletionTracking.COMPLETION_TRACKING_NONE module.completiondata.tracking == CoreCourseModuleCompletionTracking.COMPLETION_TRACKING_NONE
? undefined ? undefined
: module.completiondata.state; : module.completiondata.state;