How to use the xadmin.context 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 / wrap.js View on Github external
const perm = (permission, component, failureComponent=null) => {
  const { store } = app.context
  return (user => {
    if(user && user.isSuper) { return true }
    if(user && user.permissions) {
      if(_.isArray(permission)) {
        return !_.some(permission, p => user.permissions.indexOf(p) == -1)
      } else if(_.isFunction(permission)) {
        return permission(user)
      } else {
        return user.permissions.indexOf(permission) > -1
      }
    } else {
      return false
    }
  })(store.getState().user) ? component: failureComponent
}
github sshwsfc / xadmin / packages / xadmin-bootstrap / src / filter / components / NumberFilter.js View on Github external
render() {
    const { input: { name, value, onBlur, onChange, ...inputProps }, field } = this.props
    const { gte, lte } = this.state
    const { _t } = app.context
    return (
      
        this.onBlur(e, 'gte')} onChange={(e)=>this.onChange(e, 'gte')} />
                  
        this.onBlur(e, 'lte')} onChange={(e)=>this.onChange(e, 'lte')} />
      
    )
  }
github sshwsfc / xadmin / packages / xadmin-bootstrap / src / filter / components / BooleanFilter.js View on Github external
render() {
    const { input: { name, value, onChange }, field } = this.props
    const { _t } = app.context

    return (
      
        <button>{
          onChange(value === true?null:true)
        }}&gt;{field.boolLabel ? field.boolLabel[0] : _t('True')}</button>
        <button>{
          onChange(value === false?null:false)
        }}&gt;{field.boolLabel ? field.boolLabel[1] : _t('False')}</button>
      
    )
  }
github sshwsfc / xadmin / examples / xadmin-demo / src / auth / api.js View on Github external
let headers = () => {
    const { store } = app.context
    const user = store != undefined ? store.getState().user : null
    const hs = {
      'Content-Type': 'application/json'
    }
    if( user && user.id ) {
      hs['Authorization'] = user.id
    }
    return hs
  }
  let resource = model.resource_name || model.name
github sshwsfc / xadmin / packages / xadmin-antd / src / filter / components / EnumFilter.js View on Github external
render() {
    const { input: { name, value, onBlur, onChange, ...inputProps }, field } = this.props
    const { checks } = this.state
    const { _t } = app.context 
    return (
      &lt;&gt;
        {
            if(e.target.checked) {
              this.clear()
            }
          }} {...inputProps} &gt;{_t('All')}
        {field.titleMap.map(option =&gt; { return (
          = 0} 
            onChange={(e)=&gt;this.onChange(e, option.value)}
            {...inputProps} value={option.value} &gt;{option.name}) })}
      
    )
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-bootstrap / src / form / components / layout.js View on Github external
const ModalLayout = ({ children, invalid, handleSubmit, submitting, title, show, onClose, saveText }) =&gt; {
  const { _t } = app.context

  return (
    
      {title}
      
        <form>{children}</form>
      
      
        <button>{_t('Close')}</button>
        <button disabled="{invalid" type="submit">
           {saveText || _t('Save')}
        </button>
      
    
  )
}
github sshwsfc / xadmin / packages / xadmin-i18n / src / index.js View on Github external
const _t = (...props) => app.context._t(...props)
github sshwsfc / xadmin / packages / xadmin-auth / src / mappers.js View on Github external
onChange: ({ dispatch }) => (item) => {
        const { _t } = app.context
        return new Promise((resolve, reject) => {
          dispatch({ model: UserChangePassword(app), type: 'SAVE_ITEM', item, promise: { resolve, reject }, 
            message: _t('Change password success') })
        }).then(user => {
          app.go('/app/')
        }).catch(error => {
          throw new SubmissionError({ old_password: _t('Incorrect old password') })
        })
      }
    }
github sshwsfc / xadmin / packages / xadmin-bootstrap / src / model / relate.js View on Github external
render() {
    const { _t } = app.context
    const { input: { value: item }, field } = this.props
    const displayField = field.displayField || 'name'
    return (
      
    )
  }
}