MOBILE-4616 book: Move book constants to a file

main
Pau Ferrer Ocaña 2024-07-11 22:40:08 +02:00
parent 06fec4e6cf
commit bc1e3f00e7
9 changed files with 60 additions and 45 deletions

View File

@ -43,4 +43,4 @@ const routes: Routes = [
AddonModBookContentsPage,
],
})
export class AddonModBookLazyModule {}
export default class AddonModBookLazyModule {}

View File

@ -19,18 +19,19 @@ import { CoreCourseModuleDelegate } from '@features/course/services/module-deleg
import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate';
import { CoreMainMenuTabRoutingModule } from '@features/mainmenu/mainmenu-tab-routing.module';
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 { AddonModBookListLinkHandler } from './services/handlers/list-link';
import { AddonModBookPrefetchHandler } from './services/handlers/prefetch';
import { AddonModBookTagAreaHandler } from './services/handlers/tag-area';
import { CORE_SITE_SCHEMAS } from '@services/sites';
import { BOOK_SITE_SCHEMA } from './services/database/book';
import { ADDON_MOD_BOOK_PAGE_NAME } from './constants';
const routes: Routes = [
{
path: AddonModBookModuleHandlerService.PAGE_NAME,
loadChildren: () => import('./book-lazy.module').then(m => m.AddonModBookLazyModule),
path: ADDON_MOD_BOOK_PAGE_NAME,
loadChildren: () => import('./book-lazy.module'),
},
];

View File

@ -14,12 +14,12 @@
import { Component, Optional, OnInit, OnDestroy } from '@angular/core';
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 { CoreCourse } from '@features/course/services/course';
import { CoreNavigator } from '@services/navigator';
import { AddonModBookModuleHandlerService } from '../../services/handlers/module';
import { CoreUtils } from '@services/utils/utils';
import { ADDON_MOD_BOOK_PAGE_NAME, AddonModBookNumbering } from '../../constants';
/**
* Component that displays a book entry page.
@ -116,7 +116,7 @@ export class AddonModBookIndexComponent extends CoreCourseModuleMainResourceComp
*/
async openBook(chapterId?: number): Promise<void> {
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 } },
);

View File

@ -14,7 +14,8 @@
import { Component, Input, OnInit } from '@angular/core';
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.

View File

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

View File

@ -35,12 +35,11 @@ import {
AddonModBook,
AddonModBookBookWSData,
AddonModBookContentsMap,
AddonModBookNavStyle,
AddonModBookProvider,
AddonModBookTocChapter,
} from '../../services/book';
import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics';
import { CoreUrlUtils } from '@services/utils/url';
import { ADDON_MOD_BOOK_COMPONENT, AddonModBookNavStyle } from '../../constants';
/**
* Page that displays a book contents.
@ -58,7 +57,7 @@ export class AddonModBookContentsPage implements OnInit, OnDestroy {
cmId!: number;
courseId!: number;
initialChapterId?: number;
component = AddonModBookProvider.COMPONENT;
component = ADDON_MOD_BOOK_COMPONENT;
manager?: CoreSwipeSlidesItemsManager<LoadedChapter, AddonModBookSlidesItemsManagerSource>;
warning = '';
displayNavBar = true;

View File

@ -27,27 +27,7 @@ import { CoreDomUtils } from '@services/utils/dom';
import { CoreFile } from '@services/file';
import { CoreError } from '@classes/errors/error';
import { CoreSiteWSPreSets } from '@classes/sites/authenticated-site';
/**
* 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:';
import { ADDON_MOD_BOOK_COMPONENT } from '../constants';
/**
* Service that provides some features for books.
@ -55,7 +35,7 @@ const ROOT_CACHE_KEY = 'mmaModBook:';
@Injectable({ providedIn: 'root' })
export class AddonModBookProvider {
static readonly COMPONENT = 'mmaModBook';
protected static readonly ROOT_CACHE_KEY = 'mmaModBook:';
/**
* Get a book by course module ID.
@ -92,7 +72,7 @@ export class AddonModBookProvider {
const preSets: CoreSiteWSPreSets = {
cacheKey: this.getBookDataCacheKey(courseId),
updateFrequency: CoreSite.FREQUENCY_RARELY,
component: AddonModBookProvider.COMPONENT,
component: ADDON_MOD_BOOK_COMPONENT,
...CoreSites.getReadingStrategyPreSets(options.readingStrategy),
};
@ -114,7 +94,7 @@ export class AddonModBookProvider {
* @returns Cache key.
*/
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 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);
@ -226,7 +206,7 @@ export class AddonModBookProvider {
*/
async getLastChapterViewed(id: number, siteId?: string): Promise<number | undefined> {
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);
@ -327,7 +307,7 @@ export class AddonModBookProvider {
const promises: Promise<void>[] = [];
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));
return CoreUtils.allPromises(promises);
@ -372,7 +352,7 @@ export class AddonModBookProvider {
await CoreCourseLogHelper.log(
'mod_book_view_book',
params,
AddonModBookProvider.COMPONENT,
ADDON_MOD_BOOK_COMPONENT,
id,
siteId,
);
@ -390,7 +370,7 @@ export class AddonModBookProvider {
async storeLastChapterViewed(id: number, chapterId: number, courseId: number, siteId?: string): Promise<void> {
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) });
}
}

View File

@ -18,6 +18,7 @@ import { CoreConstants, ModPurpose } from '@/core/constants';
import { CoreCourseModuleHandler } from '@features/course/services/module-delegate';
import { makeSingleton } from '@singletons';
import { CoreModuleHandlerBase } from '@features/course/classes/module-base-handler';
import { ADDON_MOD_BOOK_PAGE_NAME } from '../../constants';
/**
* Handler to support book modules.
@ -25,11 +26,9 @@ import { CoreModuleHandlerBase } from '@features/course/classes/module-base-hand
@Injectable({ providedIn: 'root' })
export class AddonModBookModuleHandlerService extends CoreModuleHandlerBase implements CoreCourseModuleHandler {
static readonly PAGE_NAME = 'mod_book';
name = 'AddonModBook';
modName = 'book';
protected pageName = AddonModBookModuleHandlerService.PAGE_NAME;
protected pageName = ADDON_MOD_BOOK_PAGE_NAME;
supportedFeatures = {
[CoreConstants.FEATURE_MOD_ARCHETYPE]: CoreConstants.MOD_ARCHETYPE_RESOURCE,

View File

@ -19,7 +19,8 @@ import { CoreCourseModuleData } from '@features/course/services/course-helper';
import { CoreUtils } from '@services/utils/utils';
import { CoreWSFile } from '@services/ws';
import { makeSingleton } from '@singletons';
import { AddonModBook, AddonModBookProvider } from '../book';
import { AddonModBook } from '../book';
import { ADDON_MOD_BOOK_COMPONENT } from '../../constants';
/**
* Handler to prefetch books.
@ -29,7 +30,7 @@ export class AddonModBookPrefetchHandlerService extends CoreCourseResourcePrefet
name = 'AddonModBook';
modName = 'book';
component = AddonModBookProvider.COMPONENT;
component = ADDON_MOD_BOOK_COMPONENT;
updatesNames = /^configuration$|^.*files$|^entries$/;
/**