diff --git a/src/addons/badges/services/handlers/user.ts b/src/addons/badges/services/handlers/user.ts index f9f357ce2..54cf3e552 100644 --- a/src/addons/badges/services/handlers/user.ts +++ b/src/addons/badges/services/handlers/user.ts @@ -16,9 +16,9 @@ import { Injectable } from '@angular/core'; import { CoreCourseUserAdminOrNavOptionIndexed } from '@features/courses/services/courses'; import { CoreUserDelegateContext, - CoreUserDelegateService, CoreUserProfileHandler, CoreUserProfileHandlerData, + CoreUserProfileHandlerType, } from '@features/user/services/user-delegate'; import { CoreNavigator } from '@services/navigator'; import { CoreSites } from '@services/sites'; @@ -33,7 +33,7 @@ export class AddonBadgesUserHandlerService implements CoreUserProfileHandler { name = 'AddonBadges:fakename'; // This name doesn't match any disabled feature, they'll be checked in isEnabledForContext. priority = 300; - type = CoreUserDelegateService.TYPE_NEW_PAGE; + type = CoreUserProfileHandlerType.LIST_ITEM; /** * @inheritdoc diff --git a/src/addons/blog/services/handlers/user.ts b/src/addons/blog/services/handlers/user.ts index f2b5e75de..85b81f942 100644 --- a/src/addons/blog/services/handlers/user.ts +++ b/src/addons/blog/services/handlers/user.ts @@ -16,7 +16,7 @@ import { Injectable } from '@angular/core'; import { CoreUserProfileHandler, CoreUserProfileHandlerData, - CoreUserDelegateService, + CoreUserProfileHandlerType, CoreUserDelegateContext, } from '@features/user/services/user-delegate'; import { CoreNavigator } from '@services/navigator'; @@ -32,7 +32,7 @@ export class AddonBlogUserHandlerService implements CoreUserProfileHandler { name = 'AddonBlog'; // This name doesn't match any disabled feature, they'll be checked in isEnabledForContext. priority = 200; - type = CoreUserDelegateService.TYPE_NEW_PAGE; + type = CoreUserProfileHandlerType.LIST_ITEM; /** * @inheritdoc diff --git a/src/addons/competency/services/handlers/user.ts b/src/addons/competency/services/handlers/user.ts index dbae1b0a8..9cd7df793 100644 --- a/src/addons/competency/services/handlers/user.ts +++ b/src/addons/competency/services/handlers/user.ts @@ -18,7 +18,7 @@ import { COURSE_PAGE_NAME } from '@features/course/course.module'; import { CoreUserProfile } from '@features/user/services/user'; import { CoreUserProfileHandler, - CoreUserDelegateService, + CoreUserProfileHandlerType, CoreUserProfileHandlerData, CoreUserDelegateContext, } from '@features/user/services/user-delegate'; @@ -36,7 +36,7 @@ export class AddonCompetencyUserHandlerService implements CoreUserProfileHandler name = 'AddonCompetency'; // This name doesn't match any disabled feature, they'll be checked in isEnabledForContext. priority = 100; - type = CoreUserDelegateService.TYPE_NEW_PAGE; + type = CoreUserProfileHandlerType.LIST_ITEM; cacheEnabled = true; /** diff --git a/src/addons/coursecompletion/services/handlers/user.ts b/src/addons/coursecompletion/services/handlers/user.ts index a31b5dc44..322274482 100644 --- a/src/addons/coursecompletion/services/handlers/user.ts +++ b/src/addons/coursecompletion/services/handlers/user.ts @@ -16,7 +16,7 @@ import { Injectable } from '@angular/core'; import { CoreUserProfile } from '@features/user/services/user'; import { CoreUserProfileHandler, - CoreUserDelegateService, + CoreUserProfileHandlerType, CoreUserProfileHandlerData, CoreUserDelegateContext, } from '@features/user/services/user-delegate'; @@ -31,7 +31,7 @@ import { AddonCourseCompletion } from '../coursecompletion'; export class AddonCourseCompletionUserHandlerService implements CoreUserProfileHandler { name = 'AddonCourseCompletion:viewCompletion'; - type = CoreUserDelegateService.TYPE_NEW_PAGE; + type = CoreUserProfileHandlerType.LIST_ITEM; priority = 350; cacheEnabled = true; diff --git a/src/addons/messages/services/handlers/user-send-message.ts b/src/addons/messages/services/handlers/user-send-message.ts index b7a677645..d217fe580 100644 --- a/src/addons/messages/services/handlers/user-send-message.ts +++ b/src/addons/messages/services/handlers/user-send-message.ts @@ -15,7 +15,11 @@ import { Injectable } from '@angular/core'; import { Params } from '@angular/router'; import { CoreUserProfile } from '@features/user/services/user'; -import { CoreUserDelegateService, CoreUserProfileHandler, CoreUserProfileHandlerData } from '@features/user/services/user-delegate'; +import { + CoreUserProfileHandlerType, + CoreUserProfileHandler, + CoreUserProfileHandlerData, +} from '@features/user/services/user-delegate'; import { CoreNavigator } from '@services/navigator'; import { CoreSites } from '@services/sites'; import { makeSingleton } from '@singletons'; @@ -29,7 +33,7 @@ export class AddonMessagesSendMessageUserHandlerService implements CoreUserProfi name = 'AddonMessages:sendMessage'; priority = 1000; - type = CoreUserDelegateService.TYPE_COMMUNICATION; + type = CoreUserProfileHandlerType.BUTTON; /** * @inheritdoc diff --git a/src/addons/notes/services/handlers/user.ts b/src/addons/notes/services/handlers/user.ts index 6626ba29b..399e37310 100644 --- a/src/addons/notes/services/handlers/user.ts +++ b/src/addons/notes/services/handlers/user.ts @@ -16,7 +16,7 @@ import { Injectable } from '@angular/core'; import { CoreUserProfile } from '@features/user/services/user'; import { CoreUserProfileHandler, - CoreUserDelegateService, + CoreUserProfileHandlerType, CoreUserProfileHandlerData, CoreUserDelegateContext, } from '@features/user/services/user-delegate'; @@ -33,7 +33,7 @@ export class AddonNotesUserHandlerService implements CoreUserProfileHandler { name = 'AddonNotes:notes'; priority = 250; - type = CoreUserDelegateService.TYPE_NEW_PAGE; + type = CoreUserProfileHandlerType.LIST_ITEM; cacheEnabled = true; /** diff --git a/src/addons/privatefiles/services/handlers/user.ts b/src/addons/privatefiles/services/handlers/user.ts index 5aad0dd54..81387cdea 100644 --- a/src/addons/privatefiles/services/handlers/user.ts +++ b/src/addons/privatefiles/services/handlers/user.ts @@ -18,7 +18,7 @@ import { AddonPrivateFiles } from '@addons/privatefiles/services/privatefiles'; import { makeSingleton } from '@singletons'; import { CoreUserDelegateContext, - CoreUserDelegateService, + CoreUserProfileHandlerType, CoreUserProfileHandler, CoreUserProfileHandlerData, } from '@features/user/services/user-delegate'; @@ -36,7 +36,7 @@ export class AddonPrivateFilesUserHandlerService implements CoreUserProfileHandl name = 'AddonPrivateFiles'; priority = 400; - type = CoreUserDelegateService.TYPE_NEW_PAGE; + type = CoreUserProfileHandlerType.LIST_ITEM; cacheEnabled = true; /** diff --git a/src/core/features/dataprivacy/services/handlers/user.ts b/src/core/features/dataprivacy/services/handlers/user.ts index fbb6bcd3f..60698c03d 100644 --- a/src/core/features/dataprivacy/services/handlers/user.ts +++ b/src/core/features/dataprivacy/services/handlers/user.ts @@ -13,7 +13,11 @@ // limitations under the License. import { Injectable } from '@angular/core'; -import { CoreUserDelegateService, CoreUserProfileHandler, CoreUserProfileHandlerData } from '@features/user/services/user-delegate'; +import { + CoreUserProfileHandlerType, + CoreUserProfileHandler, + CoreUserProfileHandlerData, +} from '@features/user/services/user-delegate'; import { CoreNavigator } from '@services/navigator'; import { makeSingleton } from '@singletons'; import { CoreDataPrivacy } from '../dataprivacy'; @@ -27,7 +31,7 @@ export class CoreDataPrivacyUserHandlerService implements CoreUserProfileHandler protected pageName = CORE_DATAPRIVACY_PAGE_NAME; - type = CoreUserDelegateService.TYPE_NEW_PAGE; + type = CoreUserProfileHandlerType.LIST_ACCOUNT_ITEM; name = 'CoreDataPrivacyDelegate'; priority = 100; diff --git a/src/core/features/grades/services/handlers/user.ts b/src/core/features/grades/services/handlers/user.ts index ade60adf5..247e255e9 100644 --- a/src/core/features/grades/services/handlers/user.ts +++ b/src/core/features/grades/services/handlers/user.ts @@ -19,7 +19,7 @@ import { CoreGrades } from '@features/grades/services/grades'; import { CoreUserProfile } from '@features/user/services/user'; import { CoreUserDelegateContext, - CoreUserDelegateService , + CoreUserProfileHandlerType , CoreUserProfileHandler, CoreUserProfileHandlerData, } from '@features/user/services/user-delegate'; @@ -38,7 +38,7 @@ export class CoreGradesUserHandlerService implements CoreUserProfileHandler { name = 'CoreGrades'; // This name doesn't match any disabled feature, they'll be checked in isEnabledForContext. priority = 500; - type = CoreUserDelegateService.TYPE_NEW_PAGE; + type = CoreUserProfileHandlerType.LIST_ITEM; cacheEnabled = true; /** diff --git a/src/core/features/mainmenu/components/user-menu/user-menu.html b/src/core/features/mainmenu/components/user-menu/user-menu.html index 04bacc312..70b2023c7 100644 --- a/src/core/features/mainmenu/components/user-menu/user-menu.html +++ b/src/core/features/mainmenu/components/user-menu/user-menu.html @@ -40,7 +40,7 @@ - @@ -48,12 +48,7 @@ - - - - - - + @if (handlers.length + accountHandlers.length > 0) { @@ -70,8 +65,35 @@ + + + } @else { + + + + + + } + + + + + class="core-user-menu-preferences core-user-menu-separator"> -
- +
+ - - - - - - - - diff --git a/src/core/features/user/pages/profile/profile.ts b/src/core/features/user/pages/profile/profile.ts index 64d97ed6a..8e61e47b9 100644 --- a/src/core/features/user/pages/profile/profile.ts +++ b/src/core/features/user/pages/profile/profile.ts @@ -25,7 +25,7 @@ import { CoreUserHelper } from '@features/user/services/user-helper'; import { CoreUserDelegate, CoreUserDelegateContext, - CoreUserDelegateService, + CoreUserProfileHandlerType, CoreUserProfileHandlerData, } from '@features/user/services/user-delegate'; import { CoreUtils } from '@services/utils/utils'; @@ -59,9 +59,8 @@ export class CoreUserProfilePage implements OnInit, OnDestroy { isSuspended = false; isEnrolled = true; rolesFormatted?: string; - actionHandlers: CoreUserProfileHandlerData[] = []; - newPageHandlers: CoreUserProfileHandlerData[] = []; - communicationHandlers: CoreUserProfileHandlerData[] = []; + listItemHandlers: CoreUserProfileHandlerData[] = []; + buttonHandlers: CoreUserProfileHandlerData[] = []; users?: CoreUserSwipeItemsManager; @@ -153,20 +152,19 @@ export class CoreUserProfilePage implements OnInit, OnDestroy { const context = this.courseId ? CoreUserDelegateContext.COURSE : CoreUserDelegateContext.SITE; this.subscription = CoreUserDelegate.getProfileHandlersFor(user, context, this.courseId).subscribe((handlers) => { - this.actionHandlers = []; - this.newPageHandlers = []; - this.communicationHandlers = []; + this.listItemHandlers = []; + this.buttonHandlers = []; handlers.forEach((handler) => { switch (handler.type) { - case CoreUserDelegateService.TYPE_COMMUNICATION: - this.communicationHandlers.push(handler.data); + case CoreUserProfileHandlerType.BUTTON: + this.buttonHandlers.push(handler.data); break; - case CoreUserDelegateService.TYPE_ACTION: - this.actionHandlers.push(handler.data); + case CoreUserProfileHandlerType.LIST_ACCOUNT_ITEM: + // Discard this for now. break; - case CoreUserDelegateService.TYPE_NEW_PAGE: + case CoreUserProfileHandlerType.LIST_ITEM: default: - this.newPageHandlers.push(handler.data); + this.listItemHandlers.push(handler.data); break; } }); diff --git a/src/core/features/user/services/handlers/profile-mail.ts b/src/core/features/user/services/handlers/profile-mail.ts index daba6ac66..7a23a58ef 100644 --- a/src/core/features/user/services/handlers/profile-mail.ts +++ b/src/core/features/user/services/handlers/profile-mail.ts @@ -14,7 +14,11 @@ import { Injectable } from '@angular/core'; -import { CoreUserDelegateService, CoreUserProfileHandler, CoreUserProfileHandlerData } from '../user-delegate'; +import { + CoreUserProfileHandlerType, + CoreUserProfileHandler, + CoreUserProfileHandlerData, +} from '../user-delegate'; import { CoreSites } from '@services/sites'; import { CoreUtils } from '@services/utils/utils'; import { CoreUserProfile } from '../user'; @@ -28,7 +32,7 @@ export class CoreUserProfileMailHandlerService implements CoreUserProfileHandler name = 'CoreUserProfileMail'; priority = 700; - type = CoreUserDelegateService.TYPE_COMMUNICATION; + type = CoreUserProfileHandlerType.BUTTON; /** * @inheritdoc diff --git a/src/core/features/user/services/user-delegate.ts b/src/core/features/user/services/user-delegate.ts index 3c8ea1f71..937cb5bf1 100644 --- a/src/core/features/user/services/user-delegate.ts +++ b/src/core/features/user/services/user-delegate.ts @@ -23,6 +23,12 @@ import { makeSingleton } from '@singletons'; import { CoreCourses, CoreCourseUserAdminOrNavOptionIndexed } from '@features/courses/services/courses'; import { CoreSites } from '@services/sites'; +export enum CoreUserProfileHandlerType { + LIST_ITEM = 'listitem', // User profile handler type to be shown as a list item. + LIST_ACCOUNT_ITEM = 'account_listitem', // User profile handler type to be shown as a list item and it's related to an account. + BUTTON = 'button', // User profile handler type to be shown as a button. +} + declare module '@singletons/events' { /** @@ -46,13 +52,11 @@ export interface CoreUserProfileHandler extends CoreDelegateHandler { priority: number; /** - * A type should be specified among these: - * - TYPE_COMMUNICATION: will be displayed under the user avatar. Should have icon. Spinner not used. - * - TYPE_NEW_PAGE: will be displayed as a list of items. Should have icon. Spinner not used. - * Default value if none is specified. - * - TYPE_ACTION: will be displayed as a button and should not redirect to any state. Spinner use is recommended. + * The type of Handler. + * + * @see CoreUserProfileHandlerType for more info. */ - type: string; + type: CoreUserProfileHandlerType; /** * If isEnabledForUser Cache should be enabled. @@ -106,7 +110,7 @@ export interface CoreUserProfileHandlerData { title: string; /** - * Name of the icon to display. Mandatory for TYPE_COMMUNICATION. + * Name of the icon to display. Mandatory for CoreUserProfileHandlerType.BUTTON. */ icon?: string; @@ -116,32 +120,34 @@ export interface CoreUserProfileHandlerData { class?: string; /** - * If enabled, element will be hidden. Only for TYPE_NEW_PAGE and TYPE_ACTION. + * If enabled, element will be hidden. Only for CoreUserProfileHandlerType.LIST_ITEM. */ hidden?: boolean; /** - * If enabled will show an spinner. Only for TYPE_ACTION. + * If enabled will show an spinner. + * + * @deprecated since 4.4. Not used anymore. */ spinner?: boolean; /** - * If the handler has badge to show or not. Only for TYPE_NEW_PAGE. + * If the handler has badge to show or not. Only for CoreUserProfileHandlerType.LIST_ITEM. */ showBadge?: boolean; /** - * Text to display on the badge. Only used if showBadge is true and only for TYPE_NEW_PAGE. + * Text to display on the badge. Only used if showBadge is true and only for CoreUserProfileHandlerType.LIST_ITEM. */ badge?: string; /** - * Accessibility text to add on the badge. Only used if showBadge is true and only for TYPE_NEW_PAGE. + * Accessibility text to add on the badge. Only used if showBadge is true and only for CoreUserProfileHandlerType.LIST_ITEM. */ badgeA11yText?: string; /** - * If true, the badge number is being loaded. Only used if showBadge is true and only for TYPE_NEW_PAGE. + * If true, the badge number is being loaded. Only used if showBadge is true and only for CoreUserProfileHandlerType.LIST_ITEM. */ loading?: boolean; @@ -195,14 +201,20 @@ export class CoreUserDelegateService extends CoreDelegate