Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const RelateAction = props => {
const { model, item } = use('model', props)
const actions = []
const models = app.get('models')
Object.keys(models).forEach(key => {
const m = models[key]
for(let pname of Object.keys(m.properties || {})) {
const prop = m.properties[pname]
if(prop.type == 'object' && (prop.relateTo == model.key || prop.relateTo == model.name)) {
actions.push(m)
continue
}
}
})
return actions.length ? : null
}
render() {
const { parent, model, refFilter, refData, refField, modelProps, children, header, ...props } = this.props
const { _t } = app.context
const cmodel = _.isString(model) ? app.get('models')[model] : model
const schema = {
...cmodel,
parent,
item_actions: [
...(cmodel.item_actions || []),
item => {_t('Edit')}
],
permission: {
...cmodel.permission,
edit: false,
childEdit: cmodel.permission && cmodel.permission.edit
},
...modelProps
}
const initialValues = {
wheres: { filters: refFilter || { [refField]: parent.id } }
(f, schema, options) => {
if(schema.type == 'object' && schema.relateTo) {
const models = app.get('models')
const relateName = schema.relateTo
if(models[relateName]) {
const model = models[relateName]
f.type = 'filter_relate'
f.schema = model
f.displayField = model.displayField || 'name'
}
}
return f
}
]
return ({ value, wrap }) => {
if(value && value.id !== undefined && schema.showDetail === true && Object.keys(app.get('models')).indexOf(schema.relateTo) >= 0) {
const newWrap = ({ children }) => (
{children}
)
return
} else {
return
}
}
}
export default ({ input, label, field, option }) => {
let renderItems = field.itemsRender || defaultItemsRender
if(typeof renderItems === 'string') {
renderItems = app.get('array_render')[renderItems]
}
const { items } = field
const fieldsBuilder = (name, index, removeBtn, itemLable) => {
const itemLabel = itemLable || (<div>{removeBtn ? removeBtn : ''}</div>)
const itemFields = items.fields ?
(items.fields.map(f => prefixFieldKey(f, name + '.'))) :
[ { ...items, key: name, name: name, label: itemLabel } ]
return objectBuilder(itemFields, items.render, option)
}
return (
)
}
'model.batchActions': props => {
const { model } = use('model', props)
const modelActions = app.get('modelBatchActions')
const actions = model.batchActions === undefined ?
Object.keys(modelActions).filter(k => modelActions[k].default) : model.batchActions
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 }
},
'actons.batch_delete': props => {
const C = args => {
if(typeof args == 'string') {
return app.get('components')[args]
} else {
const { is, ...props } = args
const Component = C(is)
if(Component)
return
else
return <div>Component {is} not found.</div>
}
}
const ChildrenModel = props => {
const [ show, setShow ] = React.useState(false)
const { parent, model, refFilter, refData, refField, modelProps, children, header, value, onClose, refreshTimeout, ...extProps } = props
const handleCancel = () => {
setShow(false)
onClose && onClose()
}
const cmodel = _.isString(model) ? app.get('models')[model] : model
const schema = {
...cmodel,
parent,
itemActions: [
...(cmodel.itemActions || []),
item => {_t('Edit')}
],
permission: {
...cmodel.permission,
edit: false,
childEdit: cmodel.permission && cmodel.permission.edit
},
...modelProps
}
const initialValues = {
wheres: { filters: refFilter || { [refField]: parent.id } }
export default ({ error, children, invalid, handleSubmit, submitting }) => {
const { auth } = app.get('config')
return (
<form>
<h4>{_t('Please Login')}</h4>
{children}
{error && <strong>{error}</strong>}
<button disabled="{invalid" type="submit">
{_t('Login')}</button>
{ auth.can_signup && (<div>{_t('Not registed')}? <a href="#">app.go('/signup')}>{_t('please signup')}</a></div>) }
{ auth.can_reset_password && (<div>{_t('Forgot password')}? <a href="#">app.go('/forget_password')}>{_t('reset password')}</a></div>) }
</form>