MOBILE-2319 competency: Moved event handlers of delegate handlers

main
Albert Gasset 2018-03-21 16:10:59 +01:00
parent a0c57f46c0
commit 4cefb20455
3 changed files with 8 additions and 38 deletions

View File

@ -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());
}
}

View File

@ -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<boolean>} 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;
});
}

View File

@ -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 = {};
}