-
Notifications
You must be signed in to change notification settings - Fork 335
/
template.go
84 lines (66 loc) · 2.34 KB
/
template.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
package types
import (
"database/sql/driver"
"encoding/json"
"time"
"github.com/cortezaproject/corteza/server/pkg/sql"
"github.com/cortezaproject/corteza/server/pkg/filter"
)
type (
DocumentType string
Template struct {
ID uint64 `json:"templateID,string"`
Handle string `json:"handle"`
// Language specifies the language the template is written for; leave empty for default
Language string `json:"language"`
Type DocumentType `json:"type"`
// Partial templates can be used to construct larger templates; for example headers and footers
Partial bool `json:"partial"`
// use int so JS can handle it normally
//
// @todo We'll handle this at a later point
// Revision int `json:"revision,string"`
Meta TemplateMeta `json:"meta"`
Template string `json:"template"`
Labels map[string]string `json:"labels,omitempty"`
OwnerID uint64 `json:"ownerID,string"`
CreatedAt time.Time `json:"createdAt,omitempty"`
UpdatedAt *time.Time `json:"updatedAt,omitempty"`
DeletedAt *time.Time `json:"deletedAt,omitempty"`
LastUsedAt *time.Time `json:"lastUsedAt,omitempty"`
}
TemplateMeta struct {
Short string `json:"short"`
Description string `json:"description,omitempty"`
}
TemplateFilter struct {
TemplateID []string `json:"templateID"`
Query string `json:"query"`
Handle string `json:"handle"`
Type string `json:"type"`
OwnerID uint64 `json:"ownerID,string"`
Partial bool `json:"partial"`
LabeledIDs []uint64 `json:"-"`
Labels map[string]string `json:"labels,omitempty"`
// Check fn is called by store backend for each resource found function can
// modify the resource and return false if store should not return it
//
// Store then loads additional resources to satisfy the paging parameters
Check func(*Template) (bool, error) `json:"-"`
Deleted filter.State `json:"deleted"`
// Standard helpers for paging and sorting
filter.Sorting
filter.Paging
}
)
const (
DocumentTypePlain DocumentType = "text/plain"
DocumentTypeHTML DocumentType = "text/html"
DocumentTypePDF DocumentType = "application/pdf"
)
func (t *TemplateMeta) Scan(src any) error { return sql.ParseJSON(src, t) }
func (t TemplateMeta) Value() (driver.Value, error) { return json.Marshal(t) }
func (t Template) Clone() *Template {
c := &t
return c
}