Removed themeService from templates #70

This commit is contained in:
2022-10-16 12:57:27 +02:00
parent ba881aefa8
commit 1a3126dfc5
7 changed files with 91 additions and 56 deletions

View File

@@ -229,12 +229,14 @@ export class AuthService {
return false;
}
async hasUserPermission(role: AuthRoles): Promise<boolean> {
if (!role || !await this.isUserLoggedInAsync()) {
return false;
}
const token = this.getDecodedToken();
return AuthRoles[token['role']] === AuthRoles[role];
hasUserPermission(role: AuthRoles): Promise<boolean> {
return this.isUserLoggedInAsync().then(isLoggedIn => {
if (!role || !isLoggedIn) {
return false;
}
const token = this.getDecodedToken();
return AuthRoles[token['role']] === AuthRoles[role];
});
}
getEMailFromDecodedToken(token: { [key: string]: any }): string | null {

View File

@@ -1,4 +1,5 @@
import { Injectable } from '@angular/core';
import { LangChangeEvent, TranslateService } from '@ngx-translate/core';
import { Subject } from 'rxjs';
import { Themes } from 'src/app/models/view/themes.enum';
import { AuthService } from '../auth/auth.service';
@@ -8,23 +9,31 @@ import { AuthService } from '../auth/auth.service';
})
export class ThemeService {
themeName: string | null;
themeName: string = Themes.Default;
sidebarWidth = '150px';
isSidebarOpen = false;
hasLangChanged = false;
themeName$ = new Subject<string>();
isSidebarOpen$ = new Subject<boolean>();
sidebarWidth$ = new Subject<string>();
constructor(
private authService: AuthService
) {
this.isSidebarOpen$.subscribe(isSidebarOpen => {
this.isSidebarOpen = isSidebarOpen
this.themeName$.subscribe(themeName => {
this.themeName = themeName;
});
this.isSidebarOpen$.subscribe(isSidebarOpen => {
this.isSidebarOpen = isSidebarOpen;
});
this.sidebarWidth$.subscribe(sidebarWidth => {
this.sidebarWidth = sidebarWidth;
});
this.loadTheme();
this.loadMenu();
this.themeName = null;
}
loadTheme(): void {
@@ -53,7 +62,7 @@ export class ThemeService {
this.authService.isUserLoggedInAsync().then(result => {
if (!result) {
localStorage.setItem(`default_themeName`, Themes.Default);
this.themeName = Themes.Default;
this.themeName$.next(Themes.Default);
}
const token = this.authService.getDecodedToken();
@@ -62,7 +71,7 @@ export class ThemeService {
localStorage.setItem(`${mail}_themeName`, name);
}
localStorage.setItem(`default_themeName`, name);
this.themeName = name;
this.themeName$.next(name);
});
}
@@ -97,8 +106,8 @@ export class ThemeService {
this.setSideWidth(isMenuOpen);
}
setSideWidth($event: any): void {
this.sidebarWidth = $event ? '150px' : '50px';
this.isSidebarOpen$.next($event)
setSideWidth(isSidebarOpen: boolean): void {
this.sidebarWidth$.next(isSidebarOpen ? '150px' : '50px');
this.isSidebarOpen$.next(isSidebarOpen);
}
}