|
@@ -26,6 +26,7 @@
|
|
import { FormBuilder, FormGroup, FormArray, FormControl, AbstractControl, AbstractControlOptions } from '@angular/forms';
|
|
import { FormBuilder, FormGroup, FormArray, FormControl, AbstractControl, AbstractControlOptions } from '@angular/forms';
|
|
import { cloneDeep, omit, reduce } from 'lodash/fp';
|
|
import { cloneDeep, omit, reduce } from 'lodash/fp';
|
|
import * as fmdModels from '../models/field.model';
|
|
import * as fmdModels from '../models/field.model';
|
|
|
|
+import { meta } from '@mock/testfields.v1';
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
@@ -47,7 +48,7 @@ const keyValPairToMetaRecursive = ( [key, val] ) => {
|
|
|
|
|
|
const arrayToMeta = array => array.map((val, i) => {
|
|
const arrayToMeta = array => array.map((val, i) => {
|
|
if (isScalar(val)) {
|
|
if (isScalar(val)) {
|
|
- return { name: `item${i + 1}`, 'value' : val };
|
|
|
|
|
|
+ return { name: `item${i + 1}`, value : val, label: val };
|
|
} else {
|
|
} else {
|
|
return { name: `group${i + 1}`, meta: autoMeta(val) };
|
|
return { name: `group${i + 1}`, meta: autoMeta(val) };
|
|
}
|
|
}
|
|
@@ -721,7 +722,7 @@ const isRepeating = (metaFoG): boolean => !!(metaFoG.minRepeat || metaFoG.maxRep
|
|
|
|
|
|
// Is Repeating Field
|
|
// Is Repeating Field
|
|
// Helper function to distinguish a repeating field (a field that can be repeated 1...N times)
|
|
// Helper function to distinguish a repeating field (a field that can be repeated 1...N times)
|
|
-const isRepeatingField = (metaRF): boolean => metaRF.type && metaRF.type.toLowerCase() === 'repeatingfield'
|
|
|
|
|
|
+const isRepeatingField = (metaRF): boolean => typeof metaRF.type === 'string' && metaRF.type.toLowerCase() === 'repeatingfield'
|
|
|| (
|
|
|| (
|
|
!metaRF.type
|
|
!metaRF.type
|
|
&& isRepeating(metaRF)
|
|
&& isRepeating(metaRF)
|
|
@@ -735,7 +736,7 @@ const isRepeatingField = (metaRF): boolean => metaRF.type && metaRF.type.toLower
|
|
|
|
|
|
// Is Container
|
|
// Is Container
|
|
// Helper function to distinguish container group (a group of child fields)
|
|
// Helper function to distinguish container group (a group of child fields)
|
|
-const isContainer = (metaFoG): boolean => metaFoG.type && metaFoG.type.toLowerCase() === 'container'
|
|
|
|
|
|
+const isContainer = (metaFoG): boolean => typeof metaFoG.type === 'string' && metaFoG.type.toLowerCase() === 'container'
|
|
|| (
|
|
|| (
|
|
!metaFoG.type
|
|
!metaFoG.type
|
|
&& hasMeta(metaFoG)
|
|
&& hasMeta(metaFoG)
|
|
@@ -744,7 +745,7 @@ const isContainer = (metaFoG): boolean => metaFoG.type && metaFoG.type.toLowerCa
|
|
|
|
|
|
// Is Repeating Container
|
|
// Is Repeating Container
|
|
// Helper function to distinguish a repeating container group (a group of child fields that can be repeated 1...N times)
|
|
// Helper function to distinguish a repeating container group (a group of child fields that can be repeated 1...N times)
|
|
-const isRepeatingContainer = (metaFoG): boolean => metaFoG.type && metaFoG.type.toLowerCase() === 'repeatingcontainer'
|
|
|
|
|
|
+const isRepeatingContainer = (metaFoG): boolean => typeof metaFoG.type === 'string' && metaFoG.type.toLowerCase() === 'repeatingcontainer'
|
|
|| (
|
|
|| (
|
|
!metaFoG.type
|
|
!metaFoG.type
|
|
&& isRepeating(metaFoG)
|
|
&& isRepeating(metaFoG)
|
|
@@ -761,7 +762,11 @@ const addNameIfMissing = (metaFoG, key) => metaFoG.name ? metaFoG : addProp(meta
|
|
const addNameToSelfAndChildren = ( [key, metaFoG] ) => {
|
|
const addNameToSelfAndChildren = ( [key, metaFoG] ) => {
|
|
metaFoG = addNameIfMissing(metaFoG, key);
|
|
metaFoG = addNameIfMissing(metaFoG, key);
|
|
if (hasMeta(metaFoG) && !isRepeatingContainer(metaFoG)) {
|
|
if (hasMeta(metaFoG) && !isRepeatingContainer(metaFoG)) {
|
|
- metaFoG.meta = isArray(metaFoG.meta) ? Object.values(addMissingNames(metaFoG.meta)) : addMissingNames(metaFoG.meta); // Recursion
|
|
|
|
|
|
+ if (metaFoG.meta.length && metaFoG.meta.every(isScalar)) {
|
|
|
|
+ metaFoG.meta = metaFoG.meta.map(val => ({ name: val, value: val }));
|
|
|
|
+ } else {
|
|
|
|
+ metaFoG.meta = isArray(metaFoG.meta) ? Object.values(addMissingNames(metaFoG.meta)) : addMissingNames(metaFoG.meta); // Recursion
|
|
|
|
+ }
|
|
}
|
|
}
|
|
return [key, metaFoG];
|
|
return [key, metaFoG];
|
|
};
|
|
};
|