Skip to content

Commit 2b13d13

Browse files
authored
Merge pull request #2286 from dpalou/MOBILE-3341
MOBILE-3341 book: Apply numbering setting
2 parents fbf551b + f662013 commit 2b13d13

File tree

5 files changed

+40
-4
lines changed

5 files changed

+40
-4
lines changed

src/addon/mod/book/components/index/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { Content, ModalController } from 'ionic-angular';
1717
import { CoreAppProvider } from '@providers/app';
1818
import { CoreCourseProvider } from '@core/course/providers/course';
1919
import { CoreCourseModuleMainResourceComponent } from '@core/course/classes/main-resource-component';
20-
import { AddonModBookProvider, AddonModBookContentsMap, AddonModBookTocChapter } from '../../providers/book';
20+
import { AddonModBookProvider, AddonModBookContentsMap, AddonModBookTocChapter, AddonModBookBook } from '../../providers/book';
2121
import { AddonModBookPrefetchHandler } from '../../providers/prefetch-handler';
2222
import { CoreTagProvider } from '@core/tag/providers/tag';
2323

@@ -40,6 +40,7 @@ export class AddonModBookIndexComponent extends CoreCourseModuleMainResourceComp
4040
protected chapters: AddonModBookTocChapter[];
4141
protected currentChapter: string;
4242
protected contentsMap: AddonModBookContentsMap;
43+
protected book: AddonModBookBook;
4344

4445
constructor(injector: Injector, private bookProvider: AddonModBookProvider, private courseProvider: CoreCourseProvider,
4546
private appProvider: CoreAppProvider, private prefetchDelegate: AddonModBookPrefetchHandler,
@@ -69,7 +70,8 @@ export class AddonModBookIndexComponent extends CoreCourseModuleMainResourceComp
6970
moduleId: this.module.id,
7071
chapters: this.chapters,
7172
selected: this.currentChapter,
72-
courseId: this.courseId
73+
courseId: this.courseId,
74+
book: this.book,
7375
}, { cssClass: 'core-modal-lateral',
7476
showBackdrop: true,
7577
enableBackdropDismiss: true,
@@ -123,6 +125,7 @@ export class AddonModBookIndexComponent extends CoreCourseModuleMainResourceComp
123125

124126
// Try to get the book data.
125127
promises.push(this.bookProvider.getBook(this.courseId, this.module.id).then((book) => {
128+
this.book = book;
126129
this.dataRetrieved.emit(book);
127130
this.description = book.intro;
128131
}).catch(() => {

src/addon/mod/book/pages/toc/toc.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
<nav>
1313
<ion-list>
1414
<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">
15-
<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>
15+
<p [attr.padding-left]="addPadding && chapter.level == 1 ? true : null">
16+
<span *ngIf="showNumbers" class="addon-mod-book-number">{{chapter.number}}</span>
17+
<span *ngIf="showBullets" class="addon-mod-book-bullet">&bull;</span>
18+
<core-format-text [text]="chapter.title" contextLevel="module" [contextInstanceId]="moduleId" [courseId]="courseId"></core-format-text>
19+
</p>
1620
</a>
1721
</ion-list>
1822
</nav>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
ion-app.app-root page-addon-mod-book-toc {
2+
.addon-mod-book-bullet {
3+
font-weight: bold;
4+
font-size: 1.5em;
5+
margin-right: 3px;
6+
}
7+
}

src/addon/mod/book/pages/toc/toc.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import { Component } from '@angular/core';
1616
import { IonicPage, NavParams, ViewController } from 'ionic-angular';
17-
import { AddonModBookTocChapter } from '../../providers/book';
17+
import { AddonModBookTocChapter, AddonModBookBook, AddonModBookNumbering } from '../../providers/book';
1818

1919
/**
2020
* Modal to display the TOC of a book.
@@ -29,12 +29,24 @@ export class AddonModBookTocPage {
2929
chapters: AddonModBookTocChapter[];
3030
selected: number;
3131
courseId: number;
32+
showNumbers = true;
33+
addPadding = true;
34+
showBullets = false;
35+
36+
protected book: AddonModBookBook;
3237

3338
constructor(navParams: NavParams, private viewCtrl: ViewController) {
3439
this.moduleId = navParams.get('moduleId');
3540
this.chapters = navParams.get('chapters') || [];
3641
this.selected = navParams.get('selected');
3742
this.courseId = navParams.get('courseId');
43+
this.book = navParams.get('book');
44+
45+
if (this.book) {
46+
this.showNumbers = this.book.numbering == AddonModBookNumbering.NUMBERS;
47+
this.showBullets = this.book.numbering == AddonModBookNumbering.BULLETS;
48+
this.addPadding = this.book.numbering != AddonModBookNumbering.NONE;
49+
}
3850
}
3951

4052
/**

src/addon/mod/book/providers/book.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ import { CoreSite } from '@classes/site';
2626
import { CoreTagItem } from '@core/tag/providers/tag';
2727
import { CoreWSProvider, CoreWSExternalWarning, CoreWSExternalFile } from '@providers/ws';
2828

29+
/**
30+
* Constants to define how the chapters and subchapters of a book should be displayed in that table of contents.
31+
*/
32+
export const enum AddonModBookNumbering {
33+
NONE = 0,
34+
NUMBERS = 1,
35+
BULLETS = 2,
36+
INDENTED = 3,
37+
}
38+
2939
/**
3040
* Service that provides some features for books.
3141
*/

0 commit comments

Comments
 (0)