MOBILE-4616 book: Move book constants to a file
parent
06fec4e6cf
commit
bc1e3f00e7
|
@ -43,4 +43,4 @@ const routes: Routes = [
|
||||||
AddonModBookContentsPage,
|
AddonModBookContentsPage,
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class AddonModBookLazyModule {}
|
export default class AddonModBookLazyModule {}
|
||||||
|
|
|
@ -19,18 +19,19 @@ import { CoreCourseModuleDelegate } from '@features/course/services/module-deleg
|
||||||
import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate';
|
import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate';
|
||||||
import { CoreMainMenuTabRoutingModule } from '@features/mainmenu/mainmenu-tab-routing.module';
|
import { CoreMainMenuTabRoutingModule } from '@features/mainmenu/mainmenu-tab-routing.module';
|
||||||
import { CoreTagAreaDelegate } from '@features/tag/services/tag-area-delegate';
|
import { CoreTagAreaDelegate } from '@features/tag/services/tag-area-delegate';
|
||||||
import { AddonModBookModuleHandler, AddonModBookModuleHandlerService } from './services/handlers/module';
|
import { AddonModBookModuleHandler } from './services/handlers/module';
|
||||||
import { AddonModBookIndexLinkHandler } from './services/handlers/index-link';
|
import { AddonModBookIndexLinkHandler } from './services/handlers/index-link';
|
||||||
import { AddonModBookListLinkHandler } from './services/handlers/list-link';
|
import { AddonModBookListLinkHandler } from './services/handlers/list-link';
|
||||||
import { AddonModBookPrefetchHandler } from './services/handlers/prefetch';
|
import { AddonModBookPrefetchHandler } from './services/handlers/prefetch';
|
||||||
import { AddonModBookTagAreaHandler } from './services/handlers/tag-area';
|
import { AddonModBookTagAreaHandler } from './services/handlers/tag-area';
|
||||||
import { CORE_SITE_SCHEMAS } from '@services/sites';
|
import { CORE_SITE_SCHEMAS } from '@services/sites';
|
||||||
import { BOOK_SITE_SCHEMA } from './services/database/book';
|
import { BOOK_SITE_SCHEMA } from './services/database/book';
|
||||||
|
import { ADDON_MOD_BOOK_PAGE_NAME } from './constants';
|
||||||
|
|
||||||
const routes: Routes = [
|
const routes: Routes = [
|
||||||
{
|
{
|
||||||
path: AddonModBookModuleHandlerService.PAGE_NAME,
|
path: ADDON_MOD_BOOK_PAGE_NAME,
|
||||||
loadChildren: () => import('./book-lazy.module').then(m => m.AddonModBookLazyModule),
|
loadChildren: () => import('./book-lazy.module'),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -14,12 +14,12 @@
|
||||||
|
|
||||||
import { Component, Optional, OnInit, OnDestroy } from '@angular/core';
|
import { Component, Optional, OnInit, OnDestroy } from '@angular/core';
|
||||||
import { CoreCourseModuleMainResourceComponent } from '@features/course/classes/main-resource-component';
|
import { CoreCourseModuleMainResourceComponent } from '@features/course/classes/main-resource-component';
|
||||||
import { AddonModBook, AddonModBookBookWSData, AddonModBookNumbering, AddonModBookTocChapter } from '../../services/book';
|
import { AddonModBook, AddonModBookBookWSData, AddonModBookTocChapter } from '../../services/book';
|
||||||
import { CoreCourseContentsPage } from '@features/course/pages/contents/contents';
|
import { CoreCourseContentsPage } from '@features/course/pages/contents/contents';
|
||||||
import { CoreCourse } from '@features/course/services/course';
|
import { CoreCourse } from '@features/course/services/course';
|
||||||
import { CoreNavigator } from '@services/navigator';
|
import { CoreNavigator } from '@services/navigator';
|
||||||
import { AddonModBookModuleHandlerService } from '../../services/handlers/module';
|
|
||||||
import { CoreUtils } from '@services/utils/utils';
|
import { CoreUtils } from '@services/utils/utils';
|
||||||
|
import { ADDON_MOD_BOOK_PAGE_NAME, AddonModBookNumbering } from '../../constants';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Component that displays a book entry page.
|
* Component that displays a book entry page.
|
||||||
|
@ -116,7 +116,7 @@ export class AddonModBookIndexComponent extends CoreCourseModuleMainResourceComp
|
||||||
*/
|
*/
|
||||||
async openBook(chapterId?: number): Promise<void> {
|
async openBook(chapterId?: number): Promise<void> {
|
||||||
await CoreNavigator.navigateToSitePath(
|
await CoreNavigator.navigateToSitePath(
|
||||||
`${AddonModBookModuleHandlerService.PAGE_NAME}/${this.courseId}/${this.module.id}/contents`,
|
`${ADDON_MOD_BOOK_PAGE_NAME}/${this.courseId}/${this.module.id}/contents`,
|
||||||
{ params: { chapterId } },
|
{ params: { chapterId } },
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,8 @@
|
||||||
|
|
||||||
import { Component, Input, OnInit } from '@angular/core';
|
import { Component, Input, OnInit } from '@angular/core';
|
||||||
import { ModalController } from '@singletons';
|
import { ModalController } from '@singletons';
|
||||||
import { AddonModBookTocChapter, AddonModBookBookWSData, AddonModBookNumbering } from '../../services/book';
|
import { AddonModBookTocChapter, AddonModBookBookWSData } from '../../services/book';
|
||||||
|
import { AddonModBookNumbering } from '../../constants';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Modal to display the TOC of a book.
|
* Modal to display the TOC of a book.
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
// (C) Copyright 2015 Moodle Pty Ltd.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
export const ADDON_MOD_BOOK_COMPONENT = 'mmaModBook';
|
||||||
|
export const ADDON_MOD_BOOK_PAGE_NAME = 'mod_book';
|
||||||
|
/**
|
||||||
|
* 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,
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constants to define the navigation style used within a book.
|
||||||
|
*/
|
||||||
|
export const enum AddonModBookNavStyle {
|
||||||
|
TOC_ONLY = 0,
|
||||||
|
IMAGE = 1,
|
||||||
|
TEXT = 2,
|
||||||
|
}
|
|
@ -35,12 +35,11 @@ import {
|
||||||
AddonModBook,
|
AddonModBook,
|
||||||
AddonModBookBookWSData,
|
AddonModBookBookWSData,
|
||||||
AddonModBookContentsMap,
|
AddonModBookContentsMap,
|
||||||
AddonModBookNavStyle,
|
|
||||||
AddonModBookProvider,
|
|
||||||
AddonModBookTocChapter,
|
AddonModBookTocChapter,
|
||||||
} from '../../services/book';
|
} from '../../services/book';
|
||||||
import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics';
|
import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics';
|
||||||
import { CoreUrlUtils } from '@services/utils/url';
|
import { CoreUrlUtils } from '@services/utils/url';
|
||||||
|
import { ADDON_MOD_BOOK_COMPONENT, AddonModBookNavStyle } from '../../constants';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Page that displays a book contents.
|
* Page that displays a book contents.
|
||||||
|
@ -58,7 +57,7 @@ export class AddonModBookContentsPage implements OnInit, OnDestroy {
|
||||||
cmId!: number;
|
cmId!: number;
|
||||||
courseId!: number;
|
courseId!: number;
|
||||||
initialChapterId?: number;
|
initialChapterId?: number;
|
||||||
component = AddonModBookProvider.COMPONENT;
|
component = ADDON_MOD_BOOK_COMPONENT;
|
||||||
manager?: CoreSwipeSlidesItemsManager<LoadedChapter, AddonModBookSlidesItemsManagerSource>;
|
manager?: CoreSwipeSlidesItemsManager<LoadedChapter, AddonModBookSlidesItemsManagerSource>;
|
||||||
warning = '';
|
warning = '';
|
||||||
displayNavBar = true;
|
displayNavBar = true;
|
||||||
|
|
|
@ -27,27 +27,7 @@ import { CoreDomUtils } from '@services/utils/dom';
|
||||||
import { CoreFile } from '@services/file';
|
import { CoreFile } from '@services/file';
|
||||||
import { CoreError } from '@classes/errors/error';
|
import { CoreError } from '@classes/errors/error';
|
||||||
import { CoreSiteWSPreSets } from '@classes/sites/authenticated-site';
|
import { CoreSiteWSPreSets } from '@classes/sites/authenticated-site';
|
||||||
|
import { ADDON_MOD_BOOK_COMPONENT } from '../constants';
|
||||||
/**
|
|
||||||
* 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,
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constants to define the navigation style used within a book.
|
|
||||||
*/
|
|
||||||
export const enum AddonModBookNavStyle {
|
|
||||||
TOC_ONLY = 0,
|
|
||||||
IMAGE = 1,
|
|
||||||
TEXT = 2,
|
|
||||||
}
|
|
||||||
|
|
||||||
const ROOT_CACHE_KEY = 'mmaModBook:';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service that provides some features for books.
|
* Service that provides some features for books.
|
||||||
|
@ -55,7 +35,7 @@ const ROOT_CACHE_KEY = 'mmaModBook:';
|
||||||
@Injectable({ providedIn: 'root' })
|
@Injectable({ providedIn: 'root' })
|
||||||
export class AddonModBookProvider {
|
export class AddonModBookProvider {
|
||||||
|
|
||||||
static readonly COMPONENT = 'mmaModBook';
|
protected static readonly ROOT_CACHE_KEY = 'mmaModBook:';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a book by course module ID.
|
* Get a book by course module ID.
|
||||||
|
@ -92,7 +72,7 @@ export class AddonModBookProvider {
|
||||||
const preSets: CoreSiteWSPreSets = {
|
const preSets: CoreSiteWSPreSets = {
|
||||||
cacheKey: this.getBookDataCacheKey(courseId),
|
cacheKey: this.getBookDataCacheKey(courseId),
|
||||||
updateFrequency: CoreSite.FREQUENCY_RARELY,
|
updateFrequency: CoreSite.FREQUENCY_RARELY,
|
||||||
component: AddonModBookProvider.COMPONENT,
|
component: ADDON_MOD_BOOK_COMPONENT,
|
||||||
...CoreSites.getReadingStrategyPreSets(options.readingStrategy),
|
...CoreSites.getReadingStrategyPreSets(options.readingStrategy),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -114,7 +94,7 @@ export class AddonModBookProvider {
|
||||||
* @returns Cache key.
|
* @returns Cache key.
|
||||||
*/
|
*/
|
||||||
protected getBookDataCacheKey(courseId: number): string {
|
protected getBookDataCacheKey(courseId: number): string {
|
||||||
return ROOT_CACHE_KEY + 'book:' + courseId;
|
return AddonModBookProvider.ROOT_CACHE_KEY + 'book:' + courseId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -140,7 +120,7 @@ export class AddonModBookProvider {
|
||||||
|
|
||||||
const siteId = CoreSites.getCurrentSiteId();
|
const siteId = CoreSites.getCurrentSiteId();
|
||||||
|
|
||||||
const url = await CoreFilepool.downloadUrl(siteId, indexUrl, false, AddonModBookProvider.COMPONENT, moduleId);
|
const url = await CoreFilepool.downloadUrl(siteId, indexUrl, false, ADDON_MOD_BOOK_COMPONENT, moduleId);
|
||||||
|
|
||||||
const content = await CoreWS.getText(url);
|
const content = await CoreWS.getText(url);
|
||||||
|
|
||||||
|
@ -226,7 +206,7 @@ export class AddonModBookProvider {
|
||||||
*/
|
*/
|
||||||
async getLastChapterViewed(id: number, siteId?: string): Promise<number | undefined> {
|
async getLastChapterViewed(id: number, siteId?: string): Promise<number | undefined> {
|
||||||
const site = await CoreSites.getSite(siteId);
|
const site = await CoreSites.getSite(siteId);
|
||||||
const entry = await site.getLastViewed(AddonModBookProvider.COMPONENT, id);
|
const entry = await site.getLastViewed(ADDON_MOD_BOOK_COMPONENT, id);
|
||||||
|
|
||||||
const chapterId = Number(entry?.value);
|
const chapterId = Number(entry?.value);
|
||||||
|
|
||||||
|
@ -327,7 +307,7 @@ export class AddonModBookProvider {
|
||||||
const promises: Promise<void>[] = [];
|
const promises: Promise<void>[] = [];
|
||||||
|
|
||||||
promises.push(this.invalidateBookData(courseId, siteId));
|
promises.push(this.invalidateBookData(courseId, siteId));
|
||||||
promises.push(CoreFilepool.invalidateFilesByComponent(siteId, AddonModBookProvider.COMPONENT, moduleId));
|
promises.push(CoreFilepool.invalidateFilesByComponent(siteId, ADDON_MOD_BOOK_COMPONENT, moduleId));
|
||||||
promises.push(CoreCourse.invalidateModule(moduleId, siteId));
|
promises.push(CoreCourse.invalidateModule(moduleId, siteId));
|
||||||
|
|
||||||
return CoreUtils.allPromises(promises);
|
return CoreUtils.allPromises(promises);
|
||||||
|
@ -372,7 +352,7 @@ export class AddonModBookProvider {
|
||||||
await CoreCourseLogHelper.log(
|
await CoreCourseLogHelper.log(
|
||||||
'mod_book_view_book',
|
'mod_book_view_book',
|
||||||
params,
|
params,
|
||||||
AddonModBookProvider.COMPONENT,
|
ADDON_MOD_BOOK_COMPONENT,
|
||||||
id,
|
id,
|
||||||
siteId,
|
siteId,
|
||||||
);
|
);
|
||||||
|
@ -390,7 +370,7 @@ export class AddonModBookProvider {
|
||||||
async storeLastChapterViewed(id: number, chapterId: number, courseId: number, siteId?: string): Promise<void> {
|
async storeLastChapterViewed(id: number, chapterId: number, courseId: number, siteId?: string): Promise<void> {
|
||||||
const site = await CoreSites.getSite(siteId);
|
const site = await CoreSites.getSite(siteId);
|
||||||
|
|
||||||
await site.storeLastViewed(AddonModBookProvider.COMPONENT, id, chapterId, { data: String(courseId) });
|
await site.storeLastViewed(ADDON_MOD_BOOK_COMPONENT, id, chapterId, { data: String(courseId) });
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ import { CoreConstants, ModPurpose } from '@/core/constants';
|
||||||
import { CoreCourseModuleHandler } from '@features/course/services/module-delegate';
|
import { CoreCourseModuleHandler } from '@features/course/services/module-delegate';
|
||||||
import { makeSingleton } from '@singletons';
|
import { makeSingleton } from '@singletons';
|
||||||
import { CoreModuleHandlerBase } from '@features/course/classes/module-base-handler';
|
import { CoreModuleHandlerBase } from '@features/course/classes/module-base-handler';
|
||||||
|
import { ADDON_MOD_BOOK_PAGE_NAME } from '../../constants';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler to support book modules.
|
* Handler to support book modules.
|
||||||
|
@ -25,11 +26,9 @@ import { CoreModuleHandlerBase } from '@features/course/classes/module-base-hand
|
||||||
@Injectable({ providedIn: 'root' })
|
@Injectable({ providedIn: 'root' })
|
||||||
export class AddonModBookModuleHandlerService extends CoreModuleHandlerBase implements CoreCourseModuleHandler {
|
export class AddonModBookModuleHandlerService extends CoreModuleHandlerBase implements CoreCourseModuleHandler {
|
||||||
|
|
||||||
static readonly PAGE_NAME = 'mod_book';
|
|
||||||
|
|
||||||
name = 'AddonModBook';
|
name = 'AddonModBook';
|
||||||
modName = 'book';
|
modName = 'book';
|
||||||
protected pageName = AddonModBookModuleHandlerService.PAGE_NAME;
|
protected pageName = ADDON_MOD_BOOK_PAGE_NAME;
|
||||||
|
|
||||||
supportedFeatures = {
|
supportedFeatures = {
|
||||||
[CoreConstants.FEATURE_MOD_ARCHETYPE]: CoreConstants.MOD_ARCHETYPE_RESOURCE,
|
[CoreConstants.FEATURE_MOD_ARCHETYPE]: CoreConstants.MOD_ARCHETYPE_RESOURCE,
|
||||||
|
|
|
@ -19,7 +19,8 @@ import { CoreCourseModuleData } from '@features/course/services/course-helper';
|
||||||
import { CoreUtils } from '@services/utils/utils';
|
import { CoreUtils } from '@services/utils/utils';
|
||||||
import { CoreWSFile } from '@services/ws';
|
import { CoreWSFile } from '@services/ws';
|
||||||
import { makeSingleton } from '@singletons';
|
import { makeSingleton } from '@singletons';
|
||||||
import { AddonModBook, AddonModBookProvider } from '../book';
|
import { AddonModBook } from '../book';
|
||||||
|
import { ADDON_MOD_BOOK_COMPONENT } from '../../constants';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler to prefetch books.
|
* Handler to prefetch books.
|
||||||
|
@ -29,7 +30,7 @@ export class AddonModBookPrefetchHandlerService extends CoreCourseResourcePrefet
|
||||||
|
|
||||||
name = 'AddonModBook';
|
name = 'AddonModBook';
|
||||||
modName = 'book';
|
modName = 'book';
|
||||||
component = AddonModBookProvider.COMPONENT;
|
component = ADDON_MOD_BOOK_COMPONENT;
|
||||||
updatesNames = /^configuration$|^.*files$|^entries$/;
|
updatesNames = /^configuration$|^.*files$|^entries$/;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue