From 986880b23c0043be4b504b99ffd1f46d41a1bb96 Mon Sep 17 00:00:00 2001 From: Rodolphe_Lassalle Date: Tue, 11 Jun 2024 11:48:22 +0200 Subject: [PATCH] mise a jour directive --- .../app/components/auth/login/login.component.ts | 2 +- .../list-prospects/list-prospects.component.html | 4 ++-- .../list-prospects/list-prospects.component.ts | 3 --- frontend/src/app/services/auth/auth.service.ts | 4 ++-- frontend/src/app/services/auth/identity.service.ts | 6 ++++-- .../shared/components/topbar/topbar.component.html | 3 +++ .../shared/components/topbar/topbar.component.ts | 14 +++++++++++++- 7 files changed, 25 insertions(+), 11 deletions(-) diff --git a/frontend/src/app/components/auth/login/login.component.ts b/frontend/src/app/components/auth/login/login.component.ts index a2457bd..11fc9ba 100644 --- a/frontend/src/app/components/auth/login/login.component.ts +++ b/frontend/src/app/components/auth/login/login.component.ts @@ -41,7 +41,7 @@ export class LoginComponent { }); this.loginVisible = false; - console.log(this.auth.getUserId()); + console.log(this.auth.getRole()); this.router.navigate(['/prospect']); }, error => { diff --git a/frontend/src/app/components/list-prospects/list-prospects.component.html b/frontend/src/app/components/list-prospects/list-prospects.component.html index 798d922..51ca247 100644 --- a/frontend/src/app/components/list-prospects/list-prospects.component.html +++ b/frontend/src/app/components/list-prospects/list-prospects.component.html @@ -121,8 +121,8 @@ } @else {
- +
} diff --git a/frontend/src/app/components/list-prospects/list-prospects.component.ts b/frontend/src/app/components/list-prospects/list-prospects.component.ts index df3aad8..769f38b 100644 --- a/frontend/src/app/components/list-prospects/list-prospects.component.ts +++ b/frontend/src/app/components/list-prospects/list-prospects.component.ts @@ -159,9 +159,6 @@ export class ListProspectsComponent implements OnInit { rh: rhValue }; - console.log(newProspect); - - this.prospectService.saveProspect(newProspect).subscribe(() => { this.messageService.add({ severity:'success', summary: 'Success', detail: 'Le prospect est ajouté' }); this.visible = false; diff --git a/frontend/src/app/services/auth/auth.service.ts b/frontend/src/app/services/auth/auth.service.ts index 9287733..9e7bbc6 100644 --- a/frontend/src/app/services/auth/auth.service.ts +++ b/frontend/src/app/services/auth/auth.service.ts @@ -82,8 +82,8 @@ export class AuthService { return typeof window !== 'undefined' ? localStorage.getItem('lastName') : null; } - getRoles(): string | null { - return typeof window !== 'undefined' ? localStorage.getItem('roles') : null; + getRole(): string | null { + return typeof window !== 'undefined' ? localStorage.getItem('role') : null; } getToken(): string | null { diff --git a/frontend/src/app/services/auth/identity.service.ts b/frontend/src/app/services/auth/identity.service.ts index 3846840..4de8bb4 100644 --- a/frontend/src/app/services/auth/identity.service.ts +++ b/frontend/src/app/services/auth/identity.service.ts @@ -1,12 +1,14 @@ -import { Injectable } from '@angular/core'; +import { inject, Injectable } from '@angular/core'; import { Roles } from '@eps/shared/enums/role'; +import { AuthService } from './auth.service'; @Injectable({ providedIn: 'root' }) export class IdentityService { + readonly auth = inject(AuthService); - role = localStorage.getItem('roles'); + role = this.auth.getRole(); isAdmin(){ if (this.role !== undefined && this.role !== null) { diff --git a/frontend/src/app/shared/components/topbar/topbar.component.html b/frontend/src/app/shared/components/topbar/topbar.component.html index 2773acf..938f469 100644 --- a/frontend/src/app/shared/components/topbar/topbar.component.html +++ b/frontend/src/app/shared/components/topbar/topbar.component.html @@ -36,6 +36,9 @@ [text]="true" severity="secondary " *ifAdmin /> + + {{ user }} + diff --git a/frontend/src/app/shared/components/topbar/topbar.component.ts b/frontend/src/app/shared/components/topbar/topbar.component.ts index 91ea93d..ea18ab0 100644 --- a/frontend/src/app/shared/components/topbar/topbar.component.ts +++ b/frontend/src/app/shared/components/topbar/topbar.component.ts @@ -8,6 +8,7 @@ import { IfAdminDirective } from '@eps/directives/if-admin.directive'; import { MenuItem } from 'primeng/api'; import { ButtonModule } from 'primeng/button'; import { TooltipModule } from 'primeng/tooltip'; +import { AuthService } from '@eps/service/auth/auth.service'; @Component({ selector: 'eps-topbar', @@ -23,5 +24,16 @@ export class TopbarComponent { @ViewChild('topbarmenubutton') topbarMenuButton!: ElementRef; @ViewChild('topbarmenu') menu!: ElementRef; - layoutService = inject(LayoutService); + readonly layoutService = inject(LayoutService); + readonly auth = inject(AuthService); + + firstName: string | null = ''; + user: string = ''; + + ngOnInit(): void { + this.firstName = this.auth.getFirstName(); + if(this.firstName !== null) { + this.user = this.firstName; + } + } }