admin module refactoring finished

This commit is contained in:
Edi Cziszter 2021-11-20 21:55:40 +02:00
parent 66d9083bfa
commit 0c3ec3fc0b
3 changed files with 32 additions and 30 deletions

View File

@ -13,7 +13,7 @@ import { BaseDialogComponent, LoadingService } from '@iqser/common-ui';
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AddEditJustificationDialogComponent extends BaseDialogComponent {
form: FormGroup;
readonly form: FormGroup = this._getForm();
constructor(
private readonly _formBuilder: FormBuilder,
@ -24,7 +24,10 @@ export class AddEditJustificationDialogComponent extends BaseDialogComponent {
@Inject(MAT_DIALOG_DATA) public justification: Justification,
) {
super();
this.form = this._formBuilder.group({
}
private _getForm(): FormGroup {
return this._formBuilder.group({
name: [{ value: this.justification?.name, disabled: !!this.justification }, Validators.required],
reason: [this.justification?.reason, Validators.required],
description: [this.justification?.description, Validators.required],

View File

@ -24,7 +24,7 @@
<div *ngIf="changed && permissionsService.isAdmin()" class="changes-box">
<iqser-icon-button
(action)="save()"
[disabled]="configForm.invalid"
[disabled]="form.invalid"
[label]="'watermark-screen.action.save' | translate"
[type]="iconButtonTypes.primary"
icon="iqser:check"
@ -35,7 +35,7 @@
<div class="right-container" iqserHasScrollbar>
<div class="heading-xl" translate="watermark-screen.title"></div>
<form (keyup)="configChanged()" [formGroup]="configForm">
<form (keyup)="configChanged()" [formGroup]="form">
<div class="iqser-input-group w-300">
<textarea
(mousemove)="triggerChanges()"
@ -55,8 +55,8 @@
<div
(click)="setValue('orientation', option)"
*ngFor="let option of ['VERTICAL', 'HORIZONTAL', 'DIAGONAL']"
[class.active]="configForm.get('orientation').value === option"
[class.disabled]="configForm.get('orientation').disabled"
[class.active]="form.get('orientation').value === option"
[class.disabled]="form.get('orientation').disabled"
[ngClass]="option"
>
<span>ABC</span>
@ -85,17 +85,17 @@
/>
<div
(colorPickerChange)="setValue('hexColor', $event)"
[class.disabled]="configForm.get('hexColor').disabled"
[colorPicker]="configForm.get('hexColor').value"
[cpDisabled]="configForm.get('hexColor').disabled"
[class.disabled]="form.get('hexColor').disabled"
[colorPicker]="form.get('hexColor').value"
[cpDisabled]="form.get('hexColor').disabled"
[cpOutputFormat]="'hex'"
[cpPosition]="'top-right'"
[cpUseRootViewContainer]="true"
[style.background]="configForm.get('hexColor').value"
[style.background]="form.get('hexColor').value"
class="input-icon"
>
<mat-icon
*ngIf="!configForm.get('hexColor')?.value || configForm.get('hexColor').value?.length === 0"
*ngIf="!form.get('hexColor')?.value || form.get('hexColor').value?.length === 0"
svgIcon="red:color-picker"
></mat-icon>
</div>
@ -113,8 +113,8 @@
{ value: 'courier', display: 'Courier' }
]
"
[class.active]="configForm.get('fontType').value === option.value"
[class.disabled]="configForm.get('fontType').disabled"
[class.active]="form.get('fontType').value === option.value"
[class.disabled]="form.get('fontType').disabled"
[ngClass]="option.value"
>
{{ option.display }}

View File

@ -28,7 +28,7 @@ export const DEFAULT_WATERMARK: IWatermark = {
})
export class WatermarkScreenComponent implements OnInit {
readonly iconButtonTypes = IconButtonTypes;
configForm: FormGroup;
readonly form: FormGroup = this._getForm();
private _instance: WebViewerInstance;
private _watermark: IWatermark = {};
@ViewChild('viewer', { static: true })
@ -46,7 +46,6 @@ export class WatermarkScreenComponent implements OnInit {
private readonly _loadingService: LoadingService,
) {
this._loadingService.start();
this._initForm();
}
get changed(): boolean {
@ -54,7 +53,7 @@ export class WatermarkScreenComponent implements OnInit {
return true;
}
for (const key of Object.keys(this._watermark)) {
if (this._watermark[key] !== this.configForm.get(key)?.value) {
if (this._watermark[key] !== this.form.get(key)?.value) {
return true;
}
}
@ -72,7 +71,7 @@ export class WatermarkScreenComponent implements OnInit {
save() {
const watermark = {
...this.configForm.getRawValue(),
...this.form.getRawValue(),
};
const dossierTemplateId = this._dossierTemplatesService.activeDossierTemplateId;
@ -93,15 +92,15 @@ export class WatermarkScreenComponent implements OnInit {
}
async revert() {
this.configForm.setValue({ ...this._watermark });
this.form.setValue({ ...this._watermark });
await this.configChanged();
}
triggerChanges() {}
async setValue(type: 'fontType' | 'orientation' | 'hexColor', value: any) {
if (!this.configForm.get(type).disabled) {
this.configForm.get(type).setValue(value);
if (!this.form.get(type).disabled) {
this.form.get(type).setValue(value);
await this.configChanged();
}
}
@ -110,12 +109,12 @@ export class WatermarkScreenComponent implements OnInit {
this._watermarkService.getWatermark(this._dossierTemplatesService.activeDossierTemplateId).subscribe(
watermark => {
this._watermark = watermark;
this.configForm.setValue({ ...this._watermark });
this.form.setValue({ ...this._watermark });
this._loadViewer();
},
() => {
this._watermark = DEFAULT_WATERMARK;
this.configForm.setValue({ ...this._watermark });
this.form.setValue({ ...this._watermark });
this._loadViewer();
},
);
@ -162,12 +161,12 @@ export class WatermarkScreenComponent implements OnInit {
const pdfNet = this._instance.Core.PDFNet;
const document = await this._instance.Core.documentViewer.getDocument().getPDFDoc();
const text = this.configForm.get('text').value || '';
const fontSize = this.configForm.get('fontSize').value;
const fontType = this.configForm.get('fontType').value;
const orientation: WatermarkOrientation = this.configForm.get('orientation').value;
const opacity = this.configForm.get('opacity').value;
const color = this.configForm.get('hexColor').value;
const text = this.form.get('text').value || '';
const fontSize = this.form.get('fontSize').value;
const fontType = this.form.get('fontType').value;
const orientation: WatermarkOrientation = this.form.get('orientation').value;
const opacity = this.form.get('opacity').value;
const color = this.form.get('hexColor').value;
await stampPDFPage(document, pdfNet, text, fontSize, fontType, orientation, opacity, color, [1]);
this._instance.Core.documentViewer.refreshAll();
@ -175,8 +174,8 @@ export class WatermarkScreenComponent implements OnInit {
this._changeDetectorRef.detectChanges();
}
private _initForm() {
this.configForm = this._formBuilder.group({
private _getForm(): FormGroup {
return this._formBuilder.group({
text: [{ value: null, disabled: !this.permissionsService.isAdmin() }],
hexColor: [
{