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

View File

@ -21,6 +21,10 @@
<div padding> <div padding>
<core-navigation-bar [previous]="previousChapter > 0 && previousChapter" [next]="nextChapter > 0 && nextChapter" (action)="changeChapter($event)"></core-navigation-bar> <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> <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> <core-navigation-bar [previous]="previousChapter > 0 && previousChapter" [next]="nextChapter > 0 && nextChapter" (action)="changeChapter($event)"></core-navigation-bar>
</div> </div>

View File

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

View File

@ -24,6 +24,7 @@ import { CoreUtilsProvider } from '@providers/utils/utils';
import { CoreCourseProvider } from '@core/course/providers/course'; import { CoreCourseProvider } from '@core/course/providers/course';
import { CoreCourseLogHelperProvider } from '@core/course/providers/log-helper'; import { CoreCourseLogHelperProvider } from '@core/course/providers/log-helper';
import { CoreSite } from '@classes/site'; import { CoreSite } from '@classes/site';
import { CoreTagItem } from '@core/tag/providers/tag';
/** /**
* A book chapter inside the toc list. * 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 * 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. * 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. * Service that provides some features for books.
@ -203,8 +210,9 @@ export class AddonModBookProvider {
map[chapter] = map[chapter] || { paths: {} }; map[chapter] = map[chapter] || { paths: {} };
if (content.filename == 'index.html' && filepathIsChapter) { 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].indexUrl = content.fileurl;
map[chapter].tags = content.tags;
} else { } else {
if (filepathIsChapter) { if (filepathIsChapter) {
// It's a file in the root folder OR the WS isn't returning the filepath as it should (MDL-53671). // It's a file in the root folder OR the WS isn't returning the filepath as it should (MDL-53671).