mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 18:14:17 +00:00
Added form field parser factory to remove switch in row-parser.ts
This commit is contained in:
@@ -1,26 +1,26 @@
|
|||||||
import { FieldParser } from './field-parser';
|
import { FieldParser } from './field-parser';
|
||||||
import { FormFieldModel } from '../models/form-field.model';
|
import { FormFieldModel } from '../models/form-field.model';
|
||||||
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
|
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
|
||||||
import {
|
import { DynamicFormControlLayout, DynamicInputModel, DynamicInputModelConfig } from '@ng-dynamic-forms/core';
|
||||||
DynamicFormControlLayout, DynamicInputModel,
|
|
||||||
DynamicInputModelConfig
|
|
||||||
} from '@ng-dynamic-forms/core';
|
|
||||||
import {
|
import {
|
||||||
CONCAT_FIRST_INPUT_SUFFIX,
|
CONCAT_FIRST_INPUT_SUFFIX,
|
||||||
CONCAT_GROUP_SUFFIX, CONCAT_SECOND_INPUT_SUFFIX,
|
CONCAT_GROUP_SUFFIX,
|
||||||
DynamicConcatModel, DynamicConcatModelConfig
|
CONCAT_SECOND_INPUT_SUFFIX,
|
||||||
|
DynamicConcatModel,
|
||||||
|
DynamicConcatModelConfig
|
||||||
} from '../ds-dynamic-form-ui/models/ds-dynamic-concat.model';
|
} from '../ds-dynamic-form-ui/models/ds-dynamic-concat.model';
|
||||||
import { isNotEmpty } from '../../../empty.util';
|
import { isNotEmpty } from '../../../empty.util';
|
||||||
|
import { ParserOptions } from './parser-options';
|
||||||
|
|
||||||
export class ConcatFieldParser extends FieldParser {
|
export class ConcatFieldParser extends FieldParser {
|
||||||
|
|
||||||
constructor(protected configData: FormFieldModel,
|
constructor(protected configData: FormFieldModel,
|
||||||
protected initFormValues,
|
protected initFormValues,
|
||||||
protected readOnly: boolean,
|
protected parserOptions: ParserOptions,
|
||||||
private separator: string,
|
protected separator: string,
|
||||||
protected firstPlaceholder: string = null,
|
protected firstPlaceholder: string = null,
|
||||||
protected secondPlaceholder: string = null) {
|
protected secondPlaceholder: string = null) {
|
||||||
super(configData, initFormValues, readOnly);
|
super(configData, initFormValues, parserOptions);
|
||||||
|
|
||||||
this.separator = separator;
|
this.separator = separator;
|
||||||
this.firstPlaceholder = firstPlaceholder;
|
this.firstPlaceholder = firstPlaceholder;
|
||||||
@@ -71,7 +71,7 @@ export class ConcatFieldParser extends FieldParser {
|
|||||||
|
|
||||||
// Init values
|
// Init values
|
||||||
if (isNotEmpty(fieldValue)) {
|
if (isNotEmpty(fieldValue)) {
|
||||||
const values = fieldValue.value.split(this.separator);
|
const values = fieldValue.value.split(this.separator);
|
||||||
|
|
||||||
if (values.length > 1) {
|
if (values.length > 1) {
|
||||||
input1ModelConfig.value = values[0].trim();
|
input1ModelConfig.value = values[0].trim();
|
||||||
|
@@ -4,12 +4,17 @@ import { SeriesFieldParser } from './series-field-parser';
|
|||||||
import { DateFieldParser } from './date-field-parser';
|
import { DateFieldParser } from './date-field-parser';
|
||||||
import { DynamicDsDatePickerModel } from '../ds-dynamic-form-ui/models/date-picker/date-picker.model';
|
import { DynamicDsDatePickerModel } from '../ds-dynamic-form-ui/models/date-picker/date-picker.model';
|
||||||
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
|
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
|
||||||
|
import { ParserOptions } from './parser-options';
|
||||||
|
|
||||||
describe('DateFieldParser test suite', () => {
|
describe('DateFieldParser test suite', () => {
|
||||||
let field: FormFieldModel;
|
let field: FormFieldModel;
|
||||||
let initFormValues: any = {};
|
let initFormValues: any = {};
|
||||||
|
|
||||||
const readOnly = false;
|
const parserOptions: ParserOptions = {
|
||||||
|
readOnly: false,
|
||||||
|
submissionScope: null,
|
||||||
|
authorityUuid: null
|
||||||
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
field = {
|
field = {
|
||||||
@@ -32,13 +37,13 @@ describe('DateFieldParser test suite', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should init parser properly', () => {
|
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);
|
expect(parser instanceof DateFieldParser).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return a DynamicDsDatePickerModel object when repeatable option is false', () => {
|
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();
|
const fieldModel = parser.parse();
|
||||||
|
|
||||||
@@ -51,7 +56,7 @@ describe('DateFieldParser test suite', () => {
|
|||||||
};
|
};
|
||||||
const expectedValue = '1983-11-18';
|
const expectedValue = '1983-11-18';
|
||||||
|
|
||||||
const parser = new DateFieldParser(field, initFormValues, readOnly);
|
const parser = new DateFieldParser(field, initFormValues, parserOptions);
|
||||||
|
|
||||||
const fieldModel = parser.parse();
|
const fieldModel = parser.parse();
|
||||||
|
|
||||||
|
@@ -1,13 +1,17 @@
|
|||||||
import { FormFieldModel } from '../models/form-field.model';
|
import { FormFieldModel } from '../models/form-field.model';
|
||||||
import { DropdownFieldParser } from './dropdown-field-parser';
|
import { DropdownFieldParser } from './dropdown-field-parser';
|
||||||
import { DynamicScrollableDropdownModel } from '../ds-dynamic-form-ui/models/scrollable-dropdown/dynamic-scrollable-dropdown.model';
|
import { DynamicScrollableDropdownModel } from '../ds-dynamic-form-ui/models/scrollable-dropdown/dynamic-scrollable-dropdown.model';
|
||||||
|
import { ParserOptions } from './parser-options';
|
||||||
|
|
||||||
describe('DropdownFieldParser test suite', () => {
|
describe('DropdownFieldParser test suite', () => {
|
||||||
let field: FormFieldModel;
|
let field: FormFieldModel;
|
||||||
|
|
||||||
const authorityUuid = 'testScopeUUID';
|
|
||||||
const initFormValues = {};
|
const initFormValues = {};
|
||||||
const readOnly = false;
|
const parserOptions: ParserOptions = {
|
||||||
|
readOnly: false,
|
||||||
|
submissionScope: 'testScopeUUID',
|
||||||
|
authorityUuid: null
|
||||||
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
field = {
|
field = {
|
||||||
@@ -31,13 +35,13 @@ describe('DropdownFieldParser test suite', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should init parser properly', () => {
|
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);
|
expect(parser instanceof DropdownFieldParser).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return a DynamicScrollableDropdownModel object when repeatable option is false', () => {
|
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();
|
const fieldModel = parser.parse();
|
||||||
|
|
||||||
@@ -46,7 +50,7 @@ describe('DropdownFieldParser test suite', () => {
|
|||||||
|
|
||||||
it('should throw when authority is not passed', () => {
|
it('should throw when authority is not passed', () => {
|
||||||
field.selectableMetadata[0].authority = null;
|
field.selectableMetadata[0].authority = null;
|
||||||
const parser = new DropdownFieldParser(field, initFormValues, readOnly, authorityUuid);
|
const parser = new DropdownFieldParser(field, initFormValues, parserOptions);
|
||||||
|
|
||||||
expect(() => parser.parse())
|
expect(() => parser.parse())
|
||||||
.toThrow();
|
.toThrow();
|
||||||
|
@@ -4,25 +4,17 @@ import {
|
|||||||
DynamicScrollableDropdownModel,
|
DynamicScrollableDropdownModel,
|
||||||
DynamicScrollableDropdownModelConfig
|
DynamicScrollableDropdownModelConfig
|
||||||
} from '../ds-dynamic-form-ui/models/scrollable-dropdown/dynamic-scrollable-dropdown.model';
|
} 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 { isNotEmpty } from '../../../empty.util';
|
||||||
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
|
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
|
||||||
|
|
||||||
export class DropdownFieldParser extends FieldParser {
|
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 {
|
public modelFactory(fieldValue: FormFieldMetadataValueObject): any {
|
||||||
const dropdownModelConfig: DynamicScrollableDropdownModelConfig = this.initModel();
|
const dropdownModelConfig: DynamicScrollableDropdownModelConfig = this.initModel();
|
||||||
let layout: DynamicFormControlLayout;
|
let layout: DynamicFormControlLayout;
|
||||||
|
|
||||||
if (isNotEmpty(this.configData.selectableMetadata[0].authority)) {
|
if (isNotEmpty(this.configData.selectableMetadata[0].authority)) {
|
||||||
this.setAuthorityOptions(dropdownModelConfig, this.authorityUuid);
|
this.setAuthorityOptions(dropdownModelConfig, this.parserOptions.authorityUuid);
|
||||||
if (isNotEmpty(fieldValue)) {
|
if (isNotEmpty(fieldValue)) {
|
||||||
dropdownModelConfig.value = fieldValue;
|
dropdownModelConfig.value = fieldValue;
|
||||||
}
|
}
|
||||||
|
@@ -11,12 +11,13 @@ import { DsDynamicInputModel, DsDynamicInputModelConfig } from '../ds-dynamic-fo
|
|||||||
import { DynamicFormControlLayout } from '@ng-dynamic-forms/core';
|
import { DynamicFormControlLayout } from '@ng-dynamic-forms/core';
|
||||||
import { setLayout } from './parser.utils';
|
import { setLayout } from './parser.utils';
|
||||||
import { AuthorityOptions } from '../../../../core/integration/models/authority-options.model';
|
import { AuthorityOptions } from '../../../../core/integration/models/authority-options.model';
|
||||||
|
import { ParserOptions } from './parser-options';
|
||||||
|
|
||||||
export abstract class FieldParser {
|
export abstract class FieldParser {
|
||||||
|
|
||||||
protected fieldId: string;
|
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;
|
public abstract modelFactory(fieldValue?: FormFieldMetadataValueObject): any;
|
||||||
@@ -175,8 +176,8 @@ export abstract class FieldParser {
|
|||||||
controlModel.id = (this.fieldId).replace(/\./g, '_');
|
controlModel.id = (this.fieldId).replace(/\./g, '_');
|
||||||
|
|
||||||
// Set read only option
|
// Set read only option
|
||||||
controlModel.readOnly = this.readOnly;
|
controlModel.readOnly = this.parserOptions.readOnly;
|
||||||
controlModel.disabled = this.readOnly;
|
controlModel.disabled = this.parserOptions.readOnly;
|
||||||
|
|
||||||
if (label) {
|
if (label) {
|
||||||
controlModel.label = (labelEmpty) ? ' ' : this.configData.label;
|
controlModel.label = (labelEmpty) ? ' ' : this.configData.label;
|
||||||
|
@@ -2,14 +2,17 @@ import { FormFieldModel } from '../models/form-field.model';
|
|||||||
import { GroupFieldParser } from './group-field-parser';
|
import { GroupFieldParser } from './group-field-parser';
|
||||||
import { DynamicGroupModel } from '../ds-dynamic-form-ui/models/dynamic-group/dynamic-group.model';
|
import { DynamicGroupModel } from '../ds-dynamic-form-ui/models/dynamic-group/dynamic-group.model';
|
||||||
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
|
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
|
||||||
|
import { ParserOptions } from './parser-options';
|
||||||
|
|
||||||
describe('GroupFieldParser test suite', () => {
|
describe('GroupFieldParser test suite', () => {
|
||||||
let field: FormFieldModel;
|
let field: FormFieldModel;
|
||||||
let initFormValues = {};
|
let initFormValues = {};
|
||||||
|
|
||||||
const authorityUuid = 'testScopeUUID';
|
const parserOptions: ParserOptions = {
|
||||||
const readOnly = false;
|
readOnly: false,
|
||||||
const submissionScope = 'WORKSPACE';
|
submissionScope: 'testScopeUUID',
|
||||||
|
authorityUuid: 'WORKSPACE'
|
||||||
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
field = {
|
field = {
|
||||||
@@ -68,13 +71,13 @@ describe('GroupFieldParser test suite', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should init parser properly', () => {
|
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);
|
expect(parser instanceof GroupFieldParser).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return a DynamicGroupModel object', () => {
|
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();
|
const fieldModel = parser.parse();
|
||||||
|
|
||||||
@@ -83,7 +86,7 @@ describe('GroupFieldParser test suite', () => {
|
|||||||
|
|
||||||
it('should throw when rows configuration is empty', () => {
|
it('should throw when rows configuration is empty', () => {
|
||||||
field.rows = null;
|
field.rows = null;
|
||||||
const parser = new GroupFieldParser(field, initFormValues, readOnly, submissionScope, authorityUuid);
|
const parser = new GroupFieldParser(field, initFormValues, parserOptions);
|
||||||
|
|
||||||
expect(() => parser.parse())
|
expect(() => parser.parse())
|
||||||
.toThrow();
|
.toThrow();
|
||||||
@@ -94,7 +97,7 @@ describe('GroupFieldParser test suite', () => {
|
|||||||
author: [new FormFieldMetadataValueObject('test author')],
|
author: [new FormFieldMetadataValueObject('test author')],
|
||||||
affiliation: [new FormFieldMetadataValueObject('test affiliation')]
|
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 fieldModel = parser.parse();
|
||||||
const expectedValue = [{
|
const expectedValue = [{
|
||||||
|
@@ -3,26 +3,19 @@ import { FormFieldMetadataValueObject } from '../models/form-field-metadata-valu
|
|||||||
import { FormFieldModel } from '../models/form-field.model';
|
import { FormFieldModel } from '../models/form-field.model';
|
||||||
import {
|
import {
|
||||||
DynamicGroupModel,
|
DynamicGroupModel,
|
||||||
DynamicGroupModelConfig, PLACEHOLDER_PARENT_METADATA
|
DynamicGroupModelConfig,
|
||||||
|
PLACEHOLDER_PARENT_METADATA
|
||||||
} from '../ds-dynamic-form-ui/models/dynamic-group/dynamic-group.model';
|
} from '../ds-dynamic-form-ui/models/dynamic-group/dynamic-group.model';
|
||||||
import { isNotEmpty } from '../../../empty.util';
|
import { isNotEmpty } from '../../../empty.util';
|
||||||
import { FormRowModel } from '../../../../core/shared/config/config-submission-forms.model';
|
import { FormRowModel } from '../../../../core/shared/config/config-submission-forms.model';
|
||||||
|
|
||||||
export class GroupFieldParser extends FieldParser {
|
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) {
|
public modelFactory(fieldValue: FormFieldMetadataValueObject) {
|
||||||
const modelConfiguration: DynamicGroupModelConfig = this.initModel();
|
const modelConfiguration: DynamicGroupModelConfig = this.initModel();
|
||||||
|
|
||||||
modelConfiguration.scopeUUID = this.authorityUuid;
|
modelConfiguration.scopeUUID = this.parserOptions.authorityUuid;
|
||||||
modelConfiguration.submissionScope = this.submissionScope;
|
modelConfiguration.submissionScope = this.parserOptions.submissionScope;
|
||||||
if (this.configData && this.configData.rows && this.configData.rows.length > 0) {
|
if (this.configData && this.configData.rows && this.configData.rows.length > 0) {
|
||||||
modelConfiguration.formConfiguration = this.configData.rows;
|
modelConfiguration.formConfiguration = this.configData.rows;
|
||||||
modelConfiguration.relationFields = [];
|
modelConfiguration.relationFields = [];
|
||||||
|
@@ -3,13 +3,17 @@ import { FormFieldMetadataValueObject } from '../models/form-field-metadata-valu
|
|||||||
import { ListFieldParser } from './list-field-parser';
|
import { ListFieldParser } from './list-field-parser';
|
||||||
import { DynamicListCheckboxGroupModel } from '../ds-dynamic-form-ui/models/list/dynamic-list-checkbox-group.model';
|
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 { DynamicListRadioGroupModel } from '../ds-dynamic-form-ui/models/list/dynamic-list-radio-group.model';
|
||||||
|
import { ParserOptions } from './parser-options';
|
||||||
|
|
||||||
describe('ListFieldParser test suite', () => {
|
describe('ListFieldParser test suite', () => {
|
||||||
let field: FormFieldModel;
|
let field: FormFieldModel;
|
||||||
let initFormValues = {};
|
let initFormValues = {};
|
||||||
|
|
||||||
const authorityUuid = 'testScopeUUID';
|
const parserOptions: ParserOptions = {
|
||||||
const readOnly = false;
|
readOnly: false,
|
||||||
|
submissionScope: 'testScopeUUID',
|
||||||
|
authorityUuid: null
|
||||||
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
field = {
|
field = {
|
||||||
@@ -33,13 +37,13 @@ describe('ListFieldParser test suite', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should init parser properly', () => {
|
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);
|
expect(parser instanceof ListFieldParser).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return a DynamicListCheckboxGroupModel object when repeatable option is 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();
|
const fieldModel = parser.parse();
|
||||||
|
|
||||||
@@ -48,7 +52,7 @@ describe('ListFieldParser test suite', () => {
|
|||||||
|
|
||||||
it('should return a DynamicListRadioGroupModel object when repeatable option is false', () => {
|
it('should return a DynamicListRadioGroupModel object when repeatable option is false', () => {
|
||||||
field.repeatable = false;
|
field.repeatable = false;
|
||||||
const parser = new ListFieldParser(field, initFormValues, readOnly, authorityUuid);
|
const parser = new ListFieldParser(field, initFormValues, parserOptions);
|
||||||
|
|
||||||
const fieldModel = parser.parse();
|
const fieldModel = parser.parse();
|
||||||
|
|
||||||
@@ -61,7 +65,7 @@ describe('ListFieldParser test suite', () => {
|
|||||||
};
|
};
|
||||||
const expectedValue = [new FormFieldMetadataValueObject('test type')];
|
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();
|
const fieldModel = parser.parse();
|
||||||
|
|
||||||
|
@@ -1,5 +1,4 @@
|
|||||||
import { FieldParser } from './field-parser';
|
import { FieldParser } from './field-parser';
|
||||||
import { FormFieldModel } from '../models/form-field.model';
|
|
||||||
import { isNotEmpty } from '../../../empty.util';
|
import { isNotEmpty } from '../../../empty.util';
|
||||||
import { IntegrationSearchOptions } from '../../../../core/integration/models/integration-options.model';
|
import { IntegrationSearchOptions } from '../../../../core/integration/models/integration-options.model';
|
||||||
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.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 {
|
export class ListFieldParser extends FieldParser {
|
||||||
searchOptions: IntegrationSearchOptions;
|
searchOptions: IntegrationSearchOptions;
|
||||||
|
|
||||||
constructor(protected configData: FormFieldModel,
|
|
||||||
protected initFormValues,
|
|
||||||
protected readOnly: boolean,
|
|
||||||
protected authorityUuid: string) {
|
|
||||||
super(configData, initFormValues, readOnly);
|
|
||||||
}
|
|
||||||
|
|
||||||
public modelFactory(fieldValue: FormFieldMetadataValueObject): any {
|
public modelFactory(fieldValue: FormFieldMetadataValueObject): any {
|
||||||
const listModelConfig = this.initModel();
|
const listModelConfig = this.initModel();
|
||||||
listModelConfig.repeatable = this.configData.repeatable;
|
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;
|
let listModel;
|
||||||
|
@@ -2,13 +2,17 @@ import { FormFieldModel } from '../models/form-field.model';
|
|||||||
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
|
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
|
||||||
import { LookupFieldParser } from './lookup-field-parser';
|
import { LookupFieldParser } from './lookup-field-parser';
|
||||||
import { DynamicLookupModel } from '../ds-dynamic-form-ui/models/lookup/dynamic-lookup.model';
|
import { DynamicLookupModel } from '../ds-dynamic-form-ui/models/lookup/dynamic-lookup.model';
|
||||||
|
import { ParserOptions } from './parser-options';
|
||||||
|
|
||||||
describe('LookupFieldParser test suite', () => {
|
describe('LookupFieldParser test suite', () => {
|
||||||
let field: FormFieldModel;
|
let field: FormFieldModel;
|
||||||
let initFormValues = {};
|
let initFormValues = {};
|
||||||
|
|
||||||
const authorityUuid = 'testScopeUUID';
|
const parserOptions: ParserOptions = {
|
||||||
const readOnly = false;
|
readOnly: false,
|
||||||
|
submissionScope: 'testScopeUUID',
|
||||||
|
authorityUuid: null
|
||||||
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
field = {
|
field = {
|
||||||
@@ -32,13 +36,13 @@ describe('LookupFieldParser test suite', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should init parser properly', () => {
|
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);
|
expect(parser instanceof LookupFieldParser).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return a DynamicLookupModel object when repeatable option is false', () => {
|
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();
|
const fieldModel = parser.parse();
|
||||||
|
|
||||||
@@ -51,7 +55,7 @@ describe('LookupFieldParser test suite', () => {
|
|||||||
};
|
};
|
||||||
const expectedValue = new FormFieldMetadataValueObject('test journal');
|
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();
|
const fieldModel = parser.parse();
|
||||||
|
|
||||||
|
@@ -1,21 +1,13 @@
|
|||||||
import { FieldParser } from './field-parser';
|
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';
|
import { DynamicLookupModel, DynamicLookupModelConfig } from '../ds-dynamic-form-ui/models/lookup/dynamic-lookup.model';
|
||||||
|
|
||||||
export class LookupFieldParser extends FieldParser {
|
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 {
|
public modelFactory(fieldValue: any): any {
|
||||||
if (this.configData.selectableMetadata[0].authority) {
|
if (this.configData.selectableMetadata[0].authority) {
|
||||||
const lookupModelConfig: DynamicLookupModelConfig = this.initModel();
|
const lookupModelConfig: DynamicLookupModelConfig = this.initModel();
|
||||||
|
|
||||||
this.setAuthorityOptions(lookupModelConfig, this.authorityUuid);
|
this.setAuthorityOptions(lookupModelConfig, this.parserOptions.authorityUuid);
|
||||||
|
|
||||||
this.setValues(lookupModelConfig, fieldValue, true);
|
this.setValues(lookupModelConfig, fieldValue, true);
|
||||||
|
|
||||||
|
@@ -4,13 +4,17 @@ import { LookupFieldParser } from './lookup-field-parser';
|
|||||||
import { DynamicLookupModel } from '../ds-dynamic-form-ui/models/lookup/dynamic-lookup.model';
|
import { DynamicLookupModel } from '../ds-dynamic-form-ui/models/lookup/dynamic-lookup.model';
|
||||||
import { LookupNameFieldParser } from './lookup-name-field-parser';
|
import { LookupNameFieldParser } from './lookup-name-field-parser';
|
||||||
import { DynamicLookupNameModel } from '../ds-dynamic-form-ui/models/lookup/dynamic-lookup-name.model';
|
import { DynamicLookupNameModel } from '../ds-dynamic-form-ui/models/lookup/dynamic-lookup-name.model';
|
||||||
|
import { ParserOptions } from './parser-options';
|
||||||
|
|
||||||
describe('LookupNameFieldParser test suite', () => {
|
describe('LookupNameFieldParser test suite', () => {
|
||||||
let field: FormFieldModel;
|
let field: FormFieldModel;
|
||||||
let initFormValues = {};
|
let initFormValues = {};
|
||||||
|
|
||||||
const authorityUuid = 'testScopeUUID';
|
const parserOptions: ParserOptions = {
|
||||||
const readOnly = false;
|
readOnly: false,
|
||||||
|
submissionScope: 'testScopeUUID',
|
||||||
|
authorityUuid: null
|
||||||
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
field = {
|
field = {
|
||||||
@@ -34,13 +38,13 @@ describe('LookupNameFieldParser test suite', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should init parser properly', () => {
|
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);
|
expect(parser instanceof LookupNameFieldParser).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return a DynamicLookupNameModel object when repeatable option is false', () => {
|
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();
|
const fieldModel = parser.parse();
|
||||||
|
|
||||||
@@ -53,7 +57,7 @@ describe('LookupNameFieldParser test suite', () => {
|
|||||||
};
|
};
|
||||||
const expectedValue = new FormFieldMetadataValueObject('test author');
|
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();
|
const fieldModel = parser.parse();
|
||||||
|
|
||||||
|
@@ -1,4 +1,3 @@
|
|||||||
import { FormFieldModel } from '../models/form-field.model';
|
|
||||||
import { FieldParser } from './field-parser';
|
import { FieldParser } from './field-parser';
|
||||||
import {
|
import {
|
||||||
DynamicLookupNameModel,
|
DynamicLookupNameModel,
|
||||||
@@ -7,18 +6,11 @@ import {
|
|||||||
|
|
||||||
export class LookupNameFieldParser extends FieldParser {
|
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 {
|
public modelFactory(fieldValue: any): any {
|
||||||
if (this.configData.selectableMetadata[0].authority) {
|
if (this.configData.selectableMetadata[0].authority) {
|
||||||
const lookupModelConfig: DynamicLookupNameModelConfig = this.initModel();
|
const lookupModelConfig: DynamicLookupNameModelConfig = this.initModel();
|
||||||
|
|
||||||
this.setAuthorityOptions(lookupModelConfig, this.authorityUuid);
|
this.setAuthorityOptions(lookupModelConfig, this.parserOptions.authorityUuid);
|
||||||
|
|
||||||
this.setValues(lookupModelConfig, fieldValue, true);
|
this.setValues(lookupModelConfig, fieldValue, true);
|
||||||
|
|
||||||
|
@@ -2,6 +2,7 @@ import { FormFieldModel } from '../models/form-field.model';
|
|||||||
import { NameFieldParser } from './name-field-parser';
|
import { NameFieldParser } from './name-field-parser';
|
||||||
import { DynamicConcatModel } from '../ds-dynamic-form-ui/models/ds-dynamic-concat.model';
|
import { DynamicConcatModel } from '../ds-dynamic-form-ui/models/ds-dynamic-concat.model';
|
||||||
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
|
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
|
||||||
|
import { ParserOptions } from './parser-options';
|
||||||
|
|
||||||
describe('NameFieldParser test suite', () => {
|
describe('NameFieldParser test suite', () => {
|
||||||
let field1: FormFieldModel;
|
let field1: FormFieldModel;
|
||||||
@@ -9,7 +10,11 @@ describe('NameFieldParser test suite', () => {
|
|||||||
let field3: FormFieldModel;
|
let field3: FormFieldModel;
|
||||||
let initFormValues: any = {};
|
let initFormValues: any = {};
|
||||||
|
|
||||||
const readOnly = false;
|
const parserOptions: ParserOptions = {
|
||||||
|
readOnly: false,
|
||||||
|
submissionScope: 'testScopeUUID',
|
||||||
|
authorityUuid: null
|
||||||
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
field1 = {
|
field1 = {
|
||||||
@@ -64,13 +69,13 @@ describe('NameFieldParser test suite', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should init parser properly', () => {
|
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);
|
expect(parser instanceof NameFieldParser).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return a DynamicConcatModel object when repeatable option is false', () => {
|
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();
|
const fieldModel = parser.parse();
|
||||||
|
|
||||||
@@ -78,7 +83,7 @@ describe('NameFieldParser test suite', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return a DynamicConcatModel object with the correct separator', () => {
|
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();
|
const fieldModel = parser.parse();
|
||||||
|
|
||||||
@@ -91,7 +96,7 @@ describe('NameFieldParser test suite', () => {
|
|||||||
};
|
};
|
||||||
const expectedValue = new FormFieldMetadataValueObject('test, name');
|
const expectedValue = new FormFieldMetadataValueObject('test, name');
|
||||||
|
|
||||||
const parser = new NameFieldParser(field1, initFormValues, readOnly);
|
const parser = new NameFieldParser(field1, initFormValues, parserOptions);
|
||||||
|
|
||||||
const fieldModel = parser.parse();
|
const fieldModel = parser.parse();
|
||||||
|
|
||||||
|
@@ -1,10 +1,10 @@
|
|||||||
import { FormFieldModel } from '../models/form-field.model';
|
import { FormFieldModel } from '../models/form-field.model';
|
||||||
|
|
||||||
import { ConcatFieldParser } from './concat-field-parser';
|
import { ConcatFieldParser } from './concat-field-parser';
|
||||||
|
import { ParserOptions } from './parser-options';
|
||||||
|
|
||||||
export class NameFieldParser extends ConcatFieldParser {
|
export class NameFieldParser extends ConcatFieldParser {
|
||||||
|
|
||||||
constructor(protected configData: FormFieldModel, protected initFormValues, protected readOnly: boolean) {
|
constructor(protected configData: FormFieldModel, protected initFormValues, protected parserOptions: ParserOptions) {
|
||||||
super(configData, initFormValues, readOnly, ',', 'form.last-name', 'form.first-name');
|
super(configData, initFormValues, parserOptions, ',', 'form.last-name', 'form.first-name');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,15 +3,19 @@ import { OneboxFieldParser } from './onebox-field-parser';
|
|||||||
import { DynamicQualdropModel } from '../ds-dynamic-form-ui/models/ds-dynamic-qualdrop.model';
|
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 { DynamicTypeaheadModel } from '../ds-dynamic-form-ui/models/typeahead/dynamic-typeahead.model';
|
||||||
import { DsDynamicInputModel } from '../ds-dynamic-form-ui/models/ds-dynamic-input.model';
|
import { DsDynamicInputModel } from '../ds-dynamic-form-ui/models/ds-dynamic-input.model';
|
||||||
|
import { ParserOptions } from './parser-options';
|
||||||
|
|
||||||
describe('OneboxFieldParser test suite', () => {
|
describe('OneboxFieldParser test suite', () => {
|
||||||
let field1: FormFieldModel;
|
let field1: FormFieldModel;
|
||||||
let field2: FormFieldModel;
|
let field2: FormFieldModel;
|
||||||
let field3: FormFieldModel;
|
let field3: FormFieldModel;
|
||||||
|
|
||||||
const authorityUuid = 'testScopeUUID';
|
|
||||||
const initFormValues = {};
|
const initFormValues = {};
|
||||||
const readOnly = false;
|
const parserOptions: ParserOptions = {
|
||||||
|
readOnly: false,
|
||||||
|
submissionScope: 'testScopeUUID',
|
||||||
|
authorityUuid: null
|
||||||
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
field1 = {
|
field1 = {
|
||||||
@@ -66,13 +70,13 @@ describe('OneboxFieldParser test suite', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should init parser properly', () => {
|
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);
|
expect(parser instanceof OneboxFieldParser).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return a DynamicQualdropModel object when selectableMetadata is multiple', () => {
|
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();
|
const fieldModel = parser.parse();
|
||||||
|
|
||||||
@@ -80,7 +84,7 @@ describe('OneboxFieldParser test suite', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return a DsDynamicInputModel object when selectableMetadata is not multiple', () => {
|
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();
|
const fieldModel = parser.parse();
|
||||||
|
|
||||||
@@ -88,7 +92,7 @@ describe('OneboxFieldParser test suite', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return a DynamicTypeaheadModel object when selectableMetadata has authority', () => {
|
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();
|
const fieldModel = parser.parse();
|
||||||
|
|
||||||
|
@@ -1,13 +1,12 @@
|
|||||||
import { DynamicSelectModel, DynamicSelectModelConfig } from '@ng-dynamic-forms/core';
|
import { DynamicSelectModel, DynamicSelectModelConfig } from '@ng-dynamic-forms/core';
|
||||||
|
|
||||||
import { FieldParser } from './field-parser';
|
import { FieldParser } from './field-parser';
|
||||||
import { FormFieldModel } from '../models/form-field.model';
|
|
||||||
import {
|
import {
|
||||||
|
DsDynamicQualdropModelConfig,
|
||||||
|
DynamicQualdropModel,
|
||||||
QUALDROP_GROUP_SUFFIX,
|
QUALDROP_GROUP_SUFFIX,
|
||||||
QUALDROP_METADATA_SUFFIX,
|
QUALDROP_METADATA_SUFFIX,
|
||||||
QUALDROP_VALUE_SUFFIX,
|
QUALDROP_VALUE_SUFFIX
|
||||||
DsDynamicQualdropModelConfig,
|
|
||||||
DynamicQualdropModel
|
|
||||||
} from '../ds-dynamic-form-ui/models/ds-dynamic-qualdrop.model';
|
} from '../ds-dynamic-form-ui/models/ds-dynamic-qualdrop.model';
|
||||||
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
|
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
|
||||||
import { isNotEmpty } from '../../../empty.util';
|
import { isNotEmpty } from '../../../empty.util';
|
||||||
@@ -19,13 +18,6 @@ import {
|
|||||||
|
|
||||||
export class OneboxFieldParser extends FieldParser {
|
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 {
|
public modelFactory(fieldValue: FormFieldMetadataValueObject): any {
|
||||||
if (this.configData.selectableMetadata.length > 1) {
|
if (this.configData.selectableMetadata.length > 1) {
|
||||||
// Case ComboBox
|
// Case ComboBox
|
||||||
@@ -79,7 +71,7 @@ export class OneboxFieldParser extends FieldParser {
|
|||||||
return new DynamicQualdropModel(inputSelectGroup, clsGroup);
|
return new DynamicQualdropModel(inputSelectGroup, clsGroup);
|
||||||
} else if (this.configData.selectableMetadata[0].authority) {
|
} else if (this.configData.selectableMetadata[0].authority) {
|
||||||
const typeaheadModelConfig: DsDynamicTypeaheadModelConfig = this.initModel();
|
const typeaheadModelConfig: DsDynamicTypeaheadModelConfig = this.initModel();
|
||||||
this.setAuthorityOptions(typeaheadModelConfig, this.authorityUuid);
|
this.setAuthorityOptions(typeaheadModelConfig, this.parserOptions.authorityUuid);
|
||||||
this.setValues(typeaheadModelConfig, fieldValue, true);
|
this.setValues(typeaheadModelConfig, fieldValue, true);
|
||||||
const typeaheadModel = new DynamicTypeaheadModel(typeaheadModelConfig);
|
const typeaheadModel = new DynamicTypeaheadModel(typeaheadModelConfig);
|
||||||
return typeaheadModel;
|
return typeaheadModel;
|
||||||
|
58
src/app/shared/form/builder/parsers/parser-factory.ts
Normal file
58
src/app/shared/form/builder/parsers/parser-factory.ts
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
5
src/app/shared/form/builder/parsers/parser-options.ts
Normal file
5
src/app/shared/form/builder/parsers/parser-options.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
export interface ParserOptions {
|
||||||
|
readOnly: boolean;
|
||||||
|
submissionScope: string;
|
||||||
|
authorityUuid: string
|
||||||
|
}
|
13
src/app/shared/form/builder/parsers/parser-type.ts
Normal file
13
src/app/shared/form/builder/parsers/parser-type.ts
Normal 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'
|
||||||
|
}
|
@@ -1,32 +1,15 @@
|
|||||||
import {
|
import { DYNAMIC_FORM_CONTROL_TYPE_ARRAY, DynamicFormGroupModelConfig } from '@ng-dynamic-forms/core';
|
||||||
DYNAMIC_FORM_CONTROL_TYPE_ARRAY,
|
|
||||||
DynamicFormArrayModel,
|
|
||||||
DynamicFormControlModel,
|
|
||||||
DynamicFormGroupModelConfig
|
|
||||||
} from '@ng-dynamic-forms/core';
|
|
||||||
import { uniqueId } from 'lodash';
|
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 { IntegrationSearchOptions } from '../../../../core/integration/models/integration-options.model';
|
||||||
import {
|
import { DYNAMIC_FORM_CONTROL_TYPE_RELATION_GROUP } from '../ds-dynamic-form-ui/models/dynamic-group/dynamic-group.model';
|
||||||
DYNAMIC_FORM_CONTROL_TYPE_RELATION_GROUP,
|
|
||||||
DynamicGroupModel
|
|
||||||
} 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 { DynamicRowGroupModel } from '../ds-dynamic-form-ui/models/ds-dynamic-row-group-model';
|
||||||
import { isEmpty } from '../../../empty.util';
|
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 { setLayout } from './parser.utils';
|
||||||
import { FormFieldModel } from '../models/form-field.model';
|
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-';
|
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 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
|
// Iterate over row's fields
|
||||||
scopedFields.forEach((fieldData: FormFieldModel) => {
|
scopedFields.forEach((fieldData: FormFieldModel) => {
|
||||||
|
|
||||||
switch (fieldData.input.type) {
|
const parserCo = ParserFactory.getConstructor(fieldData.input.type as ParserType);
|
||||||
case 'date':
|
if (parserCo) {
|
||||||
fieldModel = (new DateFieldParser(fieldData, this.initFormValues, this.readOnly).parse());
|
fieldModel = new parserCo(fieldData, this.initFormValues, parserOptions).parse();
|
||||||
break;
|
} else {
|
||||||
|
throw new Error(`unknown form control model type defined with label "${fieldData.label}"`);
|
||||||
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}"`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fieldModel) {
|
if (fieldModel) {
|
||||||
|
@@ -2,12 +2,17 @@ import { FormFieldModel } from '../models/form-field.model';
|
|||||||
import { DynamicConcatModel } from '../ds-dynamic-form-ui/models/ds-dynamic-concat.model';
|
import { DynamicConcatModel } from '../ds-dynamic-form-ui/models/ds-dynamic-concat.model';
|
||||||
import { SeriesFieldParser } from './series-field-parser';
|
import { SeriesFieldParser } from './series-field-parser';
|
||||||
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
|
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
|
||||||
|
import { ParserOptions } from './parser-options';
|
||||||
|
|
||||||
describe('SeriesFieldParser test suite', () => {
|
describe('SeriesFieldParser test suite', () => {
|
||||||
let field: FormFieldModel;
|
let field: FormFieldModel;
|
||||||
let initFormValues: any = {};
|
let initFormValues: any = {};
|
||||||
|
|
||||||
const readOnly = false;
|
const parserOptions: ParserOptions = {
|
||||||
|
readOnly: false,
|
||||||
|
submissionScope: 'testScopeUUID',
|
||||||
|
authorityUuid: null
|
||||||
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
field = {
|
field = {
|
||||||
@@ -27,13 +32,13 @@ describe('SeriesFieldParser test suite', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should init parser properly', () => {
|
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);
|
expect(parser instanceof SeriesFieldParser).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return a DynamicConcatModel object when repeatable option is false', () => {
|
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();
|
const fieldModel = parser.parse();
|
||||||
|
|
||||||
@@ -41,7 +46,7 @@ describe('SeriesFieldParser test suite', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return a DynamicConcatModel object with the correct separator', () => {
|
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();
|
const fieldModel = parser.parse();
|
||||||
|
|
||||||
@@ -54,7 +59,7 @@ describe('SeriesFieldParser test suite', () => {
|
|||||||
};
|
};
|
||||||
const expectedValue = new FormFieldMetadataValueObject('test; series');
|
const expectedValue = new FormFieldMetadataValueObject('test; series');
|
||||||
|
|
||||||
const parser = new SeriesFieldParser(field, initFormValues, readOnly);
|
const parser = new SeriesFieldParser(field, initFormValues, parserOptions);
|
||||||
|
|
||||||
const fieldModel = parser.parse();
|
const fieldModel = parser.parse();
|
||||||
|
|
||||||
|
@@ -1,10 +1,10 @@
|
|||||||
import { FormFieldModel } from '../models/form-field.model';
|
import { FormFieldModel } from '../models/form-field.model';
|
||||||
|
|
||||||
import { ConcatFieldParser } from './concat-field-parser';
|
import { ConcatFieldParser } from './concat-field-parser';
|
||||||
|
import { ParserOptions } from './parser-options';
|
||||||
|
|
||||||
export class SeriesFieldParser extends ConcatFieldParser {
|
export class SeriesFieldParser extends ConcatFieldParser {
|
||||||
|
|
||||||
constructor(protected configData: FormFieldModel, protected initFormValues, protected readOnly: boolean) {
|
constructor(protected configData: FormFieldModel, protected initFormValues, protected parserOptions: ParserOptions) {
|
||||||
super(configData, initFormValues, readOnly, ';');
|
super(configData, initFormValues, parserOptions, ';');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2,13 +2,17 @@ import { FormFieldModel } from '../models/form-field.model';
|
|||||||
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
|
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
|
||||||
import { TagFieldParser } from './tag-field-parser';
|
import { TagFieldParser } from './tag-field-parser';
|
||||||
import { DynamicTagModel } from '../ds-dynamic-form-ui/models/tag/dynamic-tag.model';
|
import { DynamicTagModel } from '../ds-dynamic-form-ui/models/tag/dynamic-tag.model';
|
||||||
|
import { ParserOptions } from './parser-options';
|
||||||
|
|
||||||
describe('TagFieldParser test suite', () => {
|
describe('TagFieldParser test suite', () => {
|
||||||
let field: FormFieldModel;
|
let field: FormFieldModel;
|
||||||
let initFormValues: any = {};
|
let initFormValues: any = {};
|
||||||
|
|
||||||
const authorityUuid = 'testScopeUUID';
|
const parserOptions: ParserOptions = {
|
||||||
const readOnly = false;
|
readOnly: false,
|
||||||
|
submissionScope: 'testScopeUUID',
|
||||||
|
authorityUuid: null
|
||||||
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
field = {
|
field = {
|
||||||
@@ -32,13 +36,13 @@ describe('TagFieldParser test suite', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should init parser properly', () => {
|
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);
|
expect(parser instanceof TagFieldParser).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return a DynamicTagModel object when repeatable option is false', () => {
|
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();
|
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();
|
const fieldModel = parser.parse();
|
||||||
|
|
||||||
|
@@ -1,23 +1,14 @@
|
|||||||
import { FieldParser } from './field-parser';
|
import { FieldParser } from './field-parser';
|
||||||
import { FormFieldModel } from '../models/form-field.model';
|
|
||||||
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.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';
|
import { DynamicTagModel, DynamicTagModelConfig } from '../ds-dynamic-form-ui/models/tag/dynamic-tag.model';
|
||||||
|
|
||||||
export class TagFieldParser extends FieldParser {
|
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 {
|
public modelFactory(fieldValue: FormFieldMetadataValueObject): any {
|
||||||
const tagModelConfig: DynamicTagModelConfig = this.initModel();
|
const tagModelConfig: DynamicTagModelConfig = this.initModel();
|
||||||
if (this.configData.selectableMetadata[0].authority
|
if (this.configData.selectableMetadata[0].authority
|
||||||
&& this.configData.selectableMetadata[0].authority.length > 0) {
|
&& this.configData.selectableMetadata[0].authority.length > 0) {
|
||||||
this.setAuthorityOptions(tagModelConfig, this.authorityUuid);
|
this.setAuthorityOptions(tagModelConfig, this.parserOptions.authorityUuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setValues(tagModelConfig, fieldValue, null, true);
|
this.setValues(tagModelConfig, fieldValue, null, true);
|
||||||
|
@@ -2,13 +2,17 @@ import { FormFieldModel } from '../models/form-field.model';
|
|||||||
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
|
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
|
||||||
import { TextareaFieldParser } from './textarea-field-parser';
|
import { TextareaFieldParser } from './textarea-field-parser';
|
||||||
import { DsDynamicTextAreaModel } from '../ds-dynamic-form-ui/models/ds-dynamic-textarea.model';
|
import { DsDynamicTextAreaModel } from '../ds-dynamic-form-ui/models/ds-dynamic-textarea.model';
|
||||||
|
import { ParserOptions } from './parser-options';
|
||||||
|
|
||||||
describe('TextareaFieldParser test suite', () => {
|
describe('TextareaFieldParser test suite', () => {
|
||||||
let field: FormFieldModel;
|
let field: FormFieldModel;
|
||||||
let initFormValues: any = {};
|
let initFormValues: any = {};
|
||||||
|
|
||||||
const authorityUuid = 'testScopeUUID';
|
const parserOptions: ParserOptions = {
|
||||||
const readOnly = false;
|
readOnly: false,
|
||||||
|
submissionScope: null,
|
||||||
|
authorityUuid: null
|
||||||
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
field = {
|
field = {
|
||||||
@@ -30,13 +34,13 @@ describe('TextareaFieldParser test suite', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should init parser properly', () => {
|
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);
|
expect(parser instanceof TextareaFieldParser).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return a DsDynamicTextAreaModel object when repeatable option is false', () => {
|
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();
|
const fieldModel = parser.parse();
|
||||||
|
|
||||||
@@ -51,7 +55,7 @@ describe('TextareaFieldParser test suite', () => {
|
|||||||
};
|
};
|
||||||
const expectedValue ='test description';
|
const expectedValue ='test description';
|
||||||
|
|
||||||
const parser = new TextareaFieldParser(field, initFormValues, readOnly);
|
const parser = new TextareaFieldParser(field, initFormValues, parserOptions);
|
||||||
|
|
||||||
const fieldModel = parser.parse();
|
const fieldModel = parser.parse();
|
||||||
|
|
||||||
|
@@ -1,10 +1,6 @@
|
|||||||
import { FieldParser } from './field-parser';
|
import { FieldParser } from './field-parser';
|
||||||
import {
|
import { DynamicFormControlLayout } from '@ng-dynamic-forms/core';
|
||||||
DynamicFormControlLayout, DynamicTextAreaModel, DynamicTextAreaModelConfig
|
|
||||||
} from '@ng-dynamic-forms/core';
|
|
||||||
import { FormFieldModel } from '../models/form-field.model';
|
|
||||||
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
|
import { FormFieldMetadataValueObject } from '../models/form-field-metadata-value.model';
|
||||||
import { isNotEmpty } from '../../../empty.util';
|
|
||||||
import {
|
import {
|
||||||
DsDynamicTextAreaModel,
|
DsDynamicTextAreaModel,
|
||||||
DsDynamicTextAreaModelConfig
|
DsDynamicTextAreaModelConfig
|
||||||
|
Reference in New Issue
Block a user