/
api.go
91 lines (73 loc) · 3.15 KB
/
api.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package presets
import (
"fmt"
"net/http"
"net/url"
"github.com/qor5/ui/vuetifyx"
"github.com/qor5/web"
h "github.com/theplant/htmlgo"
)
type ComponentFunc func(ctx *web.EventContext) h.HTMLComponent
type ObjectComponentFunc func(obj interface{}, ctx *web.EventContext) h.HTMLComponent
type EditingTitleComponentFunc func(obj interface{}, defaultTitle string, ctx *web.EventContext) h.HTMLComponent
type FieldComponentFunc func(obj interface{}, field *FieldContext, ctx *web.EventContext) h.HTMLComponent
type ActionComponentFunc func(id string, ctx *web.EventContext) h.HTMLComponent
type ActionUpdateFunc func(id string, ctx *web.EventContext) (err error)
type BulkActionComponentFunc func(selectedIds []string, ctx *web.EventContext) h.HTMLComponent
type BulkActionUpdateFunc func(selectedIds []string, ctx *web.EventContext) (err error)
type BulkActionSelectedIdsProcessorFunc func(selectedIds []string, ctx *web.EventContext) (processedSelectedIds []string, err error)
type BulkActionSelectedIdsProcessorNoticeFunc func(selectedIds []string, processedSelectedIds []string, unactionableIds []string) string
type MessagesFunc func(r *http.Request) *Messages
// Data Layer
type DataOperator interface {
Search(obj interface{}, params *SearchParams, ctx *web.EventContext) (r interface{}, totalCount int, err error)
// return ErrRecordNotFound if record not found
Fetch(obj interface{}, id string, ctx *web.EventContext) (r interface{}, err error)
Save(obj interface{}, id string, ctx *web.EventContext) (err error)
Delete(obj interface{}, id string, ctx *web.EventContext) (err error)
}
type SetterFunc func(obj interface{}, ctx *web.EventContext)
type FieldSetterFunc func(obj interface{}, field *FieldContext, ctx *web.EventContext) (err error)
type ValidateFunc func(obj interface{}, ctx *web.EventContext) (err web.ValidationErrors)
type SearchFunc func(model interface{}, params *SearchParams, ctx *web.EventContext) (r interface{}, totalCount int, err error)
type FetchFunc func(obj interface{}, id string, ctx *web.EventContext) (r interface{}, err error)
type SaveFunc func(obj interface{}, id string, ctx *web.EventContext) (err error)
type DeleteFunc func(obj interface{}, id string, ctx *web.EventContext) (err error)
type SQLCondition struct {
Query string
Args []interface{}
}
type SearchParams struct {
KeywordColumns []string
Keyword string
SQLConditions []*SQLCondition
PerPage int64
Page int64
OrderBy string
PageURL *url.URL
}
type SlugDecoder interface {
PrimaryColumnValuesBySlug(slug string) map[string]string
}
func RecoverPrimaryColumnValuesBySlug(dec SlugDecoder, slug string) (r map[string]string, err error) {
defer func() {
if e := recover(); e != nil {
r = nil
err = fmt.Errorf("wrong slug: %v", slug)
}
}()
r = dec.PrimaryColumnValuesBySlug(slug)
return r, nil
}
type SlugEncoder interface {
PrimarySlug() string
}
type FilterDataFunc func(ctx *web.EventContext) vuetifyx.FilterData
type FilterTab struct {
ID string
Label string
// render AdvancedLabel if it is not nil
AdvancedLabel h.HTMLComponent
Query url.Values
}
type FilterTabsFunc func(ctx *web.EventContext) []*FilterTab