mirror of
https://github.com/akveo/ngx-admin.git
synced 2026-02-14 20:28:06 +01:00
fix(baSidebar): fix current selected menu
This commit is contained in:
parent
9312084fa4
commit
affc122a77
2 changed files with 8 additions and 17 deletions
|
|
@ -15,19 +15,19 @@ export class BaSidebarService {
|
|||
return this;
|
||||
}
|
||||
|
||||
public selectMenuItem(items:Array<any>, currentPath:string) {
|
||||
public selectMenuItem(items:Array<any>) {
|
||||
let currentMenu;
|
||||
|
||||
let assignCurrent = (menu) => (menu.selected ? currentMenu = menu : null);
|
||||
|
||||
items.forEach((menu: any) => {
|
||||
|
||||
this._selectItem(currentPath, [menu.component], menu);
|
||||
this._selectItem([menu.component], menu);
|
||||
assignCurrent(menu);
|
||||
|
||||
if (menu.subMenu) {
|
||||
menu.subMenu.forEach((subMenu) => {
|
||||
this._selectItem(currentPath, [menu.component, subMenu.component], subMenu, menu);
|
||||
this._selectItem([menu.component, subMenu.component], subMenu, menu);
|
||||
assignCurrent(subMenu);
|
||||
});
|
||||
}
|
||||
|
|
@ -35,9 +35,9 @@ export class BaSidebarService {
|
|||
return currentMenu;
|
||||
}
|
||||
|
||||
private _selectItem(currentPath, instructions, item, parentMenu = null) {
|
||||
private _selectItem(instructions, item, parentMenu = null) {
|
||||
let route = this._generateRoute(instructions);
|
||||
item.selected = !item.disabled && this._isCurrent(route) && this._resolvePath(route, '') == currentPath;
|
||||
item.selected = !item.disabled && this._isCurrent(route);
|
||||
if (parentMenu) {
|
||||
parentMenu.expanded = parentMenu.expanded || item.selected;
|
||||
}
|
||||
|
|
@ -50,13 +50,4 @@ export class BaSidebarService {
|
|||
private _generateRoute(instructions) {
|
||||
return instructions.filter(i => typeof i !== 'undefined').length > 0 ? this._router.generate(instructions) : null;
|
||||
}
|
||||
|
||||
private _resolvePath(instruction, collected) {
|
||||
if (instruction !== null) {
|
||||
collected += instruction.urlPath + '/';
|
||||
return this._resolvePath(instruction.child, collected)
|
||||
} else {
|
||||
return collected.slice(0, -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue