-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtabs.go
68 lines (59 loc) · 1.5 KB
/
tabs.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
package summer
import (
"sort"
)
type (
tab struct {
Order int
Title string
Link string
Active bool
}
tabs []*tab
)
func (slice tabs) Len() int {
return len(slice)
}
func (slice tabs) Less(i, j int) bool {
if slice[i].Order != slice[j].Order {
return slice[i].Order < slice[j].Order
}
return slice[i].Title < slice[j].Title
}
func (slice tabs) Swap(i, j int) {
slice[i], slice[j] = slice[j], slice[i]
}
func getTabs(panel *Panel, name string, u *UsersStruct) interface{} {
tabsList := tabs{}
current, ex := panel.Modules.Get(name)
if !ex {
return obj{"title": name, "icon": "", "list": tabsList}
}
parent := current
if current.GetSettings().GroupTo != nil {
parent = current.GetSettings().GroupTo
}
if checkRights(panel, parent.GetSettings().Rights, u.Rights) {
for _, module := range panel.Modules.GetList() {
sett := module.GetSettings()
if sett.GroupTo == parent && checkRights(panel, sett.Rights, u.Rights) {
tabsList = append(tabsList, &tab{
Order: sett.MenuOrder,
Title: sett.GroupTitle,
Link: "/" + sett.PageRouteName + "/",
Active: module == current,
})
}
}
}
sort.Sort(tabsList)
if len(tabsList) > 0 {
tabsList = append(tabs{&tab{
Order: parent.GetSettings().MenuOrder,
Title: parent.GetSettings().GroupTitle,
Link: "/" + parent.GetSettings().PageRouteName + "/",
Active: parent == current,
}}, tabsList...)
}
return obj{"title": parent.GetSettings().Title, "icon": parent.GetSettings().Icon, "list": tabsList}
}