grider

package module
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2023 License: MIT Imports: 13 Imported by: 0

README

grider

Backend part of the web table view

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FieldTagLabel = "grid"

FieldTagLabel holds struct field tag key.

Functions

func AssignActionSet added in v0.0.10

func AssignActionSet(lw Widgeter, as ActionSet) error

func NewActionSet added in v0.0.3

func NewActionSet() map[ActionCode]Action

NewActionSet builds instance of ActionSet.

func SetLinkPrefix

func SetLinkPrefix(s string)

func ToSnakeCase

func ToSnakeCase(str string) string

ToSnakeCase converts string like RobertEgorov to robert_egorov.

func WitTitlePrefix

func WitTitlePrefix(prefix string) func(*Option)

func WithDownloadOption

func WithDownloadOption(b bool) func(*Option)

func WithI18n added in v0.0.2

func WithI18n() func(*Option)

Types

type Action added in v0.0.2

type Action struct {
	Code       ActionCode  `json:"code,omitempty"`
	Perm       string      `json:"perm,omitempty"`
	Title      string      `json:"title,omitempty"`
	Icon       *Icon       `json:"icon,omitempty"`
	DirectCall *DirectCall `json:"directCall,omitempty"`
}

Action describes an operation on UI user can invocate. An action could relate to the specific row or not.

type ActionCode added in v0.0.3

type ActionCode string

type ActionSet added in v0.0.3

type ActionSet map[ActionCode]Action

ActionSet holds Actions identified by code. The type is useful for describe all supported application actions.

func (ActionSet) Add added in v0.0.6

func (as ActionSet) Add(arr []ActionCode)

func (ActionSet) AssignActionValues added in v0.0.6

func (dst ActionSet) AssignActionValues(src ActionSet) error

type AttrValueWidget added in v0.0.3

type AttrValueWidget struct {
	*Widget
	Lines []Line `json:"lines,omitempty"`
}

func (AttrValueWidget) WidgetType added in v0.0.3

func (AttrValueWidget) WidgetType() WidgetType

type Column added in v0.0.3

type Column struct {
	Name       string `json:"name"`
	Hidden     bool   `json:"hidden,omitempty"`     // default false
	Sortable   bool   `json:"sortable,omitempty"`   // default false
	Filterable bool   `json:"filterable,omitempty"` // default false
	Title      string `json:"title,omitempty"`      // default ""
	Perm       string `json:"perm,omitempty"`       // default not permission
	Type       string `json:"type,omitempty"`       // default "" (regular text)
	Href       string `json:"href,omitempty"`       // default "" (no link)
	Align      string `json:"align,omitempty"`      // default "" ("left") cell align
	Caption    string `json:"caption,omitempty"`    // default ""
	Method     string `json:"method,omitempty"`     // ?
	Icons      string `json:"icons,omitempty"`      // comma separated fa-* icon names
	IconsAlign string `json:"ialign,omitempty"`     // default "" ("left") "right" - after text
	Target     string `json:"target,omitempty"`     // default "" browser window target for opening link
	BgColor    string `json:"bgColor,omitempty"`    // default "" background color
	FgColor    string `json:"fgColor,omitempty"`    // default "" foreground color
	Width      string `json:"width,omitempty"`      // default "" column width
}

Column describes grid column's properties.

type ContentBodyType added in v0.0.13

type ContentBodyType int
const (
	Text     ContentBodyType = 1
	Html     ContentBodyType = 2
	Markdown ContentBodyType = 3
)

func (ContentBodyType) MarshalJSON added in v0.0.13

func (wt ContentBodyType) MarshalJSON() ([]byte, error)

func (ContentBodyType) String added in v0.0.13

func (wt ContentBodyType) String() string

type ContentWidget added in v0.0.13

type ContentWidget struct {
	*Widget
	Type ContentBodyType `json:"type"`
	Body string          `json:"body"`
}

func (ContentWidget) WidgetType added in v0.0.13

func (ContentWidget) WidgetType() WidgetType

type Date

type Date date.Date

func (Date) ConvertToString

func (t Date) ConvertToString(layout string) string

type DirectCall added in v0.0.3

type DirectCall struct {
	IsConfirmationRequired bool            `json:"isConfirmationRequired,omitempty"`
	ConfirmationMessage    string          `json:"confirmationMessage,omitempty"`
	Method                 string          `json:"method,omitempty"`
	Path                   string          `json:"path,omitempty"`
	Body                   json.RawMessage `json:"body,omitempty"`
}

DirectCall is action's extended attributes describing a simple action what does not have user interaction. As instance an action what directly calls server REST handler.

type DownloadResponse

type DownloadResponse struct {
	FileName    string
	ContentType string
	Content     string // base64
}

type EmptyWidget added in v0.0.19

type EmptyWidget struct {
	*Widget
}

func (EmptyWidget) WidgetType added in v0.0.19

func (EmptyWidget) WidgetType() WidgetType

type Float

type Float null.Float

func (Float) ConvertToString

func (t Float) ConvertToString(layout string) string

type Formatter

type Formatter interface {
	ConvertToString(layout string) string
}

type Grid

type Grid struct {
	Columns        []Column       `json:"columns"`
	Rows           [][]string     `json:"rows"`
	RowObjects     []interface{}  `json:"rowObjects,omitempty"`
	RowIDs         []int          `json:"rowIds,omitempty"`
	RowActions     [][]ActionCode `json:"rowActions,omitempty"`
	GridActions    []ActionCode   `json:"gridActions,omitempty"`
	Action         ActionSet      `json:"action,omitempty"`
	IsDownloadable bool           `json:"isDownloadable"`
	IsFilterable   bool           `json:"isFilterable"`
	NoPagination   bool           `json:"noPagination,omitempty"`
	PaginationType PaginationType `json:"paginationType"`
	TotalCount     int            `json:"totalCount,omitempty"` // total count of rows in accordance with applied filters
	// contains filtered or unexported fields
}

Grid describes data and metadata for presenting grid.

func New

func New(opts ...func(*Option)) *Grid

func (*Grid) ApplySliceOfStruct

func (g *Grid) ApplySliceOfStruct(src interface{}) *Grid

ApplySliceOfStruct converts slice of any struct to Grid, slice of column and rows.

func (*Grid) AssignActionSet added in v0.0.6

func (g *Grid) AssignActionSet(as ActionSet) error

func (*Grid) DeleteColumns

func (g *Grid) DeleteColumns(col []string)

DeleteColumns deletes columns with exact names in cols.

func (*Grid) Excelize

func (r *Grid) Excelize(fname string) (*DownloadResponse, error)

func (*Grid) JSON

func (g *Grid) JSON() ([]byte, error)
func (g *Grid) ReplaceCellWithFullLinks() error

type GridWidget added in v0.0.7

type GridWidget struct {
	*Widget
	Grid *Grid `json:"grid,omitempty"`
}

func (GridWidget) WidgetType added in v0.0.7

func (GridWidget) WidgetType() WidgetType
type Header struct {
	ID int `json:"id,omitempty"`

	// Icon параметры иконки отображемой в заголовке.
	LeftIcons []Icon `json:"leftIcons,omitempty"`

	// Title может содержать код из ресурсов %слово%
	Title string `json:"title,omitempty"`

	// SubTitle может содержать код из ресурсов %слово%
	SubTitle string `json:"subTitle,omitempty"`

	RightIcons []Icon `json:"rightIcons,omitempty"`

	// URL для перехода на страницу объекта, если значение заполнено.
	URL string `json:"url,omitempty"`

	// BgColor содержит цвета фона заголовка в формате HTML: red, #fff или #fefefe.
	BgColor string `json:"bgColor,omitempty"`
}

Header describes header of the Page or Tab.

type Icon added in v0.0.3

type Icon struct {
	// Name is name of font-awesome icon.
	Name string `json:"name"`

	// Color in HTML format.
	Color string `json:"color,omitempty"`
}

Icon describes fa-icon properties.

type Int

type Int null.Int

func (Int) ConvertToString

func (t Int) ConvertToString(layout string) string

type LazyWidget added in v0.0.9

type LazyWidget struct {
	*Widget
	URL string `json:"url"`
}

func (LazyWidget) WidgetType added in v0.0.9

func (LazyWidget) WidgetType() WidgetType

type Line added in v0.0.3

type Line struct {
	ID    int      `json:"id,omitempty"`
	Icon  *Icon    `json:"icon,omitempty"`
	Label string   `json:"label,omitempty"`
	Value string   `json:"value,omitempty"`
	Type  LineType `json:"type,omitempty"`
	// RefBook заполняется только если Type = "refbook"
	RefBook    *RefBookType    `json:"refBook,omitempty"`
	Suggestion *SuggestionType `json:"suggestion,omitempty"`

	// URL заполняется при Type = href или exthref
	URL     string       `json:"url,omitempty"`
	Actions []ActionCode `json:"actions,omitempty"`
}

Line описывает одну информационную строчку

type LineType added in v0.0.3

type LineType string

LineType описывает поддерживаемые типы линий.

const (
	// LineTypeDefault обычная строка. Показывать как текст
	LineTypeDefault LineType = ""

	// LineTypeHref показывать Value как ссылку
	LineTypeHref LineType = "href"

	// LineTypeExtHref показывать Value как ссылку на внешний ресурс.
	LineTypeExtHref LineType = "exthref"

	// LineTypeRefbook отображать Value как ссылку активирующую режим редактирования
	// параметры отображения комбобокса в структуре RefBookType.
	LineTypeRefbook LineType = "refbook"

	// LineTypeSuggestion отображать Value как ссылку активирующую режим редактирования
	// параметры отображения комбобокса в структуре RefBookType.
	LineTypeSuggestion LineType = "suggestion"
)

type Media added in v0.0.3

type Media struct {
	// ThumbnailURL содержит URL который необходимо использовать для отображения
	// миниатюр.
	ThumbnailURL string `json:"thumbnailUrl"`

	// URL содержит адрес полной фотографии/видео.
	URL string `json:"url"`

	// IsVideo = true, если это видео. В миниатюре будет фото.
	IsVideo bool `json:"isVideo,omitempty"`
}

Media описывает фото или видео для отображения в окне.

type MediaWidget added in v0.0.3

type MediaWidget struct {
	*Widget
	Media []Media `json:"media,omitempty"`
}

func (MediaWidget) WidgetType added in v0.0.3

func (MediaWidget) WidgetType() WidgetType

type NullTime

type NullTime null.Time

func (NullTime) ConvertToString

func (t NullTime) ConvertToString(layout string) string

type Option

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

type Page added in v0.0.3

type Page struct {
	ID     int     `json:"id,omitempty"`
	Header *Header `json:"header,omitempty"`

	Widgets []Widgeter `json:"widgets,omitempty"`

	// Tabs содержит описание подчиненных объектов.
	Tabs []Tab `json:"tabs,omitempty"`

	Action ActionSet `json:"action,omitempty"`

	// PageActions holds actions available in the drop down list on the page level.
	PageActions []ActionCode `json:"pageActions,omitempty"`
}

Page describes a single object page.

func (*Page) AssignActionSet added in v0.0.6

func (p *Page) AssignActionSet(supported ActionSet) error

Footer описывает содержимое нижней части окна.

type Footer struct {
	Media []Media `json:"media,omitempty"`
}

type PaginationType added in v0.0.12

type PaginationType int
const (
	PaginationServer  PaginationType = 0
	PaginationClient  PaginationType = 1
	PaginationWithout PaginationType = 2
)

func (PaginationType) MarshalJSON added in v0.0.12

func (pt PaginationType) MarshalJSON() ([]byte, error)

func (PaginationType) String added in v0.0.12

func (pt PaginationType) String() string

type RefBookType added in v0.0.3

type RefBookType struct {
	// Name содержит название справочника из /dictionary
	Name string `json:"name"`
	// SelectedID текущий ID элемента справочника.
	SelectedID int `json:"selectedId"`

	// SubmitURL адрес куда надо направить POST запрос содержащий новый выбранный id из справочника Name.
	// Структура запроса {"id" : 2}
	SubmitURL string `json:"sumbitUrl"`
}

RefBookType описывает параметры строчки которая является изменяемым элементом справочника.

type String

type String null.String

func (String) ConvertToString

func (t String) ConvertToString(layout string) string

type SuggestionType added in v0.0.3

type SuggestionType struct {
	// Name содержит название справочника из /dictionary
	Name string `json:"name"`
	// SelectedID текущий ID элемента справочника.
	SelectedID *int64 `json:"selectedId,omitempty"`

	UID string `json:"uid,omitempty"`

	// SubmitURL адрес куда надо направить POST запрос содержащий новый выбранный id из справочника Name.
	// Структура запроса {"id" : 2}
	SubmitURL string `json:"submitUrl"`
}

type Tab added in v0.0.3

type Tab struct {
	Header     *Header      `json:"header,omitempty"`
	TabActions []ActionCode `json:"tabActions,omitempty"`

	Widgets []Widgeter `json:"widgets,omitempty"`

	IsActive       bool `json:"isActive,omitempty"`
	IsInitRequired bool `json:"isInitRequired,omitempty"`
	IsDisabled     bool `json:"isDisabled,omitempty"`
}

Tab описывает содержимое одного связанного объекта.

type Time

type Time time.Time

func (Time) ConvertToString

func (t Time) ConvertToString(layout string) string

type Widget added in v0.0.4

type Widget struct {
	ID     int        `json:"id,omitempty"`
	Type   WidgetType `json:"type"`
	Header *Header    `json:"header,omitempty"`
	// Row     int          `json:"row"`
	// Col     int          `json:"col"`
	Width   int          `json:"width"`
	Actions []ActionCode `json:"widgetActions,omitempty"`

	// Action must be only filled if widget generated independent as
	// result of request from lazy widget.
	Action ActionSet `json:"action,omitempty"`

	// Object is an object in JSON. The object can be consumed
	// by customized UI logic. As instance: take data to init modal window.
	Object interface{} `json:"object,omitempty"`
}

type WidgetType added in v0.0.3

type WidgetType int
const (
	AttrValueType WidgetType = 1
	MediaType     WidgetType = 2
	GridType      WidgetType = 3
	MapType       WidgetType = 4
	ChartType     WidgetType = 5
	CustomType    WidgetType = 6
	LazyType      WidgetType = 7
	ContentType   WidgetType = 8
	EmptyType     WidgetType = 9
)

func (WidgetType) MarshalJSON added in v0.0.4

func (wt WidgetType) MarshalJSON() ([]byte, error)

func (WidgetType) String added in v0.0.4

func (wt WidgetType) String() string

type Widgeter added in v0.0.3

type Widgeter interface {
	WidgetType() WidgetType
}

Jump to

Keyboard shortcuts

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