0
0
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:
☙◦ The Tablet ❀ GamerGirlandCo ◦❧ 2025-08-16 15:48:19 -04:00
parent bc0c9e6aa6
commit 15446db55a
No known key found for this signature in database
GPG Key ID: 924A5F6AF051E87C

View File

@ -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)