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:
@@ -1,4 +1,5 @@
|
||||
@using WebApp.Models
|
||||
@using Core.Utility
|
||||
|
||||
@if (Title != null)
|
||||
{
|
||||
@@ -14,14 +15,20 @@
|
||||
@foreach (var team in Teams.OrderByEventFormatFirst().ThenBy(e => e.Event.Name))
|
||||
{
|
||||
<MudToggleItem Value="@team" Style="font-size: .75rem;">
|
||||
<MudTooltip Text="@team.StudentsFirstNames">
|
||||
<MudStack Row="true" AlignItems="AlignItems.Center" Justify="Justify.SpaceBetween" Spacing="1" Wrap="Wrap.Wrap">
|
||||
<MudText Class="ellipsis">@team.ToString()</MudText>
|
||||
<MudTooltip Text="@TeamStudentNameFormatter.FormatStudentList(
|
||||
team,
|
||||
new TeamStudentNameFormatter.FormatOptions
|
||||
{
|
||||
CaptainIndicator = TeamStudentNameFormatter.CaptainIndicatorStyle.Captain,
|
||||
Ordering = TeamStudentNameFormatter.OrderingStyle.None
|
||||
})">
|
||||
<div style="display: flex; align-items: center; justify-content: space-between; gap: 4px; width: 100%;">
|
||||
<span class="ellipsis" style="flex: 1; min-width: 0;">@team.ToString()</span>
|
||||
@if (ShowEventAttributes)
|
||||
{
|
||||
<EventAttributes EventDefinition="@team.Event"></EventAttributes>
|
||||
}
|
||||
</MudStack>
|
||||
</div>
|
||||
</MudTooltip>
|
||||
</MudToggleItem>
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
@using Microsoft.EntityFrameworkCore
|
||||
@using WebApp.Models
|
||||
@using WebApp.Components.Shared.Components
|
||||
@using Core.Utility
|
||||
@inject IConfiguration Configuration
|
||||
@inject AppDbContext Context
|
||||
|
||||
@@ -35,7 +36,12 @@ else
|
||||
@if (team.Event.EventFormat == EventFormat.Team)
|
||||
{
|
||||
<span style="font-weight: normal; font-size: 0.9em;">
|
||||
(Team: @string.Join(", ", team.Students.OrderByDescending(e => e.Grade + e.TsaYear).Select(e => e.FirstName)))
|
||||
(Team: @TeamStudentNameFormatter.FormatStudentList(
|
||||
team,
|
||||
new TeamStudentNameFormatter.FormatOptions
|
||||
{
|
||||
Ordering = TeamStudentNameFormatter.OrderingStyle.GradeDescending
|
||||
}))
|
||||
</span>
|
||||
}
|
||||
</MudText>
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
@using Microsoft.EntityFrameworkCore
|
||||
@using WebApp.Models
|
||||
@using WebApp.Components.Shared.Components
|
||||
@using Core.Utility
|
||||
@inject IConfiguration Configuration
|
||||
@inject AppDbContext Context
|
||||
|
||||
@@ -57,7 +58,12 @@ else
|
||||
{
|
||||
<MudItem xs="12">
|
||||
<MudText Class="d-flex py-1" Typo="Typo.h6">
|
||||
Team Members: @string.Join(", ", team.Students.OrderByDescending(e => e.Grade + e.TsaYear).Select(e => e.FirstName))
|
||||
Team Members: @TeamStudentNameFormatter.FormatStudentList(
|
||||
team,
|
||||
new TeamStudentNameFormatter.FormatOptions
|
||||
{
|
||||
Ordering = TeamStudentNameFormatter.OrderingStyle.GradeDescending
|
||||
})
|
||||
</MudText>
|
||||
</MudItem>
|
||||
}
|
||||
|
||||
@@ -128,6 +128,7 @@
|
||||
= Context.Teams
|
||||
.AsNoTracking()
|
||||
.Include(e => e.Event)
|
||||
.Include(e => e.Captain)
|
||||
.Include(e => e.Students)
|
||||
.ThenInclude(e => e.EventRankings);
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
@using Microsoft.EntityFrameworkCore
|
||||
@using WebApp.Models
|
||||
@using WebApp.Components.Shared.Components
|
||||
@using Core.Utility
|
||||
@inject IConfiguration Configuration
|
||||
@inject AppDbContext Context
|
||||
|
||||
@@ -56,7 +57,13 @@ else
|
||||
.Find(e => e.EventDefinition == context.Event)?.Rank ?? int.MaxValue;
|
||||
|
||||
<MudTd Class="@(EventRankClass(rank))">
|
||||
@student.Name @if(context?.Captain == student) {<span> (Cpt)</span>}
|
||||
@TeamStudentNameFormatter.FormatStudentName(
|
||||
student,
|
||||
context,
|
||||
new TeamStudentNameFormatter.FormatOptions
|
||||
{
|
||||
CaptainIndicator = TeamStudentNameFormatter.CaptainIndicatorStyle.Captain
|
||||
})
|
||||
</MudTd>
|
||||
}
|
||||
else
|
||||
@@ -191,7 +198,12 @@ else
|
||||
<span>❔</span>
|
||||
}
|
||||
</MudTd>
|
||||
<MudTd>@string.Join(", ", team.Students.Where(e => e != context).Select(e => e.FirstName))</MudTd>
|
||||
<MudTd>@TeamStudentNameFormatter.FormatStudentList(
|
||||
new Team { Students = team.Students.Where(e => e != context).ToList(), Event = team.Event },
|
||||
new TeamStudentNameFormatter.FormatOptions
|
||||
{
|
||||
Ordering = TeamStudentNameFormatter.OrderingStyle.None
|
||||
})</MudTd>
|
||||
<MudTd></MudTd>
|
||||
</RowTemplate>
|
||||
</MudTable>
|
||||
|
||||
Reference in New Issue
Block a user