118 lines
3.0 KiB
TypeScript
118 lines
3.0 KiB
TypeScript
import { AuthenticationService } from '../user-services';
|
|
import { Subscription } from 'rxjs'
|
|
import { Component, EventEmitter, Output, OnInit, OnDestroy, inject, signal } from '@angular/core';
|
|
import { Router, RouterModule } from '@angular/router';
|
|
import { Utils } from '../shares';
|
|
import { Bars } from '@primeicons/angular/bars';
|
|
|
|
import { MenuModule } from 'primeng/menu';
|
|
import { ButtonModule } from 'primeng/button';
|
|
import { MenuItem } from 'primeng/api';
|
|
|
|
@Component({
|
|
selector: 'app-nav-toolbar',
|
|
imports: [RouterModule, Bars, MenuModule, ButtonModule],
|
|
templateUrl: './nav-toolbar.component.html',
|
|
styleUrls: ['./nav-toolbar.component.css']
|
|
})
|
|
export class NavToolarComponent implements OnInit, OnDestroy {
|
|
isExpanded = false;
|
|
items: MenuItem[] | undefined;
|
|
isAuth = signal(false);
|
|
isAdmin = signal(false);
|
|
currentUserName = "";
|
|
authSubscription: Subscription = new Subscription;
|
|
@Output() toggleEvent: EventEmitter<boolean> = new EventEmitter();
|
|
private authService = inject(AuthenticationService);
|
|
|
|
constructor(
|
|
private router: Router) { }
|
|
|
|
ngOnInit() {
|
|
const currentUser = this.authService.authChange();
|
|
this.isAuth.set(false);
|
|
this.isAdmin.set(false);
|
|
if (currentUser.firstName != '') {
|
|
this.isAuth.set(Utils.getIsAuth());
|
|
this.isAdmin.set(Utils.getIsAdmin());
|
|
this.initValue();
|
|
this.currentUserName = currentUser.firstName + ' ' + currentUser.lastName;
|
|
}
|
|
else {
|
|
this.initValue();
|
|
}
|
|
|
|
}
|
|
|
|
initValue(): void {
|
|
this.items = [
|
|
{
|
|
label: 'Concession Validation',
|
|
icon: 'pi pi-user-edit',
|
|
command: () => {
|
|
this.router.navigate(['/concessionvalidation']);
|
|
}
|
|
},
|
|
{
|
|
label: 'Report',
|
|
icon: 'pi pi-user-edit',
|
|
command: () => {
|
|
this.router.navigate(['/app-concessionvalidation-report']);
|
|
}
|
|
}
|
|
];
|
|
if (this.isAdmin() == true) {
|
|
this.items.push({
|
|
label: 'Admin User',
|
|
icon: 'pi pi-user-edit',
|
|
command: () => {
|
|
this.router.navigate(['/adminuser']);
|
|
}
|
|
});
|
|
this.items.push({
|
|
label: 'Concession Type',
|
|
icon: 'pi pi-user-edit',
|
|
command: () => {
|
|
this.router.navigate(['/concessiontype']);
|
|
}
|
|
});
|
|
this.items.push({
|
|
label: 'Validation Point',
|
|
icon: 'pi pi-user-edit',
|
|
command: () => {
|
|
this.router.navigate(['/validationpoint']);
|
|
}
|
|
});
|
|
}
|
|
this.items.push({
|
|
label: 'Logout',
|
|
icon: 'pi pi-user-edit',
|
|
command: () => {
|
|
this.authService.logout();
|
|
this.router.navigate(['/login']);
|
|
}
|
|
});
|
|
}
|
|
|
|
ngOnDestroy() {
|
|
if (this.authSubscription) {
|
|
this.authSubscription.unsubscribe();
|
|
}
|
|
}
|
|
|
|
onHome() {
|
|
this.router.navigate(['/concessionvalidation']);
|
|
}
|
|
onToggle() {
|
|
this.isExpanded = !this.isExpanded;
|
|
this.toggleEvent.emit(this.isExpanded);
|
|
}
|
|
onLogout() {
|
|
this.authService.logout();
|
|
this.router.navigate(['/login']);
|
|
}
|
|
|
|
}
|
|
|
|
|