From 70507ce604038b68c924e9df83a88aa067d762b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Thu, 11 Jul 2024 22:42:02 +0200 Subject: [PATCH] MOBILE-4616 imscp: Move imscp constants to a file --- src/addons/mod/imscp/components/index/index.ts | 5 +++-- src/addons/mod/imscp/constants.ts | 16 ++++++++++++++++ src/addons/mod/imscp/imscp-lazy.module.ts | 2 +- src/addons/mod/imscp/imscp.module.ts | 7 ++++--- .../mod/imscp/services/handlers/module.ts | 5 ++--- .../mod/imscp/services/handlers/prefetch.ts | 5 +++-- src/addons/mod/imscp/services/imscp.ts | 17 ++++++++--------- 7 files changed, 37 insertions(+), 20 deletions(-) create mode 100644 src/addons/mod/imscp/constants.ts diff --git a/src/addons/mod/imscp/components/index/index.ts b/src/addons/mod/imscp/components/index/index.ts index 29e111c8a..9cd2303af 100644 --- a/src/addons/mod/imscp/components/index/index.ts +++ b/src/addons/mod/imscp/components/index/index.ts @@ -17,8 +17,9 @@ import { CoreCourseModuleMainResourceComponent } from '@features/course/classes/ import { CoreCourseContentsPage } from '@features/course/pages/contents/contents'; import { CoreCourse } from '@features/course/services/course'; import { CoreNavigator } from '@services/navigator'; -import { AddonModImscpProvider, AddonModImscp, AddonModImscpTocItem } from '../../services/imscp'; +import { AddonModImscp, AddonModImscpTocItem } from '../../services/imscp'; import { CoreUtils } from '@services/utils/utils'; +import { ADDON_MOD_IMSCP_COMPONENT } from '../../constants'; /** * Component that displays a IMSCP. @@ -30,7 +31,7 @@ import { CoreUtils } from '@services/utils/utils'; }) export class AddonModImscpIndexComponent extends CoreCourseModuleMainResourceComponent implements OnInit { - component = AddonModImscpProvider.COMPONENT; + component = ADDON_MOD_IMSCP_COMPONENT; pluginName = 'imscp'; items: AddonModImscpTocItem[] = []; diff --git a/src/addons/mod/imscp/constants.ts b/src/addons/mod/imscp/constants.ts new file mode 100644 index 000000000..a2c990326 --- /dev/null +++ b/src/addons/mod/imscp/constants.ts @@ -0,0 +1,16 @@ +// (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_IMSCP_COMPONENT = 'mmaModImscp'; +export const ADDON_MOD_IMSCP_PAGE_NAME = 'mod_imscp'; diff --git a/src/addons/mod/imscp/imscp-lazy.module.ts b/src/addons/mod/imscp/imscp-lazy.module.ts index 1ef464bb7..1bcde4c27 100644 --- a/src/addons/mod/imscp/imscp-lazy.module.ts +++ b/src/addons/mod/imscp/imscp-lazy.module.ts @@ -42,4 +42,4 @@ const routes: Routes = [ AddonModImscpViewPage, ], }) -export class AddonModImscpLazyModule {} +export default class AddonModImscpLazyModule {} diff --git a/src/addons/mod/imscp/imscp.module.ts b/src/addons/mod/imscp/imscp.module.ts index 6014981a1..83ce09f8b 100644 --- a/src/addons/mod/imscp/imscp.module.ts +++ b/src/addons/mod/imscp/imscp.module.ts @@ -21,14 +21,15 @@ import { CoreMainMenuTabRoutingModule } from '@features/mainmenu/mainmenu-tab-ro import { CorePluginFileDelegate } from '@services/plugin-file-delegate'; import { AddonModImscpIndexLinkHandler } from './services/handlers/index-link'; import { AddonModImscpListLinkHandler } from './services/handlers/list-link'; -import { AddonModImscpModuleHandler, AddonModImscpModuleHandlerService } from './services/handlers/module'; +import { AddonModImscpModuleHandler } from './services/handlers/module'; import { AddonModImscpPluginFileHandler } from './services/handlers/pluginfile'; import { AddonModImscpPrefetchHandler } from './services/handlers/prefetch'; +import { ADDON_MOD_IMSCP_PAGE_NAME } from './constants'; const routes: Routes = [ { - path: AddonModImscpModuleHandlerService.PAGE_NAME, - loadChildren: () => import('./imscp-lazy.module').then(m => m.AddonModImscpLazyModule), + path: ADDON_MOD_IMSCP_PAGE_NAME, + loadChildren: () => import('./imscp-lazy.module'), }, ]; diff --git a/src/addons/mod/imscp/services/handlers/module.ts b/src/addons/mod/imscp/services/handlers/module.ts index 180381380..e328ba0ec 100644 --- a/src/addons/mod/imscp/services/handlers/module.ts +++ b/src/addons/mod/imscp/services/handlers/module.ts @@ -18,6 +18,7 @@ import { CoreModuleHandlerBase } from '@features/course/classes/module-base-hand import { CoreCourseModuleHandler } from '@features/course/services/module-delegate'; import { makeSingleton } from '@singletons'; import { AddonModImscp } from '../imscp'; +import { ADDON_MOD_IMSCP_PAGE_NAME } from '../../constants'; /** * Handler to support IMSCP modules. @@ -25,11 +26,9 @@ import { AddonModImscp } from '../imscp'; @Injectable( { providedIn: 'root' }) export class AddonModImscpModuleHandlerService extends CoreModuleHandlerBase implements CoreCourseModuleHandler { - static readonly PAGE_NAME = 'mod_imscp'; - name = 'AddonModImscp'; modName = 'imscp'; - protected pageName = AddonModImscpModuleHandlerService.PAGE_NAME; + protected pageName = ADDON_MOD_IMSCP_PAGE_NAME; supportedFeatures = { [CoreConstants.FEATURE_MOD_ARCHETYPE]: CoreConstants.MOD_ARCHETYPE_RESOURCE, diff --git a/src/addons/mod/imscp/services/handlers/prefetch.ts b/src/addons/mod/imscp/services/handlers/prefetch.ts index 667603fed..5aa83b35a 100644 --- a/src/addons/mod/imscp/services/handlers/prefetch.ts +++ b/src/addons/mod/imscp/services/handlers/prefetch.ts @@ -25,7 +25,8 @@ import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreUtils } from '@services/utils/utils'; import { CoreWSFile } from '@services/ws'; import { makeSingleton } from '@singletons'; -import { AddonModImscp, AddonModImscpProvider } from '../imscp'; +import { AddonModImscp } from '../imscp'; +import { ADDON_MOD_IMSCP_COMPONENT } from '../../constants'; /** * Handler to prefetch IMSCPs. @@ -35,7 +36,7 @@ export class AddonModImscpPrefetchHandlerService extends CoreCourseResourcePrefe name = 'AddonModImscp'; modName = 'imscp'; - component = AddonModImscpProvider.COMPONENT; + component = ADDON_MOD_IMSCP_COMPONENT; /** * @inheritdoc diff --git a/src/addons/mod/imscp/services/imscp.ts b/src/addons/mod/imscp/services/imscp.ts index d756a88ce..caa1cab77 100644 --- a/src/addons/mod/imscp/services/imscp.ts +++ b/src/addons/mod/imscp/services/imscp.ts @@ -27,8 +27,7 @@ import { CoreWSExternalFile, CoreWSExternalWarning } from '@services/ws'; import { makeSingleton, Translate } from '@singletons'; import { CorePath } from '@singletons/path'; import { CoreSiteWSPreSets } from '@classes/sites/authenticated-site'; - -const ROOT_CACHE_KEY = 'mmaModImscp:'; +import { ADDON_MOD_IMSCP_COMPONENT } from '../constants'; /** * Service that provides some features for IMSCP. @@ -36,7 +35,7 @@ const ROOT_CACHE_KEY = 'mmaModImscp:'; @Injectable( { providedIn: 'root' }) export class AddonModImscpProvider { - static readonly COMPONENT = 'mmaModImscp'; + protected static readonly ROOT_CACHE_KEY = 'mmaModImscp:'; /** * Get the IMSCP toc as an array. @@ -89,7 +88,7 @@ export class AddonModImscpProvider { * @returns Cache key. */ protected getImscpDataCacheKey(courseId: number): string { - return ROOT_CACHE_KEY + 'imscp:' + courseId; + return AddonModImscpProvider.ROOT_CACHE_KEY + 'imscp:' + courseId; } /** @@ -116,7 +115,7 @@ export class AddonModImscpProvider { const preSets: CoreSiteWSPreSets = { cacheKey: this.getImscpDataCacheKey(courseId), updateFrequency: CoreSite.FREQUENCY_RARELY, - component: AddonModImscpProvider.COMPONENT, + component: ADDON_MOD_IMSCP_COMPONENT, ...CoreSites.getReadingStrategyPreSets(options.readingStrategy), }; @@ -207,7 +206,7 @@ export class AddonModImscpProvider { */ async getLastItemViewed(id: number, siteId?: string): Promise { const site = await CoreSites.getSite(siteId); - const entry = await site.getLastViewed(AddonModImscpProvider.COMPONENT, id); + const entry = await site.getLastViewed(ADDON_MOD_IMSCP_COMPONENT, id); return entry?.value; } @@ -226,7 +225,7 @@ export class AddonModImscpProvider { const promises: Promise[] = []; promises.push(this.invalidateImscpData(courseId, siteId)); - promises.push(CoreFilepool.invalidateFilesByComponent(siteId, AddonModImscpProvider.COMPONENT, moduleId)); + promises.push(CoreFilepool.invalidateFilesByComponent(siteId, ADDON_MOD_IMSCP_COMPONENT, moduleId)); promises.push(CoreCourse.invalidateModule(moduleId, siteId)); await CoreUtils.allPromises(promises); @@ -283,7 +282,7 @@ export class AddonModImscpProvider { await CoreCourseLogHelper.log( 'mod_imscp_view_imscp', params, - AddonModImscpProvider.COMPONENT, + ADDON_MOD_IMSCP_COMPONENT, id, siteId, ); @@ -301,7 +300,7 @@ export class AddonModImscpProvider { async storeLastItemViewed(id: number, href: string, courseId: number, siteId?: string): Promise { const site = await CoreSites.getSite(siteId); - await site.storeLastViewed(AddonModImscpProvider.COMPONENT, id, href, { data: String(courseId) }); + await site.storeLastViewed(ADDON_MOD_IMSCP_COMPONENT, id, href, { data: String(courseId) }); } }