admin

package
v0.0.0-...-38b5e39 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 24, 2015 License: MIT Imports: 24 Imported by: 0

README

Qor Admin

Usage

HTTP Mux

mux := http.NewServeMux()
web := admin.New(&qor.Config{DB: &db})
web.AddToMux("/admin", mux)
http.ListenAndServe(":8080", mux)

Gin

mux := http.NewServeMux()

web := admin.New(&qor.Config{DB: &db.DB})
web.AddToMux("/admin", mux)

router := gin.Default()
// ...
mux.Handle("/", router)
http.ListenAndServe(":8080", mux)

Documentation

Index

Constants

This section is empty.

Variables

View Source
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
}
View Source
var DisableLogging bool
View Source
var Root, _ = os.Getwd()

Functions

func Equal

func Equal(a, b interface{}) bool

func RegisterViewPath

func RegisterViewPath(path string) error

Types

type Action

type Action struct {
	Name   string
	Metas  []string
	Handle func(scope *gorm.DB, context *qor.Context) error
	Inline bool
}

type Admin

type Admin struct {
	Config *qor.Config
	// contains filtered or unexported fields
}

func New

func New(config *qor.Config) *Admin

func (*Admin) AddMenu

func (admin *Admin) AddMenu(menu *Menu)

func (*Admin) AddResource

func (admin *Admin) AddResource(value interface{}, config *Config) *Resource

func (Admin) GetMenu

func (admin Admin) GetMenu(name string) (m *Menu)

func (Admin) GetMenus

func (admin Admin) GetMenus() []*Menu

func (*Admin) GetResource

func (admin *Admin) GetResource(name string) *Resource

func (*Admin) GetRouter

func (admin *Admin) GetRouter() *Router

func (*Admin) MountTo

func (admin *Admin) MountTo(prefix string, mux *http.ServeMux)

func (*Admin) NewContext

func (admin *Admin) NewContext(w http.ResponseWriter, r *http.Request) *Context

func (*Admin) RegisterFuncMap

func (admin *Admin) RegisterFuncMap(name string, fc interface{})

func (*Admin) ServeHTTP

func (admin *Admin) ServeHTTP(w http.ResponseWriter, req *http.Request)

func (*Admin) SetAuth

func (admin *Admin) SetAuth(auth Auth)

type AssetManager

type AssetManager struct {
	ID   int
	File media_library.FileSystem `media_library:"URL:/system/assets/{{primary_key}}/{{filename_with_hash}}"`
}

func (*AssetManager) InjectQorAdmin

func (*AssetManager) InjectQorAdmin(res *Resource)

type Auth

type Auth interface {
	GetCurrentUser(*Context) qor.CurrentUser
	Login(*Context)
	Logout(*Context)
}

type Config

type Config struct {
	Name       string
	Menu       []string
	Invisible  bool
	Permission *roles.Permission
	Theme      string
}

type Context

type Context struct {
	*qor.Context
	*Searcher
	Resource    *Resource
	Admin       *Admin
	CurrentUser qor.CurrentUser
	Writer      http.ResponseWriter
	Result      interface{}
	Content     string
}

func (*Context) AllMetas

func (context *Context) AllMetas(resources ...*Resource) []*Meta

func (*Context) EditMetas

func (context *Context) EditMetas(resources ...*Resource) []*Meta

func (*Context) Execute

func (context *Context) Execute(name string, result interface{})

func (*Context) HasPrimaryKey

func (context *Context) HasPrimaryKey(value interface{}, primaryKey interface{}) bool

func (*Context) IndexMetas

func (context *Context) IndexMetas(resources ...*Resource) []*Meta

func (*Context) JavaScriptTag

func (context *Context) JavaScriptTag(name string) string

func (*Context) LinkTo

func (context *Context) LinkTo(text interface{}, link interface{}) string

func (*Context) NewMetas

func (context *Context) NewMetas(resources ...*Resource) []*Meta

func (*Context) NewRecord

func (context *Context) NewRecord(value interface{}) interface{}

func (*Context) NewResource

func (context *Context) NewResource(name ...string) *Context

func (*Context) NewResourcePath

func (context *Context) NewResourcePath(value interface{}) string

func (*Context) PrimaryKeyOf

func (context *Context) PrimaryKeyOf(value interface{}) interface{}

Function Maps

func (*Context) Render

func (context *Context) Render(name string, results ...interface{}) string

func (*Context) RenderForm

func (context *Context) RenderForm(value interface{}, metas []*Meta) string

func (*Context) RenderMeta

func (context *Context) RenderMeta(writer *bytes.Buffer, meta *Meta, value interface{}, prefix []string)

func (*Context) ResourcePath

func (context *Context) ResourcePath() string

Resource

func (*Context) SetResource

func (context *Context) SetResource(res *Resource) *Context

func (*Context) ShowMetas

func (context *Context) ShowMetas(resources ...*Resource) []*Meta

func (*Context) StyleSheetTag

func (context *Context) StyleSheetTag(name string) string

func (*Context) UrlFor

func (context *Context) UrlFor(value interface{}, resources ...*Resource) string

func (*Context) ValueOf

func (context *Context) ValueOf(value interface{}, meta *Meta) interface{}

type Filter

type Filter struct {
	Name       string
	Operations []string
	Handler    func(name string, value string, scope *gorm.DB, context *qor.Context) *gorm.DB
}

type Handle

type Handle func(c *Context)

type Handler

type Handler struct {
	Path   *regexp.Regexp
	Handle Handle
}

type Injector

type Injector interface {
	InjectQorAdmin(*Resource)
}
type Menu struct {
	Name string

	Link  string
	Items []*Menu
	// contains filtered or unexported fields
}
func (m *Menu) AddChild(menu *Menu)

type Meta

type Meta struct {
	Name   string
	Alias  string
	Label  string
	Type   string
	Valuer func(interface{}, *qor.Context) interface{}
	// TODO: should allow Setter to return error, at least have a place to register
	Setter        func(resource interface{}, metaValue *resource.MetaValue, context *qor.Context)
	Metas         []resource.Metaor
	Resource      resource.Resourcer
	Collection    interface{}
	GetCollection func(interface{}, *qor.Context) [][]string
	Permission    *roles.Permission
	// contains filtered or unexported fields
}

func (*Meta) GetFieldName

func (meta *Meta) GetFieldName() string

func (*Meta) GetMetas

func (meta *Meta) GetMetas() []resource.Metaor

func (*Meta) GetName

func (meta *Meta) GetName() string

func (*Meta) GetResource

func (meta *Meta) GetResource() resource.Resourcer

func (*Meta) GetSetter

func (meta *Meta) GetSetter() func(resource interface{}, metaValue *resource.MetaValue, context *qor.Context)

func (*Meta) GetValuer

func (meta *Meta) GetValuer() func(interface{}, *qor.Context) interface{}

func (*Meta) HasPermission

func (meta *Meta) HasPermission(mode roles.PermissionMode, context *qor.Context) bool

type Resource

type Resource struct {
	resource.Resource

	Config *Config
	Metas  []*Meta
	// contains filtered or unexported fields
}

func (*Resource) Action

func (res *Resource) Action(action *Action)

func (*Resource) AllMetas

func (res *Resource) AllMetas() []*Meta

func (*Resource) AllowedMetas

func (res *Resource) AllowedMetas(attrs []*Meta, context *Context, roles ...roles.PermissionMode) []*Meta

func (*Resource) CallFinder

func (res *Resource) CallFinder(result interface{}, metaValues *resource.MetaValues, context *qor.Context) error

func (*Resource) CallSaver

func (res *Resource) CallSaver(result interface{}, context *qor.Context) error

func (*Resource) CallSearcher

func (res *Resource) CallSearcher(result interface{}, context *qor.Context) error

func (*Resource) ConvertObjectToMap

func (res *Resource) ConvertObjectToMap(context qor.Contextor, value interface{}, metas []*Meta) interface{}

func (*Resource) Decode

func (res *Resource) Decode(contextor qor.Contextor, value interface{}) (errs []error)

func (*Resource) EditAttrs

func (res *Resource) EditAttrs(columns ...string)

func (*Resource) EditMetas

func (res *Resource) EditMetas() []*Meta

func (*Resource) Filter

func (res *Resource) Filter(filter *Filter)

func (Resource) GetAdmin

func (res Resource) GetAdmin() *Admin

func (*Resource) GetMetas

func (res *Resource) GetMetas(_attrs ...[]string) []resource.Metaor

func (*Resource) IndexAttrs

func (res *Resource) IndexAttrs(columns ...string)

func (*Resource) IndexMetas

func (res *Resource) IndexMetas() []*Meta

func (*Resource) Meta

func (res *Resource) Meta(meta *Meta)

func (*Resource) NewAttrs

func (res *Resource) NewAttrs(columns ...string)

func (*Resource) NewMetas

func (res *Resource) NewMetas() []*Meta

func (*Resource) Scope

func (res *Resource) Scope(scope *Scope)

func (*Resource) ShowAttrs

func (res *Resource) ShowAttrs(columns ...string)

func (*Resource) ShowMetas

func (res *Resource) ShowMetas() []*Meta

func (Resource) ToParam

func (res Resource) ToParam() string

type ResourceNamer

type ResourceNamer interface {
	ResourceName() string
}

type Router

type Router struct {
	Prefix string
	// contains filtered or unexported fields
}

func (*Router) Delete

func (r *Router) Delete(path string, handle Handle)

func (*Router) Get

func (r *Router) Get(path string, handle Handle)

func (*Router) Post

func (r *Router) Post(path string, handle Handle)

func (*Router) Put

func (r *Router) Put(path string, handle Handle)

type Scope

type Scope struct {
	Name    string
	Label   string
	Handle  func(*gorm.DB, *qor.Context) *gorm.DB
	Default bool
}

type Searcher

type Searcher struct {
	*Context
	// contains filtered or unexported fields
}

func (*Searcher) Filter

func (s *Searcher) Filter(name, query string) *Searcher

func (*Searcher) FindAll

func (s *Searcher) FindAll() (interface{}, error)

func (*Searcher) FindOne

func (s *Searcher) FindOne() (interface{}, error)

func (*Searcher) Scope

func (s *Searcher) Scope(names ...string) *Searcher

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL