MOBILE-2201 book: Display tags in book chapters

main
Albert Gasset 2019-07-08 15:09:36 +02:00
parent 2ea97b0840
commit 85d214edba
4 changed files with 22 additions and 4 deletions

View File

@ -20,6 +20,7 @@ import { CoreComponentsModule } from '@components/components.module';
import { CoreDirectivesModule } from '@directives/directives.module';
import { CoreCourseComponentsModule } from '@core/course/components/components.module';
import { AddonModBookIndexComponent } from './index/index';
import { CoreTagComponentsModule } from '@core/tag/components/components.module';
@NgModule({
declarations: [
@ -31,7 +32,8 @@ import { AddonModBookIndexComponent } from './index/index';
TranslateModule.forChild(),
CoreComponentsModule,
CoreDirectivesModule,
CoreCourseComponentsModule
CoreCourseComponentsModule,
CoreTagComponentsModule
],
providers: [
],

View File

@ -21,6 +21,10 @@
<div padding>
<core-navigation-bar [previous]="previousChapter > 0 && previousChapter" [next]="nextChapter > 0 && nextChapter" (action)="changeChapter($event)"></core-navigation-bar>
<core-format-text [component]="component" [componentId]="componentId" [text]="chapterContent"></core-format-text>
<div margin-top *ngIf="tagsEnabled && contentsMap && contentsMap[currentChapter] && contentsMap[currentChapter].tags && contentsMap[currentChapter].tags.length > 0">
<b>{{ 'core.tag.tags' | translate }}:</b>
<core-tag-list [tags]="contentsMap[currentChapter].tags"></core-tag-list>
</div>
<core-navigation-bar [previous]="previousChapter > 0 && previousChapter" [next]="nextChapter > 0 && nextChapter" (action)="changeChapter($event)"></core-navigation-bar>
</div>

View File

@ -19,6 +19,7 @@ import { CoreCourseProvider } from '@core/course/providers/course';
import { CoreCourseModuleMainResourceComponent } from '@core/course/classes/main-resource-component';
import { AddonModBookProvider, AddonModBookContentsMap, AddonModBookTocChapter } from '../../providers/book';
import { AddonModBookPrefetchHandler } from '../../providers/prefetch-handler';
import { CoreTagProvider } from '@core/tag/providers/tag';
/**
* Component that displays a book.
@ -34,6 +35,7 @@ export class AddonModBookIndexComponent extends CoreCourseModuleMainResourceComp
chapterContent: string;
previousChapter: string;
nextChapter: string;
tagsEnabled: boolean;
protected chapters: AddonModBookTocChapter[];
protected currentChapter: string;
@ -41,7 +43,7 @@ export class AddonModBookIndexComponent extends CoreCourseModuleMainResourceComp
constructor(injector: Injector, private bookProvider: AddonModBookProvider, private courseProvider: CoreCourseProvider,
private appProvider: CoreAppProvider, private prefetchDelegate: AddonModBookPrefetchHandler,
private modalCtrl: ModalController, @Optional() private content: Content) {
private modalCtrl: ModalController, private tagProvider: CoreTagProvider, @Optional() private content: Content) {
super(injector);
}
@ -51,6 +53,8 @@ export class AddonModBookIndexComponent extends CoreCourseModuleMainResourceComp
ngOnInit(): void {
super.ngOnInit();
this.tagsEnabled = this.tagProvider.areTagsAvailableInSite();
this.loadContent();
}

View File

@ -24,6 +24,7 @@ import { CoreUtilsProvider } from '@providers/utils/utils';
import { CoreCourseProvider } from '@core/course/providers/course';
import { CoreCourseLogHelperProvider } from '@core/course/providers/log-helper';
import { CoreSite } from '@classes/site';
import { CoreTagItem } from '@core/tag/providers/tag';
/**
* A book chapter inside the toc list.
@ -52,7 +53,13 @@ export interface AddonModBookTocChapter {
* Map of book contents. For each chapter it has its index URL and the list of paths of the files the chapter has. Each path
* is identified by the relative path in the book, and the value is the URL of the file.
*/
export type AddonModBookContentsMap = {[chapter: string]: {indexUrl?: string, paths: {[path: string]: string}}};
export type AddonModBookContentsMap = {
[chapter: string]: {
indexUrl?: string,
paths: {[path: string]: string},
tags?: CoreTagItem[]
}
};
/**
* Service that provides some features for books.
@ -203,8 +210,9 @@ export class AddonModBookProvider {
map[chapter] = map[chapter] || { paths: {} };
if (content.filename == 'index.html' && filepathIsChapter) {
// Index of the chapter, set indexUrl of the chapter.
// Index of the chapter, set indexUrl and tags of the chapter.
map[chapter].indexUrl = content.fileurl;
map[chapter].tags = content.tags;
} else {
if (filepathIsChapter) {
// It's a file in the root folder OR the WS isn't returning the filepath as it should (MDL-53671).