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 {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
promises.push(this.coursesProvider.getCoursesAdminAndNavOptions(courseIds).then((options) => {
|
if (this.coursesProvider.canGetAdminAndNavOptions()) {
|
||||||
courses.forEach((course) => {
|
promises.push(this.coursesProvider.getCoursesAdminAndNavOptions(courseIds).then((options) => {
|
||||||
course.navOptions = options.navOptions[course.id];
|
courses.forEach((course) => {
|
||||||
course.admOptions = options.admOptions[course.id];
|
course.navOptions = options.navOptions[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,13 +223,15 @@ export class CoreCoursesMyOverviewPage implements OnDestroy {
|
||||||
return course.id;
|
return course.id;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Load course options of the course.
|
if (this.coursesProvider.canGetAdminAndNavOptions()) {
|
||||||
promises.push(this.coursesProvider.getCoursesAdminAndNavOptions(courseIds).then((options) => {
|
// Load course options of the course.
|
||||||
courses.forEach((course) => {
|
promises.push(this.coursesProvider.getCoursesAdminAndNavOptions(courseIds).then((options) => {
|
||||||
course.navOptions = options.navOptions[course.id];
|
courses.forEach((course) => {
|
||||||
course.admOptions = options.admOptions[course.id];
|
course.navOptions = options.navOptions[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,51 +213,62 @@ 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;
|
||||||
|
|
||||||
|
if (this.coursesProvider.canGetAdminAndNavOptions()) {
|
||||||
|
// Get course options.
|
||||||
|
promise = this.coursesProvider.getUserCourses(true).then((courses) => {
|
||||||
|
const courseIds = courses.map((course) => {
|
||||||
|
return course.id;
|
||||||
|
});
|
||||||
|
|
||||||
|
return this.coursesProvider.getCoursesAdminAndNavOptions(courseIds).then((options) => {
|
||||||
|
// For backwards compatibility we don't modify the courseId.
|
||||||
|
const courseIdForOptions = courseId || this.sitesProvider.getCurrentSiteHomeId();
|
||||||
|
|
||||||
|
navOptions = options.navOptions[courseIdForOptions];
|
||||||
|
admOptions = options.admOptions[courseIdForOptions];
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
promise = Promise.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
this.userHandlers = [];
|
this.userHandlers = [];
|
||||||
|
|
||||||
// Retrieve course options forcing cache.
|
promise.then(() => {
|
||||||
this.coursesProvider.getUserCourses(true).then((courses) => {
|
const promises = [];
|
||||||
const courseIds = courses.map((course) => {
|
|
||||||
return course.id;
|
|
||||||
});
|
|
||||||
|
|
||||||
return this.coursesProvider.getCoursesAdminAndNavOptions(courseIds).then((options) => {
|
for (const name in this.enabledHandlers) {
|
||||||
// For backwards compatibility we don't modify the courseId.
|
// Checks if the handler is enabled for the user.
|
||||||
const courseIdForOptions = courseId || this.sitesProvider.getCurrentSiteHomeId(),
|
const handler = <CoreUserProfileHandler> this.handlers[name],
|
||||||
navOptions = options.navOptions[courseIdForOptions],
|
isEnabledForUser = handler.isEnabledForUser(user, courseId, navOptions, admOptions),
|
||||||
admOptions = options.admOptions[courseIdForOptions];
|
promise = Promise.resolve(isEnabledForUser).then((enabled) => {
|
||||||
|
if (enabled) {
|
||||||
for (const name in this.enabledHandlers) {
|
this.userHandlers.push({
|
||||||
// Checks if the handler is enabled for the user.
|
name: name,
|
||||||
const handler = <CoreUserProfileHandler> this.handlers[name],
|
data: handler.getDisplayData(user, courseId),
|
||||||
isEnabledForUser = handler.isEnabledForUser(user, courseId, navOptions, admOptions),
|
priority: handler.priority,
|
||||||
promise = Promise.resolve(isEnabledForUser).then((enabled) => {
|
type: handler.type || CoreUserDelegate.TYPE_NEW_PAGE
|
||||||
if (enabled) {
|
});
|
||||||
this.userHandlers.push({
|
} else {
|
||||||
name: name,
|
return Promise.reject(null);
|
||||||
data: handler.getDisplayData(user, courseId),
|
}
|
||||||
priority: handler.priority,
|
}).catch(() => {
|
||||||
type: handler.type || CoreUserDelegate.TYPE_NEW_PAGE
|
// Nothing to do here, it is not enabled for this user.
|
||||||
});
|
|
||||||
} else {
|
|
||||||
return Promise.reject(null);
|
|
||||||
}
|
|
||||||
}).catch(() => {
|
|
||||||
// Nothing to do here, it is not enabled for this user.
|
|
||||||
});
|
|
||||||
promises.push(promise);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Promise.all(promises).then(() => {
|
|
||||||
// Sort them by priority.
|
|
||||||
this.userHandlers.sort((a, b) => {
|
|
||||||
return b.priority - a.priority;
|
|
||||||
});
|
});
|
||||||
this.loaded = true;
|
promises.push(promise);
|
||||||
this.observableHandlers.next(this.userHandlers);
|
}
|
||||||
|
|
||||||
|
return Promise.all(promises).then(() => {
|
||||||
|
// Sort them by priority.
|
||||||
|
this.userHandlers.sort((a, b) => {
|
||||||
|
return b.priority - a.priority;
|
||||||
});
|
});
|
||||||
|
this.loaded = true;
|
||||||
|
this.observableHandlers.next(this.userHandlers);
|
||||||
});
|
});
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
// Never fails.
|
// Never fails.
|
||||||
|
|
Loading…
Reference in New Issue