How to use the xadmin.error 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 / 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
const data = yield api(model).save(item, partial)
    yield put({ type: 'SAVE_ITEM', model, item: data || item, partial, success: true })
    if(promise) {
      promise.resolve(data)
    }
    if( message !== false) {
      const object = model.title || model.name
      const noticeMessage = message || (item.id == undefined ? 
        _t('Create {{object}} success', { object }) : 
        _t('Save {{object}} success', { object }))
      yield put({ type: '@@xadmin/ADD_NOTICE', payload: {
        type: 'success', headline: _t('Success'), message: noticeMessage
      } }) 
    }
  } catch(err) {
    app.error(err)
    if(promise) {
      promise.reject(err)
    }
  }
  yield put({ type: 'END_LOADING', model , key: `${model.key}.save` })
}
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 / actions.js View on Github external
yield put({ type: 'START_LOADING', model, key: `${model.key}.delete_items` })
  const { _t } = app.context
  const API = api(model)

  try {
    if(API.batchDelte) {
      yield API.batchDelte(items.map(item=>item.id))
    } else {
      yield all(items.map(item => call([ API, API.delete ], item.id)))
    }
    for(let item of items) {
      yield put({ type: 'SELECT_ITEMS', selected: false, item, model })
    }
    yield put({ type: 'GET_ITEMS', model })
  } catch(err) {
    app.error(err)
  }

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

  try {
    yield api(model).delete(item.id)
    yield put({ type: 'SELECT_ITEMS', selected: false, item, model })
    yield put({ type: '@@xadmin/ADD_NOTICE', payload: {
      type: 'success', headline: _t('Success'), message: message || _t('Delete {{object}} success', { object: model.title || model.name })
    } })
    yield put({ type: 'GET_ITEMS', model })
  } catch(err) {
    app.error(err)
  }

  yield put({ type: 'END_LOADING', model, key: `${model.key}.delete` })
}
github sshwsfc / xadmin / packages / xadmin-model / src / actions.js View on Github external
}
    yield put({ type: 'GET_ITEMS', model })

    if(promise) {
      promise.resolve(ret)
    }

    if( message !== false) {
      const object = model.title || model.name
      const noticeMessage = message || _t('Batch Save {{object}} success', { object })
      yield put({ type: '@@xadmin/ADD_NOTICE', payload: {
        type: 'success', headline: 'Success', message: noticeMessage
      } }) 
    }
  } catch(err) {
    app.error(err)
    if(promise) {
      promise.reject(err)
    }
  }
  yield put({ type: 'END_LOADING', model , key: `${model.key}.save_items` })
}