Added form field parser factory to remove switch in row-parser.ts

This commit is contained in:
Giuseppe Digilio
2018-07-04 16:01:53 +02:00
parent f627c9443e
commit 8dd11c9a3c
27 changed files with 230 additions and 220 deletions

View File

@@ -1,26 +1,26 @@
import { FieldParser } from './field-parser';
import { FormFieldModel } from '../models/form-field.model';
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
import {
DynamicFormControlLayout, DynamicInputModel,
DynamicInputModelConfig
} from '@ng-dynamic-forms/core';
import { DynamicFormControlLayout, DynamicInputModel, DynamicInputModelConfig } from '@ng-dynamic-forms/core';
import {
CONCAT_FIRST_INPUT_SUFFIX,
CONCAT_GROUP_SUFFIX, CONCAT_SECOND_INPUT_SUFFIX,
DynamicConcatModel, DynamicConcatModelConfig
CONCAT_GROUP_SUFFIX,
CONCAT_SECOND_INPUT_SUFFIX,
DynamicConcatModel,
DynamicConcatModelConfig
} from '../ds-dynamic-form-ui/models/ds-dynamic-concat.model';
import { isNotEmpty } from '../../../empty.util';
import { ParserOptions } from './parser-options';
export class ConcatFieldParser extends FieldParser {
constructor(protected configData: FormFieldModel,
protected initFormValues,
protected readOnly: boolean,
private separator: string,
protected parserOptions: ParserOptions,
protected separator: string,
protected firstPlaceholder: string = null,
protected secondPlaceholder: string = null) {
super(configData, initFormValues, readOnly);
super(configData, initFormValues, parserOptions);
this.separator = separator;
this.firstPlaceholder = firstPlaceholder;

View File

@@ -4,12 +4,17 @@ import { SeriesFieldParser } from './series-field-parser';
import { DateFieldParser } from './date-field-parser';
import { DynamicDsDatePickerModel } from '../ds-dynamic-form-ui/models/date-picker/date-picker.model';
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
import { ParserOptions } from './parser-options';
describe('DateFieldParser test suite', () => {
let field: FormFieldModel;
let initFormValues: any = {};
const readOnly = false;
const parserOptions: ParserOptions = {
readOnly: false,
submissionScope: null,
authorityUuid: null
};
beforeEach(() => {
field = {
@@ -32,13 +37,13 @@ describe('DateFieldParser test suite', () => {
});
it('should init parser properly', () => {
const parser = new DateFieldParser(field, initFormValues, readOnly);
const parser = new DateFieldParser(field, initFormValues, parserOptions);
expect(parser instanceof DateFieldParser).toBe(true);
});
it('should return a DynamicDsDatePickerModel object when repeatable option is false', () => {
const parser = new DateFieldParser(field, initFormValues, readOnly);
const parser = new DateFieldParser(field, initFormValues, parserOptions);
const fieldModel = parser.parse();
@@ -51,7 +56,7 @@ describe('DateFieldParser test suite', () => {
};
const expectedValue = '1983-11-18';
const parser = new DateFieldParser(field, initFormValues, readOnly);
const parser = new DateFieldParser(field, initFormValues, parserOptions);
const fieldModel = parser.parse();

View File

@@ -1,13 +1,17 @@
import { FormFieldModel } from '../models/form-field.model';
import { DropdownFieldParser } from './dropdown-field-parser';
import { DynamicScrollableDropdownModel } from '../ds-dynamic-form-ui/models/scrollable-dropdown/dynamic-scrollable-dropdown.model';
import { ParserOptions } from './parser-options';
describe('DropdownFieldParser test suite', () => {
let field: FormFieldModel;
const authorityUuid = 'testScopeUUID';
const initFormValues = {};
const readOnly = false;
const parserOptions: ParserOptions = {
readOnly: false,
submissionScope: 'testScopeUUID',
authorityUuid: null
};
beforeEach(() => {
field = {
@@ -31,13 +35,13 @@ describe('DropdownFieldParser test suite', () => {
});
it('should init parser properly', () => {
const parser = new DropdownFieldParser(field, initFormValues, readOnly, authorityUuid);
const parser = new DropdownFieldParser(field, initFormValues, parserOptions);
expect(parser instanceof DropdownFieldParser).toBe(true);
});
it('should return a DynamicScrollableDropdownModel object when repeatable option is false', () => {
const parser = new DropdownFieldParser(field, initFormValues, readOnly, authorityUuid);
const parser = new DropdownFieldParser(field, initFormValues, parserOptions);
const fieldModel = parser.parse();
@@ -46,7 +50,7 @@ describe('DropdownFieldParser test suite', () => {
it('should throw when authority is not passed', () => {
field.selectableMetadata[0].authority = null;
const parser = new DropdownFieldParser(field, initFormValues, readOnly, authorityUuid);
const parser = new DropdownFieldParser(field, initFormValues, parserOptions);
expect(() => parser.parse())
.toThrow();

View File

@@ -4,25 +4,17 @@ import {
DynamicScrollableDropdownModel,
DynamicScrollableDropdownModelConfig
} from '../ds-dynamic-form-ui/models/scrollable-dropdown/dynamic-scrollable-dropdown.model';
import { FormFieldModel } from '../models/form-field.model';
import { isNotEmpty } from '../../../empty.util';
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
export class DropdownFieldParser extends FieldParser {
constructor(protected configData: FormFieldModel,
protected initFormValues,
protected readOnly: boolean,
protected authorityUuid: string) {
super(configData, initFormValues, readOnly);
}
public modelFactory(fieldValue: FormFieldMetadataValueObject): any {
const dropdownModelConfig: DynamicScrollableDropdownModelConfig = this.initModel();
let layout: DynamicFormControlLayout;
if (isNotEmpty(this.configData.selectableMetadata[0].authority)) {
this.setAuthorityOptions(dropdownModelConfig, this.authorityUuid);
this.setAuthorityOptions(dropdownModelConfig, this.parserOptions.authorityUuid);
if (isNotEmpty(fieldValue)) {
dropdownModelConfig.value = fieldValue;
}

View File

@@ -11,12 +11,13 @@ import { DsDynamicInputModel, DsDynamicInputModelConfig } from '../ds-dynamic-fo
import { DynamicFormControlLayout } from '@ng-dynamic-forms/core';
import { setLayout } from './parser.utils';
import { AuthorityOptions } from '../../../../core/integration/models/authority-options.model';
import { ParserOptions } from './parser-options';
export abstract class FieldParser {
protected fieldId: string;
constructor(protected configData: FormFieldModel, protected initFormValues, protected readOnly: boolean) {
constructor(protected configData: FormFieldModel, protected initFormValues, protected parserOptions: ParserOptions) {
}
public abstract modelFactory(fieldValue?: FormFieldMetadataValueObject): any;
@@ -175,8 +176,8 @@ export abstract class FieldParser {
controlModel.id = (this.fieldId).replace(/\./g, '_');
// Set read only option
controlModel.readOnly = this.readOnly;
controlModel.disabled = this.readOnly;
controlModel.readOnly = this.parserOptions.readOnly;
controlModel.disabled = this.parserOptions.readOnly;
if (label) {
controlModel.label = (labelEmpty) ? ' ' : this.configData.label;

View File

@@ -2,14 +2,17 @@ import { FormFieldModel } from '../models/form-field.model';
import { GroupFieldParser } from './group-field-parser';
import { DynamicGroupModel } from '../ds-dynamic-form-ui/models/dynamic-group/dynamic-group.model';
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
import { ParserOptions } from './parser-options';
describe('GroupFieldParser test suite', () => {
let field: FormFieldModel;
let initFormValues = {};
const authorityUuid = 'testScopeUUID';
const readOnly = false;
const submissionScope = 'WORKSPACE';
const parserOptions: ParserOptions = {
readOnly: false,
submissionScope: 'testScopeUUID',
authorityUuid: 'WORKSPACE'
};
beforeEach(() => {
field = {
@@ -68,13 +71,13 @@ describe('GroupFieldParser test suite', () => {
});
it('should init parser properly', () => {
const parser = new GroupFieldParser(field, initFormValues, readOnly, submissionScope, authorityUuid);
const parser = new GroupFieldParser(field, initFormValues, parserOptions);
expect(parser instanceof GroupFieldParser).toBe(true);
});
it('should return a DynamicGroupModel object', () => {
const parser = new GroupFieldParser(field, initFormValues, readOnly, submissionScope, authorityUuid);
const parser = new GroupFieldParser(field, initFormValues, parserOptions);
const fieldModel = parser.parse();
@@ -83,7 +86,7 @@ describe('GroupFieldParser test suite', () => {
it('should throw when rows configuration is empty', () => {
field.rows = null;
const parser = new GroupFieldParser(field, initFormValues, readOnly, submissionScope, authorityUuid);
const parser = new GroupFieldParser(field, initFormValues, parserOptions);
expect(() => parser.parse())
.toThrow();
@@ -94,7 +97,7 @@ describe('GroupFieldParser test suite', () => {
author: [new FormFieldMetadataValueObject('test author')],
affiliation: [new FormFieldMetadataValueObject('test affiliation')]
};
const parser = new GroupFieldParser(field, initFormValues, readOnly, submissionScope, authorityUuid);
const parser = new GroupFieldParser(field, initFormValues, parserOptions);
const fieldModel = parser.parse();
const expectedValue = [{

View File

@@ -3,26 +3,19 @@ import { FormFieldMetadataValueObject } from '../models/form-field-metadata-valu
import { FormFieldModel } from '../models/form-field.model';
import {
DynamicGroupModel,
DynamicGroupModelConfig, PLACEHOLDER_PARENT_METADATA
DynamicGroupModelConfig,
PLACEHOLDER_PARENT_METADATA
} from '../ds-dynamic-form-ui/models/dynamic-group/dynamic-group.model';
import { isNotEmpty } from '../../../empty.util';
import { FormRowModel } from '../../../../core/shared/config/config-submission-forms.model';
export class GroupFieldParser extends FieldParser {
constructor(protected configData: FormFieldModel,
protected initFormValues,
protected readOnly: boolean,
protected submissionScope: string,
protected authorityUuid: string,) {
super(configData, initFormValues, readOnly);
}
public modelFactory(fieldValue: FormFieldMetadataValueObject) {
const modelConfiguration: DynamicGroupModelConfig = this.initModel();
modelConfiguration.scopeUUID = this.authorityUuid;
modelConfiguration.submissionScope = this.submissionScope;
modelConfiguration.scopeUUID = this.parserOptions.authorityUuid;
modelConfiguration.submissionScope = this.parserOptions.submissionScope;
if (this.configData && this.configData.rows && this.configData.rows.length > 0) {
modelConfiguration.formConfiguration = this.configData.rows;
modelConfiguration.relationFields = [];

View File

@@ -3,13 +3,17 @@ import { FormFieldMetadataValueObject } from '../models/form-field-metadata-valu
import { ListFieldParser } from './list-field-parser';
import { DynamicListCheckboxGroupModel } from '../ds-dynamic-form-ui/models/list/dynamic-list-checkbox-group.model';
import { DynamicListRadioGroupModel } from '../ds-dynamic-form-ui/models/list/dynamic-list-radio-group.model';
import { ParserOptions } from './parser-options';
describe('ListFieldParser test suite', () => {
let field: FormFieldModel;
let initFormValues = {};
const authorityUuid = 'testScopeUUID';
const readOnly = false;
const parserOptions: ParserOptions = {
readOnly: false,
submissionScope: 'testScopeUUID',
authorityUuid: null
};
beforeEach(() => {
field = {
@@ -33,13 +37,13 @@ describe('ListFieldParser test suite', () => {
});
it('should init parser properly', () => {
const parser = new ListFieldParser(field, initFormValues, readOnly, authorityUuid);
const parser = new ListFieldParser(field, initFormValues, parserOptions);
expect(parser instanceof ListFieldParser).toBe(true);
});
it('should return a DynamicListCheckboxGroupModel object when repeatable option is true', () => {
const parser = new ListFieldParser(field, initFormValues, readOnly, authorityUuid);
const parser = new ListFieldParser(field, initFormValues, parserOptions);
const fieldModel = parser.parse();
@@ -48,7 +52,7 @@ describe('ListFieldParser test suite', () => {
it('should return a DynamicListRadioGroupModel object when repeatable option is false', () => {
field.repeatable = false;
const parser = new ListFieldParser(field, initFormValues, readOnly, authorityUuid);
const parser = new ListFieldParser(field, initFormValues, parserOptions);
const fieldModel = parser.parse();
@@ -61,7 +65,7 @@ describe('ListFieldParser test suite', () => {
};
const expectedValue = [new FormFieldMetadataValueObject('test type')];
const parser = new ListFieldParser(field, initFormValues, readOnly, authorityUuid);
const parser = new ListFieldParser(field, initFormValues, parserOptions);
const fieldModel = parser.parse();

View File

@@ -1,5 +1,4 @@
import { FieldParser } from './field-parser';
import { FormFieldModel } from '../models/form-field.model';
import { isNotEmpty } from '../../../empty.util';
import { IntegrationSearchOptions } from '../../../../core/integration/models/integration-options.model';
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
@@ -9,13 +8,6 @@ import { DynamicListRadioGroupModel } from '../ds-dynamic-form-ui/models/list/dy
export class ListFieldParser extends FieldParser {
searchOptions: IntegrationSearchOptions;
constructor(protected configData: FormFieldModel,
protected initFormValues,
protected readOnly: boolean,
protected authorityUuid: string) {
super(configData, initFormValues, readOnly);
}
public modelFactory(fieldValue: FormFieldMetadataValueObject): any {
const listModelConfig = this.initModel();
listModelConfig.repeatable = this.configData.repeatable;
@@ -34,7 +26,7 @@ export class ListFieldParser extends FieldParser {
}
});
}
this.setAuthorityOptions(listModelConfig, this.authorityUuid);
this.setAuthorityOptions(listModelConfig, this.parserOptions.authorityUuid);
}
let listModel;

View File

@@ -2,13 +2,17 @@ import { FormFieldModel } from '../models/form-field.model';
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
import { LookupFieldParser } from './lookup-field-parser';
import { DynamicLookupModel } from '../ds-dynamic-form-ui/models/lookup/dynamic-lookup.model';
import { ParserOptions } from './parser-options';
describe('LookupFieldParser test suite', () => {
let field: FormFieldModel;
let initFormValues = {};
const authorityUuid = 'testScopeUUID';
const readOnly = false;
const parserOptions: ParserOptions = {
readOnly: false,
submissionScope: 'testScopeUUID',
authorityUuid: null
};
beforeEach(() => {
field = {
@@ -32,13 +36,13 @@ describe('LookupFieldParser test suite', () => {
});
it('should init parser properly', () => {
const parser = new LookupFieldParser(field, initFormValues, readOnly, authorityUuid);
const parser = new LookupFieldParser(field, initFormValues, parserOptions);
expect(parser instanceof LookupFieldParser).toBe(true);
});
it('should return a DynamicLookupModel object when repeatable option is false', () => {
const parser = new LookupFieldParser(field, initFormValues, readOnly, authorityUuid);
const parser = new LookupFieldParser(field, initFormValues, parserOptions);
const fieldModel = parser.parse();
@@ -51,7 +55,7 @@ describe('LookupFieldParser test suite', () => {
};
const expectedValue = new FormFieldMetadataValueObject('test journal');
const parser = new LookupFieldParser(field, initFormValues, readOnly, authorityUuid);
const parser = new LookupFieldParser(field, initFormValues, parserOptions);
const fieldModel = parser.parse();

View File

@@ -1,21 +1,13 @@
import { FieldParser } from './field-parser';
import { FormFieldModel } from '../models/form-field.model';
import { DynamicLookupModel, DynamicLookupModelConfig } from '../ds-dynamic-form-ui/models/lookup/dynamic-lookup.model';
export class LookupFieldParser extends FieldParser {
constructor(protected configData: FormFieldModel,
protected initFormValues,
protected readOnly: boolean,
protected authorityUuid: string) {
super(configData, initFormValues, readOnly);
}
public modelFactory(fieldValue: any): any {
if (this.configData.selectableMetadata[0].authority) {
const lookupModelConfig: DynamicLookupModelConfig = this.initModel();
this.setAuthorityOptions(lookupModelConfig, this.authorityUuid);
this.setAuthorityOptions(lookupModelConfig, this.parserOptions.authorityUuid);
this.setValues(lookupModelConfig, fieldValue, true);

View File

@@ -4,13 +4,17 @@ import { LookupFieldParser } from './lookup-field-parser';
import { DynamicLookupModel } from '../ds-dynamic-form-ui/models/lookup/dynamic-lookup.model';
import { LookupNameFieldParser } from './lookup-name-field-parser';
import { DynamicLookupNameModel } from '../ds-dynamic-form-ui/models/lookup/dynamic-lookup-name.model';
import { ParserOptions } from './parser-options';
describe('LookupNameFieldParser test suite', () => {
let field: FormFieldModel;
let initFormValues = {};
const authorityUuid = 'testScopeUUID';
const readOnly = false;
const parserOptions: ParserOptions = {
readOnly: false,
submissionScope: 'testScopeUUID',
authorityUuid: null
};
beforeEach(() => {
field = {
@@ -34,13 +38,13 @@ describe('LookupNameFieldParser test suite', () => {
});
it('should init parser properly', () => {
const parser = new LookupNameFieldParser(field, initFormValues, readOnly, authorityUuid);
const parser = new LookupNameFieldParser(field, initFormValues, parserOptions);
expect(parser instanceof LookupNameFieldParser).toBe(true);
});
it('should return a DynamicLookupNameModel object when repeatable option is false', () => {
const parser = new LookupNameFieldParser(field, initFormValues, readOnly, authorityUuid);
const parser = new LookupNameFieldParser(field, initFormValues, parserOptions);
const fieldModel = parser.parse();
@@ -53,7 +57,7 @@ describe('LookupNameFieldParser test suite', () => {
};
const expectedValue = new FormFieldMetadataValueObject('test author');
const parser = new LookupNameFieldParser(field, initFormValues, readOnly, authorityUuid);
const parser = new LookupNameFieldParser(field, initFormValues, parserOptions);
const fieldModel = parser.parse();

View File

@@ -1,4 +1,3 @@
import { FormFieldModel } from '../models/form-field.model';
import { FieldParser } from './field-parser';
import {
DynamicLookupNameModel,
@@ -7,18 +6,11 @@ import {
export class LookupNameFieldParser extends FieldParser {
constructor(protected configData: FormFieldModel,
protected initFormValues,
protected readOnly: boolean,
protected authorityUuid: string) {
super(configData, initFormValues, readOnly);
}
public modelFactory(fieldValue: any): any {
if (this.configData.selectableMetadata[0].authority) {
const lookupModelConfig: DynamicLookupNameModelConfig = this.initModel();
this.setAuthorityOptions(lookupModelConfig, this.authorityUuid);
this.setAuthorityOptions(lookupModelConfig, this.parserOptions.authorityUuid);
this.setValues(lookupModelConfig, fieldValue, true);

View File

@@ -2,6 +2,7 @@ import { FormFieldModel } from '../models/form-field.model';
import { NameFieldParser } from './name-field-parser';
import { DynamicConcatModel } from '../ds-dynamic-form-ui/models/ds-dynamic-concat.model';
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
import { ParserOptions } from './parser-options';
describe('NameFieldParser test suite', () => {
let field1: FormFieldModel;
@@ -9,7 +10,11 @@ describe('NameFieldParser test suite', () => {
let field3: FormFieldModel;
let initFormValues: any = {};
const readOnly = false;
const parserOptions: ParserOptions = {
readOnly: false,
submissionScope: 'testScopeUUID',
authorityUuid: null
};
beforeEach(() => {
field1 = {
@@ -64,13 +69,13 @@ describe('NameFieldParser test suite', () => {
});
it('should init parser properly', () => {
const parser = new NameFieldParser(field1, initFormValues, readOnly);
const parser = new NameFieldParser(field1, initFormValues, parserOptions);
expect(parser instanceof NameFieldParser).toBe(true);
});
it('should return a DynamicConcatModel object when repeatable option is false', () => {
const parser = new NameFieldParser(field2, initFormValues, readOnly);
const parser = new NameFieldParser(field2, initFormValues, parserOptions);
const fieldModel = parser.parse();
@@ -78,7 +83,7 @@ describe('NameFieldParser test suite', () => {
});
it('should return a DynamicConcatModel object with the correct separator', () => {
const parser = new NameFieldParser(field2, initFormValues, readOnly);
const parser = new NameFieldParser(field2, initFormValues, parserOptions);
const fieldModel = parser.parse();
@@ -91,7 +96,7 @@ describe('NameFieldParser test suite', () => {
};
const expectedValue = new FormFieldMetadataValueObject('test, name');
const parser = new NameFieldParser(field1, initFormValues, readOnly);
const parser = new NameFieldParser(field1, initFormValues, parserOptions);
const fieldModel = parser.parse();

View File

@@ -1,10 +1,10 @@
import { FormFieldModel } from '../models/form-field.model';
import { ConcatFieldParser } from './concat-field-parser';
import { ParserOptions } from './parser-options';
export class NameFieldParser extends ConcatFieldParser {
constructor(protected configData: FormFieldModel, protected initFormValues, protected readOnly: boolean) {
super(configData, initFormValues, readOnly, ',', 'form.last-name', 'form.first-name');
constructor(protected configData: FormFieldModel, protected initFormValues, protected parserOptions: ParserOptions) {
super(configData, initFormValues, parserOptions, ',', 'form.last-name', 'form.first-name');
}
}

View File

@@ -3,15 +3,19 @@ import { OneboxFieldParser } from './onebox-field-parser';
import { DynamicQualdropModel } from '../ds-dynamic-form-ui/models/ds-dynamic-qualdrop.model';
import { DynamicTypeaheadModel } from '../ds-dynamic-form-ui/models/typeahead/dynamic-typeahead.model';
import { DsDynamicInputModel } from '../ds-dynamic-form-ui/models/ds-dynamic-input.model';
import { ParserOptions } from './parser-options';
describe('OneboxFieldParser test suite', () => {
let field1: FormFieldModel;
let field2: FormFieldModel;
let field3: FormFieldModel;
const authorityUuid = 'testScopeUUID';
const initFormValues = {};
const readOnly = false;
const parserOptions: ParserOptions = {
readOnly: false,
submissionScope: 'testScopeUUID',
authorityUuid: null
};
beforeEach(() => {
field1 = {
@@ -66,13 +70,13 @@ describe('OneboxFieldParser test suite', () => {
});
it('should init parser properly', () => {
const parser = new OneboxFieldParser(field1, initFormValues, readOnly, authorityUuid);
const parser = new OneboxFieldParser(field1, initFormValues, parserOptions);
expect(parser instanceof OneboxFieldParser).toBe(true);
});
it('should return a DynamicQualdropModel object when selectableMetadata is multiple', () => {
const parser = new OneboxFieldParser(field2, initFormValues, readOnly, authorityUuid);
const parser = new OneboxFieldParser(field2, initFormValues, parserOptions);
const fieldModel = parser.parse();
@@ -80,7 +84,7 @@ describe('OneboxFieldParser test suite', () => {
});
it('should return a DsDynamicInputModel object when selectableMetadata is not multiple', () => {
const parser = new OneboxFieldParser(field3, initFormValues, readOnly, authorityUuid);
const parser = new OneboxFieldParser(field3, initFormValues, parserOptions);
const fieldModel = parser.parse();
@@ -88,7 +92,7 @@ describe('OneboxFieldParser test suite', () => {
});
it('should return a DynamicTypeaheadModel object when selectableMetadata has authority', () => {
const parser = new OneboxFieldParser(field1, initFormValues, readOnly, authorityUuid);
const parser = new OneboxFieldParser(field1, initFormValues, parserOptions);
const fieldModel = parser.parse();

View File

@@ -1,13 +1,12 @@
import { DynamicSelectModel, DynamicSelectModelConfig } from '@ng-dynamic-forms/core';
import { FieldParser } from './field-parser';
import { FormFieldModel } from '../models/form-field.model';
import {
DsDynamicQualdropModelConfig,
DynamicQualdropModel,
QUALDROP_GROUP_SUFFIX,
QUALDROP_METADATA_SUFFIX,
QUALDROP_VALUE_SUFFIX,
DsDynamicQualdropModelConfig,
DynamicQualdropModel
QUALDROP_VALUE_SUFFIX
} from '../ds-dynamic-form-ui/models/ds-dynamic-qualdrop.model';
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
import { isNotEmpty } from '../../../empty.util';
@@ -19,13 +18,6 @@ import {
export class OneboxFieldParser extends FieldParser {
constructor(protected configData: FormFieldModel,
protected initFormValues,
protected readOnly: boolean,
protected authorityUuid: string) {
super(configData, initFormValues, readOnly);
}
public modelFactory(fieldValue: FormFieldMetadataValueObject): any {
if (this.configData.selectableMetadata.length > 1) {
// Case ComboBox
@@ -79,7 +71,7 @@ export class OneboxFieldParser extends FieldParser {
return new DynamicQualdropModel(inputSelectGroup, clsGroup);
} else if (this.configData.selectableMetadata[0].authority) {
const typeaheadModelConfig: DsDynamicTypeaheadModelConfig = this.initModel();
this.setAuthorityOptions(typeaheadModelConfig, this.authorityUuid);
this.setAuthorityOptions(typeaheadModelConfig, this.parserOptions.authorityUuid);
this.setValues(typeaheadModelConfig, fieldValue, true);
const typeaheadModel = new DynamicTypeaheadModel(typeaheadModelConfig);
return typeaheadModel;

View File

@@ -0,0 +1,58 @@
import { ParserType } from './parser-type';
import { GenericConstructor } from '../../../../core/shared/generic-constructor';
import { FieldParser } from './field-parser';
import { DateFieldParser } from './date-field-parser';
import { DropdownFieldParser } from './dropdown-field-parser';
import { GroupFieldParser } from './group-field-parser';
import { ListFieldParser } from './list-field-parser';
import { LookupFieldParser } from './lookup-field-parser';
import { LookupNameFieldParser } from './lookup-name-field-parser';
import { OneboxFieldParser } from './onebox-field-parser';
import { NameFieldParser } from './name-field-parser';
import { SeriesFieldParser } from './series-field-parser';
import { TagFieldParser } from './tag-field-parser';
import { TextareaFieldParser } from './textarea-field-parser';
export class ParserFactory {
public static getConstructor(type: ParserType): GenericConstructor<FieldParser> {
switch (type) {
case ParserType.Date: {
return DateFieldParser
}
case ParserType.Dropdown: {
return DropdownFieldParser
}
case ParserType.Group: {
return GroupFieldParser
}
case ParserType.List: {
return ListFieldParser
}
case ParserType.Lookup: {
return LookupFieldParser
}
case ParserType.LookupName: {
return LookupNameFieldParser
}
case ParserType.Onebox: {
return OneboxFieldParser
}
case ParserType.Name: {
return NameFieldParser
}
case ParserType.Series: {
return SeriesFieldParser
}
case ParserType.Tag: {
return TagFieldParser
}
case ParserType.Textarea: {
return TextareaFieldParser
}
default: {
return undefined;
}
}
}
}

View File

@@ -0,0 +1,5 @@
export interface ParserOptions {
readOnly: boolean;
submissionScope: string;
authorityUuid: string
}

View File

@@ -0,0 +1,13 @@
export enum ParserType {
Date = 'date',
Dropdown = 'dropdown',
Group = 'group',
List = 'list',
Lookup = 'lookup',
LookupName = 'lookup-name',
Onebox = 'onebox',
Name = 'name',
Series = 'series',
Tag = 'tag',
Textarea = 'textarea'
}

View File

@@ -1,32 +1,15 @@
import {
DYNAMIC_FORM_CONTROL_TYPE_ARRAY,
DynamicFormArrayModel,
DynamicFormControlModel,
DynamicFormGroupModelConfig
} from '@ng-dynamic-forms/core';
import { DYNAMIC_FORM_CONTROL_TYPE_ARRAY, DynamicFormGroupModelConfig } from '@ng-dynamic-forms/core';
import { uniqueId } from 'lodash';
import { DateFieldParser } from './date-field-parser';
import { DropdownFieldParser } from './dropdown-field-parser';
import { ListFieldParser } from './list-field-parser';
import { OneboxFieldParser } from './onebox-field-parser';
import { NameFieldParser } from './name-field-parser';
import { SeriesFieldParser } from './series-field-parser';
import { TagFieldParser } from './tag-field-parser';
import { TextareaFieldParser } from './textarea-field-parser';
import { GroupFieldParser } from './group-field-parser';
import { IntegrationSearchOptions } from '../../../../core/integration/models/integration-options.model';
import {
DYNAMIC_FORM_CONTROL_TYPE_RELATION_GROUP,
DynamicGroupModel
} from '../ds-dynamic-form-ui/models/dynamic-group/dynamic-group.model';
import { DYNAMIC_FORM_CONTROL_TYPE_RELATION_GROUP } from '../ds-dynamic-form-ui/models/dynamic-group/dynamic-group.model';
import { DynamicRowGroupModel } from '../ds-dynamic-form-ui/models/ds-dynamic-row-group-model';
import { isEmpty } from '../../../empty.util';
import { LookupFieldParser } from './lookup-field-parser';
import { LookupNameFieldParser } from './lookup-name-field-parser';
import { DsDynamicInputModel } from '../ds-dynamic-form-ui/models/ds-dynamic-input.model';
import { setLayout } from './parser.utils';
import { FormFieldModel } from '../models/form-field.model';
import { ParserType } from './parser-type';
import { ParserOptions } from './parser-options';
import { ParserFactory } from './parser-factory';
export const ROW_ID_PREFIX = 'df-row-group-config-';
@@ -53,56 +36,20 @@ export class RowParser {
const layoutGridClass = ' col-sm-' + Math.trunc(12 / scopedFields.length) + ' d-flex flex-column justify-content-start';
const parserOptions: ParserOptions = {
readOnly: this.readOnly,
submissionScope: this.submissionScope,
authorityUuid: this.authorityOptions.uuid
};
// Iterate over row's fields
scopedFields.forEach((fieldData: FormFieldModel) => {
switch (fieldData.input.type) {
case 'date':
fieldModel = (new DateFieldParser(fieldData, this.initFormValues, this.readOnly).parse());
break;
case 'dropdown':
fieldModel = (new DropdownFieldParser(fieldData, this.initFormValues, this.readOnly, this.authorityOptions.uuid).parse());
break;
case 'list':
fieldModel = (new ListFieldParser(fieldData, this.initFormValues, this.readOnly, this.authorityOptions.uuid).parse());
break;
case 'lookup':
fieldModel = (new LookupFieldParser(fieldData, this.initFormValues, this.readOnly, this.authorityOptions.uuid).parse());
break;
case 'onebox':
fieldModel = (new OneboxFieldParser(fieldData, this.initFormValues, this.readOnly, this.authorityOptions.uuid).parse());
break;
case 'lookup-name':
fieldModel = (new LookupNameFieldParser(fieldData, this.initFormValues, this.readOnly, this.authorityOptions.uuid).parse());
break;
case 'name':
fieldModel = (new NameFieldParser(fieldData, this.initFormValues, this.readOnly).parse());
break;
case 'series':
fieldModel = (new SeriesFieldParser(fieldData, this.initFormValues, this.readOnly).parse());
break;
case 'tag':
fieldModel = (new TagFieldParser(fieldData, this.initFormValues, this.readOnly, this.authorityOptions.uuid).parse());
break;
case 'textarea':
fieldModel = (new TextareaFieldParser(fieldData, this.initFormValues, this.readOnly).parse());
break;
case 'group':
fieldModel = new GroupFieldParser(fieldData, this.initFormValues, this.readOnly, this.submissionScope, this.authorityOptions.uuid).parse();
break;
default:
throw new Error(`unknown form control model type defined on JSON object with label "${fieldData.label}"`);
const parserCo = ParserFactory.getConstructor(fieldData.input.type as ParserType);
if (parserCo) {
fieldModel = new parserCo(fieldData, this.initFormValues, parserOptions).parse();
} else {
throw new Error(`unknown form control model type defined with label "${fieldData.label}"`);
}
if (fieldModel) {

View File

@@ -2,12 +2,17 @@ import { FormFieldModel } from '../models/form-field.model';
import { DynamicConcatModel } from '../ds-dynamic-form-ui/models/ds-dynamic-concat.model';
import { SeriesFieldParser } from './series-field-parser';
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
import { ParserOptions } from './parser-options';
describe('SeriesFieldParser test suite', () => {
let field: FormFieldModel;
let initFormValues: any = {};
const readOnly = false;
const parserOptions: ParserOptions = {
readOnly: false,
submissionScope: 'testScopeUUID',
authorityUuid: null
};
beforeEach(() => {
field = {
@@ -27,13 +32,13 @@ describe('SeriesFieldParser test suite', () => {
});
it('should init parser properly', () => {
const parser = new SeriesFieldParser(field, initFormValues, readOnly);
const parser = new SeriesFieldParser(field, initFormValues, parserOptions);
expect(parser instanceof SeriesFieldParser).toBe(true);
});
it('should return a DynamicConcatModel object when repeatable option is false', () => {
const parser = new SeriesFieldParser(field, initFormValues, readOnly);
const parser = new SeriesFieldParser(field, initFormValues, parserOptions);
const fieldModel = parser.parse();
@@ -41,7 +46,7 @@ describe('SeriesFieldParser test suite', () => {
});
it('should return a DynamicConcatModel object with the correct separator', () => {
const parser = new SeriesFieldParser(field, initFormValues, readOnly);
const parser = new SeriesFieldParser(field, initFormValues, parserOptions);
const fieldModel = parser.parse();
@@ -54,7 +59,7 @@ describe('SeriesFieldParser test suite', () => {
};
const expectedValue = new FormFieldMetadataValueObject('test; series');
const parser = new SeriesFieldParser(field, initFormValues, readOnly);
const parser = new SeriesFieldParser(field, initFormValues, parserOptions);
const fieldModel = parser.parse();

View File

@@ -1,10 +1,10 @@
import { FormFieldModel } from '../models/form-field.model';
import { ConcatFieldParser } from './concat-field-parser';
import { ParserOptions } from './parser-options';
export class SeriesFieldParser extends ConcatFieldParser {
constructor(protected configData: FormFieldModel, protected initFormValues, protected readOnly: boolean) {
super(configData, initFormValues, readOnly, ';');
constructor(protected configData: FormFieldModel, protected initFormValues, protected parserOptions: ParserOptions) {
super(configData, initFormValues, parserOptions, ';');
}
}

View File

@@ -2,13 +2,17 @@ import { FormFieldModel } from '../models/form-field.model';
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
import { TagFieldParser } from './tag-field-parser';
import { DynamicTagModel } from '../ds-dynamic-form-ui/models/tag/dynamic-tag.model';
import { ParserOptions } from './parser-options';
describe('TagFieldParser test suite', () => {
let field: FormFieldModel;
let initFormValues: any = {};
const authorityUuid = 'testScopeUUID';
const readOnly = false;
const parserOptions: ParserOptions = {
readOnly: false,
submissionScope: 'testScopeUUID',
authorityUuid: null
};
beforeEach(() => {
field = {
@@ -32,13 +36,13 @@ describe('TagFieldParser test suite', () => {
});
it('should init parser properly', () => {
const parser = new TagFieldParser(field, initFormValues, readOnly, authorityUuid);
const parser = new TagFieldParser(field, initFormValues, parserOptions);
expect(parser instanceof TagFieldParser).toBe(true);
});
it('should return a DynamicTagModel object when repeatable option is false', () => {
const parser = new TagFieldParser(field, initFormValues, readOnly, authorityUuid);
const parser = new TagFieldParser(field, initFormValues, parserOptions);
const fieldModel = parser.parse();
@@ -53,7 +57,7 @@ describe('TagFieldParser test suite', () => {
],
};
const parser = new TagFieldParser(field, initFormValues, readOnly, authorityUuid);
const parser = new TagFieldParser(field, initFormValues, parserOptions);
const fieldModel = parser.parse();

View File

@@ -1,23 +1,14 @@
import { FieldParser } from './field-parser';
import { FormFieldModel } from '../models/form-field.model';
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
import { isNotEmpty } from '../../../empty.util';
import { DynamicTagModel, DynamicTagModelConfig } from '../ds-dynamic-form-ui/models/tag/dynamic-tag.model';
export class TagFieldParser extends FieldParser {
constructor(protected configData: FormFieldModel,
protected initFormValues,
protected readOnly: boolean,
protected authorityUuid: string) {
super(configData, initFormValues, readOnly);
}
public modelFactory(fieldValue: FormFieldMetadataValueObject): any {
const tagModelConfig: DynamicTagModelConfig = this.initModel();
if (this.configData.selectableMetadata[0].authority
&& this.configData.selectableMetadata[0].authority.length > 0) {
this.setAuthorityOptions(tagModelConfig, this.authorityUuid);
this.setAuthorityOptions(tagModelConfig, this.parserOptions.authorityUuid);
}
this.setValues(tagModelConfig, fieldValue, null, true);

View File

@@ -2,13 +2,17 @@ import { FormFieldModel } from '../models/form-field.model';
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
import { TextareaFieldParser } from './textarea-field-parser';
import { DsDynamicTextAreaModel } from '../ds-dynamic-form-ui/models/ds-dynamic-textarea.model';
import { ParserOptions } from './parser-options';
describe('TextareaFieldParser test suite', () => {
let field: FormFieldModel;
let initFormValues: any = {};
const authorityUuid = 'testScopeUUID';
const readOnly = false;
const parserOptions: ParserOptions = {
readOnly: false,
submissionScope: null,
authorityUuid: null
};
beforeEach(() => {
field = {
@@ -30,13 +34,13 @@ describe('TextareaFieldParser test suite', () => {
});
it('should init parser properly', () => {
const parser = new TextareaFieldParser(field, initFormValues, readOnly);
const parser = new TextareaFieldParser(field, initFormValues, parserOptions);
expect(parser instanceof TextareaFieldParser).toBe(true);
});
it('should return a DsDynamicTextAreaModel object when repeatable option is false', () => {
const parser = new TextareaFieldParser(field, initFormValues, readOnly);
const parser = new TextareaFieldParser(field, initFormValues, parserOptions);
const fieldModel = parser.parse();
@@ -51,7 +55,7 @@ describe('TextareaFieldParser test suite', () => {
};
const expectedValue ='test description';
const parser = new TextareaFieldParser(field, initFormValues, readOnly);
const parser = new TextareaFieldParser(field, initFormValues, parserOptions);
const fieldModel = parser.parse();

View File

@@ -1,10 +1,6 @@
import { FieldParser } from './field-parser';
import {
DynamicFormControlLayout, DynamicTextAreaModel, DynamicTextAreaModelConfig
} from '@ng-dynamic-forms/core';
import { FormFieldModel } from '../models/form-field.model';
import { DynamicFormControlLayout } from '@ng-dynamic-forms/core';
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
import { isNotEmpty } from '../../../empty.util';
import {
DsDynamicTextAreaModel,
DsDynamicTextAreaModelConfig