Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const getModel = (name, key, props) => {
const model = app.get('models')[name]
if(!model) {
throw Error(`Model '${name}' not found!`)
}
model.name = model.name || name
return {
...model,
key: key || model.name,
...props
}
}
const convert = (schema, options) => {
const opts = options || {}
if(opts.path === undefined) {
opts.path = []
}
if(opts.lookup === undefined) {
opts.lookup = {}
}
return app.get('schema_converter').reduce((prve, converter) => {
return converter(prve, schema, opts)
}, opts.global && opts.global.formDefaults ? _.cloneDeep(opts.global.formDefaults) : {})
}
'model.list.item': props => {
const { model, schema, field, item, nest } = use('model', props)
const property = schema || getFieldProp(model, field)
const data = schema ? {} : { schema: property }
const key = schema ? `${schema.name}.${field}` : field
if(model.fieldRender == undefined) {
model.fieldRender = {}
}
if(model.fieldRender[key] == undefined) {
model.fieldRender[key] = property != undefined ?
app.get('fieldRenders').reduce((prev, render) => {
return render(prev, property, field)
}, null) : null
}
if(model.fieldRender[key]) {
data['componentClass'] = model.fieldRender[key]
}
data['value'] = _.get(item, field)
data['editable'] = nest == true || model.editableFields == undefined || model.editableFields.indexOf(field) < 0
return { ...props, ...data, model }
}
'model.actions': props => {
const { model } = use('model', props)
const modelActions = app.get('modelActions')
const actions = model.itemActions === undefined ?
Object.keys(modelActions).filter(k => modelActions[k].default) : model.itemActions
const renderActions = React.useCallback(actProps => {
return actions ? actions.map((action, i) => {
const Action = _.isString(action) && modelActions[action] ? modelActions[action].component : action
if(Action) {
return
}
return null
}).filter(Boolean) : null
}, [ actions ])
return { ...props, actions, renderActions }
},
'model.select': props => {
const objectBuilder = (fields, render, option) => {
const fields_defined = app.get('form_fields')
const fields_wraped = fields
.filter(field => field.type === undefined || fields_defined[field.type] !== undefined)
.map(field => { return { ...fields_defined[field.type || 'text'], ...field, option } })
return (render || defaultUIRender)(fields_wraped, option)
}
compute: ({ model }, { items, field, schema }) => {
const property = schema || getFieldProp(model, field)
const data = schema ? {} : { schema: property }
const key = schema ? `${schema.name}.${field}` : field
if(model.fieldRender == undefined) {
model.fieldRender = {}
}
if(model.fieldRender[key] == undefined) {
model.fieldRender[key] = property != undefined ?
app.get('fieldRenders').reduce((prev, render) => {
return render(prev, property, field)
}, null) : null
}
if(model.fieldRender[key]) {
data['componentClass'] = model.fieldRender[key]
}
return data
}
},