From 195cb571f61a6857a5c6c66de6c77e8d2eacbc36 Mon Sep 17 00:00:00 2001 From: Edi Cziszter Date: Fri, 19 Nov 2021 11:06:32 +0200 Subject: [PATCH] renamed forms to "form" --- .../notifications/notifications.component.ts | 6 +--- .../add-dossier-dialog.component.html | 2 +- .../add-dossier-dialog.component.ts | 32 +++++++++--------- ...sign-reviewer-approver-dialog.component.ts | 19 +++++++---- .../change-legal-basis-dialog.component.html | 6 ++-- .../change-legal-basis-dialog.component.ts | 19 ++++------- .../document-info-dialog.component.html | 6 ++-- .../document-info-dialog.component.ts | 33 ++++++++++--------- .../manual-annotation-dialog.component.ts | 4 +-- 9 files changed, 63 insertions(+), 64 deletions(-) diff --git a/apps/red-ui/src/app/components/notifications/notifications.component.ts b/apps/red-ui/src/app/components/notifications/notifications.component.ts index fd6cdba44..79b71d79c 100644 --- a/apps/red-ui/src/app/components/notifications/notifications.component.ts +++ b/apps/red-ui/src/app/components/notifications/notifications.component.ts @@ -39,14 +39,10 @@ export class NotificationsComponent extends AutoUnsubscribe implements OnInit { ) { super(); this.notifications$ = this._notifications$.asObservable().pipe(shareLast()); - this.groupedNotifications$ = this._groupedNotifications$; + this.groupedNotifications$ = this.notifications$.pipe(map(notifications => this._groupNotifications(notifications))); this.hasUnreadNotifications$ = this._hasUnreadNotifications$; } - async ngOnInit(): Promise { - await this._loadData(); - } - async ngOnInit(): Promise { await this._loadData(); diff --git a/apps/red-ui/src/app/modules/dossier/dialogs/add-dossier-dialog/add-dossier-dialog.component.html b/apps/red-ui/src/app/modules/dossier/dialogs/add-dossier-dialog/add-dossier-dialog.component.html index bba61223a..e4b6d7c77 100644 --- a/apps/red-ui/src/app/modules/dossier/dialogs/add-dossier-dialog/add-dossier-dialog.component.html +++ b/apps/red-ui/src/app/modules/dossier/dialogs/add-dossier-dialog/add-dossier-dialog.component.html @@ -1,5 +1,5 @@
-
+
diff --git a/apps/red-ui/src/app/modules/dossier/dialogs/add-dossier-dialog/add-dossier-dialog.component.ts b/apps/red-ui/src/app/modules/dossier/dialogs/add-dossier-dialog/add-dossier-dialog.component.ts index d90473966..a980580f3 100644 --- a/apps/red-ui/src/app/modules/dossier/dialogs/add-dossier-dialog/add-dossier-dialog.component.ts +++ b/apps/red-ui/src/app/modules/dossier/dialogs/add-dossier-dialog/add-dossier-dialog.component.ts @@ -16,7 +16,7 @@ import { ReportTemplateService } from '@services/report-template.service'; export class AddDossierDialogComponent { readonly iconButtonTypes = IconButtonTypes; - readonly dossierForm: FormGroup; + readonly form: FormGroup; hasDueDate = false; downloadTypes: { key: DownloadFileType; label: string }[] = ['ORIGINAL', 'PREVIEW', 'REDACTED'].map((type: DownloadFileType) => ({ key: type, @@ -33,7 +33,7 @@ export class AddDossierDialogComponent { readonly dialogRef: MatDialogRef, ) { this._getDossierTemplates(); - this.dossierForm = this._getForm(); + this.form = this._getForm(); } private _getForm(): FormGroup { @@ -58,19 +58,19 @@ export class AddDossierDialogComponent { } get reportTemplateIdsLength() { - return this.dossierForm.controls['reportTemplateIds']?.value?.length || 0; + return this.form.controls['reportTemplateIds']?.value?.length || 0; } get downloadFileTypesLength() { - return this.dossierForm.controls['downloadFileTypes']?.value?.length || 0; + return this.form.controls['downloadFileTypes']?.value?.length || 0; } get disabled() { - if (this.hasDueDate && this.dossierForm.get('dueDate').value === null) { + if (this.hasDueDate && this.form.get('dueDate').value === null) { return true; } - return this.dossierForm.invalid; + return this.form.invalid; } reportTemplateValueMapper = (reportTemplate: IReportTemplate) => reportTemplate.templateId; @@ -90,7 +90,7 @@ export class AddDossierDialogComponent { this.availableReportTypes = (await this._reportTemplateController.getAvailableReportTemplates(dossierTemplate.dossierTemplateId).toPromise()) || []; // update dropdown values - this.dossierForm.patchValue( + this.form.patchValue( { downloadFileTypes: dossierTemplate.downloadFileTypes, reportTemplateIds: [], // TODO DEFAULT @@ -99,7 +99,7 @@ export class AddDossierDialogComponent { ); } else { this.availableReportTypes = []; - this.dossierForm.patchValue( + this.form.patchValue( { downloadFileTypes: [], reportTemplateIds: [], @@ -121,14 +121,14 @@ export class AddDossierDialogComponent { private _formToObject(): IDossierRequest { return { - dossierName: this.dossierForm.get('dossierName').value, - description: this.dossierForm.get('description').value, - dueDate: this.hasDueDate ? this.dossierForm.get('dueDate').value : undefined, - dossierTemplateId: this.dossierForm.get('dossierTemplateId').value, - downloadFileTypes: this.dossierForm.get('downloadFileTypes').value, - reportTemplateIds: this.dossierForm.get('reportTemplateIds').value, - watermarkEnabled: this.dossierForm.get('watermarkEnabled').value, - watermarkPreviewEnabled: this.dossierForm.get('watermarkPreviewEnabled').value, + dossierName: this.form.get('dossierName').value, + description: this.form.get('description').value, + dueDate: this.hasDueDate ? this.form.get('dueDate').value : undefined, + dossierTemplateId: this.form.get('dossierTemplateId').value, + downloadFileTypes: this.form.get('downloadFileTypes').value, + reportTemplateIds: this.form.get('reportTemplateIds').value, + watermarkEnabled: this.form.get('watermarkEnabled').value, + watermarkPreviewEnabled: this.form.get('watermarkPreviewEnabled').value, }; } } diff --git a/apps/red-ui/src/app/modules/dossier/dialogs/assign-reviewer-approver-dialog/assign-reviewer-approver-dialog.component.ts b/apps/red-ui/src/app/modules/dossier/dialogs/assign-reviewer-approver-dialog/assign-reviewer-approver-dialog.component.ts index f9f1779ef..b69d7b02e 100644 --- a/apps/red-ui/src/app/modules/dossier/dialogs/assign-reviewer-approver-dialog/assign-reviewer-approver-dialog.component.ts +++ b/apps/red-ui/src/app/modules/dossier/dialogs/assign-reviewer-approver-dialog/assign-reviewer-approver-dialog.component.ts @@ -21,7 +21,7 @@ class DialogData { styleUrls: ['./assign-reviewer-approver-dialog.component.scss'], }) export class AssignReviewerApproverDialogComponent { - form: FormGroup; + readonly form: FormGroup; dossier: Dossier; constructor( @@ -36,7 +36,7 @@ export class AssignReviewerApproverDialogComponent { @Inject(MAT_DIALOG_DATA) readonly data: DialogData, ) { this.dossier = this._dossiersService.find(this.data.files[0].dossierId); - this._loadData(); + this.form = this._getForm(); } get selectedUser(): string { @@ -102,20 +102,27 @@ export class AssignReviewerApproverDialogComponent { * the id of the current reviewer of the files list if there is only one reviewer for all of them; * or the id of the current user **/ - private _loadData() { + + private get _uniqueReviewers(): Set { const uniqueReviewers = new Set(); for (const file of this.data.files) { if (file.currentReviewer) { uniqueReviewers.add(file.currentReviewer); } } - let user: string = uniqueReviewers.size === 1 ? uniqueReviewers.values().next().value : this.userService.currentUser.id; + return uniqueReviewers; + } + private get _user(): string { + let user: string = this._uniqueReviewers.size === 1 ? this._uniqueReviewers.values().next().value : this.userService.currentUser.id; user = this.userOptions.indexOf(user) >= 0 ? user : this.userOptions[0]; + return user; + } - this.form = this._formBuilder.group({ + private _getForm(): FormGroup { + return this._formBuilder.group({ // Allow a null reviewer if a previous reviewer exists (= it's not the first assignment) & current user is allowed to unassign - user: [user, this._canUnassignFiles && !user ? Validators.required : null], + user: [this._user, this._canUnassignFiles && !this._user ? Validators.required : null], }); } } diff --git a/apps/red-ui/src/app/modules/dossier/dialogs/change-legal-basis-dialog/change-legal-basis-dialog.component.html b/apps/red-ui/src/app/modules/dossier/dialogs/change-legal-basis-dialog/change-legal-basis-dialog.component.html index 1324714b3..690ff3b32 100644 --- a/apps/red-ui/src/app/modules/dossier/dialogs/change-legal-basis-dialog/change-legal-basis-dialog.component.html +++ b/apps/red-ui/src/app/modules/dossier/dialogs/change-legal-basis-dialog/change-legal-basis-dialog.component.html @@ -1,5 +1,5 @@
- +
@@ -18,7 +18,7 @@
- +
@@ -28,7 +28,7 @@
-
diff --git a/apps/red-ui/src/app/modules/dossier/dialogs/change-legal-basis-dialog/change-legal-basis-dialog.component.ts b/apps/red-ui/src/app/modules/dossier/dialogs/change-legal-basis-dialog/change-legal-basis-dialog.component.ts index 69cd98de3..c48c4fafc 100644 --- a/apps/red-ui/src/app/modules/dossier/dialogs/change-legal-basis-dialog/change-legal-basis-dialog.component.ts +++ b/apps/red-ui/src/app/modules/dossier/dialogs/change-legal-basis-dialog/change-legal-basis-dialog.component.ts @@ -17,7 +17,7 @@ export interface LegalBasisOption { templateUrl: './change-legal-basis-dialog.component.html', }) export class ChangeLegalBasisDialogComponent implements OnInit { - legalBasisForm: FormGroup; + form: FormGroup = this._getForm(); isDocumentAdmin: boolean; legalOptions: LegalBasisOption[] = []; @@ -31,17 +31,10 @@ export class ChangeLegalBasisDialogComponent implements OnInit { ) {} get changed(): boolean { - return this.legalBasisForm.get('reason').value.legalBasis !== this._data.annotations[0].legalBasis; + return this.form.get('reason').value.legalBasis !== this._data.annotations[0].legalBasis; } async ngOnInit() { - this.isDocumentAdmin = this._permissionsService.isApprover(this._data.dossier); - - this.legalBasisForm = this._formBuilder.group({ - reason: [null, Validators.required], - comment: this.isDocumentAdmin ? [null] : [null, Validators.required], - }); - const data = await this._justificationsService.getForDossierTemplate(this._data.dossier.dossierTemplateId).toPromise(); this.legalOptions = data @@ -52,13 +45,13 @@ export class ChangeLegalBasisDialogComponent implements OnInit { })) .sort((a, b) => a.label.localeCompare(b.label)); - this.legalBasisForm.patchValue({ + this.form.patchValue({ reason: this.legalOptions.find(option => option.legalBasis === this._data.annotations[0].legalBasis), }); } private _getForm(): FormGroup { - this.isDocumentAdmin = this._permissionsService.isApprover(); + this.isDocumentAdmin = this._permissionsService.isApprover(this._data.dossier); return this._formBuilder.group({ reason: [null, Validators.required], comment: this.isDocumentAdmin ? [null] : [null, Validators.required], @@ -67,8 +60,8 @@ export class ChangeLegalBasisDialogComponent implements OnInit { save() { this.dialogRef.close({ - legalBasis: this.legalBasisForm.get('reason').value.legalBasis, - comment: this.legalBasisForm.get('comment').value, + legalBasis: this.form.get('reason').value.legalBasis, + comment: this.form.get('comment').value, }); } } diff --git a/apps/red-ui/src/app/modules/dossier/dialogs/document-info-dialog/document-info-dialog.component.html b/apps/red-ui/src/app/modules/dossier/dialogs/document-info-dialog/document-info-dialog.component.html index e913530f5..2d8ddfe7c 100644 --- a/apps/red-ui/src/app/modules/dossier/dialogs/document-info-dialog/document-info-dialog.component.html +++ b/apps/red-ui/src/app/modules/dossier/dialogs/document-info-dialog/document-info-dialog.component.html @@ -1,7 +1,7 @@ -
+
- +
@@ -9,7 +9,7 @@
-
diff --git a/apps/red-ui/src/app/modules/dossier/dialogs/document-info-dialog/document-info-dialog.component.ts b/apps/red-ui/src/app/modules/dossier/dialogs/document-info-dialog/document-info-dialog.component.ts index 3683c3bdf..c094fccc5 100644 --- a/apps/red-ui/src/app/modules/dossier/dialogs/document-info-dialog/document-info-dialog.component.ts +++ b/apps/red-ui/src/app/modules/dossier/dialogs/document-info-dialog/document-info-dialog.component.ts @@ -11,8 +11,7 @@ import { DossiersService } from '@services/entity-services/dossiers.service'; styleUrls: ['./document-info-dialog.component.scss'], }) export class DocumentInfoDialogComponent implements OnInit { - documentInfoForm: FormGroup; - file: IFile; + form: FormGroup; attributes: IFileAttributeConfig[]; private readonly _dossier: Dossier; @@ -25,31 +24,35 @@ export class DocumentInfoDialogComponent implements OnInit { public dialogRef: MatDialogRef, @Inject(MAT_DIALOG_DATA) public data: IFile, ) { - this.file = this.data; - this._dossier = this._dossiersService.find(this.file.dossierId); + this._dossier = this._dossiersService.find(this.data.dossierId); } async ngOnInit() { this.attributes = ( await this._fileAttributesService.getFileAttributesConfig(this._dossier.dossierTemplateId).toPromise() ).fileAttributeConfigs.filter(attr => attr.editable); - const formConfig = this.attributes.reduce( - (acc, attr) => ({ - ...acc, - [attr.id]: [this.file.fileAttributes?.attributeIdToValue[attr.id]], - }), - {}, + this.form = this._getForm(); + } + + private _getForm(): FormGroup { + return this._formBuilder.group( + this.attributes.reduce( + (acc, attr) => ({ + ...acc, + [attr.id]: [this.data.fileAttributes?.attributeIdToValue[attr.id]], + }), + {}, + ), ); - this.documentInfoForm = this._formBuilder.group(formConfig); } async saveDocumentInfo() { const attributeIdToValue = { - ...this.file.fileAttributes?.attributeIdToValue, - ...this.documentInfoForm.getRawValue(), + ...this.data.fileAttributes?.attributeIdToValue, + ...this.form.getRawValue(), }; - await this._fileAttributesService.setFileAttributes({ attributeIdToValue }, this.file.dossierId, this.file.fileId).toPromise(); - this.file.fileAttributes = { attributeIdToValue }; + await this._fileAttributesService.setFileAttributes({ attributeIdToValue }, this.data.dossierId, this.data.fileId).toPromise(); + this.data.fileAttributes = { attributeIdToValue }; this.dialogRef.close(true); } } diff --git a/apps/red-ui/src/app/modules/dossier/dialogs/manual-redaction-dialog/manual-annotation-dialog.component.ts b/apps/red-ui/src/app/modules/dossier/dialogs/manual-redaction-dialog/manual-annotation-dialog.component.ts index 17862b78f..bafec82ce 100644 --- a/apps/red-ui/src/app/modules/dossier/dialogs/manual-redaction-dialog/manual-annotation-dialog.component.ts +++ b/apps/red-ui/src/app/modules/dossier/dialogs/manual-redaction-dialog/manual-annotation-dialog.component.ts @@ -62,8 +62,8 @@ export class ManualAnnotationDialogComponent implements OnInit { private get _redactionDictionaries(): Dictionary[] { const redactionDictionaries: Dictionary[] = []; - for (const key of Object.keys(this._appStateService.dictionaryData[data.dossier.dossierTemplateId])) { - const dictionaryData = this._appStateService.getDictionary(key, data.dossier.dossierTemplateId); + for (const key of Object.keys(this._appStateService.dictionaryData[this.data.dossier.dossierTemplateId])) { + const dictionaryData = this._appStateService.getDictionary(key, this.data.dossier.dossierTemplateId); if (!dictionaryData.virtual && dictionaryData.addToDictionaryAction) { redactionDictionaries.push(dictionaryData); }