From f662013b479767e030b559110ddf37feaef7739c Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Mon, 17 Feb 2020 14:23:59 +0100 Subject: [PATCH] MOBILE-3341 book: Apply numbering setting --- src/addon/mod/book/components/index/index.ts | 7 +++++-- src/addon/mod/book/pages/toc/toc.html | 6 +++++- src/addon/mod/book/pages/toc/toc.scss | 7 +++++++ src/addon/mod/book/pages/toc/toc.ts | 14 +++++++++++++- src/addon/mod/book/providers/book.ts | 10 ++++++++++ 5 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 src/addon/mod/book/pages/toc/toc.scss diff --git a/src/addon/mod/book/components/index/index.ts b/src/addon/mod/book/components/index/index.ts index ee66c3b9a..bce85ab3d 100644 --- a/src/addon/mod/book/components/index/index.ts +++ b/src/addon/mod/book/components/index/index.ts @@ -17,7 +17,7 @@ import { Content, ModalController } from 'ionic-angular'; import { CoreAppProvider } from '@providers/app'; import { CoreCourseProvider } from '@core/course/providers/course'; import { CoreCourseModuleMainResourceComponent } from '@core/course/classes/main-resource-component'; -import { AddonModBookProvider, AddonModBookContentsMap, AddonModBookTocChapter } from '../../providers/book'; +import { AddonModBookProvider, AddonModBookContentsMap, AddonModBookTocChapter, AddonModBookBook } from '../../providers/book'; import { AddonModBookPrefetchHandler } from '../../providers/prefetch-handler'; import { CoreTagProvider } from '@core/tag/providers/tag'; @@ -40,6 +40,7 @@ export class AddonModBookIndexComponent extends CoreCourseModuleMainResourceComp protected chapters: AddonModBookTocChapter[]; protected currentChapter: string; protected contentsMap: AddonModBookContentsMap; + protected book: AddonModBookBook; constructor(injector: Injector, private bookProvider: AddonModBookProvider, private courseProvider: CoreCourseProvider, private appProvider: CoreAppProvider, private prefetchDelegate: AddonModBookPrefetchHandler, @@ -69,7 +70,8 @@ export class AddonModBookIndexComponent extends CoreCourseModuleMainResourceComp moduleId: this.module.id, chapters: this.chapters, selected: this.currentChapter, - courseId: this.courseId + courseId: this.courseId, + book: this.book, }, { cssClass: 'core-modal-lateral', showBackdrop: true, enableBackdropDismiss: true, @@ -123,6 +125,7 @@ export class AddonModBookIndexComponent extends CoreCourseModuleMainResourceComp // Try to get the book data. promises.push(this.bookProvider.getBook(this.courseId, this.module.id).then((book) => { + this.book = book; this.dataRetrieved.emit(book); this.description = book.intro; }).catch(() => { diff --git a/src/addon/mod/book/pages/toc/toc.html b/src/addon/mod/book/pages/toc/toc.html index 01fcaa92b..5e6ec0247 100644 --- a/src/addon/mod/book/pages/toc/toc.html +++ b/src/addon/mod/book/pages/toc/toc.html @@ -12,7 +12,11 @@ diff --git a/src/addon/mod/book/pages/toc/toc.scss b/src/addon/mod/book/pages/toc/toc.scss new file mode 100644 index 000000000..2ed350b72 --- /dev/null +++ b/src/addon/mod/book/pages/toc/toc.scss @@ -0,0 +1,7 @@ +ion-app.app-root page-addon-mod-book-toc { + .addon-mod-book-bullet { + font-weight: bold; + font-size: 1.5em; + margin-right: 3px; + } +} diff --git a/src/addon/mod/book/pages/toc/toc.ts b/src/addon/mod/book/pages/toc/toc.ts index 3df7cffc0..d6dc1b3f8 100644 --- a/src/addon/mod/book/pages/toc/toc.ts +++ b/src/addon/mod/book/pages/toc/toc.ts @@ -14,7 +14,7 @@ import { Component } from '@angular/core'; import { IonicPage, NavParams, ViewController } from 'ionic-angular'; -import { AddonModBookTocChapter } from '../../providers/book'; +import { AddonModBookTocChapter, AddonModBookBook, AddonModBookNumbering } from '../../providers/book'; /** * Modal to display the TOC of a book. @@ -29,12 +29,24 @@ export class AddonModBookTocPage { chapters: AddonModBookTocChapter[]; selected: number; courseId: number; + showNumbers = true; + addPadding = true; + showBullets = false; + + protected book: AddonModBookBook; constructor(navParams: NavParams, private viewCtrl: ViewController) { this.moduleId = navParams.get('moduleId'); this.chapters = navParams.get('chapters') || []; this.selected = navParams.get('selected'); this.courseId = navParams.get('courseId'); + this.book = navParams.get('book'); + + if (this.book) { + this.showNumbers = this.book.numbering == AddonModBookNumbering.NUMBERS; + this.showBullets = this.book.numbering == AddonModBookNumbering.BULLETS; + this.addPadding = this.book.numbering != AddonModBookNumbering.NONE; + } } /** diff --git a/src/addon/mod/book/providers/book.ts b/src/addon/mod/book/providers/book.ts index 6944ea73e..001f3775c 100644 --- a/src/addon/mod/book/providers/book.ts +++ b/src/addon/mod/book/providers/book.ts @@ -27,6 +27,16 @@ import { CoreSite } from '@classes/site'; import { CoreTagItem } from '@core/tag/providers/tag'; import { CoreWSExternalWarning, CoreWSExternalFile } from '@providers/ws'; +/** + * Constants to define how the chapters and subchapters of a book should be displayed in that table of contents. + */ +export const enum AddonModBookNumbering { + NONE = 0, + NUMBERS = 1, + BULLETS = 2, + INDENTED = 3, +} + /** * Service that provides some features for books. */