-
Notifications
You must be signed in to change notification settings - Fork 0
/
view_data.go
66 lines (50 loc) · 1.05 KB
/
view_data.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
package goadmin
import (
"github.com/CloudyKit/jet/v6"
"github.com/partyzanex/go-admin-bootstrap/widgets"
)
type ViewData interface {
JetVars() jet.VarMap
JetData() map[string]interface{}
}
type Data struct {
jet.VarMap
Title string
User *User
Breadcrumbs widgets.Breadcrumbs
}
func (data *Data) JetVars() jet.VarMap {
if data.VarMap == nil {
data.VarMap = make(jet.VarMap)
}
data.Set("scripts", JS)
data.Set("styles", CSS)
data.Set("title", data.Title)
return data.VarMap
}
func (data *Data) JetData() map[string]interface{} {
result := map[string]interface{}{}
if data.User != nil {
result["User"] = data.User
}
if data.Breadcrumbs != nil {
result["Breadcrumbs"] = data.Breadcrumbs
}
return result
}
func (data *Data) Set(name string, value interface{}) {
if data.VarMap == nil {
data.VarMap = make(jet.VarMap)
}
data.VarMap.Set(name, value)
}
func (data Data) Has(key string) bool {
if data.VarMap == nil {
return false
}
v, ok := data.VarMap[key]
if !ok || v.IsNil() {
return false
}
return true
}