-
Notifications
You must be signed in to change notification settings - Fork 34
/
board.go
75 lines (66 loc) · 1.39 KB
/
board.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
package teaconfigs
// 看板
type Board struct {
Charts []*BoardChart `yaml:"charts" json:"charts"`
}
// 获取新对象
func NewBoard() *Board {
return &Board{}
}
// 判断是否在使用某个Chart
func (this *Board) HasChart(chartId string) bool {
for _, c := range this.Charts {
if c.ChartId == chartId {
return true
}
}
return false
}
// 移除某个Chart
func (this *Board) RemoveChart(chartId string) {
result := []*BoardChart{}
for _, c := range this.Charts {
if c.ChartId == chartId {
continue
}
result = append(result, c)
}
this.Charts = result
}
// 添加Chart
func (this *Board) AddChart(widgetId string, chartId string) {
if this.HasChart(chartId) {
return
}
this.Charts = append(this.Charts, &BoardChart{
WidgetId: widgetId,
ChartId: chartId,
})
}
// 移动Chart
func (this *Board) MoveChart(fromIndex int, toIndex int) {
if fromIndex < 0 || fromIndex >= len(this.Charts) {
return
}
if toIndex < 0 || toIndex >= len(this.Charts) {
return
}
if fromIndex == toIndex {
return
}
chart := this.Charts[fromIndex]
newList := []*BoardChart{}
for i := 0; i < len(this.Charts); i ++ {
if i == fromIndex {
continue
}
if fromIndex > toIndex && i == toIndex {
newList = append(newList, chart)
}
newList = append(newList, this.Charts[i])
if fromIndex < toIndex && i == toIndex {
newList = append(newList, chart)
}
}
this.Charts = newList
}