adsa-cms: github.com/mmanjoura/adsa-cms/admin Index | Files

package admin

import "github.com/mmanjoura/adsa-cms/admin"

Index

Package Files

action.go admin.go assetfs.go auth.go config.go context.go controller.go filter.go flash.go func_map.go menu.go meta.go meta_configors.go meta_rich_editor.go meta_select_many.go meta_select_one.go resource.go route.go route_handler.go scope.go searcher.go section.go utils.go

Constants

const HTTPUnprocessableEntity = 422

HTTPUnprocessableEntity error status code

func RegisterViewPath Uses

func RegisterViewPath(pth string)

RegisterViewPath register view path for all assetfs

type Action Uses

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

Action action definiation

func (Action) HasPermission Uses

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

HasPermission check if current user has permission for the action

func (Action) ToParam Uses

func (action Action) ToParam() string

ToParam used to register routes for actions

type ActionArgument Uses

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

ActionArgument action argument that used in handle

func (*ActionArgument) FindSelectedRecords Uses

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

FindSelectedRecords find selected records when run bulk actions

type Admin Uses

type Admin struct {
    SiteName string
    Config   *qor.Config
    I18n     I18n
    AssetFS  AssetFSInterface
    // contains filtered or unexported fields
}

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

func New Uses

func New(config *qor.Config) *Admin

New new admin with configuration

func (*Admin) AddMenu Uses

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

AddMenu add a menu to admin

func (*Admin) AddResource Uses

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

AddResource make a model manageable from admin interface

func (*Admin) AddSearchResource Uses

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

AddSearchResource make a resource searchable from search center

func (Admin) GetMenu Uses

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

GetMenu get menu with name from admin

func (Admin) GetMenus Uses

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

GetMenus get menus for admin sidebar

func (*Admin) GetResource Uses

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

GetResource get resource with name

func (*Admin) GetResources Uses

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

GetResources get defined resources from admin

func (*Admin) GetRouter Uses

func (admin *Admin) GetRouter() *Router

GetRouter get router from admin

func (*Admin) GetSearchResources Uses

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

GetSearchResources get defined search resources from admin

func (*Admin) MountTo Uses

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

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

func (*Admin) NewContext Uses

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

NewContext new admin context

func (*Admin) NewResource Uses

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

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

func (*Admin) RegisterFuncMap Uses

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

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

func (*Admin) RegisterMetaConfigor Uses

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

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

func (*Admin) RegisterViewPath Uses

func (admin *Admin) RegisterViewPath(pth string)

RegisterViewPath register view path for admin

func (*Admin) ServeHTTP Uses

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

ServeHTTP dispatches the handler registered in the matched route

func (*Admin) SetAssetFS Uses

func (admin *Admin) SetAssetFS(assetFS AssetFSInterface)

SetAssetFS set AssetFS for admin

func (*Admin) SetAuth Uses

func (admin *Admin) SetAuth(auth Auth)

SetAuth set admin's authorization gateway

func (*Admin) SetSiteName Uses

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 Uses

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

T call i18n backend to translate

type AssetFSInterface Uses

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

type AssetFileSystem Uses

type AssetFileSystem struct {
    Paths []string
}

func (*AssetFileSystem) Asset Uses

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

func (*AssetFileSystem) Compile Uses

func (fs *AssetFileSystem) Compile() error

func (*AssetFileSystem) Glob Uses

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

func (*AssetFileSystem) RegisterPath Uses

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

type Auth Uses

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

Auth is an auth interface that used to qor admin If you want to implement an authorization gateway for admin interface, you could implement this interface, and set it to the admin with `admin.SetAuth(auth)`

type Config Uses

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

Config admin config struct

type Context Uses

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

Context admin context, which is used for admin controller

func (*Context) AllowedActions Uses

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

AllowedActions return allowed actions based on context

func (*Context) Asset Uses

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

func (*Context) Execute Uses

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

Execute execute template with layout

func (*Context) Flash Uses

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

Flash add flash message to next request

func (*Context) FlashNow Uses

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

FlashNow add flash message to current request

func (*Context) FormattedValueOf Uses

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

FormattedValueOf return formatted value of a meta for current resource

func (*Context) FuncMap Uses

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

FuncMap return funcs map

func (*Context) GetFlashes Uses

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

GetFlashes get flash messages for this request

func (*Context) GetScopes Uses

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

GetScopes get scopes from current context

func (*Context) JSON Uses

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

JSON generate json outputs for action

func (*Context) NewResourceContext Uses

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

NewResourceContext new resource context

func (*Context) Pagination Uses

func (context *Context) Pagination() *PaginationResult

Pagination return pagination information Keep visiblePageCount'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 Uses

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

RawValueOf return raw value of a meta for current resource

func (*Context) Render Uses

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

Render render template based on context

func (*Context) URLFor Uses

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

URLFor generate url for resource value

context.URLFor(&Product{})
context.URLFor(&Product{ID: 111})
context.URLFor(productResource)

type Filter Uses

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

Filter filter definiation

type Flash Uses

type Flash struct {
    Type    string
    Message string
    Keep    bool
}

Flash flash message definiation

type HasPermissioner Uses

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

HasPermissioner has permission interface

type I18n Uses

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
    Permission *roles.Permission
    // contains filtered or unexported fields
}

Menu qor admin sidebar menus definiation

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

GetSubMenus get submenus for a menu

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

type Meta Uses

type Meta struct {
    Name            string
    Type            string
    Label           string
    FieldName       string
    Setter          func(resource interface{}, metaValue *resource.MetaValue, context *qor.Context)
    Valuer          func(interface{}, *qor.Context) interface{}
    FormattedValuer func(interface{}, *qor.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 Uses

func (meta *Meta) DBName() string

DBName get meta's db name

func (*Meta) GetMetas Uses

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

GetMetas get sub metas

func (*Meta) GetResource Uses

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

GetResource get resource from meta

func (*Meta) SetPermission Uses

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

SetPermission set meta's permission

type MetaConfigInterface Uses

type MetaConfigInterface interface {
    resource.MetaConfigInterface
}

MetaConfigInterface meta config interface

type Middleware Uses

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 Uses

func (middleware Middleware) Next(context *Context)

Next will call the next middleware

type Page Uses

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

Page contain pagination information

type Pagination Uses

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

Pagination is used to hold pagination related information when rendering tables

type PaginationResult Uses

type PaginationResult struct {
    Pagination Pagination
    Pages      []Page
}

type Resource Uses

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
}

Resource is the most important thing for qor admin, every model is defined as a resource, qor admin will genetate management interface based on its definition

func (*Resource) Action Uses

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

Action register action for qor resource

func (*Resource) ConvertSectionToMetas Uses

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

ConvertSectionToMetas convert section to metas

func (*Resource) ConvertSectionToStrings Uses

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

ConvertSectionToStrings convert section to strings

func (*Resource) Decode Uses

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

Decode decode context into a value

func (*Resource) EditAttrs Uses

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

EditAttrs set attributes will be shown in the edit page

   // show given attributes in the new page
   order.EditAttrs("User", "PaymentAmount", "ShippedAt", "CancelledAt", "State", "ShippingAddress")
   // show all attributes except `State` in the edit page
   order.EditAttrs("-State")
You could also use `Section` to structure form to make it tidy and clean
   product.EditAttrs(
     &admin.Section{
     	Title: "Basic Information",
     	Rows: [][]string{
     		{"Name"},
     		{"Code", "Price"},
     	}},
     &admin.Section{
     	Title: "Organization",
     	Rows: [][]string{
     		{"Category", "Collections", "MadeCountry"},
     	}},
     "Description",
     "ColorVariations",
   }

func (*Resource) Filter Uses

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

Filter register filter for qor resource

func (*Resource) GetAction Uses

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

func (Resource) GetAdmin Uses

func (res Resource) GetAdmin() *Admin

GetAdmin get admin from resource

func (*Resource) GetMeta Uses

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

GetMeta get meta with name

func (*Resource) GetMetaOrNew Uses

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

GetMetaOrNew get meta or initalize a new one

func (*Resource) GetMetas Uses

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

GetMetas get metas with give attrs

func (Resource) GetPrimaryValue Uses

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

GetPrimaryValue get priamry value from request

func (*Resource) IndexAttrs Uses

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

IndexAttrs set attributes will be shown in the index page

// show given attributes in the index page
order.IndexAttrs("User", "PaymentAmount", "ShippedAt", "CancelledAt", "State", "ShippingAddress")
// show all attributes except `State` in the index page
order.IndexAttrs("-State")

func (*Resource) Meta Uses

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

Meta register meta for admin resource

func (*Resource) NewAttrs Uses

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

NewAttrs set attributes will be shown in the new page

   // show given attributes in the new page
   order.NewAttrs("User", "PaymentAmount", "ShippedAt", "CancelledAt", "State", "ShippingAddress")
   // show all attributes except `State` in the new page
   order.NewAttrs("-State")
You could also use `Section` to structure form to make it tidy and clean
   product.NewAttrs(
     &admin.Section{
     	Title: "Basic Information",
     	Rows: [][]string{
     		{"Name"},
     		{"Code", "Price"},
     	}},
     &admin.Section{
     	Title: "Organization",
     	Rows: [][]string{
     		{"Category", "Collections", "MadeCountry"},
     	}},
     "Description",
     "ColorVariations",
   }

func (Resource) ParamIDName Uses

func (res Resource) ParamIDName() string

ParamIDName return param name for primary key like :product_id

func (*Resource) Scope Uses

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

Scope register scope for qor resource

func (*Resource) SearchAttrs Uses

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

SearchAttrs set search attributes, when search resources, will use those columns to search

    // Search products with its name, code, category's name, brand's name
	   product.SearchAttrs("Name", "Code", "Category.Name", "Brand.Name")

func (*Resource) ShowAttrs Uses

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

ShowAttrs set attributes will be shown in the show page

   // show given attributes in the show page
   order.ShowAttrs("User", "PaymentAmount", "ShippedAt", "CancelledAt", "State", "ShippingAddress")
   // show all attributes except `State` in the show page
   order.ShowAttrs("-State")
You could also use `Section` to structure form to make it tidy and clean
   product.ShowAttrs(
     &admin.Section{
     	Title: "Basic Information",
     	Rows: [][]string{
     		{"Name"},
     		{"Code", "Price"},
     	}},
     &admin.Section{
     	Title: "Organization",
     	Rows: [][]string{
     		{"Category", "Collections", "MadeCountry"},
     	}},
     "Description",
     "ColorVariations",
   }

func (*Resource) SortableAttrs Uses

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

SortableAttrs set sortable attributes, sortable attributes could be click to order in qor table

func (Resource) ToParam Uses

func (res Resource) ToParam() string

ToParam used as urls to register routes for resource

func (Resource) UseTheme Uses

func (res Resource) UseTheme(theme string) []string

UseTheme use them for resource, will auto load the theme's javascripts, stylesheets for this resource

type ResourceNamer Uses

type ResourceNamer interface {
    ResourceName() string
}

ResourceNamer is an interface for models that defined method `ResourceName`

type RichEditorConfig Uses

type RichEditorConfig struct {
    AssetManager *Resource
}

func (*RichEditorConfig) ConfigureQorMeta Uses

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

ConfigureQorMeta configure rich editor meta

type RouteConfig Uses

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

RouteConfig config for admin routes

type Router Uses

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

Router contains registered routers

func (*Router) Delete Uses

func (r *Router) Delete(path string, handle requestHandler, config ...RouteConfig)

Delete register a DELETE request handle with the given path

func (*Router) Get Uses

func (r *Router) Get(path string, handle requestHandler, config ...RouteConfig)

Get register a GET request handle with the given path

func (*Router) Post Uses

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

Post register a POST request handle with the given path

func (*Router) Put Uses

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

Put register a PUT request handle with the given path

func (*Router) Use Uses

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

Use reigster a middleware to the router

type Scope Uses

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

Scope scope definiation

type Searcher Uses

type Searcher struct {
    *Context

    Pagination Pagination
    // contains filtered or unexported fields
}

Searcher is used to search results

func (*Searcher) Filter Uses

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

Filter filter with defined filters, filter with columns value

func (*Searcher) FindMany Uses

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

FindMany find many records based on current conditions

func (*Searcher) FindOne Uses

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

FindOne find one record based on current conditions

func (*Searcher) Page Uses

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

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

func (*Searcher) PerPage Uses

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

PerPage set pre page count

func (*Searcher) Scope Uses

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

Scope filter with defined scopes

type Section Uses

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

Section is used to structure forms, it could group your fields into sections, to make your form clean & tidy

product.EditAttrs(
  &admin.Section{
  	Title: "Basic Information",
  	Rows: [][]string{
  		{"Name"},
  		{"Code", "Price"},
  	}},
  &admin.Section{
  	Title: "Organization",
  	Rows: [][]string{
  		{"Category", "Collections", "MadeCountry"},
  	}},
  "Description",
  "ColorVariations",
}

func (*Section) String Uses

func (section *Section) String() string

String stringify section

type SelectManyConfig Uses

type SelectManyConfig struct {
    Collection interface{}
    SelectOneConfig
}

SelectManyConfig meta configuration used for select many

func (*SelectManyConfig) ConfigureQorMeta Uses

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

ConfigureQorMeta configure select many meta

type SelectOneConfig Uses

type SelectOneConfig struct {
    Collection interface{}
    // contains filtered or unexported fields
}

SelectOneConfig meta configuration used for select one

func (*SelectOneConfig) ConfigureQorMeta Uses

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

ConfigureQorMeta configure select one meta

func (SelectOneConfig) GetCollection Uses

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

GetCollection get collections from select one meta

Package admin imports 34 packages (graph) and is imported by 22 packages. Updated 2017-06-08. Refresh now. Tools for package owners.