forked from GoAdminGroup/go-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dot.go
40 lines (35 loc) · 1 KB
/
dot.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
package display
import (
"html/template"
"github.com/kotovmak/go-admin/template/types"
)
type Dot struct {
types.BaseDisplayFnGenerator
}
func init() {
types.RegisterDisplayFnGenerator("dot", new(Dot))
}
func (d *Dot) Get(args ...interface{}) types.FieldFilterFn {
return func(value types.FieldModel) interface{} {
icons := args[0].(map[string]types.FieldDotColor)
defaultDot := types.FieldDotColor("")
if len(args) > 1 {
defaultDot = args[1].(types.FieldDotColor)
}
for k, style := range icons {
if k == value.Value {
return template.HTML(`<span class="label-`+style+`"
style="width: 8px;height: 8px;padding: 0;border-radius: 50%;display: inline-block;">
</span> `) +
template.HTML(value.Value)
}
}
if defaultDot != "" {
return template.HTML(`<span class="label-`+defaultDot+`"
style="width: 8px;height: 8px;padding: 0;border-radius: 50%;display: inline-block;">
</span> `) +
template.HTML(value.Value)
}
return value.Value
}
}