admin

package
v0.0.0-...-24faacb Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2015 License: MIT Imports: 31 Imported by: 0

README

Introduction

Qor admin provide easy-to-use interface for data management.

Quick example

Use 35 lines of code to setup & run Qor admin.

package main

import (
  "net/http"

  "github.com/jinzhu/gorm"
  _ "github.com/mattn/go-sqlite3"
  "github.com/qor/qor"
  "github.com/qor/qor/admin"
)

type User struct {
  gorm.Model
  Name string
}

type Product struct {
  gorm.Model
  Name        string
  Description string
}

func main() {
  DB, _ := gorm.Open("sqlite3", "demo.db")
  DB.AutoMigrate(&User{}, &Product{})

  Admin := admin.New(&qor.Config{DB: &DB})
  Admin.AddResource(&User{}, &admin.Config{Menu: []string{"User Management"}})
  Admin.AddResource(&Product{}, &admin.Config{Menu: []string{"Product Management"}})

  mux := http.NewServeMux()
  Admin.MountTo("/admin", mux)
  http.ListenAndServe(":9000", mux)
}

// TODO: add screenshot after QOR admin UI finished go run main.go and visit localhost:9000/admin to see the result !

You can view qor example for a more detailed configuration example.

Features

  • CRUD of any resource
  • Search and filtering
  • Authentication
  • Authorization(detail)
  • Custom actions
  • Customizable view
  • Rich editor
  • Image crop
  • Integrate-able with Publish
  • Integrate-able with l10n
  • JSON API supported
  • Extendable

Documentation

https://github.com/qor/qor/wiki

Documentation

Index

Constants

View Source
const (
	DEFAULT_PAGE_COUNT = 20
)
View Source
const HTTPUnprocessableEntity = 422
View Source
const (
	VISIBLE_PAGE_COUNT = 8
)

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 Root, _ = os.Getwd()

Functions

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
	I18n   I18n
	// 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) *Menu

func (Admin) GetMenus

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

func (*Admin) GetResource

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

func (*Admin) GetResources

func (admin *Admin) GetResources() []*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) NewResource

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

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
	LoginURL(*Context) string
	LogoutURL(*Context) string
}

type Config

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

type Context

type Context struct {
	*qor.Context
	*Searcher
	Flashes  []Flash
	Resource *Resource
	Admin    *Admin
	Result   interface{}
	Content  template.HTML
}

func (*Context) Execute

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

func (*Context) FindTemplate

func (context *Context) FindTemplate(tmpl *template.Template, layout string) (*template.Template, error)

func (*Context) Flash

func (context *Context) Flash(message, typ string)

func (*Context) FlashNow

func (context *Context) FlashNow(message, typ string)

func (*Context) FuncMap

func (context *Context) FuncMap() template.FuncMap

func (*Context) GetFlashes

func (context *Context) GetFlashes() []Flash

func (*Context) GetResource

func (context *Context) GetResource(name string) *Resource

func (*Context) GetScopes

func (context *Context) GetScopes() (menus []*scopeMenu)

func (*Context) LinkTo

func (context *Context) LinkTo(text interface{}, link interface{}) template.HTML

func (*Context) NewResourceContext

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

func (*Context) Pagination

func (context *Context) Pagination() *[]Page

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) Render

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

func (*Context) RenderForm

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

func (*Context) T

func (context *Context) T(key string, values ...interface{}) 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 Flash

type Flash struct {
	Type    string
	Message string
	Keep    bool
}

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{}) string
}

type Injector

type Injector interface {
	InjectQorAdmin(*Resource)
}
type Menu struct {
	Name      string
	Link      string
	Ancestors []string
	// contains filtered or unexported fields
}
func (menu *Menu) GetSubMenus() []*Menu

type Meta

type Meta struct {
	Name          string
	DBName        string
	Alias         string
	Label         string
	Type          string
	Valuer        func(interface{}, *qor.Context) interface{}
	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 Middleware

type Middleware struct {
	Handler func(*Context, *Middleware)
	// contains filtered or unexported fields
}

func (Middleware) Next

func (middleware Middleware) Next(context *Context)

type Page

type Page struct {
	Page       int
	Current    bool
	IsPrevious bool
	IsNext     bool
}

type Pagination

type Pagination struct {
	Total       int
	Pages       int
	CurrentPage int
	PrePage     int
}

type Resource

type Resource struct {
	resource.Resource

	Config *Config
	Metas  []*Meta

	SearchHandler func(keyword string, context *qor.Context) *gorm.DB
	// contains filtered or unexported fields
}

func (*Resource) Action

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

func (*Resource) Decode

func (res *Resource) Decode(context *qor.Context, value interface{}) error

func (*Resource) EditAttrs

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

func (*Resource) Filter

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

func (Resource) GetAdmin

func (res Resource) GetAdmin() *Admin

func (*Resource) GetMeta

func (res *Resource) GetMeta(name string) *Meta

func (*Resource) GetMetas

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

func (*Resource) HasPermission

func (res *Resource) HasPermission(mode roles.PermissionMode, context *qor.Context) bool

func (*Resource) IndexAttrs

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

func (*Resource) Meta

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

func (*Resource) NewAttrs

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

func (*Resource) Scope

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

func (*Resource) SearchAttrs

func (res *Resource) SearchAttrs(columns ...string) []string

func (*Resource) ShowAttrs

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

func (*Resource) SortableAttrs

func (res *Resource) SortableAttrs(columns ...string) []string

func (Resource) ToParam

func (res Resource) ToParam() string

func (Resource) UseTheme

func (res Resource) UseTheme(theme string) []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)

func (*Router) Use

func (r *Router) Use(handler func(*Context, *Middleware))

type Scope

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

type Searcher

type Searcher struct {
	*Context

	Pagination Pagination
	// contains filtered or unexported fields
}

func (*Searcher) Filter

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

func (*Searcher) FindMany

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

func (*Searcher) FindOne

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

func (*Searcher) Page

func (s *Searcher) Page(num int) *Searcher

func (*Searcher) PrePage

func (s *Searcher) PrePage(num int) *Searcher

func (*Searcher) Scope

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

func (*Searcher) WithPagination

func (s *Searcher) WithPagination() *Searcher

Jump to

Keyboard shortcuts

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