forked from qor/admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
meta_configors.go
109 lines (96 loc) · 2.7 KB
/
meta_configors.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package admin
import (
"errors"
"github.com/qor/qor"
)
// metaConfig meta config
type metaConfig struct {
}
// GetTemplate get customized template for meta
func (metaConfig) GetTemplate(context *Context, metaType string) ([]byte, error) {
return nil, errors.New("not implemented")
}
var defaultMetaConfigorMaps = map[string]func(*Meta){
"date": func(meta *Meta) {
if _, ok := meta.Config.(*DatetimeConfig); !ok || meta.Config == nil {
meta.Config = &DatetimeConfig{}
meta.Config.ConfigureQorMeta(meta)
}
},
"datetime": func(meta *Meta) {
if _, ok := meta.Config.(*DatetimeConfig); !ok || meta.Config == nil {
meta.Config = &DatetimeConfig{ShowTime: true}
meta.Config.ConfigureQorMeta(meta)
}
},
"string": func(meta *Meta) {
if meta.FormattedValuer == nil {
meta.SetFormattedValuer(func(value interface{}, context *qor.Context) interface{} {
switch str := meta.GetValuer()(value, context).(type) {
case *string:
if str != nil {
return *str
}
return ""
case string:
return str
default:
return str
}
})
}
},
"text": func(meta *Meta) {
if meta.FormattedValuer == nil {
meta.SetFormattedValuer(func(value interface{}, context *qor.Context) interface{} {
switch str := meta.GetValuer()(value, context).(type) {
case *string:
if str != nil {
return *str
}
return ""
case string:
return str
default:
return str
}
})
}
},
"select_one": func(meta *Meta) {
if metaConfig, ok := meta.Config.(*SelectOneConfig); !ok || metaConfig == nil {
meta.Config = &SelectOneConfig{Collection: meta.Collection}
meta.Config.ConfigureQorMeta(meta)
} else if meta.Collection != nil {
metaConfig.Collection = meta.Collection
meta.Config.ConfigureQorMeta(meta)
}
},
"select_many": func(meta *Meta) {
if metaConfig, ok := meta.Config.(*SelectManyConfig); !ok || metaConfig == nil {
meta.Config = &SelectManyConfig{Collection: meta.Collection}
meta.Config.ConfigureQorMeta(meta)
} else if meta.Collection != nil {
metaConfig.Collection = meta.Collection
meta.Config.ConfigureQorMeta(meta)
}
},
"single_edit": func(meta *Meta) {
if _, ok := meta.Config.(*SingleEditConfig); !ok || meta.Config == nil {
meta.Config = &SingleEditConfig{}
meta.Config.ConfigureQorMeta(meta)
}
},
"collection_edit": func(meta *Meta) {
if _, ok := meta.Config.(*CollectionEditConfig); !ok || meta.Config == nil {
meta.Config = &CollectionEditConfig{}
meta.Config.ConfigureQorMeta(meta)
}
},
"rich_editor": func(meta *Meta) {
if _, ok := meta.Config.(*RichEditorConfig); !ok || meta.Config == nil {
meta.Config = &RichEditorConfig{}
meta.Config.ConfigureQorMeta(meta)
}
},
}