-
Notifications
You must be signed in to change notification settings - Fork 0
/
sourcemenu.go
65 lines (52 loc) · 1.59 KB
/
sourcemenu.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
package workspace
import (
"fmt"
"path/filepath"
"admini.dev/admini/app/lib/menu"
"admini.dev/admini/app/lib/schema/model"
"admini.dev/admini/app/util"
)
var menuItemBack = &menu.Item{Key: "_back", Title: "Back to " + util.AppName, Description: "Return to " + util.AppName, Icon: "backward", Route: "/"}
func SourceMenuPackage(mp *model.Package, path string) menu.Items {
ret := menu.Items{}
for _, m := range mp.ChildModels {
ret = sourceMenuAddModel(ret, m, path)
}
for _, p := range mp.ChildPackages {
ret = sourceMenuAddPackage(ret, p, path)
}
return ret
}
func SourceMenuModel(m *model.Model, path string) *menu.Item {
return &menu.Item{
Key: m.Key,
Title: m.Name(),
Icon: m.Type.Icon,
Description: m.Description(),
Route: path,
}
}
func sourceMenuAddModel(ret menu.Items, m *model.Model, path string) menu.Items {
return append(ret, SourceMenuModel(m, filepath.Join(path, m.Key)))
}
func sourceMenuAddPackage(ret menu.Items, mp *model.Package, path string) menu.Items {
path = filepath.Join(path, mp.Key)
desc := fmt.Sprintf("package [%s], containing [%d] models", mp.Key, len(mp.ChildModels))
if len(mp.ChildPackages) > 0 {
desc += fmt.Sprintf(" and [%d] packages", len(mp.ChildPackages))
}
i := &menu.Item{
Key: mp.Key,
Title: mp.Name(),
Icon: "world",
Description: desc,
Route: path,
}
for _, m := range mp.ChildModels {
i.Children = sourceMenuAddModel(i.Children, m, path)
}
for _, p := range mp.ChildPackages {
i.Children = sourceMenuAddPackage(i.Children, p, path)
}
return append(ret, i)
}