| 1 | using AgentForge.Data.Entities; |
| 2 | using AgentForge.Plugin.View; |
| 3 | using AgentForge.Plugin.View.Components.Layout; |
| 4 | |
| 5 | namespace AgentForge.Plugin.Org.Web.Components; |
| 6 | |
| 7 | internal static class ForgeViewOrgGroupNode |
| 8 | { |
| 9 | internal static string Render(ForgeRepoGroupEntity group, in ForgeViewOrgCatalogContext context) |
| 10 | { |
| 11 | var path = context.ResolvePath(group); |
| 12 | context.Index.ReposByGroupPath.TryGetValue(path, out var groupRepos); |
| 13 | groupRepos ??= []; |
| 14 | |
| 15 | var childGroups = context.Index.ChildrenByParentId.GetValueOrDefault(group.Id) ?? []; |
| 16 | var repoCount = context.Index.RepoCountByGroupPath.GetValueOrDefault(path, groupRepos.Count); |
| 17 | var head = ForgeViewOrgGroupHead.Render( |
| 18 | context, |
| 19 | group, |
| 20 | path, |
| 21 | repoCount, |
| 22 | childGroups.Count, |
| 23 | context.IsActive(path)); |
| 24 | |
| 25 | var childNodes = new List<string>(); |
| 26 | foreach (var child in childGroups) |
| 27 | childNodes.Add(Render(child, context)); |
| 28 | |
| 29 | ForgeViewOrgRepoList.AddRepoNodes(childNodes, groupRepos, context.Grouping, context.GroupingContext); |
| 30 | |
| 31 | if (childNodes.Count == 0) |
| 32 | childNodes.Add(ForgeHtml.Li("meta", ForgeHtml.Text("empty"))); |
| 33 | |
| 34 | var body = ForgeHtml.Ul("plain org-repo-tree-children", [.. childNodes]); |
| 35 | var details = ForgeViewDisclosure.Render( |
| 36 | head.SummaryInner, |
| 37 | body, |
| 38 | context.ShouldExpand(path), |
| 39 | "org-group-details", |
| 40 | head.SummaryCssClass); |
| 41 | |
| 42 | return ForgeHtml.Li(null, details); |
| 43 | } |
| 44 | } |
| 45 | |