admin

package
v0.0.0-...-c72e3f0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2015 License: MIT Imports: 27 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

Search Center

It provide feature set that let End User to be able to quickly find any resources Developer defnited, like Product, Order, User, etc. Developer define what field of information user can search on.

Developer side usage

End User side usage

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
	SiteName string
	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) AddSearchResource

func (admin *Admin) AddSearchResource(resources ...*Resource)

func (*Admin) EnabledSearchCenter

func (admin *Admin) EnabledSearchCenter() bool

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)

func (*Admin) SetSiteName

func (admin *Admin) SetSiteName(siteName string)

func (*Admin) T

func (admin *Admin) T(context *qor.Context, key string, value string, values ...interface{}) template.HTML

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
	Singleton  bool
}

type Context

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

func (*Context) Execute

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

func (*Context) FindTemplate

func (context *Context) FindTemplate(layouts ...string) (string, error)

func (*Context) Flash

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

func (*Context) FlashNow

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

func (*Context) FormattedValueOf

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

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

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

func (*Context) LinkTo

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

func (*Context) NewResourceContext

func (context *Context) NewResourceContext(name ...interface{}) *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) RawValueOf

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

func (*Context) Render

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

func (*Context) RenderForm

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

func (*Context) RenderMeta

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

func (*Context) UrlFor

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

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{}) template.HTML
}

I18n define admin's i18n interface

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
	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.Resourcer
	Collection      interface{}
	GetCollection   func(interface{}, *qor.Context) [][]string
	Permission      *roles.Permission
	resource.Meta
	// contains filtered or unexported fields
}

func (*Meta) DBName

func (meta *Meta) DBName() string

func (*Meta) GetMetas

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

func (*Meta) GetResource

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

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

	IsSetShowAttrs bool

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

func (res *Resource) ConvertSectionToMetas(sections []*Section) []*Meta

func (*Resource) ConvertSectionToStrings

func (res *Resource) ConvertSectionToStrings(sections []*Section) []string

func (*Resource) Decode

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

func (*Resource) EditAttrs

func (res *Resource) EditAttrs(values ...interface{}) []*Section

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

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

func (*Resource) GetMetas

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

func (*Resource) IndexAttrs

func (res *Resource) IndexAttrs(values ...interface{}) []*Section

func (*Resource) Meta

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

func (*Resource) NewAttrs

func (res *Resource) NewAttrs(values ...interface{}) []*Section

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(values ...interface{}) []*Section

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

type Section

type Section struct {
	Resource Resource
	Title    string
	Rows     [][]string
}

Jump to

Keyboard shortcuts

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