diff --git a/src/addon/competency/competency.module.ts b/src/addon/competency/competency.module.ts index 83ae4bd28..7d31bae23 100644 --- a/src/addon/competency/competency.module.ts +++ b/src/addon/competency/competency.module.ts @@ -22,10 +22,6 @@ import { AddonCompetencyComponentsModule } from './components/components.module' import { CoreCourseOptionsDelegate } from '@core/course/providers/options-delegate'; import { CoreMainMenuDelegate } from '@core/mainmenu/providers/delegate'; import { CoreUserDelegate } from '@core/user/providers/user-delegate'; -import { CoreUserProvider } from '@core/user/providers/user'; -import { CoreEventsProvider } from '@providers/events'; -import { CoreSitesProvider } from '@providers/sites'; -import { CoreCoursesProvider } from '@core/courses/providers/courses'; @NgModule({ declarations: [ @@ -44,24 +40,10 @@ import { CoreCoursesProvider } from '@core/courses/providers/courses'; export class AddonCompetencyModule { constructor(mainMenuDelegate: CoreMainMenuDelegate, mainMenuHandler: AddonCompetencyMainMenuHandler, courseOptionsDelegate: CoreCourseOptionsDelegate, courseOptionHandler: AddonCompetencyCourseOptionHandler, - userDelegate: CoreUserDelegate, userHandler: AddonCompetencyUserHandler, - eventsProvider: CoreEventsProvider, sitesProvider: CoreSitesProvider) { + userDelegate: CoreUserDelegate, userHandler: AddonCompetencyUserHandler) { mainMenuDelegate.registerHandler(mainMenuHandler); courseOptionsDelegate.registerHandler(courseOptionHandler); userDelegate.registerHandler(userHandler); - - eventsProvider.on(CoreEventsProvider.LOGOUT, () => { - courseOptionHandler.clearCoursesNavCache(); - userHandler.clearUsersNavCache(); - }, sitesProvider.getCurrentSiteId()); - - eventsProvider.on(CoreCoursesProvider.EVENT_MY_COURSES_REFRESHED, () => { - courseOptionHandler.clearCoursesNavCache(); - }, sitesProvider.getCurrentSiteId()); - - eventsProvider.on(CoreUserProvider.PROFILE_REFRESHED, () => { - userHandler.clearUsersNavCache(); - }, sitesProvider.getCurrentSiteId()); } } diff --git a/src/addon/competency/providers/course-option-handler.ts b/src/addon/competency/providers/course-option-handler.ts index fe7bdd9d8..4aee5b3dc 100644 --- a/src/addon/competency/providers/course-option-handler.ts +++ b/src/addon/competency/providers/course-option-handler.ts @@ -26,17 +26,8 @@ export class AddonCompetencyCourseOptionHandler implements CoreCourseOptionsHand name = 'AddonCompetency'; priority = 700; - protected coursesNavEnabledCache = {}; - constructor(private competencyProvider: AddonCompetencyProvider) {} - /** - * Clear courses nav cache. - */ - clearCoursesNavCache(): void { - this.coursesNavEnabledCache = {}; - } - /** * Whether or not the handler is enabled ona site level. * @return {boolean|Promise} Whether or not the handler is enabled on a site level. @@ -63,15 +54,8 @@ export class AddonCompetencyCourseOptionHandler implements CoreCourseOptionsHand return navOptions.competencies; } - if (typeof this.coursesNavEnabledCache[courseId] != 'undefined') { - return this.coursesNavEnabledCache[courseId]; - } - return this.competencyProvider.isPluginForCourseEnabled(courseId).then((competencies) => { - const enabled = competencies ? !competencies.canmanagecoursecompetencies : false; - this.coursesNavEnabledCache[courseId] = enabled; - - return enabled; + return competencies ? !competencies.canmanagecoursecompetencies : false; }); } diff --git a/src/addon/competency/providers/user-handler.ts b/src/addon/competency/providers/user-handler.ts index a80b6fa57..ffc4a7c51 100644 --- a/src/addon/competency/providers/user-handler.ts +++ b/src/addon/competency/providers/user-handler.ts @@ -16,6 +16,8 @@ import { Injectable } from '@angular/core'; import { CoreUserDelegate, CoreUserProfileHandler, CoreUserProfileHandlerData } from '@core/user/providers/user-delegate'; import { CoreSitesProvider } from '@providers/sites'; import { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper'; +import { CoreEventsProvider } from '@providers/events'; +import { CoreUserProvider } from '@core/user/providers/user'; import { AddonCompetencyProvider } from './competency'; /** @@ -30,13 +32,15 @@ export class AddonCompetencyUserHandler implements CoreUserProfileHandler { usersNavEnabledCache = {}; constructor(private linkHelper: CoreContentLinksHelperProvider, protected sitesProvider: CoreSitesProvider, - private competencyProvider: AddonCompetencyProvider) { + private competencyProvider: AddonCompetencyProvider, eventsProvider: CoreEventsProvider) { + eventsProvider.on(CoreEventsProvider.LOGOUT, this.clearUsersNavCache.bind(this)); + eventsProvider.on(CoreUserProvider.PROFILE_REFRESHED, this.clearUsersNavCache.bind(this)); } /** * Clear users nav cache. */ - clearUsersNavCache(): void { + private clearUsersNavCache(): void { this.participantsNavEnabledCache = {}; this.usersNavEnabledCache = {}; }