How to use the xadmin.app.get function in xadmin

To help you get started, we’ve selected a few xadmin examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sshwsfc / xadmin / packages / xadmin-model / src / base.js View on Github external
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
  }
}
github sshwsfc / xadmin / packages / xadmin-form / src / schema.js View on Github external
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) : {})
}
github sshwsfc / xadmin / packages / xadmin-model / src / hooks.js View on Github external
'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 }
  }
github sshwsfc / xadmin / packages / xadmin-model / src / hooks.js View on Github external
'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 => {
github sshwsfc / xadmin / packages / xadmin-form / src / builder.js View on Github external
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)
}
github sshwsfc / xadmin / packages / xadmin-model / src / mappers.js View on Github external
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
    }
  },