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);
+ }
+ }];
+ }
}