mirror of
https://github.com/go-gitea/gitea.git
synced 2026-05-09 01:17:43 +02:00
add methods for retrieving nesting depth and generating a left padding CSS value to Group struct
This commit is contained in:
parent
bc0c9e6aa6
commit
15446db55a
@ -178,6 +178,35 @@ func (g *Group) ShortName(length int) string {
|
||||
return util.EllipsisDisplayString(g.Name, length)
|
||||
}
|
||||
|
||||
// Depth retrieves the depth/nesting level of this group
|
||||
func (g *Group) Depth(ctx context.Context) (d int) {
|
||||
err := g.LoadParentGroup(ctx)
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
pg := g.ParentGroup
|
||||
for {
|
||||
if pg == nil {
|
||||
break
|
||||
}
|
||||
if pg.ParentGroup == nil {
|
||||
err = pg.LoadParentGroup(ctx)
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
d++
|
||||
pg = pg.ParentGroup
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// DisplayLeftMargin generates a value for the left margin
|
||||
// displayed on the frontend beside this group
|
||||
func (g *Group) DisplayLeftMargin(ctx context.Context) string {
|
||||
return fmt.Sprintf("%drem", g.Depth(ctx)+1)
|
||||
}
|
||||
|
||||
func GetGroupByID(ctx context.Context, id int64) (*Group, error) {
|
||||
group := new(Group)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user