-
Notifications
You must be signed in to change notification settings - Fork 34
/
charts.go
133 lines (120 loc) · 3.08 KB
/
charts.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package board
import (
"github.com/TeaWeb/code/teaconfigs"
"github.com/TeaWeb/code/teaconfigs/widgets"
"github.com/TeaWeb/code/teastats"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/lists"
"github.com/iwind/TeaGo/maps"
)
type ChartsAction actions.Action
// 图表
func (this *ChartsAction) Run(params struct {
ServerId string
BoardType string
}) {
if len(params.BoardType) == 0 {
params.BoardType = "realtime"
}
this.Data["boardType"] = params.BoardType
server := teaconfigs.NewServerConfigFromId(params.ServerId)
if server == nil {
this.Fail("找不到Server")
}
this.Data["server"] = maps.Map{
"id": server.Id,
}
// 正在使用的图表
usingCharts := []maps.Map{}
if params.BoardType == "realtime" {
if server.RealtimeBoard != nil {
for _, c := range server.RealtimeBoard.Charts {
widget, chart := c.FindChart()
if chart == nil {
continue
}
usingCharts = append(usingCharts, maps.Map{
"id": chart.Id,
"name": chart.Name,
"description": chart.Description,
"requirements": chart.Requirements,
"columns": chart.Columns,
"on": chart.On,
"widget": maps.Map{
"id": widget.Id,
"author": widget.Author,
"version": widget.Version,
},
})
}
}
} else {
if server.StatBoard != nil {
for _, c := range server.StatBoard.Charts {
widget, chart := c.FindChart()
if chart == nil {
continue
}
usingCharts = append(usingCharts, maps.Map{
"id": chart.Id,
"name": chart.Name,
"description": chart.Description,
"requirements": chart.Requirements,
"columns": chart.Columns,
"on": chart.On,
"widget": maps.Map{
"id": widget.Id,
"author": widget.Author,
"version": widget.Version,
},
})
}
}
}
this.Data["usingCharts"] = usingCharts
// 所有的图表
this.Data["widgets"] = lists.Map(widgets.LoadAllWidgets(), func(k int, v interface{}) interface{} {
widget := v.(*widgets.Widget)
return maps.Map{
"id": widget.Id,
"charts": lists.Map(widget.Charts, func(k int, v interface{}) interface{} {
chart := v.(*widgets.Chart)
isUsing := false
if params.BoardType == "realtime" {
if server.RealtimeBoard != nil {
isUsing = server.RealtimeBoard.HasChart(chart.Id)
}
} else {
if server.StatBoard != nil {
isUsing = server.StatBoard.HasChart(chart.Id)
}
}
items := []maps.Map{}
for _, r := range chart.Requirements {
filter := teastats.FindFilter(r)
if filter != nil {
items = append(items, maps.Map{
"name": filter.Name(),
"code": r,
})
}
}
return maps.Map{
"id": chart.Id,
"name": chart.Name,
"description": chart.Description,
"items": items,
"columns": chart.Columns,
"on": chart.On,
"isUsing": isUsing,
"widget": maps.Map{
"id": widget.Id,
"author": widget.Author,
"version": widget.Version,
},
}
}),
}
})
this.Show()
}