From cc8481f0807ef512efc653276df76808e4bfd9ed Mon Sep 17 00:00:00 2001 From: George Date: Thu, 16 Feb 2023 18:49:48 +0200 Subject: [PATCH 1/2] RED-6122: Don't autocomplete current date if not set for file attribute, send proper date string when doing inline edits. --- .../file-attribute/file-attribute.component.ts | 15 ++++++++++++--- .../document-info-dialog.component.ts | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/apps/red-ui/src/app/modules/dossier-overview/components/table-item/file-attribute/file-attribute.component.ts b/apps/red-ui/src/app/modules/dossier-overview/components/table-item/file-attribute/file-attribute.component.ts index 4f2b58feb..20021ee1d 100644 --- a/apps/red-ui/src/app/modules/dossier-overview/components/table-item/file-attribute/file-attribute.component.ts +++ b/apps/red-ui/src/app/modules/dossier-overview/components/table-item/file-attribute/file-attribute.component.ts @@ -4,9 +4,11 @@ import { BaseFormComponent, Toaster } from '@iqser/common-ui'; import { PermissionsService } from '@services/permissions.service'; import { FormBuilder, UntypedFormGroup } from '@angular/forms'; import { FileAttributesService } from '@services/entity-services/file-attributes.service'; -import { BehaviorSubject, firstValueFrom, Observable } from 'rxjs'; +import { BehaviorSubject, firstValueFrom } from 'rxjs'; import { FilesService } from '@services/files/files.service'; import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; +import dayjs from 'dayjs'; + @Component({ selector: 'redaction-file-attribute [fileAttribute] [file] [dossier]', templateUrl: './file-attribute.component.html', @@ -74,10 +76,17 @@ export class FileAttributeComponent extends BaseFormComponent implements OnInit } async save($event?: MouseEvent): Promise { - $event.stopPropagation(); + $event?.stopPropagation(); try { - const attributeIdToValue = this.form.getRawValue(); + const rawFormValue = this.form.getRawValue(); + const fileAttributeValue = rawFormValue[this.fileAttribute.id]; + const attributeIdToValue = { + ...rawFormValue, + [this.fileAttribute.id]: this.isDate + ? fileAttributeValue && dayjs(fileAttributeValue).format('YYYY-MM-DD') + : fileAttributeValue, + }; await firstValueFrom( this._fileAttributesService.setFileAttributes({ attributeIdToValue }, this.file.dossierId, this.file.fileId), ); diff --git a/apps/red-ui/src/app/modules/file-preview/dialogs/document-info-dialog/document-info-dialog.component.ts b/apps/red-ui/src/app/modules/file-preview/dialogs/document-info-dialog/document-info-dialog.component.ts index 8974e1037..23f5848e0 100644 --- a/apps/red-ui/src/app/modules/file-preview/dialogs/document-info-dialog/document-info-dialog.component.ts +++ b/apps/red-ui/src/app/modules/file-preview/dialogs/document-info-dialog/document-info-dialog.component.ts @@ -53,7 +53,7 @@ export class DocumentInfoDialogComponent extends BaseDialogComponent implements const attrValue = this.file.fileAttributes?.attributeIdToValue[attr.id]; return { ...acc, - [attr.id]: [this._isDate(attr.id) ? dayjs(attrValue).toDate() : attrValue], + [attr.id]: [this._isDate(attr.id) ? attrValue && dayjs(attrValue).toDate() : attrValue], }; }, {}), ); From 0a34d0f914c3614ba7b1673677059f55b9316e0c Mon Sep 17 00:00:00 2001 From: George Date: Thu, 16 Feb 2023 19:58:11 +0200 Subject: [PATCH 2/2] RED-6122: Refactoring, fix comparison bug. --- .../file-attribute.component.ts | 24 ++++++++++--------- libs/common-ui | 2 +- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/apps/red-ui/src/app/modules/dossier-overview/components/table-item/file-attribute/file-attribute.component.ts b/apps/red-ui/src/app/modules/dossier-overview/components/table-item/file-attribute/file-attribute.component.ts index 20021ee1d..c97d5e1a7 100644 --- a/apps/red-ui/src/app/modules/dossier-overview/components/table-item/file-attribute/file-attribute.component.ts +++ b/apps/red-ui/src/app/modules/dossier-overview/components/table-item/file-attribute/file-attribute.component.ts @@ -70,28 +70,26 @@ export class FileAttributeComponent extends BaseFormComponent implements OnInit const config = {}; const fileAttributes = this.file.fileAttributes.attributeIdToValue; Object.keys(fileAttributes).forEach(key => { - config[key] = [fileAttributes[key]]; + const attrValue = fileAttributes[key]; + config[key] = [dayjs(attrValue, 'YYYY-MM-DD', true).isValid() ? dayjs(attrValue).toDate() : attrValue]; }); return this._formBuilder.group(config); } async save($event?: MouseEvent): Promise { $event?.stopPropagation(); - + const rawFormValue = this.form.getRawValue(); + const fileAttrValue = rawFormValue[this.fileAttribute.id]; + const attributeIdToValue = { + ...rawFormValue, + [this.fileAttribute.id]: this.#formatAttributeValue(fileAttrValue), + }; try { - const rawFormValue = this.form.getRawValue(); - const fileAttributeValue = rawFormValue[this.fileAttribute.id]; - const attributeIdToValue = { - ...rawFormValue, - [this.fileAttribute.id]: this.isDate - ? fileAttributeValue && dayjs(fileAttributeValue).format('YYYY-MM-DD') - : fileAttributeValue, - }; await firstValueFrom( this._fileAttributesService.setFileAttributes({ attributeIdToValue }, this.file.dossierId, this.file.fileId), ); await firstValueFrom(this._filesService.reload(this.file.dossierId, this.file)); - this.initialFormValue = this.form.getRawValue(); + this.initialFormValue = rawFormValue; this._toaster.success(_('file-attribute.update.success')); } catch (e) { this._toaster.error(_('file-attribute.update.error')); @@ -105,6 +103,10 @@ export class FileAttributeComponent extends BaseFormComponent implements OnInit this.#toggleEdit(); } + #formatAttributeValue(attrValue) { + return this.isDate ? attrValue && dayjs(attrValue).format('YYYY-MM-DD') : attrValue; + } + #toggleEdit(): void { this.isInEditMode = !this.isInEditMode; this.isEditingFileAttribute$.next(this.isInEditMode); diff --git a/libs/common-ui b/libs/common-ui index 42988aa9e..66f13e9ef 160000 --- a/libs/common-ui +++ b/libs/common-ui @@ -1 +1 @@ -Subproject commit 42988aa9ed14830df7d9777550f758e8ce6bc76c +Subproject commit 66f13e9ef0e0cb6c2c323806baf5b0d2ab2446e4