MOBILE-2431 courses: Fix course options not available
parent
11013c69ab
commit
10da720a4a
|
@ -395,7 +395,9 @@ export class CoreCourseOptionsDelegate extends CoreDelegate {
|
||||||
* @return {Promise<void>} Promise resolved when done.
|
* @return {Promise<void>} Promise resolved when done.
|
||||||
*/
|
*/
|
||||||
protected loadCourseOptions(course: any, refresh?: boolean): Promise<void> {
|
protected loadCourseOptions(course: any, refresh?: boolean): Promise<void> {
|
||||||
if (typeof course.navOptions == 'undefined' || typeof course.admOptions == 'undefined' || refresh) {
|
if (this.coursesProvider.canGetAdminAndNavOptions() &&
|
||||||
|
(typeof course.navOptions == 'undefined' || typeof course.admOptions == 'undefined' || refresh)) {
|
||||||
|
|
||||||
return this.coursesProvider.getCoursesAdminAndNavOptions([course.id]).then((options) => {
|
return this.coursesProvider.getCoursesAdminAndNavOptions([course.id]).then((options) => {
|
||||||
course.navOptions = options.navOptions[course.id];
|
course.navOptions = options.navOptions[course.id];
|
||||||
course.admOptions = options.admOptions[course.id];
|
course.admOptions = options.admOptions[course.id];
|
||||||
|
|
|
@ -111,12 +111,14 @@ export class CoreCoursesMyCoursesPage implements OnDestroy {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.coursesProvider.canGetAdminAndNavOptions()) {
|
||||||
promises.push(this.coursesProvider.getCoursesAdminAndNavOptions(courseIds).then((options) => {
|
promises.push(this.coursesProvider.getCoursesAdminAndNavOptions(courseIds).then((options) => {
|
||||||
courses.forEach((course) => {
|
courses.forEach((course) => {
|
||||||
course.navOptions = options.navOptions[course.id];
|
course.navOptions = options.navOptions[course.id];
|
||||||
course.admOptions = options.admOptions[course.id];
|
course.admOptions = options.admOptions[course.id];
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
return Promise.all(promises).then(() => {
|
return Promise.all(promises).then(() => {
|
||||||
this.courses = courses;
|
this.courses = courses;
|
||||||
|
|
|
@ -223,6 +223,7 @@ export class CoreCoursesMyOverviewPage implements OnDestroy {
|
||||||
return course.id;
|
return course.id;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (this.coursesProvider.canGetAdminAndNavOptions()) {
|
||||||
// Load course options of the course.
|
// Load course options of the course.
|
||||||
promises.push(this.coursesProvider.getCoursesAdminAndNavOptions(courseIds).then((options) => {
|
promises.push(this.coursesProvider.getCoursesAdminAndNavOptions(courseIds).then((options) => {
|
||||||
courses.forEach((course) => {
|
courses.forEach((course) => {
|
||||||
|
@ -230,6 +231,7 @@ export class CoreCoursesMyOverviewPage implements OnDestroy {
|
||||||
course.admOptions = options.admOptions[course.id];
|
course.admOptions = options.admOptions[course.id];
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
this.courseIds = courseIds.join(',');
|
this.courseIds = courseIds.join(',');
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,16 @@ export class CoreCoursesProvider {
|
||||||
this.logger = logger.getInstance('CoreCoursesProvider');
|
this.logger = logger.getInstance('CoreCoursesProvider');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether current site supports getting course options.
|
||||||
|
*
|
||||||
|
* @return {boolean} Whether current site supports getting course options.
|
||||||
|
*/
|
||||||
|
canGetAdminAndNavOptions(): boolean {
|
||||||
|
return this.sitesProvider.wsAvailableInCurrentSite('core_course_get_user_navigation_options') &&
|
||||||
|
this.sitesProvider.wsAvailableInCurrentSite('core_course_get_user_administration_options');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get categories. They can be filtered by id.
|
* Get categories. They can be filtered by id.
|
||||||
*
|
*
|
||||||
|
|
|
@ -213,21 +213,33 @@ export class CoreUserDelegate extends CoreDelegate {
|
||||||
* @return {Subject<CoreUserProfileHandlerToDisplay[]>} Resolved with the handlers.
|
* @return {Subject<CoreUserProfileHandlerToDisplay[]>} Resolved with the handlers.
|
||||||
*/
|
*/
|
||||||
getProfileHandlersFor(user: any, courseId: number): Subject<CoreUserProfileHandlerToDisplay[]> {
|
getProfileHandlersFor(user: any, courseId: number): Subject<CoreUserProfileHandlerToDisplay[]> {
|
||||||
const promises = [];
|
let promise,
|
||||||
|
navOptions,
|
||||||
|
admOptions;
|
||||||
|
|
||||||
this.userHandlers = [];
|
if (this.coursesProvider.canGetAdminAndNavOptions()) {
|
||||||
|
// Get course options.
|
||||||
// Retrieve course options forcing cache.
|
promise = this.coursesProvider.getUserCourses(true).then((courses) => {
|
||||||
this.coursesProvider.getUserCourses(true).then((courses) => {
|
|
||||||
const courseIds = courses.map((course) => {
|
const courseIds = courses.map((course) => {
|
||||||
return course.id;
|
return course.id;
|
||||||
});
|
});
|
||||||
|
|
||||||
return this.coursesProvider.getCoursesAdminAndNavOptions(courseIds).then((options) => {
|
return this.coursesProvider.getCoursesAdminAndNavOptions(courseIds).then((options) => {
|
||||||
// For backwards compatibility we don't modify the courseId.
|
// For backwards compatibility we don't modify the courseId.
|
||||||
const courseIdForOptions = courseId || this.sitesProvider.getCurrentSiteHomeId(),
|
const courseIdForOptions = courseId || this.sitesProvider.getCurrentSiteHomeId();
|
||||||
navOptions = options.navOptions[courseIdForOptions],
|
|
||||||
|
navOptions = options.navOptions[courseIdForOptions];
|
||||||
admOptions = options.admOptions[courseIdForOptions];
|
admOptions = options.admOptions[courseIdForOptions];
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
promise = Promise.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.userHandlers = [];
|
||||||
|
|
||||||
|
promise.then(() => {
|
||||||
|
const promises = [];
|
||||||
|
|
||||||
for (const name in this.enabledHandlers) {
|
for (const name in this.enabledHandlers) {
|
||||||
// Checks if the handler is enabled for the user.
|
// Checks if the handler is enabled for the user.
|
||||||
|
@ -258,7 +270,6 @@ export class CoreUserDelegate extends CoreDelegate {
|
||||||
this.loaded = true;
|
this.loaded = true;
|
||||||
this.observableHandlers.next(this.userHandlers);
|
this.observableHandlers.next(this.userHandlers);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
// Never fails.
|
// Never fails.
|
||||||
this.loaded = true;
|
this.loaded = true;
|
||||||
|
|
Loading…
Reference in New Issue