Pull request #400: RED-6122, pass the date as a string for file attributes.
Merge in RED/ui from RED-6122 to master * commit '831b30dd9f81d6baa83f12e29cbd26f6c906241d': RED-6122, pass the date as a string for file attributes.
This commit is contained in:
commit
631296c3ab
@ -7,6 +7,7 @@ import { ActiveDossiersService } from '@services/dossiers/active-dossiers.servic
|
||||
import { FilesService } from '@services/files/files.service';
|
||||
import { BaseDialogComponent } from '@iqser/common-ui';
|
||||
import { firstValueFrom } from 'rxjs';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
@Component({
|
||||
templateUrl: './document-info-dialog.component.html',
|
||||
@ -39,7 +40,7 @@ export class DocumentInfoDialogComponent extends BaseDialogComponent implements
|
||||
async save() {
|
||||
const attributeIdToValue = {
|
||||
...this.file.fileAttributes?.attributeIdToValue,
|
||||
...this.form.getRawValue(),
|
||||
...this._mapFormValues(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));
|
||||
@ -48,13 +49,27 @@ export class DocumentInfoDialogComponent extends BaseDialogComponent implements
|
||||
|
||||
private _getForm(): UntypedFormGroup {
|
||||
return this._formBuilder.group(
|
||||
this.attributes.reduce(
|
||||
(acc, attr) => ({
|
||||
this.attributes.reduce((acc, attr) => {
|
||||
const attrValue = this.file.fileAttributes?.attributeIdToValue[attr.id];
|
||||
return {
|
||||
...acc,
|
||||
[attr.id]: [this.file.fileAttributes?.attributeIdToValue[attr.id]],
|
||||
}),
|
||||
{},
|
||||
),
|
||||
[attr.id]: [this._isDate(attr.id) ? dayjs(attrValue).toDate() : attrValue],
|
||||
};
|
||||
}, {}),
|
||||
);
|
||||
}
|
||||
|
||||
private _isDate(attrId: string) {
|
||||
return this.attributes.find(a => a.id === attrId).type === 'DATE';
|
||||
}
|
||||
|
||||
private _mapFormValues(formValue) {
|
||||
return Object.keys(formValue).reduce((acc, key) => {
|
||||
const crtValue = formValue[key];
|
||||
return {
|
||||
...acc,
|
||||
[key]: this._isDate(key) ? dayjs(crtValue).format('YYYY-MM-DD') : crtValue,
|
||||
};
|
||||
}, {});
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user