forked from EVOgeek/Vmeda.Online
MOBILE-3817 core: Create WSObservable type
parent
979e995166
commit
52a4322f0d
|
@ -17,12 +17,11 @@ import { CoreLogger } from '@singletons/logger';
|
||||||
import { CoreSites, CoreSitesCommonWSOptions } from '@services/sites';
|
import { CoreSites, CoreSitesCommonWSOptions } from '@services/sites';
|
||||||
import { CoreUtils } from '@services/utils/utils';
|
import { CoreUtils } from '@services/utils/utils';
|
||||||
import { CoreCourses } from '@features/courses/services/courses';
|
import { CoreCourses } from '@features/courses/services/courses';
|
||||||
import { CoreSite, CoreSiteWSPreSets } from '@classes/site';
|
import { CoreSite, CoreSiteWSPreSets, WSObservable } from '@classes/site';
|
||||||
import { CoreStatusWithWarningsWSResponse, CoreWSExternalWarning } from '@services/ws';
|
import { CoreStatusWithWarningsWSResponse, CoreWSExternalWarning } from '@services/ws';
|
||||||
import { makeSingleton } from '@singletons';
|
import { makeSingleton } from '@singletons';
|
||||||
import { CoreError } from '@classes/errors/error';
|
import { CoreError } from '@classes/errors/error';
|
||||||
import { asyncObservable, firstValueFrom } from '@/core/utils/rxjs';
|
import { asyncObservable, firstValueFrom } from '@/core/utils/rxjs';
|
||||||
import { Observable } from 'rxjs';
|
|
||||||
import { map } from 'rxjs/operators';
|
import { map } from 'rxjs/operators';
|
||||||
|
|
||||||
const ROOT_CACHE_KEY = 'mmaCourseCompletion:';
|
const ROOT_CACHE_KEY = 'mmaCourseCompletion:';
|
||||||
|
@ -119,7 +118,7 @@ export class AddonCourseCompletionProvider {
|
||||||
getCompletionObservable(
|
getCompletionObservable(
|
||||||
courseId: number,
|
courseId: number,
|
||||||
options: AddonCourseCompletionGetCompletionOptions = {},
|
options: AddonCourseCompletionGetCompletionOptions = {},
|
||||||
): Observable<AddonCourseCompletionCourseCompletionStatus> {
|
): WSObservable<AddonCourseCompletionCourseCompletionStatus> {
|
||||||
return asyncObservable(async () => {
|
return asyncObservable(async () => {
|
||||||
const site = await CoreSites.getSite(options.siteId);
|
const site = await CoreSites.getSite(options.siteId);
|
||||||
|
|
||||||
|
|
|
@ -125,7 +125,7 @@ export class CoreSite {
|
||||||
protected lastAutoLogin = 0;
|
protected lastAutoLogin = 0;
|
||||||
protected offlineDisabled = false;
|
protected offlineDisabled = false;
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
protected ongoingRequests: { [cacheId: string]: Observable<any> } = {};
|
protected ongoingRequests: { [cacheId: string]: WSObservable<any> } = {};
|
||||||
protected requestQueue: RequestQueueItem[] = [];
|
protected requestQueue: RequestQueueItem[] = [];
|
||||||
protected requestQueueTimeout: number | null = null;
|
protected requestQueueTimeout: number | null = null;
|
||||||
protected tokenPluginFileWorks?: boolean;
|
protected tokenPluginFileWorks?: boolean;
|
||||||
|
@ -504,10 +504,10 @@ export class CoreSite {
|
||||||
* @param method WS method to use.
|
* @param method WS method to use.
|
||||||
* @param data Data to send to the WS.
|
* @param data Data to send to the WS.
|
||||||
* @param preSets Extra options.
|
* @param preSets Extra options.
|
||||||
* @return Observable.
|
* @return Observable returning the WS data.
|
||||||
*/
|
*/
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
readObservable<T = unknown>(method: string, data: any, preSets?: CoreSiteWSPreSets): Observable<T> {
|
readObservable<T = unknown>(method: string, data: any, preSets?: CoreSiteWSPreSets): WSObservable<T> {
|
||||||
preSets = preSets || {};
|
preSets = preSets || {};
|
||||||
preSets.getFromCache = preSets.getFromCache ?? true;
|
preSets.getFromCache = preSets.getFromCache ?? true;
|
||||||
preSets.saveToCache = preSets.saveToCache ?? true;
|
preSets.saveToCache = preSets.saveToCache ?? true;
|
||||||
|
@ -535,10 +535,10 @@ export class CoreSite {
|
||||||
* @param method WS method to use.
|
* @param method WS method to use.
|
||||||
* @param data Data to send to the WS.
|
* @param data Data to send to the WS.
|
||||||
* @param preSets Extra options.
|
* @param preSets Extra options.
|
||||||
* @return Observable.
|
* @return Observable returning the WS data.
|
||||||
*/
|
*/
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
writeObservable<T = unknown>(method: string, data: any, preSets?: CoreSiteWSPreSets): Observable<T> {
|
writeObservable<T = unknown>(method: string, data: any, preSets?: CoreSiteWSPreSets): WSObservable<T> {
|
||||||
preSets = preSets || {};
|
preSets = preSets || {};
|
||||||
preSets.getFromCache = preSets.getFromCache ?? false;
|
preSets.getFromCache = preSets.getFromCache ?? false;
|
||||||
preSets.saveToCache = preSets.saveToCache ?? false;
|
preSets.saveToCache = preSets.saveToCache ?? false;
|
||||||
|
@ -566,7 +566,7 @@ export class CoreSite {
|
||||||
* @param method The WebService method to be called.
|
* @param method The WebService method to be called.
|
||||||
* @param data Arguments to pass to the method.
|
* @param data Arguments to pass to the method.
|
||||||
* @param preSets Extra options.
|
* @param preSets Extra options.
|
||||||
* @return Observable
|
* @return Observable returning the WS data.
|
||||||
* @description
|
* @description
|
||||||
*
|
*
|
||||||
* Sends a webservice request to the site. This method will automatically add the
|
* Sends a webservice request to the site. This method will automatically add the
|
||||||
|
@ -576,7 +576,7 @@ export class CoreSite {
|
||||||
* data hasn't expired.
|
* data hasn't expired.
|
||||||
*/
|
*/
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
requestObservable<T = unknown>(method: string, data: any, preSets: CoreSiteWSPreSets): Observable<T> {
|
requestObservable<T = unknown>(method: string, data: any, preSets: CoreSiteWSPreSets): WSObservable<T> {
|
||||||
if (this.isLoggedOut() && !ALLOWED_LOGGEDOUT_WS.includes(method)) {
|
if (this.isLoggedOut() && !ALLOWED_LOGGEDOUT_WS.includes(method)) {
|
||||||
// Site is logged out, it cannot call WebServices.
|
// Site is logged out, it cannot call WebServices.
|
||||||
CoreEvents.trigger(CoreEvents.SESSION_EXPIRED, {}, this.id);
|
CoreEvents.trigger(CoreEvents.SESSION_EXPIRED, {}, this.id);
|
||||||
|
@ -665,14 +665,14 @@ export class CoreSite {
|
||||||
* @param data Arguments to pass to the method.
|
* @param data Arguments to pass to the method.
|
||||||
* @param preSets Extra options related to the site.
|
* @param preSets Extra options related to the site.
|
||||||
* @param wsPreSets Extra options related to the WS call.
|
* @param wsPreSets Extra options related to the WS call.
|
||||||
* @return Observable.
|
* @return Observable returning the WS data.
|
||||||
*/
|
*/
|
||||||
protected performRequest<T = unknown>(
|
protected performRequest<T = unknown>(
|
||||||
method: string,
|
method: string,
|
||||||
data: unknown,
|
data: unknown,
|
||||||
preSets: CoreSiteWSPreSets,
|
preSets: CoreSiteWSPreSets,
|
||||||
wsPreSets: CoreWSPreSets,
|
wsPreSets: CoreWSPreSets,
|
||||||
): Observable<T> {
|
): WSObservable<T> {
|
||||||
const subject = new Subject<T>();
|
const subject = new Subject<T>();
|
||||||
|
|
||||||
const run = async () => {
|
const run = async () => {
|
||||||
|
@ -1903,9 +1903,9 @@ export class CoreSite {
|
||||||
* @param readingStrategy Reading strategy.
|
* @param readingStrategy Reading strategy.
|
||||||
* @return Observable returning site config.
|
* @return Observable returning site config.
|
||||||
*/
|
*/
|
||||||
getConfigObservable(name?: undefined, readingStrategy?: CoreSitesReadingStrategy): Observable<CoreSiteConfig>;
|
getConfigObservable(name?: undefined, readingStrategy?: CoreSitesReadingStrategy): WSObservable<CoreSiteConfig>;
|
||||||
getConfigObservable(name: string, readingStrategy?: CoreSitesReadingStrategy): Observable<string>;
|
getConfigObservable(name: string, readingStrategy?: CoreSitesReadingStrategy): WSObservable<string>;
|
||||||
getConfigObservable(name?: string, readingStrategy?: CoreSitesReadingStrategy): Observable<string | CoreSiteConfig> {
|
getConfigObservable(name?: string, readingStrategy?: CoreSitesReadingStrategy): WSObservable<string | CoreSiteConfig> {
|
||||||
const preSets: CoreSiteWSPreSets = {
|
const preSets: CoreSiteWSPreSets = {
|
||||||
cacheKey: this.getConfigCacheKey(),
|
cacheKey: this.getConfigCacheKey(),
|
||||||
...CoreSites.getReadingStrategyPreSets(readingStrategy),
|
...CoreSites.getReadingStrategyPreSets(readingStrategy),
|
||||||
|
@ -2403,7 +2403,7 @@ export function chainRequests<T, O extends ObservableInput<any>>(
|
||||||
readingStrategy: CoreSitesReadingStrategy | undefined,
|
readingStrategy: CoreSitesReadingStrategy | undefined,
|
||||||
callback: (data: T, readingStrategy?: CoreSitesReadingStrategy) => O,
|
callback: (data: T, readingStrategy?: CoreSitesReadingStrategy) => O,
|
||||||
): OperatorFunction<T, ObservedValueOf<O>> {
|
): OperatorFunction<T, ObservedValueOf<O>> {
|
||||||
return (source: Observable<T>) => new Observable<{ data: T; readingStrategy?: CoreSitesReadingStrategy }>(subscriber => {
|
return (source: WSObservable<T>) => new Observable<{ data: T; readingStrategy?: CoreSitesReadingStrategy }>(subscriber => {
|
||||||
let firstValue = true;
|
let firstValue = true;
|
||||||
let isCompleted = false;
|
let isCompleted = false;
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ import { CoreLogger } from '@singletons/logger';
|
||||||
import { CoreSitesCommonWSOptions, CoreSites, CoreSitesReadingStrategy } from '@services/sites';
|
import { CoreSitesCommonWSOptions, CoreSites, CoreSitesReadingStrategy } from '@services/sites';
|
||||||
import { CoreTimeUtils } from '@services/utils/time';
|
import { CoreTimeUtils } from '@services/utils/time';
|
||||||
import { CoreUtils } from '@services/utils/utils';
|
import { CoreUtils } from '@services/utils/utils';
|
||||||
import { CoreSiteWSPreSets, CoreSite } from '@classes/site';
|
import { CoreSiteWSPreSets, CoreSite, WSObservable } from '@classes/site';
|
||||||
import { CoreConstants } from '@/core/constants';
|
import { CoreConstants } from '@/core/constants';
|
||||||
import { makeSingleton, Translate } from '@singletons';
|
import { makeSingleton, Translate } from '@singletons';
|
||||||
import { CoreStatusWithWarningsWSResponse, CoreWSExternalFile, CoreWSExternalWarning } from '@services/ws';
|
import { CoreStatusWithWarningsWSResponse, CoreWSExternalFile, CoreWSExternalWarning } from '@services/ws';
|
||||||
|
@ -54,7 +54,6 @@ import { CoreDatabaseCachingStrategy } from '@classes/database/database-table-pr
|
||||||
import { SQLiteDB } from '@classes/sqlitedb';
|
import { SQLiteDB } from '@classes/sqlitedb';
|
||||||
import { CorePlatform } from '@services/platform';
|
import { CorePlatform } from '@services/platform';
|
||||||
import { CoreTime } from '@singletons/time';
|
import { CoreTime } from '@singletons/time';
|
||||||
import { Observable } from 'rxjs';
|
|
||||||
import { asyncObservable, firstValueFrom } from '@/core/utils/rxjs';
|
import { asyncObservable, firstValueFrom } from '@/core/utils/rxjs';
|
||||||
import { map } from 'rxjs/operators';
|
import { map } from 'rxjs/operators';
|
||||||
|
|
||||||
|
@ -417,7 +416,7 @@ export class CoreCourseProvider {
|
||||||
* @return Observable that returns the blocks.
|
* @return Observable that returns the blocks.
|
||||||
* @since 3.7
|
* @since 3.7
|
||||||
*/
|
*/
|
||||||
getCourseBlocksObservable(courseId: number, options: CoreSitesCommonWSOptions = {}): Observable<CoreCourseBlock[]> {
|
getCourseBlocksObservable(courseId: number, options: CoreSitesCommonWSOptions = {}): WSObservable<CoreCourseBlock[]> {
|
||||||
return asyncObservable(async () => {
|
return asyncObservable(async () => {
|
||||||
const site = await CoreSites.getSite(options.siteId);
|
const site = await CoreSites.getSite(options.siteId);
|
||||||
|
|
||||||
|
@ -955,7 +954,7 @@ export class CoreCourseProvider {
|
||||||
getSectionsObservable(
|
getSectionsObservable(
|
||||||
courseId: number,
|
courseId: number,
|
||||||
options: CoreCourseGetSectionsOptions = {},
|
options: CoreCourseGetSectionsOptions = {},
|
||||||
): Observable<CoreCourseWSSection[]> {
|
): WSObservable<CoreCourseWSSection[]> {
|
||||||
options.includeStealthModules = options.includeStealthModules ?? true;
|
options.includeStealthModules = options.includeStealthModules ?? true;
|
||||||
|
|
||||||
return asyncObservable(async () => {
|
return asyncObservable(async () => {
|
||||||
|
|
|
@ -26,10 +26,10 @@ import { makeSingleton, Translate } from '@singletons';
|
||||||
import { CoreWSExternalFile } from '@services/ws';
|
import { CoreWSExternalFile } from '@services/ws';
|
||||||
import { AddonCourseCompletion } from '@addons/coursecompletion/services/coursecompletion';
|
import { AddonCourseCompletion } from '@addons/coursecompletion/services/coursecompletion';
|
||||||
import moment from 'moment-timezone';
|
import moment from 'moment-timezone';
|
||||||
import { Observable, of } from 'rxjs';
|
import { of } from 'rxjs';
|
||||||
import { firstValueFrom, zipIncludingComplete } from '@/core/utils/rxjs';
|
import { firstValueFrom, zipIncludingComplete } from '@/core/utils/rxjs';
|
||||||
import { catchError, map } from 'rxjs/operators';
|
import { catchError, map } from 'rxjs/operators';
|
||||||
import { chainRequests } from '@classes/site';
|
import { chainRequests, WSObservable } from '@classes/site';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper to gather some common courses functions.
|
* Helper to gather some common courses functions.
|
||||||
|
@ -134,7 +134,7 @@ export class CoreCoursesHelperProvider {
|
||||||
courses: CoreEnrolledCourseDataWithExtraInfo[],
|
courses: CoreEnrolledCourseDataWithExtraInfo[],
|
||||||
loadCategoryNames: boolean = false,
|
loadCategoryNames: boolean = false,
|
||||||
options: CoreSitesCommonWSOptions = {},
|
options: CoreSitesCommonWSOptions = {},
|
||||||
): Observable<CoreEnrolledCourseDataWithExtraInfo[]> {
|
): WSObservable<CoreEnrolledCourseDataWithExtraInfo[]> {
|
||||||
if (!courses.length) {
|
if (!courses.length) {
|
||||||
return of([]);
|
return of([]);
|
||||||
}
|
}
|
||||||
|
@ -245,7 +245,7 @@ export class CoreCoursesHelperProvider {
|
||||||
*/
|
*/
|
||||||
getUserCoursesWithOptionsObservable(
|
getUserCoursesWithOptionsObservable(
|
||||||
options: CoreCoursesGetWithOptionsOptions = {},
|
options: CoreCoursesGetWithOptionsOptions = {},
|
||||||
): Observable<CoreEnrolledCourseDataWithExtraInfoAndOptions[]> {
|
): WSObservable<CoreEnrolledCourseDataWithExtraInfoAndOptions[]> {
|
||||||
|
|
||||||
return CoreCourses.getUserCoursesObservable(options).pipe(
|
return CoreCourses.getUserCoursesObservable(options).pipe(
|
||||||
chainRequests(options.readingStrategy, (courses, newReadingStrategy) => {
|
chainRequests(options.readingStrategy, (courses, newReadingStrategy) => {
|
||||||
|
@ -338,7 +338,7 @@ export class CoreCoursesHelperProvider {
|
||||||
protected loadCourseCompletedStatus(
|
protected loadCourseCompletedStatus(
|
||||||
course: CoreEnrolledCourseDataWithExtraInfo,
|
course: CoreEnrolledCourseDataWithExtraInfo,
|
||||||
options: CoreSitesCommonWSOptions = {},
|
options: CoreSitesCommonWSOptions = {},
|
||||||
): Observable<CoreEnrolledCourseDataWithExtraInfo> {
|
): WSObservable<CoreEnrolledCourseDataWithExtraInfo> {
|
||||||
if (course.completed !== undefined) {
|
if (course.completed !== undefined) {
|
||||||
// The WebService already returns the completed status, no need to fetch it.
|
// The WebService already returns the completed status, no need to fetch it.
|
||||||
return of(course);
|
return of(course);
|
||||||
|
|
|
@ -14,14 +14,14 @@
|
||||||
|
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { CoreSites, CoreSitesCommonWSOptions, CoreSitesReadingStrategy } from '@services/sites';
|
import { CoreSites, CoreSitesCommonWSOptions, CoreSitesReadingStrategy } from '@services/sites';
|
||||||
import { CoreSite, CoreSiteWSPreSets } from '@classes/site';
|
import { CoreSite, CoreSiteWSPreSets, WSObservable } from '@classes/site';
|
||||||
import { makeSingleton } from '@singletons';
|
import { makeSingleton } from '@singletons';
|
||||||
import { CoreStatusWithWarningsWSResponse, CoreWarningsWSResponse, CoreWSExternalFile, CoreWSExternalWarning } from '@services/ws';
|
import { CoreStatusWithWarningsWSResponse, CoreWarningsWSResponse, CoreWSExternalFile, CoreWSExternalWarning } from '@services/ws';
|
||||||
import { CoreEvents } from '@singletons/events';
|
import { CoreEvents } from '@singletons/events';
|
||||||
import { CoreWSError } from '@classes/errors/wserror';
|
import { CoreWSError } from '@classes/errors/wserror';
|
||||||
import { CoreCourseAnyCourseDataWithExtraInfoAndOptions, CoreCourseWithImageAndColor } from './courses-helper';
|
import { CoreCourseAnyCourseDataWithExtraInfoAndOptions, CoreCourseWithImageAndColor } from './courses-helper';
|
||||||
import { asyncObservable, firstValueFrom, ignoreErrors, zipIncludingComplete } from '@/core/utils/rxjs';
|
import { asyncObservable, firstValueFrom, ignoreErrors, zipIncludingComplete } from '@/core/utils/rxjs';
|
||||||
import { of, Observable } from 'rxjs';
|
import { of } from 'rxjs';
|
||||||
import { map } from 'rxjs/operators';
|
import { map } from 'rxjs/operators';
|
||||||
|
|
||||||
const ROOT_CACHE_KEY = 'mmCourses:';
|
const ROOT_CACHE_KEY = 'mmCourses:';
|
||||||
|
@ -510,7 +510,7 @@ export class CoreCoursesProvider {
|
||||||
field: string = '',
|
field: string = '',
|
||||||
value: string | number = '',
|
value: string | number = '',
|
||||||
options: CoreSitesCommonWSOptions = {},
|
options: CoreSitesCommonWSOptions = {},
|
||||||
): Observable<CoreCourseSearchedData[]> {
|
): WSObservable<CoreCourseSearchedData[]> {
|
||||||
return asyncObservable(async () => {
|
return asyncObservable(async () => {
|
||||||
const siteId = options.siteId || CoreSites.getCurrentSiteId();
|
const siteId = options.siteId || CoreSites.getCurrentSiteId();
|
||||||
const originalValue = value;
|
const originalValue = value;
|
||||||
|
@ -617,7 +617,7 @@ export class CoreCoursesProvider {
|
||||||
customFieldName: string,
|
customFieldName: string,
|
||||||
customFieldValue: string,
|
customFieldValue: string,
|
||||||
options: CoreSitesCommonWSOptions,
|
options: CoreSitesCommonWSOptions,
|
||||||
): Observable<CoreCourseSummaryData[]> {
|
): WSObservable<CoreCourseSummaryData[]> {
|
||||||
return asyncObservable(async () => {
|
return asyncObservable(async () => {
|
||||||
const site = await CoreSites.getSite(options. siteId);
|
const site = await CoreSites.getSite(options. siteId);
|
||||||
|
|
||||||
|
@ -685,7 +685,7 @@ export class CoreCoursesProvider {
|
||||||
getCoursesAdminAndNavOptionsObservable(
|
getCoursesAdminAndNavOptionsObservable(
|
||||||
courseIds: number[],
|
courseIds: number[],
|
||||||
options: CoreSitesCommonWSOptions = {},
|
options: CoreSitesCommonWSOptions = {},
|
||||||
): Observable<{
|
): WSObservable<{
|
||||||
navOptions: CoreCourseUserAdminOrNavOptionCourseIndexed;
|
navOptions: CoreCourseUserAdminOrNavOptionCourseIndexed;
|
||||||
admOptions: CoreCourseUserAdminOrNavOptionCourseIndexed;
|
admOptions: CoreCourseUserAdminOrNavOptionCourseIndexed;
|
||||||
}> {
|
}> {
|
||||||
|
@ -780,7 +780,7 @@ export class CoreCoursesProvider {
|
||||||
getUserAdministrationOptionsObservable(
|
getUserAdministrationOptionsObservable(
|
||||||
courseIds: number[],
|
courseIds: number[],
|
||||||
options: CoreSitesCommonWSOptions = {},
|
options: CoreSitesCommonWSOptions = {},
|
||||||
): Observable<CoreCourseUserAdminOrNavOptionCourseIndexed> {
|
): WSObservable<CoreCourseUserAdminOrNavOptionCourseIndexed> {
|
||||||
if (!courseIds || courseIds.length == 0) {
|
if (!courseIds || courseIds.length == 0) {
|
||||||
return of({});
|
return of({});
|
||||||
}
|
}
|
||||||
|
@ -847,7 +847,7 @@ export class CoreCoursesProvider {
|
||||||
getUserNavigationOptionsObservable(
|
getUserNavigationOptionsObservable(
|
||||||
courseIds: number[],
|
courseIds: number[],
|
||||||
options: CoreSitesCommonWSOptions = {},
|
options: CoreSitesCommonWSOptions = {},
|
||||||
): Observable<CoreCourseUserAdminOrNavOptionCourseIndexed> {
|
): WSObservable<CoreCourseUserAdminOrNavOptionCourseIndexed> {
|
||||||
if (!courseIds || courseIds.length == 0) {
|
if (!courseIds || courseIds.length == 0) {
|
||||||
return of({});
|
return of({});
|
||||||
}
|
}
|
||||||
|
@ -939,10 +939,10 @@ export class CoreCoursesProvider {
|
||||||
): Promise<CoreEnrolledCourseData[]> {
|
): Promise<CoreEnrolledCourseData[]> {
|
||||||
strategy = strategy ?? (preferCache ? CoreSitesReadingStrategy.PREFER_CACHE : undefined);
|
strategy = strategy ?? (preferCache ? CoreSitesReadingStrategy.PREFER_CACHE : undefined);
|
||||||
|
|
||||||
return this.getUserCoursesObservable({
|
return firstValueFrom(this.getUserCoursesObservable({
|
||||||
readingStrategy: strategy,
|
readingStrategy: strategy,
|
||||||
siteId,
|
siteId,
|
||||||
}).toPromise();
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -951,7 +951,7 @@ export class CoreCoursesProvider {
|
||||||
* @param options Options.
|
* @param options Options.
|
||||||
* @return Observable that returns the courses.
|
* @return Observable that returns the courses.
|
||||||
*/
|
*/
|
||||||
getUserCoursesObservable(options: CoreSitesCommonWSOptions = {}): Observable<CoreEnrolledCourseData[]> {
|
getUserCoursesObservable(options: CoreSitesCommonWSOptions = {}): WSObservable<CoreEnrolledCourseData[]> {
|
||||||
return asyncObservable(async () => {
|
return asyncObservable(async () => {
|
||||||
const site = await CoreSites.getSite(options.siteId);
|
const site = await CoreSites.getSite(options.siteId);
|
||||||
|
|
||||||
|
|
|
@ -14,12 +14,11 @@
|
||||||
|
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { CoreSites, CoreSitesCommonWSOptions } from '@services/sites';
|
import { CoreSites, CoreSitesCommonWSOptions } from '@services/sites';
|
||||||
import { CoreSite, CoreSiteWSPreSets } from '@classes/site';
|
import { CoreSite, CoreSiteWSPreSets, WSObservable } from '@classes/site';
|
||||||
import { CoreCourseBlock } from '@features/course/services/course';
|
import { CoreCourseBlock } from '@features/course/services/course';
|
||||||
import { CoreStatusWithWarningsWSResponse } from '@services/ws';
|
import { CoreStatusWithWarningsWSResponse } from '@services/ws';
|
||||||
import { makeSingleton } from '@singletons';
|
import { makeSingleton } from '@singletons';
|
||||||
import { CoreError } from '@classes/errors/error';
|
import { CoreError } from '@classes/errors/error';
|
||||||
import { Observable } from 'rxjs';
|
|
||||||
import { map } from 'rxjs/operators';
|
import { map } from 'rxjs/operators';
|
||||||
import { asyncObservable, firstValueFrom } from '@/core/utils/rxjs';
|
import { asyncObservable, firstValueFrom } from '@/core/utils/rxjs';
|
||||||
|
|
||||||
|
@ -73,7 +72,7 @@ export class CoreCoursesDashboardProvider {
|
||||||
* @return Observable that returns the list of blocks.
|
* @return Observable that returns the list of blocks.
|
||||||
* @since 3.6
|
* @since 3.6
|
||||||
*/
|
*/
|
||||||
getDashboardBlocksFromWSObservable(options: GetDashboardBlocksOptions = {}): Observable<CoreCourseBlock[]> {
|
getDashboardBlocksFromWSObservable(options: GetDashboardBlocksOptions = {}): WSObservable<CoreCourseBlock[]> {
|
||||||
return asyncObservable(async () => {
|
return asyncObservable(async () => {
|
||||||
const site = await CoreSites.getSite(options.siteId);
|
const site = await CoreSites.getSite(options.siteId);
|
||||||
|
|
||||||
|
@ -142,7 +141,7 @@ export class CoreCoursesDashboardProvider {
|
||||||
* @param options Options.
|
* @param options Options.
|
||||||
* @return observable that returns the list of blocks.
|
* @return observable that returns the list of blocks.
|
||||||
*/
|
*/
|
||||||
getDashboardBlocksObservable(options: GetDashboardBlocksOptions = {}): Observable<CoreCoursesDashboardBlocks> {
|
getDashboardBlocksObservable(options: GetDashboardBlocksOptions = {}): WSObservable<CoreCoursesDashboardBlocks> {
|
||||||
return this.getDashboardBlocksFromWSObservable(options).pipe(map(blocks => {
|
return this.getDashboardBlocksFromWSObservable(options).pipe(map(blocks => {
|
||||||
let mainBlocks: CoreCourseBlock[] = [];
|
let mainBlocks: CoreCourseBlock[] = [];
|
||||||
let sideBlocks: CoreCourseBlock[] = [];
|
let sideBlocks: CoreCourseBlock[] = [];
|
||||||
|
|
Loading…
Reference in New Issue