From 53f986a26bd573ef4cd9e4bf77e1ae7839eabfea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Fri, 11 Feb 2022 16:34:25 +0100 Subject: [PATCH] MOBILE-3970 course: Move courseMenuHandlers to course summary --- .../course/pages/contents/contents.html | 5 --- .../course/pages/contents/contents.ts | 28 +------------- .../course/pages/preview/preview.html | 16 ++++++-- .../course/pages/preview/preview.page.ts | 38 ++++++++++++++++++- 4 files changed, 49 insertions(+), 38 deletions(-) diff --git a/src/core/features/course/pages/contents/contents.html b/src/core/features/course/pages/contents/contents.html index 2648ff943..b12da3cc6 100644 --- a/src/core/features/course/pages/contents/contents.html +++ b/src/core/features/course/pages/contents/contents.html @@ -1,9 +1,4 @@ - - - - diff --git a/src/core/features/course/pages/contents/contents.ts b/src/core/features/course/pages/contents/contents.ts index d93a3cb18..26c407028 100644 --- a/src/core/features/course/pages/contents/contents.ts +++ b/src/core/features/course/pages/contents/contents.ts @@ -29,10 +29,7 @@ import { } from '@features/course/services/course-helper'; import { CoreCourseFormatDelegate } from '@features/course/services/format-delegate'; import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate'; -import { - CoreCourseOptionsDelegate, - CoreCourseOptionsMenuHandlerToDisplay, -} from '@features/course/services/course-options-delegate'; +import { CoreCourseOptionsMenuHandlerToDisplay } from '@features/course/services/course-options-delegate'; import { CoreCourseSync, CoreCourseSyncProvider } from '@features/course/services/sync'; import { CoreCourseFormatComponent } from '../../components/format/format'; import { @@ -69,7 +66,6 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy { protected syncObserver?: CoreEventObserver; protected isDestroyed = false; protected modulesHaveCompletion = false; - protected isGuest = false; protected debouncedUpdateCachedCompletion?: () => void; // Update the cached completion after a certain time. /** @@ -89,7 +85,6 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy { this.sectionId = CoreNavigator.getRouteNumberParam('sectionId'); this.sectionNumber = CoreNavigator.getRouteNumberParam('sectionNumber'); this.moduleId = CoreNavigator.getRouteNumberParam('moduleId'); - this.isGuest = !!CoreNavigator.getRouteBooleanParam('isGuest'); this.debouncedUpdateCachedCompletion = CoreUtils.debounce(() => { if (this.modulesHaveCompletion) { @@ -184,7 +179,6 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy { try { await Promise.all([ this.loadSections(refresh), - this.loadMenuHandlers(refresh), this.loadCourseFormatOptions(), ]); } catch (error) { @@ -248,16 +242,6 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy { this.displayRefresher = CoreCourseFormatDelegate.displayRefresher(this.course, this.sections); } - /** - * Load the course menu handlers. - * - * @param refresh If it's refreshing content. - * @return Promise resolved when done. - */ - protected async loadMenuHandlers(refresh?: boolean): Promise { - this.courseMenuHandlers = await CoreCourseOptionsDelegate.getMenuHandlersToDisplay(this.course, refresh, this.isGuest); - } - /** * Load course format options if needed. * @@ -379,16 +363,6 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy { } } - /** - * Opens a menu item registered to the delegate. - * - * @param item Item to open - */ - openMenuItem(item: CoreCourseOptionsMenuHandlerToDisplay): void { - const params = Object.assign({ course: this.course }, item.data.pageParams); - CoreNavigator.navigateToSitePath(item.data.page, { params }); - } - /** * Page destroyed. */ diff --git a/src/core/features/course/pages/preview/preview.html b/src/core/features/course/pages/preview/preview.html index 60cedf7c5..2bb64554c 100644 --- a/src/core/features/course/pages/preview/preview.html +++ b/src/core/features/course/pages/preview/preview.html @@ -23,7 +23,7 @@
-
+

@@ -94,13 +94,13 @@ -

+
- + - +

{{ instance.name }}

@@ -122,6 +122,14 @@

{{ 'core.courses.notenrollable' | translate }}

+
+ + + + + {{item.data.title | translate }} + diff --git a/src/core/features/course/pages/preview/preview.page.ts b/src/core/features/course/pages/preview/preview.page.ts index c2b686885..f269e84c3 100644 --- a/src/core/features/course/pages/preview/preview.page.ts +++ b/src/core/features/course/pages/preview/preview.page.ts @@ -26,7 +26,10 @@ import { CoreCoursesProvider, CoreEnrolledCourseData, } from '@features/courses/services/courses'; -import { CoreCourseOptionsDelegate } from '@features/course/services/course-options-delegate'; +import { + CoreCourseOptionsDelegate, + CoreCourseOptionsMenuHandlerToDisplay, +} from '@features/course/services/course-options-delegate'; import { CoreCourseHelper } from '@features/course/services/course-helper'; import { ModalController, NgZone, Platform, Translate } from '@singletons'; import { CoreCoursesSelfEnrolPasswordComponent } from '../../../courses/components/self-enrol-password/self-enrol-password'; @@ -59,6 +62,8 @@ export class CoreCoursePreviewPage implements OnInit, OnDestroy { courseImageUrl?: string; progress?: number; + courseMenuHandlers: CoreCourseOptionsMenuHandlerToDisplay[] = []; + protected isGuestEnabled = false; protected useGuestAccess = false; protected guestInstanceId?: number; @@ -145,8 +150,10 @@ export class CoreCoursePreviewPage implements OnInit, OnDestroy { /** * Convenience function to get course. We use this to determine if a user can see the course or not. + * + * @param refresh If it's refreshing content. */ - protected async getCourse(): Promise { + protected async getCourse(refresh = false): Promise { // Get course enrolment methods. this.selfEnrolInstances = []; @@ -223,9 +230,26 @@ export class CoreCoursePreviewPage implements OnInit, OnDestroy { this.progress = this.course.progress; } + await this.loadMenuHandlers(refresh); + this.dataLoaded = true; } + /** + * Load the course menu handlers. + * + * @param refresh If it's refreshing content. + * @return Promise resolved when done. + */ + protected async loadMenuHandlers(refresh?: boolean): Promise { + if (!this.course) { + return; + } + + this.courseMenuHandlers = + await CoreCourseOptionsDelegate.getMenuHandlersToDisplay(this.course, refresh, this.useGuestAccess); + } + /** * Open the course. * @@ -399,6 +423,16 @@ export class CoreCoursePreviewPage implements OnInit, OnDestroy { } } + /** + * Opens a menu item registered to the delegate. + * + * @param item Item to open + */ + openMenuItem(item: CoreCourseOptionsMenuHandlerToDisplay): void { + const params = Object.assign({ course: this.course }, item.data.pageParams); + CoreNavigator.navigateToSitePath(item.data.page, { params }); + } + /** * Close the modal. */