Merge branch 'w2p-65195_dynamic-component-refactoring' into clean-relationships-in-submission

This commit is contained in:
lotte
2019-10-17 12:49:22 +02:00
573 changed files with 12000 additions and 3824 deletions

View File

@@ -72,6 +72,12 @@ export class SubmissionSectionformComponent extends SectionModelComponent {
*/
public isLoading = true;
/**
* A map representing all field on their way to be removed
* @type {Map}
*/
protected fieldsOnTheirWayToBeRemoved: Map<string, number[]> = new Map();
/**
* The form config
* @type {SubmissionFormsModel}
@@ -311,6 +317,7 @@ export class SubmissionSectionformComponent extends SectionModelComponent {
}),
distinctUntilChanged())
.subscribe((sectionState: SubmissionSectionObject) => {
this.fieldsOnTheirWayToBeRemoved = new Map();
this.updateForm(sectionState.data as WorkspaceitemSectionFormObject, sectionState.errors);
})
)
@@ -364,11 +371,24 @@ export class SubmissionSectionformComponent extends SectionModelComponent {
* the [[DynamicFormControlEvent]] emitted
*/
onRemove(event: DynamicFormControlEvent): void {
const fieldId = this.formBuilderService.getId(event.model);
const fieldIndex = this.formOperationsService.getArrayIndexFromEvent(event);
// Keep track that this field will be removed
if (this.fieldsOnTheirWayToBeRemoved.has(fieldId)) {
const indexes = this.fieldsOnTheirWayToBeRemoved.get(fieldId);
indexes.push(fieldIndex);
this.fieldsOnTheirWayToBeRemoved.set(fieldId, indexes);
} else {
this.fieldsOnTheirWayToBeRemoved.set(fieldId, [fieldIndex]);
}
this.formOperationsService.dispatchOperationsFromEvent(
this.pathCombiner,
event,
this.previousValue,
this.hasStoredValue(this.formBuilderService.getId(event.model), this.formOperationsService.getArrayIndexFromEvent(event)));
this.hasStoredValue(fieldId, fieldIndex));
}
/**
@@ -381,9 +401,23 @@ export class SubmissionSectionformComponent extends SectionModelComponent {
*/
hasStoredValue(fieldId, index): boolean {
if (isNotEmpty(this.sectionData.data)) {
return this.sectionData.data.hasOwnProperty(fieldId) && isNotEmpty(this.sectionData.data[fieldId][index]);
return this.sectionData.data.hasOwnProperty(fieldId) &&
isNotEmpty(this.sectionData.data[fieldId][index]) &&
!this.isFieldToRemove(fieldId, index);
} else {
return false;
}
}
/**
* Check if the specified field is on the way to be removed
*
* @param fieldId
* the section data retrieved from the serverù
* @param index
* the section data retrieved from the server
*/
isFieldToRemove(fieldId, index) {
return this.fieldsOnTheirWayToBeRemoved.has(fieldId) && this.fieldsOnTheirWayToBeRemoved.get(fieldId).includes(index);
}
}

View File

@@ -155,14 +155,14 @@ export class SubmissionSectionUploadComponent extends SectionModelComponent {
filter((submissionObject: SubmissionObjectEntry) => isUndefined(this.collectionId) || this.collectionId !== submissionObject.collection),
tap((submissionObject: SubmissionObjectEntry) => this.collectionId = submissionObject.collection),
flatMap((submissionObject: SubmissionObjectEntry) => this.collectionDataService.findById(submissionObject.collection)),
find((rd: RemoteData<Collection>) => isNotUndefined((rd.payload))),
filter((rd: RemoteData<Collection>) => isNotUndefined((rd.payload))),
tap((collectionRemoteData: RemoteData<Collection>) => this.collectionName = collectionRemoteData.payload.name),
flatMap((collectionRemoteData: RemoteData<Collection>) => {
return this.resourcePolicyService.findByHref(
(collectionRemoteData.payload as any)._links.defaultAccessConditions
);
}),
find((defaultAccessConditionsRemoteData: RemoteData<ResourcePolicy>) =>
filter((defaultAccessConditionsRemoteData: RemoteData<ResourcePolicy>) =>
defaultAccessConditionsRemoteData.hasSucceeded),
tap((defaultAccessConditionsRemoteData: RemoteData<ResourcePolicy>) => {
if (isNotEmpty(defaultAccessConditionsRemoteData.payload)) {
@@ -171,7 +171,6 @@ export class SubmissionSectionUploadComponent extends SectionModelComponent {
}
}),
flatMap(() => config$),
take(1),
flatMap((config: SubmissionUploadsModel) => {
this.availableAccessConditionOptions = isNotEmpty(config.accessConditionOptions) ? config.accessConditionOptions : [];