MOBILE-2652 glossary: Clean up service class

main
Noel De Martin 2023-03-21 13:54:41 +01:00
parent 61809c06c8
commit 7e8e694c63
4 changed files with 73 additions and 215 deletions

View File

@ -164,21 +164,8 @@ export class AddonModGlossaryEntriesSource extends CoreRoutedItemsManagerSource<
const glossaryId = this.glossary.id; const glossaryId = this.glossary.id;
this.fetchFunction = (options) => AddonModGlossary.getEntriesBySearch( this.fetchFunction = (options) => AddonModGlossary.getEntriesBySearch(glossaryId, query, true, options);
glossaryId, this.fetchInvalidate = () => AddonModGlossary.invalidateEntriesBySearch(glossaryId, query, true);
query,
true,
'CONCEPT',
'ASC',
options,
);
this.fetchInvalidate = () => AddonModGlossary.invalidateEntriesBySearch(
glossaryId,
query,
true,
'CONCEPT',
'ASC',
);
this.hasSearched = true; this.hasSearched = true;
this.setDirty(true); this.setDirty(true);
} }
@ -220,65 +207,29 @@ export class AddonModGlossaryEntriesSource extends CoreRoutedItemsManagerSource<
case 'author_all': case 'author_all':
// Browse by author. // Browse by author.
this.viewMode = 'author'; this.viewMode = 'author';
this.fetchFunction = (options) => AddonModGlossary.getEntriesByAuthor( this.fetchFunction = (options) => AddonModGlossary.getEntriesByAuthor(glossaryId, options);
glossaryId, this.fetchInvalidate = () => AddonModGlossary.invalidateEntriesByAuthor(glossaryId);
'ALL',
'LASTNAME',
'ASC',
options,
);
this.fetchInvalidate = () => AddonModGlossary.invalidateEntriesByAuthor(
glossaryId,
'ALL',
'LASTNAME',
'ASC',
);
break; break;
case 'cat_all': case 'cat_all':
// Browse by category. // Browse by category.
this.viewMode = 'cat'; this.viewMode = 'cat';
this.fetchFunction = (options) => AddonModGlossary.getEntriesByCategory( this.fetchFunction = (options) => AddonModGlossary.getEntriesByCategory(glossaryId, options);
glossaryId, this.fetchInvalidate = () => AddonModGlossary.invalidateEntriesByCategory(glossaryId);
AddonModGlossaryProvider.SHOW_ALL_CATEGORIES,
options,
);
this.fetchInvalidate = () => AddonModGlossary.invalidateEntriesByCategory(
glossaryId,
AddonModGlossaryProvider.SHOW_ALL_CATEGORIES,
);
break; break;
case 'newest_first': case 'newest_first':
// Newest first. // Newest first.
this.viewMode = 'date'; this.viewMode = 'date';
this.fetchFunction = (options) => AddonModGlossary.getEntriesByDate( this.fetchFunction = (options) => AddonModGlossary.getEntriesByDate(glossaryId, 'CREATION', options);
glossaryId, this.fetchInvalidate = () => AddonModGlossary.invalidateEntriesByDate(glossaryId, 'CREATION');
'CREATION',
'DESC',
options,
);
this.fetchInvalidate = () => AddonModGlossary.invalidateEntriesByDate(
glossaryId,
'CREATION',
'DESC',
);
break; break;
case 'recently_updated': case 'recently_updated':
// Recently updated. // Recently updated.
this.viewMode = 'date'; this.viewMode = 'date';
this.fetchFunction = (options) => AddonModGlossary.getEntriesByDate( this.fetchFunction = (options) => AddonModGlossary.getEntriesByDate(glossaryId, 'UPDATE', options);
glossaryId, this.fetchInvalidate = () => AddonModGlossary.invalidateEntriesByDate(glossaryId, 'UPDATE');
'UPDATE',
'DESC',
options,
);
this.fetchInvalidate = () => AddonModGlossary.invalidateEntriesByDate(
glossaryId,
'UPDATE',
'DESC',
);
break; break;
case 'letter_all': case 'letter_all':
@ -286,15 +237,8 @@ export class AddonModGlossaryEntriesSource extends CoreRoutedItemsManagerSource<
// Consider it is 'letter_all'. // Consider it is 'letter_all'.
this.viewMode = 'letter'; this.viewMode = 'letter';
this.fetchMode = 'letter_all'; this.fetchMode = 'letter_all';
this.fetchFunction = (options) => AddonModGlossary.getEntriesByLetter( this.fetchFunction = (options) => AddonModGlossary.getEntriesByLetter(glossaryId, options);
glossaryId, this.fetchInvalidate = () => AddonModGlossary.invalidateEntriesByLetter(glossaryId);
'ALL',
options,
);
this.fetchInvalidate = () => AddonModGlossary.invalidateEntriesByLetter(
glossaryId,
'ALL',
);
break; break;
} }
} }

View File

@ -30,8 +30,6 @@ import { AddonModGlossaryOffline } from './glossary-offline';
import { AddonModGlossaryAutoSyncData, AddonModGlossarySyncProvider } from './glossary-sync'; import { AddonModGlossaryAutoSyncData, AddonModGlossarySyncProvider } from './glossary-sync';
import { CoreFileEntry } from '@services/file-helper'; import { CoreFileEntry } from '@services/file-helper';
const ROOT_CACHE_KEY = 'mmaModGlossary:';
/** /**
* Service that provides some features for glossaries. * Service that provides some features for glossaries.
*/ */
@ -41,11 +39,12 @@ export class AddonModGlossaryProvider {
static readonly COMPONENT = 'mmaModGlossary'; static readonly COMPONENT = 'mmaModGlossary';
static readonly LIMIT_ENTRIES = 25; static readonly LIMIT_ENTRIES = 25;
static readonly LIMIT_CATEGORIES = 10; static readonly LIMIT_CATEGORIES = 10;
static readonly SHOW_ALL_CATEGORIES = 0;
static readonly SHOW_NOT_CATEGORISED = -1;
static readonly ADD_ENTRY_EVENT = 'addon_mod_glossary_add_entry'; static readonly ADD_ENTRY_EVENT = 'addon_mod_glossary_add_entry';
private static readonly SHOW_ALL_CATEGORIES = 0;
private static readonly ROOT_CACHE_KEY = 'mmaModGlossary:';
/** /**
* Get the course glossary cache key. * Get the course glossary cache key.
* *
@ -53,7 +52,7 @@ export class AddonModGlossaryProvider {
* @returns Cache key. * @returns Cache key.
*/ */
protected getCourseGlossariesCacheKey(courseId: number): string { protected getCourseGlossariesCacheKey(courseId: number): string {
return ROOT_CACHE_KEY + 'courseGlossaries:' + courseId; return `${AddonModGlossaryProvider.ROOT_CACHE_KEY}courseGlossaries:${courseId}`;
} }
/** /**
@ -90,7 +89,6 @@ export class AddonModGlossaryProvider {
* *
* @param courseId Course Id. * @param courseId Course Id.
* @param siteId Site ID. If not defined, current site. * @param siteId Site ID. If not defined, current site.
* @returns Resolved when data is invalidated.
*/ */
async invalidateCourseGlossaries(courseId: number, siteId?: string): Promise<void> { async invalidateCourseGlossaries(courseId: number, siteId?: string): Promise<void> {
const site = await CoreSites.getSite(siteId); const site = await CoreSites.getSite(siteId);
@ -104,44 +102,35 @@ export class AddonModGlossaryProvider {
* Get the entries by author cache key. * Get the entries by author cache key.
* *
* @param glossaryId Glossary Id. * @param glossaryId Glossary Id.
* @param letter First letter of firstname or lastname, or either keywords: ALL or SPECIAL.
* @param field Search and order using: FIRSTNAME or LASTNAME
* @param sort The direction of the order: ASC or DESC
* @returns Cache key. * @returns Cache key.
*/ */
protected getEntriesByAuthorCacheKey(glossaryId: number, letter: string, field: string, sort: string): string { protected getEntriesByAuthorCacheKey(glossaryId: number): string {
return ROOT_CACHE_KEY + 'entriesByAuthor:' + glossaryId + ':' + letter + ':' + field + ':' + sort; return `${AddonModGlossaryProvider.ROOT_CACHE_KEY}entriesByAuthor:${glossaryId}:ALL:LASTNAME:ASC`;
} }
/** /**
* Get entries by author. * Get entries by author.
* *
* @param glossaryId Glossary Id. * @param glossaryId Glossary Id.
* @param letter First letter of firstname or lastname, or either keywords: ALL or SPECIAL.
* @param field Search and order using: FIRSTNAME or LASTNAME
* @param sort The direction of the order: ASC or DESC
* @param options Other options. * @param options Other options.
* @returns Resolved with the entries. * @returns Resolved with the entries.
*/ */
async getEntriesByAuthor( async getEntriesByAuthor(
glossaryId: number, glossaryId: number,
letter: string,
field: string,
sort: string,
options: AddonModGlossaryGetEntriesOptions = {}, options: AddonModGlossaryGetEntriesOptions = {},
): Promise<AddonModGlossaryGetEntriesWSResponse> { ): Promise<AddonModGlossaryGetEntriesWSResponse> {
const site = await CoreSites.getSite(options.siteId); const site = await CoreSites.getSite(options.siteId);
const params: AddonModGlossaryGetEntriesByAuthorWSParams = { const params: AddonModGlossaryGetEntriesByAuthorWSParams = {
id: glossaryId, id: glossaryId,
letter: letter, letter: 'ALL',
field: field, field: 'LASTNAME',
sort: sort, sort: 'ASC',
from: options.from || 0, from: options.from || 0,
limit: options.limit || AddonModGlossaryProvider.LIMIT_ENTRIES, limit: options.limit || AddonModGlossaryProvider.LIMIT_ENTRIES,
}; };
const preSets: CoreSiteWSPreSets = { const preSets: CoreSiteWSPreSets = {
cacheKey: this.getEntriesByAuthorCacheKey(glossaryId, letter, field, sort), cacheKey: this.getEntriesByAuthorCacheKey(glossaryId),
updateFrequency: CoreSite.FREQUENCY_SOMETIMES, updateFrequency: CoreSite.FREQUENCY_SOMETIMES,
component: AddonModGlossaryProvider.COMPONENT, component: AddonModGlossaryProvider.COMPONENT,
componentId: options.cmId, componentId: options.cmId,
@ -155,22 +144,12 @@ export class AddonModGlossaryProvider {
* Invalidate cache of entries by author. * Invalidate cache of entries by author.
* *
* @param glossaryId Glossary Id. * @param glossaryId Glossary Id.
* @param letter First letter of firstname or lastname, or either keywords: ALL or SPECIAL.
* @param field Search and order using: FIRSTNAME or LASTNAME
* @param sort The direction of the order: ASC or DESC
* @param siteId Site ID. If not defined, current site. * @param siteId Site ID. If not defined, current site.
* @returns Resolved when data is invalidated.
*/ */
async invalidateEntriesByAuthor( async invalidateEntriesByAuthor(glossaryId: number, siteId?: string): Promise<void> {
glossaryId: number,
letter: string,
field: string,
sort: string,
siteId?: string,
): Promise<void> {
const site = await CoreSites.getSite(siteId); const site = await CoreSites.getSite(siteId);
const key = this.getEntriesByAuthorCacheKey(glossaryId, letter, field, sort); const key = this.getEntriesByAuthorCacheKey(glossaryId);
await site.invalidateWsCacheForKey(key); await site.invalidateWsCacheForKey(key);
} }
@ -179,26 +158,23 @@ export class AddonModGlossaryProvider {
* Get entries by category. * Get entries by category.
* *
* @param glossaryId Glossary Id. * @param glossaryId Glossary Id.
* @param categoryId The category ID. Use constant SHOW_ALL_CATEGORIES for all categories, or
* constant SHOW_NOT_CATEGORISED for uncategorised entries.
* @param options Other options. * @param options Other options.
* @returns Resolved with the entries. * @returns Resolved with the entries.
*/ */
async getEntriesByCategory( async getEntriesByCategory(
glossaryId: number, glossaryId: number,
categoryId: number,
options: AddonModGlossaryGetEntriesOptions = {}, options: AddonModGlossaryGetEntriesOptions = {},
): Promise<AddonModGlossaryGetEntriesByCategoryWSResponse> { ): Promise<AddonModGlossaryGetEntriesByCategoryWSResponse> {
const site = await CoreSites.getSite(options.siteId); const site = await CoreSites.getSite(options.siteId);
const params: AddonModGlossaryGetEntriesByCategoryWSParams = { const params: AddonModGlossaryGetEntriesByCategoryWSParams = {
id: glossaryId, id: glossaryId,
categoryid: categoryId, categoryid: AddonModGlossaryProvider.SHOW_ALL_CATEGORIES,
from: options.from || 0, from: options.from || 0,
limit: options.limit || AddonModGlossaryProvider.LIMIT_ENTRIES, limit: options.limit || AddonModGlossaryProvider.LIMIT_ENTRIES,
}; };
const preSets: CoreSiteWSPreSets = { const preSets: CoreSiteWSPreSets = {
cacheKey: this.getEntriesByCategoryCacheKey(glossaryId, categoryId), cacheKey: this.getEntriesByCategoryCacheKey(glossaryId),
updateFrequency: CoreSite.FREQUENCY_SOMETIMES, updateFrequency: CoreSite.FREQUENCY_SOMETIMES,
component: AddonModGlossaryProvider.COMPONENT, component: AddonModGlossaryProvider.COMPONENT,
componentId: options.cmId, componentId: options.cmId,
@ -212,15 +188,12 @@ export class AddonModGlossaryProvider {
* Invalidate cache of entries by category. * Invalidate cache of entries by category.
* *
* @param glossaryId Glossary Id. * @param glossaryId Glossary Id.
* @param categoryId The category ID. Use constant SHOW_ALL_CATEGORIES for all categories, or
* constant SHOW_NOT_CATEGORISED for uncategorised entries.
* @param siteId Site ID. If not defined, current site. * @param siteId Site ID. If not defined, current site.
* @returns Resolved when data is invalidated.
*/ */
async invalidateEntriesByCategory(glossaryId: number, categoryId: number, siteId?: string): Promise<void> { async invalidateEntriesByCategory(glossaryId: number, siteId?: string): Promise<void> {
const site = await CoreSites.getSite(siteId); const site = await CoreSites.getSite(siteId);
const key = this.getEntriesByCategoryCacheKey(glossaryId, categoryId); const key = this.getEntriesByCategoryCacheKey(glossaryId);
await site.invalidateWsCacheForKey(key); await site.invalidateWsCacheForKey(key);
} }
@ -229,12 +202,12 @@ export class AddonModGlossaryProvider {
* Get the entries by category cache key. * Get the entries by category cache key.
* *
* @param glossaryId Glossary Id. * @param glossaryId Glossary Id.
* @param categoryId The category ID. Use constant SHOW_ALL_CATEGORIES for all categories, or
* constant SHOW_NOT_CATEGORISED for uncategorised entries.
* @returns Cache key. * @returns Cache key.
*/ */
getEntriesByCategoryCacheKey(glossaryId: number, categoryId: number): string { getEntriesByCategoryCacheKey(glossaryId: number): string {
return ROOT_CACHE_KEY + 'entriesByCategory:' + glossaryId + ':' + categoryId; const prefix = `${AddonModGlossaryProvider.ROOT_CACHE_KEY}entriesByCategory`;
return `${prefix}:${glossaryId}:${AddonModGlossaryProvider.SHOW_ALL_CATEGORIES}`;
} }
/** /**
@ -242,11 +215,10 @@ export class AddonModGlossaryProvider {
* *
* @param glossaryId Glossary Id. * @param glossaryId Glossary Id.
* @param order The way to order the records. * @param order The way to order the records.
* @param sort The direction of the order.
* @returns Cache key. * @returns Cache key.
*/ */
getEntriesByDateCacheKey(glossaryId: number, order: string, sort: string): string { getEntriesByDateCacheKey(glossaryId: number, order: string): string {
return ROOT_CACHE_KEY + 'entriesByDate:' + glossaryId + ':' + order + ':' + sort; return `${AddonModGlossaryProvider.ROOT_CACHE_KEY}entriesByDate:${glossaryId}:${order}:DESC`;
} }
/** /**
@ -254,14 +226,12 @@ export class AddonModGlossaryProvider {
* *
* @param glossaryId Glossary Id. * @param glossaryId Glossary Id.
* @param order The way to order the records. * @param order The way to order the records.
* @param sort The direction of the order.
* @param options Other options. * @param options Other options.
* @returns Resolved with the entries. * @returns Resolved with the entries.
*/ */
async getEntriesByDate( async getEntriesByDate(
glossaryId: number, glossaryId: number,
order: string, order: string,
sort: string,
options: AddonModGlossaryGetEntriesOptions = {}, options: AddonModGlossaryGetEntriesOptions = {},
): Promise<AddonModGlossaryGetEntriesWSResponse> { ): Promise<AddonModGlossaryGetEntriesWSResponse> {
const site = await CoreSites.getSite(options.siteId); const site = await CoreSites.getSite(options.siteId);
@ -269,12 +239,12 @@ export class AddonModGlossaryProvider {
const params: AddonModGlossaryGetEntriesByDateWSParams = { const params: AddonModGlossaryGetEntriesByDateWSParams = {
id: glossaryId, id: glossaryId,
order: order, order: order,
sort: sort, sort: 'DESC',
from: options.from || 0, from: options.from || 0,
limit: options.limit || AddonModGlossaryProvider.LIMIT_ENTRIES, limit: options.limit || AddonModGlossaryProvider.LIMIT_ENTRIES,
}; };
const preSets: CoreSiteWSPreSets = { const preSets: CoreSiteWSPreSets = {
cacheKey: this.getEntriesByDateCacheKey(glossaryId, order, sort), cacheKey: this.getEntriesByDateCacheKey(glossaryId, order),
updateFrequency: CoreSite.FREQUENCY_SOMETIMES, updateFrequency: CoreSite.FREQUENCY_SOMETIMES,
component: AddonModGlossaryProvider.COMPONENT, component: AddonModGlossaryProvider.COMPONENT,
componentId: options.cmId, componentId: options.cmId,
@ -289,14 +259,12 @@ export class AddonModGlossaryProvider {
* *
* @param glossaryId Glossary Id. * @param glossaryId Glossary Id.
* @param order The way to order the records. * @param order The way to order the records.
* @param sort The direction of the order.
* @param siteId Site ID. If not defined, current site. * @param siteId Site ID. If not defined, current site.
* @returns Resolved when data is invalidated.
*/ */
async invalidateEntriesByDate(glossaryId: number, order: string, sort: string, siteId?: string): Promise<void> { async invalidateEntriesByDate(glossaryId: number, order: string, siteId?: string): Promise<void> {
const site = await CoreSites.getSite(siteId); const site = await CoreSites.getSite(siteId);
const key = this.getEntriesByDateCacheKey(glossaryId, order, sort); const key = this.getEntriesByDateCacheKey(glossaryId, order);
await site.invalidateWsCacheForKey(key); await site.invalidateWsCacheForKey(key);
} }
@ -305,24 +273,21 @@ export class AddonModGlossaryProvider {
* Get the entries by letter cache key. * Get the entries by letter cache key.
* *
* @param glossaryId Glossary Id. * @param glossaryId Glossary Id.
* @param letter A letter, or a special keyword.
* @returns Cache key. * @returns Cache key.
*/ */
protected getEntriesByLetterCacheKey(glossaryId: number, letter: string): string { protected getEntriesByLetterCacheKey(glossaryId: number): string {
return ROOT_CACHE_KEY + 'entriesByLetter:' + glossaryId + ':' + letter; return `${AddonModGlossaryProvider.ROOT_CACHE_KEY}entriesByLetter:${glossaryId}:ALL`;
} }
/** /**
* Get entries by letter. * Get entries by letter.
* *
* @param glossaryId Glossary Id. * @param glossaryId Glossary Id.
* @param letter A letter, or a special keyword.
* @param options Other options. * @param options Other options.
* @returns Resolved with the entries. * @returns Resolved with the entries.
*/ */
async getEntriesByLetter( async getEntriesByLetter(
glossaryId: number, glossaryId: number,
letter: string,
options: AddonModGlossaryGetEntriesOptions = {}, options: AddonModGlossaryGetEntriesOptions = {},
): Promise<AddonModGlossaryGetEntriesWSResponse> { ): Promise<AddonModGlossaryGetEntriesWSResponse> {
options.from = options.from || 0; options.from = options.from || 0;
@ -332,12 +297,12 @@ export class AddonModGlossaryProvider {
const params: AddonModGlossaryGetEntriesByLetterWSParams = { const params: AddonModGlossaryGetEntriesByLetterWSParams = {
id: glossaryId, id: glossaryId,
letter: letter, letter: 'ALL',
from: options.from, from: options.from,
limit: options.limit, limit: options.limit,
}; };
const preSets: CoreSiteWSPreSets = { const preSets: CoreSiteWSPreSets = {
cacheKey: this.getEntriesByLetterCacheKey(glossaryId, letter), cacheKey: this.getEntriesByLetterCacheKey(glossaryId),
updateFrequency: CoreSite.FREQUENCY_SOMETIMES, updateFrequency: CoreSite.FREQUENCY_SOMETIMES,
component: AddonModGlossaryProvider.COMPONENT, component: AddonModGlossaryProvider.COMPONENT,
componentId: options.cmId, componentId: options.cmId,
@ -362,16 +327,14 @@ export class AddonModGlossaryProvider {
* Invalidate cache of entries by letter. * Invalidate cache of entries by letter.
* *
* @param glossaryId Glossary Id. * @param glossaryId Glossary Id.
* @param letter A letter, or a special keyword.
* @param siteId Site ID. If not defined, current site. * @param siteId Site ID. If not defined, current site.
* @returns Resolved when data is invalidated.
*/ */
async invalidateEntriesByLetter(glossaryId: number, letter: string, siteId?: string): Promise<void> { async invalidateEntriesByLetter(glossaryId: number, siteId?: string): Promise<void> {
const site = await CoreSites.getSite(siteId); const site = await CoreSites.getSite(siteId);
const key = this.getEntriesByLetterCacheKey(glossaryId, letter); const key = this.getEntriesByLetterCacheKey(glossaryId);
return site.invalidateWsCacheForKey(key); await site.invalidateWsCacheForKey(key);
} }
/** /**
@ -380,18 +343,10 @@ export class AddonModGlossaryProvider {
* @param glossaryId Glossary Id. * @param glossaryId Glossary Id.
* @param query The search query. * @param query The search query.
* @param fullSearch Whether or not full search is required. * @param fullSearch Whether or not full search is required.
* @param order The way to order the results.
* @param sort The direction of the order.
* @returns Cache key. * @returns Cache key.
*/ */
protected getEntriesBySearchCacheKey( protected getEntriesBySearchCacheKey(glossaryId: number, query: string, fullSearch: boolean): string {
glossaryId: number, return `${AddonModGlossaryProvider.ROOT_CACHE_KEY}entriesBySearch:${glossaryId}:${fullSearch}:CONCEPT:ASC:${query}`;
query: string,
fullSearch: boolean,
order: string,
sort: string,
): string {
return ROOT_CACHE_KEY + 'entriesBySearch:' + glossaryId + ':' + fullSearch + ':' + order + ':' + sort + ':' + query;
} }
/** /**
@ -400,8 +355,6 @@ export class AddonModGlossaryProvider {
* @param glossaryId Glossary Id. * @param glossaryId Glossary Id.
* @param query The search query. * @param query The search query.
* @param fullSearch Whether or not full search is required. * @param fullSearch Whether or not full search is required.
* @param order The way to order the results.
* @param sort The direction of the order.
* @param options Get entries options. * @param options Get entries options.
* @returns Resolved with the entries. * @returns Resolved with the entries.
*/ */
@ -409,8 +362,6 @@ export class AddonModGlossaryProvider {
glossaryId: number, glossaryId: number,
query: string, query: string,
fullSearch: boolean, fullSearch: boolean,
order: string,
sort: string,
options: AddonModGlossaryGetEntriesOptions = {}, options: AddonModGlossaryGetEntriesOptions = {},
): Promise<AddonModGlossaryGetEntriesWSResponse> { ): Promise<AddonModGlossaryGetEntriesWSResponse> {
const site = await CoreSites.getSite(options.siteId); const site = await CoreSites.getSite(options.siteId);
@ -419,13 +370,13 @@ export class AddonModGlossaryProvider {
id: glossaryId, id: glossaryId,
query: query, query: query,
fullsearch: fullSearch, fullsearch: fullSearch,
order: order, order: 'CONCEPT',
sort: sort, sort: 'ASC',
from: options.from || 0, from: options.from || 0,
limit: options.limit || AddonModGlossaryProvider.LIMIT_ENTRIES, limit: options.limit || AddonModGlossaryProvider.LIMIT_ENTRIES,
}; };
const preSets: CoreSiteWSPreSets = { const preSets: CoreSiteWSPreSets = {
cacheKey: this.getEntriesBySearchCacheKey(glossaryId, query, fullSearch, order, sort), cacheKey: this.getEntriesBySearchCacheKey(glossaryId, query, fullSearch),
updateFrequency: CoreSite.FREQUENCY_SOMETIMES, updateFrequency: CoreSite.FREQUENCY_SOMETIMES,
component: AddonModGlossaryProvider.COMPONENT, component: AddonModGlossaryProvider.COMPONENT,
componentId: options.cmId, componentId: options.cmId,
@ -441,22 +392,17 @@ export class AddonModGlossaryProvider {
* @param glossaryId Glossary Id. * @param glossaryId Glossary Id.
* @param query The search query. * @param query The search query.
* @param fullSearch Whether or not full search is required. * @param fullSearch Whether or not full search is required.
* @param order The way to order the results.
* @param sort The direction of the order.
* @param siteId Site ID. If not defined, current site. * @param siteId Site ID. If not defined, current site.
* @returns Resolved when data is invalidated.
*/ */
async invalidateEntriesBySearch( async invalidateEntriesBySearch(
glossaryId: number, glossaryId: number,
query: string, query: string,
fullSearch: boolean, fullSearch: boolean,
order: string,
sort: string,
siteId?: string, siteId?: string,
): Promise<void> { ): Promise<void> {
const site = await CoreSites.getSite(siteId); const site = await CoreSites.getSite(siteId);
const key = this.getEntriesBySearchCacheKey(glossaryId, query, fullSearch, order, sort); const key = this.getEntriesBySearchCacheKey(glossaryId, query, fullSearch);
await site.invalidateWsCacheForKey(key); await site.invalidateWsCacheForKey(key);
} }
@ -468,7 +414,7 @@ export class AddonModGlossaryProvider {
* @returns The cache key. * @returns The cache key.
*/ */
protected getCategoriesCacheKey(glossaryId: number): string { protected getCategoriesCacheKey(glossaryId: number): string {
return ROOT_CACHE_KEY + 'categories:' + glossaryId; return AddonModGlossaryProvider.ROOT_CACHE_KEY + 'categories:' + glossaryId;
} }
/** /**
@ -533,7 +479,6 @@ export class AddonModGlossaryProvider {
* *
* @param glossaryId Glossary Id. * @param glossaryId Glossary Id.
* @param siteId Site ID. If not defined, current site. * @param siteId Site ID. If not defined, current site.
* @returns Promise resolved when categories data has been invalidated,
*/ */
async invalidateCategories(glossaryId: number, siteId?: string): Promise<void> { async invalidateCategories(glossaryId: number, siteId?: string): Promise<void> {
const site = await CoreSites.getSite(siteId); const site = await CoreSites.getSite(siteId);
@ -548,7 +493,7 @@ export class AddonModGlossaryProvider {
* @returns Cache key. * @returns Cache key.
*/ */
protected getEntryCacheKey(entryId: number): string { protected getEntryCacheKey(entryId: number): string {
return ROOT_CACHE_KEY + 'getEntry:' + entryId; return `${AddonModGlossaryProvider.ROOT_CACHE_KEY}getEntry:${entryId}`;
} }
/** /**
@ -637,7 +582,7 @@ export class AddonModGlossaryProvider {
options: CoreCourseCommonModWSOptions = {}, options: CoreCourseCommonModWSOptions = {},
): Promise<AddonModGlossaryGetEntryByIdResponse> { ): Promise<AddonModGlossaryGetEntryByIdResponse> {
// Get the entries from this "page" and check if the entry we're looking for is in it. // Get the entries from this "page" and check if the entry we're looking for is in it.
const result = await this.getEntriesByLetter(glossaryId, 'ALL', { const result = await this.getEntriesByLetter(glossaryId, {
from: from, from: from,
readingStrategy: CoreSitesReadingStrategy.ONLY_CACHE, readingStrategy: CoreSitesReadingStrategy.ONLY_CACHE,
cmId: options.cmId, cmId: options.cmId,
@ -695,7 +640,6 @@ export class AddonModGlossaryProvider {
* *
* @param entryId Entry Id. * @param entryId Entry Id.
* @param siteId Site ID. If not defined, current site. * @param siteId Site ID. If not defined, current site.
* @returns Resolved when data is invalidated.
*/ */
async invalidateEntry(entryId: number, siteId?: string): Promise<void> { async invalidateEntry(entryId: number, siteId?: string): Promise<void> {
const site = await CoreSites.getSite(siteId); const site = await CoreSites.getSite(siteId);
@ -708,7 +652,6 @@ export class AddonModGlossaryProvider {
* *
* @param entries Entry objects to invalidate. * @param entries Entry objects to invalidate.
* @param siteId Site ID. If not defined, current site. * @param siteId Site ID. If not defined, current site.
* @returns Resolved when data is invalidated.
*/ */
protected async invalidateEntries(entries: AddonModGlossaryEntry[], siteId?: string): Promise<void> { protected async invalidateEntries(entries: AddonModGlossaryEntry[], siteId?: string): Promise<void> {
const keys: string[] = []; const keys: string[] = [];
@ -727,7 +670,6 @@ export class AddonModGlossaryProvider {
* *
* @param moduleId The module ID. * @param moduleId The module ID.
* @param courseId Course ID. * @param courseId Course ID.
* @returns Promise resolved when data is invalidated.
*/ */
async invalidateContent(moduleId: number, courseId: number): Promise<void> { async invalidateContent(moduleId: number, courseId: number): Promise<void> {
const glossary = await this.getGlossary(courseId, moduleId); const glossary = await this.getGlossary(courseId, moduleId);
@ -747,7 +689,6 @@ export class AddonModGlossaryProvider {
* @param glossary The glossary object. * @param glossary The glossary object.
* @param onlyEntriesList If true, entries won't be invalidated. * @param onlyEntriesList If true, entries won't be invalidated.
* @param siteId Site ID. If not defined, current site. * @param siteId Site ID. If not defined, current site.
* @returns Promise resolved when data is invalidated.
*/ */
async invalidateGlossaryEntries(glossary: AddonModGlossaryGlossary, onlyEntriesList?: boolean, siteId?: string): Promise<void> { async invalidateGlossaryEntries(glossary: AddonModGlossaryGlossary, onlyEntriesList?: boolean, siteId?: string): Promise<void> {
siteId = siteId || CoreSites.getCurrentSiteId(); siteId = siteId || CoreSites.getCurrentSiteId();
@ -755,7 +696,7 @@ export class AddonModGlossaryProvider {
const promises: Promise<void>[] = []; const promises: Promise<void>[] = [];
if (!onlyEntriesList) { if (!onlyEntriesList) {
promises.push(this.fetchAllEntries((options) => this.getEntriesByLetter(glossary.id, 'ALL', options), { promises.push(this.fetchAllEntries((options) => this.getEntriesByLetter(glossary.id, options), {
cmId: glossary.coursemodule, cmId: glossary.coursemodule,
readingStrategy: CoreSitesReadingStrategy.PREFER_CACHE, readingStrategy: CoreSitesReadingStrategy.PREFER_CACHE,
siteId, siteId,
@ -765,21 +706,17 @@ export class AddonModGlossaryProvider {
glossary.browsemodes.forEach((mode) => { glossary.browsemodes.forEach((mode) => {
switch (mode) { switch (mode) {
case 'letter': case 'letter':
promises.push(this.invalidateEntriesByLetter(glossary.id, 'ALL', siteId)); promises.push(this.invalidateEntriesByLetter(glossary.id, siteId));
break; break;
case 'cat': case 'cat':
promises.push(this.invalidateEntriesByCategory( promises.push(this.invalidateEntriesByCategory(glossary.id, siteId));
glossary.id,
AddonModGlossaryProvider.SHOW_ALL_CATEGORIES,
siteId,
));
break; break;
case 'date': case 'date':
promises.push(this.invalidateEntriesByDate(glossary.id, 'CREATION', 'DESC', siteId)); promises.push(this.invalidateEntriesByDate(glossary.id, 'CREATION', siteId));
promises.push(this.invalidateEntriesByDate(glossary.id, 'UPDATE', 'DESC', siteId)); promises.push(this.invalidateEntriesByDate(glossary.id, 'UPDATE', siteId));
break; break;
case 'author': case 'author':
promises.push(this.invalidateEntriesByAuthor(glossary.id, 'ALL', 'LASTNAME', 'ASC', siteId)); promises.push(this.invalidateEntriesByAuthor(glossary.id, siteId));
break; break;
default: default:
} }
@ -959,7 +896,7 @@ export class AddonModGlossaryProvider {
}; };
if (attachId) { if (attachId) {
params.options!.push({ params.options?.push({
name: 'attachmentsid', name: 'attachmentsid',
value: String(attachId), value: String(attachId),
}); });
@ -989,7 +926,7 @@ export class AddonModGlossaryProvider {
// If we get here, there's no offline entry with this name, check online. // If we get here, there's no offline entry with this name, check online.
// Get entries from the cache. // Get entries from the cache.
const entries = await this.fetchAllEntries((options) => this.getEntriesByLetter(glossaryId, 'ALL', options), { const entries = await this.fetchAllEntries((options) => this.getEntriesByLetter(glossaryId, options), {
cmId: options.cmId, cmId: options.cmId,
readingStrategy: CoreSitesReadingStrategy.PREFER_CACHE, readingStrategy: CoreSitesReadingStrategy.PREFER_CACHE,
siteId: options.siteId, siteId: options.siteId,
@ -1010,15 +947,14 @@ export class AddonModGlossaryProvider {
* @param mode The mode in which the glossary was viewed. * @param mode The mode in which the glossary was viewed.
* @param name Name of the glossary. * @param name Name of the glossary.
* @param siteId Site ID. If not defined, current site. * @param siteId Site ID. If not defined, current site.
* @returns Promise resolved when the WS call is successful.
*/ */
logView(glossaryId: number, mode: string, name?: string, siteId?: string): Promise<void> { async logView(glossaryId: number, mode: string, name?: string, siteId?: string): Promise<void> {
const params: AddonModGlossaryViewGlossaryWSParams = { const params: AddonModGlossaryViewGlossaryWSParams = {
id: glossaryId, id: glossaryId,
mode: mode, mode: mode,
}; };
return CoreCourseLogHelper.logSingle( await CoreCourseLogHelper.logSingle(
'mod_glossary_view_glossary', 'mod_glossary_view_glossary',
params, params,
AddonModGlossaryProvider.COMPONENT, AddonModGlossaryProvider.COMPONENT,
@ -1037,14 +973,13 @@ export class AddonModGlossaryProvider {
* @param glossaryId Glossary ID. * @param glossaryId Glossary ID.
* @param name Name of the glossary. * @param name Name of the glossary.
* @param siteId Site ID. If not defined, current site. * @param siteId Site ID. If not defined, current site.
* @returns Promise resolved when the WS call is successful.
*/ */
logEntryView(entryId: number, glossaryId: number, name?: string, siteId?: string): Promise<void> { async logEntryView(entryId: number, glossaryId: number, name?: string, siteId?: string): Promise<void> {
const params: AddonModGlossaryViewEntryWSParams = { const params: AddonModGlossaryViewEntryWSParams = {
id: entryId, id: entryId,
}; };
return CoreCourseLogHelper.logSingle( await CoreCourseLogHelper.logSingle(
'mod_glossary_view_entry', 'mod_glossary_view_entry',
params, params,
AddonModGlossaryProvider.COMPONENT, AddonModGlossaryProvider.COMPONENT,
@ -1063,7 +998,6 @@ export class AddonModGlossaryProvider {
* @param entries Entries. * @param entries Entries.
* @param from The "page" the entries belong to. * @param from The "page" the entries belong to.
* @param siteId Site ID. If not defined, current site. * @param siteId Site ID. If not defined, current site.
* @returns Promise resolved when done.
*/ */
protected async storeEntries( protected async storeEntries(
glossaryId: number, glossaryId: number,
@ -1081,7 +1015,6 @@ export class AddonModGlossaryProvider {
* @param entryId Entry ID. * @param entryId Entry ID.
* @param from The "page" the entry belongs to. * @param from The "page" the entry belongs to.
* @param siteId Site ID. If not defined, current site. * @param siteId Site ID. If not defined, current site.
* @returns Promise resolved when done.
*/ */
protected async storeEntryId(glossaryId: number, entryId: number, from: number, siteId?: string): Promise<void> { protected async storeEntryId(glossaryId: number, entryId: number, from: number, siteId?: string): Promise<void> {
const site = await CoreSites.getSite(siteId); const site = await CoreSites.getSite(siteId);

View File

@ -45,7 +45,7 @@ export class AddonModGlossaryPrefetchHandlerService extends CoreCourseActivityPr
const glossary = await AddonModGlossary.getGlossary(courseId, module.id); const glossary = await AddonModGlossary.getGlossary(courseId, module.id);
const entries = await AddonModGlossary.fetchAllEntries( const entries = await AddonModGlossary.fetchAllEntries(
(options) => AddonModGlossary.getEntriesByLetter(glossary.id, 'ALL', options), (options) => AddonModGlossary.getEntriesByLetter(glossary.id, options),
{ {
cmId: module.id, cmId: module.id,
}, },
@ -125,43 +125,23 @@ export class AddonModGlossaryPrefetchHandlerService extends CoreCourseActivityPr
break; break;
case 'cat': case 'cat':
promises.push(AddonModGlossary.fetchAllEntries( promises.push(AddonModGlossary.fetchAllEntries(
(newOptions) => AddonModGlossary.getEntriesByCategory( (newOptions) => AddonModGlossary.getEntriesByCategory(glossary.id, newOptions),
glossary.id,
AddonModGlossaryProvider.SHOW_ALL_CATEGORIES,
newOptions,
),
options, options,
)); ));
break; break;
case 'date': case 'date':
promises.push(AddonModGlossary.fetchAllEntries( promises.push(AddonModGlossary.fetchAllEntries(
(newOptions) => AddonModGlossary.getEntriesByDate( (newOptions) => AddonModGlossary.getEntriesByDate(glossary.id, 'CREATION', newOptions),
glossary.id,
'CREATION',
'DESC',
newOptions,
),
options, options,
)); ));
promises.push(AddonModGlossary.fetchAllEntries( promises.push(AddonModGlossary.fetchAllEntries(
(newOptions) => AddonModGlossary.getEntriesByDate( (newOptions) => AddonModGlossary.getEntriesByDate(glossary.id, 'UPDATE', newOptions),
glossary.id,
'UPDATE',
'DESC',
newOptions,
),
options, options,
)); ));
break; break;
case 'author': case 'author':
promises.push(AddonModGlossary.fetchAllEntries( promises.push(AddonModGlossary.fetchAllEntries(
(newOptions) => AddonModGlossary.getEntriesByAuthor( (newOptions) => AddonModGlossary.getEntriesByAuthor(glossary.id, newOptions),
glossary.id,
'ALL',
'LASTNAME',
'ASC',
newOptions,
),
options, options,
)); ));
break; break;
@ -171,7 +151,7 @@ export class AddonModGlossaryPrefetchHandlerService extends CoreCourseActivityPr
// Fetch all entries to get information from. // Fetch all entries to get information from.
promises.push(AddonModGlossary.fetchAllEntries( promises.push(AddonModGlossary.fetchAllEntries(
(newOptions) => AddonModGlossary.getEntriesByLetter(glossary.id, 'ALL', newOptions), (newOptions) => AddonModGlossary.getEntriesByLetter(glossary.id, newOptions),
options, options,
).then((entries) => { ).then((entries) => {
const promises: Promise<unknown>[] = []; const promises: Promise<unknown>[] = [];

View File

@ -6,6 +6,7 @@ information provided here is intended especially for developers.
- CoreIconComponent has been removed after deprecation period: Use CoreFaIconDirective instead. - CoreIconComponent has been removed after deprecation period: Use CoreFaIconDirective instead.
- The courseSummaryComponent property has been removed from the CoreCourseFormatComponent component, and the getCourseSummaryComponent method from the CoreCourseFormatHandler interface. - The courseSummaryComponent property has been removed from the CoreCourseFormatComponent component, and the getCourseSummaryComponent method from the CoreCourseFormatHandler interface.
- Font Awesome icon library has been updated to 6.3.0. - Font Awesome icon library has been updated to 6.3.0.
- Some methods in AddonModGlossaryProvider have changed their signatures to remove unused parameters.
=== 4.1.0 === === 4.1.0 ===