RED-10139: removed some more getters.

This commit is contained in:
Nicoleta Panaghiu 2024-11-05 13:05:40 +02:00
parent 7ef5fc7bc9
commit 953c0c65cc
4 changed files with 214 additions and 180 deletions

View File

@ -81,28 +81,28 @@ export class UserProfileScreenComponent extends BaseFormComponent {
this._loadingService.stop();
}
get languageChanged(): boolean {
get #languageChanged(): boolean {
return this.initialFormValue['language'] !== this.form.controls.language.value;
}
get themeChanged(): boolean {
get #themeChanged(): boolean {
return this.initialFormValue['darkTheme'] !== this.form.controls.darkTheme.value;
}
get emailChanged(): boolean {
get #emailChanged(): boolean {
return this.initialFormValue['email'] !== this.form.controls.email.value;
}
get profileChanged(): boolean {
get #profileChanged(): boolean {
return this.profileKeys.some(key => this.initialFormValue[key] !== this.form.get(key).value);
}
async save(): Promise<void> {
try {
if (this.profileChanged) {
if (this.#profileChanged) {
const value = this.form.getRawValue() as IProfile;
if (this.emailChanged) {
if (this.#emailChanged) {
const dialogRef = this._dialogService.openDialog('confirmPassword');
const password = await firstValueFrom(dialogRef.afterClosed());
if (!password) {
@ -118,12 +118,12 @@ export class UserProfileScreenComponent extends BaseFormComponent {
await firstValueFrom(this._userService.loadAll());
}
if (this.languageChanged) {
if (this.#languageChanged) {
await this._languageService.change(this.form.controls.language.value);
await this._pdfViewer.instance?.UI.setLanguage(this._languageService.currentLanguage);
}
if (this.themeChanged) {
if (this.#themeChanged) {
await this._userPreferenceService.saveTheme(this.form.controls.darkTheme.value ? 'dark' : 'light');
}

View File

@ -38,7 +38,7 @@ export class UserDetailsComponent extends BaseFormComponent implements OnInit {
super();
}
get activeRoles(): string[] {
get #activeRoles(): string[] {
return this.ROLES.reduce((acc, role) => {
if (this.form.get(role).value) {
acc.push(role);
@ -47,7 +47,7 @@ export class UserDetailsComponent extends BaseFormComponent implements OnInit {
}, []);
}
get sendSetPasswordMail() {
get #sendSetPasswordMail() {
return !this.form.controls.sendSetPasswordMail.value;
}
@ -89,8 +89,8 @@ export class UserDetailsComponent extends BaseFormComponent implements OnInit {
this._loadingService.start();
const userData: IProfileUpdateRequest = {
...this.form.getRawValue(),
roles: this.activeRoles,
sendSetPasswordMail: this.sendSetPasswordMail,
roles: this.#activeRoles,
sendSetPasswordMail: this.#sendSetPasswordMail,
};
if (!this.user()) {

View File

@ -1,144 +1,153 @@
<div class="content-container">
<div #viewer class="viewer"></div>
<redaction-paginator (changePage)="navigateTo($event)" *ngIf="loaded$ | async"></redaction-paginator>
@if (loaded$ | async) {
<redaction-paginator (changePage)="navigateTo($event)"></redaction-paginator>
}
<div *ngIf="!!instance && changed && currentUser.isAdmin" class="changes-box">
<iqser-icon-button
(action)="save()"
[disabled]="!valid"
[label]="'watermark-screen.action.save' | translate"
[type]="iconButtonTypes.primary"
icon="iqser:check"
></iqser-icon-button>
@if (!!instance && changed() && currentUser.isAdmin) {
<div class="changes-box">
<iqser-icon-button
(action)="save()"
[disabled]="!valid()"
[label]="'watermark-screen.action.save' | translate"
[type]="iconButtonTypes.primary"
icon="iqser:check"
></iqser-icon-button>
<div (click)="revert()" [translate]="'watermark-screen.action.revert'" class="all-caps-label cancel"></div>
<div (click)="revert()" [translate]="'watermark-screen.action.revert'" class="all-caps-label cancel"></div>
</div>
}
</div>
@if (watermark$ | async) {
<div class="right-container" [attr.help-mode-key]="'watermarks'" iqserHasScrollbar>
<form (keyup)="configChanged()" [formGroup]="form">
<div class="iqser-input-group required w-300">
<label [translate]="'watermark-screen.form.name-label'"></label>
<input [placeholder]="'watermark-screen.form.name-placeholder' | translate" formControlName="name" type="text" />
</div>
<div class="iqser-input-group required w-300">
<label [translate]="'watermark-screen.form.text-label'"></label>
<textarea
[placeholder]="'watermark-screen.form.text-placeholder' | translate"
class="w-full"
formControlName="text"
iqserHasScrollbar
name="text"
rows="4"
type="text"
></textarea>
</div>
<div class="iqser-input-group">
<label [translate]="'watermark-screen.form.orientation'" class="all-caps-label mb-8"></label>
<div class="square-options">
@for (option of orientationOptions; track option) {
<div
(click)="setValue('orientation', option)"
[class.active]="form.controls.orientation.value === option"
[class.disabled]="orientationStatus() === 'DISABLED'"
[ngClass]="option"
>
<span>ABC</span>
</div>
}
</div>
</div>
<div class="iqser-input-group">
<label [translate]="'watermark-screen.form.alignment'" class="all-caps-label mb-8"></label>
<div class="flex">
<div [class.disabled]="horizontalTextAlignmentStatus() === 'DISABLED'" class="alignment-buttons">
@for (alignment of watermarkHorizontalAlignments; track alignment) {
<div
(click)="alignHorizontally(alignment)"
[class.active]="currentAlignment.horizontal === alignment"
[class.disabled]="horizontalTextAlignmentStatus() === 'DISABLED'"
[matTooltipPosition]="'above'"
[matTooltip]="translations.HORIZONTAL[alignment] | translate"
[ngClass]="'horizontal-' + loweredWatermarkHorizontalAlignments[alignment]"
class="alignment"
>
<mat-icon [svgIcon]="'red:align-horizontal-' + loweredWatermarkHorizontalAlignments[alignment]"></mat-icon>
</div>
}
</div>
<div [class.disabled]="verticalTextAlignmentStatus() === 'DISABLED'" class="alignment-buttons">
@for (alignment of watermarkVerticalAlignments; track alignment) {
<div
(click)="alignVertically(alignment)"
[class.active]="currentAlignment.vertical === alignment"
[class.disabled]="verticalTextAlignmentStatus() === 'DISABLED'"
[matTooltipPosition]="'above'"
[matTooltip]="translations.VERTICAL[alignment] | translate"
[ngClass]="'vertical-' + loweredWatermarkVerticalAlignments[alignment]"
class="alignment"
>
<mat-icon [svgIcon]="'red:align-vertical-' + loweredWatermarkVerticalAlignments[alignment]"></mat-icon>
</div>
}
</div>
</div>
</div>
<div class="iqser-input-group w-150">
<label [translate]="'watermark-screen.form.font-size'" class="all-caps-label"></label>
<mat-slider color="primary" max="50" min="5">
<input (change)="configChanged()" formControlName="fontSize" matSliderThumb />
</mat-slider>
</div>
<div class="iqser-input-group w-150">
<label [translate]="'watermark-screen.form.opacity'" class="all-caps-label"></label>
<mat-slider color="primary" min="1">
<input (change)="configChanged()" formControlName="opacity" matSliderThumb />
</mat-slider>
</div>
<div class="iqser-input-group w-150">
<label [translate]="'watermark-screen.form.color'" class="all-caps-label mb-5"></label>
<input
[placeholder]="'watermark-screen.form.color-placeholder' | translate"
class="hex-color-input"
formControlName="hexColor"
name="hexColor"
type="text"
/>
<div
(colorPickerChange)="setValue('hexColor', $event)"
[class.disabled]="hexColorStatus() === 'DISABLED'"
[colorPicker]="form.controls.hexColor.value"
[cpDisabled]="hexColorStatus() === 'DISABLED'"
[cpOutputFormat]="'hex'"
[cpPosition]="'top-right'"
[cpUseRootViewContainer]="true"
[style.background]="form.controls.hexColor.value"
class="input-icon"
>
@if (!form.controls.hexColor?.value || form.controls.hexColor.value?.length === 0) {
<mat-icon svgIcon="iqser:color-picker"></mat-icon>
}
</div>
</div>
<div class="iqser-input-group">
<label [translate]="'watermark-screen.form.font-type'" class="all-caps-label mb-8"></label>
<div class="square-options">
@for (option of fontOptions; track option.value) {
<div
(click)="setValue('fontType', option.value)"
[class.active]="form.controls.fontType.value === option.value"
[class.disabled]="fontTypeStatus() === 'DISABLED'"
[ngClass]="option.value"
>
{{ option.display }}
</div>
}
</div>
</div>
</form>
</div>
</div>
<div *ngIf="watermark$ | async" class="right-container" [attr.help-mode-key]="'watermarks'" iqserHasScrollbar>
<form (keyup)="configChanged()" [formGroup]="form">
<div class="iqser-input-group required w-300">
<label [translate]="'watermark-screen.form.name-label'"></label>
<input [placeholder]="'watermark-screen.form.name-placeholder' | translate" formControlName="name" type="text" />
</div>
<div class="iqser-input-group required w-300">
<label [translate]="'watermark-screen.form.text-label'"></label>
<textarea
[placeholder]="'watermark-screen.form.text-placeholder' | translate"
class="w-full"
formControlName="text"
iqserHasScrollbar
name="text"
rows="4"
type="text"
></textarea>
</div>
<div class="iqser-input-group">
<label [translate]="'watermark-screen.form.orientation'" class="all-caps-label mb-8"></label>
<div class="square-options">
<div
(click)="setValue('orientation', option)"
*ngFor="let option of orientationOptions"
[class.active]="form.controls.orientation.value === option"
[class.disabled]="form.controls.orientation.disabled"
[ngClass]="option"
>
<span>ABC</span>
</div>
</div>
</div>
<div class="iqser-input-group">
<label [translate]="'watermark-screen.form.alignment'" class="all-caps-label mb-8"></label>
<div class="flex">
<div [class.disabled]="form.controls.horizontalTextAlignment.disabled" class="alignment-buttons">
<div
(click)="alignHorizontally(alignment)"
*ngFor="let alignment of watermarkHorizontalAlignments"
[class.active]="currentAlignment.horizontal === alignment"
[class.disabled]="form.controls.horizontalTextAlignment.disabled"
[matTooltipPosition]="'above'"
[matTooltip]="translations.HORIZONTAL[alignment] | translate"
[ngClass]="'horizontal-' + alignment.toLowerCase()"
class="alignment"
>
<mat-icon [svgIcon]="'red:align-horizontal-' + alignment.toLowerCase()"></mat-icon>
</div>
</div>
<div [class.disabled]="form.controls.verticalTextAlignment.disabled" class="alignment-buttons">
<div
(click)="alignVertically(alignment)"
*ngFor="let alignment of watermarkVerticalAlignments"
[class.active]="currentAlignment.vertical === alignment"
[class.disabled]="form.controls.verticalTextAlignment.disabled"
[matTooltipPosition]="'above'"
[matTooltip]="translations.VERTICAL[alignment] | translate"
[ngClass]="'vertical-' + alignment.toLowerCase()"
class="alignment"
>
<mat-icon [svgIcon]="'red:align-vertical-' + alignment.toLowerCase()"></mat-icon>
</div>
</div>
</div>
</div>
<div class="iqser-input-group w-150">
<label [translate]="'watermark-screen.form.font-size'" class="all-caps-label"></label>
<mat-slider color="primary" max="50" min="5">
<input (change)="configChanged()" formControlName="fontSize" matSliderThumb />
</mat-slider>
</div>
<div class="iqser-input-group w-150">
<label [translate]="'watermark-screen.form.opacity'" class="all-caps-label"></label>
<mat-slider color="primary" min="1">
<input (change)="configChanged()" formControlName="opacity" matSliderThumb />
</mat-slider>
</div>
<div class="iqser-input-group w-150">
<label [translate]="'watermark-screen.form.color'" class="all-caps-label mb-5"></label>
<input
[placeholder]="'watermark-screen.form.color-placeholder' | translate"
class="hex-color-input"
formControlName="hexColor"
name="hexColor"
type="text"
/>
<div
(colorPickerChange)="setValue('hexColor', $event)"
[class.disabled]="form.controls.hexColor.disabled"
[colorPicker]="form.controls.hexColor.value"
[cpDisabled]="form.controls.hexColor.disabled"
[cpOutputFormat]="'hex'"
[cpPosition]="'top-right'"
[cpUseRootViewContainer]="true"
[style.background]="form.controls.hexColor.value"
class="input-icon"
>
<mat-icon
*ngIf="!form.controls.hexColor?.value || form.controls.hexColor.value?.length === 0"
svgIcon="iqser:color-picker"
></mat-icon>
</div>
</div>
<div class="iqser-input-group">
<label [translate]="'watermark-screen.form.font-type'" class="all-caps-label mb-8"></label>
<div class="square-options">
<div
(click)="setValue('fontType', option.value)"
*ngFor="let option of fontOptions"
[class.active]="form.controls.fontType.value === option.value"
[class.disabled]="form.controls.fontType.disabled"
[ngClass]="option.value"
>
{{ option.display }}
</div>
</div>
</div>
</form>
</div>
}

View File

@ -1,7 +1,7 @@
import { AsyncPipe, NgClass, NgForOf, NgIf } from '@angular/common';
import { AsyncPipe, NgClass } from '@angular/common';
import { HttpClient } from '@angular/common/http';
import { ChangeDetectorRef, Component, ElementRef, inject, OnInit, ViewChild } from '@angular/core';
import { FormBuilder, FormGroup, ReactiveFormsModule } from '@angular/forms';
import { ChangeDetectorRef, Component, computed, ElementRef, inject, OnInit, viewChild, ViewChild } from '@angular/core';
import { FormBuilder, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
import { MatIcon } from '@angular/material/icon';
import { MatSlider, MatSliderThumb } from '@angular/material/slider';
import { MatTooltip } from '@angular/material/tooltip';
@ -18,7 +18,15 @@ import {
Toaster,
} from '@iqser/common-ui';
import { getCurrentUser } from '@iqser/common-ui/lib/users';
import { AsControl, Debounce, getParam, trackByFactory, UI_ROOT_PATH_FN } from '@iqser/common-ui/lib/utils';
import {
AsControl,
Debounce,
formStatusToSignal,
formValueToSignal,
getParam,
trackByFactory,
UI_ROOT_PATH_FN,
} from '@iqser/common-ui/lib/utils';
import { TranslateModule } from '@ngx-translate/core';
import WebViewer, { WebViewerInstance } from '@pdftron/webviewer';
import {
@ -77,14 +85,12 @@ interface WatermarkForm {
standalone: true,
imports: [
PaginatorComponent,
NgIf,
IconButtonComponent,
TranslateModule,
AsyncPipe,
ReactiveFormsModule,
HasScrollbarDirective,
MatTooltip,
NgForOf,
NgClass,
MatIcon,
MatSlider,
@ -93,7 +99,7 @@ interface WatermarkForm {
],
})
export class WatermarkScreenComponent implements OnInit {
@ViewChild('viewer', { static: true }) private readonly _viewer: ElementRef<HTMLDivElement>;
private readonly _viewer = viewChild.required<ElementRef<HTMLDivElement>>('viewer');
readonly #loaded$ = new BehaviorSubject(false);
readonly #dossierTemplateId = getParam(DOSSIER_TEMPLATE_ID);
readonly #watermarkId = Number(getParam(WATERMARK_ID));
@ -104,7 +110,7 @@ export class WatermarkScreenComponent implements OnInit {
readonly translations = watermarkTranslations;
readonly trackBy = trackByFactory();
readonly currentUser = getCurrentUser<User>();
readonly form = this.#form;
readonly form: FormGroup<AsControl<WatermarkForm>> = this.#form;
readonly watermark$: Observable<Partial<IWatermark>>;
readonly fontOptions = [
{ value: 'times-new-roman', display: 'Times' },
@ -117,6 +123,42 @@ export class WatermarkScreenComponent implements OnInit {
readonly watermarkHorizontalAlignments = Object.values(WATERMARK_HORIZONTAL_ALIGNMENTS);
readonly watermarkVerticalAlignments = Object.values(WATERMARK_VERTICAL_ALIGNMENTS);
currentAlignment: WatermarkAlignment;
readonly loweredWatermarkHorizontalAlignments = this.watermarkHorizontalAlignments.reduce(
(acc, curr: string) => ({
...acc,
[curr]: curr.toLowerCase(),
}),
{},
);
readonly loweredWatermarkVerticalAlignments = this.watermarkVerticalAlignments.reduce(
(acc, curr: string) => ({
...acc,
[curr]: curr.toLowerCase(),
}),
{},
);
readonly hexColorStatus = formStatusToSignal(this.form.controls.hexColor);
readonly fontTypeStatus = formStatusToSignal(this.form.controls.fontType);
readonly verticalTextAlignmentStatus = formStatusToSignal(this.form.controls.verticalTextAlignment);
readonly horizontalTextAlignmentStatus = formStatusToSignal(this.form.controls.horizontalTextAlignment);
readonly orientationStatus = formStatusToSignal(this.form.controls.orientation);
readonly formValue = formValueToSignal(this.form);
readonly formStatus = formStatusToSignal(this.form);
readonly changed = computed(() => {
for (const key of Object.keys(this.form.getRawValue())) {
if (this.#watermark[key] !== this.formValue()[key]) {
return true;
}
}
return false;
});
readonly valid = computed(() => {
if (!this.formValue()['name'] || !this.formValue()['text']) {
return false;
}
return this.formStatus() === 'VALID';
});
constructor(
private readonly _http: HttpClient,
@ -137,26 +179,10 @@ export class WatermarkScreenComponent implements OnInit {
this.watermark$ = obs$.pipe(tap(watermark => this.#initForm(watermark)));
}
get changed(): boolean {
for (const key of Object.keys(this.form.getRawValue())) {
if (this.#watermark[key] !== this.form.get(key)?.value) {
return true;
}
}
return false;
}
get valid(): boolean {
if (!this.form.controls.name?.value || !this.form.controls.text?.value) {
return false;
}
return this.form.valid;
}
get #form() {
const form: FormGroup<AsControl<WatermarkForm>> = this._formBuilder.group({
name: [null],
text: [null],
get #form(): FormGroup<AsControl<WatermarkForm>> {
const form = this._formBuilder.group({
name: ['', Validators.required],
text: ['', Validators.required],
hexColor: [null],
opacity: [null],
fontSize: [null],
@ -175,7 +201,6 @@ export class WatermarkScreenComponent implements OnInit {
@Debounce()
async configChanged() {
console.log('configChanged');
await this.#drawWatermark();
}
@ -258,7 +283,7 @@ export class WatermarkScreenComponent implements OnInit {
},
// use nativeElement instead of document.getElementById('viwer')
// because WebViewer works better with this approach
this._viewer.nativeElement,
this._viewer().nativeElement,
);
this.instance.UI.setTheme(this._userPreferenceService.getTheme());