From 06a46aa6c9007b2c555c5480e24eb4f92d77eb96 Mon Sep 17 00:00:00 2001 From: milanmajchrak <90026355+milanmajchrak@users.noreply.github.com> Date: Thu, 5 Dec 2024 10:51:22 +0100 Subject: [PATCH 01/31] UFAL/Temporary fix for the type-bind. The form automatically refreshes after the type is changed. (#761) * The Save action is automatically dispatched when the type is changed * Updated the handleFormSave method name to `dispatchFormSaveAndReinitialize` * Added missing function to mock object --- .../form/builder/form-builder.service.ts | 10 +++--- .../shared/mocks/form-builder-service.mock.ts | 3 +- .../sections/form/section-form.component.ts | 35 +++++++++++++++---- 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/src/app/shared/form/builder/form-builder.service.ts b/src/app/shared/form/builder/form-builder.service.ts index b6f7a4673dd..8755d774f57 100644 --- a/src/app/shared/form/builder/form-builder.service.ts +++ b/src/app/shared/form/builder/form-builder.service.ts @@ -94,7 +94,7 @@ export class FormBuilderService extends DynamicFormService { this.typeFields.set(TYPE_BIND_DEFAULT_KEY, 'dc_type'); // If optional config service was passed, perform an initial set of type field (default dc_type) for type binds if (hasValue(this.configService)) { - this.setTypeBindFieldFromConfig(); + this.setTypeBindFieldFromConfig(this.typeFields); } @@ -560,7 +560,7 @@ export class FormBuilderService extends DynamicFormService { /** * Get the type bind field from config */ - setTypeBindFieldFromConfig(metadataField: string = null): void { + setTypeBindFieldFromConfig(typeBindFields: Map, metadataField: string = null): void { this.configService.findByPropertyName('submit.type-bind.field').pipe( getFirstCompletedRemoteData(), ).subscribe((remoteData: any) => { @@ -584,7 +584,7 @@ export class FormBuilderService extends DynamicFormService { const normalizedValuePart = valuePart.replace(/\./g, '_'); // Set the value in the typeFields map - this.typeFields.set(metadataFieldConfigPart, normalizedValuePart); + typeBindFields.set(metadataFieldConfigPart, normalizedValuePart); if (metadataFieldConfigPart === metadataField) { typeFieldConfigValue = valuePart; @@ -596,7 +596,7 @@ export class FormBuilderService extends DynamicFormService { } // Always update the typeFields map with the default value, normalized - this.typeFields.set(TYPE_BIND_DEFAULT_KEY, typeFieldConfigValue.replace(/\./g, '_')); + typeBindFields.set(TYPE_BIND_DEFAULT_KEY, typeFieldConfigValue.replace(/\./g, '_')); }); }); } @@ -607,7 +607,7 @@ export class FormBuilderService extends DynamicFormService { */ getTypeField(metadataField: string): string { if (hasValue(this.configService) && isEmpty(this.typeFields.values())) { - this.setTypeBindFieldFromConfig(metadataField); + this.setTypeBindFieldFromConfig(this.typeFields, metadataField); } else if (hasNoValue(this.typeFields.get(TYPE_BIND_DEFAULT_KEY))) { this.typeFields.set(TYPE_BIND_DEFAULT_KEY, 'dc_type'); } diff --git a/src/app/shared/mocks/form-builder-service.mock.ts b/src/app/shared/mocks/form-builder-service.mock.ts index eaaeb608297..f863ce905ef 100644 --- a/src/app/shared/mocks/form-builder-service.mock.ts +++ b/src/app/shared/mocks/form-builder-service.mock.ts @@ -39,7 +39,8 @@ export function getMockFormBuilderService(): FormBuilderService { {match: 'VISIBLE', operator: 'OR', when: [{id: 'dc.type', value: 'boundType'}]} ] } - ) + ), + setTypeBindFieldFromConfig: {}, }); } diff --git a/src/app/submission/sections/form/section-form.component.ts b/src/app/submission/sections/form/section-form.component.ts index 02c574c204d..3b4af9f5ade 100644 --- a/src/app/submission/sections/form/section-form.component.ts +++ b/src/app/submission/sections/form/section-form.component.ts @@ -135,6 +135,11 @@ export class SubmissionSectionFormComponent extends SectionModelComponent { */ public sponsorRefreshTimeout = 20; + /** + * The map of type bind fields. We need to have this map to check if the type field is updated. + */ + private typeFields: Map; + /** * The FormComponent reference */ @@ -175,6 +180,7 @@ export class SubmissionSectionFormComponent extends SectionModelComponent { @Inject('sectionDataProvider') public injectedSectionData: SectionDataObject, @Inject('submissionIdProvider') public injectedSubmissionId: string) { super(injectedCollectionId, injectedSectionData, injectedSubmissionId); + this.typeFields = new Map(); } /** @@ -209,6 +215,7 @@ export class SubmissionSectionFormComponent extends SectionModelComponent { this.cdr.detectChanges(); } }); + this.formBuilderService.setTypeBindFieldFromConfig(this.typeFields); } /** @@ -424,17 +431,31 @@ export class SubmissionSectionFormComponent extends SectionModelComponent { this.submissionService.dispatchSave(this.submissionId); } - if (metadata === SPONSOR_METADATA_NAME) { - this.submissionService.dispatchSaveSection(this.submissionId, this.sectionData.id); - this.reinitializeForm(SPONSOR_METADATA_NAME, value); - } + // Check if the type field is updated it could be e.g. `dc.type` or `edm.type` metadata field + // `.some()` method is used to break the loop when the type field is found. + // The values in the `typeFields` are in the format `dc_type` or `edm_type`, so we need to replace `_` with `.` + [...this.typeFields.values()].some(typeValue => { + if (typeValue.replace('_', '.') === metadata) { + this.dispatchFormSaveAndReinitialize(typeValue, value); + return true; + } + }); - if (metadata === AUTHOR_METADATA_FIELD_NAME) { - this.submissionService.dispatchSaveSection(this.submissionId, this.sectionData.id); - this.reinitializeForm(AUTHOR_METADATA_FIELD_NAME, value); + if ([SPONSOR_METADATA_NAME, AUTHOR_METADATA_FIELD_NAME].includes(metadata)) { + this.dispatchFormSaveAndReinitialize(metadata, value); } } + /** + * Dispatch form save and reinitialize form + * @param metadata + * @param value + */ + dispatchFormSaveAndReinitialize(metadata, value) { + this.submissionService.dispatchSaveSection(this.submissionId, this.sectionData.id); + this.reinitializeForm(metadata, value); + } + /** * This method updates specific input field e.g. `local.sponsor` and check if the metadata value was updated * in the DB. When the metadata is updated in the DB refresh this input field. From 50f68bb580e49d70f743ffa333d3be040e46beb2 Mon Sep 17 00:00:00 2001 From: milanmajchrak <90026355+milanmajchrak@users.noreply.github.com> Date: Thu, 5 Dec 2024 10:57:57 +0100 Subject: [PATCH 02/31] Execute autoregistration component only in client side (#762) --- .../autoregistration.component.html | 2 +- .../autoregistration.component.ts | 44 ++++++++++++------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/app/login-page/autoregistration/autoregistration.component.html b/src/app/login-page/autoregistration/autoregistration.component.html index 8c2343ab387..8b100217b57 100644 --- a/src/app/login-page/autoregistration/autoregistration.component.html +++ b/src/app/login-page/autoregistration/autoregistration.component.html @@ -1,4 +1,4 @@ -
+
{{'clarin.autoregistration.welcome.message' | translate}} {{dspaceName$ | async}}