From fc3269cc0c86ce3c26c9c0266e4429f393214d37 Mon Sep 17 00:00:00 2001 From: Dan Percic Date: Thu, 28 Jul 2022 01:57:10 +0300 Subject: [PATCH] show border if user is special --- src/assets/styles/common-layout.scss | 2 +- src/lib/services/iqser-config.service.ts | 1 + .../initials-avatar.component.ts | 2 +- .../user-button/user-button.component.html | 2 +- .../user-button/user-button.component.ts | 3 ++ src/lib/users/iqser-user.model.ts | 30 +++++++++++++++++++ 6 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/assets/styles/common-layout.scss b/src/assets/styles/common-layout.scss index 47629ab..70a18d8 100644 --- a/src/assets/styles/common-layout.scss +++ b/src/assets/styles/common-layout.scss @@ -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; } } diff --git a/src/lib/services/iqser-config.service.ts b/src/lib/services/iqser-config.service.ts index 8628449..2792623 100644 --- a/src/lib/services/iqser-config.service.ts +++ b/src/lib/services/iqser-config.service.ts @@ -9,6 +9,7 @@ export class IqserConfigService { constructor(protected _values: T) { this._checkFrontendVersion(); + this._titleService.setTitle(this._values.APP_NAME); } get values() { diff --git a/src/lib/users/components/initials-avatar/initials-avatar.component.ts b/src/lib/users/components/initials-avatar/initials-avatar.component.ts index c87e7be..0b4fbaf 100644 --- a/src/lib/users/components/initials-avatar/initials-avatar.component.ts +++ b/src/lib/users/components/initials-avatar/initials-avatar.component.ts @@ -68,7 +68,7 @@ export class InitialsAvatarComponent(user: T) => boolean = () => false; + @Input() showBorderCondition: (user: T) => boolean = user => user.isSpecial; ngOnChanges(): void { if (this._isSystemUser) { diff --git a/src/lib/users/components/user-button/user-button.component.html b/src/lib/users/components/user-button/user-button.component.html index fe868ac..bc937c6 100644 --- a/src/lib/users/components/user-button/user-button.component.html +++ b/src/lib/users/components/user-button/user-button.component.html @@ -1,5 +1,5 @@ diff --git a/src/lib/users/components/user-button/user-button.component.ts b/src/lib/users/components/user-button/user-button.component.ts index b67fcea..2d97814 100644 --- a/src/lib/users/components/user-button/user-button.component.ts +++ b/src/lib/users/components/user-button/user-button.component.ts @@ -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) {} } diff --git a/src/lib/users/iqser-user.model.ts b/src/lib/users/iqser-user.model.ts index 74c272c..3035449 100644 --- a/src/lib/users/iqser-user.model.ts +++ b/src/lib/users/iqser-user.model.ts @@ -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); }