From 6b274c14cd02bcf8fc8d3d1c4cc8be8f7b03632b Mon Sep 17 00:00:00 2001 From: dpalou Date: Wed, 26 Sep 2018 11:33:00 +0200 Subject: [PATCH] MOBILE-2575 course: Allow selecting another tab in course --- src/core/course/pages/section/section.ts | 19 ++++++++++++++++++- src/core/course/providers/options-delegate.ts | 9 ++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/core/course/pages/section/section.ts b/src/core/course/pages/section/section.ts index e2b51ce58..4184c17ac 100644 --- a/src/core/course/pages/section/section.ts +++ b/src/core/course/pages/section/section.ts @@ -62,6 +62,7 @@ export class CoreCourseSectionPage implements OnDestroy { protected module: any; protected completionObserver; protected courseStatusObserver; + protected firstTabName: string; protected isDestroyed = false; constructor(navParams: NavParams, private courseProvider: CoreCourseProvider, private domUtils: CoreDomUtilsProvider, @@ -74,6 +75,7 @@ export class CoreCourseSectionPage implements OnDestroy { this.sectionId = navParams.get('sectionId'); this.sectionNumber = navParams.get('sectionNumber'); this.module = navParams.get('module'); + this.firstTabName = navParams.get('selectedTab'); // Get the title to display. We dont't have sections yet. this.title = courseFormatDelegate.getCourseTitle(this.course); @@ -228,13 +230,28 @@ export class CoreCourseSectionPage implements OnDestroy { // Load the course handlers. promises.push(this.courseOptionsDelegate.getHandlersToDisplay(this.injector, this.course, refresh, false) .then((handlers) => { + let tabToLoad; + // Add the courseId to the handler component data. - handlers.forEach((handler) => { + handlers.forEach((handler, index) => { handler.data.componentData = handler.data.componentData || {}; handler.data.componentData.courseId = this.course.id; + + // Check if this handler should be the first selected tab. + if (this.firstTabName && handler.name == this.firstTabName) { + tabToLoad = index + 1; + } }); this.courseHandlers = handlers; + + // Select the tab if needed. + this.firstTabName = undefined; + if (tabToLoad) { + setTimeout(() => { + this.tabsComponent.selectTab(tabToLoad); + }); + } })); return Promise.all(promises).catch((error) => { diff --git a/src/core/course/providers/options-delegate.ts b/src/core/course/providers/options-delegate.ts index 7f2f9968c..7ba2d5ff5 100644 --- a/src/core/course/providers/options-delegate.ts +++ b/src/core/course/providers/options-delegate.ts @@ -109,6 +109,12 @@ export interface CoreCourseOptionsHandlerToDisplay { */ data: CoreCourseOptionsHandlerData; + /** + * Name of the handler, or name and sub context (AddonMessages, AddonMessages:blockContact, ...). + * @type {string} + */ + name: string; + /** * The highest priority is displayed first. * @type {number} @@ -277,7 +283,8 @@ export class CoreCourseOptionsDelegate extends CoreDelegate { handlersToDisplay.push({ data: data, priority: handler.priority, - prefetch: handler.prefetch && handler.prefetch.bind(handler) + prefetch: handler.prefetch && handler.prefetch.bind(handler), + name: handler.name }); }).catch((err) => { this.logger.error('Error getting data for handler', handler.name, err);