MOBILE-4616 resource: Move resource constants to a file

main
Pau Ferrer Ocaña 2024-07-11 22:44:06 +02:00
parent c0856c0c97
commit b93dcfb87f
8 changed files with 39 additions and 21 deletions

View File

@ -31,10 +31,10 @@ import { Subscription } from 'rxjs';
import {
AddonModResource,
AddonModResourceCustomData,
AddonModResourceProvider,
} from '../../services/resource';
import { AddonModResourceHelper } from '../../services/resource-helper';
import { CorePlatform } from '@services/platform';
import { ADDON_MOD_RESOURCE_COMPONENT } from '../../constants';
/**
* Component that displays a resource.
@ -46,7 +46,7 @@ import { CorePlatform } from '@services/platform';
})
export class AddonModResourceIndexComponent extends CoreCourseModuleMainResourceComponent implements OnInit, OnDestroy {
component = AddonModResourceProvider.COMPONENT;
component = ADDON_MOD_RESOURCE_COMPONENT;
pluginName = 'resource';
mode = '';

View File

@ -0,0 +1,17 @@
// (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_RESOURCE_COMPONENT = 'mmaModResource';
export const ADDON_MOD_RESOURCE_PAGE_NAME = 'mod_resource';

View File

@ -35,4 +35,4 @@ const routes: Routes = [
AddonModResourceIndexPage,
],
})
export class AddonModResourceLazyModule {}
export default class AddonModResourceLazyModule {}

View File

@ -21,14 +21,15 @@ import { CoreMainMenuTabRoutingModule } from '@features/mainmenu/mainmenu-tab-ro
import { CorePluginFileDelegate } from '@services/plugin-file-delegate';
import { AddonModResourceIndexLinkHandler } from './services/handlers/index-link';
import { AddonModResourceListLinkHandler } from './services/handlers/list-link';
import { AddonModResourceModuleHandlerService, AddonModResourceModuleHandler } from './services/handlers/module';
import { AddonModResourceModuleHandler } from './services/handlers/module';
import { AddonModResourcePluginFileHandler } from './services/handlers/pluginfile';
import { AddonModResourcePrefetchHandler } from './services/handlers/prefetch';
import { ADDON_MOD_RESOURCE_PAGE_NAME } from './constants';
const routes: Routes = [
{
path: AddonModResourceModuleHandlerService.PAGE_NAME,
loadChildren: () => import('./resource-lazy.module').then(m => m.AddonModResourceLazyModule),
path: ADDON_MOD_RESOURCE_PAGE_NAME,
loadChildren: () => import('./resource-lazy.module'),
},
];

View File

@ -25,6 +25,7 @@ import { makeSingleton, Translate } from '@singletons';
import { AddonModResource } from '../resource';
import { AddonModResourceHelper } from '../resource-helper';
import { CoreUtils } from '@services/utils/utils';
import { ADDON_MOD_RESOURCE_PAGE_NAME } from '../../constants';
/**
* Handler to support resource modules.
@ -32,11 +33,9 @@ import { CoreUtils } from '@services/utils/utils';
@Injectable({ providedIn: 'root' })
export class AddonModResourceModuleHandlerService extends CoreModuleHandlerBase implements CoreCourseModuleHandler {
static readonly PAGE_NAME = 'mod_resource';
name = 'AddonModResource';
modName = 'resource';
protected pageName = AddonModResourceModuleHandlerService.PAGE_NAME;
protected pageName = ADDON_MOD_RESOURCE_PAGE_NAME;
supportedFeatures = {
[CoreConstants.FEATURE_MOD_ARCHETYPE]: CoreConstants.MOD_ARCHETYPE_RESOURCE,

View File

@ -20,8 +20,9 @@ import { CoreCourseModuleData } from '@features/course/services/course-helper';
import { CoreFilepool } from '@services/filepool';
import { CoreSites } from '@services/sites';
import { makeSingleton } from '@singletons';
import { AddonModResource, AddonModResourceProvider } from '../resource';
import { AddonModResource } from '../resource';
import { AddonModResourceHelper } from '../resource-helper';
import { ADDON_MOD_RESOURCE_COMPONENT } from '../../constants';
/**
* Handler to prefetch resources.
@ -31,7 +32,7 @@ export class AddonModResourcePrefetchHandlerService extends CoreCourseResourcePr
name = 'AddonModResource';
modName = 'resource';
component = AddonModResourceProvider.COMPONENT;
component = ADDON_MOD_RESOURCE_COMPONENT;
/**
* @inheritdoc

View File

@ -27,10 +27,11 @@ import { CoreMimetypeUtils } from '@services/utils/mimetype';
import { CoreUtilsOpenFileOptions } from '@services/utils/utils';
import { makeSingleton, Translate } from '@singletons';
import { CorePath } from '@singletons/path';
import { AddonModResource, AddonModResourceCustomData, AddonModResourceProvider } from './resource';
import { AddonModResource, AddonModResourceCustomData } from './resource';
import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics';
import { CoreTextUtils } from '@services/utils/text';
import { CoreTimeUtils } from '@services/utils/time';
import { ADDON_MOD_RESOURCE_COMPONENT } from '../constants';
/**
* Service that provides helper functions for resources.
@ -50,7 +51,7 @@ export class AddonModResourceHelperProvider {
const result = await CoreCourseHelper.downloadModuleWithMainFileIfNeeded(
module,
module.course,
AddonModResourceProvider.COMPONENT,
ADDON_MOD_RESOURCE_COMPONENT,
module.id,
contents,
);
@ -196,7 +197,7 @@ export class AddonModResourceHelperProvider {
await CoreCourseHelper.downloadModuleAndOpenFile(
module,
courseId,
AddonModResourceProvider.COMPONENT,
ADDON_MOD_RESOURCE_COMPONENT,
module.id,
module.contents,
undefined,

View File

@ -23,8 +23,7 @@ import { CoreSites, CoreSitesCommonWSOptions } from '@services/sites';
import { CoreUtils } from '@services/utils/utils';
import { CoreWSExternalFile, CoreWSExternalWarning } from '@services/ws';
import { makeSingleton, Translate } from '@singletons';
const ROOT_CACHE_KEY = 'mmaModResource:';
import { ADDON_MOD_RESOURCE_COMPONENT } from '../constants';
/**
* Service that provides some features for resources.
@ -32,7 +31,7 @@ const ROOT_CACHE_KEY = 'mmaModResource:';
@Injectable({ providedIn: 'root' })
export class AddonModResourceProvider {
static readonly COMPONENT = 'mmaModResource';
protected static readonly ROOT_CACHE_KEY = 'mmaModResource:';
/**
* Get cache key for resource data WS calls.
@ -41,7 +40,7 @@ export class AddonModResourceProvider {
* @returns Cache key.
*/
protected getResourceCacheKey(courseId: number): string {
return ROOT_CACHE_KEY + 'resource:' + courseId;
return AddonModResourceProvider.ROOT_CACHE_KEY + 'resource:' + courseId;
}
/**
@ -68,7 +67,7 @@ export class AddonModResourceProvider {
const preSets: CoreSiteWSPreSets = {
cacheKey: this.getResourceCacheKey(courseId),
updateFrequency: CoreSite.FREQUENCY_RARELY,
component: AddonModResourceProvider.COMPONENT,
component: ADDON_MOD_RESOURCE_COMPONENT,
...CoreSites.getReadingStrategyPreSets(options.readingStrategy),
};
@ -112,7 +111,7 @@ export class AddonModResourceProvider {
const promises: Promise<void>[] = [];
promises.push(this.invalidateResourceData(courseId, siteId));
promises.push(CoreFilepool.invalidateFilesByComponent(siteId, AddonModResourceProvider.COMPONENT, moduleId));
promises.push(CoreFilepool.invalidateFilesByComponent(siteId, ADDON_MOD_RESOURCE_COMPONENT, moduleId));
promises.push(CoreCourse.invalidateModule(moduleId, siteId, 'resource'));
await CoreUtils.allPromises(promises);
@ -158,7 +157,7 @@ export class AddonModResourceProvider {
await CoreCourseLogHelper.log(
'mod_resource_view_resource',
params,
AddonModResourceProvider.COMPONENT,
ADDON_MOD_RESOURCE_COMPONENT,
id,
siteId,
);