improve the text template of user menu

pull/11214/head
mehmet-erim 4 years ago
parent 570646a636
commit 25e23461e1

@ -48,8 +48,13 @@
</ng-template>
<ng-template #textTemplate>
<a (click)="item.action ? item.action() : null" class="dropdown-item pointer">
{{ item.text }}</a
<a
*ngIf="item.textTemplate"
(click)="item.action ? item.action() : null"
class="dropdown-item pointer"
>
<i *ngIf="item.textTemplate.icon" class="me-1 {{ item.textTemplate.icon }}"></i>
{{ item.textTemplate.text | abpLocalization }}</a
>
</ng-template>
</li>

@ -1,12 +1,6 @@
import {
AuthService,
ConfigStateService,
LocalizationService,
NAVIGATE_TO_MANAGE_PROFILE,
} from '@abp/ng.core';
import { AuthService, NAVIGATE_TO_MANAGE_PROFILE } from '@abp/ng.core';
import { UserMenuService } from '@abp/ng.theme.shared';
import { APP_INITIALIZER, Injector } from '@angular/core';
import { filter } from 'rxjs/operators';
import { eUserMenuItems } from '../enums/user-menu-items';
export const BASIC_THEME_USER_MENU_PROVIDERS = [
@ -19,41 +13,32 @@ export const BASIC_THEME_USER_MENU_PROVIDERS = [
];
export function configureUserMenu(injector: Injector) {
const configState = injector.get(ConfigStateService);
const userMenu = injector.get(UserMenuService);
const localization = injector.get(LocalizationService);
const authService = injector.get(AuthService);
const navigateToManageProfile = injector.get(NAVIGATE_TO_MANAGE_PROFILE);
return () => {
configState
.getAll$()
.pipe(filter(res => !!res?.localization))
.subscribe(() => {
userMenu.addItems([
{
id: eUserMenuItems.MyAccount,
order: 100,
html: `
<a class="dropdown-item pointer"
><i class="fa fa-cog me-1"></i>${localization.instant('AbpAccount::MyAccount')}</a
>
`,
action: () => navigateToManageProfile(),
},
{
id: eUserMenuItems.Logout,
order: 101,
html: `
<a class="dropdown-item" href="javascript:void(0)"
><i class="fa fa-power-off me-1"></i>${localization.instant('AbpUi::Logout')}</a
>
`,
action: () => {
authService.logout().subscribe();
},
},
]);
});
userMenu.addItems([
{
id: eUserMenuItems.MyAccount,
order: 100,
textTemplate: {
text: 'AbpAccount::MyAccount',
icon: 'fa fa-cog',
},
action: () => navigateToManageProfile(),
},
{
id: eUserMenuItems.Logout,
order: 101,
textTemplate: {
text: 'AbpUi::Logout',
icon: 'fa fa-power-off',
},
action: () => {
authService.logout().subscribe();
},
},
]);
};
}

@ -1,5 +1,10 @@
import { NavItem } from './nav-item';
export class UserMenu extends NavItem {
text?: string;
textTemplate?: UserMenuTextTemplate;
}
export interface UserMenuTextTemplate {
text: string;
icon?: string;
}

Loading…
Cancel
Save