MOBILE-2324 course: Remove shouldDisplayForCourse function
parent
c6032d76ed
commit
ad03f6ed4e
|
@ -33,7 +33,6 @@ export interface CoreCourseOptionsHandler extends CoreDelegateHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether or not the handler is enabled for a certain course.
|
* Whether or not the handler is enabled for a certain course.
|
||||||
* For perfomance reasons, do NOT call WebServices in here, call them in shouldDisplayForCourse.
|
|
||||||
*
|
*
|
||||||
* @param {number} courseId The course ID.
|
* @param {number} courseId The course ID.
|
||||||
* @param {any} accessData Access type and data. Default, guest, ...
|
* @param {any} accessData Access type and data. Default, guest, ...
|
||||||
|
@ -43,17 +42,6 @@ export interface CoreCourseOptionsHandler extends CoreDelegateHandler {
|
||||||
*/
|
*/
|
||||||
isEnabledForCourse(courseId: number, accessData: any, navOptions?: any, admOptions?: any): boolean | Promise<boolean>;
|
isEnabledForCourse(courseId: number, accessData: any, navOptions?: any, admOptions?: any): boolean | Promise<boolean>;
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether or not the handler should be displayed for a course. If not implemented, assume it's true.
|
|
||||||
*
|
|
||||||
* @param {number} courseId The course ID.
|
|
||||||
* @param {any} accessData Access type and data. Default, guest, ...
|
|
||||||
* @param {any} [navOptions] Course navigation options for current user. See CoreCoursesProvider.getUserNavigationOptions.
|
|
||||||
* @param {any} [admOptions] Course admin options for current user. See CoreCoursesProvider.getUserAdministrationOptions.
|
|
||||||
* @return {boolean|Promise<boolean>} True or promise resolved with true if enabled.
|
|
||||||
*/
|
|
||||||
shouldDisplayForCourse(courseId: number, accessData: any, navOptions?: any, admOptions?: any): boolean | Promise<boolean>;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the data needed to render the handler.
|
* Returns the data needed to render the handler.
|
||||||
*
|
*
|
||||||
|
@ -275,31 +263,16 @@ export class CoreCourseOptionsDelegate extends CoreDelegate {
|
||||||
// Call getHandlersForAccess to make sure the handlers have been loaded.
|
// Call getHandlersForAccess to make sure the handlers have been loaded.
|
||||||
return this.getHandlersForAccess(course.id, refresh, accessData, course.navOptions, course.admOptions);
|
return this.getHandlersForAccess(course.id, refresh, accessData, course.navOptions, course.admOptions);
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
const handlersToDisplay: CoreCourseOptionsHandlerToDisplay[] = [],
|
const handlersToDisplay: CoreCourseOptionsHandlerToDisplay[] = [];
|
||||||
promises = [];
|
|
||||||
let promise;
|
|
||||||
|
|
||||||
this.coursesHandlers[course.id].enabledHandlers.forEach((handler) => {
|
this.coursesHandlers[course.id].enabledHandlers.forEach((handler) => {
|
||||||
if (handler.shouldDisplayForCourse) {
|
|
||||||
promise = Promise.resolve(handler.shouldDisplayForCourse(
|
|
||||||
course.id, accessData, course.navOptions, course.admOptions));
|
|
||||||
} else {
|
|
||||||
// Not implemented, assume it should be displayed.
|
|
||||||
promise = Promise.resolve(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
promises.push(promise.then((enabled) => {
|
|
||||||
if (enabled) {
|
|
||||||
handlersToDisplay.push({
|
handlersToDisplay.push({
|
||||||
data: handler.getDisplayData(course),
|
data: handler.getDisplayData(course),
|
||||||
priority: handler.priority,
|
priority: handler.priority,
|
||||||
prefetch: handler.prefetch
|
prefetch: handler.prefetch
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return this.utils.allPromises(promises).then(() => {
|
|
||||||
// Sort them by priority.
|
// Sort them by priority.
|
||||||
handlersToDisplay.sort((a, b) => {
|
handlersToDisplay.sort((a, b) => {
|
||||||
return b.priority - a.priority;
|
return b.priority - a.priority;
|
||||||
|
@ -307,7 +280,6 @@ export class CoreCourseOptionsDelegate extends CoreDelegate {
|
||||||
|
|
||||||
return handlersToDisplay;
|
return handlersToDisplay;
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -444,8 +416,7 @@ export class CoreCourseOptionsDelegate extends CoreDelegate {
|
||||||
* @param {any} accessData Access type and data. Default, guest, ...
|
* @param {any} accessData Access type and data. Default, guest, ...
|
||||||
* @param {any} [navOptions] Course navigation options for current user. See CoreCoursesProvider.getUserNavigationOptions.
|
* @param {any} [navOptions] Course navigation options for current user. See CoreCoursesProvider.getUserNavigationOptions.
|
||||||
* @param {any} [admOptions] Course admin options for current user. See CoreCoursesProvider.getUserAdministrationOptions.
|
* @param {any} [admOptions] Course admin options for current user. See CoreCoursesProvider.getUserAdministrationOptions.
|
||||||
* @return {Promise} Resolved when updated.
|
* @return {Promise<any>} Resolved when updated.
|
||||||
* @protected
|
|
||||||
*/
|
*/
|
||||||
updateHandlersForCourse(courseId: number, accessData: any, navOptions?: any, admOptions?: any): Promise<any> {
|
updateHandlersForCourse(courseId: number, accessData: any, navOptions?: any, admOptions?: any): Promise<any> {
|
||||||
const promises = [],
|
const promises = [],
|
||||||
|
|
|
@ -58,7 +58,6 @@ export class CoreUserParticipantsCourseOptionHandler implements CoreCourseOption
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether or not the handler is enabled for a certain course.
|
* Whether or not the handler is enabled for a certain course.
|
||||||
* For perfomance reasons, do NOT call WebServices in here, call them in shouldDisplayForCourse.
|
|
||||||
*
|
*
|
||||||
* @param {number} courseId The course ID.
|
* @param {number} courseId The course ID.
|
||||||
* @param {any} accessData Access type and data. Default, guest, ...
|
* @param {any} accessData Access type and data. Default, guest, ...
|
||||||
|
@ -75,24 +74,6 @@ export class CoreUserParticipantsCourseOptionHandler implements CoreCourseOption
|
||||||
return navOptions.participants;
|
return navOptions.participants;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assume it's enabled for now, further checks will be done in shouldDisplayForCourse.
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether or not the handler should be displayed for a course. If not implemented, assume it's true.
|
|
||||||
*
|
|
||||||
* @param {number} courseId The course ID.
|
|
||||||
* @param {any} accessData Access type and data. Default, guest, ...
|
|
||||||
* @param {any} [navOptions] Course navigation options for current user. See CoreCoursesProvider.getUserNavigationOptions.
|
|
||||||
* @param {any} [admOptions] Course admin options for current user. See CoreCoursesProvider.getUserAdministrationOptions.
|
|
||||||
* @return {boolean|Promise<boolean>} True or promise resolved with true if enabled.
|
|
||||||
*/
|
|
||||||
shouldDisplayForCourse(courseId: number, accessData: any, navOptions?: any, admOptions?: any): boolean | Promise<boolean> {
|
|
||||||
if (navOptions && typeof navOptions.participants != 'undefined') {
|
|
||||||
return navOptions.participants;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.userProvider.isPluginEnabledForCourse(courseId);
|
return this.userProvider.isPluginEnabledForCourse(courseId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue