MOBILE-2652 glossary: Clean up service class
parent
61809c06c8
commit
7e8e694c63
|
@ -164,21 +164,8 @@ export class AddonModGlossaryEntriesSource extends CoreRoutedItemsManagerSource<
|
|||
|
||||
const glossaryId = this.glossary.id;
|
||||
|
||||
this.fetchFunction = (options) => AddonModGlossary.getEntriesBySearch(
|
||||
glossaryId,
|
||||
query,
|
||||
true,
|
||||
'CONCEPT',
|
||||
'ASC',
|
||||
options,
|
||||
);
|
||||
this.fetchInvalidate = () => AddonModGlossary.invalidateEntriesBySearch(
|
||||
glossaryId,
|
||||
query,
|
||||
true,
|
||||
'CONCEPT',
|
||||
'ASC',
|
||||
);
|
||||
this.fetchFunction = (options) => AddonModGlossary.getEntriesBySearch(glossaryId, query, true, options);
|
||||
this.fetchInvalidate = () => AddonModGlossary.invalidateEntriesBySearch(glossaryId, query, true);
|
||||
this.hasSearched = true;
|
||||
this.setDirty(true);
|
||||
}
|
||||
|
@ -220,65 +207,29 @@ export class AddonModGlossaryEntriesSource extends CoreRoutedItemsManagerSource<
|
|||
case 'author_all':
|
||||
// Browse by author.
|
||||
this.viewMode = 'author';
|
||||
this.fetchFunction = (options) => AddonModGlossary.getEntriesByAuthor(
|
||||
glossaryId,
|
||||
'ALL',
|
||||
'LASTNAME',
|
||||
'ASC',
|
||||
options,
|
||||
);
|
||||
this.fetchInvalidate = () => AddonModGlossary.invalidateEntriesByAuthor(
|
||||
glossaryId,
|
||||
'ALL',
|
||||
'LASTNAME',
|
||||
'ASC',
|
||||
);
|
||||
this.fetchFunction = (options) => AddonModGlossary.getEntriesByAuthor(glossaryId, options);
|
||||
this.fetchInvalidate = () => AddonModGlossary.invalidateEntriesByAuthor(glossaryId);
|
||||
break;
|
||||
|
||||
case 'cat_all':
|
||||
// Browse by category.
|
||||
this.viewMode = 'cat';
|
||||
this.fetchFunction = (options) => AddonModGlossary.getEntriesByCategory(
|
||||
glossaryId,
|
||||
AddonModGlossaryProvider.SHOW_ALL_CATEGORIES,
|
||||
options,
|
||||
);
|
||||
this.fetchInvalidate = () => AddonModGlossary.invalidateEntriesByCategory(
|
||||
glossaryId,
|
||||
AddonModGlossaryProvider.SHOW_ALL_CATEGORIES,
|
||||
);
|
||||
this.fetchFunction = (options) => AddonModGlossary.getEntriesByCategory(glossaryId, options);
|
||||
this.fetchInvalidate = () => AddonModGlossary.invalidateEntriesByCategory(glossaryId);
|
||||
break;
|
||||
|
||||
case 'newest_first':
|
||||
// Newest first.
|
||||
this.viewMode = 'date';
|
||||
this.fetchFunction = (options) => AddonModGlossary.getEntriesByDate(
|
||||
glossaryId,
|
||||
'CREATION',
|
||||
'DESC',
|
||||
options,
|
||||
);
|
||||
this.fetchInvalidate = () => AddonModGlossary.invalidateEntriesByDate(
|
||||
glossaryId,
|
||||
'CREATION',
|
||||
'DESC',
|
||||
);
|
||||
this.fetchFunction = (options) => AddonModGlossary.getEntriesByDate(glossaryId, 'CREATION', options);
|
||||
this.fetchInvalidate = () => AddonModGlossary.invalidateEntriesByDate(glossaryId, 'CREATION');
|
||||
break;
|
||||
|
||||
case 'recently_updated':
|
||||
// Recently updated.
|
||||
this.viewMode = 'date';
|
||||
this.fetchFunction = (options) => AddonModGlossary.getEntriesByDate(
|
||||
glossaryId,
|
||||
'UPDATE',
|
||||
'DESC',
|
||||
options,
|
||||
);
|
||||
this.fetchInvalidate = () => AddonModGlossary.invalidateEntriesByDate(
|
||||
glossaryId,
|
||||
'UPDATE',
|
||||
'DESC',
|
||||
);
|
||||
this.fetchFunction = (options) => AddonModGlossary.getEntriesByDate(glossaryId, 'UPDATE', options);
|
||||
this.fetchInvalidate = () => AddonModGlossary.invalidateEntriesByDate(glossaryId, 'UPDATE');
|
||||
break;
|
||||
|
||||
case 'letter_all':
|
||||
|
@ -286,15 +237,8 @@ export class AddonModGlossaryEntriesSource extends CoreRoutedItemsManagerSource<
|
|||
// Consider it is 'letter_all'.
|
||||
this.viewMode = 'letter';
|
||||
this.fetchMode = 'letter_all';
|
||||
this.fetchFunction = (options) => AddonModGlossary.getEntriesByLetter(
|
||||
glossaryId,
|
||||
'ALL',
|
||||
options,
|
||||
);
|
||||
this.fetchInvalidate = () => AddonModGlossary.invalidateEntriesByLetter(
|
||||
glossaryId,
|
||||
'ALL',
|
||||
);
|
||||
this.fetchFunction = (options) => AddonModGlossary.getEntriesByLetter(glossaryId, options);
|
||||
this.fetchInvalidate = () => AddonModGlossary.invalidateEntriesByLetter(glossaryId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,8 +30,6 @@ import { AddonModGlossaryOffline } from './glossary-offline';
|
|||
import { AddonModGlossaryAutoSyncData, AddonModGlossarySyncProvider } from './glossary-sync';
|
||||
import { CoreFileEntry } from '@services/file-helper';
|
||||
|
||||
const ROOT_CACHE_KEY = 'mmaModGlossary:';
|
||||
|
||||
/**
|
||||
* Service that provides some features for glossaries.
|
||||
*/
|
||||
|
@ -41,11 +39,12 @@ export class AddonModGlossaryProvider {
|
|||
static readonly COMPONENT = 'mmaModGlossary';
|
||||
static readonly LIMIT_ENTRIES = 25;
|
||||
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';
|
||||
|
||||
private static readonly SHOW_ALL_CATEGORIES = 0;
|
||||
private static readonly ROOT_CACHE_KEY = 'mmaModGlossary:';
|
||||
|
||||
/**
|
||||
* Get the course glossary cache key.
|
||||
*
|
||||
|
@ -53,7 +52,7 @@ export class AddonModGlossaryProvider {
|
|||
* @returns Cache key.
|
||||
*/
|
||||
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 siteId Site ID. If not defined, current site.
|
||||
* @returns Resolved when data is invalidated.
|
||||
*/
|
||||
async invalidateCourseGlossaries(courseId: number, siteId?: string): Promise<void> {
|
||||
const site = await CoreSites.getSite(siteId);
|
||||
|
@ -104,44 +102,35 @@ export class AddonModGlossaryProvider {
|
|||
* Get the entries by author cache key.
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
protected getEntriesByAuthorCacheKey(glossaryId: number, letter: string, field: string, sort: string): string {
|
||||
return ROOT_CACHE_KEY + 'entriesByAuthor:' + glossaryId + ':' + letter + ':' + field + ':' + sort;
|
||||
protected getEntriesByAuthorCacheKey(glossaryId: number): string {
|
||||
return `${AddonModGlossaryProvider.ROOT_CACHE_KEY}entriesByAuthor:${glossaryId}:ALL:LASTNAME:ASC`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get entries by author.
|
||||
*
|
||||
* @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.
|
||||
* @returns Resolved with the entries.
|
||||
*/
|
||||
async getEntriesByAuthor(
|
||||
glossaryId: number,
|
||||
letter: string,
|
||||
field: string,
|
||||
sort: string,
|
||||
options: AddonModGlossaryGetEntriesOptions = {},
|
||||
): Promise<AddonModGlossaryGetEntriesWSResponse> {
|
||||
const site = await CoreSites.getSite(options.siteId);
|
||||
|
||||
const params: AddonModGlossaryGetEntriesByAuthorWSParams = {
|
||||
id: glossaryId,
|
||||
letter: letter,
|
||||
field: field,
|
||||
sort: sort,
|
||||
letter: 'ALL',
|
||||
field: 'LASTNAME',
|
||||
sort: 'ASC',
|
||||
from: options.from || 0,
|
||||
limit: options.limit || AddonModGlossaryProvider.LIMIT_ENTRIES,
|
||||
};
|
||||
const preSets: CoreSiteWSPreSets = {
|
||||
cacheKey: this.getEntriesByAuthorCacheKey(glossaryId, letter, field, sort),
|
||||
cacheKey: this.getEntriesByAuthorCacheKey(glossaryId),
|
||||
updateFrequency: CoreSite.FREQUENCY_SOMETIMES,
|
||||
component: AddonModGlossaryProvider.COMPONENT,
|
||||
componentId: options.cmId,
|
||||
|
@ -155,22 +144,12 @@ export class AddonModGlossaryProvider {
|
|||
* Invalidate cache of entries by author.
|
||||
*
|
||||
* @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.
|
||||
* @returns Resolved when data is invalidated.
|
||||
*/
|
||||
async invalidateEntriesByAuthor(
|
||||
glossaryId: number,
|
||||
letter: string,
|
||||
field: string,
|
||||
sort: string,
|
||||
siteId?: string,
|
||||
): Promise<void> {
|
||||
async invalidateEntriesByAuthor(glossaryId: number, siteId?: string): Promise<void> {
|
||||
const site = await CoreSites.getSite(siteId);
|
||||
|
||||
const key = this.getEntriesByAuthorCacheKey(glossaryId, letter, field, sort);
|
||||
const key = this.getEntriesByAuthorCacheKey(glossaryId);
|
||||
|
||||
await site.invalidateWsCacheForKey(key);
|
||||
}
|
||||
|
@ -179,26 +158,23 @@ export class AddonModGlossaryProvider {
|
|||
* Get entries by category.
|
||||
*
|
||||
* @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.
|
||||
* @returns Resolved with the entries.
|
||||
*/
|
||||
async getEntriesByCategory(
|
||||
glossaryId: number,
|
||||
categoryId: number,
|
||||
options: AddonModGlossaryGetEntriesOptions = {},
|
||||
): Promise<AddonModGlossaryGetEntriesByCategoryWSResponse> {
|
||||
const site = await CoreSites.getSite(options.siteId);
|
||||
|
||||
const params: AddonModGlossaryGetEntriesByCategoryWSParams = {
|
||||
id: glossaryId,
|
||||
categoryid: categoryId,
|
||||
categoryid: AddonModGlossaryProvider.SHOW_ALL_CATEGORIES,
|
||||
from: options.from || 0,
|
||||
limit: options.limit || AddonModGlossaryProvider.LIMIT_ENTRIES,
|
||||
};
|
||||
const preSets: CoreSiteWSPreSets = {
|
||||
cacheKey: this.getEntriesByCategoryCacheKey(glossaryId, categoryId),
|
||||
cacheKey: this.getEntriesByCategoryCacheKey(glossaryId),
|
||||
updateFrequency: CoreSite.FREQUENCY_SOMETIMES,
|
||||
component: AddonModGlossaryProvider.COMPONENT,
|
||||
componentId: options.cmId,
|
||||
|
@ -212,15 +188,12 @@ export class AddonModGlossaryProvider {
|
|||
* Invalidate cache of entries by category.
|
||||
*
|
||||
* @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.
|
||||
* @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 key = this.getEntriesByCategoryCacheKey(glossaryId, categoryId);
|
||||
const key = this.getEntriesByCategoryCacheKey(glossaryId);
|
||||
|
||||
await site.invalidateWsCacheForKey(key);
|
||||
}
|
||||
|
@ -229,12 +202,12 @@ export class AddonModGlossaryProvider {
|
|||
* Get the entries by category cache key.
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
getEntriesByCategoryCacheKey(glossaryId: number, categoryId: number): string {
|
||||
return ROOT_CACHE_KEY + 'entriesByCategory:' + glossaryId + ':' + categoryId;
|
||||
getEntriesByCategoryCacheKey(glossaryId: number): string {
|
||||
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 order The way to order the records.
|
||||
* @param sort The direction of the order.
|
||||
* @returns Cache key.
|
||||
*/
|
||||
getEntriesByDateCacheKey(glossaryId: number, order: string, sort: string): string {
|
||||
return ROOT_CACHE_KEY + 'entriesByDate:' + glossaryId + ':' + order + ':' + sort;
|
||||
getEntriesByDateCacheKey(glossaryId: number, order: string): string {
|
||||
return `${AddonModGlossaryProvider.ROOT_CACHE_KEY}entriesByDate:${glossaryId}:${order}:DESC`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -254,14 +226,12 @@ export class AddonModGlossaryProvider {
|
|||
*
|
||||
* @param glossaryId Glossary Id.
|
||||
* @param order The way to order the records.
|
||||
* @param sort The direction of the order.
|
||||
* @param options Other options.
|
||||
* @returns Resolved with the entries.
|
||||
*/
|
||||
async getEntriesByDate(
|
||||
glossaryId: number,
|
||||
order: string,
|
||||
sort: string,
|
||||
options: AddonModGlossaryGetEntriesOptions = {},
|
||||
): Promise<AddonModGlossaryGetEntriesWSResponse> {
|
||||
const site = await CoreSites.getSite(options.siteId);
|
||||
|
@ -269,12 +239,12 @@ export class AddonModGlossaryProvider {
|
|||
const params: AddonModGlossaryGetEntriesByDateWSParams = {
|
||||
id: glossaryId,
|
||||
order: order,
|
||||
sort: sort,
|
||||
sort: 'DESC',
|
||||
from: options.from || 0,
|
||||
limit: options.limit || AddonModGlossaryProvider.LIMIT_ENTRIES,
|
||||
};
|
||||
const preSets: CoreSiteWSPreSets = {
|
||||
cacheKey: this.getEntriesByDateCacheKey(glossaryId, order, sort),
|
||||
cacheKey: this.getEntriesByDateCacheKey(glossaryId, order),
|
||||
updateFrequency: CoreSite.FREQUENCY_SOMETIMES,
|
||||
component: AddonModGlossaryProvider.COMPONENT,
|
||||
componentId: options.cmId,
|
||||
|
@ -289,14 +259,12 @@ export class AddonModGlossaryProvider {
|
|||
*
|
||||
* @param glossaryId Glossary Id.
|
||||
* @param order The way to order the records.
|
||||
* @param sort The direction of the order.
|
||||
* @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 key = this.getEntriesByDateCacheKey(glossaryId, order, sort);
|
||||
const key = this.getEntriesByDateCacheKey(glossaryId, order);
|
||||
|
||||
await site.invalidateWsCacheForKey(key);
|
||||
}
|
||||
|
@ -305,24 +273,21 @@ export class AddonModGlossaryProvider {
|
|||
* Get the entries by letter cache key.
|
||||
*
|
||||
* @param glossaryId Glossary Id.
|
||||
* @param letter A letter, or a special keyword.
|
||||
* @returns Cache key.
|
||||
*/
|
||||
protected getEntriesByLetterCacheKey(glossaryId: number, letter: string): string {
|
||||
return ROOT_CACHE_KEY + 'entriesByLetter:' + glossaryId + ':' + letter;
|
||||
protected getEntriesByLetterCacheKey(glossaryId: number): string {
|
||||
return `${AddonModGlossaryProvider.ROOT_CACHE_KEY}entriesByLetter:${glossaryId}:ALL`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get entries by letter.
|
||||
*
|
||||
* @param glossaryId Glossary Id.
|
||||
* @param letter A letter, or a special keyword.
|
||||
* @param options Other options.
|
||||
* @returns Resolved with the entries.
|
||||
*/
|
||||
async getEntriesByLetter(
|
||||
glossaryId: number,
|
||||
letter: string,
|
||||
options: AddonModGlossaryGetEntriesOptions = {},
|
||||
): Promise<AddonModGlossaryGetEntriesWSResponse> {
|
||||
options.from = options.from || 0;
|
||||
|
@ -332,12 +297,12 @@ export class AddonModGlossaryProvider {
|
|||
|
||||
const params: AddonModGlossaryGetEntriesByLetterWSParams = {
|
||||
id: glossaryId,
|
||||
letter: letter,
|
||||
letter: 'ALL',
|
||||
from: options.from,
|
||||
limit: options.limit,
|
||||
};
|
||||
const preSets: CoreSiteWSPreSets = {
|
||||
cacheKey: this.getEntriesByLetterCacheKey(glossaryId, letter),
|
||||
cacheKey: this.getEntriesByLetterCacheKey(glossaryId),
|
||||
updateFrequency: CoreSite.FREQUENCY_SOMETIMES,
|
||||
component: AddonModGlossaryProvider.COMPONENT,
|
||||
componentId: options.cmId,
|
||||
|
@ -362,16 +327,14 @@ export class AddonModGlossaryProvider {
|
|||
* Invalidate cache of entries by letter.
|
||||
*
|
||||
* @param glossaryId Glossary Id.
|
||||
* @param letter A letter, or a special keyword.
|
||||
* @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 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 query The search query.
|
||||
* @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.
|
||||
*/
|
||||
protected getEntriesBySearchCacheKey(
|
||||
glossaryId: number,
|
||||
query: string,
|
||||
fullSearch: boolean,
|
||||
order: string,
|
||||
sort: string,
|
||||
): string {
|
||||
return ROOT_CACHE_KEY + 'entriesBySearch:' + glossaryId + ':' + fullSearch + ':' + order + ':' + sort + ':' + query;
|
||||
protected getEntriesBySearchCacheKey(glossaryId: number, query: string, fullSearch: boolean): string {
|
||||
return `${AddonModGlossaryProvider.ROOT_CACHE_KEY}entriesBySearch:${glossaryId}:${fullSearch}:CONCEPT:ASC:${query}`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -400,8 +355,6 @@ export class AddonModGlossaryProvider {
|
|||
* @param glossaryId Glossary Id.
|
||||
* @param query The search query.
|
||||
* @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.
|
||||
* @returns Resolved with the entries.
|
||||
*/
|
||||
|
@ -409,8 +362,6 @@ export class AddonModGlossaryProvider {
|
|||
glossaryId: number,
|
||||
query: string,
|
||||
fullSearch: boolean,
|
||||
order: string,
|
||||
sort: string,
|
||||
options: AddonModGlossaryGetEntriesOptions = {},
|
||||
): Promise<AddonModGlossaryGetEntriesWSResponse> {
|
||||
const site = await CoreSites.getSite(options.siteId);
|
||||
|
@ -419,13 +370,13 @@ export class AddonModGlossaryProvider {
|
|||
id: glossaryId,
|
||||
query: query,
|
||||
fullsearch: fullSearch,
|
||||
order: order,
|
||||
sort: sort,
|
||||
order: 'CONCEPT',
|
||||
sort: 'ASC',
|
||||
from: options.from || 0,
|
||||
limit: options.limit || AddonModGlossaryProvider.LIMIT_ENTRIES,
|
||||
};
|
||||
const preSets: CoreSiteWSPreSets = {
|
||||
cacheKey: this.getEntriesBySearchCacheKey(glossaryId, query, fullSearch, order, sort),
|
||||
cacheKey: this.getEntriesBySearchCacheKey(glossaryId, query, fullSearch),
|
||||
updateFrequency: CoreSite.FREQUENCY_SOMETIMES,
|
||||
component: AddonModGlossaryProvider.COMPONENT,
|
||||
componentId: options.cmId,
|
||||
|
@ -441,22 +392,17 @@ export class AddonModGlossaryProvider {
|
|||
* @param glossaryId Glossary Id.
|
||||
* @param query The search query.
|
||||
* @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.
|
||||
* @returns Resolved when data is invalidated.
|
||||
*/
|
||||
async invalidateEntriesBySearch(
|
||||
glossaryId: number,
|
||||
query: string,
|
||||
fullSearch: boolean,
|
||||
order: string,
|
||||
sort: string,
|
||||
siteId?: string,
|
||||
): Promise<void> {
|
||||
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);
|
||||
}
|
||||
|
@ -468,7 +414,7 @@ export class AddonModGlossaryProvider {
|
|||
* @returns The cache key.
|
||||
*/
|
||||
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 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> {
|
||||
const site = await CoreSites.getSite(siteId);
|
||||
|
@ -548,7 +493,7 @@ export class AddonModGlossaryProvider {
|
|||
* @returns Cache key.
|
||||
*/
|
||||
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 = {},
|
||||
): Promise<AddonModGlossaryGetEntryByIdResponse> {
|
||||
// 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,
|
||||
readingStrategy: CoreSitesReadingStrategy.ONLY_CACHE,
|
||||
cmId: options.cmId,
|
||||
|
@ -695,7 +640,6 @@ export class AddonModGlossaryProvider {
|
|||
*
|
||||
* @param entryId Entry Id.
|
||||
* @param siteId Site ID. If not defined, current site.
|
||||
* @returns Resolved when data is invalidated.
|
||||
*/
|
||||
async invalidateEntry(entryId: number, siteId?: string): Promise<void> {
|
||||
const site = await CoreSites.getSite(siteId);
|
||||
|
@ -708,7 +652,6 @@ export class AddonModGlossaryProvider {
|
|||
*
|
||||
* @param entries Entry objects to invalidate.
|
||||
* @param siteId Site ID. If not defined, current site.
|
||||
* @returns Resolved when data is invalidated.
|
||||
*/
|
||||
protected async invalidateEntries(entries: AddonModGlossaryEntry[], siteId?: string): Promise<void> {
|
||||
const keys: string[] = [];
|
||||
|
@ -727,7 +670,6 @@ export class AddonModGlossaryProvider {
|
|||
*
|
||||
* @param moduleId The module ID.
|
||||
* @param courseId Course ID.
|
||||
* @returns Promise resolved when data is invalidated.
|
||||
*/
|
||||
async invalidateContent(moduleId: number, courseId: number): Promise<void> {
|
||||
const glossary = await this.getGlossary(courseId, moduleId);
|
||||
|
@ -747,7 +689,6 @@ export class AddonModGlossaryProvider {
|
|||
* @param glossary The glossary object.
|
||||
* @param onlyEntriesList If true, entries won't be invalidated.
|
||||
* @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> {
|
||||
siteId = siteId || CoreSites.getCurrentSiteId();
|
||||
|
@ -755,7 +696,7 @@ export class AddonModGlossaryProvider {
|
|||
const promises: Promise<void>[] = [];
|
||||
|
||||
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,
|
||||
readingStrategy: CoreSitesReadingStrategy.PREFER_CACHE,
|
||||
siteId,
|
||||
|
@ -765,21 +706,17 @@ export class AddonModGlossaryProvider {
|
|||
glossary.browsemodes.forEach((mode) => {
|
||||
switch (mode) {
|
||||
case 'letter':
|
||||
promises.push(this.invalidateEntriesByLetter(glossary.id, 'ALL', siteId));
|
||||
promises.push(this.invalidateEntriesByLetter(glossary.id, siteId));
|
||||
break;
|
||||
case 'cat':
|
||||
promises.push(this.invalidateEntriesByCategory(
|
||||
glossary.id,
|
||||
AddonModGlossaryProvider.SHOW_ALL_CATEGORIES,
|
||||
siteId,
|
||||
));
|
||||
promises.push(this.invalidateEntriesByCategory(glossary.id, siteId));
|
||||
break;
|
||||
case 'date':
|
||||
promises.push(this.invalidateEntriesByDate(glossary.id, 'CREATION', 'DESC', siteId));
|
||||
promises.push(this.invalidateEntriesByDate(glossary.id, 'UPDATE', 'DESC', siteId));
|
||||
promises.push(this.invalidateEntriesByDate(glossary.id, 'CREATION', siteId));
|
||||
promises.push(this.invalidateEntriesByDate(glossary.id, 'UPDATE', siteId));
|
||||
break;
|
||||
case 'author':
|
||||
promises.push(this.invalidateEntriesByAuthor(glossary.id, 'ALL', 'LASTNAME', 'ASC', siteId));
|
||||
promises.push(this.invalidateEntriesByAuthor(glossary.id, siteId));
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
@ -959,7 +896,7 @@ export class AddonModGlossaryProvider {
|
|||
};
|
||||
|
||||
if (attachId) {
|
||||
params.options!.push({
|
||||
params.options?.push({
|
||||
name: 'attachmentsid',
|
||||
value: String(attachId),
|
||||
});
|
||||
|
@ -989,7 +926,7 @@ export class AddonModGlossaryProvider {
|
|||
|
||||
// If we get here, there's no offline entry with this name, check online.
|
||||
// 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,
|
||||
readingStrategy: CoreSitesReadingStrategy.PREFER_CACHE,
|
||||
siteId: options.siteId,
|
||||
|
@ -1010,15 +947,14 @@ export class AddonModGlossaryProvider {
|
|||
* @param mode The mode in which the glossary was viewed.
|
||||
* @param name Name of the glossary.
|
||||
* @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 = {
|
||||
id: glossaryId,
|
||||
mode: mode,
|
||||
};
|
||||
|
||||
return CoreCourseLogHelper.logSingle(
|
||||
await CoreCourseLogHelper.logSingle(
|
||||
'mod_glossary_view_glossary',
|
||||
params,
|
||||
AddonModGlossaryProvider.COMPONENT,
|
||||
|
@ -1037,14 +973,13 @@ export class AddonModGlossaryProvider {
|
|||
* @param glossaryId Glossary ID.
|
||||
* @param name Name of the glossary.
|
||||
* @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 = {
|
||||
id: entryId,
|
||||
};
|
||||
|
||||
return CoreCourseLogHelper.logSingle(
|
||||
await CoreCourseLogHelper.logSingle(
|
||||
'mod_glossary_view_entry',
|
||||
params,
|
||||
AddonModGlossaryProvider.COMPONENT,
|
||||
|
@ -1063,7 +998,6 @@ export class AddonModGlossaryProvider {
|
|||
* @param entries Entries.
|
||||
* @param from The "page" the entries belong to.
|
||||
* @param siteId Site ID. If not defined, current site.
|
||||
* @returns Promise resolved when done.
|
||||
*/
|
||||
protected async storeEntries(
|
||||
glossaryId: number,
|
||||
|
@ -1081,7 +1015,6 @@ export class AddonModGlossaryProvider {
|
|||
* @param entryId Entry ID.
|
||||
* @param from The "page" the entry belongs to.
|
||||
* @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> {
|
||||
const site = await CoreSites.getSite(siteId);
|
||||
|
|
|
@ -45,7 +45,7 @@ export class AddonModGlossaryPrefetchHandlerService extends CoreCourseActivityPr
|
|||
const glossary = await AddonModGlossary.getGlossary(courseId, module.id);
|
||||
|
||||
const entries = await AddonModGlossary.fetchAllEntries(
|
||||
(options) => AddonModGlossary.getEntriesByLetter(glossary.id, 'ALL', options),
|
||||
(options) => AddonModGlossary.getEntriesByLetter(glossary.id, options),
|
||||
{
|
||||
cmId: module.id,
|
||||
},
|
||||
|
@ -125,43 +125,23 @@ export class AddonModGlossaryPrefetchHandlerService extends CoreCourseActivityPr
|
|||
break;
|
||||
case 'cat':
|
||||
promises.push(AddonModGlossary.fetchAllEntries(
|
||||
(newOptions) => AddonModGlossary.getEntriesByCategory(
|
||||
glossary.id,
|
||||
AddonModGlossaryProvider.SHOW_ALL_CATEGORIES,
|
||||
newOptions,
|
||||
),
|
||||
(newOptions) => AddonModGlossary.getEntriesByCategory(glossary.id, newOptions),
|
||||
options,
|
||||
));
|
||||
break;
|
||||
case 'date':
|
||||
promises.push(AddonModGlossary.fetchAllEntries(
|
||||
(newOptions) => AddonModGlossary.getEntriesByDate(
|
||||
glossary.id,
|
||||
'CREATION',
|
||||
'DESC',
|
||||
newOptions,
|
||||
),
|
||||
(newOptions) => AddonModGlossary.getEntriesByDate(glossary.id, 'CREATION', newOptions),
|
||||
options,
|
||||
));
|
||||
promises.push(AddonModGlossary.fetchAllEntries(
|
||||
(newOptions) => AddonModGlossary.getEntriesByDate(
|
||||
glossary.id,
|
||||
'UPDATE',
|
||||
'DESC',
|
||||
newOptions,
|
||||
),
|
||||
(newOptions) => AddonModGlossary.getEntriesByDate(glossary.id, 'UPDATE', newOptions),
|
||||
options,
|
||||
));
|
||||
break;
|
||||
case 'author':
|
||||
promises.push(AddonModGlossary.fetchAllEntries(
|
||||
(newOptions) => AddonModGlossary.getEntriesByAuthor(
|
||||
glossary.id,
|
||||
'ALL',
|
||||
'LASTNAME',
|
||||
'ASC',
|
||||
newOptions,
|
||||
),
|
||||
(newOptions) => AddonModGlossary.getEntriesByAuthor(glossary.id, newOptions),
|
||||
options,
|
||||
));
|
||||
break;
|
||||
|
@ -171,7 +151,7 @@ export class AddonModGlossaryPrefetchHandlerService extends CoreCourseActivityPr
|
|||
|
||||
// Fetch all entries to get information from.
|
||||
promises.push(AddonModGlossary.fetchAllEntries(
|
||||
(newOptions) => AddonModGlossary.getEntriesByLetter(glossary.id, 'ALL', newOptions),
|
||||
(newOptions) => AddonModGlossary.getEntriesByLetter(glossary.id, newOptions),
|
||||
options,
|
||||
).then((entries) => {
|
||||
const promises: Promise<unknown>[] = [];
|
||||
|
|
|
@ -6,6 +6,7 @@ information provided here is intended especially for developers.
|
|||
- 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.
|
||||
- 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 ===
|
||||
|
||||
|
|
Loading…
Reference in New Issue