From 0b52f9896083bc26bc28d553a88e501c3fcd28dd Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Fri, 23 Mar 2018 13:24:31 +0100 Subject: [PATCH] MOBILE-2391 core: Use different property for modName/etc in delegates --- .../mod/book/providers/module-handler.ts | 3 ++- .../mod/book/providers/prefetch-handler.ts | 3 ++- .../mod/folder/providers/module-handler.ts | 3 ++- .../mod/folder/providers/prefetch-handler.ts | 3 ++- .../mod/label/providers/module-handler.ts | 3 ++- .../mod/page/providers/module-handler.ts | 3 ++- .../mod/page/providers/prefetch-handler.ts | 3 ++- .../mod/resource/providers/module-handler.ts | 3 ++- .../resource/providers/prefetch-handler.ts | 3 ++- .../mod/survey/providers/module-handler.ts | 3 ++- .../mod/survey/providers/prefetch-handler.ts | 3 ++- src/addon/mod/url/providers/module-handler.ts | 3 ++- .../checkbox/providers/handler.ts | 3 ++- .../datetime/providers/handler.ts | 3 ++- .../menu/providers/handler.ts | 3 ++- .../text/providers/handler.ts | 3 ++- .../textarea/providers/handler.ts | 3 ++- src/classes/delegate.ts | 21 +++++++++++++------ .../course/classes/module-prefetch-handler.ts | 8 ++++++- .../singleactivity/providers/handler.ts | 3 ++- .../formats/social/providers/handler.ts | 3 ++- .../formats/topics/providers/handler.ts | 3 ++- .../course/formats/weeks/providers/handler.ts | 3 ++- src/core/course/providers/default-format.ts | 3 ++- src/core/course/providers/format-delegate.ts | 9 +++++++- src/core/course/providers/module-delegate.ts | 7 +++++++ .../providers/module-prefetch-delegate.ts | 7 +++++++ .../classes/course-format-handler.ts | 2 +- .../siteplugins/classes/module-handler.ts | 2 +- .../classes/module-prefetch-handler.ts | 7 ++++--- .../classes/user-profile-field-handler.ts | 2 +- src/core/siteplugins/providers/helper.ts | 17 ++++++++------- .../providers/user-profile-field-delegate.ts | 6 ++++++ 33 files changed, 111 insertions(+), 43 deletions(-) diff --git a/src/addon/mod/book/providers/module-handler.ts b/src/addon/mod/book/providers/module-handler.ts index e440fcf33..7cae479c6 100644 --- a/src/addon/mod/book/providers/module-handler.ts +++ b/src/addon/mod/book/providers/module-handler.ts @@ -24,7 +24,8 @@ import { CoreCourseProvider } from '@core/course/providers/course'; */ @Injectable() export class AddonModBookModuleHandler implements CoreCourseModuleHandler { - name = 'book'; + name = 'AddonModBook'; + modName = 'book'; constructor(protected bookProvider: AddonModBookProvider, private courseProvider: CoreCourseProvider) { } diff --git a/src/addon/mod/book/providers/prefetch-handler.ts b/src/addon/mod/book/providers/prefetch-handler.ts index 17aa4b636..aa0b5d8a5 100644 --- a/src/addon/mod/book/providers/prefetch-handler.ts +++ b/src/addon/mod/book/providers/prefetch-handler.ts @@ -21,7 +21,8 @@ import { AddonModBookProvider } from './book'; */ @Injectable() export class AddonModBookPrefetchHandler extends CoreCourseModulePrefetchHandlerBase { - name = 'book'; + name = 'AddonModBook'; + modName = 'book'; component = AddonModBookProvider.COMPONENT; updatesNames = /^configuration$|^.*files$|^entries$/; isResource = true; diff --git a/src/addon/mod/folder/providers/module-handler.ts b/src/addon/mod/folder/providers/module-handler.ts index e30a9b890..54899cb35 100644 --- a/src/addon/mod/folder/providers/module-handler.ts +++ b/src/addon/mod/folder/providers/module-handler.ts @@ -23,7 +23,8 @@ import { CoreCourseProvider } from '@core/course/providers/course'; */ @Injectable() export class AddonModFolderModuleHandler implements CoreCourseModuleHandler { - name = 'folder'; + name = 'AddonModFolder'; + modName = 'folder'; constructor(private courseProvider: CoreCourseProvider) { } diff --git a/src/addon/mod/folder/providers/prefetch-handler.ts b/src/addon/mod/folder/providers/prefetch-handler.ts index e764111d5..2b443ae83 100644 --- a/src/addon/mod/folder/providers/prefetch-handler.ts +++ b/src/addon/mod/folder/providers/prefetch-handler.ts @@ -21,7 +21,8 @@ import { AddonModFolderProvider } from './folder'; */ @Injectable() export class AddonModFolderPrefetchHandler extends CoreCourseModulePrefetchHandlerBase { - name = 'folder'; + name = 'AddonModFolder'; + modName = 'folder'; component = AddonModFolderProvider.COMPONENT; isResource = true; diff --git a/src/addon/mod/label/providers/module-handler.ts b/src/addon/mod/label/providers/module-handler.ts index 06ab1e7f7..f54871597 100644 --- a/src/addon/mod/label/providers/module-handler.ts +++ b/src/addon/mod/label/providers/module-handler.ts @@ -20,7 +20,8 @@ import { CoreCourseModuleHandler, CoreCourseModuleHandlerData } from '@core/cour */ @Injectable() export class AddonModLabelModuleHandler implements CoreCourseModuleHandler { - name = 'label'; + name = 'AddonModLabel'; + modName = 'label'; constructor() { // Nothing to do. diff --git a/src/addon/mod/page/providers/module-handler.ts b/src/addon/mod/page/providers/module-handler.ts index 88d14ebd5..69e04dd5d 100644 --- a/src/addon/mod/page/providers/module-handler.ts +++ b/src/addon/mod/page/providers/module-handler.ts @@ -24,7 +24,8 @@ import { CoreCourseProvider } from '@core/course/providers/course'; */ @Injectable() export class AddonModPageModuleHandler implements CoreCourseModuleHandler { - name = 'page'; + name = 'AddonModPage'; + modName = 'page'; constructor(private courseProvider: CoreCourseProvider, protected pageProvider: AddonModPageProvider) { } diff --git a/src/addon/mod/page/providers/prefetch-handler.ts b/src/addon/mod/page/providers/prefetch-handler.ts index 8ee99b75a..32f6627e6 100644 --- a/src/addon/mod/page/providers/prefetch-handler.ts +++ b/src/addon/mod/page/providers/prefetch-handler.ts @@ -23,7 +23,8 @@ import { AddonModPageHelperProvider } from './helper'; */ @Injectable() export class AddonModPagePrefetchHandler extends CoreCourseModulePrefetchHandlerBase { - name = 'page'; + name = 'AddonModPage'; + modName = 'page'; component = AddonModPageProvider.COMPONENT; updatesNames = /^configuration$|^.*files$/; isResource = true; diff --git a/src/addon/mod/resource/providers/module-handler.ts b/src/addon/mod/resource/providers/module-handler.ts index f952695a0..a531d8029 100644 --- a/src/addon/mod/resource/providers/module-handler.ts +++ b/src/addon/mod/resource/providers/module-handler.ts @@ -26,7 +26,8 @@ import { CoreMimetypeUtilsProvider } from '@providers/utils/mimetype'; */ @Injectable() export class AddonModResourceModuleHandler implements CoreCourseModuleHandler { - name = 'resource'; + name = 'AddonModResource'; + modName = 'resource'; constructor(protected resourceProvider: AddonModResourceProvider, private courseProvider: CoreCourseProvider, protected mimetypeUtils: CoreMimetypeUtilsProvider, private resourceHelper: AddonModResourceHelperProvider) { } diff --git a/src/addon/mod/resource/providers/prefetch-handler.ts b/src/addon/mod/resource/providers/prefetch-handler.ts index a17dc360e..d6d9db96f 100644 --- a/src/addon/mod/resource/providers/prefetch-handler.ts +++ b/src/addon/mod/resource/providers/prefetch-handler.ts @@ -23,7 +23,8 @@ import { CoreFilepoolProvider } from '@providers/filepool'; */ @Injectable() export class AddonModResourcePrefetchHandler extends CoreCourseModulePrefetchHandlerBase { - name = 'resource'; + name = 'AddonModResource'; + modName = 'resource'; component = AddonModResourceProvider.COMPONENT; isResource = true; diff --git a/src/addon/mod/survey/providers/module-handler.ts b/src/addon/mod/survey/providers/module-handler.ts index a2255adde..4cefa0b32 100644 --- a/src/addon/mod/survey/providers/module-handler.ts +++ b/src/addon/mod/survey/providers/module-handler.ts @@ -23,7 +23,8 @@ import { CoreCourseProvider } from '@core/course/providers/course'; */ @Injectable() export class AddonModSurveyModuleHandler implements CoreCourseModuleHandler { - name = 'survey'; + name = 'AddonModSurvey'; + modName = 'survey'; constructor(private courseProvider: CoreCourseProvider) { } diff --git a/src/addon/mod/survey/providers/prefetch-handler.ts b/src/addon/mod/survey/providers/prefetch-handler.ts index 1dce26b38..6b1c998dc 100644 --- a/src/addon/mod/survey/providers/prefetch-handler.ts +++ b/src/addon/mod/survey/providers/prefetch-handler.ts @@ -22,7 +22,8 @@ import { AddonModSurveyHelperProvider } from './helper'; */ @Injectable() export class AddonModSurveyPrefetchHandler extends CoreCourseModulePrefetchHandlerBase { - name = 'survey'; + name = 'AddonModSurvey'; + modName = 'survey'; component = AddonModSurveyProvider.COMPONENT; updatesNames = /^configuration$|^.*files$|^answers$/; diff --git a/src/addon/mod/url/providers/module-handler.ts b/src/addon/mod/url/providers/module-handler.ts index 7bc5e1166..f1162e636 100644 --- a/src/addon/mod/url/providers/module-handler.ts +++ b/src/addon/mod/url/providers/module-handler.ts @@ -25,7 +25,8 @@ import { AddonModUrlHelperProvider } from './helper'; */ @Injectable() export class AddonModUrlModuleHandler implements CoreCourseModuleHandler { - name = 'url'; + name = 'AddonModUrl'; + modName = 'url'; constructor(private courseProvider: CoreCourseProvider, private urlProvider: AddonModUrlProvider, private urlHelper: AddonModUrlHelperProvider) { } diff --git a/src/addon/userprofilefield/checkbox/providers/handler.ts b/src/addon/userprofilefield/checkbox/providers/handler.ts index 4383da420..42297a1a2 100644 --- a/src/addon/userprofilefield/checkbox/providers/handler.ts +++ b/src/addon/userprofilefield/checkbox/providers/handler.ts @@ -21,7 +21,8 @@ import { AddonUserProfileFieldCheckboxComponent } from '../component/checkbox'; */ @Injectable() export class AddonUserProfileFieldCheckboxHandler implements CoreUserProfileFieldHandler { - name = 'checkbox'; + name = 'AddonUserProfileFieldCheckbox'; + type = 'checkbox'; constructor() { // Nothing to do. diff --git a/src/addon/userprofilefield/datetime/providers/handler.ts b/src/addon/userprofilefield/datetime/providers/handler.ts index 2f2ae2513..65a7a6f66 100644 --- a/src/addon/userprofilefield/datetime/providers/handler.ts +++ b/src/addon/userprofilefield/datetime/providers/handler.ts @@ -21,7 +21,8 @@ import { AddonUserProfileFieldDatetimeComponent } from '../component/datetime'; */ @Injectable() export class AddonUserProfileFieldDatetimeHandler implements CoreUserProfileFieldHandler { - name = 'datetime'; + name = 'AddonUserProfileFieldDatetime'; + type = 'datetime'; constructor() { // Nothing to do. diff --git a/src/addon/userprofilefield/menu/providers/handler.ts b/src/addon/userprofilefield/menu/providers/handler.ts index 89d536561..6516c0559 100644 --- a/src/addon/userprofilefield/menu/providers/handler.ts +++ b/src/addon/userprofilefield/menu/providers/handler.ts @@ -21,7 +21,8 @@ import { AddonUserProfileFieldMenuComponent } from '../component/menu'; */ @Injectable() export class AddonUserProfileFieldMenuHandler implements CoreUserProfileFieldHandler { - name = 'menu'; + name = 'AddonUserProfileFieldMenu'; + type = 'menu'; constructor() { // Nothing to do. diff --git a/src/addon/userprofilefield/text/providers/handler.ts b/src/addon/userprofilefield/text/providers/handler.ts index 5c4ce7d9f..2cdcac9ee 100644 --- a/src/addon/userprofilefield/text/providers/handler.ts +++ b/src/addon/userprofilefield/text/providers/handler.ts @@ -22,7 +22,8 @@ import { CoreTextUtilsProvider } from '@providers/utils/text'; */ @Injectable() export class AddonUserProfileFieldTextHandler implements CoreUserProfileFieldHandler { - name = 'text'; + name = 'AddonUserProfileFieldText'; + type = 'text'; constructor(private textUtils: CoreTextUtilsProvider) { } diff --git a/src/addon/userprofilefield/textarea/providers/handler.ts b/src/addon/userprofilefield/textarea/providers/handler.ts index b2bffda4e..fc079ffb7 100644 --- a/src/addon/userprofilefield/textarea/providers/handler.ts +++ b/src/addon/userprofilefield/textarea/providers/handler.ts @@ -22,7 +22,8 @@ import { CoreTextUtilsProvider } from '@providers/utils/text'; */ @Injectable() export class AddonUserProfileFieldTextareaHandler implements CoreUserProfileFieldHandler { - name = 'textarea'; + name = 'AddonUserProfileFieldTextarea'; + type = 'textarea'; constructor(private textUtils: CoreTextUtilsProvider) { } diff --git a/src/classes/delegate.ts b/src/classes/delegate.ts index 7f19b8c00..953de9ac0 100644 --- a/src/classes/delegate.ts +++ b/src/classes/delegate.ts @@ -20,6 +20,7 @@ import { CoreEventsProvider } from '@providers/events'; export interface CoreDelegateHandler { /** * Name of the handler, or name and sub context (AddonMessages, AddonMessages:blockContact, ...). + * This name will be used to check if the feature is disabled. * @type {string} */ name: string; @@ -74,6 +75,14 @@ export class CoreDelegate { */ protected featurePrefix: string; + /** + * Name of the property to be used to index the handlers. By default, the handler's name will be used. + * If your delegate uses a Moodle component name to identify the handlers, please override this property. + * E.g. CoreCourseModuleDelegate uses 'modName' to index the handlers. + * @type {string} + */ + protected handlerNameProperty = 'name'; + /** * Constructor of the Delegate. * @@ -182,14 +191,14 @@ export class CoreDelegate { * @return {boolean} True when registered, false if already registered. */ registerHandler(handler: CoreDelegateHandler): boolean { - if (typeof this.handlers[handler.name] !== 'undefined') { - this.logger.log(`Addon '${handler.name}' already registered`); + if (typeof this.handlers[handler[this.handlerNameProperty]] !== 'undefined') { + this.logger.log(`Handler '${handler[this.handlerNameProperty]}' already registered`); return false; } - this.logger.log(`Registered addon '${handler.name}'`); - this.handlers[handler.name] = handler; + this.logger.log(`Registered handler '${handler[this.handlerNameProperty]}'`); + this.handlers[handler[this.handlerNameProperty]] = handler; return true; } @@ -222,9 +231,9 @@ export class CoreDelegate { // Check that site hasn't changed since the check started. if (this.isLastUpdateCall(time) && this.sitesProvider.getCurrentSiteId() === siteId) { if (enabled) { - this.enabledHandlers[handler.name] = handler; + this.enabledHandlers[handler[this.handlerNameProperty]] = handler; } else { - delete this.enabledHandlers[handler.name]; + delete this.enabledHandlers[handler[this.handlerNameProperty]]; } } }); diff --git a/src/core/course/classes/module-prefetch-handler.ts b/src/core/course/classes/module-prefetch-handler.ts index c078e1b6a..076b0e44e 100644 --- a/src/core/course/classes/module-prefetch-handler.ts +++ b/src/core/course/classes/module-prefetch-handler.ts @@ -53,11 +53,17 @@ export type prefetchFunction = (module: any, courseId: number, single: boolean, * recommended to call the prefetchPackage function since it'll handle changing the status of the module. */ export class CoreCourseModulePrefetchHandlerBase implements CoreCourseModulePrefetchHandler { + /** + * Name of the handler. + * @type {string} + */ + name = 'CoreCourseModulePrefetchHandler'; + /** * Name of the module. It should match the "modname" of the module returned in core_course_get_contents. * @type {string} */ - name = ''; + modName = 'default'; /** * The handler's component. diff --git a/src/core/course/formats/singleactivity/providers/handler.ts b/src/core/course/formats/singleactivity/providers/handler.ts index 9dd528021..67090c9ee 100644 --- a/src/core/course/formats/singleactivity/providers/handler.ts +++ b/src/core/course/formats/singleactivity/providers/handler.ts @@ -21,7 +21,8 @@ import { CoreCourseFormatSingleActivityComponent } from '../components/singleact */ @Injectable() export class CoreCourseFormatSingleActivityHandler implements CoreCourseFormatHandler { - name = 'singleactivity'; + name = 'CoreCourseFormatSingleActivity'; + format = 'singleactivity'; constructor() { // Nothing to do. diff --git a/src/core/course/formats/social/providers/handler.ts b/src/core/course/formats/social/providers/handler.ts index 25d942515..fd4c7f5bb 100644 --- a/src/core/course/formats/social/providers/handler.ts +++ b/src/core/course/formats/social/providers/handler.ts @@ -21,5 +21,6 @@ import { CoreCourseFormatSingleActivityHandler } from '../../singleactivity/prov */ @Injectable() export class CoreCourseFormatSocialHandler extends CoreCourseFormatSingleActivityHandler { - name = 'social'; + name = 'CoreCourseFormatSocial'; + format = 'social'; } diff --git a/src/core/course/formats/topics/providers/handler.ts b/src/core/course/formats/topics/providers/handler.ts index bfac65132..0f6d49e3c 100644 --- a/src/core/course/formats/topics/providers/handler.ts +++ b/src/core/course/formats/topics/providers/handler.ts @@ -20,7 +20,8 @@ import { CoreCourseFormatHandler } from '../../../providers/format-delegate'; */ @Injectable() export class CoreCourseFormatTopicsHandler implements CoreCourseFormatHandler { - name = 'topics'; + name = 'CoreCourseFormatTopics'; + format = 'topics'; constructor() { // Nothing to do. diff --git a/src/core/course/formats/weeks/providers/handler.ts b/src/core/course/formats/weeks/providers/handler.ts index 7fea18e9a..675e343b1 100644 --- a/src/core/course/formats/weeks/providers/handler.ts +++ b/src/core/course/formats/weeks/providers/handler.ts @@ -22,7 +22,8 @@ import { CoreConstants } from '../../../../constants'; */ @Injectable() export class CoreCourseFormatWeeksHandler implements CoreCourseFormatHandler { - name = 'weeks'; + name = 'CoreCourseFormatWeeks'; + format = 'weeks'; constructor(private timeUtils: CoreTimeUtilsProvider) { } diff --git a/src/core/course/providers/default-format.ts b/src/core/course/providers/default-format.ts index 2e9a58a17..c8e596d22 100644 --- a/src/core/course/providers/default-format.ts +++ b/src/core/course/providers/default-format.ts @@ -23,7 +23,8 @@ import { CoreCourseProvider } from './course'; */ @Injectable() export class CoreCourseFormatDefaultHandler implements CoreCourseFormatHandler { - name = 'default'; + name = 'CoreCourseFormatDefault'; + format = 'default'; constructor(private coursesProvider: CoreCoursesProvider) { } diff --git a/src/core/course/providers/format-delegate.ts b/src/core/course/providers/format-delegate.ts index 55f064f2a..7154e3290 100644 --- a/src/core/course/providers/format-delegate.ts +++ b/src/core/course/providers/format-delegate.ts @@ -25,6 +25,12 @@ import { CoreDelegate, CoreDelegateHandler } from '@classes/delegate'; * Interface that all course format handlers must implement. */ export interface CoreCourseFormatHandler extends CoreDelegateHandler { + /** + * Name of the format the handler supports. E.g. 'singleactivity'. + * @type {string} + */ + format: string; + /** * Get the title to use in course page. If not defined, course fullname. * This function will be called without sections first, and then call it again when the sections are retrieved. @@ -151,7 +157,8 @@ export interface CoreCourseFormatHandler extends CoreDelegateHandler { export class CoreCourseFormatDelegate extends CoreDelegate { protected handlers: { [s: string]: CoreCourseFormatHandler } = {}; // All registered handlers. protected enabledHandlers: { [s: string]: CoreCourseFormatHandler } = {}; // Handlers enabled for the current site. - protected featurePrefix = 'CoreCourseFormatHandler_'; + protected featurePrefix = 'CoreCourseFormatDelegate_'; + protected handlerNameProperty = 'format'; constructor(loggerProvider: CoreLoggerProvider, protected sitesProvider: CoreSitesProvider, eventsProvider: CoreEventsProvider, protected defaultHandler: CoreCourseFormatDefaultHandler) { diff --git a/src/core/course/providers/module-delegate.ts b/src/core/course/providers/module-delegate.ts index a162e1f0a..f6bbdc669 100644 --- a/src/core/course/providers/module-delegate.ts +++ b/src/core/course/providers/module-delegate.ts @@ -25,6 +25,12 @@ import { CoreDelegate, CoreDelegateHandler } from '@classes/delegate'; * Interface that all course module handlers must implement. */ export interface CoreCourseModuleHandler extends CoreDelegateHandler { + /** + * Name of the module. It should match the "modname" of the module returned in core_course_get_contents. + * @type {string} + */ + modName: string; + /** * Get the data required to display the module in the course contents view. * @@ -169,6 +175,7 @@ export class CoreCourseModuleDelegate extends CoreDelegate { protected handlers: { [s: string]: CoreCourseModuleHandler } = {}; // All registered handlers. protected enabledHandlers: { [s: string]: CoreCourseModuleHandler } = {}; // Handlers enabled for the current site. protected featurePrefix = 'CoreCourseModuleDelegate_'; + protected handlerNameProperty = 'modName'; constructor(loggerProvider: CoreLoggerProvider, protected sitesProvider: CoreSitesProvider, eventsProvider: CoreEventsProvider, protected courseProvider: CoreCourseProvider) { diff --git a/src/core/course/providers/module-prefetch-delegate.ts b/src/core/course/providers/module-prefetch-delegate.ts index 0fac45323..1e7c5e73f 100644 --- a/src/core/course/providers/module-prefetch-delegate.ts +++ b/src/core/course/providers/module-prefetch-delegate.ts @@ -56,6 +56,12 @@ export type CoreCourseModulesProgressFunction = (data: CoreCourseModulesProgress * Interface that all course prefetch handlers must implement. */ export interface CoreCourseModulePrefetchHandler extends CoreDelegateHandler { + /** + * Name of the module. It should match the "modname" of the module returned in core_course_get_contents. + * @type {string} + */ + modName: string; + /** * The handler's component. * @type {string} @@ -214,6 +220,7 @@ export class CoreCourseModulePrefetchDelegate extends CoreDelegate { protected ROOT_CACHE_KEY = 'mmCourse:'; protected statusCache = new CoreCache(); + protected handlerNameProperty = 'modName'; // Promises for check updates, to prevent performing the same request twice at the same time. protected courseUpdatesPromises: { [s: string]: { [s: string]: Promise } } = {}; diff --git a/src/core/siteplugins/classes/course-format-handler.ts b/src/core/siteplugins/classes/course-format-handler.ts index 91e3a5366..ed31e6db4 100644 --- a/src/core/siteplugins/classes/course-format-handler.ts +++ b/src/core/siteplugins/classes/course-format-handler.ts @@ -22,7 +22,7 @@ import { CoreSitePluginsCourseFormatComponent } from '../components/course-forma */ export class CoreSitePluginsCourseFormatHandler extends CoreSitePluginsBaseHandler implements CoreCourseFormatHandler { - constructor(name: string, protected handlerSchema: any) { + constructor(name: string, public format: string, protected handlerSchema: any) { super(name); } diff --git a/src/core/siteplugins/classes/module-handler.ts b/src/core/siteplugins/classes/module-handler.ts index 69ec55ba8..ee09ead5f 100644 --- a/src/core/siteplugins/classes/module-handler.ts +++ b/src/core/siteplugins/classes/module-handler.ts @@ -24,7 +24,7 @@ import { CoreSitePluginsModuleIndexComponent } from '../components/module-index/ export class CoreSitePluginsModuleHandler extends CoreSitePluginsBaseHandler implements CoreCourseModuleHandler { priority: number; - constructor(name: string, protected handlerSchema: any) { + constructor(name: string, public modName: string, protected handlerSchema: any) { super(name); } diff --git a/src/core/siteplugins/classes/module-prefetch-handler.ts b/src/core/siteplugins/classes/module-prefetch-handler.ts index e309067e6..a6d6d836f 100644 --- a/src/core/siteplugins/classes/module-prefetch-handler.ts +++ b/src/core/siteplugins/classes/module-prefetch-handler.ts @@ -22,12 +22,13 @@ import { CoreCourseModulePrefetchHandlerBase } from '@core/course/classes/module export class CoreSitePluginsModulePrefetchHandler extends CoreCourseModulePrefetchHandlerBase { protected ROOT_CACHE_KEY = 'CoreSitePluginsModulePrefetchHandler:'; - constructor(injector: Injector, protected sitePluginsProvider: CoreSitePluginsProvider, component: string, modName: string, - protected handlerSchema: any) { + constructor(injector: Injector, protected sitePluginsProvider: CoreSitePluginsProvider, component: string, name: string, + modName: string, protected handlerSchema: any) { super(injector); this.component = component; - this.name = modName; + this.name = name; + this.modName = modName; this.isResource = handlerSchema.isresource; if (handlerSchema.updatesnames) { diff --git a/src/core/siteplugins/classes/user-profile-field-handler.ts b/src/core/siteplugins/classes/user-profile-field-handler.ts index 9fd8ed73b..36ae73268 100644 --- a/src/core/siteplugins/classes/user-profile-field-handler.ts +++ b/src/core/siteplugins/classes/user-profile-field-handler.ts @@ -22,7 +22,7 @@ import { CoreSitePluginsUserProfileFieldComponent } from '../components/user-pro */ export class CoreSitePluginsUserProfileFieldHandler extends CoreSitePluginsBaseHandler implements CoreUserProfileFieldHandler { - constructor(name: string) { + constructor(name: string, public type: string) { super(name); } diff --git a/src/core/siteplugins/providers/helper.ts b/src/core/siteplugins/providers/helper.ts index 88f1c0013..95cffee2d 100644 --- a/src/core/siteplugins/providers/helper.ts +++ b/src/core/siteplugins/providers/helper.ts @@ -353,8 +353,9 @@ export class CoreSitePluginsHelperProvider { this.logger.debug('Register site plugin in course format delegate:', plugin, handlerSchema, bootstrapResult); // Create and register the handler. - const formatName = plugin.component.replace('format_', ''); - this.courseFormatDelegate.registerHandler(new CoreSitePluginsCourseFormatHandler(formatName, handlerSchema)); + const uniqueName = this.sitePluginsProvider.getHandlerUniqueName(plugin, handlerName), + formatName = plugin.component.replace('format_', ''); + this.courseFormatDelegate.registerHandler(new CoreSitePluginsCourseFormatHandler(uniqueName, formatName, handlerSchema)); return formatName; } @@ -437,14 +438,15 @@ export class CoreSitePluginsHelperProvider { this.logger.debug('Register site plugin in module delegate:', plugin, handlerSchema, bootstrapResult); // Create and register the handler. - const modName = plugin.component.replace('mod_', ''); + const uniqueName = this.sitePluginsProvider.getHandlerUniqueName(plugin, handlerName), + modName = plugin.component.replace('mod_', ''); - this.moduleDelegate.registerHandler(new CoreSitePluginsModuleHandler(modName, handlerSchema)); + this.moduleDelegate.registerHandler(new CoreSitePluginsModuleHandler(uniqueName, modName, handlerSchema)); if (handlerSchema.offlinefunctions && Object.keys(handlerSchema.offlinefunctions).length) { // Register the prefetch handler. this.prefetchDelegate.registerHandler(new CoreSitePluginsModulePrefetchHandler( - this.injector, this.sitePluginsProvider, plugin.component, modName, handlerSchema)); + this.injector, this.sitePluginsProvider, plugin.component, uniqueName, modName, handlerSchema)); } return modName; @@ -502,8 +504,9 @@ export class CoreSitePluginsHelperProvider { // Execute the main method and its JS. The template returned will be used in the profile field component. return this.executeMethodAndJS(plugin, handlerSchema.method).then((result) => { // Create and register the handler. - const fieldType = plugin.component.replace('profilefield_', ''), - fieldHandler = new CoreSitePluginsUserProfileFieldHandler(fieldType); + const uniqueName = this.sitePluginsProvider.getHandlerUniqueName(plugin, handlerName), + fieldType = plugin.component.replace('profilefield_', ''), + fieldHandler = new CoreSitePluginsUserProfileFieldHandler(uniqueName, fieldType); // Store in handlerSchema some data required by the component. handlerSchema.methodTemplates = result.templates; diff --git a/src/core/user/providers/user-profile-field-delegate.ts b/src/core/user/providers/user-profile-field-delegate.ts index b8ba951c8..2cc3a5f4a 100644 --- a/src/core/user/providers/user-profile-field-delegate.ts +++ b/src/core/user/providers/user-profile-field-delegate.ts @@ -19,6 +19,11 @@ import { CoreSitesProvider } from '@providers/sites'; import { CoreEventsProvider } from '@providers/events'; export interface CoreUserProfileFieldHandler extends CoreDelegateHandler { + /** + * Type of the field the handler supports. E.g. 'checkbox'. + * @type {string} + */ + type: string; /** * Return the Component to use to display the user profile field. @@ -68,6 +73,7 @@ export interface CoreUserProfileFieldHandlerData { export class CoreUserProfileFieldDelegate extends CoreDelegate { protected handlers: { [s: string]: CoreUserProfileFieldHandler } = {}; protected enabledHandlers: { [s: string]: CoreUserProfileFieldHandler } = {}; + protected handlerNameProperty = 'type'; constructor(protected loggerProvider: CoreLoggerProvider, protected sitesProvider: CoreSitesProvider, protected eventsProvider: CoreEventsProvider) {