show border if user is special

This commit is contained in:
Dan Percic 2022-07-28 01:57:10 +03:00
parent 0ea1bd1900
commit fc3269cc0c
6 changed files with 37 additions and 3 deletions

View File

@ -150,7 +150,7 @@ section.settings {
align-items: center;
// TODO: Shouldn't use `redaction-` here
redaction-initials-avatar .username {
iqser-initials-avatar .username {
display: none;
}
}

View File

@ -9,6 +9,7 @@ export class IqserConfigService<T extends IqserAppConfig = IqserAppConfig> {
constructor(protected _values: T) {
this._checkFrontendVersion();
this._titleService.setTitle(this._values.APP_NAME);
}
get values() {

View File

@ -68,7 +68,7 @@ export class InitialsAvatarComponent<Interface extends IIqserUser = IIqserUser,
return this._user?.id?.toLowerCase() === 'system';
}
@Input() showBorderCondition: <T extends Class = Class>(user: T) => boolean = () => false;
@Input() showBorderCondition: <T extends Class = Class>(user: T) => boolean = user => user.isSpecial;
ngOnChanges(): void {
if (this._isSystemUser) {

View File

@ -1,5 +1,5 @@
<button [class.overlay]="showDot" mat-button>
<ng-content></ng-content>
<iqser-initials-avatar [user]="userService.currentUser$ | async" [withName]="true"></iqser-initials-avatar>
<mat-icon svgIcon="iqser:arrow-down"></mat-icon>
</button>

View File

@ -1,4 +1,5 @@
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import { IqserUserService } from '../../services/iqser-user.service';
@Component({
selector: 'iqser-user-button',
@ -8,4 +9,6 @@ import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
})
export class UserButtonComponent {
@Input() showDot = false;
constructor(readonly userService: IqserUserService) {}
}

View File

@ -14,6 +14,7 @@ export class IqserUser implements IIqserUser, IListable {
readonly hasAnyRole = this.roles.length > 0;
constructor(user: KeycloakProfile | IIqserUser, ...args: unknown[]);
constructor(user: KeycloakProfile | IIqserUser, readonly roles: List, readonly userId: string) {
this.email = user.email;
this.username = user.username ?? this.email ?? 'unknown user';
@ -23,10 +24,39 @@ export class IqserUser implements IIqserUser, IListable {
this.searchKey = `${this.name || '-'}${this.username || '-'}${this.email || ''}`;
}
private _isSpecial?: boolean;
/**
* This getter is required by initials avatar to know if the border should be drawn
*/
get isSpecial() {
if (!this._isExtended) {
return false;
}
if (this._isSpecial === undefined) {
throw new Error('Property isSpecial is not implemented');
}
return this._isSpecial;
}
set isSpecial(value: boolean) {
this._isSpecial = value;
}
get id() {
return this.userId;
}
/**
* Checks if this class is used as a base class
* @private
*/
private get _isExtended() {
return this.constructor !== IqserUser;
}
has(role: string): boolean {
return this.roles.includes(role);
}