mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-09 02:54:13 +00:00
[TLC-254] Port submission field type binding from DSpace-CRIS 7
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { Inject, InjectionToken } from '@angular/core';
|
||||
|
||||
import { uniqueId } from 'lodash';
|
||||
import { DynamicFormControlLayout } from '@ng-dynamic-forms/core';
|
||||
import {DynamicFormControlLayout, DynamicFormControlRelation, MATCH_VISIBLE, OR_OPERATOR} from '@ng-dynamic-forms/core';
|
||||
|
||||
import { hasValue, isNotEmpty, isNotNull, isNotUndefined } from '../../../empty.util';
|
||||
import { FormFieldModel } from '../models/form-field.model';
|
||||
@@ -67,6 +67,7 @@ export abstract class FieldParser {
|
||||
metadataFields: this.getAllFieldIds(),
|
||||
hasSelectableMetadata: isNotEmpty(this.configData.selectableMetadata),
|
||||
isDraggable,
|
||||
typeBindRelations: isNotEmpty(this.configData.typeBind) ? this.getTypeBindRelations(this.configData.typeBind) : null,
|
||||
groupFactory: () => {
|
||||
let model;
|
||||
if ((arrayCounter === 0)) {
|
||||
@@ -275,7 +276,7 @@ export abstract class FieldParser {
|
||||
// Set label
|
||||
this.setLabel(controlModel, label);
|
||||
if (hint) {
|
||||
controlModel.hint = this.configData.hints;
|
||||
controlModel.hint = this.configData.hints || ' ';
|
||||
}
|
||||
controlModel.placeholder = this.configData.label;
|
||||
|
||||
@@ -292,9 +293,45 @@ export abstract class FieldParser {
|
||||
(controlModel as DsDynamicInputModel).languageCodes = this.configData.languageCodes;
|
||||
}
|
||||
|
||||
// If typeBind is configured
|
||||
if (isNotEmpty(this.configData.typeBind)) {
|
||||
(controlModel as DsDynamicInputModel).typeBindRelations = this.getTypeBindRelations(this.configData.typeBind);
|
||||
}
|
||||
|
||||
return controlModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the type bind values from the REST data for a specific field
|
||||
* The return value is any[] in the method signature but in reality it's
|
||||
* returning the 'relation' that'll be used for a dynamic matcher when filtering
|
||||
* fields in type bind, made up of a 'match' outcome (make this field visible), an 'operator'
|
||||
* (OR) and a 'when' condition (the bindValues array).
|
||||
* @param configuredTypeBindValues array of types from the submission definition (CONFIG_DATA)
|
||||
* @private
|
||||
* @return DynamicFormControlRelation[] array with one relation in it, for type bind matching to show a field
|
||||
*/
|
||||
private getTypeBindRelations(configuredTypeBindValues: string[]): DynamicFormControlRelation[] {
|
||||
const bindValues = [];
|
||||
configuredTypeBindValues.forEach((value) => {
|
||||
bindValues.push({
|
||||
id: 'dc_type',
|
||||
value: value
|
||||
});
|
||||
});
|
||||
// match: MATCH_VISIBLE means that if true, the field / component will be visible
|
||||
// operator: OR means that all the values in the 'when' condition will be compared with OR, not AND
|
||||
// when: the list of values to match against, in this case the list of strings from <type-bind>...</type-bind>
|
||||
// Example: Field [x] will be VISIBLE if dc_type = book OR dc_type = book_part
|
||||
//
|
||||
// The opposing match value will be the dc.type for the workspace item
|
||||
return [{
|
||||
match: MATCH_VISIBLE,
|
||||
operator: OR_OPERATOR,
|
||||
when: bindValues
|
||||
}];
|
||||
}
|
||||
|
||||
protected hasRegex() {
|
||||
return hasValue(this.configData.input.regex);
|
||||
}
|
||||
|
Reference in New Issue
Block a user