Avatar initials color depending on role

This commit is contained in:
Adina Țeudan 2020-10-27 03:23:35 +02:00
parent 205fe57422
commit 56c1147d5f
7 changed files with 38 additions and 35 deletions

View File

@ -1,4 +1,4 @@
<div class="flex-row"> <div class="flex-row">
<div [className]="color + ' oval ' + size">{{initials}}</div> <div [className]="colorClass + ' oval ' + size">{{initials}}</div>
<div *ngIf="withName" class="clamp-2">{{username || ('initials-avatar.unassigned.label' | translate)}}</div> <div *ngIf="withName" class="clamp-2">{{username || ('initials-avatar.unassigned.label' | translate)}}</div>
</div> </div>

View File

@ -1,16 +1,18 @@
import {Component, Input, OnInit} from '@angular/core'; import { Component, Input, OnChanges, OnInit } from '@angular/core';
import { UserService } from '../../user/user.service';
import { User } from '@redaction/red-ui-http';
@Component({ @Component({
selector: 'redaction-initials-avatar', selector: 'redaction-initials-avatar',
templateUrl: './initials-avatar.component.html', templateUrl: './initials-avatar.component.html',
styleUrls: ['./initials-avatar.component.scss'] styleUrls: ['./initials-avatar.component.scss']
}) })
export class InitialsAvatarComponent implements OnInit { export class InitialsAvatarComponent implements OnInit, OnChanges {
@Input() @Input()
public username: string; public userId: string;
@Input() @Input()
public color = 'lightgray-dark'; public color = 'lightgray';
@Input() @Input()
public size: 'small' | 'large' = 'small'; public size: 'small' | 'large' = 'small';
@ -18,21 +20,40 @@ export class InitialsAvatarComponent implements OnInit {
@Input() @Input()
public withName = false; public withName = false;
constructor() { public _user: User;
constructor(private readonly _userService: UserService) {
} }
ngOnInit(): void { ngOnInit(): void {
} }
ngOnChanges(): void {
this._user = this._userService.getUserById(this.userId);
}
public get username(): string {
return this._userService.getName(this._user);
}
public get initials(): string { public get initials(): string {
if (!this.username) { if (!this._user) {
return '?' return '?'
} }
return this.username return this._userService.getName(this._user)
.split(' ') .split(' ')
.filter(value => value !== ' ')
.filter((value, idx) => idx < 2) .filter((value, idx) => idx < 2)
.map((str) => str[0]) .map((str) => str[0])
.join(''); .join('');
} }
public get colorClass() {
if (this.color.includes('-')) {
return this.color;
}
const textColor = !this._user || !this._userService.isManager(this._user) ? 'dark' : 'red';
return `${this.color}-${textColor}`
}
} }

View File

@ -40,7 +40,7 @@
</div> </div>
<div class="menu right flex-2"> <div class="menu right flex-2">
<button [matMenuTriggerFor]="menu" mat-button class="arrow-button"> <button [matMenuTriggerFor]="menu" mat-button class="arrow-button">
<redaction-initials-avatar color="red-white" size="small" [username]="user?.name" [withName]="true"></redaction-initials-avatar> <redaction-initials-avatar color="red-white" size="small" [userId]="user?.id" [withName]="true"></redaction-initials-avatar>
<mat-icon svgIcon="red:arrow-down"></mat-icon> <mat-icon svgIcon="red:arrow-down"></mat-icon>
</button> </button>
<mat-menu #menu="matMenu"> <mat-menu #menu="matMenu">

View File

@ -85,8 +85,7 @@
</div> </div>
</div> </div>
<div> <div>
<redaction-initials-avatar [username]="getOwnerName(pw)" <redaction-initials-avatar [userId]="pw.project.ownerId"
color="lightgray-red"
withName="true" withName="true"
></redaction-initials-avatar> ></redaction-initials-avatar>
</div> </div>

View File

@ -68,10 +68,6 @@ export class ProjectListingScreenComponent implements OnInit {
return this.appStateService.allProjects.length - this.activeProjects; return this.appStateService.allProjects.length - this.activeProjects;
} }
public getOwnerName(pw: ProjectWrapper) {
return this._userService.getNameForId(pw.project.ownerId);
}
public documentCount(project: ProjectWrapper) { public documentCount(project: ProjectWrapper) {
return project.files.length; return project.files.length;
} }
@ -107,6 +103,6 @@ export class ProjectListingScreenComponent implements OnInit {
return acc; return acc;
}, {}) }, {})
return Object.keys(obj).map(status => ({ length: obj[status], color: status })); return Object.keys(obj).sort().map(status => ({ length: obj[status], color: status }));
} }
} }

View File

@ -108,7 +108,7 @@
<div class="assigned-to"> <div class="assigned-to">
<redaction-initials-avatar <redaction-initials-avatar
withName="true" withName="true"
[username]="getFileOwnerUsername(fileStatus)" [userId]="fileStatus.currentReviewer"
></redaction-initials-avatar> ></redaction-initials-avatar>
</div> </div>
@ -178,9 +178,8 @@
</div> </div>
<div class="owner flex-row mt-20"> <div class="owner flex-row mt-20">
<redaction-initials-avatar [username]="ownerName" <redaction-initials-avatar [userId]="activeProject.ownerId"
size="large" size="large"
color="lightgray-red"
withName="true" withName="true"
></redaction-initials-avatar> ></redaction-initials-avatar>
</div> </div>
@ -192,8 +191,8 @@
<div class="project-team mt-20"> <div class="project-team mt-20">
<div class="all-caps-label" translate="project-overview.project-details.project-team.label"></div> <div class="all-caps-label" translate="project-overview.project-details.project-team.label"></div>
<div class="flex mt-20 members-container"> <div class="flex mt-20 members-container">
<div *ngFor="let username of displayMembers" class="member"> <div *ngFor="let userId of displayMembers" class="member">
<redaction-initials-avatar [username]="username" size="large"></redaction-initials-avatar> <redaction-initials-avatar [userId]="userId" size="large"></redaction-initials-avatar>
</div> </div>
<div class="member" *ngIf="overflowCount"> <div class="member" *ngIf="overflowCount">
<div class="oval large white-dark">+{{overflowCount}}</div> <div class="oval large white-dark">+{{overflowCount}}</div>

View File

@ -69,20 +69,12 @@ export class ProjectOverviewScreenComponent implements OnInit, OnDestroy {
return this._userService.user; return this._userService.user;
} }
public get members() {
return this.activeProject.memberIds.map(m => this._userService.getName(this._userService.getUserById(m)));
}
public get displayMembers() { public get displayMembers() {
return this.members.slice(0, 6); return this.activeProject.memberIds.slice(0, 6);
} }
public get overflowCount() { public get overflowCount() {
return this.members.length > 6 ? this.members.length - 6 : 0; return this.activeProject.memberIds.length > 6 ? this.activeProject.memberIds.length - 6 : 0;
}
public get ownerName() {
return this._userService.getNameForId(this.activeProject.ownerId);
} }
private _getFileStatus() { private _getFileStatus() {
@ -190,10 +182,6 @@ export class ProjectOverviewScreenComponent implements OnInit, OnDestroy {
return fileStatus === 'PROCESSING' || fileStatus === 'REVIEWED' || true; return fileStatus === 'PROCESSING' || fileStatus === 'REVIEWED' || true;
} }
public getFileOwnerUsername(fileStatus: FileStatus) {
return this._userService.getNameForId(fileStatus.currentReviewer);
}
public toggleSortByAddedOn() { public toggleSortByAddedOn() {
const sortedByRecent: boolean = (this.sortingOption === this.sortingOptions[0]); const sortedByRecent: boolean = (this.sortingOption === this.sortingOptions[0]);
this.sortingOption = sortedByRecent ? this.sortingOptions[1] : this.sortingOptions[0]; this.sortingOption = sortedByRecent ? this.sortingOptions[1] : this.sortingOptions[0];