MOBILE-4616 folder: Move folder constants to a file

main
Pau Ferrer Ocaña 2024-07-11 22:40:51 +02:00
parent 09791c8d20
commit c836e94101
7 changed files with 36 additions and 19 deletions

View File

@ -19,10 +19,10 @@ import { CoreCourseContentsPage } from '@features/course/pages/contents/contents
import { CoreCourse } from '@features/course/services/course';
import { CoreNavigator } from '@services/navigator';
import { Md5 } from 'ts-md5';
import { AddonModFolder, AddonModFolderFolder, AddonModFolderProvider } from '../../services/folder';
import { AddonModFolder, AddonModFolderFolder } from '../../services/folder';
import { AddonModFolderFolderFormattedData, AddonModFolderHelper } from '../../services/folder-helper';
import { AddonModFolderModuleHandlerService } from '../../services/handlers/module';
import { CoreUtils } from '@services/utils/utils';
import { ADDON_MOD_FOLDER_COMPONENT, ADDON_MOD_FOLDER_PAGE_NAME } from '../../constants';
/**
* Component that displays a folder.
@ -39,7 +39,7 @@ export class AddonModFolderIndexComponent extends CoreCourseModuleMainResourceCo
@Input() folderInstance?: AddonModFolderFolder; // The mod_folder instance.
@Input() subfolder?: AddonModFolderFolderFormattedData; // Subfolder to show.
component = AddonModFolderProvider.COMPONENT;
component = ADDON_MOD_FOLDER_COMPONENT;
pluginName = 'folder';
contents?: AddonModFolderFolderFormattedData;
@ -141,7 +141,7 @@ export class AddonModFolderIndexComponent extends CoreCourseModuleMainResourceCo
const hash = Md5.hashAsciiStr(folder.filepath);
CoreNavigator.navigateToSitePath(
`${AddonModFolderModuleHandlerService.PAGE_NAME}/${this.courseId}/${this.module.id}/${hash}`,
`${ADDON_MOD_FOLDER_PAGE_NAME}/${this.courseId}/${this.module.id}/${hash}`,
{ params },
);
}

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_FOLDER_COMPONENT = 'mmaModFolder';
export const ADDON_MOD_FOLDER_PAGE_NAME = 'mod_folder';

View File

@ -42,4 +42,4 @@ const routes: Routes = [
AddonModFolderIndexPage,
],
})
export class AddonModFolderLazyModule {}
export default class AddonModFolderLazyModule {}

View File

@ -21,14 +21,15 @@ import { CoreMainMenuTabRoutingModule } from '@features/mainmenu/mainmenu-tab-ro
import { CorePluginFileDelegate } from '@services/plugin-file-delegate';
import { AddonModFolderIndexLinkHandler } from './services/handlers/index-link';
import { AddonModFolderListLinkHandler } from './services/handlers/list-link';
import { AddonModFolderModuleHandler, AddonModFolderModuleHandlerService } from './services/handlers/module';
import { AddonModFolderModuleHandler } from './services/handlers/module';
import { AddonModFolderPluginFileHandler } from './services/handlers/pluginfile';
import { AddonModFolderPrefetchHandler } from './services/handlers/prefetch';
import { ADDON_MOD_FOLDER_PAGE_NAME } from './constants';
const routes: Routes = [
{
path: AddonModFolderModuleHandlerService.PAGE_NAME,
loadChildren: () => import('./folder-lazy.module').then(m => m.AddonModFolderLazyModule),
path: ADDON_MOD_FOLDER_PAGE_NAME,
loadChildren: () => import('./folder-lazy.module'),
},
];

View File

@ -22,8 +22,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 = 'mmaModFolder:';
import { ADDON_MOD_FOLDER_COMPONENT } from '../constants';
/**
* Service that provides some features for folder.
@ -31,7 +30,7 @@ const ROOT_CACHE_KEY = 'mmaModFolder:';
@Injectable({ providedIn: 'root' })
export class AddonModFolderProvider {
static readonly COMPONENT = 'mmaModFolder';
protected static readonly ROOT_CACHE_KEY = 'mmaModFolder:';
/**
* Get a folder by course module ID.
@ -69,7 +68,7 @@ export class AddonModFolderProvider {
const preSets: CoreSiteWSPreSets = {
cacheKey: this.getFolderCacheKey(courseId),
updateFrequency: CoreSite.FREQUENCY_RARELY,
component: AddonModFolderProvider.COMPONENT,
component: ADDON_MOD_FOLDER_COMPONENT,
...CoreSites.getReadingStrategyPreSets(options.readingStrategy),
};
@ -91,7 +90,7 @@ export class AddonModFolderProvider {
* @returns Cache key.
*/
protected getFolderCacheKey(courseId: number): string {
return ROOT_CACHE_KEY + 'folder:' + courseId;
return AddonModFolderProvider.ROOT_CACHE_KEY + 'folder:' + courseId;
}
/**
@ -138,7 +137,7 @@ export class AddonModFolderProvider {
await CoreCourseLogHelper.log(
'mod_folder_view_folder',
params,
AddonModFolderProvider.COMPONENT,
ADDON_MOD_FOLDER_COMPONENT,
id,
siteId,
);

View File

@ -20,6 +20,7 @@ import { CoreCourseModuleHandler, CoreCourseModuleHandlerData } from '@features/
import { CoreNavigator } from '@services/navigator';
import { CoreDomUtils } from '@services/utils/dom';
import { makeSingleton } from '@singletons';
import { ADDON_MOD_FOLDER_PAGE_NAME } from '../../constants';
/**
* Handler to support folder modules.
@ -27,11 +28,9 @@ import { makeSingleton } from '@singletons';
@Injectable({ providedIn: 'root' })
export class AddonModFolderModuleHandlerService extends CoreModuleHandlerBase implements CoreCourseModuleHandler {
static readonly PAGE_NAME = 'mod_folder';
name = 'AddonModFolder';
modName = 'folder';
protected pageName = AddonModFolderModuleHandlerService.PAGE_NAME;
protected pageName = ADDON_MOD_FOLDER_PAGE_NAME;
supportedFeatures = {
[CoreConstants.FEATURE_MOD_ARCHETYPE]: CoreConstants.MOD_ARCHETYPE_RESOURCE,

View File

@ -17,7 +17,8 @@ import { CoreCourseResourcePrefetchHandlerBase } from '@features/course/classes/
import { CoreCourse, CoreCourseAnyModuleData } from '@features/course/services/course';
import { CoreCourseModuleData } from '@features/course/services/course-helper';
import { makeSingleton } from '@singletons';
import { AddonModFolder, AddonModFolderProvider } from '../folder';
import { AddonModFolder } from '../folder';
import { ADDON_MOD_FOLDER_COMPONENT } from '../../constants';
/**
* Handler to prefetch folders.
@ -27,7 +28,7 @@ export class AddonModFolderPrefetchHandlerService extends CoreCourseResourcePref
name = 'AddonModFolder';
modName = 'folder';
component = AddonModFolderProvider.COMPONENT;
component = ADDON_MOD_FOLDER_COMPONENT;
/**
* @inheritdoc