diff --git a/src/Fusion.Summary.Functions/CardBuilder/AdaptiveCardBuilder.cs b/src/Fusion.Summary.Functions/CardBuilder/AdaptiveCardBuilder.cs index ef8079bf8..5f8244daa 100644 --- a/src/Fusion.Summary.Functions/CardBuilder/AdaptiveCardBuilder.cs +++ b/src/Fusion.Summary.Functions/CardBuilder/AdaptiveCardBuilder.cs @@ -65,7 +65,7 @@ public AdaptiveCardBuilder AddTextRow(string valueText, string headerText, strin } - public AdaptiveCardBuilder AddGrid(string headerText, string subtitleText, IEnumerable columnsEnumerable, GoToAction? goToAction = null) + public AdaptiveCardBuilder AddGrid(string headerText, string subtitleText, IEnumerable columnsEnumerable, GoToAction? goToAction = null, int? maxItems = 10) { var columns = columnsEnumerable.ToList(); var listContainer = new AdaptiveContainer @@ -91,13 +91,23 @@ public AdaptiveCardBuilder AddGrid(string headerText, string subtitleText, IEnum var grid = new AdaptiveColumnSet(); + var maxItemsReached = false; + var totalRows = columns.FirstOrDefault()?.Cells.Count(c => !c.IsHeader) ?? 0; foreach (var column in columns) { + maxItemsReached = false; + var cellCount = 0; var rows = new List(); foreach (var gridCell in column.Cells) { + if (maxItems.HasValue && cellCount >= maxItems) + { + maxItemsReached = true; + break; + } + var cell = new AdaptiveTextBlock { Text = gridCell.Value, @@ -108,6 +118,8 @@ public AdaptiveCardBuilder AddGrid(string headerText, string subtitleText, IEnum }; rows.Add(cell); + if (!gridCell.IsHeader) + cellCount++; } var gridColumn = new AdaptiveColumn @@ -175,6 +187,16 @@ public AdaptiveCardBuilder AddGrid(string headerText, string subtitleText, IEnum }); } + if (maxItemsReached && maxItems.HasValue) + { + listContainer.Items.Add(new AdaptiveTextBlock + { + Text = $"And {totalRows - maxItems} more...", + Wrap = true, + HorizontalAlignment = AdaptiveHorizontalAlignment.Center + }); + } + _adaptiveCard.Body.Add(listContainer); return this; diff --git a/src/Fusion.Summary.Functions/Functions/TaskOwnerReports/WeeklyTaskOwnerReportSender.cs b/src/Fusion.Summary.Functions/Functions/TaskOwnerReports/WeeklyTaskOwnerReportSender.cs index 948918944..91600d900 100644 --- a/src/Fusion.Summary.Functions/Functions/TaskOwnerReports/WeeklyTaskOwnerReportSender.cs +++ b/src/Fusion.Summary.Functions/Functions/TaskOwnerReports/WeeklyTaskOwnerReportSender.cs @@ -250,87 +250,90 @@ private SendEmailWithTemplateRequest CreateReportMail(string[] recipients, Proje Title = "Go to open requests", Url = $"{fusionUri}/apps/org-admin/{contextId}/open-requests?filter=awaiting-task-owner" }) - .AddGrid("Admin access expiring in less than 3 months", "(Consider extending the access in Access control management)", new List() - { - new() + .AddGrid($"Admin access expiring in less than 3 months", + "(Consider extending the access in Access control management)", new List() { - Width = AdaptiveColumnWidth.Stretch, - Cells = - [ - new GridCell(isHeader: true, value: "Name"), - ..report.AdminAccessExpiringInLessThanThreeMonths.Select(a - => new GridCell(isHeader: false, value: a.FullName)) - ] - }, - new() + new() + { + Width = AdaptiveColumnWidth.Stretch, + Cells = + [ + new GridCell(isHeader: true, value: "Name"), + ..report.AdminAccessExpiringInLessThanThreeMonths.Select(a + => new GridCell(isHeader: false, value: a.FullName)) + ] + }, + new() + { + Width = AdaptiveColumnWidth.Auto, + Cells = + [ + new GridCell(isHeader: true, value: "Expires"), + ..report.AdminAccessExpiringInLessThanThreeMonths.Select(a + => new GridCell(isHeader: false, value: a.Expires.ToString("dd/MM/yyyy"))) + ] + } + }, new GoToAction() { - Width = AdaptiveColumnWidth.Auto, - Cells = - [ - new GridCell(isHeader: true, value: "Expires"), - ..report.AdminAccessExpiringInLessThanThreeMonths.Select(a - => new GridCell(isHeader: false, value: a.Expires.ToString("dd/MM/yyyy"))) - ] - } - }, new GoToAction() - { - Title = "Go to access control management", - Url = $"{fusionUri}/apps/org-admin/{contextId}/access-control" - }) - .AddGrid("Allocations expiring next 3 months", "(Contact the resource owner if there is a need to extend the allocation)", new List() - { - new() + Title = "Go to access control management", + Url = $"{fusionUri}/apps/org-admin/{contextId}/access-control" + }) + .AddGrid($"Allocations expiring next 3 months", + "(Contact the resource owner if there is a need to extend the allocation)", new List() { - Width = AdaptiveColumnWidth.Stretch, - Cells = - [ - new GridCell(isHeader: true, value: "Position"), - ..report.PositionAllocationsEndingInNextThreeMonths.Select(p - => new GridCell(isHeader: false, value: $"{p.PositionExternalId} {p.PositionNameDetailed}")) - ] - }, - new() + new() + { + Width = AdaptiveColumnWidth.Stretch, + Cells = + [ + new GridCell(isHeader: true, value: "Position"), + ..report.PositionAllocationsEndingInNextThreeMonths.Select(p + => new GridCell(isHeader: false, value: $"{p.PositionExternalId} {p.PositionNameDetailed}")) + ] + }, + new() + { + Width = AdaptiveColumnWidth.Auto, + Cells = + [ + new GridCell(isHeader: true, value: "End date"), + ..report.PositionAllocationsEndingInNextThreeMonths.Select(p + => new GridCell(isHeader: false, value: p.PositionAppliesTo.ToString("dd/MM/yyyy"))) + ] + } + }, new GoToAction() { - Width = AdaptiveColumnWidth.Auto, - Cells = - [ - new GridCell(isHeader: true, value: "End date"), - ..report.PositionAllocationsEndingInNextThreeMonths.Select(p - => new GridCell(isHeader: false, value: p.PositionAppliesTo.ToString("dd/MM/yyyy"))) - ] - } - }, new GoToAction() - { - Title = "Go to positions listing view", - Url = $"{fusionUri}/apps/org-admin/{contextId}/edit-positions/listing-view?filter=allocations-exp-3m" - }) - .AddGrid("TBN positions with start date next 3 months", "(Please create a resource request or update the position start-date)", new List() - { - new() + Title = "Go to positions listing view", + Url = $"{fusionUri}/apps/org-admin/{contextId}/edit-positions/listing-view?filter=allocations-exp-3m" + }) + .AddGrid($"TBN positions with start date next 3 months", + "(Please create a resource request or update the position start-date)", new List() { - Width = AdaptiveColumnWidth.Stretch, - Cells = - [ - new GridCell(isHeader: true, value: "Position"), - ..report.TBNPositionsStartingInLessThanThreeMonths.Select(p - => new GridCell(isHeader: false, value: $"{p.PositionExternalId} {p.PositionNameDetailed}")) - ] - }, - new() + new() + { + Width = AdaptiveColumnWidth.Stretch, + Cells = + [ + new GridCell(isHeader: true, value: "Position"), + ..report.TBNPositionsStartingInLessThanThreeMonths.Select(p + => new GridCell(isHeader: false, value: $"{p.PositionExternalId} {p.PositionNameDetailed}")) + ] + }, + new() + { + Width = AdaptiveColumnWidth.Auto, + Cells = + [ + new GridCell(isHeader: true, value: "Start date"), + ..report.TBNPositionsStartingInLessThanThreeMonths.Select(p + => new GridCell(isHeader: false, value: p.PositionAppliesFrom.ToString("dd/MM/yyyy"))) + ] + } + }, new GoToAction() { - Width = AdaptiveColumnWidth.Auto, - Cells = - [ - new GridCell(isHeader: true, value: "Start date"), - ..report.TBNPositionsStartingInLessThanThreeMonths.Select(p - => new GridCell(isHeader: false, value: p.PositionAppliesFrom.ToString("dd/MM/yyyy"))) - ] - } - }, new GoToAction() - { - Title = "Go to positions timeline view", - Url = $"{fusionUri}/apps/org-admin/{contextId}/edit-positions/timeline-view?filter=tbn-pos-3m" - }) + Title = "Go to positions timeline view", + Url = $"{fusionUri}/apps/org-admin/{contextId}/edit-positions/timeline-view?filter=tbn-pos-3m" + }) .Build(); var subject = $"Weekly summary - {project.Name}";