From be7f21eb3225dba4eb5c6edec4fc096e05bd0ec7 Mon Sep 17 00:00:00 2001 From: Kim Shepherd Date: Thu, 17 Feb 2022 11:50:40 +1300 Subject: [PATCH] [TLC-254] Make the item type field configurable (default dc.type) --- config/config.example.yml | 5 +++++ src/app/shared/form/builder/form-builder.service.ts | 10 +++++++++- src/app/shared/form/builder/parsers/field-parser.ts | 12 ++++++++++-- src/config/default-app-config.ts | 3 +++ src/config/submission-config.interface.ts | 5 +++++ src/environments/environment.test.ts | 3 +++ 6 files changed, 35 insertions(+), 3 deletions(-) diff --git a/config/config.example.yml b/config/config.example.yml index 771c7b1653..fb0b4fd589 100644 --- a/config/config.example.yml +++ b/config/config.example.yml @@ -77,6 +77,11 @@ submission: # NOTE: after how many time (milliseconds) submission is saved automatically # eg. timer: 5 * (1000 * 60); // 5 minutes timer: 0 + typeBind: + # NOTE: which field to use when matching to type-bind configuration, + # eg. dc.type, local.publicationType + # default: dc.type + field: dc.type icons: metadata: # NOTE: example of configuration diff --git a/src/app/shared/form/builder/form-builder.service.ts b/src/app/shared/form/builder/form-builder.service.ts index 33703abf94..12d7585a1c 100644 --- a/src/app/shared/form/builder/form-builder.service.ts +++ b/src/app/shared/form/builder/form-builder.service.ts @@ -33,6 +33,7 @@ import { dateToString, isNgbDateStruct } from '../../date.util'; import { DYNAMIC_FORM_CONTROL_TYPE_RELATION_GROUP } from './ds-dynamic-form-ui/ds-dynamic-form-constants'; import { CONCAT_GROUP_SUFFIX, DynamicConcatModel } from './ds-dynamic-form-ui/models/ds-dynamic-concat.model'; import { VIRTUAL_METADATA_PREFIX } from '../../../core/shared/metadata.models'; +import { environment } from '../../../../environments/environment'; @Injectable() export class FormBuilderService extends DynamicFormService { @@ -49,6 +50,11 @@ export class FormBuilderService extends DynamicFormService { */ private formGroups: Map; + /** + * This is the field to use for type binding + */ + private typeField: string; + constructor( componentService: DynamicFormComponentService, validationService: DynamicFormValidationService, @@ -57,6 +63,8 @@ export class FormBuilderService extends DynamicFormService { super(componentService, validationService); this.formModels = new Map(); this.formGroups = new Map(); + // Replace . with _ in configured type field here, to make configuration more simple and user-friendly + this.typeField = environment.submission.typeBind.field.replace('\.', '_'); } createDynamicFormControlEvent(control: FormControl, group: FormGroup, model: DynamicFormControlModel, type: string): DynamicFormControlEvent { @@ -274,7 +282,7 @@ export class FormBuilderService extends DynamicFormService { } if (isNull(typeBindModel)) { - typeBindModel = this.findById('dc_type', rows); + typeBindModel = this.findById(this.typeField, rows); } if (typeBindModel !== null) { diff --git a/src/app/shared/form/builder/parsers/field-parser.ts b/src/app/shared/form/builder/parsers/field-parser.ts index 838816ebb1..6e1c03efe0 100644 --- a/src/app/shared/form/builder/parsers/field-parser.ts +++ b/src/app/shared/form/builder/parsers/field-parser.ts @@ -17,6 +17,7 @@ import { RelationshipOptions } from '../models/relationship-options.model'; import { VocabularyOptions } from '../../../../core/submission/vocabularies/models/vocabulary-options.model'; import { ParserType } from './parser-type'; import { isNgbDateStruct } from '../../../date.util'; +import { environment } from '../../../../../environments/environment'; export const SUBMISSION_ID: InjectionToken = new InjectionToken('submissionId'); export const CONFIG_DATA: InjectionToken = new InjectionToken('configData'); @@ -26,6 +27,11 @@ export const PARSER_OPTIONS: InjectionToken = new InjectionToken< export abstract class FieldParser { protected fieldId: string; + /** + * This is the field to use for type binding + * @protected + */ + protected typeField: string; constructor( @Inject(SUBMISSION_ID) protected submissionId: string, @@ -33,6 +39,8 @@ 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('\.', '_'); } public abstract modelFactory(fieldValue?: FormFieldMetadataValueObject, label?: boolean): any; @@ -315,14 +323,14 @@ export abstract class FieldParser { const bindValues = []; configuredTypeBindValues.forEach((value) => { bindValues.push({ - id: 'dc_type', + id: this.typeField, 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 ... - // Example: Field [x] will be VISIBLE if dc_type = book OR dc_type = book_part + // Example: Field [x] will be VISIBLE if item type = book OR item type = book_part // // The opposing match value will be the dc.type for the workspace item return [{ diff --git a/src/config/default-app-config.ts b/src/config/default-app-config.ts index dc54c2fcb0..7a4a5047ba 100644 --- a/src/config/default-app-config.ts +++ b/src/config/default-app-config.ts @@ -110,6 +110,9 @@ export class DefaultAppConfig implements AppConfig { */ timer: 0 }, + typeBind: { + field: 'dc.type' + }, icons: { metadata: [ /** diff --git a/src/config/submission-config.interface.ts b/src/config/submission-config.interface.ts index ce275b9bf8..a63af45e38 100644 --- a/src/config/submission-config.interface.ts +++ b/src/config/submission-config.interface.ts @@ -5,6 +5,10 @@ interface AutosaveConfig extends Config { timer: number; } +interface TypeBindConfig extends Config { + field: string; +} + interface IconsConfig extends Config { metadata: MetadataIconConfig[]; authority: { @@ -24,5 +28,6 @@ export interface ConfidenceIconConfig extends Config { export interface SubmissionConfig extends Config { autosave: AutosaveConfig; + typeBind: TypeBindConfig; icons: IconsConfig; } diff --git a/src/environments/environment.test.ts b/src/environments/environment.test.ts index 7c24ef8f05..95237f4b7c 100644 --- a/src/environments/environment.test.ts +++ b/src/environments/environment.test.ts @@ -100,6 +100,9 @@ export const environment: BuildConfig = { // NOTE: every how many minutes submission is saved automatically timer: 5 }, + typeBind: { + field: 'dc.type' + }, icons: { metadata: [ {