pagespecifier

package
v0.0.0-...-0aa8bca Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	FilterTypeString = map[FilterType]string{
		FilterTypeDateRange: "date",
		FilterTypeSelect:    "select",
		FilterTypeNumber:    "number",
		FilterTypeText:      "text",
		FilterTypeDate:      "date",
	}
)

Functions

func DefaultQueryFilterParser

func DefaultQueryFilterParser(f FilterQuery) (string, interface{})

func DefaultQuerySortParser

func DefaultQuerySortParser(s Sort) string

func EndsWithFilterParser

func EndsWithFilterParser(f FilterQuery) (string, interface{})

EndsWithFilterParser use this only with like operator or else it won't work as expected

func GlobalMatchFilterParser

func GlobalMatchFilterParser(f FilterQuery) (string, interface{})

GlobalMatchFilterParser use this only with like operator or else it won't work as expected

func StartsWithFilterParser

func StartsWithFilterParser(f FilterQuery) (string, interface{})

StartsWithFilterParser use this only with like operator or else it won't work as expected

Types

type Action

type Action struct {
	Id   string `json:"id"`
	Name string `json:"name"`
	//GroupAccess need to check this to enterprise if this is not permitted to be wandering around then it need to be hidden but if it's permitted to wander arround it would be nice for front end to use this
	GroupAccess []string `json:"group_access"`
	//ElementID need to check this to enterprise //I think we can use this for better access management integration with enterprise UAM
	ElementID string `json:"element_id"`
	Type      string `json:"type"`
	Class     string `json:"class"`
}

type Actions

type Actions struct {
	Top    []Action `json:"top"`
	Middle []Action `json:"middle"`
	Bottom []Action `json:"bottom"`
}

type Columns

type Columns struct {
	Header         string `json:"header"`
	Data           string `json:"-"`
	Variable       string `json:"variable"`
	Orderable      bool   `json:"orderable"`
	DefaultContent string `json:"default_content"`
	ClassName      string `json:"class_name"`
}

type ComparisonOperator

type ComparisonOperator int
const (
	ComparisonOperatorEqualTo ComparisonOperator = iota
	ComparisonOperatorNotEqualTo
	ComparisonOperatorGreaterThan
	ComparisonOperatorLessThan
	ComparisonOperatorGreaterThanEqualTo
	ComparisonOperatorLessThanEqualTo
	ComparisonOperatorLike
)

func (ComparisonOperator) String

func (c ComparisonOperator) String() string

type DetailData

type DetailData struct {
	Title string        `json:"title"`
	Data  []DetailField `json:"data"`
}

type DetailField

type DetailField struct {
	Label string `json:"label"`
	Value string `json:"value"`
}

type ExportResult

type ExportResult struct {
	Status   string `json:"status"`
	Location string `json:"location"`
}

type Filter

type Filter struct {
	ID         string     `json:"id"`
	Label      string     `json:"label"`
	Type       FilterType `json:"type"`
	TypeString string     `json:"type_string"`
	MetaData   MetaData   `json:"meta_data,omitempty"`
	Value      string     `json:"value"`
}

type FilterData

type FilterData struct {
	GroupMap      []map[string][]FilterGroup `json:"filter_data"`
	Headers       []string                   `json:"headers"`
	IsReverse     bool                       `json:"is_reverse"`
	UserActions   map[string]string          `json:"user_actions"`
	ActionButtons Actions                    `json:"action_buttons"`
	Columns       []Columns                  `json:"columns"`
}

type FilterDefinition

type FilterDefinition struct {
	Label string
	//Variable put url variabel name here
	Variable string
	//Operator please use the constant if you want to add new addition please make adjusment on the code
	Operator            ComparisonOperator
	FilterToQueryParser FilterToQueryParser
	//Data put database variabel name here
	Data string
	//FilterType please use the constant if you want to add new addition please make adjusment on the code
	Type    FilterType
	Hasher  Hasher
	IsShown bool
}

type FilterGroup

type FilterGroup struct {
	Label   string   `json:"label"`
	Filters []Filter `json:"filters"`
	Class   string   `json:"class"`
}

type FilterGroupDefinitions

type FilterGroupDefinitions [][]FilterDefinition

func (*FilterGroupDefinitions) GetFilterGroup

func (f *FilterGroupDefinitions) GetFilterGroup(options map[string][]SelectOption) []map[string][]FilterGroup

type FilterQuery

type FilterQuery struct {
	Column     string
	Operator   string
	Value      interface{}
	ColumnHash string
	ValueHash  interface{}
}

type FilterToQueryParser

type FilterToQueryParser int
const (
	FilterToQueryDefault FilterToQueryParser = iota
	FilterToQueryGlobalMatch
	FilterToQueryStartsWith
	FilterToQueryEndsWith
)

func (FilterToQueryParser) ParserFunc

type FilterType

type FilterType int
const (
	FilterTypeDateRange FilterType = iota
	FilterTypeSelect
	FilterTypeNumber
	FilterTypeText
	FilterTypeDate
)

func (FilterType) String

func (c FilterType) String() string

type FilterValue

type FilterValue struct {
	Column              string
	ColumnHash          string
	Operator            string
	FilterToQueryParser FilterToQueryParser
	Value               interface{}
	ValueHash           interface{}
}

type Hasher

type Hasher interface {
	HashString(value string) string
}

type InToolCards

type InToolCards struct {
	Id    string `json:"id"`
	Name  string `json:"name"`
	Value string `json:"value"`
}

type IntoolsResponse

type IntoolsResponse struct {
	Table IntoolsTable  `json:"table"`
	Cards []InToolCards `json:"cards"`
}

type IntoolsTable

type IntoolsTable struct {
	Total     int64       `json:"total"`
	TotalPage int64       `json:"total_page"`
	Page      int64       `json:"page"`
	Limit     int64       `json:"limit"`
	Rows      interface{} `json:"rows"`
}

type MetaData

type MetaData struct {
	Options []SelectOption `json:"options,omitempty"`
}

type PageSpecification

type PageSpecification struct {
	Filters       FilterGroupDefinitions
	Columns       []Columns
	UserActions   map[string]string
	ActionButtons Actions
}

PageSpecification Will Specify some page detail to front end

avoid using exact keyword sort,page,limit on filter variabel as it is reserved for the functional purpose if you need it so badly then you have to find other way or don't use this feature make your own.

example :

CategoryPageSpec = pagespecifier.PageSpecification{
	Filters: pagespecifier.FilterGroupDefinitions{
		[]pagespecifier.FilterDefinition{
			{
				Label:    "Parent Category",
				Operator: pagespecifier.ComparisonOperatorEqualTo,
				Data:     "c.parent_id", //base on database
				Variable: "parent_id", //base on url query
				Type:     pagespecifier.FilterTypeSelect,
			},
		},
	},
	Columns: []pagespecifier.Columns{
		{Header: "Column1", Data: "i_am_the_json_data1", Orderable: true},
		{Header: "Column2", Data: "i_am_the_json_data2", Orderable: false},
		{Header: "Column3", Data: "i_am_the_json_data3", Orderable: true},
		{Header: "Column4", Data: "i_am_the_json_data4", Orderable: false},
		{Header: "Column5", Data: "i_am_the_json_data5", Orderable: true},
		{Header: "Column6", Data: "i_am_the_json_data6", Orderable: true},
		{Header: ""}, //Put Blank for action column
	},
	UserActions: map[string]string{
		"searchUrl": "/order",
	},
	ActionButtons: pagespecifier.Actions{
		Top: []pagespecifier.Action{
			{
				Id:          "download",
				Name:        "Download",
				GroupAccess: []string{"put Group Access here"},
				ElementID:   "Put ElementID here",
				Class:       "btn btn-sm btn-custom w-md waves-effect waves-light mr-10",
			},
		},
		Middle: []pagespecifier.Action{
			{
				Id:          "search",
				Name:        "Search",
				Type:        "submit",
				GroupAccess: []string{"put Group Access here"},
				ElementID:   "Put ElementID here",
				Class:       "btn btn-sm btn-search btn-primary w-md  waves-effect waves-light mr-10",
			},
			{
				Id:          "reset",
				Name:        "Reset",
				Type:        "reset",
				GroupAccess: []string{"ftinins-product", "fitnins-business"},
				ElementID:   "Put ElementID here",
				Class:       "btn btn-sm btn-default btn-custom w-md waves-effect waves-light mr-10",
			},
		},
	},
}

func (*PageSpecification) GetFilterData

func (ps *PageSpecification) GetFilterData(options map[string][]SelectOption) *FilterData

func (*PageSpecification) GetResultFilter

func (ps *PageSpecification) GetResultFilter(input url.Values) ResultFilter

func (*PageSpecification) Parsefilter

func (ps *PageSpecification) Parsefilter(input url.Values) []FilterValue

Parsefilter equivalent of parser.ParseFilterRaw but with input of url.values but do not support 'in' clause yet will add it later :D

type QueryFilter

type QueryFilter struct {
	Filter []string
	Args   []interface{}
}

func GetQueryFilterWithParser

func GetQueryFilterWithParser(filters []FilterValue) *QueryFilter

GetQueryFilterWithParser added 'like' operator version util.GetQueryFilterWithParser from lending-platform

func (*QueryFilter) GetWhereClause

func (qf *QueryFilter) GetWhereClause() string

func (*QueryFilter) JoinFilter

func (qf *QueryFilter) JoinFilter() string

type QueryFilterParserFunc

type QueryFilterParserFunc func(f FilterQuery) (string, interface{})

type QuerySort

type QuerySort struct {
	Sort []string
}

func GetQuerySortWithParser

func GetQuerySortWithParser(sort []Sort, sp QuerySortParserFunc) *QuerySort

func (*QuerySort) GetOrderClause

func (qs *QuerySort) GetOrderClause() string

func (*QuerySort) JoinSort

func (qs *QuerySort) JoinSort() string

type QuerySortParserFunc

type QuerySortParserFunc func(s Sort) string

type ResultFilter

type ResultFilter struct {
	Filter  []FilterValue
	Sort    []Sort
	Page    int64
	Limit   int64
	Finance bool
	Export  bool
}

type SelectOption

type SelectOption struct {
	Value string
	Label string
}

type Sort

type Sort struct {
	Column    string
	SortOrder string
}

func ParseSortV2

func ParseSortV2(_sort string, m map[string]string) []Sort

Jump to

Keyboard shortcuts

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