Pull request #401: RED-6122: Don't autocomplete current date if not set for file attribute, send proper date string when doing inline edits.

Merge in RED/ui from RED-6122 to master

* commit '0a34d0f914c3614ba7b1673677059f55b9316e0c':
  RED-6122: Refactoring, fix comparison bug.
  RED-6122: Don't autocomplete current date if not set for file attribute, send proper date string when doing inline edits.
This commit is contained in:
George Balanesc 2023-02-16 19:05:17 +01:00
commit 78501289a3
3 changed files with 19 additions and 8 deletions

View File

@ -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<void> {
$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);

View File

@ -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],
};
}, {}),
);

@ -1 +1 @@
Subproject commit 42988aa9ed14830df7d9777550f758e8ce6bc76c
Subproject commit 66f13e9ef0e0cb6c2c323806baf5b0d2ab2446e4