diff --git a/src/addon/mod/assign/providers/module-handler.ts b/src/addon/mod/assign/providers/module-handler.ts index 937aeeb1d..1aa0cda0d 100644 --- a/src/addon/mod/assign/providers/module-handler.ts +++ b/src/addon/mod/assign/providers/module-handler.ts @@ -68,8 +68,12 @@ export class AddonModAssignModuleHandler implements CoreCourseModuleHandler { title: module.name, class: 'addon-mod_assign-handler', showDownloadButton: true, - action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void { - navCtrl.push('AddonModAssignIndexPage', {module: module, courseId: courseId}, options); + action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions, params?: any): void { + const pageParams = {module: module, courseId: courseId}; + if (params) { + Object.assign(pageParams, params); + } + navCtrl.push('AddonModAssignIndexPage', pageParams, options); } }; } diff --git a/src/addon/mod/book/components/index/index.ts b/src/addon/mod/book/components/index/index.ts index 573a53778..bcb78e821 100644 --- a/src/addon/mod/book/components/index/index.ts +++ b/src/addon/mod/book/components/index/index.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { Component, Optional, Injector } from '@angular/core'; +import { Component, Optional, Injector, Input } from '@angular/core'; import { Content, PopoverController } from 'ionic-angular'; import { CoreAppProvider } from '@providers/app'; import { CoreCourseProvider } from '@core/course/providers/course'; @@ -29,6 +29,8 @@ import { AddonModBookTocPopoverComponent } from '../../components/toc-popover/to templateUrl: 'addon-mod-book-index.html', }) export class AddonModBookIndexComponent extends CoreCourseModuleMainResourceComponent { + @Input() initialChapterId: string; // The initial chapter ID to load. + component = AddonModBookProvider.COMPONENT; chapterContent: string; previousChapter: string; @@ -128,7 +130,19 @@ export class AddonModBookIndexComponent extends CoreCourseModuleMainResourceComp this.contentsMap = this.bookProvider.getContentsMap(this.module.contents); this.chapters = this.bookProvider.getTocList(this.module.contents); + if (typeof this.currentChapter == 'undefined' && typeof this.initialChapterId != 'undefined' && this.chapters) { + // Initial chapter set. Validate that the chapter exists. + const chapter = this.chapters.find((chapter) => { + return chapter.id == this.initialChapterId; + }); + + if (chapter) { + this.currentChapter = this.initialChapterId; + } + } + if (typeof this.currentChapter == 'undefined') { + // Load the first chapter. this.currentChapter = this.bookProvider.getFirstChapter(this.chapters); } diff --git a/src/addon/mod/book/pages/index/index.html b/src/addon/mod/book/pages/index/index.html index 14f0a66bd..78c828426 100644 --- a/src/addon/mod/book/pages/index/index.html +++ b/src/addon/mod/book/pages/index/index.html @@ -12,5 +12,5 @@ - + diff --git a/src/addon/mod/book/pages/index/index.ts b/src/addon/mod/book/pages/index/index.ts index a45a34e1d..7bb9e1f0f 100644 --- a/src/addon/mod/book/pages/index/index.ts +++ b/src/addon/mod/book/pages/index/index.ts @@ -30,10 +30,12 @@ export class AddonModBookIndexPage { title: string; module: any; courseId: number; + chapterId: number; constructor(navParams: NavParams) { this.module = navParams.get('module') || {}; this.courseId = navParams.get('courseId'); + this.chapterId = navParams.get('chapterId'); this.title = this.module.name; } diff --git a/src/addon/mod/book/providers/link-handler.ts b/src/addon/mod/book/providers/link-handler.ts index 1035ef3f9..899978d4b 100644 --- a/src/addon/mod/book/providers/link-handler.ts +++ b/src/addon/mod/book/providers/link-handler.ts @@ -15,6 +15,7 @@ import { Injectable } from '@angular/core'; import { CoreContentLinksModuleIndexHandler } from '@core/contentlinks/classes/module-index-handler'; import { CoreCourseHelperProvider } from '@core/course/providers/helper'; +import { CoreContentLinksAction } from '@core/contentlinks/providers/delegate'; /** * Handler to treat links to book. @@ -26,4 +27,27 @@ export class AddonModBookLinkHandler extends CoreContentLinksModuleIndexHandler constructor(courseHelper: CoreCourseHelperProvider) { super(courseHelper, 'AddonModBook', 'book'); } + + /** + * Get the list of actions for a link (url). + * + * @param {string[]} siteIds List of sites the URL belongs to. + * @param {string} url The URL to treat. + * @param {any} params The params of the URL. E.g. 'mysite.com?id=1' -> {id: 1} + * @param {number} [courseId] Course ID related to the URL. Optional but recommended. + * @return {CoreContentLinksAction[]|Promise} List of (or promise resolved with list of) actions. + */ + getActions(siteIds: string[], url: string, params: any, courseId?: number): + CoreContentLinksAction[] | Promise { + + const modParams = params.chapterid ? {chapterId: params.chapterid} : undefined; + courseId = courseId || params.courseid || params.cid; + + return [{ + action: (siteId, navCtrl?): void => { + this.courseHelper.navigateToModule(parseInt(params.id, 10), siteId, courseId, undefined, + this.useModNameToGetModule ? this.modName : undefined, modParams); + } + }]; + } } diff --git a/src/addon/mod/book/providers/module-handler.ts b/src/addon/mod/book/providers/module-handler.ts index a1b4c9af4..6f92d6f32 100644 --- a/src/addon/mod/book/providers/module-handler.ts +++ b/src/addon/mod/book/providers/module-handler.ts @@ -65,8 +65,12 @@ export class AddonModBookModuleHandler implements CoreCourseModuleHandler { title: module.name, class: 'addon-mod_book-handler', showDownloadButton: true, - action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void { - navCtrl.push('AddonModBookIndexPage', {module: module, courseId: courseId}, options); + action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions, params?: any): void { + const pageParams = {module: module, courseId: courseId}; + if (params) { + Object.assign(pageParams, params); + } + navCtrl.push('AddonModBookIndexPage', pageParams, options); } }; } diff --git a/src/addon/mod/chat/providers/module-handler.ts b/src/addon/mod/chat/providers/module-handler.ts index e54d0fda2..4ef57c7b3 100644 --- a/src/addon/mod/chat/providers/module-handler.ts +++ b/src/addon/mod/chat/providers/module-handler.ts @@ -62,8 +62,12 @@ export class AddonModChatModuleHandler implements CoreCourseModuleHandler { icon: this.courseProvider.getModuleIconSrc(this.modName, module.modicon), title: module.name, class: 'addon-mod_chat-handler', - action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void { - navCtrl.push('AddonModChatIndexPage', {module: module, courseId: courseId}, options); + action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions, params?: any): void { + const pageParams = {module: module, courseId: courseId}; + if (params) { + Object.assign(pageParams, params); + } + navCtrl.push('AddonModChatIndexPage', pageParams, options); } }; } diff --git a/src/addon/mod/choice/providers/module-handler.ts b/src/addon/mod/choice/providers/module-handler.ts index 163b595a5..cc2448da9 100644 --- a/src/addon/mod/choice/providers/module-handler.ts +++ b/src/addon/mod/choice/providers/module-handler.ts @@ -64,8 +64,12 @@ export class AddonModChoiceModuleHandler implements CoreCourseModuleHandler { title: module.name, class: 'addon-mod_choice-handler', showDownloadButton: true, - action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void { - navCtrl.push('AddonModChoiceIndexPage', {module: module, courseId: courseId}, options); + action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions, params?: any): void { + const pageParams = {module: module, courseId: courseId}; + if (params) { + Object.assign(pageParams, params); + } + navCtrl.push('AddonModChoiceIndexPage', pageParams, options); } }; } diff --git a/src/addon/mod/data/providers/module-handler.ts b/src/addon/mod/data/providers/module-handler.ts index 78cecd43b..162a9923b 100644 --- a/src/addon/mod/data/providers/module-handler.ts +++ b/src/addon/mod/data/providers/module-handler.ts @@ -67,8 +67,12 @@ export class AddonModDataModuleHandler implements CoreCourseModuleHandler { title: module.name, class: 'addon-mod_data-handler', showDownloadButton: true, - action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void { - navCtrl.push('AddonModDataIndexPage', {module: module, courseId: courseId}, options); + action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions, params?: any): void { + const pageParams = {module: module, courseId: courseId}; + if (params) { + Object.assign(pageParams, params); + } + navCtrl.push('AddonModDataIndexPage', pageParams, options); } }; } diff --git a/src/addon/mod/feedback/providers/module-handler.ts b/src/addon/mod/feedback/providers/module-handler.ts index 8da7e41d9..7744ce1b3 100644 --- a/src/addon/mod/feedback/providers/module-handler.ts +++ b/src/addon/mod/feedback/providers/module-handler.ts @@ -65,8 +65,12 @@ export class AddonModFeedbackModuleHandler implements CoreCourseModuleHandler { title: module.name, class: 'addon-mod_feedback-handler', showDownloadButton: true, - action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void { - navCtrl.push('AddonModFeedbackIndexPage', {module: module, courseId: courseId}, options); + action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions, params?: any): void { + const pageParams = {module: module, courseId: courseId}; + if (params) { + Object.assign(pageParams, params); + } + navCtrl.push('AddonModFeedbackIndexPage', pageParams, options); } }; } diff --git a/src/addon/mod/folder/providers/module-handler.ts b/src/addon/mod/folder/providers/module-handler.ts index c17f6f0a2..5d372a12c 100644 --- a/src/addon/mod/folder/providers/module-handler.ts +++ b/src/addon/mod/folder/providers/module-handler.ts @@ -64,8 +64,12 @@ export class AddonModFolderModuleHandler implements CoreCourseModuleHandler { title: module.name, class: 'addon-mod_folder-handler', showDownloadButton: true, - action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void { - navCtrl.push('AddonModFolderIndexPage', {module: module, courseId: courseId}, options); + action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions, params?: any): void { + const pageParams = {module: module, courseId: courseId}; + if (params) { + Object.assign(pageParams, params); + } + navCtrl.push('AddonModFolderIndexPage', pageParams, options); } }; } diff --git a/src/addon/mod/forum/providers/module-handler.ts b/src/addon/mod/forum/providers/module-handler.ts index 478ed249d..f87f93d03 100644 --- a/src/addon/mod/forum/providers/module-handler.ts +++ b/src/addon/mod/forum/providers/module-handler.ts @@ -72,8 +72,12 @@ export class AddonModForumModuleHandler implements CoreCourseModuleHandler { title: module.name, class: 'addon-mod_forum-handler', showDownloadButton: true, - action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void { - navCtrl.push('AddonModForumIndexPage', {module: module, courseId: courseId}, options); + action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions, params?: any): void { + const pageParams = {module: module, courseId: courseId}; + if (params) { + Object.assign(pageParams, params); + } + navCtrl.push('AddonModForumIndexPage', pageParams, options); } }; diff --git a/src/addon/mod/glossary/providers/module-handler.ts b/src/addon/mod/glossary/providers/module-handler.ts index 5cfc21bd4..88b952b13 100644 --- a/src/addon/mod/glossary/providers/module-handler.ts +++ b/src/addon/mod/glossary/providers/module-handler.ts @@ -66,8 +66,12 @@ export class AddonModGlossaryModuleHandler implements CoreCourseModuleHandler { title: module.name, class: 'addon-mod_glossary-handler', showDownloadButton: true, - action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void { - navCtrl.push('AddonModGlossaryIndexPage', {module: module, courseId: courseId}, options); + action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions, params?: any): void { + const pageParams = {module: module, courseId: courseId}; + if (params) { + Object.assign(pageParams, params); + } + navCtrl.push('AddonModGlossaryIndexPage', pageParams, options); } }; } diff --git a/src/addon/mod/imscp/providers/module-handler.ts b/src/addon/mod/imscp/providers/module-handler.ts index d99d7ba76..94f5e48ea 100644 --- a/src/addon/mod/imscp/providers/module-handler.ts +++ b/src/addon/mod/imscp/providers/module-handler.ts @@ -65,8 +65,12 @@ export class AddonModImscpModuleHandler implements CoreCourseModuleHandler { title: module.name, class: 'addon-mod_imscp-handler', showDownloadButton: true, - action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void { - navCtrl.push('AddonModImscpIndexPage', {module: module, courseId: courseId}, options); + action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions, params?: any): void { + const pageParams = {module: module, courseId: courseId}; + if (params) { + Object.assign(pageParams, params); + } + navCtrl.push('AddonModImscpIndexPage', pageParams, options); } }; } diff --git a/src/addon/mod/lesson/providers/module-handler.ts b/src/addon/mod/lesson/providers/module-handler.ts index 710578202..ec28dc40c 100644 --- a/src/addon/mod/lesson/providers/module-handler.ts +++ b/src/addon/mod/lesson/providers/module-handler.ts @@ -65,8 +65,12 @@ export class AddonModLessonModuleHandler implements CoreCourseModuleHandler { title: module.name, class: 'addon-mod_lesson-handler', showDownloadButton: true, - action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void { - navCtrl.push('AddonModLessonIndexPage', {module: module, courseId: courseId}, options); + action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions, params?: any): void { + const pageParams = {module: module, courseId: courseId}; + if (params) { + Object.assign(pageParams, params); + } + navCtrl.push('AddonModLessonIndexPage', pageParams, options); } }; } diff --git a/src/addon/mod/lti/providers/module-handler.ts b/src/addon/mod/lti/providers/module-handler.ts index 85204e90e..72ca2f2ba 100644 --- a/src/addon/mod/lti/providers/module-handler.ts +++ b/src/addon/mod/lti/providers/module-handler.ts @@ -74,8 +74,12 @@ export class AddonModLtiModuleHandler implements CoreCourseModuleHandler { icon: this.courseProvider.getModuleIconSrc(this.modName, module.modicon), title: module.name, class: 'addon-mod_lti-handler', - action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void { - navCtrl.push('AddonModLtiIndexPage', {module: module, courseId: courseId}, options); + action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions, params?: any): void { + const pageParams = {module: module, courseId: courseId}; + if (params) { + Object.assign(pageParams, params); + } + navCtrl.push('AddonModLtiIndexPage', pageParams, options); }, buttons: [{ icon: 'link', diff --git a/src/addon/mod/page/providers/module-handler.ts b/src/addon/mod/page/providers/module-handler.ts index 4a75ce269..34b827807 100644 --- a/src/addon/mod/page/providers/module-handler.ts +++ b/src/addon/mod/page/providers/module-handler.ts @@ -65,8 +65,12 @@ export class AddonModPageModuleHandler implements CoreCourseModuleHandler { title: module.name, class: 'addon-mod_page-handler', showDownloadButton: true, - action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void { - navCtrl.push('AddonModPageIndexPage', {module: module, courseId: courseId}, options); + action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions, params?: any): void { + const pageParams = {module: module, courseId: courseId}; + if (params) { + Object.assign(pageParams, params); + } + navCtrl.push('AddonModPageIndexPage', pageParams, options); } }; } diff --git a/src/addon/mod/quiz/providers/module-handler.ts b/src/addon/mod/quiz/providers/module-handler.ts index 9c821ec38..f3b484ce9 100644 --- a/src/addon/mod/quiz/providers/module-handler.ts +++ b/src/addon/mod/quiz/providers/module-handler.ts @@ -66,8 +66,12 @@ export class AddonModQuizModuleHandler implements CoreCourseModuleHandler { title: module.name, class: 'addon-mod_quiz-handler', showDownloadButton: true, - action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void { - navCtrl.push('AddonModQuizIndexPage', {module: module, courseId: courseId}, options); + action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions, params?: any): void { + const pageParams = {module: module, courseId: courseId}; + if (params) { + Object.assign(pageParams, params); + } + navCtrl.push('AddonModQuizIndexPage', pageParams, options); } }; } diff --git a/src/addon/mod/resource/providers/module-handler.ts b/src/addon/mod/resource/providers/module-handler.ts index 94267ed38..5dc520d7b 100644 --- a/src/addon/mod/resource/providers/module-handler.ts +++ b/src/addon/mod/resource/providers/module-handler.ts @@ -82,8 +82,12 @@ export class AddonModResourceModuleHandler implements CoreCourseModuleHandler { title: module.name, class: 'addon-mod_resource-handler', showDownloadButton: true, - action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void { - navCtrl.push('AddonModResourceIndexPage', {module: module, courseId: courseId}, options); + action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions, params?: any): void { + const pageParams = {module: module, courseId: courseId}; + if (params) { + Object.assign(pageParams, params); + } + navCtrl.push('AddonModResourceIndexPage', pageParams, options); }, updateStatus: updateStatus.bind(this), buttons: [ { diff --git a/src/addon/mod/scorm/providers/module-handler.ts b/src/addon/mod/scorm/providers/module-handler.ts index b096f7463..1f1df4c8d 100644 --- a/src/addon/mod/scorm/providers/module-handler.ts +++ b/src/addon/mod/scorm/providers/module-handler.ts @@ -64,8 +64,12 @@ export class AddonModScormModuleHandler implements CoreCourseModuleHandler { title: module.name, class: 'addon-mod_scorm-handler', showDownloadButton: true, - action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void { - navCtrl.push('AddonModScormIndexPage', {module: module, courseId: courseId}, options); + action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions, params?: any): void { + const pageParams = {module: module, courseId: courseId}; + if (params) { + Object.assign(pageParams, params); + } + navCtrl.push('AddonModScormIndexPage', pageParams, options); } }; } diff --git a/src/addon/mod/survey/providers/module-handler.ts b/src/addon/mod/survey/providers/module-handler.ts index 4725b6ea3..ed3368ccb 100644 --- a/src/addon/mod/survey/providers/module-handler.ts +++ b/src/addon/mod/survey/providers/module-handler.ts @@ -64,8 +64,12 @@ export class AddonModSurveyModuleHandler implements CoreCourseModuleHandler { title: module.name, class: 'addon-mod_survey-handler', showDownloadButton: true, - action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void { - navCtrl.push('AddonModSurveyIndexPage', {module: module, courseId: courseId}, options); + action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions, params?: any): void { + const pageParams = {module: module, courseId: courseId}; + if (params) { + Object.assign(pageParams, params); + } + navCtrl.push('AddonModSurveyIndexPage', pageParams, options); } }; } diff --git a/src/addon/mod/url/providers/module-handler.ts b/src/addon/mod/url/providers/module-handler.ts index 79c8c54f4..6c205ae51 100644 --- a/src/addon/mod/url/providers/module-handler.ts +++ b/src/addon/mod/url/providers/module-handler.ts @@ -72,7 +72,7 @@ export class AddonModUrlModuleHandler implements CoreCourseModuleHandler { title: module.name, class: 'addon-mod_url-handler', showDownloadButton: false, - action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void { + action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions, params?: any): void { const modal = handler.domUtils.showModalLoading(); // First of all, check if the URL can be handled by the app. If so, always open it directly. @@ -100,7 +100,11 @@ export class AddonModUrlModuleHandler implements CoreCourseModuleHandler { if (shouldOpen) { handler.openUrl(module, courseId); } else { - navCtrl.push('AddonModUrlIndexPage', {module: module, courseId: courseId}, options); + const pageParams = {module: module, courseId: courseId}; + if (params) { + Object.assign(pageParams, params); + } + navCtrl.push('AddonModUrlIndexPage', pageParams, options); } }).finally(() => { modal.dismiss(); diff --git a/src/addon/mod/wiki/providers/module-handler.ts b/src/addon/mod/wiki/providers/module-handler.ts index 72056f85b..20a94af39 100644 --- a/src/addon/mod/wiki/providers/module-handler.ts +++ b/src/addon/mod/wiki/providers/module-handler.ts @@ -65,8 +65,12 @@ export class AddonModWikiModuleHandler implements CoreCourseModuleHandler { title: module.name, class: 'addon-mod_wiki-handler', showDownloadButton: true, - action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void { - navCtrl.push('AddonModWikiIndexPage', {module: module, courseId: courseId}, options); + action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions, params?: any): void { + const pageParams = {module: module, courseId: courseId}; + if (params) { + Object.assign(pageParams, params); + } + navCtrl.push('AddonModWikiIndexPage', pageParams, options); } }; } diff --git a/src/addon/mod/workshop/providers/module-handler.ts b/src/addon/mod/workshop/providers/module-handler.ts index 11914daa9..addfe132d 100644 --- a/src/addon/mod/workshop/providers/module-handler.ts +++ b/src/addon/mod/workshop/providers/module-handler.ts @@ -64,8 +64,12 @@ export class AddonModWorkshopModuleHandler implements CoreCourseModuleHandler { title: module.name, class: 'addon-mod_workshop-handler', showDownloadButton: true, - action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void { - navCtrl.push('AddonModWorkshopIndexPage', {module: module, courseId: courseId}, options); + action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions, params?: any): void { + const pageParams = {module: module, courseId: courseId}; + if (params) { + Object.assign(pageParams, params); + } + navCtrl.push('AddonModWorkshopIndexPage', pageParams, options); } }; } diff --git a/src/core/course/pages/section/section.ts b/src/core/course/pages/section/section.ts index 4a8bcf145..e711e1e08 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 { displayRefresher: boolean; protected module: any; + protected modParams: any; protected completionObserver; protected courseStatusObserver; protected syncObserver; @@ -80,6 +81,7 @@ export class CoreCourseSectionPage implements OnDestroy { this.sectionNumber = navParams.get('sectionNumber'); this.module = navParams.get('module'); this.firstTabName = navParams.get('selectedTab'); + this.modParams = navParams.get('modParams'); // Get the title to display. We dont't have sections yet. this.title = courseFormatDelegate.getCourseTitle(this.course); @@ -124,7 +126,7 @@ export class CoreCourseSectionPage implements OnDestroy { if (this.module) { this.moduleId = this.module.id; - this.courseHelper.openModule(this.navCtrl, this.module, this.course.id, this.sectionId); + this.courseHelper.openModule(this.navCtrl, this.module, this.course.id, this.sectionId, this.modParams); } this.loadData(false, true).finally(() => { diff --git a/src/core/course/providers/helper.ts b/src/core/course/providers/helper.ts index 3c1dcdb48..a6970a565 100644 --- a/src/core/course/providers/helper.ts +++ b/src/core/course/providers/helper.ts @@ -1007,9 +1007,11 @@ export class CoreCourseHelperProvider { * @param {number} [sectionId] Section the module belongs to. If not defined we'll try to retrieve it from the site. * @param {string} [modName] If set, the app will retrieve all modules of this type with a single WS call. This reduces the * number of WS calls, but it isn't recommended for modules that can return a lot of contents. + * @param {any} [modParams] Params to pass to the module * @return {Promise} Promise resolved when done. */ - navigateToModule(moduleId: number, siteId?: string, courseId?: number, sectionId?: number, modName?: string): Promise { + navigateToModule(moduleId: number, siteId?: string, courseId?: number, sectionId?: number, modName?: string, modParams?: any) + : Promise { siteId = siteId || this.sitesProvider.getCurrentSiteId(); const modal = this.domUtils.showModalLoading(); @@ -1048,7 +1050,8 @@ export class CoreCourseHelperProvider { const params = { course: { id: courseId }, module: module, - sectionId: sectionId + sectionId: sectionId, + modParams: modParams }; module.handlerData = this.moduleDelegate.getModuleDataFor(module.modname, module, courseId, sectionId); @@ -1075,15 +1078,16 @@ export class CoreCourseHelperProvider { * @param {any} module The module to open. * @param {number} courseId The course ID of the module. * @param {number} [sectionId] The section ID of the module. + * @param {any} [modParams] Params to pass to the module * @param {boolean} True if module can be opened, false otherwise. */ - openModule(navCtrl: NavController, module: any, courseId: number, sectionId?: number): boolean { + openModule(navCtrl: NavController, module: any, courseId: number, sectionId?: number, modParams?: any): boolean { if (!module.handlerData) { module.handlerData = this.moduleDelegate.getModuleDataFor(module.modname, module, courseId, sectionId); } if (module.handlerData && module.handlerData.action) { - module.handlerData.action(new Event('click'), navCtrl, module, courseId, { animate: false }); + module.handlerData.action(new Event('click'), navCtrl, module, courseId, { animate: false }, modParams); return true; } diff --git a/src/core/course/providers/module-delegate.ts b/src/core/course/providers/module-delegate.ts index 3dbf06c42..4a3824784 100644 --- a/src/core/course/providers/module-delegate.ts +++ b/src/core/course/providers/module-delegate.ts @@ -156,8 +156,9 @@ export interface CoreCourseModuleHandlerData { * @param {any} module The module object. * @param {number} courseId The course ID. * @param {NavOptions} [options] Options for the navigation. + * @param {any} [params] Params for the new page. */ - action?(event: Event, navCtrl: NavController, module: any, courseId: number, options?: NavOptions): void; + action?(event: Event, navCtrl: NavController, module: any, courseId: number, options?: NavOptions, params?: any): void; /** * Updates the status of the module. diff --git a/src/core/sitehome/pages/index/index.ts b/src/core/sitehome/pages/index/index.ts index 23247963b..a66018fec 100644 --- a/src/core/sitehome/pages/index/index.ts +++ b/src/core/sitehome/pages/index/index.ts @@ -31,9 +31,11 @@ export class CoreSiteHomeIndexPage { constructor(navParams: NavParams, navCtrl: NavController, courseHelper: CoreCourseHelperProvider, sitesProvider: CoreSitesProvider) { - const module = navParams.get('module'); + const module = navParams.get('module'), + modParams = navParams.get('modParams'); + if (module) { - courseHelper.openModule(navCtrl, module, sitesProvider.getCurrentSite().getSiteHomeId()); + courseHelper.openModule(navCtrl, module, sitesProvider.getCurrentSite().getSiteHomeId(), undefined, modParams); } } }