2018-04-26 10:20:46 +00:00
|
|
|
const deepmerge = require('deepmerge');
|
|
|
|
|
2018-01-12 12:25:07 +00:00
|
|
|
module.exports = {
|
2018-04-26 10:20:46 +00:00
|
|
|
extend: (base, target, options = {}) => {
|
|
|
|
const fieldsToMerge = (target.fields || []).map(df => df.fieldname);
|
|
|
|
const fieldsToRemove = options.skipFields || [];
|
|
|
|
|
|
|
|
base.fields = base.fields
|
|
|
|
.filter(df => !fieldsToRemove.includes(df.fieldname))
|
|
|
|
.map(df => {
|
|
|
|
if (fieldsToMerge.includes(df.fieldname)) {
|
|
|
|
return deepmerge(df, target.fields.find(tdf => tdf.fieldname === df.fieldname));
|
|
|
|
}
|
|
|
|
return df;
|
|
|
|
});
|
|
|
|
|
|
|
|
const overrideProps = options.overrideProps || [];
|
|
|
|
for (let prop of overrideProps) {
|
|
|
|
if (base.hasOwnProperty(prop)) {
|
|
|
|
delete base[prop];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return deepmerge(base, target);
|
|
|
|
},
|
2018-02-27 16:29:14 +00:00
|
|
|
commonFields: [
|
2018-01-12 12:25:07 +00:00
|
|
|
{
|
2018-02-09 12:55:55 +00:00
|
|
|
fieldname: 'name', fieldtype: 'Data', required: 1
|
2018-01-31 12:56:21 +00:00
|
|
|
}
|
2018-01-31 13:04:46 +00:00
|
|
|
],
|
2018-02-27 16:29:14 +00:00
|
|
|
parentFields: [
|
2018-01-12 12:25:07 +00:00
|
|
|
{
|
2018-02-20 14:11:44 +00:00
|
|
|
fieldname: 'owner', fieldtype: 'Data', required: 1
|
2018-01-12 12:25:07 +00:00
|
|
|
},
|
|
|
|
{
|
2018-03-29 14:28:56 +00:00
|
|
|
fieldname: 'modifiedBy', fieldtype: 'Data', required: 1
|
2018-01-12 12:25:07 +00:00
|
|
|
},
|
|
|
|
{
|
2018-02-09 12:55:55 +00:00
|
|
|
fieldname: 'creation', fieldtype: 'Datetime', required: 1
|
2018-01-12 12:25:07 +00:00
|
|
|
},
|
|
|
|
{
|
2018-02-09 12:55:55 +00:00
|
|
|
fieldname: 'modified', fieldtype: 'Datetime', required: 1
|
2018-01-12 12:25:07 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
fieldname: 'keywords', fieldtype: 'Text'
|
|
|
|
}
|
|
|
|
],
|
2018-02-27 16:29:14 +00:00
|
|
|
childFields: [
|
2018-01-12 12:25:07 +00:00
|
|
|
{
|
2018-02-09 12:55:55 +00:00
|
|
|
fieldname: 'idx', fieldtype: 'Int', required: 1
|
2018-01-12 12:25:07 +00:00
|
|
|
},
|
|
|
|
{
|
2018-02-09 12:55:55 +00:00
|
|
|
fieldname: 'parent', fieldtype: 'Data', required: 1
|
2018-01-12 12:25:07 +00:00
|
|
|
},
|
|
|
|
{
|
2018-02-20 14:11:44 +00:00
|
|
|
fieldname: 'parenttype', fieldtype: 'Data', required: 1
|
2018-01-12 12:25:07 +00:00
|
|
|
},
|
|
|
|
{
|
2018-02-09 12:55:55 +00:00
|
|
|
fieldname: 'parentfield', fieldtype: 'Data', required: 1
|
2018-01-12 12:25:07 +00:00
|
|
|
}
|
2018-04-18 06:48:24 +00:00
|
|
|
],
|
|
|
|
treeFields: [
|
|
|
|
{
|
|
|
|
fieldname: 'lft', fieldtype: 'Int', required: 1
|
|
|
|
},
|
|
|
|
{
|
|
|
|
fieldname: 'rgt', fieldtype: 'Int', required: 1
|
|
|
|
}
|
2018-01-12 12:25:07 +00:00
|
|
|
]
|
2018-04-18 06:48:24 +00:00
|
|
|
};
|