MOBILE-3341 book: Apply numbering setting

main
Dani Palou 2020-02-17 14:23:59 +01:00
parent 6d06a7e41c
commit f662013b47
5 changed files with 40 additions and 4 deletions

View File

@ -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(() => {

View File

@ -12,7 +12,11 @@
<nav>
<ion-list>
<a ion-item text-wrap *ngFor="let chapter of chapters" (click)="loadChapter(chapter.id)" [class.core-nav-item-selected]="selected == chapter.id" [class.item-dimmed]="chapter.hidden">
<p [attr.padding-left]="chapter.level == 1 ? true : null">{{chapter.number}} <core-format-text [text]="chapter.title" contextLevel="module" [contextInstanceId]="moduleId" [courseId]="courseId"></core-format-text></p>
<p [attr.padding-left]="addPadding && chapter.level == 1 ? true : null">
<span *ngIf="showNumbers" class="addon-mod-book-number">{{chapter.number}}</span>
<span *ngIf="showBullets" class="addon-mod-book-bullet">&bull;</span>
<core-format-text [text]="chapter.title" contextLevel="module" [contextInstanceId]="moduleId" [courseId]="courseId"></core-format-text>
</p>
</a>
</ion-list>
</nav>

View File

@ -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;
}
}

View File

@ -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;
}
}
/**

View File

@ -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.
*/