MOBILE-4616 label: Move label constants to a file

main
Pau Ferrer Ocaña 2024-07-11 22:42:15 +02:00
parent 70507ce604
commit 7e37b47fd4
3 changed files with 23 additions and 8 deletions

View File

@ -0,0 +1,15 @@
// (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_LABEL_COMPONENT = 'mmaModLabel';

View File

@ -19,7 +19,8 @@ import { CoreSitesReadingStrategy } from '@services/sites';
import { CoreUtils } from '@services/utils/utils';
import { CoreWSFile } from '@services/ws';
import { makeSingleton } from '@singletons';
import { AddonModLabel, AddonModLabelProvider } from '../label';
import { AddonModLabel } from '../label';
import { ADDON_MOD_LABEL_COMPONENT } from '../../constants';
/**
* Handler to prefetch labels.
@ -29,7 +30,7 @@ export class AddonModLabelPrefetchHandlerService extends CoreCourseResourcePrefe
name = 'AddonModLabel';
modName = 'label';
component = AddonModLabelProvider.COMPONENT;
component = ADDON_MOD_LABEL_COMPONENT;
updatesNames = /^.*files$/;
/**

View File

@ -21,8 +21,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 = 'mmaModLabel:';
import { ADDON_MOD_LABEL_COMPONENT } from '../constants';
/**
* Service that provides some features for labels.
@ -30,7 +29,7 @@ const ROOT_CACHE_KEY = 'mmaModLabel:';
@Injectable({ providedIn: 'root' })
export class AddonModLabelProvider {
static readonly COMPONENT = 'mmaModLabel';
protected static readonly ROOT_CACHE_KEY = 'mmaModLabel:';
/**
* Get cache key for label data WS calls.
@ -39,7 +38,7 @@ export class AddonModLabelProvider {
* @returns Cache key.
*/
protected getLabelDataCacheKey(courseId: number): string {
return ROOT_CACHE_KEY + 'label:' + courseId;
return AddonModLabelProvider.ROOT_CACHE_KEY + 'label:' + courseId;
}
/**
@ -66,7 +65,7 @@ export class AddonModLabelProvider {
const preSets: CoreSiteWSPreSets = {
cacheKey: this.getLabelDataCacheKey(courseId),
updateFrequency: CoreSite.FREQUENCY_RARELY,
component: AddonModLabelProvider.COMPONENT,
component: ADDON_MOD_LABEL_COMPONENT,
...CoreSites.getReadingStrategyPreSets(options.readingStrategy),
};
@ -132,7 +131,7 @@ export class AddonModLabelProvider {
const promises: Promise<void>[] = [];
promises.push(this.invalidateLabelData(courseId, siteId));
promises.push(CoreFilepool.invalidateFilesByComponent(siteId, AddonModLabelProvider.COMPONENT, moduleId, true));
promises.push(CoreFilepool.invalidateFilesByComponent(siteId, ADDON_MOD_LABEL_COMPONENT, moduleId, true));
await CoreUtils.allPromises(promises);
}