show user name and initials when user has no roles
This commit is contained in:
parent
ffafaa3bdf
commit
0a61c36e14
@ -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);
|
||||
|
||||
@ -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])
|
||||
|
||||
@ -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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user