add methods for retrieving nesting depth and generating a left padding CSS value to Group struct

This commit is contained in:
☙◦ The Tablet ❀ GamerGirlandCo ◦❧
2026-04-02 20:31:56 -04:00
parent bc0c9e6aa6
commit 15446db55a
+29
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)