MCPcopy Index your code
hub / github.com/APIParkLab/APIPark / NewRoot

Function NewRoot

module/catalogue/tree.go:48–83  ·  view source on GitHub ↗
(list []*catalogue.Catalogue)

Source from the content-addressed store, hash-verified

46 return nil
47}
48func NewRoot(list []*catalogue.Catalogue) *Root {
49 m := make(map[string]*Group)
50 l := make([]*Group, 0, len(list))
51 for _, i := range list {
52 g := &Group{
53 Uuid: i.Id,
54 Parent: i.Parent,
55 Name: i.Name,
56 Depth: 0,
57 children: nil,
58 sort: i.Sort,
59 }
60 l = append(l, g)
61 m[g.Uuid] = g
62 }
63 parentMap := make(map[string][]string)
64 root := new(Group)
65 for _, i := range l {
66 if i.Parent != "" {
67 p, has := m[i.Parent]
68 if !has {
69 i.Parent = ""
70 root.children = append(root.children, i)
71 } else {
72 p.children = append(p.children, i)
73 p.parents = getParents(i.Parent, m, parentMap)
74 }
75
76 } else {
77 root.children = append(root.children, i)
78 }
79 }
80 root.ResetDepth(-1)
81 sort.Sort(Groups(l))
82 return &Root{nodes: m, list: l}
83}
84
85func getParents(parentID string, nodeMap map[string]*Group, parentMap map[string][]string) []string {
86 if parentID == "" {

Callers 5

SortMethod · 0.85
SearchMethod · 0.85
CreateMethod · 0.85
EditMethod · 0.85
DeleteMethod · 0.85

Calls 4

getParentsFunction · 0.85
GroupsTypeAlias · 0.85
ResetDepthMethod · 0.80
SortMethod · 0.65

Tested by

no test coverage detected