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..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 @@ -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', @@ -68,21 +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(); - + $event?.stopPropagation(); + const rawFormValue = this.form.getRawValue(); + const fileAttrValue = rawFormValue[this.fileAttribute.id]; + const attributeIdToValue = { + ...rawFormValue, + [this.fileAttribute.id]: this.#formatAttributeValue(fileAttrValue), + }; try { - const attributeIdToValue = this.form.getRawValue(); 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')); @@ -96,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/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], }; }, {}), ); 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