forked from GoAdminGroup/go-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bool.go
48 lines (43 loc) · 961 Bytes
/
bool.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
package display
import (
"strings"
"github.com/GoAdminGroup/html"
"github.com/romutchio/go-admin/template/icon"
"github.com/romutchio/go-admin/template/types"
)
type Bool struct {
types.BaseDisplayFnGenerator
}
func init() {
types.RegisterDisplayFnGenerator("bool", new(Bool))
}
func (b *Bool) Get(args ...interface{}) types.FieldFilterFn {
return func(value types.FieldModel) interface{} {
params := args[0].([]string)
pass := icon.IconWithStyle(icon.Check, html.Style{
"color": "green",
})
fail := icon.IconWithStyle(icon.Remove, html.Style{
"color": "red",
})
if len(params) == 0 {
if value.Value == "0" || strings.ToLower(value.Value) == "false" {
return fail
}
return pass
} else if len(params) == 1 {
if value.Value == params[0] {
return pass
}
return fail
} else {
if value.Value == params[0] {
return pass
}
if value.Value == params[1] {
return fail
}
}
return ""
}
}