Skip to content

Commit

Permalink
[ACS-6699] cleanup user info menu and details (#3625)
Browse files Browse the repository at this point in the history
* cleanup user menu

* cleanup user info component
  • Loading branch information
DenysVuika authored Feb 2, 2024
1 parent 489a847 commit 4393f33
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 421 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<div mat-menu-item class="aca-user-info" [routerLink]="['/profile']" title="{{'APP.TOOLTIPS.MY_PROFILE' | translate}}">
<button class="aca-user-info-button">
<div>{{ (displayName$ | async)?.initials }}</div>
</button>
<div class="aca-user-info-name-email">
<div>{{ (displayName$ | async)?.firstName }}</div>
<div>{{ (displayName$ | async)?.email }}</div>
</div>
<div mat-menu-item class="aca-user-info" [routerLink]="['/profile']" title="{{ 'APP.TOOLTIPS.MY_PROFILE' | translate }}">
<ng-container *ngIf="user$ | async as user">
<button class="aca-user-info-button">
<div>{{ user.initials || 'U' }}</div>
</button>
<div class="aca-user-info-details">
<div>{{ user.userName }}</div>
<div>{{ user.email }}</div>
</div>
</ng-container>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
border: none;
}

&-name-email {
&-details {
line-height: 24px;
margin-left: 10px;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
*/

import { IdentityUserService, AuthenticationService } from '@alfresco/adf-core';
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { Observable, of } from 'rxjs';
import { PeopleContentService } from '@alfresco/adf-content-services';
import { map } from 'rxjs/operators';
import { Component, ViewEncapsulation, inject } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterModule } from '@angular/router';
import { MatMenuModule } from '@angular/material/menu';
import { TranslateModule } from '@ngx-translate/core';
import { AppStore, getUserProfile } from '@alfresco/aca-shared/store';
import { Store } from '@ngrx/store';

@Component({
standalone: true,
Expand All @@ -40,63 +38,7 @@ import { TranslateModule } from '@ngx-translate/core';
styleUrls: ['./user-info.component.scss'],
encapsulation: ViewEncapsulation.None
})
export class UserInfoComponent implements OnInit {
displayName$: Observable<{ firstName: string; initials: string; email: string }>;

constructor(
private peopleContentService: PeopleContentService,
private identityUserService: IdentityUserService,
private authService: AuthenticationService
) {}

ngOnInit() {
this.getUserInfo();
}

getUserInfo() {
if (this.authService.isOauth()) {
this.loadIdentityUserInfo();

if (this.authService.isECMProvider() && this.authService.isEcmLoggedIn()) {
this.loadEcmUserInfo();
}
} else if (this.isEcmLoggedIn()) {
this.loadEcmUserInfo();
}
}

get isLoggedIn(): boolean {
if (this.authService.isKerberosEnabled()) {
return true;
}
return this.authService.isLoggedIn();
}

private loadEcmUserInfo(): void {
this.displayName$ = this.peopleContentService.getCurrentUserInfo().pipe(map((model) => this.parseDisplayName(model)));
}

private loadIdentityUserInfo() {
this.displayName$ = of(this.identityUserService.getCurrentUserInfo()).pipe(map((model) => this.parseDisplayName(model)));
}

parseDisplayName(model: { firstName?: string; lastName?: string; email?: string }): { firstName: string; initials: string; email: string } {
const result = { firstName: '', initials: '', email: '' };
if (model.firstName) {
result.firstName = model.firstName;
result.initials = model.firstName.charAt(0).toUpperCase();
}
if (model.lastName) {
result.firstName += ' ' + model.lastName;
result.initials += model.lastName.charAt(0).toUpperCase();
}
if (model.email) {
result.email = `${model.email}`;
}
return result;
}

private isEcmLoggedIn() {
return this.authService.isEcmLoggedIn() || (this.authService.isECMProvider() && this.authService.isKerberosEnabled());
}
export class UserInfoComponent {
private store = inject<Store<AppStore>>(Store<AppStore>);
user$ = this.store.select(getUserProfile);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[matMenuTriggerFor]="menu"
title="{{'APP.TOOLTIPS.OPTIONS_SETTINGS' | translate}}"
>
<div>{{ (displayName$ | async)?.initials }}</div>
<div>{{ (user$ | async)?.initials }}</div>
</button>

<mat-menu #menu="matMenu" xPosition="before">
Expand Down
Loading

0 comments on commit 4393f33

Please sign in to comment.