api.go 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package presets
  2. import (
  3. "net/http"
  4. "net/url"
  5. "github.com/qor5/ui/vuetifyx"
  6. "github.com/qor5/web"
  7. h "github.com/theplant/htmlgo"
  8. )
  9. type ComponentFunc func(ctx *web.EventContext) h.HTMLComponent
  10. type ObjectComponentFunc func(obj interface{}, ctx *web.EventContext) h.HTMLComponent
  11. type EditingTitleComponentFunc func(obj interface{}, defaultTitle string, ctx *web.EventContext) h.HTMLComponent
  12. type FieldComponentFunc func(obj interface{}, field *FieldContext, ctx *web.EventContext) h.HTMLComponent
  13. type ActionComponentFunc func(id string, ctx *web.EventContext) h.HTMLComponent
  14. type ActionUpdateFunc func(id string, ctx *web.EventContext) (err error)
  15. type BulkActionComponentFunc func(selectedIds []string, ctx *web.EventContext) h.HTMLComponent
  16. type BulkActionUpdateFunc func(selectedIds []string, ctx *web.EventContext) (err error)
  17. type BulkActionSelectedIdsProcessorFunc func(selectedIds []string, ctx *web.EventContext) (processedSelectedIds []string, err error)
  18. type BulkActionSelectedIdsProcessorNoticeFunc func(selectedIds []string, processedSelectedIds []string, unactionableIds []string) string
  19. type MessagesFunc func(r *http.Request) *Messages
  20. // Data Layer
  21. type DataOperator interface {
  22. Search(obj interface{}, params *SearchParams, ctx *web.EventContext) (r interface{}, totalCount int, err error)
  23. // return ErrRecordNotFound if record not found
  24. Fetch(obj interface{}, id string, ctx *web.EventContext) (r interface{}, err error)
  25. Save(obj interface{}, id string, ctx *web.EventContext) (err error)
  26. Delete(obj interface{}, id string, ctx *web.EventContext) (err error)
  27. }
  28. type SetterFunc func(obj interface{}, ctx *web.EventContext)
  29. type FieldSetterFunc func(obj interface{}, field *FieldContext, ctx *web.EventContext) (err error)
  30. type ValidateFunc func(obj interface{}, ctx *web.EventContext) (err web.ValidationErrors)
  31. type SearchFunc func(model interface{}, params *SearchParams, ctx *web.EventContext) (r interface{}, totalCount int, err error)
  32. type FetchFunc func(obj interface{}, id string, ctx *web.EventContext) (r interface{}, err error)
  33. type SaveFunc func(obj interface{}, id string, ctx *web.EventContext) (err error)
  34. type DeleteFunc func(obj interface{}, id string, ctx *web.EventContext) (err error)
  35. type SQLCondition struct {
  36. Query string
  37. Args []interface{}
  38. }
  39. type SearchParams struct {
  40. KeywordColumns []string
  41. Keyword string
  42. SQLConditions []*SQLCondition
  43. PerPage int64
  44. Page int64
  45. OrderBy string
  46. PageURL *url.URL
  47. }
  48. type SlugDecoder interface {
  49. PrimaryColumnValuesBySlug(slug string) map[string]string
  50. }
  51. type SlugEncoder interface {
  52. PrimarySlug() string
  53. }
  54. type FilterDataFunc func(ctx *web.EventContext) vuetifyx.FilterData
  55. type FilterTab struct {
  56. ID string
  57. Label string
  58. // render AdvancedLabel if it is not nil
  59. AdvancedLabel h.HTMLComponent
  60. Query url.Values
  61. }
  62. type FilterTabsFunc func(ctx *web.EventContext) []*FilterTab