From 9446b64efdda4ec8293df1079e7b464ce8905128 Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Mon, 3 Apr 2023 12:15:49 +0300 Subject: [PATCH] Sidebar: Toggle active item if sidebar items have been changed. --- .../sidebar/sideBar.component.ts | 27 +++++++++++-------- .../users/role-users/role-users.component.ts | 1 - 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/dashboard/sharedComponents/sidebar/sideBar.component.ts b/dashboard/sharedComponents/sidebar/sideBar.component.ts index 49d0f622..2e0c8aa1 100644 --- a/dashboard/sharedComponents/sidebar/sideBar.component.ts +++ b/dashboard/sharedComponents/sidebar/sideBar.component.ts @@ -32,6 +32,7 @@ export class SideBarComponent implements OnInit, AfterViewInit, OnDestroy, OnCha @ViewChild("sidebar_offcanvas") sidebar_offcanvas: ElementRef; public properties = properties; private subscriptions: any[] = []; + private init: boolean = false; constructor(private route: ActivatedRoute, private router: Router, private sanitizer: DomSanitizer, private layoutService: LayoutService, @@ -48,18 +49,15 @@ export class SideBarComponent implements OnInit, AfterViewInit, OnDestroy, OnCha } ngAfterViewInit() { - if(this.nav && typeof UIkit !== "undefined") { - setTimeout(() => { - if(this.items[this.activeIndex]?.items?.length > 0) { - UIkit.nav(this.nav.nativeElement).toggle(this.activeIndex, true); - } - }); - } + this.toggle(true); } ngOnChanges(changes: SimpleChanges) { if(changes.activeItem || changes.activeSubItem || changes.items) { this.setActiveMenuItem(); + if(this.init && changes.items) { + this.toggle(); + } } } @@ -72,6 +70,17 @@ export class SideBarComponent implements OnInit, AfterViewInit, OnDestroy, OnCha }); } + toggle(init: boolean = false) { + this.init = this.init || init; + if(this.nav && typeof UIkit !== "undefined") { + setTimeout(() => { + if(this.items[this.activeIndex]?.items?.length > 0) { + UIkit.nav(this.nav.nativeElement).toggle(this.activeIndex, true); + } + }); + } + } + get isBrowser() { return this.platformId === 'browser'; } @@ -143,10 +152,6 @@ export class SideBarComponent implements OnInit, AfterViewInit, OnDestroy, OnCha } } - isTheActiveUrl(menuItemURL): boolean { - return (menuItemURL == this.router.url.split('?')[0]) - } - public get open() { return this.layoutService.open; } diff --git a/dashboard/users/role-users/role-users.component.ts b/dashboard/users/role-users/role-users.component.ts index 222f8530..9adb749d 100644 --- a/dashboard/users/role-users/role-users.component.ts +++ b/dashboard/users/role-users/role-users.component.ts @@ -77,7 +77,6 @@ export class RoleUsersComponent implements OnInit, OnDestroy, OnChanges { this.updateLists(); this.userManagementService.getUserInfo().subscribe(user => { this.user = user; - console.log(this.canDelete) }); }