mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-09 11:03:05 +00:00
[TLC-254] Get Type Bind config from backend
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import { Inject, InjectionToken } from '@angular/core';
|
||||
import {Inject, InjectionToken} from '@angular/core';
|
||||
|
||||
import { uniqueId } from 'lodash';
|
||||
import {DynamicFormControlLayout, DynamicFormControlRelation, MATCH_VISIBLE, OR_OPERATOR} from '@ng-dynamic-forms/core';
|
||||
|
||||
import { hasValue, isNotEmpty, isNotNull, isNotUndefined } from '../../../empty.util';
|
||||
import {hasValue, isEmpty, isNotEmpty, isNotNull, isNotUndefined} from '../../../empty.util';
|
||||
import { FormFieldModel } from '../models/form-field.model';
|
||||
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
|
||||
import {
|
||||
@@ -18,6 +18,8 @@ import { VocabularyOptions } from '../../../../core/submission/vocabularies/mode
|
||||
import { ParserType } from './parser-type';
|
||||
import { isNgbDateStruct } from '../../../date.util';
|
||||
import { environment } from '../../../../../environments/environment';
|
||||
import {getFirstCompletedRemoteData} from "../../../../core/shared/operators";
|
||||
import {map} from "rxjs/operators";
|
||||
|
||||
export const SUBMISSION_ID: InjectionToken<string> = new InjectionToken<string>('submissionId');
|
||||
export const CONFIG_DATA: InjectionToken<FormFieldModel> = new InjectionToken<FormFieldModel>('configData');
|
||||
@@ -39,8 +41,6 @@ export abstract class FieldParser {
|
||||
@Inject(INIT_FORM_VALUES) protected initFormValues: any,
|
||||
@Inject(PARSER_OPTIONS) protected parserOptions: ParserOptions
|
||||
) {
|
||||
// Replace . with _ in configured type field here, to make configuration more simple and user-friendly
|
||||
this.typeField = environment.submission.typeBind.field.replace(/\./g, '_');
|
||||
}
|
||||
|
||||
public abstract modelFactory(fieldValue?: FormFieldMetadataValueObject, label?: boolean): any;
|
||||
@@ -75,7 +75,8 @@ export abstract class FieldParser {
|
||||
metadataFields: this.getAllFieldIds(),
|
||||
hasSelectableMetadata: isNotEmpty(this.configData.selectableMetadata),
|
||||
isDraggable,
|
||||
typeBindRelations: isNotEmpty(this.configData.typeBind) ? this.getTypeBindRelations(this.configData.typeBind) : null,
|
||||
typeBindRelations: isNotEmpty(this.configData.typeBind) ? this.getTypeBindRelations(this.configData.typeBind,
|
||||
this.parserOptions.typeField) : null,
|
||||
groupFactory: () => {
|
||||
let model;
|
||||
if ((arrayCounter === 0)) {
|
||||
@@ -303,7 +304,8 @@ export abstract class FieldParser {
|
||||
|
||||
// If typeBind is configured
|
||||
if (isNotEmpty(this.configData.typeBind)) {
|
||||
(controlModel as DsDynamicInputModel).typeBindRelations = this.getTypeBindRelations(this.configData.typeBind);
|
||||
(controlModel as DsDynamicInputModel).typeBindRelations = this.getTypeBindRelations(this.configData.typeBind,
|
||||
this.parserOptions.typeField);
|
||||
}
|
||||
|
||||
return controlModel;
|
||||
@@ -319,11 +321,11 @@ export abstract class FieldParser {
|
||||
* @private
|
||||
* @return DynamicFormControlRelation[] array with one relation in it, for type bind matching to show a field
|
||||
*/
|
||||
private getTypeBindRelations(configuredTypeBindValues: string[]): DynamicFormControlRelation[] {
|
||||
private getTypeBindRelations(configuredTypeBindValues: string[], typeField: string): DynamicFormControlRelation[] {
|
||||
const bindValues = [];
|
||||
configuredTypeBindValues.forEach((value) => {
|
||||
bindValues.push({
|
||||
id: this.typeField,
|
||||
id: typeField,
|
||||
value: value
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user