|
@@ -26,7 +26,6 @@
|
|
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';
|
|
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
@@ -77,25 +76,25 @@ const combineExtraMeta = (metaG, extraMeta, createFromExtra = false, containerSe
|
|
const metaFoG = metaG[key] || {};
|
|
const metaFoG = metaG[key] || {};
|
|
const seed = isCon ? {} : containerSeed; // Container's don't seed themselves, only their children
|
|
const seed = isCon ? {} : containerSeed; // Container's don't seed themselves, only their children
|
|
|
|
|
|
- /*
|
|
|
|
- console.log('******************* BEFORE MODELLING *******************');
|
|
|
|
- console.log(val);
|
|
|
|
- console.log('IS REPEATING', isRepeating(val));
|
|
|
|
- console.log('HAS META', hasMeta(val));
|
|
|
|
- console.log('IS ARRAY', Array.isArray(val.meta));
|
|
|
|
- console.log('MEMBER 1 DEFINED', !!val.meta[0]);
|
|
|
|
- console.log('OBJECT VALUES .........', Object.values(val.meta[0]));
|
|
|
|
- console.log('MEMBER 1 1st entry .........', Object.values(val.meta[0])[0]);
|
|
|
|
- console.log('MEMBER 1 1st entry is SCALAR', isScalar(Object.values(val.meta[0])));
|
|
|
|
- */
|
|
|
|
- /*
|
|
|
|
- console.log('IS REP Field', isRepeatingField(val));
|
|
|
|
- console.log('IS REP Container', isRepeatingContainer(val));
|
|
|
|
- console.log('IS ORD Container', isContainer(val));
|
|
|
|
- */
|
|
|
|
|
|
+ // console.log('******************* BEFORE MODELLING *******************');
|
|
|
|
+ // console.log(key);
|
|
|
|
+ // console.log(val);
|
|
|
|
+ // console.log('IS REPEATING', isRepeating(val));
|
|
|
|
+ // console.log('HAS META', hasMeta(val));
|
|
|
|
+ // console.log('IS ARRAY', Array.isArray(val.meta));
|
|
|
|
+ // console.log('MEMBER 1 DEFINED', !!val.meta[0]);
|
|
|
|
+ // console.log('OBJECT VALUES .........', Object.values(val.meta[0] || null));
|
|
|
|
+ // console.log('MEMBER 1 1st entry .........', Object.values(val.meta[0])[0]);
|
|
|
|
+ // console.log('MEMBER 1 1st entry is SCALAR', isScalar(Object.values(val.meta[0])));
|
|
|
|
+ // console.log('IS REP Field', isRepeatingField(val));
|
|
|
|
+ // console.log('IS REP Container', isRepeatingContainer(val));
|
|
|
|
+ // console.log('IS ORD Container', isContainer(val));
|
|
|
|
+
|
|
if (isRepeatingContainer(val))
|
|
if (isRepeatingContainer(val))
|
|
{
|
|
{
|
|
// We've got a Repeating Container
|
|
// We've got a Repeating Container
|
|
|
|
+ metaFoG.type = 'RepeatingContainer';
|
|
|
|
+ const extraMetaTemplate = Array.isArray(val.meta) ? val.meta[0] || {} : val.meta;
|
|
const baseObjWithAllKeys = getRCBaseObjectWithAllKeys(metaFoG, val, createFromExtra);
|
|
const baseObjWithAllKeys = getRCBaseObjectWithAllKeys(metaFoG, val, createFromExtra);
|
|
metaFoG.meta = generateRepeatedGroup(metaFoG, val, baseObjWithAllKeys);
|
|
metaFoG.meta = generateRepeatedGroup(metaFoG, val, baseObjWithAllKeys);
|
|
const extra = {
|
|
const extra = {
|
|
@@ -103,7 +102,7 @@ const combineExtraMeta = (metaG, extraMeta, createFromExtra = false, containerSe
|
|
meta: metaFoG.meta.map(
|
|
meta: metaFoG.meta.map(
|
|
rgMem => combineExtraMeta(
|
|
rgMem => combineExtraMeta(
|
|
rgMem.meta,
|
|
rgMem.meta,
|
|
- val['meta'][0],
|
|
|
|
|
|
+ extraMetaTemplate,
|
|
createFromExtra,
|
|
createFromExtra,
|
|
val['seed'] || containerSeed
|
|
val['seed'] || containerSeed
|
|
)
|
|
)
|
|
@@ -111,11 +110,11 @@ const combineExtraMeta = (metaG, extraMeta, createFromExtra = false, containerSe
|
|
};
|
|
};
|
|
combinedMeta[key] = combineMetaForField(metaFoG, {}, extra);
|
|
combinedMeta[key] = combineMetaForField(metaFoG, {}, extra);
|
|
|
|
|
|
- // Stash a 'conbtainer template' for adding extra containers to the repeating container
|
|
|
|
- combinedMeta[key].__containerTemplate = combineExtraMeta(
|
|
|
|
|
|
+ // Stash a 'container template' for adding extra containers to the repeating container
|
|
|
|
+ combinedMeta[key].__template = combineExtraMeta(
|
|
cloneDeep(baseObjWithAllKeys),
|
|
cloneDeep(baseObjWithAllKeys),
|
|
- val['meta'][0],
|
|
|
|
- false,
|
|
|
|
|
|
+ extraMetaTemplate,
|
|
|
|
+ createFromExtra,
|
|
val['seed'] || containerSeed
|
|
val['seed'] || containerSeed
|
|
);
|
|
);
|
|
}
|
|
}
|
|
@@ -124,11 +123,12 @@ const combineExtraMeta = (metaG, extraMeta, createFromExtra = false, containerSe
|
|
let extra: StringMap<any>;
|
|
let extra: StringMap<any>;
|
|
if (isCon) {
|
|
if (isCon) {
|
|
// We've got a container
|
|
// We've got a container
|
|
|
|
+ metaFoG.type = 'Container';
|
|
extra = {
|
|
extra = {
|
|
...val,
|
|
...val,
|
|
meta: combineExtraMeta( // RECURSION
|
|
meta: combineExtraMeta( // RECURSION
|
|
metaFoG.meta || {},
|
|
metaFoG.meta || {},
|
|
- val['meta'],
|
|
|
|
|
|
+ val.meta,
|
|
createFromExtra,
|
|
createFromExtra,
|
|
val['seed'] || containerSeed // Inherit seeded data if this group's seed isn't set
|
|
val['seed'] || containerSeed // Inherit seeded data if this group's seed isn't set
|
|
)
|
|
)
|
|
@@ -138,6 +138,7 @@ const combineExtraMeta = (metaG, extraMeta, createFromExtra = false, containerSe
|
|
{
|
|
{
|
|
if (isRepeating(val)) {
|
|
if (isRepeating(val)) {
|
|
// We've got a repeating field
|
|
// We've got a repeating field
|
|
|
|
+ metaFoG.type = 'RepeatingField';
|
|
const metaForFieldToRepeat = {
|
|
const metaForFieldToRepeat = {
|
|
...containerSeed,
|
|
...containerSeed,
|
|
...omit(['seed', 'minRepeat', 'maxRepeat', 'initialRepeat', 'showAddControl', 'showDeleteControl'], val as StringMap<any>),
|
|
...omit(['seed', 'minRepeat', 'maxRepeat', 'initialRepeat', 'showAddControl', 'showDeleteControl'], val as StringMap<any>),
|
|
@@ -147,7 +148,7 @@ const combineExtraMeta = (metaG, extraMeta, createFromExtra = false, containerSe
|
|
extra = {
|
|
extra = {
|
|
...val,
|
|
...val,
|
|
meta: Array.from(Array(val.initialRepeat || 1).keys()).map((f, i) => metaForFieldToRepeat),
|
|
meta: Array.from(Array(val.initialRepeat || 1).keys()).map((f, i) => metaForFieldToRepeat),
|
|
- __fieldTemplate: metaForFieldToRepeat
|
|
|
|
|
|
+ __template: metaForFieldToRepeat
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
// We've got a standard field
|
|
// We've got a standard field
|
|
@@ -171,14 +172,15 @@ const generateRepeatedGroup = (metaFoG, extraMeta, baseObjWithAllKeys): StringMa
|
|
const repeatInAutoMeta = Array.isArray(metaFoG.meta) ? metaFoG.meta.length : 0;
|
|
const repeatInAutoMeta = Array.isArray(metaFoG.meta) ? metaFoG.meta.length : 0;
|
|
const repeatInExtraMeta = extraMeta['initialRepeat'] || extraMeta['minRepeat'];
|
|
const repeatInExtraMeta = extraMeta['initialRepeat'] || extraMeta['minRepeat'];
|
|
const repeat = Math.max(repeatInAutoMeta, repeatInExtraMeta);
|
|
const repeat = Math.max(repeatInAutoMeta, repeatInExtraMeta);
|
|
-
|
|
|
|
- metaFoG.meta = metaFoG.meta.map( rcMem => ({ ...rcMem, meta: { ...baseObjWithAllKeys, ...rcMem.meta } }) ); // Add extra keys to model meta
|
|
|
|
|
|
+ // console.log('generateRepeatedGroup');
|
|
|
|
+ // console.log(metaFoG, extraMeta, baseObjWithAllKeys);
|
|
|
|
+ metaFoG.meta = (metaFoG.meta || []).map( rcMem => ({ ...rcMem, meta: { ...baseObjWithAllKeys, ...rcMem.meta } }) ); // Add extra keys to model meta
|
|
|
|
|
|
// Extend repeated group from model (if any) to correct length, and add any missing names
|
|
// Extend repeated group from model (if any) to correct length, and add any missing names
|
|
const repeatedGroup = repeatInAutoMeta ?
|
|
const repeatedGroup = repeatInAutoMeta ?
|
|
[ ...metaFoG.meta, ...Array(repeat - repeatInAutoMeta).fill({ meta: baseObjWithAllKeys }) ] :
|
|
[ ...metaFoG.meta, ...Array(repeat - repeatInAutoMeta).fill({ meta: baseObjWithAllKeys }) ] :
|
|
Array(repeat).fill({ meta: baseObjWithAllKeys });
|
|
Array(repeat).fill({ meta: baseObjWithAllKeys });
|
|
- const fullyNamedRepeatedGroup = repeatedGroup.map((rgMem, i) => rgMem.name ? rgMem : { name: `group${i + 1}`, ...rgMem });
|
|
|
|
|
|
+ const fullyNamedRepeatedGroup = repeatedGroup.map((rgMem, i) => rgMem.name ? { ...rgMem } : { name: `group${i + 1}`, ...rgMem });
|
|
return fullyNamedRepeatedGroup;
|
|
return fullyNamedRepeatedGroup;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -192,7 +194,6 @@ const getRCBaseObjectWithAllKeys = (metaFoG, extraMeta, createFromExtra = false)
|
|
return baseObjWithAllKeys;
|
|
return baseObjWithAllKeys;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
// Build Form-Field-Type-Specific Metadata (using the field models in dynaform/models)
|
|
// Build Form-Field-Type-Specific Metadata (using the field models in dynaform/models)
|
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
@@ -249,16 +250,15 @@ const buildFieldSpecificMetaInClosure = (metaG, context) => {
|
|
*/
|
|
*/
|
|
if (isRepeatingField(modeledGroupMember)) {
|
|
if (isRepeatingField(modeledGroupMember)) {
|
|
modeledGroupMember.meta = modeledGroupMember.meta.map(metaF => buildModeledField(metaF));
|
|
modeledGroupMember.meta = modeledGroupMember.meta.map(metaF => buildModeledField(metaF));
|
|
- modeledGroupMember.__fieldTemplate = buildModeledField(modeledGroupMember.__fieldTemplate);
|
|
|
|
|
|
+ modeledGroupMember.__template = buildModeledField(modeledGroupMember.__template);
|
|
} else if (isContainer(modeledGroupMember)) {
|
|
} else if (isContainer(modeledGroupMember)) {
|
|
modeledGroupMember.meta = _buildFieldSpecificMeta(modeledGroupMember.meta);
|
|
modeledGroupMember.meta = _buildFieldSpecificMeta(modeledGroupMember.meta);
|
|
} else if (isRepeatingContainer(modeledGroupMember)) {
|
|
} else if (isRepeatingContainer(modeledGroupMember)) {
|
|
modeledGroupMember.meta = modeledGroupMember.meta.map(rcMem => ({ ...rcMem, meta: _buildFieldSpecificMeta(rcMem.meta) }));
|
|
modeledGroupMember.meta = modeledGroupMember.meta.map(rcMem => ({ ...rcMem, meta: _buildFieldSpecificMeta(rcMem.meta) }));
|
|
- modeledGroupMember.__containerTemplate = {
|
|
|
|
- ...modeledGroupMember.meta[0],
|
|
|
|
- meta: _buildFieldSpecificMeta(modeledGroupMember.__containerTemplate),
|
|
|
|
- name: '__containerTemplate',
|
|
|
|
- button: ''
|
|
|
|
|
|
+ modeledGroupMember.__template = {
|
|
|
|
+ ...modeledGroupMember.meta[0] || {},
|
|
|
|
+ meta: _buildFieldSpecificMeta(modeledGroupMember.__template),
|
|
|
|
+ name: '__template'
|
|
};
|
|
};
|
|
}
|
|
}
|
|
return modeledGroupMember;
|
|
return modeledGroupMember;
|
|
@@ -317,7 +317,7 @@ const prependParentPathRecursive = (parentPath: string, obj: StringMap<any>) =>
|
|
|
|
|
|
const _extractFieldMapping = ( [key, metaFoG] ) => {
|
|
const _extractFieldMapping = ( [key, metaFoG] ) => {
|
|
let source;
|
|
let source;
|
|
- if (hasMeta(metaFoG)) {
|
|
|
|
|
|
+ if (hasMeta(metaFoG) && !Array.isArray(metaFoG.meta)) { // If it has non-array meta (note, we patch entire arrays for array meta)
|
|
if (Array.isArray(metaFoG.source)) {
|
|
if (Array.isArray(metaFoG.source)) {
|
|
source = extractFieldMappings(metaFoG.meta);
|
|
source = extractFieldMappings(metaFoG.meta);
|
|
source.__ = metaFoG.source; // Store the functional mapping (including function executed later to provide container's data)
|
|
source.__ = metaFoG.source; // Store the functional mapping (including function executed later to provide container's data)
|
|
@@ -763,7 +763,7 @@ const addNameToSelfAndChildren = ( [key, metaFoG] ) => {
|
|
metaFoG = addNameIfMissing(metaFoG, key);
|
|
metaFoG = addNameIfMissing(metaFoG, key);
|
|
if (hasMeta(metaFoG) && !isRepeatingContainer(metaFoG)) {
|
|
if (hasMeta(metaFoG) && !isRepeatingContainer(metaFoG)) {
|
|
if (metaFoG.meta.length && metaFoG.meta.every(isScalar)) {
|
|
if (metaFoG.meta.length && metaFoG.meta.every(isScalar)) {
|
|
- metaFoG.meta = metaFoG.meta.map(val => ({ name: val, value: val }));
|
|
|
|
|
|
+ metaFoG.meta = metaFoG.meta.map(val => ({ name: val, value: val, label: val.replace(/_/g, ' ') }));
|
|
} else {
|
|
} else {
|
|
metaFoG.meta = isArray(metaFoG.meta) ? Object.values(addMissingNames(metaFoG.meta)) : addMissingNames(metaFoG.meta); // Recursion
|
|
metaFoG.meta = isArray(metaFoG.meta) ? Object.values(addMissingNames(metaFoG.meta)) : addMissingNames(metaFoG.meta); // Recursion
|
|
}
|
|
}
|