Documentation
¶
Index ¶
- Constants
- Variables
- func RegisterViewPath(p string)
- type Action
- type ActionArgument
- type Admin
- func (admin *Admin) AddMenu(menu *Menu)
- func (admin *Admin) AddResource(value interface{}, config ...*Config) *Resource
- func (admin *Admin) AddSearchResource(resources ...*Resource)
- func (admin *Admin) EnabledSearchCenter() bool
- func (admin Admin) GetMenu(name string) *Menu
- func (admin Admin) GetMenus() []*Menu
- func (admin *Admin) GetResource(name string) *Resource
- func (admin *Admin) GetResources() []*Resource
- func (admin *Admin) GetRouter() *Router
- func (admin *Admin) MountTo(mountTo string, mux *http.ServeMux)
- func (admin *Admin) NewContext(w http.ResponseWriter, r *http.Request) *Context
- func (admin *Admin) NewResource(value interface{}, config ...*Config) *Resource
- func (admin *Admin) RegisterFuncMap(name string, fc interface{})
- func (admin *Admin) RegisterMetaConfigor(kind string, fc func(*Meta))
- func (admin *Admin) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (admin *Admin) SetAuth(auth Auth)
- func (admin *Admin) SetSiteName(siteName string)
- func (admin *Admin) T(context *qor.Context, key string, value string, values ...interface{}) template.HTML
- type Auth
- type Config
- type Context
- func (context *Context) AllowedActions(actions []*Action, mode string) []*Action
- func (context *Context) Execute(name string, result interface{})
- func (context *Context) FindTemplate(layouts ...string) (string, error)
- func (context *Context) Flash(message, typ string)
- func (context *Context) FlashNow(message, typ string)
- func (context *Context) FormattedValueOf(value interface{}, meta *Meta) interface{}
- func (context *Context) FuncMap() template.FuncMap
- func (context *Context) GetFlashes() []Flash
- func (context *Context) GetResource(name string) *Resource
- func (context *Context) GetScopes() (menus []*scopeMenu)
- func (context *Context) JSON(name string, result interface{})
- func (context *Context) LinkTo(text interface{}, link interface{}) template.HTML
- func (context *Context) NewResourceContext(name ...interface{}) *Context
- func (context *Context) Pagination() *[]Page
- func (context *Context) RawValueOf(value interface{}, meta *Meta) interface{}
- func (context *Context) Render(name string, results ...interface{}) template.HTML
- func (context *Context) RenderMeta(meta *Meta, value interface{}, prefix []string, metaType string, ...)
- func (context *Context) UrlFor(value interface{}, resources ...*Resource) string
- type Filter
- type Flash
- type HasPermissioner
- type I18n
- type Menu
- type Meta
- type Middleware
- type Page
- type Pagination
- type Resource
- func (res *Resource) Action(action *Action)
- func (res *Resource) ConvertSectionToMetas(sections []*Section) []*Meta
- func (res *Resource) ConvertSectionToStrings(sections []*Section) []string
- func (res *Resource) Decode(context *qor.Context, value interface{}) error
- func (res *Resource) EditAttrs(values ...interface{}) []*Section
- func (res *Resource) Filter(filter *Filter)
- func (res Resource) GetAdmin() *Admin
- func (res *Resource) GetMeta(name string) *Meta
- func (res *Resource) GetMetaOrNew(name string) *Meta
- func (res *Resource) GetMetas(attrs []string) []resource.Metaor
- func (res Resource) GetPrimaryValue(request *http.Request) string
- func (res *Resource) IndexAttrs(values ...interface{}) []*Section
- func (res *Resource) Meta(meta *Meta) *Meta
- func (res *Resource) NewAttrs(values ...interface{}) []*Section
- func (res Resource) ParamIDName() string
- func (res *Resource) Scope(scope *Scope)
- func (res *Resource) SearchAttrs(columns ...string) []string
- func (res *Resource) ShowAttrs(values ...interface{}) []*Section
- func (res *Resource) SortableAttrs(columns ...string) []string
- func (res Resource) ToParam() string
- func (res Resource) UseTheme(theme string) []string
- type ResourceNamer
- type RouteConfig
- type Router
- func (r *Router) Delete(path string, handle requestHandler, config ...RouteConfig)
- func (r *Router) Get(path string, handle requestHandler, config ...RouteConfig)
- func (r *Router) Post(path string, handle requestHandler, config ...RouteConfig)
- func (r *Router) Put(path string, handle requestHandler, config ...RouteConfig)
- func (r *Router) Use(middleware *Middleware)
- type Scope
- type Searcher
- func (s *Searcher) Filter(name, query string) *Searcher
- func (s *Searcher) FindMany() (interface{}, error)
- func (s *Searcher) FindOne() (interface{}, error)
- func (s *Searcher) Page(num int) *Searcher
- func (s *Searcher) PrePage(num int) *Searcher
- func (s *Searcher) Scope(names ...string) *Searcher
- func (s *Searcher) WithPagination() *Searcher
- type Section
Constants ¶
const (
DEFAULT_PAGE_COUNT = 20
)
const HTTPUnprocessableEntity = 422
const (
VISIBLE_PAGE_COUNT = 8
)
Variables ¶
var DefaultHandler = func(name string, value string, scope *gorm.DB, context *qor.Context) *gorm.DB { lastIndex := strings.LastIndex(name, "_") operation := name[lastIndex+1 : len(name)] column := name[0:lastIndex] switch operation { case "cont": return scope.Where(fmt.Sprintf("%v ILIKE ?", scope.NewScope(nil).Quote(column)), "%"+value+"%") case "eq": return scope.Where(fmt.Sprintf("%v = ?", scope.NewScope(nil).Quote(column)), value) case "gt": return scope.Where(fmt.Sprintf("%v > ?", scope.NewScope(nil).Quote(column)), value) case "gteq": return scope.Where(fmt.Sprintf("%v >= ?", scope.NewScope(nil).Quote(column)), value) case "lt": return scope.Where(fmt.Sprintf("%v < ?", scope.NewScope(nil).Quote(column)), value) case "lteq": return scope.Where(fmt.Sprintf("%v <= ?", scope.NewScope(nil).Quote(column)), value) } return scope }
var Root, _ = os.Getwd()
Functions ¶
Types ¶
type Action ¶
type Action struct { Name string Label string Handle func(arg *ActionArgument) error Resource *Resource Permission *roles.Permission Visibles []string }
func (Action) HasPermission ¶
type ActionArgument ¶
func (*ActionArgument) FindSelectedRecords ¶
func (actionArgument *ActionArgument) FindSelectedRecords() []interface{}
type Admin ¶
type Admin struct { Config *qor.Config SiteName string I18n I18n // contains filtered or unexported fields }
func (*Admin) AddResource ¶
func (*Admin) AddSearchResource ¶
func (*Admin) EnabledSearchCenter ¶
func (*Admin) GetResource ¶
func (*Admin) GetResources ¶
func (*Admin) MountTo ¶
MountTo mount the service into mux (HTTP request multiplexer) with given path
func (*Admin) NewContext ¶
func (*Admin) NewResource ¶
func (*Admin) RegisterFuncMap ¶
RegisterFuncMap register view funcs, it could be used in view templates
func (*Admin) RegisterMetaConfigor ¶
RegisterMetaConfigor register configor for a kind, it will be called when register those kind of metas
func (*Admin) ServeHTTP ¶
func (admin *Admin) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP dispatches the handler registered in the matched route
func (*Admin) SetSiteName ¶
type Context ¶
type Context struct { *qor.Context *Searcher Flashes []Flash Resource *Resource Admin *Admin Content template.HTML Action string Result interface{} }
func (*Context) AllowedActions ¶
func (*Context) FindTemplate ¶
func (*Context) FormattedValueOf ¶
func (*Context) GetFlashes ¶
func (*Context) GetResource ¶
func (*Context) NewResourceContext ¶
func (*Context) Pagination ¶
Keep VISIBLE_PAGE_COUNT's pages visible, exclude prev and next link Assume there are 12 pages in total. When current page is 1 [current, 2, 3, 4, 5, 6, 7, 8, next] When current page is 6 [prev, 2, 3, 4, 5, current, 7, 8, 9, 10, next] When current page is 10 [prev, 5, 6, 7, 8, 9, current, 11, 12] If total page count less than VISIBLE_PAGE_COUNT, always show all pages
func (*Context) RawValueOf ¶
func (*Context) RenderMeta ¶
type HasPermissioner ¶
type HasPermissioner interface {
HasPermission(roles.PermissionMode, *qor.Context) bool
}
type I18n ¶
type I18n interface { Scope(scope string) I18n Default(value string) I18n T(locale string, key string, args ...interface{}) template.HTML }
I18n define admin's i18n interface
type Menu ¶
type Menu struct { Name string Link string Ancestors []string // contains filtered or unexported fields }
func (*Menu) GetSubMenus ¶
type Meta ¶
type Meta struct { Name string FieldName string Label string Type string FormattedValuer func(interface{}, *qor.Context) interface{} Valuer func(interface{}, *qor.Context) interface{} Setter func(resource interface{}, metaValue *resource.MetaValue, context *qor.Context) Metas []resource.Metaor Resource *Resource Collection interface{} GetCollection func(interface{}, *qor.Context) [][]string Permission *roles.Permission resource.Meta // contains filtered or unexported fields }
func (*Meta) GetResource ¶
func (*Meta) SetPermission ¶
func (meta *Meta) SetPermission(permission *roles.Permission)
type Middleware ¶
type Middleware struct { Name string Handler func(*Context, *Middleware) // contains filtered or unexported fields }
Middleware is a way to filter a request and response coming into your application
Register new middleware with `admin.GetRouter().Use(Middleware{ Name: "middleware name", // use middleware with same name will overwrite old one Handler: func(*Context, *Middleware) { // do something // run next middleware middleware.Next(context) }, })`
It will be called in order, it need to be registered before `admin.MountTo`
func (Middleware) Next ¶
func (middleware Middleware) Next(context *Context)
Next will call the next middleware
type Resource ¶
type Resource struct { resource.Resource Config *Config Metas []*Meta Actions []*Action SearchHandler func(keyword string, context *qor.Context) *gorm.DB // contains filtered or unexported fields }
func (*Resource) ConvertSectionToMetas ¶
func (*Resource) ConvertSectionToStrings ¶
func (*Resource) GetMetaOrNew ¶
func (Resource) GetPrimaryValue ¶
GetPrimaryValue get priamry value from request
func (*Resource) IndexAttrs ¶
func (Resource) ParamIDName ¶
ParamIDName return param name for primary key like :product_id
func (*Resource) SearchAttrs ¶
func (*Resource) SortableAttrs ¶
type ResourceNamer ¶
type ResourceNamer interface {
ResourceName() string
}
type RouteConfig ¶
type RouteConfig struct { Resource *Resource Permission *roles.Permission PermissionMode roles.PermissionMode Values map[interface{}]interface{} }
type Router ¶
type Router struct { Prefix string // contains filtered or unexported fields }
Router contains registered routers
func (*Router) Delete ¶
func (r *Router) Delete(path string, handle requestHandler, config ...RouteConfig)
Delete register a DELETE request handle with the given path
func (*Router) Get ¶
func (r *Router) Get(path string, handle requestHandler, config ...RouteConfig)
Get register a GET request handle with the given path
func (*Router) Post ¶
func (r *Router) Post(path string, handle requestHandler, config ...RouteConfig)
Post register a POST request handle with the given path
func (*Router) Put ¶
func (r *Router) Put(path string, handle requestHandler, config ...RouteConfig)
Put register a PUT request handle with the given path
func (*Router) Use ¶
func (r *Router) Use(middleware *Middleware)
Use reigster a middleware to the router
type Searcher ¶
type Searcher struct { *Context Pagination Pagination // contains filtered or unexported fields }