MOBILE-4616 resource: Move resource constants to a file
parent
c0856c0c97
commit
b93dcfb87f
|
@ -31,10 +31,10 @@ import { Subscription } from 'rxjs';
|
||||||
import {
|
import {
|
||||||
AddonModResource,
|
AddonModResource,
|
||||||
AddonModResourceCustomData,
|
AddonModResourceCustomData,
|
||||||
AddonModResourceProvider,
|
|
||||||
} from '../../services/resource';
|
} from '../../services/resource';
|
||||||
import { AddonModResourceHelper } from '../../services/resource-helper';
|
import { AddonModResourceHelper } from '../../services/resource-helper';
|
||||||
import { CorePlatform } from '@services/platform';
|
import { CorePlatform } from '@services/platform';
|
||||||
|
import { ADDON_MOD_RESOURCE_COMPONENT } from '../../constants';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Component that displays a resource.
|
* Component that displays a resource.
|
||||||
|
@ -46,7 +46,7 @@ import { CorePlatform } from '@services/platform';
|
||||||
})
|
})
|
||||||
export class AddonModResourceIndexComponent extends CoreCourseModuleMainResourceComponent implements OnInit, OnDestroy {
|
export class AddonModResourceIndexComponent extends CoreCourseModuleMainResourceComponent implements OnInit, OnDestroy {
|
||||||
|
|
||||||
component = AddonModResourceProvider.COMPONENT;
|
component = ADDON_MOD_RESOURCE_COMPONENT;
|
||||||
pluginName = 'resource';
|
pluginName = 'resource';
|
||||||
|
|
||||||
mode = '';
|
mode = '';
|
||||||
|
|
|
@ -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';
|
|
@ -35,4 +35,4 @@ const routes: Routes = [
|
||||||
AddonModResourceIndexPage,
|
AddonModResourceIndexPage,
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class AddonModResourceLazyModule {}
|
export default class AddonModResourceLazyModule {}
|
||||||
|
|
|
@ -21,14 +21,15 @@ import { CoreMainMenuTabRoutingModule } from '@features/mainmenu/mainmenu-tab-ro
|
||||||
import { CorePluginFileDelegate } from '@services/plugin-file-delegate';
|
import { CorePluginFileDelegate } from '@services/plugin-file-delegate';
|
||||||
import { AddonModResourceIndexLinkHandler } from './services/handlers/index-link';
|
import { AddonModResourceIndexLinkHandler } from './services/handlers/index-link';
|
||||||
import { AddonModResourceListLinkHandler } from './services/handlers/list-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 { AddonModResourcePluginFileHandler } from './services/handlers/pluginfile';
|
||||||
import { AddonModResourcePrefetchHandler } from './services/handlers/prefetch';
|
import { AddonModResourcePrefetchHandler } from './services/handlers/prefetch';
|
||||||
|
import { ADDON_MOD_RESOURCE_PAGE_NAME } from './constants';
|
||||||
|
|
||||||
const routes: Routes = [
|
const routes: Routes = [
|
||||||
{
|
{
|
||||||
path: AddonModResourceModuleHandlerService.PAGE_NAME,
|
path: ADDON_MOD_RESOURCE_PAGE_NAME,
|
||||||
loadChildren: () => import('./resource-lazy.module').then(m => m.AddonModResourceLazyModule),
|
loadChildren: () => import('./resource-lazy.module'),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ import { makeSingleton, Translate } from '@singletons';
|
||||||
import { AddonModResource } from '../resource';
|
import { AddonModResource } from '../resource';
|
||||||
import { AddonModResourceHelper } from '../resource-helper';
|
import { AddonModResourceHelper } from '../resource-helper';
|
||||||
import { CoreUtils } from '@services/utils/utils';
|
import { CoreUtils } from '@services/utils/utils';
|
||||||
|
import { ADDON_MOD_RESOURCE_PAGE_NAME } from '../../constants';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler to support resource modules.
|
* Handler to support resource modules.
|
||||||
|
@ -32,11 +33,9 @@ import { CoreUtils } from '@services/utils/utils';
|
||||||
@Injectable({ providedIn: 'root' })
|
@Injectable({ providedIn: 'root' })
|
||||||
export class AddonModResourceModuleHandlerService extends CoreModuleHandlerBase implements CoreCourseModuleHandler {
|
export class AddonModResourceModuleHandlerService extends CoreModuleHandlerBase implements CoreCourseModuleHandler {
|
||||||
|
|
||||||
static readonly PAGE_NAME = 'mod_resource';
|
|
||||||
|
|
||||||
name = 'AddonModResource';
|
name = 'AddonModResource';
|
||||||
modName = 'resource';
|
modName = 'resource';
|
||||||
protected pageName = AddonModResourceModuleHandlerService.PAGE_NAME;
|
protected pageName = ADDON_MOD_RESOURCE_PAGE_NAME;
|
||||||
|
|
||||||
supportedFeatures = {
|
supportedFeatures = {
|
||||||
[CoreConstants.FEATURE_MOD_ARCHETYPE]: CoreConstants.MOD_ARCHETYPE_RESOURCE,
|
[CoreConstants.FEATURE_MOD_ARCHETYPE]: CoreConstants.MOD_ARCHETYPE_RESOURCE,
|
||||||
|
|
|
@ -20,8 +20,9 @@ import { CoreCourseModuleData } from '@features/course/services/course-helper';
|
||||||
import { CoreFilepool } from '@services/filepool';
|
import { CoreFilepool } from '@services/filepool';
|
||||||
import { CoreSites } from '@services/sites';
|
import { CoreSites } from '@services/sites';
|
||||||
import { makeSingleton } from '@singletons';
|
import { makeSingleton } from '@singletons';
|
||||||
import { AddonModResource, AddonModResourceProvider } from '../resource';
|
import { AddonModResource } from '../resource';
|
||||||
import { AddonModResourceHelper } from '../resource-helper';
|
import { AddonModResourceHelper } from '../resource-helper';
|
||||||
|
import { ADDON_MOD_RESOURCE_COMPONENT } from '../../constants';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler to prefetch resources.
|
* Handler to prefetch resources.
|
||||||
|
@ -31,7 +32,7 @@ export class AddonModResourcePrefetchHandlerService extends CoreCourseResourcePr
|
||||||
|
|
||||||
name = 'AddonModResource';
|
name = 'AddonModResource';
|
||||||
modName = 'resource';
|
modName = 'resource';
|
||||||
component = AddonModResourceProvider.COMPONENT;
|
component = ADDON_MOD_RESOURCE_COMPONENT;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
|
|
|
@ -27,10 +27,11 @@ import { CoreMimetypeUtils } from '@services/utils/mimetype';
|
||||||
import { CoreUtilsOpenFileOptions } from '@services/utils/utils';
|
import { CoreUtilsOpenFileOptions } from '@services/utils/utils';
|
||||||
import { makeSingleton, Translate } from '@singletons';
|
import { makeSingleton, Translate } from '@singletons';
|
||||||
import { CorePath } from '@singletons/path';
|
import { CorePath } from '@singletons/path';
|
||||||
import { AddonModResource, AddonModResourceCustomData, AddonModResourceProvider } from './resource';
|
import { AddonModResource, AddonModResourceCustomData } from './resource';
|
||||||
import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics';
|
import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics';
|
||||||
import { CoreTextUtils } from '@services/utils/text';
|
import { CoreTextUtils } from '@services/utils/text';
|
||||||
import { CoreTimeUtils } from '@services/utils/time';
|
import { CoreTimeUtils } from '@services/utils/time';
|
||||||
|
import { ADDON_MOD_RESOURCE_COMPONENT } from '../constants';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service that provides helper functions for resources.
|
* Service that provides helper functions for resources.
|
||||||
|
@ -50,7 +51,7 @@ export class AddonModResourceHelperProvider {
|
||||||
const result = await CoreCourseHelper.downloadModuleWithMainFileIfNeeded(
|
const result = await CoreCourseHelper.downloadModuleWithMainFileIfNeeded(
|
||||||
module,
|
module,
|
||||||
module.course,
|
module.course,
|
||||||
AddonModResourceProvider.COMPONENT,
|
ADDON_MOD_RESOURCE_COMPONENT,
|
||||||
module.id,
|
module.id,
|
||||||
contents,
|
contents,
|
||||||
);
|
);
|
||||||
|
@ -196,7 +197,7 @@ export class AddonModResourceHelperProvider {
|
||||||
await CoreCourseHelper.downloadModuleAndOpenFile(
|
await CoreCourseHelper.downloadModuleAndOpenFile(
|
||||||
module,
|
module,
|
||||||
courseId,
|
courseId,
|
||||||
AddonModResourceProvider.COMPONENT,
|
ADDON_MOD_RESOURCE_COMPONENT,
|
||||||
module.id,
|
module.id,
|
||||||
module.contents,
|
module.contents,
|
||||||
undefined,
|
undefined,
|
||||||
|
|
|
@ -23,8 +23,7 @@ import { CoreSites, CoreSitesCommonWSOptions } from '@services/sites';
|
||||||
import { CoreUtils } from '@services/utils/utils';
|
import { CoreUtils } from '@services/utils/utils';
|
||||||
import { CoreWSExternalFile, CoreWSExternalWarning } from '@services/ws';
|
import { CoreWSExternalFile, CoreWSExternalWarning } from '@services/ws';
|
||||||
import { makeSingleton, Translate } from '@singletons';
|
import { makeSingleton, Translate } from '@singletons';
|
||||||
|
import { ADDON_MOD_RESOURCE_COMPONENT } from '../constants';
|
||||||
const ROOT_CACHE_KEY = 'mmaModResource:';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service that provides some features for resources.
|
* Service that provides some features for resources.
|
||||||
|
@ -32,7 +31,7 @@ const ROOT_CACHE_KEY = 'mmaModResource:';
|
||||||
@Injectable({ providedIn: 'root' })
|
@Injectable({ providedIn: 'root' })
|
||||||
export class AddonModResourceProvider {
|
export class AddonModResourceProvider {
|
||||||
|
|
||||||
static readonly COMPONENT = 'mmaModResource';
|
protected static readonly ROOT_CACHE_KEY = 'mmaModResource:';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get cache key for resource data WS calls.
|
* Get cache key for resource data WS calls.
|
||||||
|
@ -41,7 +40,7 @@ export class AddonModResourceProvider {
|
||||||
* @returns Cache key.
|
* @returns Cache key.
|
||||||
*/
|
*/
|
||||||
protected getResourceCacheKey(courseId: number): string {
|
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 = {
|
const preSets: CoreSiteWSPreSets = {
|
||||||
cacheKey: this.getResourceCacheKey(courseId),
|
cacheKey: this.getResourceCacheKey(courseId),
|
||||||
updateFrequency: CoreSite.FREQUENCY_RARELY,
|
updateFrequency: CoreSite.FREQUENCY_RARELY,
|
||||||
component: AddonModResourceProvider.COMPONENT,
|
component: ADDON_MOD_RESOURCE_COMPONENT,
|
||||||
...CoreSites.getReadingStrategyPreSets(options.readingStrategy),
|
...CoreSites.getReadingStrategyPreSets(options.readingStrategy),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -112,7 +111,7 @@ export class AddonModResourceProvider {
|
||||||
const promises: Promise<void>[] = [];
|
const promises: Promise<void>[] = [];
|
||||||
|
|
||||||
promises.push(this.invalidateResourceData(courseId, siteId));
|
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'));
|
promises.push(CoreCourse.invalidateModule(moduleId, siteId, 'resource'));
|
||||||
|
|
||||||
await CoreUtils.allPromises(promises);
|
await CoreUtils.allPromises(promises);
|
||||||
|
@ -158,7 +157,7 @@ export class AddonModResourceProvider {
|
||||||
await CoreCourseLogHelper.log(
|
await CoreCourseLogHelper.log(
|
||||||
'mod_resource_view_resource',
|
'mod_resource_view_resource',
|
||||||
params,
|
params,
|
||||||
AddonModResourceProvider.COMPONENT,
|
ADDON_MOD_RESOURCE_COMPONENT,
|
||||||
id,
|
id,
|
||||||
siteId,
|
siteId,
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue