From 7619d38fb72e39409dd9e446d94deb909c054fc0 Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Thu, 13 Apr 2023 15:44:47 +0200 Subject: [PATCH] MOBILE-4277 course: Show modules in course index Including the ones that were previously hidden, such as text and label. --- .../components/course-format/course-format.ts | 6 +++-- .../components/course-index/course-index.ts | 26 +++++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/core/features/course/components/course-format/course-format.ts b/src/core/features/course/components/course-format/course-format.ts index 60514d716..15d60a938 100644 --- a/src/core/features/course/components/course-format/course-format.ts +++ b/src/core/features/course/components/course-format/course-format.ts @@ -441,8 +441,10 @@ export class CoreCourseFormatComponent implements OnInit, OnChanges, OnDestroy { await CoreCourseModuleDelegate.getModuleDataFor(module.modname, module, this.course.id); } - if (CoreCourseHelper.canUserViewModule(module, section) && module.handlerData?.action) { - module.handlerData.action(data.event, module, module.course); + if (CoreCourseHelper.canUserViewModule(module, section)) { + this.scrollToModule(module.id); + + module.handlerData?.action?.(data.event, module, module.course); } this.moduleId = data.moduleId; 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 3e9ee1499..cd09e1f15 100644 --- a/src/core/features/course/components/course-index/course-index.ts +++ b/src/core/features/course/components/course-index/course-index.ts @@ -18,9 +18,10 @@ import { CoreCourseModuleCompletionTracking, CoreCourseProvider, } from '@features/course/services/course'; -import { CoreCourseHelper, CoreCourseSection } from '@features/course/services/course-helper'; +import { CoreCourseHelper, CoreCourseModuleData, CoreCourseSection } from '@features/course/services/course-helper'; import { CoreCourseFormatDelegate } from '@features/course/services/format-delegate'; import { CoreCourseAnyCourseData } from '@features/courses/services/courses'; +import { CoreSites } from '@services/sites'; import { CoreUtils } from '@services/utils/utils'; import { ModalController } from '@singletons'; import { CoreDom } from '@singletons/dom'; @@ -79,7 +80,7 @@ export class CoreCourseCourseIndexComponent implements OnInit { .filter((section) => !CoreCourseHelper.isSectionStealth(section)) .map((section) => { const modules = section.modules - .filter((module) => !CoreCourseHelper.isModuleStealth(module, section) && !module.noviewlink) + .filter((module) => this.renderModule(section, module)) .map((module) => { const completionStatus = !completionEnabled || module.completiondata === undefined || module.completiondata.tracking == CoreCourseModuleCompletionTracking.COMPLETION_TRACKING_NONE @@ -155,6 +156,27 @@ export class CoreCourseCourseIndexComponent implements OnInit { ModalController.dismiss({ event, sectionId, moduleId }); } + /** + * Check whether a module should be rendered or not. + * + * @param section Section. + * @param module Module + * @returns Whether the module should be rendered or not. + */ + protected renderModule(section: CoreCourseSection, module: CoreCourseModuleData): boolean { + if (CoreCourseHelper.isModuleStealth(module, section)) { + return false; + } + + const site = CoreSites.getRequiredCurrentSite(); + + if (site.isVersionGreaterEqualThan('4.2')) { + return true; + } + + return !module.noviewlink; + } + } type CourseIndexSection = {