datasurvey/src/main/webapp/app/layouts/sidebar/sidebar.component.ts

82 lines
2.3 KiB
TypeScript

import { userManagementRoute } from './../../admin/user-management/user-management.route';
import { Component, OnInit, AfterViewInit, AfterViewChecked, AfterContentInit } from '@angular/core';
import { RouteInfo, ADMIN_ROUTES, USER_ROUTES } from './sidebar.constants';
import { VERSION } from 'app/app.constants';
import { Account } from 'app/core/auth/account.model';
import { AccountService } from 'app/core/auth/account.service';
import { LoginService } from 'app/login/login.service';
import { ProfileService } from 'app/layouts/profiles/profile.service';
import { SessionStorageService } from 'ngx-webstorage';
import { Router } from '@angular/router';
@Component({
selector: 'jhi-sidebar',
templateUrl: './sidebar.component.html',
styleUrls: ['./sidebar.component.scss'],
})
export class SidebarComponent {
public menuAdmin: RouteInfo[] = ADMIN_ROUTES;
public menuUser: RouteInfo[] = USER_ROUTES;
inProduction?: boolean;
isNavbarCollapsed = true;
openAPIEnabled?: boolean;
version = '';
account: Account | null = null;
constructor(
private loginService: LoginService,
private sessionStorageService: SessionStorageService,
private accountService: AccountService,
private profileService: ProfileService,
private router: Router
) {
if (VERSION) {
this.version = VERSION.toLowerCase().startsWith('v') ? VERSION : 'v' + VERSION;
}
}
isNotMobileMenu() {
if (window.outerWidth > 991) {
return false;
}
return true;
}
ngOnInit(): void {
this.profileService.getProfileInfo().subscribe(profileInfo => {
this.inProduction = profileInfo.inProduction;
this.openAPIEnabled = profileInfo.openAPIEnabled;
});
this.accountService.getAuthenticationState().subscribe(account => (this.account = account));
}
ngAfterViewInit() {}
isAdmin(): boolean {
return this.accountService.hasAnyAuthority('ROLE_ADMIN');
}
isAuthenticated(): boolean {
return this.accountService.isAuthenticated();
}
collapseNavbar(): void {
this.isNavbarCollapsed = true;
}
login(): void {
this.router.navigate(['/login']);
}
logout(): void {
this.collapseNavbar();
this.loginService.logout();
this.router.navigate(['']);
}
toggleNavbar(): void {
this.isNavbarCollapsed = !this.isNavbarCollapsed;
}
}