From dbbd2b54c46172b9ff655b954c425a18e5ea119e Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Sun, 16 Oct 2022 13:09:26 +0200 Subject: [PATCH] Fixed load menu #70 --- kdb-web/src/app/app.component.ts | 1 - .../app/components/sidebar/sidebar.component.ts | 15 +++++++-------- kdb-web/src/app/services/theme/theme.service.ts | 7 +++---- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/kdb-web/src/app/app.component.ts b/kdb-web/src/app/app.component.ts index 4bf34152..22a6a7cd 100644 --- a/kdb-web/src/app/app.component.ts +++ b/kdb-web/src/app/app.component.ts @@ -31,7 +31,6 @@ export class AppComponent implements OnInit { this.socket.startSocket(); this.themeService.loadTheme(); - this.themeService.loadMenu(); } diff --git a/kdb-web/src/app/components/sidebar/sidebar.component.ts b/kdb-web/src/app/components/sidebar/sidebar.component.ts index ddc840ea..cbf13c6f 100644 --- a/kdb-web/src/app/components/sidebar/sidebar.component.ts +++ b/kdb-web/src/app/components/sidebar/sidebar.component.ts @@ -20,33 +20,32 @@ export class SidebarComponent implements OnInit { private authService: AuthService, private translateService: TranslateService, private themeService: ThemeService - ) { } - - ngOnInit(): void { + ) { this.themeService.isSidebarOpen$.subscribe(value => { this.isSidebarOpen = value; this.setMenu(); }); - this.translateService.onLangChange.subscribe((event: LangChangeEvent) => { this.setMenu(); }); - this.setMenu(); + } + + ngOnInit(): void { + this.themeService.loadMenu(); } setMenu() { - this.authService.hasUserPermission(AuthRoles.Admin).then(hasPermission => { this.menuItems = []; this.menuItems = [ { label: this.isSidebarOpen ? this.translateService.instant('sidebar.dashboard') : '', icon: 'pi pi-th-large', routerLink: 'dashboard' }, ]; - + if (!hasPermission) { return; } - + this.menuItems.push( { separator: true }, { label: this.isSidebarOpen ? this.translateService.instant('sidebar.config') : '', icon: 'pi pi-cog', routerLink: '/admin/settings' }, diff --git a/kdb-web/src/app/services/theme/theme.service.ts b/kdb-web/src/app/services/theme/theme.service.ts index 0d3dae59..914ba774 100644 --- a/kdb-web/src/app/services/theme/theme.service.ts +++ b/kdb-web/src/app/services/theme/theme.service.ts @@ -27,13 +27,13 @@ export class ThemeService { }); this.isSidebarOpen$.subscribe(isSidebarOpen => { this.isSidebarOpen = isSidebarOpen; + this.sidebarWidth$.next(isSidebarOpen ? '150px' : '50px'); }); this.sidebarWidth$.subscribe(sidebarWidth => { this.sidebarWidth = sidebarWidth; }); - + this.loadTheme(); - this.loadMenu(); } loadTheme(): void { @@ -87,7 +87,7 @@ export class ThemeService { let isMenuOpen = true; let isMenuOpenStr = localStorage.getItem(`${mail}_isMenuOpen`); if (isMenuOpenStr) { - isMenuOpen = Boolean(isMenuOpenStr); + isMenuOpen = JSON.parse(isMenuOpenStr); } this.setIsMenuOpen(isMenuOpen); @@ -107,7 +107,6 @@ export class ThemeService { } setSideWidth(isSidebarOpen: boolean): void { - this.sidebarWidth$.next(isSidebarOpen ? '150px' : '50px'); this.isSidebarOpen$.next(isSidebarOpen); } }