MOBILE-4329 user: Rename user profile handler types
parent
dddc95bfc6
commit
cc2f238d68
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
</ion-label>
|
||||
</ion-item>
|
||||
|
||||
<ion-item button class="core-usermenu-handler ion-text-wrap" *ngIf="siteInfo" lines="full" (click)="openUserProfile($event)"
|
||||
<ion-item button class="core-usermenu-profile ion-text-wrap" *ngIf="siteInfo" lines="full" (click)="openUserProfile($event)"
|
||||
[detail]="true" [attr.aria-label]="'core.user.profile' | translate">
|
||||
<core-user-avatar [site]="siteInfo" [userId]="siteInfo.userid" [linkProfile]="false" slot="start" />
|
||||
<ion-label>
|
||||
|
@ -48,12 +48,7 @@
|
|||
</ion-label>
|
||||
</ion-item>
|
||||
|
||||
<ion-item class="ion-text-center" *ngIf="(!handlers || !handlers.length) && !handlersLoaded">
|
||||
<ion-label>
|
||||
<ion-spinner [attr.aria-label]="'core.loading' | translate" />
|
||||
</ion-label>
|
||||
</ion-item>
|
||||
|
||||
@if (handlers.length + accountHandlers.length > 0) {
|
||||
<ion-item button *ngFor="let handler of handlers" class="ion-text-wrap" (click)="handlerClicked($event, handler)"
|
||||
[ngClass]="['core-user-menu-handler', handler.class || '']" [hidden]="handler.hidden"
|
||||
[attr.aria-label]="handler.title | translate" [detail]="true">
|
||||
|
@ -70,8 +65,35 @@
|
|||
<ion-spinner slot="end" *ngIf="handler.showBadge && handler.loading" [attr.aria-label]="'core.loading' | translate" />
|
||||
</ion-item>
|
||||
|
||||
<ion-item button *ngFor="let handler of accountHandlers; let first = first" class="ion-text-wrap"
|
||||
(click)="handlerClicked($event, handler)"
|
||||
[ngClass]="['core-user-account-menu-handler', handler.class || '', first ? 'core-user-menu-separator' : '']"
|
||||
[hidden]="handler.hidden" [attr.aria-label]="handler.title | translate" [detail]="true">
|
||||
<ion-icon *ngIf="handler.icon" [name]="handler.icon" slot="start" aria-hidden="true" />
|
||||
<ion-label>
|
||||
<p class="item-heading">{{ handler.title | translate }}</p>
|
||||
</ion-label>
|
||||
<ion-badge slot="end" *ngIf="handler.showBadge" [hidden]="handler.loading || !handler.badge" aria-hidden="true">
|
||||
{{handler.badge}}
|
||||
</ion-badge>
|
||||
<span *ngIf="handler.showBadge && handler.badge && handler.badgeA11yText" class="sr-only">
|
||||
{{ handler.badgeA11yText | translate: {$a : handler.badge } }}
|
||||
</span>
|
||||
<ion-spinner slot="end" *ngIf="handler.showBadge && handler.loading" [attr.aria-label]="'core.loading' | translate" />
|
||||
</ion-item>
|
||||
} @else {
|
||||
<ion-item class="ion-text-center">
|
||||
<ion-label>
|
||||
<ion-spinner [attr.aria-label]="'core.loading' | translate" />
|
||||
</ion-label>
|
||||
</ion-item>
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
<ion-item button (click)="openPreferences($event)" [attr.aria-label]="'core.settings.preferences' | translate" [detail]="true"
|
||||
class="core-user-menu-preferences">
|
||||
class="core-user-menu-preferences core-user-menu-separator">
|
||||
<ion-icon name="fas-wrench" slot="start" aria-hidden="true" />
|
||||
<ion-label>
|
||||
<p class="item-heading">{{ 'core.settings.preferences' | translate }}</p>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
@use "theme/globals" as *;
|
||||
|
||||
:host {
|
||||
.core-user-menu-preferences {
|
||||
.core-user-menu-separator {
|
||||
--inner-border-width: 0;
|
||||
--border-width: 1px 0 0 0;
|
||||
}
|
||||
|
|
|
@ -25,12 +25,13 @@ import { CoreUser, CoreUserProfile } from '@features/user/services/user';
|
|||
import {
|
||||
CoreUserProfileHandlerData,
|
||||
CoreUserDelegate,
|
||||
CoreUserDelegateService,
|
||||
CoreUserProfileHandlerType,
|
||||
CoreUserDelegateContext,
|
||||
} from '@features/user/services/user-delegate';
|
||||
import { CoreNavigator } from '@services/navigator';
|
||||
import { CoreSites } from '@services/sites';
|
||||
import { CoreDomUtils } from '@services/utils/dom';
|
||||
import { CoreUtils } from '@services/utils/utils';
|
||||
import { ModalController, Translate } from '@singletons';
|
||||
import { Subscription } from 'rxjs';
|
||||
|
||||
|
@ -52,6 +53,7 @@ export class CoreMainMenuUserMenuComponent implements OnInit, OnDestroy {
|
|||
siteUrl?: string;
|
||||
displaySiteUrl = false;
|
||||
handlers: CoreUserProfileHandlerData[] = [];
|
||||
accountHandlers: CoreUserProfileHandlerData[] = [];
|
||||
handlersLoaded = false;
|
||||
user?: CoreUserProfile;
|
||||
displaySwitchAccount = true;
|
||||
|
@ -76,37 +78,48 @@ export class CoreMainMenuUserMenuComponent implements OnInit, OnDestroy {
|
|||
|
||||
this.loadSiteLogo(currentSite);
|
||||
|
||||
// Load the handlers.
|
||||
if (this.siteInfo) {
|
||||
try {
|
||||
this.user = await CoreUser.getProfile(this.siteInfo.userid);
|
||||
} catch {
|
||||
this.user = {
|
||||
id: this.siteInfo.userid,
|
||||
fullname: this.siteInfo.fullname,
|
||||
};
|
||||
}
|
||||
|
||||
this.subscription = CoreUserDelegate.getProfileHandlersFor(this.user, CoreUserDelegateContext.USER_MENU)
|
||||
.subscribe((handlers) => {
|
||||
if (!handlers || !this.user) {
|
||||
return;
|
||||
}
|
||||
|
||||
const newHandlers = handlers
|
||||
.filter((handler) => handler.type === CoreUserDelegateService.TYPE_NEW_PAGE)
|
||||
.map((handler) => handler.data);
|
||||
|
||||
// Only update handlers if they have changed, to prevent a blink effect.
|
||||
if (newHandlers.length !== this.handlers.length ||
|
||||
JSON.stringify(newHandlers) !== JSON.stringify(this.handlers)) {
|
||||
this.handlers = newHandlers;
|
||||
}
|
||||
|
||||
this.handlersLoaded = CoreUserDelegate.areHandlersLoaded(this.user.id, CoreUserDelegateContext.USER_MENU);
|
||||
});
|
||||
|
||||
if (!this.siteInfo) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Load the handlers.
|
||||
try {
|
||||
this.user = await CoreUser.getProfile(this.siteInfo.userid);
|
||||
} catch {
|
||||
this.user = {
|
||||
id: this.siteInfo.userid,
|
||||
fullname: this.siteInfo.fullname,
|
||||
};
|
||||
}
|
||||
|
||||
this.subscription = CoreUserDelegate.getProfileHandlersFor(this.user, CoreUserDelegateContext.USER_MENU)
|
||||
.subscribe((handlers) => {
|
||||
if (!handlers.length || !this.user) {
|
||||
return;
|
||||
}
|
||||
|
||||
let newHandlers = handlers
|
||||
.filter((handler) => handler.type === CoreUserProfileHandlerType.LIST_ITEM)
|
||||
.map((handler) => handler.data);
|
||||
|
||||
// Only update handlers if they have changed, to prevent a blink effect.
|
||||
if (newHandlers.length !== this.handlers.length ||
|
||||
JSON.stringify(newHandlers) !== JSON.stringify(this.handlers)) {
|
||||
this.handlers = newHandlers;
|
||||
}
|
||||
|
||||
newHandlers = handlers
|
||||
.filter((handler) => handler.type === CoreUserProfileHandlerType.LIST_ACCOUNT_ITEM)
|
||||
.map((handler) => handler.data);
|
||||
|
||||
// Only update handlers if they have changed, to prevent a blink effect.
|
||||
if (newHandlers.length !== this.handlers.length ||
|
||||
JSON.stringify(newHandlers) !== JSON.stringify(this.handlers)) {
|
||||
this.accountHandlers = newHandlers;
|
||||
}
|
||||
|
||||
this.handlersLoaded = CoreUserDelegate.areHandlersLoaded(this.user.id, CoreUserDelegateContext.USER_MENU);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -123,15 +136,9 @@ export class CoreMainMenuUserMenuComponent implements OnInit, OnDestroy {
|
|||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const siteConfig = await currentSite.getPublicConfig();
|
||||
|
||||
this.siteLogo = currentSite.getLogoUrl(siteConfig);
|
||||
} catch {
|
||||
// Ignore errors.
|
||||
} finally {
|
||||
this.siteLogoLoaded = true;
|
||||
}
|
||||
const siteConfig = await CoreUtils.ignoreErrors(currentSite.getPublicConfig());
|
||||
this.siteLogo = currentSite.getLogoUrl(siteConfig);
|
||||
this.siteLogoLoaded = true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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 { CoreReportBuilder } from '../reportbuilder';
|
||||
|
@ -26,7 +30,7 @@ export class CoreReportBuilderHandlerService implements CoreUserProfileHandler {
|
|||
|
||||
static readonly PAGE_NAME = 'reportbuilder';
|
||||
|
||||
type = CoreUserDelegateService.TYPE_NEW_PAGE;
|
||||
type = CoreUserProfileHandlerType.LIST_ITEM;
|
||||
cacheEnabled = true;
|
||||
name = 'CoreReportBuilderDelegate';
|
||||
priority = 350;
|
||||
|
|
|
@ -22,7 +22,7 @@ import {
|
|||
import { CoreUserProfile } from '@features/user/services/user';
|
||||
import {
|
||||
CoreUserDelegateContext,
|
||||
CoreUserDelegateService,
|
||||
CoreUserProfileHandlerType,
|
||||
CoreUserProfileHandler,
|
||||
CoreUserProfileHandlerData,
|
||||
} from '@features/user/services/user-delegate';
|
||||
|
@ -36,7 +36,7 @@ import { CoreSitePluginsBaseHandler } from './base-handler';
|
|||
export class CoreSitePluginsUserProfileHandler extends CoreSitePluginsBaseHandler implements CoreUserProfileHandler {
|
||||
|
||||
priority: number;
|
||||
type: string;
|
||||
type: CoreUserProfileHandlerType;
|
||||
|
||||
protected updatingDefer?: CorePromisedValue<void>;
|
||||
|
||||
|
@ -51,9 +51,10 @@ export class CoreSitePluginsUserProfileHandler extends CoreSitePluginsBaseHandle
|
|||
|
||||
this.priority = handlerSchema.priority || 0;
|
||||
|
||||
// Only support TYPE_COMMUNICATION and TYPE_NEW_PAGE.
|
||||
this.type = handlerSchema.type != CoreUserDelegateService.TYPE_COMMUNICATION ?
|
||||
CoreUserDelegateService.TYPE_NEW_PAGE : CoreUserDelegateService.TYPE_COMMUNICATION;
|
||||
// Only support LIST_ITEM and BUTTON.
|
||||
this.type = !handlerSchema.type || handlerSchema.type === CoreUserProfileHandlerType.LIST_ACCOUNT_ITEM
|
||||
? CoreUserProfileHandlerType.LIST_ITEM
|
||||
: handlerSchema.type;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -33,6 +33,7 @@ import { CorePromisedValue } from '@classes/promised-value';
|
|||
import { CorePlatform } from '@services/platform';
|
||||
import { CoreEnrolAction, CoreEnrolInfoIcon } from '@features/enrol/services/enrol-delegate';
|
||||
import { CoreSiteWSPreSets } from '@classes/sites/authenticated-site';
|
||||
import { CoreUserProfileHandlerType } from '@features/user/services/user-delegate';
|
||||
|
||||
const ROOT_CACHE_KEY = 'CoreSitePlugins:';
|
||||
|
||||
|
@ -907,7 +908,7 @@ export type CoreSitePluginsUserHandlerData = CoreSitePluginsHandlerCommonData &
|
|||
icon?: string;
|
||||
class?: string;
|
||||
};
|
||||
type?: string;
|
||||
type?: CoreUserProfileHandlerType;
|
||||
priority?: number;
|
||||
ptrenabled?: boolean;
|
||||
};
|
||||
|
|
|
@ -33,11 +33,10 @@
|
|||
</ion-label>
|
||||
</ion-item>
|
||||
|
||||
<div class="core-user-communication-handlers"
|
||||
*ngIf="(communicationHandlers && communicationHandlers.length) || isLoadingHandlers">
|
||||
<ion-item *ngIf="communicationHandlers && communicationHandlers.length">
|
||||
<div class="core-user-communication-handlers" *ngIf="(buttonHandlers && buttonHandlers.length) || isLoadingHandlers">
|
||||
<ion-item *ngIf="buttonHandlers && buttonHandlers.length">
|
||||
<ion-label>
|
||||
<ion-button *ngFor="let handler of communicationHandlers" expand="block" size="default"
|
||||
<ion-button *ngFor="let handler of buttonHandlers" expand="block" size="default"
|
||||
[ngClass]="['core-user-profile-handler', handler.class || '']" (click)="handlerClicked($event, handler)"
|
||||
[hidden]="handler.hidden" [attr.aria-label]="handler.title | translate" [disabled]="handler.spinner">
|
||||
<ion-icon *ngIf="handler.icon" [name]="handler.icon" slot="start" aria-hidden="true" />
|
||||
|
@ -61,7 +60,7 @@
|
|||
<ion-spinner [attr.aria-label]="'core.loading' | translate" />
|
||||
</ion-label>
|
||||
</ion-item>
|
||||
<ion-item button *ngFor="let handler of newPageHandlers" class="ion-text-wrap" (click)="handlerClicked($event, handler)"
|
||||
<ion-item button *ngFor="let handler of listItemHandlers" class="ion-text-wrap" (click)="handlerClicked($event, handler)"
|
||||
[ngClass]="['core-user-profile-handler', handler.class || '']" [hidden]="handler.hidden"
|
||||
[attr.aria-label]="handler.title | translate" [detail]="true">
|
||||
<ion-icon *ngIf="handler.icon" [name]="handler.icon" slot="start" aria-hidden="true" />
|
||||
|
@ -76,17 +75,6 @@
|
|||
</span>
|
||||
<ion-spinner slot="end" *ngIf="handler.showBadge && handler.loading" [attr.aria-label]="'core.loading' | translate" />
|
||||
</ion-item>
|
||||
<ion-item *ngIf="actionHandlers && actionHandlers.length">
|
||||
<ion-label>
|
||||
<ion-button *ngFor="let handler of actionHandlers" expand="block" fill="outline" size="default"
|
||||
[ngClass]="['core-user-profile-handler', handler.class || '']" (click)="handlerClicked($event, handler)"
|
||||
[hidden]="handler.hidden" [attr.aria-label]="handler.title | translate" [disabled]="handler.spinner">
|
||||
<ion-icon *ngIf="handler.icon" [name]="handler.icon" slot="start" aria-hidden="true" />
|
||||
{{ handler.title | translate }}
|
||||
<ion-spinner *ngIf="handler.spinner" slot="end" [attr.aria-label]="'core.loading' | translate" />
|
||||
</ion-button>
|
||||
</ion-label>
|
||||
</ion-item>
|
||||
</ion-list>
|
||||
<core-empty-box *ngIf="!user && !isDeleted && isEnrolled" icon="far-user"
|
||||
[message]=" 'core.user.detailsnotavailable' | translate" />
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<CoreUserProfileHandler
|
|||
|
||||
/**
|
||||
* User profile handler type for communication.
|
||||
*
|
||||
* @deprecated since 4.4. Use CoreUserProfileHandlerType.BUTTON instead.
|
||||
*/
|
||||
static readonly TYPE_COMMUNICATION = 'communication';
|
||||
/**
|
||||
* User profile handler type for new page.
|
||||
*
|
||||
* @deprecated since 4.4. Use CoreUserProfileHandlerType.LIST_ITEM instead.
|
||||
*/
|
||||
static readonly TYPE_NEW_PAGE = 'newpage';
|
||||
/**
|
||||
* User profile handler type for actions.
|
||||
*
|
||||
* @deprecated since 4.4. Use CoreUserProfileHandlerType.BUTTON instead.
|
||||
*/
|
||||
static readonly TYPE_ACTION = 'action';
|
||||
|
||||
|
@ -341,7 +353,7 @@ export class CoreUserDelegateService extends CoreDelegate<CoreUserProfileHandler
|
|||
name: name,
|
||||
data: handler.getDisplayData(user, context, courseId),
|
||||
priority: handler.priority || 0,
|
||||
type: handler.type || CoreUserDelegateService.TYPE_NEW_PAGE,
|
||||
type: handler.type || CoreUserProfileHandlerType.LIST_ITEM,
|
||||
});
|
||||
}
|
||||
} catch {
|
||||
|
@ -485,6 +497,24 @@ export class CoreUserDelegateService extends CoreDelegate<CoreUserProfileHandler
|
|||
return this.userHandlers[userId][contextKey];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
registerHandler(handler: CoreUserProfileHandler): boolean {
|
||||
const type = handler.type as string;
|
||||
|
||||
// eslint-disable-next-line deprecation/deprecation
|
||||
if (type == CoreUserDelegateService.TYPE_COMMUNICATION || type == CoreUserDelegateService.TYPE_ACTION) {
|
||||
handler.type = CoreUserProfileHandlerType.BUTTON;
|
||||
// eslint-disable-next-line deprecation/deprecation
|
||||
} else if (type == CoreUserDelegateService.TYPE_NEW_PAGE) {
|
||||
handler.type = CoreUserProfileHandlerType.LIST_ITEM;
|
||||
|
||||
}
|
||||
|
||||
return super.registerHandler(handler);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const CoreUserDelegate = makeSingleton(CoreUserDelegateService);
|
||||
|
|
Loading…
Reference in New Issue