forked from hazza/dspace-angular
[CST-3782] Make changes in order to remove template row in form's repeatable fields
This commit is contained in:
@@ -9,15 +9,7 @@ import {
|
||||
DynamicFormControlModel
|
||||
} from '@ng-dynamic-forms/core';
|
||||
|
||||
import {
|
||||
hasNoValue,
|
||||
hasValue,
|
||||
isNotEmpty,
|
||||
isNotNull,
|
||||
isNotUndefined,
|
||||
isNull,
|
||||
isUndefined
|
||||
} from '../../../shared/empty.util';
|
||||
import { 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';
|
||||
@@ -30,6 +22,7 @@ import { DynamicQualdropModel } from '../../../shared/form/builder/ds-dynamic-fo
|
||||
import { DynamicRelationGroupModel } from '../../../shared/form/builder/ds-dynamic-form-ui/models/relation-group/dynamic-relation-group.model';
|
||||
import { VocabularyEntryDetail } from '../../../core/submission/vocabularies/models/vocabulary-entry-detail.model';
|
||||
import { deepClone } from 'fast-json-patch';
|
||||
import { dateToString, isNgbDateStruct } from '../../../shared/date.util';
|
||||
|
||||
/**
|
||||
* The service handling all form section operations
|
||||
@@ -71,9 +64,6 @@ export class SectionFormOperationsService {
|
||||
case 'change':
|
||||
this.dispatchOperationsFromChangeEvent(pathCombiner, event, previousValue, hasStoredValue);
|
||||
break;
|
||||
case 'add':
|
||||
this.dispatchOperationsFromAddEvent(pathCombiner, event);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -245,6 +235,8 @@ export class SectionFormOperationsService {
|
||||
// Language without Authority (input, textArea)
|
||||
fieldValue = new FormFieldMetadataValueObject(value, language);
|
||||
}
|
||||
} else if (isNgbDateStruct(value)) {
|
||||
fieldValue = new FormFieldMetadataValueObject(dateToString(value));
|
||||
} else if (value instanceof FormFieldLanguageValueObject || value instanceof VocabularyEntry
|
||||
|| value instanceof VocabularyEntryDetail || isObject(value)) {
|
||||
fieldValue = value;
|
||||
@@ -295,7 +287,7 @@ export class SectionFormOperationsService {
|
||||
const value = this.getFieldValueFromChangeEvent(event);
|
||||
if (this.formBuilder.isQualdropGroup(event.model as DynamicFormControlModel)) {
|
||||
this.dispatchOperationsFromMap(this.getQualdropValueMap(event), pathCombiner, event, previousValue);
|
||||
} else if (isNotEmpty(value)) {
|
||||
} else if (isNotEmpty(value) && (value instanceof FormFieldMetadataValueObject && value.hasValue())) {
|
||||
this.operationsBuilder.remove(pathCombiner.getPath(path));
|
||||
}
|
||||
}
|
||||
@@ -362,7 +354,7 @@ 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) && hasNoValue((event.model as any).relationshipConfig)) {
|
||||
} else if (this.formBuilder.hasArrayGroupValue(event.model)) {
|
||||
// Model has as value an array, so dispatch an add operation with entire block of values
|
||||
this.operationsBuilder.add(
|
||||
pathCombiner.getPath(segmentedPath),
|
||||
@@ -398,13 +390,22 @@ export class SectionFormOperationsService {
|
||||
value);
|
||||
}
|
||||
previousValue.delete();
|
||||
} else if (value.hasValue() && (isUndefined(this.getArrayIndexFromEvent(event))
|
||||
|| this.getArrayIndexFromEvent(event) === 0)) {
|
||||
} else if (value.hasValue()) {
|
||||
// Here model has no previous value but a new one
|
||||
if (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