diff --git a/src/core/course/providers/options-delegate.ts b/src/core/course/providers/options-delegate.ts index 758003c14..6cb0e43aa 100644 --- a/src/core/course/providers/options-delegate.ts +++ b/src/core/course/providers/options-delegate.ts @@ -33,7 +33,6 @@ export interface CoreCourseOptionsHandler extends CoreDelegateHandler { /** * 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 {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; - /** - * 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} True or promise resolved with true if enabled. - */ - shouldDisplayForCourse(courseId: number, accessData: any, navOptions?: any, admOptions?: any): boolean | Promise; - /** * Returns the data needed to render the handler. * @@ -275,38 +263,22 @@ export class CoreCourseOptionsDelegate extends CoreDelegate { // Call getHandlersForAccess to make sure the handlers have been loaded. return this.getHandlersForAccess(course.id, refresh, accessData, course.navOptions, course.admOptions); }).then(() => { - const handlersToDisplay: CoreCourseOptionsHandlerToDisplay[] = [], - promises = []; - let promise; + const handlersToDisplay: CoreCourseOptionsHandlerToDisplay[] = []; 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({ - data: handler.getDisplayData(course), - priority: handler.priority, - prefetch: handler.prefetch - }); - } - })); - }); - - return this.utils.allPromises(promises).then(() => { - // Sort them by priority. - handlersToDisplay.sort((a, b) => { - return b.priority - a.priority; + handlersToDisplay.push({ + data: handler.getDisplayData(course), + priority: handler.priority, + prefetch: handler.prefetch }); - - return handlersToDisplay; }); + + // Sort them by priority. + handlersToDisplay.sort((a, b) => { + return b.priority - a.priority; + }); + + return handlersToDisplay; }); } @@ -444,8 +416,7 @@ export class CoreCourseOptionsDelegate extends CoreDelegate { * @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 {Promise} Resolved when updated. - * @protected + * @return {Promise} Resolved when updated. */ updateHandlersForCourse(courseId: number, accessData: any, navOptions?: any, admOptions?: any): Promise { const promises = [], diff --git a/src/core/user/providers/course-option-handler.ts b/src/core/user/providers/course-option-handler.ts index 35336cb65..633b5fde2 100644 --- a/src/core/user/providers/course-option-handler.ts +++ b/src/core/user/providers/course-option-handler.ts @@ -58,7 +58,6 @@ export class CoreUserParticipantsCourseOptionHandler implements CoreCourseOption /** * 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 {any} accessData Access type and data. Default, guest, ... @@ -75,24 +74,6 @@ export class CoreUserParticipantsCourseOptionHandler implements CoreCourseOption 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} True or promise resolved with true if enabled. - */ - shouldDisplayForCourse(courseId: number, accessData: any, navOptions?: any, admOptions?: any): boolean | Promise { - if (navOptions && typeof navOptions.participants != 'undefined') { - return navOptions.participants; - } - return this.userProvider.isPluginEnabledForCourse(courseId); }