2021-07-04 01:33:58 +00:00
|
|
|
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';
|
2021-07-11 21:09:53 +00:00
|
|
|
import { LocalStorageService, SessionStorageService } from 'ngx-webstorage';
|
2021-07-04 01:33:58 +00:00
|
|
|
import { Router } from '@angular/router';
|
2021-07-06 02:15:58 +00:00
|
|
|
import { UsuarioExtraService } from 'app/entities/usuario-extra/service/usuario-extra.service';
|
|
|
|
import { UsuarioExtra } from 'app/entities/usuario-extra/usuario-extra.model';
|
2021-07-04 01:15:33 +00:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'jhi-sidebar',
|
|
|
|
templateUrl: './sidebar.component.html',
|
|
|
|
styleUrls: ['./sidebar.component.scss'],
|
|
|
|
})
|
2021-07-04 01:33:58 +00:00
|
|
|
export class SidebarComponent {
|
|
|
|
public menuAdmin: RouteInfo[] = ADMIN_ROUTES;
|
|
|
|
public menuUser: RouteInfo[] = USER_ROUTES;
|
2021-07-04 01:15:33 +00:00
|
|
|
|
2021-07-04 01:33:58 +00:00
|
|
|
inProduction?: boolean;
|
|
|
|
isNavbarCollapsed = true;
|
|
|
|
openAPIEnabled?: boolean;
|
|
|
|
version = '';
|
|
|
|
account: Account | null = null;
|
|
|
|
|
2021-07-06 02:15:58 +00:00
|
|
|
usuarioExtra: UsuarioExtra | null = null;
|
|
|
|
|
2021-07-04 01:33:58 +00:00
|
|
|
constructor(
|
|
|
|
private loginService: LoginService,
|
|
|
|
private sessionStorageService: SessionStorageService,
|
2021-07-11 21:09:53 +00:00
|
|
|
private localStorageService: LocalStorageService,
|
2021-07-04 01:33:58 +00:00
|
|
|
private accountService: AccountService,
|
|
|
|
private profileService: ProfileService,
|
2021-07-06 02:15:58 +00:00
|
|
|
private router: Router,
|
|
|
|
private usuarioExtraService: UsuarioExtraService
|
2021-07-04 01:33:58 +00:00
|
|
|
) {
|
|
|
|
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;
|
|
|
|
});
|
2021-07-06 02:15:58 +00:00
|
|
|
|
|
|
|
// Get jhi_user and usuario_extra information
|
|
|
|
this.accountService.getAuthenticationState().subscribe(account => {
|
|
|
|
this.account = account;
|
|
|
|
if (account !== null) {
|
|
|
|
this.usuarioExtraService.find(account.id).subscribe(usuarioExtra => {
|
|
|
|
this.usuarioExtra = usuarioExtra.body;
|
2021-07-24 02:56:13 +00:00
|
|
|
const fullName = this.usuarioExtra!.nombre;
|
|
|
|
const firstName = fullName?.split(' ')[0] === undefined ? '' : fullName?.split(' ')[0];
|
|
|
|
const lastName = fullName?.split(' ')[1] === undefined ? '' : fullName?.split(' ')[1];
|
|
|
|
|
|
|
|
this.usuarioExtra!.nombre = `${firstName} ${lastName}`;
|
2021-07-06 02:15:58 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2021-07-04 01:33:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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(['']);
|
2021-07-11 21:09:53 +00:00
|
|
|
this.localStorageService.clear('IsGoogle');
|
2021-07-04 01:33:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
toggleNavbar(): void {
|
|
|
|
this.isNavbarCollapsed = !this.isNavbarCollapsed;
|
|
|
|
}
|
2021-07-04 01:15:33 +00:00
|
|
|
}
|