Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Summary report email layout #676

Merged
merged 16 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ public class SendNotificationsRequest
{
[JsonProperty("emailPriority")] public int EmailPriority { get; set; }

[JsonProperty("title")] public string Title { get; set; }
[JsonProperty("title")] public string? Title { get; set; }

[JsonProperty("description")] public string Description { get; set; }
[JsonProperty("description")] public string? Description { get; set; }

[JsonProperty("card")] public AdaptiveCard Card { get; set; }
[JsonProperty("appKey")] public string? AppKey { get; set; }

[JsonProperty("card")] public AdaptiveCard? Card { get; set; }
}
150 changes: 55 additions & 95 deletions src/Fusion.Summary.Functions/CardBuilder/AdaptiveCardBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Fusion.Summary.Functions.CardBuilder;

public class AdaptiveCardBuilder
{
private readonly AdaptiveCard _adaptiveCard = new(new AdaptiveSchemaVersion(1, 0));
private readonly AdaptiveCard _adaptiveCard = new(new AdaptiveSchemaVersion(1, 2));

public AdaptiveCardBuilder AddHeading(string text)
{
Expand All @@ -24,14 +24,30 @@ public AdaptiveCardBuilder AddHeading(string text)
return this;
}

public AdaptiveCardBuilder AddColumnSet(params AdaptiveCardColumn[] columns)
public AdaptiveCardBuilder AddTextRow(string valueText, string headerText, string customText = "")
{
var columnSet = new AdaptiveColumnSet
var container = new AdaptiveContainer()
{
Columns = columns.Select(col => col.Column).ToList(),
Separator = true
Separator = true,
Items = new List<AdaptiveElement>()
{
new AdaptiveTextBlock
{
Text = $"{valueText} {customText}",
Wrap = true,
HorizontalAlignment = AdaptiveHorizontalAlignment.Center,
Size = AdaptiveTextSize.ExtraLarge
},
new AdaptiveTextBlock
{
Text = headerText,
Wrap = true,
HorizontalAlignment = AdaptiveHorizontalAlignment.Center
}
}
};
_adaptiveCard.Body.Add(columnSet);

_adaptiveCard.Body.Add(container);
return this;
}

Expand All @@ -41,31 +57,45 @@ public AdaptiveCardBuilder AddListContainer(string headerText,
var listContainer = new AdaptiveContainer
{
Separator = true,
Items = new List<AdaptiveElement>
};

var header = new AdaptiveTextBlock
{
Weight = AdaptiveTextWeight.Bolder,
Text = headerText,
Wrap = true,
Size = AdaptiveTextSize.Large,
HorizontalAlignment = AdaptiveHorizontalAlignment.Center
};

var rows = new List<AdaptiveColumnSet>();

foreach (var listObject in objectLists)
{
var row = new AdaptiveColumnSet()
{
new AdaptiveTextBlock
Columns = listObject.Select(o => new AdaptiveColumn()
{
Weight = AdaptiveTextWeight.Bolder,
Text = headerText,
Wrap = true,
Size = AdaptiveTextSize.Large
},
new AdaptiveColumnSet
{
Columns = new List<AdaptiveColumn>
Width = AdaptiveColumnWidth.Stretch,
Items = new List<AdaptiveElement>
{
new()
new AdaptiveTextBlock
{
Width = AdaptiveColumnWidth.Stretch,
Items = new List<AdaptiveElement>
{
new AdaptiveCardList(objectLists).List
}
Text = o.Value,
Wrap = true,
HorizontalAlignment = o.Alignment
}
}
}
}
};
}).ToList()
};

rows.Add(row);
}

listContainer.Items.Add(header);
listContainer.Items.AddRange(rows);


_adaptiveCard.Body.Add(listContainer);
return this;
}
Expand Down Expand Up @@ -100,76 +130,6 @@ public AdaptiveCard Build()
return _adaptiveCard;
}

public class AdaptiveCardColumn
{
public AdaptiveColumn Column { get; }

public AdaptiveCardColumn(string numberText, string headerText, string customText = "")
{
Column = new AdaptiveColumn
{
Width = AdaptiveColumnWidth.Stretch,
Separator = true,
Spacing = AdaptiveSpacing.Medium,
Items = new List<AdaptiveElement>
{
new AdaptiveTextBlock
{
Text = $"{numberText} {customText}",
Wrap = true,
HorizontalAlignment = AdaptiveHorizontalAlignment.Center,
Size = AdaptiveTextSize.ExtraLarge
},
new AdaptiveTextBlock
{
Text = headerText,
Wrap = true,
HorizontalAlignment = AdaptiveHorizontalAlignment.Center
}
}
};
}
}

private class AdaptiveCardList
{
public AdaptiveContainer List { get; }

public AdaptiveCardList(List<List<ListObject>> objectLists)
{
var listItems = new List<AdaptiveElement>();
foreach (var objects in objectLists)
{
var columns = new List<AdaptiveColumn>();
foreach (var o in objects)
{
var column = new AdaptiveColumn()
{
Width = AdaptiveColumnWidth.Stretch,
Items = new List<AdaptiveElement>
{
new AdaptiveTextBlock
{
Text = $"{o.Value} ", Wrap = true,
HorizontalAlignment = o.Alignment
}
}
};
columns.Add(column);
}

listItems.Add(new AdaptiveColumnSet()
{
Columns = columns
});
}

List = new AdaptiveContainer
{
Items = listItems
};
}
}

public class ListObject
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,37 +127,36 @@ private SendNotificationsRequest CreateNotification(ApiWeeklySummaryReport repor

var card = new AdaptiveCardBuilder()
.AddHeading($"**Weekly summary - {department.FullDepartmentName}**")
.AddColumnSet(new AdaptiveCardColumn(
.AddTextRow(
report.NumberOfPersonnel,
"Number of personnel (employees and external hire)"))
.AddColumnSet(new AdaptiveCardColumn(
"Number of personnel (employees and external hire)")
.AddTextRow(
report.CapacityInUse,
"Capacity in use",
"%"))
.AddColumnSet(
new AdaptiveCardColumn(
"%")
.AddTextRow(
report.NumberOfRequestsLastPeriod,
"New requests last week"))
.AddColumnSet(new AdaptiveCardColumn(
"New requests last week")
.AddTextRow(
report.NumberOfOpenRequests,
"Open requests"))
.AddColumnSet(new AdaptiveCardColumn(
"Open requests")
.AddTextRow(
report.NumberOfRequestsStartingInLessThanThreeMonths,
"Requests with start date < 3 months"))
.AddColumnSet(new AdaptiveCardColumn(
"Requests with start date < 3 months")
.AddTextRow(
report.NumberOfRequestsStartingInMoreThanThreeMonths,
"Requests with start date > 3 months"))
.AddColumnSet(new AdaptiveCardColumn(
"Requests with start date > 3 months")
.AddTextRow(
averageTimeToHandleRequests > 0
? averageTimeToHandleRequests + " day(s)"
: "Less than a day",
"Average time to handle request (last 12 months)"))
.AddColumnSet(new AdaptiveCardColumn(
"Average time to handle request (last 12 months)")
.AddTextRow(
report.AllocationChangesAwaitingTaskOwnerAction,
"Allocation changes awaiting task owner action"))
.AddColumnSet(new AdaptiveCardColumn(
"Allocation changes awaiting task owner action")
.AddTextRow(
report.ProjectChangesAffectingNextThreeMonths,
"Project changes last week affecting next 3 months"))
"Project changes last week affecting next 3 months")
.AddListContainer("Allocations ending soon with no future allocation:", endingPositionsObjectList)
.AddListContainer("Personnel with more than 100% workload:", personnelMoreThan100PercentObjectList)
.AddNewLine()
Expand All @@ -170,6 +169,7 @@ private SendNotificationsRequest CreateNotification(ApiWeeklySummaryReport repor
Title = $"Weekly summary - {department.FullDepartmentName}",
EmailPriority = 1,
Card = card,
AppKey = "personnel-allocation",
Description = $"Weekly report for department - {department.FullDepartmentName}"
};
}
Expand Down
Loading
Loading