From 0a61c36e144e2c1329764aebae45a35f8a1261db Mon Sep 17 00:00:00 2001 From: Dan Percic Date: Thu, 1 Jul 2021 00:18:44 +0300 Subject: [PATCH] show user name and initials when user has no roles --- .../dossier-details.component.ts | 4 ++-- .../initials-avatar.component.ts | 9 ++++---- apps/red-ui/src/app/services/user.service.ts | 23 +++++++++++++------ 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/apps/red-ui/src/app/modules/dossier/components/dossier-details/dossier-details.component.ts b/apps/red-ui/src/app/modules/dossier/components/dossier-details/dossier-details.component.ts index 696bdd114..4d0212f09 100644 --- a/apps/red-ui/src/app/modules/dossier/components/dossier-details/dossier-details.component.ts +++ b/apps/red-ui/src/app/modules/dossier/components/dossier-details/dossier-details.component.ts @@ -47,7 +47,7 @@ export class DossierDetailsComponent implements OnInit { } ngOnInit(): void { - this.owner = this._userService.getUserById(this.appStateService.activeDossier.ownerId); + this.owner = this._userService.getRedUserById(this.appStateService.activeDossier.ownerId); this.calculateChartConfig(); this.appStateService.fileChanged.subscribe(() => { this.calculateChartConfig(); @@ -83,7 +83,7 @@ export class DossierDetailsComponent implements OnInit { } async assignOwner(user: User | string) { - this.owner = typeof user === 'string' ? this._userService.getUserById(user) : user; + this.owner = typeof user === 'string' ? this._userService.getRedUserById(user) : user; const dw = Object.assign({}, this.appStateService.activeDossier); dw.dossier.ownerId = this.owner.userId; await this.appStateService.addOrUpdateDossier(dw.dossier); diff --git a/apps/red-ui/src/app/modules/shared/components/initials-avatar/initials-avatar.component.ts b/apps/red-ui/src/app/modules/shared/components/initials-avatar/initials-avatar.component.ts index 0b1a8cff6..e652c47ee 100644 --- a/apps/red-ui/src/app/modules/shared/components/initials-avatar/initials-avatar.component.ts +++ b/apps/red-ui/src/app/modules/shared/components/initials-avatar/initials-avatar.component.ts @@ -63,9 +63,9 @@ export class InitialsAvatarComponent implements OnChanges { return; } - this.user = this._userService.getUserById(this.userId); + this.user = this._userService.getRedUserById(this.userId); + this.displayName = this._userService.getNameForId(this.userId); - this.displayName = this._userService.getName(this.user); if (this.showYou && this._isCurrentUser) { this.displayName += ` (${this._translateService.instant('initials-avatar.you')})`; } @@ -80,10 +80,9 @@ export class InitialsAvatarComponent implements OnChanges { } private _getInitials(): string { - if (!this.user) return '?'; + if (!this.displayName) return '?'; - return this._userService - .getName(this.user) + return this.displayName .split(' ') .filter((value, idx) => idx < 2 && value !== ' ') .map(str => str[0]) diff --git a/apps/red-ui/src/app/services/user.service.ts b/apps/red-ui/src/app/services/user.service.ts index b1eba0bee..fb100e0b3 100644 --- a/apps/red-ui/src/app/services/user.service.ts +++ b/apps/red-ui/src/app/services/user.service.ts @@ -67,6 +67,7 @@ export class UserWrapper { }) export class UserService { private _currentUser: UserWrapper; + private _allRedUsers: User[]; private _allUsers: User[]; constructor( @@ -84,6 +85,10 @@ export class UserService { ); } + get allRedUsers(): User[] { + return this._allRedUsers; + } + get allUsers(): User[] { return this._allUsers; } @@ -93,11 +98,11 @@ export class UserService { } get managerUsers(): User[] { - return this._allUsers.filter(u => u.roles.indexOf('RED_MANAGER') >= 0); + return this._allRedUsers.filter(u => u.roles.indexOf('RED_MANAGER') >= 0); } get eligibleUsers(): User[] { - return this._allUsers.filter( + return this._allRedUsers.filter( u => u.roles.indexOf('RED_USER') >= 0 || u.roles.indexOf('RED_MANAGER') >= 0 ); } @@ -112,15 +117,15 @@ export class UserService { } async loadAllUsersIfNecessary() { - if (!this._allUsers) { + if (!this._allRedUsers) { await this.loadAllUsers(); } } async loadAllUsers() { - const allUsers = await this._userControllerService.getUsers().toPromise(); - this._allUsers = allUsers.filter(u => UserService._hasAnyRedRole(u)); - return allUsers; + this._allUsers = await this._userControllerService.getAllUsers().toPromise(); + this._allRedUsers = this._allUsers.filter(u => UserService._hasAnyRedRole(u)); + return this._allUsers; } async loadCurrentUser() { @@ -134,12 +139,16 @@ export class UserService { ); } + getRedUserById(id: string) { + return this._allRedUsers.find(u => u.userId === id); + } + getUserById(id: string) { return this._allUsers.find(u => u.userId === id); } getNameForId(userId: string) { - return this.getName(this.getUserById(userId)); + return this.getName(this.getRedUserById(userId) || this.getUserById(userId)); } getName(user?: User) {