Merge branch 'RED-8763' into 'master'

RED-8763: fixed image attribute upload button.

See merge request redactmanager/red-ui!346
This commit is contained in:
Dan Percic 2024-03-15 10:38:11 +01:00
commit e80eb4cd25

View File

@ -39,7 +39,7 @@ export class EditDossierAttributesComponent implements EditDossierSectionInterfa
if (!dayjs(attr.value).isSame(dayjs(this.currentAttrValue(attr)), 'day')) { if (!dayjs(attr.value).isSame(dayjs(this.currentAttrValue(attr)), 'day')) {
return true; return true;
} }
} else if (this._parseAttrValue(attr.value) !== this._parseAttrValue(this.currentAttrValue(attr))) { } else if (this.#parseAttrValue(attr.value) !== this.#parseAttrValue(this.currentAttrValue(attr))) {
return true; return true;
} }
} }
@ -57,8 +57,8 @@ export class EditDossierAttributesComponent implements EditDossierSectionInterfa
async ngOnInit() { async ngOnInit() {
this._loadingService.start(); this._loadingService.start();
await this._loadAttributes(); await this.#loadAttributes();
this.form = this._getForm(); this.form = this.#getForm();
this.initialFormValue = this.form.getRawValue(); this.initialFormValue = this.form.getRawValue();
this._loadingService.stop(); this._loadingService.stop();
} }
@ -74,7 +74,7 @@ export class EditDossierAttributesComponent implements EditDossierSectionInterfa
try { try {
await firstValueFrom(this._dossierAttributesService.setAttributes(this.dossier, dossierAttributeList)); await firstValueFrom(this._dossierAttributesService.setAttributes(this.dossier, dossierAttributeList));
await firstValueFrom(this._dossierAttributesService.loadAll(this.dossier.dossierTemplateId)); await firstValueFrom(this._dossierAttributesService.loadAll(this.dossier.dossierTemplateId));
await this._loadAttributes(); await this.#loadAttributes();
this.initialFormValue = this.form.getRawValue(); this.initialFormValue = this.form.getRawValue();
return { success: true }; return { success: true };
} catch (error) { } catch (error) {
@ -84,7 +84,7 @@ export class EditDossierAttributesComponent implements EditDossierSectionInterfa
} }
fileInputClick(attr: DossierAttributeWithValue) { fileInputClick(attr: DossierAttributeWithValue) {
this._getFileInputById(attr.id).nativeElement.click(); this.#getFileInputById(attr.id).nativeElement.click();
} }
isSpecificType(attr: DossierAttributeWithValue, type: DossierAttributeConfigType): boolean { isSpecificType(attr: DossierAttributeWithValue, type: DossierAttributeConfigType): boolean {
@ -105,11 +105,11 @@ export class EditDossierAttributesComponent implements EditDossierSectionInterfa
this.form.patchValue({ this.form.patchValue({
[attr.id]: result, [attr.id]: result,
}); });
this._getFileInputById(attr.id).nativeElement.value = null; this.#getFileInputById(attr.id).nativeElement.value = null;
} }
revert() { revert() {
this._loadAttributes().then(() => this.form.reset(this.initialFormValue)); this.#loadAttributes().then(() => this.form.reset(this.initialFormValue));
} }
currentAttrValue(attr: DossierAttributeWithValue): string { currentAttrValue(attr: DossierAttributeWithValue): string {
@ -122,21 +122,21 @@ export class EditDossierAttributesComponent implements EditDossierSectionInterfa
}); });
} }
private _getFileInputById(id: string): ElementRef { #getFileInputById(id: string): ElementRef {
return this._fileInputs.find(el => el.nativeElement.id === id); return this._fileInputs.find(el => el.nativeElement.name === id);
} }
private _parseAttrValue(value: any) { #parseAttrValue(value: any) {
return [null, undefined, ''].includes(value) ? undefined : value; return [null, undefined, ''].includes(value) ? undefined : value;
} }
private async _loadAttributes() { async #loadAttributes() {
this.attributes = await this._dossierAttributesService.getWithValues(this.dossier); this.attributes = await this._dossierAttributesService.getWithValues(this.dossier);
this.customAttributes = this.attributes.filter(attr => !this.isSpecificType(attr, this.dossierAttributeConfigTypes.IMAGE)); this.customAttributes = this.attributes.filter(attr => !this.isSpecificType(attr, this.dossierAttributeConfigTypes.IMAGE));
this.imageAttributes = this.attributes.filter(attr => this.isSpecificType(attr, this.dossierAttributeConfigTypes.IMAGE)); this.imageAttributes = this.attributes.filter(attr => this.isSpecificType(attr, this.dossierAttributeConfigTypes.IMAGE));
} }
private _getForm(): UntypedFormGroup { #getForm(): UntypedFormGroup {
const controlsConfig = {}; const controlsConfig = {};
for (const attribute of this.attributes) { for (const attribute of this.attributes) {
controlsConfig[attribute.id] = [{ value: attribute.value, disabled: this.disabled }]; controlsConfig[attribute.id] = [{ value: attribute.value, disabled: this.disabled }];