forked from GoAdminGroup/go-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
progressbar.go
48 lines (43 loc) · 1.22 KB
/
progressbar.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 (
"fmt"
"html/template"
"strconv"
"github.com/nneesshh/go-admin/template/types"
)
type ProgressBar struct {
types.BaseDisplayFnGenerator
}
func init() {
types.RegisterDisplayFnGenerator("progressbar", new(ProgressBar))
}
func (p *ProgressBar) Get(args ...interface{}) types.FieldFilterFn {
return func(value types.FieldModel) interface{} {
param := args[0].([]types.FieldProgressBarData)
style := "primary"
size := "sm"
max := 100
if len(param) > 0 {
if param[0].Style != "" {
style = param[0].Style
}
if param[0].Size != "" {
size = param[0].Size
}
if param[0].Max != 0 {
max = param[0].Max
}
}
base, _ := strconv.Atoi(value.Value)
per := fmt.Sprintf("%.0f", float32(base)/float32(max)*100)
return template.HTML(`
<div class="row" style="min-width: 100px;">
<span class="col-sm-3" style="color:#777;width: 60px">` + per + `%</span>
<div class="progress progress-` + size + ` col-sm-9" style="padding-left: 0;width: 100px;margin-left: -13px;">
<div class="progress-bar progress-bar-` + style + `" role="progressbar" aria-valuenow="1"
aria-valuemin="0" aria-valuemax="` + strconv.Itoa(max) + `" style="width: ` + per + `%">
</div>
</div>
</div>`)
}
}