Merge pull request #8 from Quantum-P3/fix/userData-mainPage

Add logged in user profile icon and name on sidebar
This commit is contained in:
Eduardo Quiros 2021-07-06 02:18:41 +00:00 committed by GitHub
commit 57d492d21f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 22 additions and 4 deletions

View File

@ -18,6 +18,7 @@ describe('Component Tests', () => {
let fixture: ComponentFixture<SettingsComponent>; let fixture: ComponentFixture<SettingsComponent>;
let mockAccountService: AccountService; let mockAccountService: AccountService;
const account: Account = { const account: Account = {
id: 0,
firstName: 'John', firstName: 'John',
lastName: 'Doe', lastName: 'Doe',
activated: true, activated: true,

View File

@ -1,5 +1,6 @@
export class Account { export class Account {
constructor( constructor(
public id: number,
public activated: boolean, public activated: boolean,
public authorities: string[], public authorities: string[],
public email: string, public email: string,

View File

@ -19,6 +19,7 @@ import { AccountService } from './account.service';
function accountWithAuthorities(authorities: string[]): Account { function accountWithAuthorities(authorities: string[]): Account {
return { return {
id: 0,
activated: true, activated: true,
authorities, authorities,
email: '', email: '',

View File

@ -17,6 +17,7 @@ describe('Component Tests', () => {
let mockAccountService: AccountService; let mockAccountService: AccountService;
let mockRouter: Router; let mockRouter: Router;
const account: Account = { const account: Account = {
id: 0,
activated: true, activated: true,
authorities: [], authorities: [],
email: '', email: '',

View File

@ -9,12 +9,12 @@
<div class="sidebar-wrapper"> <div class="sidebar-wrapper">
<div class="user" routerLink="/account/settings"> <div class="user" routerLink="/account/settings">
<div class="photo mb-2"> <div class="photo mb-2">
<img src="../../../content/profile_icons/C2.png" /> <img src="../../../content/profile_icons/C{{ usuarioExtra?.iconoPerfil }}.png" />
</div> </div>
<div class="info"> <div class="info">
<a data-toggle="collapse" class="collapsed"> <a data-toggle="collapse" class="collapsed">
<span> <span>
Pablo Bonilla {{ usuarioExtra?.nombre }}
<!-- <b class="caret"></b> --> <!-- <b class="caret"></b> -->
</span> </span>
</a> </a>

View File

@ -8,6 +8,8 @@ import { LoginService } from 'app/login/login.service';
import { ProfileService } from 'app/layouts/profiles/profile.service'; import { ProfileService } from 'app/layouts/profiles/profile.service';
import { SessionStorageService } from 'ngx-webstorage'; import { SessionStorageService } from 'ngx-webstorage';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { UsuarioExtraService } from 'app/entities/usuario-extra/service/usuario-extra.service';
import { UsuarioExtra } from 'app/entities/usuario-extra/usuario-extra.model';
@Component({ @Component({
selector: 'jhi-sidebar', selector: 'jhi-sidebar',
@ -24,12 +26,15 @@ export class SidebarComponent {
version = ''; version = '';
account: Account | null = null; account: Account | null = null;
usuarioExtra: UsuarioExtra | null = null;
constructor( constructor(
private loginService: LoginService, private loginService: LoginService,
private sessionStorageService: SessionStorageService, private sessionStorageService: SessionStorageService,
private accountService: AccountService, private accountService: AccountService,
private profileService: ProfileService, private profileService: ProfileService,
private router: Router private router: Router,
private usuarioExtraService: UsuarioExtraService
) { ) {
if (VERSION) { if (VERSION) {
this.version = VERSION.toLowerCase().startsWith('v') ? VERSION : 'v' + VERSION; this.version = VERSION.toLowerCase().startsWith('v') ? VERSION : 'v' + VERSION;
@ -48,7 +53,16 @@ export class SidebarComponent {
this.inProduction = profileInfo.inProduction; this.inProduction = profileInfo.inProduction;
this.openAPIEnabled = profileInfo.openAPIEnabled; this.openAPIEnabled = profileInfo.openAPIEnabled;
}); });
this.accountService.getAuthenticationState().subscribe(account => (this.account = account));
// 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;
});
}
});
} }
ngAfterViewInit() {} ngAfterViewInit() {}