How to use the xadmin.api 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-auth / src / effects.js View on Github external
function *handle_verify_email({ payload }) {
  const { _t } = app.context
  try {
    yield api({ name: 'auth/registration/verify-email' }).save({
      language: 'zh_CN',
      ...payload
    })
    yield put({ type: '@@xadmin/ADD_NOTICE', payload: {
      type: 'success', headline: 'Success', message: _t('Send verify code to your email, please check')
    } })
  } catch(err) {
    app.error(err)
  }
}
github sshwsfc / xadmin / packages / xadmin-bootstrap / src / auth / components / CaptchaCodeInput.js View on Github external
getCodeUrl() {
    const { field } = this.props
    return api({}).host + (field.captcha_url || '/get_captcha_code') + '?random=' + Math.random().toString()
  }
github sshwsfc / xadmin / packages / xadmin-antd / src / auth / components / CaptchaCodeInput.js View on Github external
getCodeUrl() {
    const { field } = this.props
    return api({}).host + (field.captcha_url || '/get_captcha_code') + '?random=' + Math.random().toString()
  }
github sshwsfc / xadmin / packages / xadmin-model / src / effects.js View on Github external
function *handle_get_list({ model, filter, wheres }) {
  yield put({ type: 'START_LOADING', model, key: `${model.key}.items` })
  const { store } = app.context
  const modelState = store.getState().model[model.key]

  try {
    const { items, total } = yield api(model).query(filter || modelState.filter, wheres || modelState.wheres)
    yield put({ type: 'GET_ITEMS', model: model, items: items || [], filter, wheres, count: total })
  } catch(err) {
    app.error(err)
    yield put({ type: 'GET_ITEMS', model: model, items: [], filter, wheres, count: 0 })
  }

  yield put({ type: 'END_LOADING', model, key: `${model.key}.items` })
}
github sshwsfc / xadmin / packages / xadmin-model / src / effects.js View on Github external
function *handle_get_item({ model, id }) {
  yield put({ type: 'START_LOADING', model, key: `${model.key}.get` })
  const { _t } = app.context

  try {
    const item = yield api(model).get(id)
    if(item) {
      yield put({ type: 'GET_ITEM', model, item, success: true })
    }
  } catch(err) {
    app.error(err)
  }

  yield put({ type: 'END_LOADING', model, key: `${model.key}.get` })
}
github sshwsfc / xadmin / packages / xadmin-model / src / relate.js View on Github external
const loadOptions = React.useCallback(inputValue => {
        const displayField = field.displayField || 'name'
        setLoadig(true)
        return api(field.schema)
          .query({ limit: 1000, fields: [ 'id', displayField ] }, 
            inputValue ? { search: { [displayField]: { like: inputValue } } } : {})
          .then(({ items }) => {
            setLoadig(false)
            setOptions(items.map(item => 
              ({ value: item.id, label: item[displayField], item })
            ))
          }
          )
      }, [ model, field ])