grid

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2020 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConditionFilterSeparator = ";"
	ConditionSeparator       = ","
	ConditionFilterPrefix    = "filter_"
)
View Source
const (
	CREATE = iota + 1
	UPDATE
	DELETE
	CALLBACK
	FILTERCONFIG
	VTable
	VDetails
	VUpdate
	VCreate
	Export
)

Grid modes

View Source
const (
	BeforeFirst = iota + 1
	AfterFirst
	BeforeAll
	AfterAll
	BeforeCreate
	AfterCreate
	BeforeUpdate
	AfterUpdate
	BeforeDelete
	AfterDelete
)

Callbacks

View Source
const (
	FeSelect       = "select"
	FeUnique       = "unique"
	FeDecorator    = "decorator"
	FeNoEscaping   = "noEscaping"
	FeReturnObject = "vueReturnObject"
)

Frontend constants

View Source
const TPrefix = "GRID§§"

Variables

View Source
var ErrJsonInvalid = errors.New("grid: json is invalid")
View Source
var ErrRequestBody = errors.New("grid: request body is empty")

Functions

func FieldsToString

func FieldsToString(fields []Field) []string

func NewValue

func NewValue(val interface{}) *value

NewValue creates a new *value with the given value for all element. the grid ptr is added.

func Orm

func Orm(orm orm.Interface) *gridSource

Grid converts an orm model to an grid source.

func Translations

func Translations(ids ...string) []i18n.Message

Types

type Action

type Action struct {
	DisplayLeft   bool `json:"l,omitempty"`
	DisableFilter bool `json:"disableFilter,omitempty"`
	DisableCreate bool `json:"disableCreate,omitempty"`
	DisableDetail bool `json:"disableDetail,omitempty"`
	DisableUpdate bool `json:"disableUpdate,omitempty"`
	DisableDelete bool `json:"disableDelete,omitempty"`
}

Action

type Claim

type Claim interface {
	UserIdentification() interface{}
}

type Config

type Config struct {
	// ID is used to cache the grid fields. This must be unique.
	ID          string `json:"id,omitempty"`
	Title       string `json:"title,omitempty"`
	Description string `json:"description,omitempty"`
	Policy      int    `json:"-"`
	Action      Action `json:"action,omitempty"`

	// should not be able for the user to config.
	Filter  Filter        `json:"filter,omitempty"`
	Exports []ExportTypes `json:"exports,omitempty"`
}

Config - general grid config

func (*Config) DisableCreate

func (c *Config) DisableCreate(b bool) *Config

func (*Config) DisableDelete

func (c *Config) DisableDelete(b bool) *Config

func (*Config) DisableDetail

func (c *Config) DisableDetail(b bool) *Config

func (*Config) DisableFilter

func (c *Config) DisableFilter(b bool) *Config

func (*Config) DisableUpdate

func (c *Config) DisableUpdate(b bool) *Config

type ExportTypes

type ExportTypes struct {
	Key  string
	Name string
	Icon string
}

type FeGridActive

type FeGridActive struct {
	ID          int      `json:"id,omitempty"`
	RowsPerPage int      `json:"rowsPerPage,omitempty"`
	Sort        []string `json:"sort,omitempty"`
	Group       string   `json:"group,omitempty"`

	UserDisabledGrouping bool `json:"disabledGrouping"`
	UserDisabledSorting  bool `json:"disabledSorting"`
}

type FeGridFilter

type FeGridFilter struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

type Field

type Field struct {
	// contains filtered or unexported fields
}

func (*Field) Callback

func (f *Field) Callback() (callback interface{}, args interface{})

func (*Field) DatabaseId

func (f *Field) DatabaseId() string

func (Field) Description

func (f Field) Description() string

func (Field) Error

func (f Field) Error() error

func (*Field) Field

func (f *Field) Field(name string) *Field

Field will return the field by the given name. If it was not found, an error will be set.

func (Field) FieldType

func (f Field) FieldType() string

func (*Field) Fields

func (f *Field) Fields() []Field

func (Field) Id

func (f Field) Id() string

func (Field) IsFilterable

func (f Field) IsFilterable() bool

func (Field) IsGroupable

func (f Field) IsGroupable() bool

func (Field) IsHidden

func (f Field) IsHidden() bool

func (*Field) IsPrimary

func (f *Field) IsPrimary() bool

func (Field) IsReadOnly

func (f Field) IsReadOnly() bool

func (*Field) IsRelation

func (f *Field) IsRelation() bool

func (Field) IsRemoved

func (f Field) IsRemoved() bool

func (Field) IsSortable

func (f Field) IsSortable() bool

func (Field) MarshalJSON

func (f Field) MarshalJSON() ([]byte, error)

MarshalJson is used to create the header information of the field.

func (*Field) Option

func (f *Field) Option(key string) interface{}

func (*Field) Options

func (f *Field) Options() map[string]interface{}

func (Field) Position

func (f Field) Position() int

func (*Field) SetCallback

func (f *Field) SetCallback(callback interface{}, args ...interface{}) *Field

func (*Field) SetDatabaseId

func (f *Field) SetDatabaseId(id string)

func (*Field) SetDescription

func (f *Field) SetDescription(description interface{}) *Field

func (*Field) SetFieldType

func (f *Field) SetFieldType(fieldType string) *Field

func (*Field) SetFields

func (f *Field) SetFields(fields []Field)

func (*Field) SetFilterable

func (f *Field) SetFilterable(filterable bool) *Field

func (*Field) SetGroupable

func (f *Field) SetGroupable(groupable bool) *Field

func (*Field) SetHidden

func (f *Field) SetHidden(hidden interface{}) *Field

func (*Field) SetId

func (f *Field) SetId(id string) *Field

func (*Field) SetMode

func (f *Field) SetMode(mode int)

func (*Field) SetOption

func (f *Field) SetOption(key string, value interface{}) *Field

func (*Field) SetPosition

func (f *Field) SetPosition(position interface{}) *Field

func (*Field) SetPrimary

func (f *Field) SetPrimary(primary bool)

func (*Field) SetReadOnly

func (f *Field) SetReadOnly(readOnly bool) *Field

func (*Field) SetRelation

func (f *Field) SetRelation(r bool) *Field

func (*Field) SetRemove

func (f *Field) SetRemove(remove interface{}) *Field

func (*Field) SetSortable

func (f *Field) SetSortable(sortable bool) *Field

func (*Field) SetTitle

func (f *Field) SetTitle(title interface{}) *Field

func (*Field) SetView

func (f *Field) SetView(view interface{}) *Field

func (Field) Title

func (f Field) Title() string

func (*Field) View

func (f *Field) View() string

type Filter

type Filter struct {
	List   []FeGridFilter `json:"list,omitempty"`
	Active FeGridActive   `json:"active,omitempty"`
}

type Grid

type Grid struct {
	// contains filtered or unexported fields
}

func New

func New(c controller.Interface, config *Config) *Grid

New creates a grid instance with the given controller. the controller is used to fetch all the request data and add the response.

func (*Grid) AddCallback

func (g *Grid) AddCallback(name int, fn func(*Grid) error)

AddCallback to the grid. (Before/After)First,All,Create,Update,Delete exists.

func (*Grid) Config

func (g *Grid) Config() *Config

Config of the grid.

func (*Grid) Controller

func (g *Grid) Controller() controller.Interface

Controller returns the grid controller. This data could be useful in the implemented source.

func (*Grid) Field

func (g *Grid) Field(name string) *Field

Field by name. If the field was not found a new Field with an error is created. This helps the user to avoid annoying error if statements. If there was an error, the grid will automatically response with an error message. Or you can call field.Error() != nil to check if an error happend.

func (*Grid) Fields

func (g *Grid) Fields() []Field

Fields return all defined grid fields.

func (*Grid) IsCallback

func (g *Grid) IsCallback() bool

func (*Grid) Mode

func (g *Grid) Mode() int

Mode by the given url / http method. POST = grid create PUT = grid update DELETE = grid delete GET without any mode param = grid view table GET with mode param "create" = grid view create GET with mode param "update" = grid view update GET with mode param "details" = grid view details GET with mode param "callback" = grid view callback everything else will return 0

func (*Grid) Render

func (g *Grid) Render()

Render the grid by the defined grid mode.

func (*Grid) SetCondition

func (g *Grid) SetCondition(c *sqlquery.Condition) *Grid

SetCondition adds a condition on the primary source.

func (*Grid) SetExport

func (g *Grid) SetExport(exports ...string) error

func (*Grid) SetSource

func (g *Grid) SetSource(src SourceI) error

SetSource to the grid. Fields are getting fetched from the source.

func (*Grid) Source

func (g *Grid) Source() interface{}

type Select

type Select struct {
	TextField  string       `json:",omitempty"`
	ValueField string       `json:",omitempty"`
	Items      []SelectItem `json:",omitempty"`

	Api       string `json:"api,omitempty"`
	Condition string `json:",omitempty"`
	OrmField  string `json:"-"`
}

type SelectItem

type SelectItem struct {
	Text  interface{} `json:"text"`
	Value interface{} `json:"value"`
}

type SourceI

type SourceI interface {
	// Init is called right after the source was added.
	// This function can be used if the source has to get initialized after it was added.
	Init(grid *Grid) error
	// Fields of the grid.
	Fields(grid *Grid) ([]Field, error)
	// UpdatedFields is called before render. The grid fields have the user updated configurations.
	UpdatedFields(grid *Grid) error
	// Callback is called on a callback request of the grid.
	Callback(callback string, grid *Grid) (interface{}, error)
	// First request a single row by the given condition.
	First(c *sqlquery.Condition, grid *Grid) (interface{}, error)
	// All data by the given condition.
	All(c *sqlquery.Condition, grid *Grid) (interface{}, error)
	// Create the object
	Create(grid *Grid) (interface{}, error)
	// Update the object
	Update(grid *Grid) error
	// Delete the object by the given condition.
	Delete(c *sqlquery.Condition, grid *Grid) error
	// Count all the existing object by the given condition.
	Count(c *sqlquery.Condition, grid *Grid) (int, error)
	// Interface returns the under laying interface
	Interface() interface{}
}

type UserGrid

type UserGrid struct {
	orm.Model
	ID     int
	GridID string
	UserID int

	Name    string
	GroupBy orm.NullString

	Filters []UserGridFilter
	Sorting []UserGridSort
	Fields  []UserGridField

	Default     bool
	RowsPerPage orm.NullInt
}

type UserGridField

type UserGridField struct {
	orm.Model
	ID         int
	UserGridID int

	Key string
	Pos int
}

type UserGridFilter

type UserGridFilter struct {
	orm.Model
	ID         int
	UserGridID int

	Key   string
	Op    string
	Value orm.NullString
}

type UserGridSort

type UserGridSort struct {
	orm.Model
	ID         int
	UserGridID int

	Key  string
	Pos  orm.NullInt // because 0 should be allowed as well. TODO figure out a better solution
	Desc bool
}

Jump to

Keyboard shortcuts

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