put in ignore file
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
@if (currentUserS() && isAuth)
|
||||
{
|
||||
<div class="flex flex-column justify-between md:flex-row rounded" style="background-color:white">
|
||||
<div style="margin-top:5px;padding-right:35px; cursor: pointer;width: 400px;">
|
||||
<img (click)="onHome()" src="images/application_image.png" alt="Banner" style="height:60px;width:100%" />
|
||||
</div>
|
||||
<div class="flex justify-end items-end flex-row">
|
||||
<div class="flex-column">
|
||||
<label class=" flex justify-end items-end mr-1 mb-2 myname">{{loginUser}}</label>
|
||||
<div>
|
||||
<span class="md:hidden flex justify-end"> <!--hidden on md screen show on small-->
|
||||
<button type="button" pButton icon="pi pi-align-justify" (click)="onemenu.toggle($event);"></button>
|
||||
<p-menu #onemenu [popup]="true" [model]="oneMenu"></p-menu>
|
||||
</span>
|
||||
<span class="hidden md:inline-flex"> <!--hidden when small screen-->
|
||||
<p-buttonGroup >
|
||||
<button type="button" pButton icon="pi pi-slack" label="Home" (click)="onHome()"
|
||||
class="p-button-sm " [attr.disabled]="isHome?true:null"></button>
|
||||
<!--button *ngIf="hasRoleAdmin" type="button" pButton icon="pi pi-file" label="Report" (click)="onReport()"
|
||||
[attr.disabled]="isReport?true:null" class="p-button-sm "></button-->
|
||||
|
||||
<p-menu #reportmenu [popup]="true" [model]="reportMenu"></p-menu>
|
||||
<p-menu #sysmenu [popup]="true" [model]="systemMenu"></p-menu>
|
||||
|
||||
@if (hasRoleAdmin)
|
||||
{
|
||||
<button type="button" pButton icon="pi pi-chevron-down" iconPos="right" label="System"
|
||||
(click)="sysmenu.toggle($event);" class="p-button-sm ">
|
||||
<!--i class="pi pi-cog mr-2" style="font-size: 1rem"></i-->
|
||||
</button>
|
||||
}
|
||||
<button pButton type="button" icon="pi pi-power-off" iconPos="left" label="Logout"
|
||||
(click)="logout()" class="p-button-sm p"></button>
|
||||
</p-buttonGroup>
|
||||
</span>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
import { Component, OnInit, OnDestroy, effect, computed, Signal, } from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { MenuItem } from 'primeng/api';
|
||||
import { MenuModule } from 'primeng/menu';
|
||||
import { ButtonModule} from 'primeng/button';
|
||||
import { ButtonGroupModule } from 'primeng/buttongroup';
|
||||
import { Subscription } from 'rxjs';
|
||||
import { AuthenticationService } from '../user-services';
|
||||
import { Utils } from '../shares';
|
||||
import { User } from '../models';
|
||||
|
||||
|
||||
@Component({
|
||||
selector: 'app-toolbar',
|
||||
imports: [CommonModule, MenuModule, ButtonModule, ButtonGroupModule],
|
||||
templateUrl: './toolbar.component.html',
|
||||
styleUrl: './toolbar.component.css'
|
||||
})
|
||||
export class ToolbarComponent implements OnInit, OnDestroy {
|
||||
title = 'Safe Assessment Unit UI';
|
||||
isAuth = false;
|
||||
hasRoleAdmin = false;
|
||||
hasRoleReport = false;
|
||||
homeUrl = "/person";
|
||||
oneMenu: MenuItem[] = [];
|
||||
reportMenu: MenuItem[] = [];
|
||||
systemMenu: MenuItem[] = [];
|
||||
currentUserName = "";
|
||||
currentUserS: Signal<User> = computed (() => {
|
||||
const currentUser = this.authenticationService.authChange();
|
||||
this.isAuth =false;
|
||||
if (currentUser.username) {
|
||||
this.isAuth =true;
|
||||
this.assignRole(currentUser);
|
||||
console.log(`${this.title} on auth currentUser signal now ${this.isAuth}`);
|
||||
// add this to the one menu
|
||||
if (this.hasRoleAdmin) {
|
||||
|
||||
let i = 0;
|
||||
for (i = 0; i < this.systemMenu.length; i++) {
|
||||
this.oneMenu.push(this.systemMenu[i]);
|
||||
}
|
||||
|
||||
}
|
||||
//add the logout here
|
||||
this.oneMenu.push(
|
||||
{
|
||||
label: 'Logout', icon: 'pi pi-power-off', command: () => {
|
||||
this.logout()
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
return currentUser;
|
||||
});
|
||||
|
||||
private subscription: Subscription = new Subscription();
|
||||
constructor(
|
||||
private router: Router,
|
||||
private authenticationService: AuthenticationService
|
||||
) {
|
||||
this.authenticationService.isReport = false;
|
||||
this.authenticationService.isHome = true;
|
||||
}
|
||||
onHome(): void {
|
||||
this.authenticationService.isHome = true;
|
||||
this.router.navigate([this.homeUrl]);
|
||||
}
|
||||
get isHome(): boolean {
|
||||
return this.authenticationService.isHome;
|
||||
}
|
||||
get loginUser(): string {
|
||||
let result = "";
|
||||
let greeting = "Good ";
|
||||
const d = new Date();
|
||||
const hour = d.getHours();
|
||||
if (hour >= 5 && hour < 12)
|
||||
greeting = "Good morning, ";
|
||||
else if (hour >= 12 && hour < 17)
|
||||
greeting = "Good afternoon, ";
|
||||
else if (hour >= 17 && hour < 21)
|
||||
greeting = "Good evening, ";
|
||||
else
|
||||
greeting = "Good night, ";
|
||||
if (this.isAuth) {
|
||||
const user = Utils.getCurrentUser();
|
||||
result = user.firstName;
|
||||
}
|
||||
return greeting + result;
|
||||
}
|
||||
get isReport(): boolean {
|
||||
|
||||
return this.authenticationService.isReport;
|
||||
}
|
||||
initOneMenu(): void {
|
||||
this.oneMenu = [
|
||||
{
|
||||
label: 'Home', icon: 'pi pi-slack', command: () => {
|
||||
this.router.navigate([this.homeUrl]);
|
||||
|
||||
}
|
||||
}
|
||||
];
|
||||
}
|
||||
initSystemMenu(): void {
|
||||
this.systemMenu = [
|
||||
/*
|
||||
{
|
||||
label: 'Lookup', icon: 'pi pi-bars', command: () => {
|
||||
this.router.navigate(['/lookup']);
|
||||
this.authenticationService.isReport = false;
|
||||
this.authenticationService.isHome = false;
|
||||
}
|
||||
},
|
||||
{
|
||||
label: 'Waiting List', icon: 'pi pi-map-marker', command: () => {
|
||||
this.router.navigate(['/waitinglist']);
|
||||
this.authenticationService.isReport = false;
|
||||
this.authenticationService.isHome = false;
|
||||
}
|
||||
},
|
||||
*/
|
||||
{
|
||||
label: 'Person', icon: 'pi pi-users',
|
||||
command: () => {
|
||||
this.router.navigate(['/person']);
|
||||
|
||||
}
|
||||
},
|
||||
{
|
||||
label: 'Family tree', icon: 'pi pi-users',
|
||||
command: () => {
|
||||
this.router.navigate(['/familytree']);
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
label: 'Staff', icon: 'pi pi-users',
|
||||
command: () => {
|
||||
this.router.navigate(['/staff']);
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
logout(): void {
|
||||
this.initOneMenu();
|
||||
this.authenticationService.logout();
|
||||
this.router.navigate(['/login']);
|
||||
}
|
||||
assignRole(user: User): void {
|
||||
const userRole = Utils.getUserRole(user);
|
||||
this.hasRoleReport = Utils.canRunReport(userRole);
|
||||
this.currentUserName = user.firstName;
|
||||
//this.hasRoleAdmin = true;
|
||||
this.hasRoleAdmin = userRole == Utils.getAdminRoleName();
|
||||
//console.log(this.msg + " hasRoleAdmin ", this.hasRoleAdmin);
|
||||
|
||||
}
|
||||
ngOnInit(): void {
|
||||
this.initOneMenu();
|
||||
this.initSystemMenu();
|
||||
console.log("ngOnInit toolbar called");
|
||||
// this.initStart();
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.subscription.unsubscribe();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user