mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-14 05:23:06 +00:00
Merge remote-tracking branch 'remotes/origin/main' into authorities_and_controlled_vocabularies
This commit is contained in:
@@ -9,7 +9,15 @@ import {
|
||||
DynamicFormControlModel
|
||||
} from '@ng-dynamic-forms/core';
|
||||
|
||||
import { isNotEmpty, isNotNull, isNotUndefined, isNull, isUndefined } from '../../../shared/empty.util';
|
||||
import {
|
||||
hasNoValue,
|
||||
hasValue,
|
||||
isNotEmpty,
|
||||
isNotNull,
|
||||
isNotUndefined,
|
||||
isNull,
|
||||
isUndefined
|
||||
} from '../../../shared/empty.util';
|
||||
import { JsonPatchOperationPathCombiner } from '../../../core/json-patch/builder/json-patch-operation-path-combiner';
|
||||
import { FormFieldPreviousValueObject } from '../../../shared/form/builder/models/form-field-previous-value-object';
|
||||
import { JsonPatchOperationsBuilder } from '../../../core/json-patch/builder/json-patch-operations-builder';
|
||||
@@ -62,6 +70,9 @@ export class SectionFormOperationsService {
|
||||
case 'change':
|
||||
this.dispatchOperationsFromChangeEvent(pathCombiner, event, previousValue, hasStoredValue);
|
||||
break;
|
||||
case 'add':
|
||||
this.dispatchOperationsFromAddEvent(pathCombiner, event);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -174,7 +185,7 @@ export class SectionFormOperationsService {
|
||||
metadataValueMap.set(groupModel.qualdropId, metadataValueList);
|
||||
}
|
||||
if (index === fieldIndex) {
|
||||
path = groupModel.qualdropId + '/' + (metadataValueMap.get(groupModel.qualdropId).length - 1)
|
||||
path = groupModel.qualdropId + '/' + (metadataValueList.length - 1)
|
||||
}
|
||||
});
|
||||
|
||||
@@ -288,6 +299,42 @@ export class SectionFormOperationsService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle form add operations
|
||||
*
|
||||
* @param pathCombiner
|
||||
* the [[JsonPatchOperationPathCombiner]] object for the specified operation
|
||||
* @param event
|
||||
* the [[DynamicFormControlEvent]] for the specified operation
|
||||
*/
|
||||
protected dispatchOperationsFromAddEvent(
|
||||
pathCombiner: JsonPatchOperationPathCombiner,
|
||||
event: DynamicFormControlEvent
|
||||
): void {
|
||||
const path = this.getFieldPathSegmentedFromChangeEvent(event);
|
||||
const value = this.getFieldValueFromChangeEvent(event);
|
||||
if (isNotEmpty(value)) {
|
||||
value.place = this.getArrayIndexFromEvent(event);
|
||||
if (hasValue(event.group) && hasValue(event.group.value)) {
|
||||
const valuesInGroup = event.group.value
|
||||
.map((g) => Object.values(g))
|
||||
.reduce((accumulator, currentValue) => accumulator.concat(currentValue))
|
||||
.filter((v) => isNotEmpty(v));
|
||||
if (valuesInGroup.length === 1) {
|
||||
// The first add for a field needs to be a different PATCH operation
|
||||
// for some reason
|
||||
this.operationsBuilder.add(
|
||||
pathCombiner.getPath([path]),
|
||||
[value], false);
|
||||
} else {
|
||||
this.operationsBuilder.add(
|
||||
pathCombiner.getPath([path, '-']),
|
||||
value, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle form change operations
|
||||
*
|
||||
@@ -314,14 +361,29 @@ export class SectionFormOperationsService {
|
||||
} else if (this.formBuilder.isRelationGroup(event.model)) {
|
||||
// It's a relation model
|
||||
this.dispatchOperationsFromMap(this.getValueMap(value), pathCombiner, event, previousValue);
|
||||
} else if (this.formBuilder.hasArrayGroupValue(event.model)) {
|
||||
} else if (this.formBuilder.hasArrayGroupValue(event.model) && hasNoValue((event.model as any).relationshipConfig)) {
|
||||
// Model has as value an array, so dispatch an add operation with entire block of values
|
||||
this.operationsBuilder.add(
|
||||
pathCombiner.getPath(segmentedPath),
|
||||
value, true);
|
||||
} else if (previousValue.isPathEqual(this.formBuilder.getPath(event.model)) || hasStoredValue) {
|
||||
// Here model has a previous value changed or stored in the server
|
||||
if (!value.hasValue()) {
|
||||
if (hasValue(event.$event) && hasValue(event.$event.previousIndex)) {
|
||||
if (event.$event.previousIndex < 0) {
|
||||
this.operationsBuilder.add(
|
||||
pathCombiner.getPath(segmentedPath),
|
||||
value, true);
|
||||
} else {
|
||||
const moveTo = pathCombiner.getPath(path);
|
||||
const moveFrom = pathCombiner.getPath(segmentedPath + '/' + event.$event.previousIndex);
|
||||
if (isNotEmpty(moveFrom.path) && isNotEmpty(moveTo.path) && moveFrom.path !== moveTo.path) {
|
||||
this.operationsBuilder.move(
|
||||
moveTo,
|
||||
moveFrom.path
|
||||
)
|
||||
}
|
||||
}
|
||||
} else if (!value.hasValue()) {
|
||||
// New value is empty, so dispatch a remove operation
|
||||
if (this.getArrayIndexFromEvent(event) === 0) {
|
||||
this.operationsBuilder.remove(pathCombiner.getPath(segmentedPath));
|
||||
@@ -335,22 +397,13 @@ export class SectionFormOperationsService {
|
||||
value);
|
||||
}
|
||||
previousValue.delete();
|
||||
} else if (value.hasValue()) {
|
||||
// Here model has no previous value but a new one
|
||||
if (isUndefined(this.getArrayIndexFromEvent(event))
|
||||
|| this.getArrayIndexFromEvent(event) === 0) {
|
||||
} else if (value.hasValue() && (isUndefined(this.getArrayIndexFromEvent(event))
|
||||
|| this.getArrayIndexFromEvent(event) === 0)) {
|
||||
// Model is single field or is part of an array model but is the first item,
|
||||
// so dispatch an add operation that initialize the values of a specific metadata
|
||||
this.operationsBuilder.add(
|
||||
pathCombiner.getPath(segmentedPath),
|
||||
value, true);
|
||||
} else {
|
||||
// Model is part of an array model but is not the first item,
|
||||
// so dispatch an add operation that add a value to an existent metadata
|
||||
this.operationsBuilder.add(
|
||||
pathCombiner.getPath(path),
|
||||
value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user