feat: merge event rankings and attribute badges into the page printer
Interview notes can print each student's ranked events and a shared attribute legend from the same catalog as the ranking index, without leftover table markup or collapsed answer space. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -58,6 +58,8 @@ public class NotePrintService : INotePrintService
|
||||
query = query.Where(s => s.OfficerRole == null);
|
||||
|
||||
var students = await query
|
||||
.Include(s => s.EventRankings)
|
||||
.ThenInclude(r => r.EventDefinition)
|
||||
.OrderBy(s => s.LastName)
|
||||
.ThenBy(s => s.FirstName)
|
||||
.ToListAsync(cancellationToken);
|
||||
@@ -79,7 +81,8 @@ public class NotePrintService : INotePrintService
|
||||
template,
|
||||
row.Imported,
|
||||
StudentTokens(row.Student),
|
||||
chapter))
|
||||
chapter,
|
||||
StudentHtmlFragments(row.Student)))
|
||||
];
|
||||
}
|
||||
|
||||
@@ -140,9 +143,25 @@ public class NotePrintService : INotePrintService
|
||||
.OrderBy(e => e.Name)
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
var rankings = await _context.StudentEventRanking
|
||||
.AsNoTracking()
|
||||
.Include(r => r.Student)
|
||||
.Include(r => r.EventDefinition)
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
var rankingsByEventId = rankings
|
||||
.GroupBy(r => r.EventDefinition.Id)
|
||||
.ToDictionary(g => g.Key, g => g.ToList());
|
||||
|
||||
return
|
||||
[
|
||||
.. events.Select(evt => MergePage(evt.Name, template, null, EventTokens(evt), chapter))
|
||||
.. events.Select(evt => MergePage(
|
||||
evt.Name,
|
||||
template,
|
||||
null,
|
||||
EventTokens(evt),
|
||||
chapter,
|
||||
EventHtmlFragments(rankingsByEventId.GetValueOrDefault(evt.Id))))
|
||||
];
|
||||
}
|
||||
|
||||
@@ -151,16 +170,31 @@ public class NotePrintService : INotePrintService
|
||||
string template,
|
||||
Dictionary<string, string?>? imported,
|
||||
Dictionary<string, string?> entity,
|
||||
Dictionary<string, string?> chapter)
|
||||
Dictionary<string, string?> chapter,
|
||||
IReadOnlyDictionary<string, string>? htmlFragments = null)
|
||||
{
|
||||
var map = PrintTokenMap.Build(imported, entity, chapter);
|
||||
return new NotePrintPage
|
||||
{
|
||||
DisplayName = displayName,
|
||||
Html = NoteTemplateMerger.ApplyLayout(MarkdownHelper.ToHtml(NoteTemplateMerger.Merge(template, map)))
|
||||
Html = NoteTemplateMerger.ApplyLayout(
|
||||
MarkdownHelper.ToHtml(NoteTemplateMerger.Merge(template, map)),
|
||||
htmlFragments)
|
||||
};
|
||||
}
|
||||
|
||||
private static Dictionary<string, string> StudentHtmlFragments(Student student) =>
|
||||
new(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
[NoteTemplateMerger.RankedEventsToken] = PrintRankBadgeHtml.ForStudentEvents(student.EventRankings)
|
||||
};
|
||||
|
||||
private static Dictionary<string, string> EventHtmlFragments(IReadOnlyList<StudentEventRanking>? rankings) =>
|
||||
new(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
[NoteTemplateMerger.RankedStudentsToken] = PrintRankBadgeHtml.ForEventStudents(rankings)
|
||||
};
|
||||
|
||||
private Dictionary<string, string?> ChapterTokens()
|
||||
{
|
||||
var settings = ChapterSettings.FromConfiguration(_configuration);
|
||||
@@ -174,8 +208,9 @@ public class NotePrintService : INotePrintService
|
||||
};
|
||||
}
|
||||
|
||||
private static Dictionary<string, string?> StudentTokens(Student student) =>
|
||||
new(StringComparer.OrdinalIgnoreCase)
|
||||
private static Dictionary<string, string?> StudentTokens(Student student)
|
||||
{
|
||||
var tokens = new Dictionary<string, string?>(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
["FirstName"] = student.FirstName,
|
||||
["LastName"] = student.LastName,
|
||||
@@ -191,6 +226,12 @@ public class NotePrintService : INotePrintService
|
||||
["OfficerRole"] = student.OfficerRole?.ToString()
|
||||
};
|
||||
|
||||
foreach (var (key, value) in StudentRankTokens.FromRankings(student.EventRankings))
|
||||
tokens[key] = value;
|
||||
|
||||
return tokens;
|
||||
}
|
||||
|
||||
private static Dictionary<string, string?> TeamTokens(Team team)
|
||||
{
|
||||
var evt = team.Event;
|
||||
@@ -222,7 +263,8 @@ public class NotePrintService : INotePrintService
|
||||
["TeamSize"] = evt?.TeamSize,
|
||||
["Eligibility"] = evt?.Eligibility,
|
||||
["Description"] = evt?.Description,
|
||||
["Theme"] = evt?.Theme
|
||||
["Theme"] = evt?.Theme,
|
||||
["EventAttributes"] = EventAttributeMarks.For(evt)
|
||||
};
|
||||
|
||||
private static Dictionary<string, string?> ImportedTokens(
|
||||
|
||||
Reference in New Issue
Block a user