From 15446db55ac24143c643cea00c52680c4f3be3a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=98=99=E2=97=A6=20The=20Tablet=20=E2=9D=80=20GamerGirla?= =?UTF-8?q?ndCo=20=E2=97=A6=E2=9D=A7?= Date: Sat, 16 Aug 2025 15:48:19 -0400 Subject: [PATCH] add methods for retrieving nesting depth and generating a left padding CSS value to `Group` struct --- models/group/group.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/models/group/group.go b/models/group/group.go index d2c9f19fe0..1cc114409d 100644 --- a/models/group/group.go +++ b/models/group/group.go @@ -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)