Add student name formatting utilities and refactor team student name handling
This commit introduces two new utility classes: StudentNameFormatter and TeamStudentNameFormatter, which provide methods for formatting student names with options for indicating absence and overlaps. The Team class has been updated to remove the StudentsFirstNames property, and various components across the WebApp have been refactored to utilize the new formatting utilities. This enhances the maintainability and readability of the code while improving the presentation of student names in the UI.
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
@using Heron.MudCalendar
|
||||
@using Microsoft.Extensions.Logging
|
||||
@using WebApp.Authentication
|
||||
@using Core.Utility
|
||||
@inject IEventOccurrenceService EventOccurrenceService
|
||||
@inject ILogger<Index> Logger
|
||||
@inject IDialogService DialogService
|
||||
@@ -110,8 +111,15 @@
|
||||
}
|
||||
|
||||
// Get student first names for this event definition
|
||||
var studentFirstNames = occ.EventDefinition != null
|
||||
? StudentFirstNames(occ.EventDefinition, teamsByEventId)
|
||||
var studentFirstNames = occ.EventDefinition != null && teamsByEventId.TryGetValue(occ.EventDefinition.Id, out var teams)
|
||||
? TeamStudentNameFormatter.FormatStudentListForEvent(
|
||||
occ.EventDefinition,
|
||||
teams,
|
||||
new TeamStudentNameFormatter.FormatOptions
|
||||
{
|
||||
CaptainIndicator = TeamStudentNameFormatter.CaptainIndicatorStyle.Star,
|
||||
Ordering = TeamStudentNameFormatter.OrderingStyle.Alphabetical
|
||||
})
|
||||
: [];
|
||||
|
||||
var calendarItem = new CalendarEventItem(occ, studentFirstNames);
|
||||
@@ -143,34 +151,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
private static List<string> StudentFirstNames(EventDefinition ed, Dictionary<int, List<Team>> teamsByEventId)
|
||||
{
|
||||
List<string> studentFirstNames = [];
|
||||
if (ed?.Id == null || !teamsByEventId.TryGetValue(ed.Id, out var teams)) return studentFirstNames;
|
||||
|
||||
// Get all unique student first names from all teams for this event
|
||||
// Include captain indicator (*) for team events
|
||||
var allStudents = teams
|
||||
.SelectMany(t => t.Students)
|
||||
.DistinctBy(s => s.Id) // Ensure uniqueness by student ID
|
||||
.Select(s =>
|
||||
{
|
||||
var isCaptain = teams.Any(t => t.Captain?.Id == s.Id);
|
||||
var name = s.FirstName;
|
||||
// Add star for captain in team events (EventFormat == Team)
|
||||
if (isCaptain && ed.EventFormat == Core.Entities.EventFormat.Team)
|
||||
{
|
||||
name += "*";
|
||||
}
|
||||
return name;
|
||||
})
|
||||
.OrderBy(name => name)
|
||||
.ToList();
|
||||
|
||||
studentFirstNames = allStudents;
|
||||
|
||||
return studentFirstNames;
|
||||
}
|
||||
|
||||
private DateTime GetNextDateWithEvents()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user