MOBILE-3817 core: Implement more observable funcs for myoverview
parent
c9a0b372a9
commit
88297ed400
|
@ -1890,16 +1890,28 @@ export class CoreSite {
|
||||||
getConfig(name?: undefined, ignoreCache?: boolean): Promise<CoreSiteConfig>;
|
getConfig(name?: undefined, ignoreCache?: boolean): Promise<CoreSiteConfig>;
|
||||||
getConfig(name: string, ignoreCache?: boolean): Promise<string>;
|
getConfig(name: string, ignoreCache?: boolean): Promise<string>;
|
||||||
getConfig(name?: string, ignoreCache?: boolean): Promise<string | CoreSiteConfig> {
|
getConfig(name?: string, ignoreCache?: boolean): Promise<string | CoreSiteConfig> {
|
||||||
const preSets: CoreSiteWSPreSets = {
|
return firstValueFrom(
|
||||||
cacheKey: this.getConfigCacheKey(),
|
this.getConfigObservable(<string> name, ignoreCache ? CoreSitesReadingStrategy.ONLY_NETWORK : undefined),
|
||||||
};
|
);
|
||||||
|
|
||||||
if (ignoreCache) {
|
|
||||||
preSets.getFromCache = false;
|
|
||||||
preSets.emergencyCache = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.read('tool_mobile_get_config', {}, preSets).then((config: CoreSiteConfigResponse) => {
|
/**
|
||||||
|
* Get the config of this site.
|
||||||
|
* It is recommended to use getStoredConfig instead since it's faster and doesn't use network.
|
||||||
|
*
|
||||||
|
* @param name Name of the setting to get. If not set or false, all settings will be returned.
|
||||||
|
* @param readingStrategy Reading strategy.
|
||||||
|
* @return Observable returning site config.
|
||||||
|
*/
|
||||||
|
getConfigObservable(name?: undefined, readingStrategy?: CoreSitesReadingStrategy): Observable<CoreSiteConfig>;
|
||||||
|
getConfigObservable(name: string, readingStrategy?: CoreSitesReadingStrategy): Observable<string>;
|
||||||
|
getConfigObservable(name?: string, readingStrategy?: CoreSitesReadingStrategy): Observable<string | CoreSiteConfig> {
|
||||||
|
const preSets: CoreSiteWSPreSets = {
|
||||||
|
cacheKey: this.getConfigCacheKey(),
|
||||||
|
...CoreSites.getReadingStrategyPreSets(readingStrategy),
|
||||||
|
};
|
||||||
|
|
||||||
|
return this.readObservable<CoreSiteConfigResponse>('tool_mobile_get_config', {}, preSets).pipe(map(config => {
|
||||||
if (name) {
|
if (name) {
|
||||||
// Return the requested setting.
|
// Return the requested setting.
|
||||||
for (const x in config.settings) {
|
for (const x in config.settings) {
|
||||||
|
@ -1918,7 +1930,7 @@ export class CoreSite {
|
||||||
|
|
||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -585,7 +585,7 @@ export class CoreCoursesProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get courses matching the given custom field. Only works in online.
|
* Get courses matching the given custom field. By default it will try not to use cache.
|
||||||
*
|
*
|
||||||
* @param customFieldName Custom field name.
|
* @param customFieldName Custom field name.
|
||||||
* @param customFieldValue Custom field value.
|
* @param customFieldValue Custom field value.
|
||||||
|
@ -593,30 +593,49 @@ export class CoreCoursesProvider {
|
||||||
* @return Promise resolved with the list of courses.
|
* @return Promise resolved with the list of courses.
|
||||||
* @since 3.8
|
* @since 3.8
|
||||||
*/
|
*/
|
||||||
async getEnrolledCoursesByCustomField(
|
getEnrolledCoursesByCustomField(
|
||||||
customFieldName: string,
|
customFieldName: string,
|
||||||
customFieldValue: string,
|
customFieldValue: string,
|
||||||
siteId?: string,
|
siteId?: string,
|
||||||
): Promise<CoreCourseSummaryData[]> {
|
): Promise<CoreCourseSummaryData[]> {
|
||||||
const site = await CoreSites.getSite(siteId);
|
return firstValueFrom(this.getEnrolledCoursesByCustomFieldObservable(customFieldName, customFieldValue, {
|
||||||
|
readingStrategy: CoreSitesReadingStrategy.PREFER_NETWORK,
|
||||||
|
siteId,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get courses matching the given custom field.
|
||||||
|
*
|
||||||
|
* @param customFieldName Custom field name.
|
||||||
|
* @param customFieldValue Custom field value.
|
||||||
|
* @param options Common options.
|
||||||
|
* @return Promise resolved with the list of courses.
|
||||||
|
* @since 3.8
|
||||||
|
*/
|
||||||
|
getEnrolledCoursesByCustomFieldObservable(
|
||||||
|
customFieldName: string,
|
||||||
|
customFieldValue: string,
|
||||||
|
options: CoreSitesCommonWSOptions,
|
||||||
|
): Observable<CoreCourseSummaryData[]> {
|
||||||
|
return asyncObservable(async () => {
|
||||||
|
const site = await CoreSites.getSite(options. siteId);
|
||||||
|
|
||||||
const params: CoreCourseGetEnrolledCoursesByTimelineClassificationWSParams = {
|
const params: CoreCourseGetEnrolledCoursesByTimelineClassificationWSParams = {
|
||||||
classification: 'customfield',
|
classification: 'customfield',
|
||||||
customfieldname: customFieldName,
|
customfieldname: customFieldName,
|
||||||
customfieldvalue: customFieldValue,
|
customfieldvalue: customFieldValue,
|
||||||
};
|
};
|
||||||
const preSets: CoreSiteWSPreSets = {
|
const preSets: CoreSiteWSPreSets = {
|
||||||
getFromCache: false,
|
...CoreSites.getReadingStrategyPreSets(options.readingStrategy ?? CoreSitesReadingStrategy.PREFER_NETWORK),
|
||||||
};
|
};
|
||||||
const courses = await site.read<CoreCourseGetEnrolledCoursesByTimelineClassificationWSResponse>(
|
|
||||||
|
return site.readObservable<CoreCourseGetEnrolledCoursesByTimelineClassificationWSResponse>(
|
||||||
'core_course_get_enrolled_courses_by_timeline_classification',
|
'core_course_get_enrolled_courses_by_timeline_classification',
|
||||||
params,
|
params,
|
||||||
preSets,
|
preSets,
|
||||||
);
|
).pipe(map(response => response.courses));
|
||||||
if (courses.courses) {
|
});
|
||||||
return courses.courses;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw Error('WS core_course_get_enrolled_courses_by_timeline_classification failed');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue