-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapObjects.js
102 lines (98 loc) · 2.97 KB
/
mapObjects.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
const merge = require('ut-function.merge');
const get = require('lodash.get');
const set = require('lodash.set');
const {capital} = require('./lib');
const defaults = ({joi}, {
subject,
object,
subjectObject = `${subject}${capital(object)}`,
objectTitle = capital(object),
keyField = `${object}Id`,
nameField = `${object}.${object}Name`,
descriptionField = `${object}Description`,
tenantField = `${object}.businessUnitId`,
...rest
}) => merge({
cards: {
edit: {title: object, widgets: [nameField, descriptionField]},
history: {
className: 'col-12',
widgets: [{
name: '',
type: 'page',
page: 'history.history.browse',
params: {object, id: `\${${object}.${keyField}}`}
}]
},
hidden: {
hidden: true,
label: 'Hidden fields',
widgets: [`${object}.${keyField}`]
}
},
schema: {
properties: {
[object]: {
properties: {
[keyField]: {validation: joi && joi.any()},
[tenantField]: {title: 'Tenant', validation: joi && joi.any()},
[nameField.split('.').pop()]: {title: `${capital(object)} Name`, filter: true, sort: true},
[descriptionField]: {title: `${capital(object)} Description`, filter: true, editor: {type: 'text'}}
}
}
}
},
methods: {
fetch: `${subject}.${object}.fetch`,
add: `${subject}.${object}.add`,
delete: `${subject}.${object}.delete`,
get: `${subject}.${object}.get`,
edit: `${subject}.${object}.edit`,
report: `${subject}.${object}.report`,
import: `${subject}.${object}.import`,
start: `${subject}.${object}.start`
},
report: {
title: `${objectTitle} Report`
},
browser: {
title: rest.cards?.browse?.title || `${objectTitle} list`,
resultSet: object,
create: [{
title: 'Create'
}],
toolbar: [],
permission: {
browse: `${subject}.${object}.browse`,
add: `${subject}.${object}.add`,
delete: `${subject}.${object}.delete`,
edit: `${subject}.${object}.edit`
}
},
layouts: {
edit: ['hidden', 'edit']
},
browsers: {},
reports: {},
editor: {
resultSet: object
}
}, {
subject,
object,
subjectObject,
objectTitle,
keyField,
nameField,
descriptionField,
tenantField,
...rest
});
const override = (ut, model, models) => {
const path = [model.subject, model.object];
const prev = get(models, path);
const result = merge({}, prev || defaults(ut, model), model, get(ut.config, path));
set(models, path, result);
return result;
};
module.exports = (ut, objects, mapper, models) => [].concat(objects).map(item => override(ut, item(ut), models)).map(mapper);