admin

package module
v0.0.0-...-bc1e9b6 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2017 License: MIT Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const HTTPUnprocessableEntity = 422

'HTTPUnprocessableEntity' error status code

Variables

View Source
var DisableCompositePrimaryKeyMode = "composite_primary_key:query:disable"
View Source
var (
	PaginationPageCount = 20
)

Functions

func RegisterViewPath

func RegisterViewPath(pth string)

Types

type Action

type Action struct {
	Name        string
	Label       string
	Method      string
	URL         func(record interface{}, context *Context) string
	URLOpenType string
	Visible     func(record interface{}, context *Context) bool
	Handler     func(argument *ActionArgument) error
	Modes       []string
	Resource    *Resource
	Permission  *roles.Permission
}

'Action' action defination

func (Action) HasPermission

func (action Action) HasPermission(mode roles.PermissionMode, context *TM_EC.Context) bool

'HasPermission' check if current user has permission for the action

func (Action) IsAllowed

func (action Action) IsAllowed(mode roles.PermissionMode, context *Context, records ...interface{}) bool

'IsAllowed' check if current user has permission to view the action

func (Action) ToParam

func (action Action) ToParam() string

'ToParam' used to register routes for actions

type ActionArgument

type ActionArgument struct {
	PrimaryValues       []string
	Context             *Context
	Argument            interface{}
	SkipDefaultResponse bool
}

'ActionArgument' action argument that used in handle

func (*ActionArgument) FindSelectedRecords

func (actionArgument *ActionArgument) FindSelectedRecords() []interface{}

'FindSelectedRecords' find selected records when run bulk actions

type Admin

type Admin struct {
	SiteName string
	Config   *TM_EC.Config
	I18n     I18n
	AssetFS  AssetFSInterface

	Auth Auth
	// contains filtered or unexported fields
}

'Admin' is a struct that used to generate admin/api interface

func New

func New(config *TM_EC.Config) *Admin

'New' new admin with configuration

func (*Admin) AddMenu

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

'AddMenu' add a menu to admin

func (*Admin) AddResource

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

'AddResource' make a model manageable from admin interface

func (*Admin) AddSearchResrouce

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

func (Admin) GetMenu

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

'GetMenu' get menu with name from admin

func (Admin) GetMenus

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

'GetMenus' get menus for admin sidebar

func (*Admin) GetResource

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

'GetResource' get resource with name

func (*Admin) GetResources

func (admin *Admin) GetResources() []*Resource

'GetResources' get defined resource from admin

func (*Admin) GetRouter

func (admin *Admin) GetRouter() *Router

'GetRouter' get router from admin

func (*Admin) GetSearchResrouces

func (admin *Admin) GetSearchResrouces() []*Resource

func (*Admin) MountTo

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

'MountTo' mount the serice into mux (HTTP request multiplexer) with given path

func (*Admin) NewContext

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

'NewContext' new admin context

func (*Admin) NewResource

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

'NewResource' initialize a new ec resource, won't add it to admin, just initialize it

func (*Admin) RegisterFuncMap

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

'RegisterFuncMap' register view funcs, it could be used in view templates

func (*Admin) RegisterMetaConfigor

func (admin *Admin) RegisterMetaConfigor(king string, fc func(*Meta))

'RegisterMetaConfigor' register configor for a kind, it will be called when register those kind of metas

func (*Admin) RegisterResourceRouters

func (admin *Admin) RegisterResourceRouters(res *Resource, modes ...string)

func (*Admin) RegisterViewPath

func (admin *Admin) RegisterViewPath(pth string)

'RegisterViewPath' register view path for admin

func (*Admin) ServeHTTP

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

'ServeHTTP' dispatches the handler registered in the matched route

func (*Admin) SetAssetFS

func (admin *Admin) SetAssetFS(assetFS AssetFSInterface)

'SetAssetFS' set AssetFS for admin

func (*Admin) SetAuth

func (admin *Admin) SetAuth(auth Auth)

'SetAuth' set admin's authorization gateway

func (*Admin) SetSiteName

func (admin *Admin) SetSiteName(siteName string)

SetSiteName set site's name, the name will be used as admin HTML title and admin interface will auto load javascripts, stylesheets files based on its value For example, if you named it as `Qor Demo`, admin will look up `qor_demo.js`, `qor_demo.css` in QOR view paths, and load them if found

func (*Admin) T

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

type AssetFSInterface

type AssetFSInterface interface {
	RegisterPath(path string) error
	Asset(namt string) ([]byte, error)
	Glob(pattern string) ([]string, error)
	Compile() error
}

type AssetFileSystem

type AssetFileSystem struct {
	Paths []string
}

func (*AssetFileSystem) Asset

func (fs *AssetFileSystem) Asset(name string) ([]byte, error)

func (*AssetFileSystem) Compile

func (fs *AssetFileSystem) Compile() error

func (*AssetFileSystem) Glob

func (fs *AssetFileSystem) Glob(pattern string) (matches []string, err error)

func (*AssetFileSystem) RegisterPath

func (fs *AssetFileSystem) RegisterPath(pth string) error

type Auth

type Auth interface {
	GetCurrentUser(*Context) TM_EC.CurrentUser
	LoginURL(*Context) string
	LogoutURL(*Context) string
}

'Auth' is an auth interface that used to EC admin if you want to implement an authorization gataway for admin interface, you could implement this interface, and set it to the admin with 'admin.SetAuth(auth)'

type CollectionEditConfig

type CollectionEditConfig struct {
	Template string
	// contains filtered or unexported fields
}

'CollectionEditConfig' meta configuration used for collection edit

func (*CollectionEditConfig) ConfigureECMeta

func (collecctionEditConfig *CollectionEditConfig) ConfigureECMeta(metaor resource.Metaor)

'collecctionEditConfig' configure collection edit meta

func (CollectionEditConfig) GetTemplate

func (collecctionEditConfig CollectionEditConfig) GetTemplate(context *Context, metaType string) ([]byte, error)

'GetTemplate' get template for collection edit

type Config

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

'Config' admin config struct

type Context

type Context struct {
	*TM_EC.Context
	*Searcher
	Flashes  []Flash
	Resource *Resource
	Admin    *Admin
	Content  template.HTML
	Action   string
	Settings map[string]interface{}
	Result   interface{}
	// contains filtered or unexported fields
}

'Context' admin context, which is used for admin controller

func (*Context) AllowedActions

func (context *Context) AllowedActions(actions []*Action, mode string, records ...interface{}) []*Action

'AllowedActions' return allowed actions based on context

func (*Context) Asset

func (context *Context) Asset(layouts ...string) ([]byte, error)

func (*Context) Execute

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

'Execute' execute template with layout

func (*Context) Flash

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

'Flash' add flash message to next request

func (*Context) FlashNow

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

'FlashNow' add flash message to current request

func (*Context) FormattedValueOf

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

'FormattedValueOf' return formatted of a meta for current resource

func (*Context) FuncMap

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

'FuncMap' return funcs map

func (*Context) Funcs

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

'Funcs' set FuncMap for template

func (*Context) Get

func (context *Context) Get(key string) interface{}

'Get' get context's settings

func (*Context) GetFlashes

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

'GetFlashes' get flash message for this request

func (*Context) GetScopes

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

'GetScopes' get scopes from current context

func (*Context) JSON

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

'JSON' generate json outputs for action

func (*Context) NewResourceContext

func (context *Context) NewResourceContext(name ...interface{}) *Context

'NewResourceContext' new resource context

func (*Context) Pagination

func (context *Context) Pagination() *PaginationResult

func (*Context) RawValueOf

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

'RawValueOf' return raw value of a meta for current resource

func (*Context) Render

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

'Render' render template based on context

func (*Context) Set

func (context *Context) Set(key string, value interface{})

'Set' set context's settings

func (*Context) URLFor

func (context *Context) URLFor(value interface{}, resources ...*Resource) string
	'URLFor' generate url for resource value
  e.g.  	context.URLFor(&Product{})
    		context.URLFor(&Product{ID: 111})
    		context.URLFor(productResource)

type Controller

type Controller struct {
	*Admin
	// contains filtered or unexported fields
}

func (*Controller) Action

func (ac *Controller) Action(context *Context)

func (*Controller) Asset

func (ac *Controller) Asset(context *Context)

func (*Controller) Create

func (ac *Controller) Create(context *Context)

func (*Controller) Dashboard

func (ac *Controller) Dashboard(context *Context)

func (*Controller) Delelte

func (ac *Controller) Delelte(context *Context)

func (*Controller) Edit

func (ac *Controller) Edit(context *Context)

func (*Controller) Index

func (ac *Controller) Index(context *Context)

func (*Controller) New

func (ac *Controller) New(context *Context)

func (*Controller) SearchCenter

func (ac *Controller) SearchCenter(context *Context)

func (*Controller) Show

func (ac *Controller) Show(context *Context)

func (*Controller) Update

func (ac *Controller) Update(context *Context)

type Filter

type Filter struct {
	Name       string
	Label      string
	Type       string
	Operations []string
	Resource   *Resource
	Handler    func(*gorm.DB, *FilterArgument) *gorm.DB
	Config     FilterConfigInterface
}

'Filter' filter definiation

type FilterArgument

type FilterArgument struct {
	Value    *resource.MetaValues
	Resource *Resource
	Context  *TM_EC.Context
}

'FilterArgument' filter argument that used in handler

type FilterConfigInterface

type FilterConfigInterface interface {
	ConfigureECAdminFilter(*Filter)
}

'FilterConfigInterface' filter config interface

type Flash

type Flash struct {
	Type    string
	Message string
	Keep    bool
}

'Flash' flash message definiation

type HasPermissioner

type HasPermissioner interface {
	HasPermission(roles.PermissionMode, *TM_EC.Context) bool
}

'HasPermissioner' has permission interface

type I18n

type I18n interface {
	Scope(scope string) I18n
	Default(value string) I18n
	T(locale string, key string, args ...interface{}) template.HTML
}
type Menu struct {
	Name       string
	Link       string
	Ancestors  []string
	Priority   int
	Permission *roles.Permission
	// contains filtered or unexported fields
}

'Menu' ec admin sidebar menus defination

func (menu *Menu) GetSubMenus() []*Menu

'GetSubMenus' get submenus for a menu

func (menu Menu) HasPermission(mode roles.PermissionMode, context *TM_EC.Context) bool

type Meta

type Meta struct {
	Name            string
	Type            string
	Label           string
	FieldName       string
	Setter          func(resource interface{}, metaValue *resource.MetaValue, context *TM_EC.Context)
	Valuer          func(interface{}, *TM_EC.Context) interface{}
	FormattedValuer func(interface{}, *TM_EC.Context) interface{}
	Resource        *Resource
	Permission      *roles.Permission
	Config          MetaConfigInterface

	Metas      []resource.Metaor
	Collection interface{}
	resource.Meta
	// contains filtered or unexported fields
}

'Meta' meta struct definition

func (*Meta) DBName

func (meta *Meta) DBName() string

'DBName' get meta's db name

func (*Meta) GetMetas

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

'GetMetas' get sub metas

func (*Meta) GetResource

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

'GetResource' get resource from meta

func (Meta) HasPermission

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

'HasPermission' check has permission or not

func (*Meta) SetPermission

func (meta *Meta) SetPermission(permission *roles.Permission)

'SetPermission' set meta's permission

type MetaConfigInterface

type MetaConfigInterface interface {
	resource.MetaConfigInterface
	GetTemplate(context *Context, metaType string) ([]byte, error)
}

'MetaConfigInterface' meta config interface

type Middleware

type Middleware struct {
	Name    string
	Handler func(*Context, *Middleware)
	// contains filtered or unexported fields
}
	'Middleware' is a way to filert a request and response coming into you 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 Page

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

'Page' contain pagination information

type Pagination

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

'Pagination' is used to hold pagination related information when rendering tables

type PaginationResult

type PaginationResult struct {
	Pagination Pagination
	Pages      []Page
}

type RedactorPlugin

type RedactorPlugin struct {
	Name   string
	Source string
}

type Resource

type Resource struct {
	resource.Resource
	Config        *Config
	Metas         []*Meta
	Actions       []*Action
	SearchHandler func(keyword string, context *TM_EC.Context) *gorm.DB
	// contains filtered or unexported fields
}

'Resource' is the most important thing for EC admin, every model is defined as resource, EC admin will genetate management interface based on it's definition

func (*Resource) Action

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

'Action' register action for EC resource

func (*Resource) ConvertSectionToMetas

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

'ConvertSectionToMetas' convert section to metas

func (*Resource) ConvertSectionToStrings

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

'ConvertSectionToStrings' convert section to strings

func (*Resource) Decode

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

func (*Resource) EditAttrs

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

func (*Resource) Filter

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

'Filter' register filter for ec resource

func (*Resource) GetAction

func (res *Resource) GetAction(name string) *Action

func (Resource) GetAdmin

func (res Resource) GetAdmin() *Admin

'GetAdmin' get admin from resource

func (*Resource) GetFilter

func (res *Resource) GetFilter() []*Filter

func (*Resource) GetMeta

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

'GetMeta' get meta with name

func (*Resource) GetMetaOrNew

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

func (*Resource) GetMetas

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

func (Resource) GetPrimaryValue

func (res Resource) GetPrimaryValue(request *http.Request) string

func (*Resource) GetTheme

func (res *Resource) GetTheme(name string) ThemeInterface

func (*Resource) IndexAttrs

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

func (*Resource) Meta

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

'Meta' register meta for admin resource

func (*Resource) NewAttrs

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

func (Resource) ParamIDName

func (res Resource) ParamIDName() 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(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 interface{}) []ThemeInterface

type ResourceNamer

type ResourceNamer interface {
	ResourceName() string
}

'ResourceNamer' is an interface for models that defined methos 'ResourceName'

type RichEditorConfig

type RichEditorConfig struct {
	AssetManager *Resource
	Plugins      []RedactorPlugin
	Settings     map[string]interface{}
	// contains filtered or unexported fields
}

func (*RichEditorConfig) ConfigureECMeta

func (richEditorConfig *RichEditorConfig) ConfigureECMeta(metaor resource.Metaor)

'ConfigureECMeta' configure rich editor meta

func (RichEditorConfig) GetTemplate

func (RichEditorConfig) GetTemplate(context *Context, metaType string) ([]byte, error)

'GetTemplate' get customized template for meta

type RouteConfig

type RouteConfig struct {
	Resource       *Resource
	Permissioner   HasPermissioner
	PermissionMode roles.PermissionMode
	Values         map[interface{}]interface{}
}

'RouteConfig' config for admin routes

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 requestHanlder, config ...RouteConfig)

'Delete' register a DELETE request handler with the given path

func (*Router) Get

func (r *Router) Get(path string, handler requestHanlder, config ...RouteConfig)

'Get' register a GET request handler with the given path

func (*Router) Mounted

func (r *Router) Mounted() bool

func (*Router) Post

func (r *Router) Post(path string, handle requestHanlder, config ...RouteConfig)

'Post' register a POST request handler with the given path

func (*Router) Put

func (r *Router) Put(path string, handle requestHanlder, config ...RouteConfig)

'Put' register a PUT request handler with the given path

func (*Router) Use

func (r *Router) Use(middleware *Middleware)

'Use' register a middleware to the router

type Scope

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

'Scope' scope definiation

type Searcher

type Searcher struct {
	*Context

	Pagination Pagination
	// contains filtered or unexported fields
}

'Searcher' is used to search results

func (*Searcher) Filter

func (s *Searcher) Filter(filter *Filter, values *resource.MetaValues) *Searcher

'Filter' filter with defined filters, filter with columns value

func (*Searcher) FindMany

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

'FindMany' find many records based on current conditions

func (*Searcher) FindOne

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

'FindOne' find one record based on current conditions

func (*Searcher) Page

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

'Page' set current page, if current page equal -1, then show all records

func (*Searcher) PerPage

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

'PerPage' set per page count

func (*Searcher) Scope

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

'Scope' filter with defined scopes

type Section

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

'Section' is used to structure forms, it could gruop your fields into sections, to make your form clear & tidy

func (*Section) String

func (section *Section) String() string

'String' stringify section

type SelectManyConfig

type SelectManyConfig struct {
	Collection               interface{}
	SelectionTemplate        string
	SelectMode               string
	Select2ResultTemplate    template.JS
	Select2SelectionTemplate template.JS
	RemoteDataResource       *Resource
	SelectOneConfig
}

'SelectManyConfig' meta configuration used for select many

func (*SelectManyConfig) ConfigureECMeta

func (selectManyConfig *SelectManyConfig) ConfigureECMeta(metaor resource.Metaor)

'ConfigureECMeta' configure select many meta

func (SelectManyConfig) GetTemplate

func (selectManyConfig SelectManyConfig) GetTemplate(context *Context, metaType string) ([]byte, error)

'GetTemplate' get template for selection template

type SelectOneConfig

type SelectOneConfig struct {
	Collection               interface{}
	AllowBlank               bool
	SelectionTemplate        string
	SelectMode               string
	Select2ResultTemplate    template.JS
	Select2SelectionTemplate template.JS
	RemoteDataResource       *Resource
	// contains filtered or unexported fields
}

'SelectOneConfig' meta configuration used for select one

func (*SelectOneConfig) ConfigureECAdminFilter

func (selectOneConfig *SelectOneConfig) ConfigureECAdminFilter(filter *Filter)

func (*SelectOneConfig) ConfigureECMeta

func (selectOneConfig *SelectOneConfig) ConfigureECMeta(metaor resource.Metaor)

'ConfigureECMeta' configure select one meta

func (*SelectOneConfig) FilterValue

func (selectOneConfig *SelectOneConfig) FilterValue(filter *Filter, context *Context) interface{}

func (SelectOneConfig) GetCollection

func (selectOneConfig SelectOneConfig) GetCollection(value interface{}, context *Context) [][]string

'GetCollection' get collection s from select on meta

func (SelectOneConfig) GetTemplate

func (selectOneConfig SelectOneConfig) GetTemplate(context *Context, metaType string) ([]byte, error)

'GetTemplate' get template for selection template

type SingleEditConfig

type SingleEditConfig struct {
	Template string
	// contains filtered or unexported fields
}

'SingleEditConfig' meta configuration used for single edit

func (*SingleEditConfig) ConfigureECMeta

func (singleEditConfig *SingleEditConfig) ConfigureECMeta(metaor resource.Metaor)

'ConfigureECMeta' configure single edit meta

func (SingleEditConfig) GetTemplate

func (singleEditConfig SingleEditConfig) GetTemplate(context *Context, metaType string) ([]byte, error)

'GetTemplate' get template for single edit

type Theme

type Theme struct {
	Name string
}

'Theme' base theme config struct

func (Theme) ConfigAdminTheme

func (Theme) ConfigAdminTheme(*Resource)

'ConfigAdminTheme' config theme for admin resource

func (Theme) GetName

func (theme Theme) GetName() string

'GetName' get name from theme

func (Theme) GetViewPaths

func (Theme) GetViewPaths() []string

'GetViewPaths' get view paths from theme

type ThemeInterface

type ThemeInterface interface {
	GetName() string
	GetViewPaths() []string
	ConfigAdminTheme(*Resource)
}

'ThemeInterface' theme interface

Jump to

Keyboard shortcuts

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