diff --git a/HRM.UI/ClientApp/src/app/app.main.component.ts b/HRM.UI/ClientApp/src/app/app.main.component.ts index acc8828..6f86234 100644 --- a/HRM.UI/ClientApp/src/app/app.main.component.ts +++ b/HRM.UI/ClientApp/src/app/app.main.component.ts @@ -61,7 +61,7 @@ export class AppMainComponent { } if(user.UserType === "2"){ this.apiService.isSelService = true; - this.apiService.menuItems = this._auth.getUserMenu(); + this.apiService.menuItems = this.liftUnlabelledRootMenus(this._auth.getUserMenu()); } if(this.apiService.isSelService === true){ this.staticMenuDesktopInactive = true; @@ -74,6 +74,20 @@ export class AppMainComponent { } } } + // The server can send a top-level node with no label whose children are real top-level menus + // (e.g. "Dashboard"). Show those children in the topbar directly instead of under an empty parent. + liftUnlabelledRootMenus(menuItems: any[]): any[] { + const result: any[] = []; + (menuItems || []).forEach(item => { + const hasLabel = item.label && String(item.label).trim() !== ''; + if (!hasLabel && item.items && item.items.length > 0) { + result.push(...item.items); + } else if (hasLabel) { + result.push(item); + } + }); + return result; + } ProcessSelfServiceMenu(menuItems : any){ if(menuItems && menuItems.length > 0){ menuItems.forEach(item => { diff --git a/HRM.UI/ClientApp/src/app/app.menuitem.component.ts b/HRM.UI/ClientApp/src/app/app.menuitem.component.ts index 8fd5cf1..d9eb5ff 100644 --- a/HRM.UI/ClientApp/src/app/app.menuitem.component.ts +++ b/HRM.UI/ClientApp/src/app/app.menuitem.component.ts @@ -8,6 +8,7 @@ import {AppMainComponent} from './app.main.component'; import {RolePermission} from './_models/Authentication/role'; import { CommonModule } from '@angular/common'; import { RouterModule } from '@angular/router'; +import { JwtHelperService } from '@auth0/angular-jwt'; @Component({ /* tslint:disable:component-selector */ selector: '[app-menuitem]', @@ -119,9 +120,36 @@ export class AppMenuitemComponent implements OnInit, OnDestroy { key: string; + // SuperUser (UserType "0") only: every parent menu starts expanded and stays expanded when a + // child or another menu is clicked or the page changes; only clicking the parent itself toggles it. + private static superUserFlag: boolean | null = null; + private static superUserToken: string | null = null; + + private static isSuperUser(): boolean { + const token = localStorage.getItem('token'); + if (token !== AppMenuitemComponent.superUserToken) { + AppMenuitemComponent.superUserToken = token; + let userType: any = null; + try { + userType = token ? new JwtHelperService().decodeToken(token)?.UserType : null; + } catch (e) { + userType = null; + } + AppMenuitemComponent.superUserFlag = String(userType) === '0'; + } + return AppMenuitemComponent.superUserFlag === true; + } + + private get keepOpen(): boolean { + return !!(this.item && this.item.items) && AppMenuitemComponent.isSuperUser(); + } + constructor(public appMain: AppMainComponent, public router: Router, private cd: ChangeDetectorRef, private menuService: MenuService) { this.menuSourceSubscription = this.menuService.menuSource$.subscribe(key => { + if (this.keepOpen) { + return; + } // deactivate current active menu if (this.active && this.key !== key && key.indexOf(this.key) !== 0) { this.active = false; @@ -129,12 +157,17 @@ export class AppMenuitemComponent implements OnInit, OnDestroy { }); this.menuResetSubscription = this.menuService.resetSource$.subscribe(() => { - + if (this.keepOpen) { + return; + } this.active = false; }); this.router.events.pipe(filter(event => event instanceof NavigationEnd)) .subscribe(params => { + if (this.keepOpen) { + return; + } if (this.appMain.isHorizontal()) { this.active = false; @@ -166,7 +199,9 @@ export class AppMenuitemComponent implements OnInit, OnDestroy { } ngOnInit() { - if (!this.appMain.isHorizontal() && this.item.routerLink) { + if (this.keepOpen) { + this.active = true; + } else if (!this.appMain.isHorizontal() && this.item.routerLink) { this.updateActiveStateFromRoute(); } diff --git a/HRM.UI/ClientApp/src/app/app.topbar.component.html b/HRM.UI/ClientApp/src/app/app.topbar.component.html index 9f3afd0..e25b04d 100644 --- a/HRM.UI/ClientApp/src/app/app.topbar.component.html +++ b/HRM.UI/ClientApp/src/app/app.topbar.component.html @@ -146,7 +146,7 @@ @if (sub.items?.length) {