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:
@@ -63,17 +63,4 @@ public class Team
|
||||
{
|
||||
return $"{Event.Name} {(Identifier != null ? $"({Identifier})" : "")}";
|
||||
}
|
||||
|
||||
public string StudentsFirstNames
|
||||
{
|
||||
get
|
||||
{
|
||||
return
|
||||
string.Join(", ",
|
||||
Students.Select(e =>
|
||||
e.FirstName
|
||||
+ (Captain != null && (Captain.Equals(e)) ? "(Cpt)" : ""))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using Core.Entities;
|
||||
|
||||
namespace Core.Utility;
|
||||
|
||||
/// <summary>
|
||||
/// Utility class for formatting individual student names with overlap and absent markers.
|
||||
/// </summary>
|
||||
public static class StudentNameFormatter
|
||||
{
|
||||
/// <summary>
|
||||
/// Options for formatting student names.
|
||||
/// </summary>
|
||||
public record FormatOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Whether the student is absent. If true, adds "(absent)" suffix. Default is false.
|
||||
/// </summary>
|
||||
public bool IsAbsent { get; init; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the student has schedule overlaps. If true, adds "*" suffix. Default is false.
|
||||
/// </summary>
|
||||
public bool HasOverlap { get; init; } = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Formats a single student name with overlap and absent markers.
|
||||
/// </summary>
|
||||
/// <param name="student">The student to format.</param>
|
||||
/// <param name="options">Formatting options.</param>
|
||||
/// <returns>Formatted student name.</returns>
|
||||
public static string FormatStudentName(Student student, FormatOptions options)
|
||||
{
|
||||
if (student == null)
|
||||
return string.Empty;
|
||||
|
||||
var name = student.FirstName;
|
||||
|
||||
// Add overlap marker
|
||||
if (options.HasOverlap)
|
||||
{
|
||||
name += "*";
|
||||
}
|
||||
|
||||
// Add absent marker
|
||||
if (options.IsAbsent)
|
||||
{
|
||||
name += " (absent)";
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,261 @@
|
||||
using Core.Entities;
|
||||
|
||||
namespace Core.Utility;
|
||||
|
||||
/// <summary>
|
||||
/// Utility class for formatting student names for teams with various formatting options.
|
||||
/// </summary>
|
||||
public static class TeamStudentNameFormatter
|
||||
{
|
||||
/// <summary>
|
||||
/// Options for formatting student names.
|
||||
/// </summary>
|
||||
public record FormatOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Style for indicating the team captain. Default is None.
|
||||
/// </summary>
|
||||
public CaptainIndicatorStyle CaptainIndicator { get; init; } = CaptainIndicatorStyle.None;
|
||||
|
||||
/// <summary>
|
||||
/// How to order the students. Default is None (preserve original order).
|
||||
/// </summary>
|
||||
public OrderingStyle Ordering { get; init; } = OrderingStyle.None;
|
||||
|
||||
/// <summary>
|
||||
/// Whether to add "*" suffix for students with schedule overlaps. Default is false.
|
||||
/// </summary>
|
||||
public bool MarkOverlaps { get; init; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Whether to add "(absent)" suffix for absent students. Default is false.
|
||||
/// </summary>
|
||||
public bool MarkAbsent { get; init; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Function to determine if a student has overlaps. Required if MarkOverlaps is true.
|
||||
/// </summary>
|
||||
public Func<Student, bool>? HasOverlaps { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Collection of absent students. Required if MarkAbsent is true.
|
||||
/// </summary>
|
||||
public ICollection<Student>? AbsentStudents { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether to only show captain indicator for team events (EventFormat.Team). Default is true.
|
||||
/// </summary>
|
||||
public bool OnlyTeamEventsForCaptain { get; init; } = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Style for indicating the team captain.
|
||||
/// </summary>
|
||||
public enum CaptainIndicatorStyle
|
||||
{
|
||||
/// <summary>
|
||||
/// No captain indicator.
|
||||
/// </summary>
|
||||
None,
|
||||
|
||||
/// <summary>
|
||||
/// Use asterisk (*) for captain.
|
||||
/// </summary>
|
||||
Star,
|
||||
|
||||
/// <summary>
|
||||
/// Use "(Cpt)" for captain.
|
||||
/// </summary>
|
||||
Captain
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Style for ordering students.
|
||||
/// </summary>
|
||||
public enum OrderingStyle
|
||||
{
|
||||
/// <summary>
|
||||
/// Preserve original order.
|
||||
/// </summary>
|
||||
None,
|
||||
|
||||
/// <summary>
|
||||
/// Captain first, then alphabetical by first name.
|
||||
/// </summary>
|
||||
CaptainFirst,
|
||||
|
||||
/// <summary>
|
||||
/// Alphabetical by first name.
|
||||
/// </summary>
|
||||
Alphabetical,
|
||||
|
||||
/// <summary>
|
||||
/// By grade + TSA year descending (highest first).
|
||||
/// </summary>
|
||||
GradeDescending
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Formats a single student name with the specified options.
|
||||
/// </summary>
|
||||
/// <param name="student">The student to format.</param>
|
||||
/// <param name="team">The team the student belongs to.</param>
|
||||
/// <param name="options">Formatting options.</param>
|
||||
/// <returns>Formatted student name.</returns>
|
||||
public static string FormatStudentName(Student student, Team team, FormatOptions options)
|
||||
{
|
||||
if (student == null)
|
||||
return string.Empty;
|
||||
|
||||
var name = student.FirstName;
|
||||
|
||||
// Add captain indicator (before overlap/absent markers)
|
||||
if (options.CaptainIndicator != CaptainIndicatorStyle.None && team != null && team.Captain != null && team.Captain.Equals(student))
|
||||
{
|
||||
var shouldShow = !options.OnlyTeamEventsForCaptain || (team.Event != null && team.Event.EventFormat == EventFormat.Team);
|
||||
if (shouldShow)
|
||||
{
|
||||
name += options.CaptainIndicator switch
|
||||
{
|
||||
CaptainIndicatorStyle.Star => "*",
|
||||
CaptainIndicatorStyle.Captain => "(Cpt)",
|
||||
_ => string.Empty
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Convert collections/functions to booleans for StudentNameFormatter
|
||||
var hasOverlap = options.MarkOverlaps && options.HasOverlaps != null && options.HasOverlaps(student);
|
||||
var isAbsent = options.MarkAbsent && options.AbsentStudents != null && options.AbsentStudents.Contains(student);
|
||||
|
||||
// Use StudentNameFormatter for overlap/absent markers (appended after captain indicator)
|
||||
var studentNameOptions = new StudentNameFormatter.FormatOptions
|
||||
{
|
||||
HasOverlap = hasOverlap,
|
||||
IsAbsent = isAbsent
|
||||
};
|
||||
|
||||
// Get the suffix from StudentNameFormatter (overlap/absent markers)
|
||||
var baseFormatted = StudentNameFormatter.FormatStudentName(student, studentNameOptions);
|
||||
var suffix = baseFormatted.Substring(student.FirstName.Length);
|
||||
|
||||
return name + suffix;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Formats all students for a team as a comma-separated string.
|
||||
/// </summary>
|
||||
/// <param name="team">The team to format students for.</param>
|
||||
/// <param name="options">Formatting options.</param>
|
||||
/// <returns>Comma-separated string of formatted student names.</returns>
|
||||
public static string FormatStudentList(Team team, FormatOptions options)
|
||||
{
|
||||
if (team?.Students == null || !team.Students.Any())
|
||||
return string.Empty;
|
||||
|
||||
var students = ApplyOrdering(team.Students, team, options.Ordering);
|
||||
|
||||
return string.Join(", ", students.Select(s => FormatStudentName(s, team, options)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Formats all students for a team as a list of strings.
|
||||
/// </summary>
|
||||
/// <param name="team">The team to format students for.</param>
|
||||
/// <param name="options">Formatting options.</param>
|
||||
/// <returns>List of formatted student names.</returns>
|
||||
public static List<string> FormatStudentListAsList(Team team, FormatOptions options)
|
||||
{
|
||||
if (team?.Students == null || !team.Students.Any())
|
||||
return [];
|
||||
|
||||
var students = ApplyOrdering(team.Students, team, options.Ordering);
|
||||
|
||||
return students.Select(s => FormatStudentName(s, team, options)).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Formats all unique students across multiple teams for an event definition.
|
||||
/// Returns a list of unique student names (by student ID).
|
||||
/// </summary>
|
||||
/// <param name="eventDefinition">The event definition.</param>
|
||||
/// <param name="teams">The teams for this event.</param>
|
||||
/// <param name="options">Formatting options.</param>
|
||||
/// <returns>List of unique formatted student names.</returns>
|
||||
public static List<string> FormatStudentListForEvent(EventDefinition eventDefinition, IEnumerable<Team> teams, FormatOptions options)
|
||||
{
|
||||
if (eventDefinition == null || teams == null)
|
||||
return [];
|
||||
|
||||
var teamsList = teams.ToList();
|
||||
if (!teamsList.Any())
|
||||
return [];
|
||||
|
||||
// Get all unique students from all teams for this event
|
||||
var allStudents = teamsList
|
||||
.SelectMany(t => t.Students)
|
||||
.DistinctBy(s => s.Id)
|
||||
.ToList();
|
||||
|
||||
if (!allStudents.Any())
|
||||
return [];
|
||||
|
||||
// Determine if each student is a captain in any team
|
||||
var studentsWithCaptainInfo = allStudents.Select(s =>
|
||||
{
|
||||
var isCaptain = teamsList.Any(t => t.Captain != null && t.Captain.Equals(s));
|
||||
// Find a team this student belongs to for formatting context
|
||||
var studentTeam = teamsList.FirstOrDefault(t => t.Students.Contains(s));
|
||||
return new { Student = s, IsCaptain = isCaptain, Team = studentTeam };
|
||||
}).ToList();
|
||||
|
||||
// Apply ordering
|
||||
var orderedStudents = options.Ordering switch
|
||||
{
|
||||
OrderingStyle.CaptainFirst => studentsWithCaptainInfo
|
||||
.OrderBy(x => !x.IsCaptain)
|
||||
.ThenBy(x => x.Student.FirstName)
|
||||
.Select(x => x.Student),
|
||||
OrderingStyle.Alphabetical => studentsWithCaptainInfo
|
||||
.OrderBy(x => x.Student.FirstName)
|
||||
.Select(x => x.Student),
|
||||
OrderingStyle.GradeDescending => studentsWithCaptainInfo
|
||||
.OrderByDescending(x => x.Student.Grade + x.Student.TsaYear)
|
||||
.Select(x => x.Student),
|
||||
_ => studentsWithCaptainInfo.Select(x => x.Student)
|
||||
};
|
||||
|
||||
// Format names - for event-level formatting, we need to handle captain indicator specially
|
||||
// since a student might be captain in one team but not another
|
||||
return orderedStudents.Select(s =>
|
||||
{
|
||||
var studentInfo = studentsWithCaptainInfo.First(x => x.Student.Equals(s));
|
||||
// Use the student's team if available, otherwise create a minimal team for formatting context
|
||||
var team = studentInfo.Team ?? new Team { Students = [s], Event = eventDefinition };
|
||||
|
||||
// Create options that handle captain indicator for event-level
|
||||
var eventOptions = options with
|
||||
{
|
||||
CaptainIndicator = studentInfo.IsCaptain &&
|
||||
(!options.OnlyTeamEventsForCaptain || eventDefinition.EventFormat == EventFormat.Team)
|
||||
? options.CaptainIndicator
|
||||
: CaptainIndicatorStyle.None
|
||||
};
|
||||
|
||||
return FormatStudentName(s, team, eventOptions);
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
private static IEnumerable<Student> ApplyOrdering(IEnumerable<Student> students, Team team, OrderingStyle ordering)
|
||||
{
|
||||
return ordering switch
|
||||
{
|
||||
OrderingStyle.CaptainFirst => students
|
||||
.OrderBy(s => team.Captain == null || !team.Captain.Equals(s))
|
||||
.ThenBy(s => s.FirstName),
|
||||
OrderingStyle.Alphabetical => students.OrderBy(s => s.FirstName),
|
||||
OrderingStyle.GradeDescending => students.OrderByDescending(s => s.Grade + s.TsaYear),
|
||||
_ => students
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
@using Core.Calculation
|
||||
@using Microsoft.EntityFrameworkCore
|
||||
@using WebApp.Components.Shared.Components
|
||||
@using Core.Utility
|
||||
@inject IConfiguration Configuration
|
||||
@inject AppDbContext Context
|
||||
@inject ClipboardService ClipboardService
|
||||
@@ -380,21 +381,44 @@
|
||||
|
||||
private string FormatStudentList(Team team, TeamScheduleTimeSlot timeslot)
|
||||
{
|
||||
return string.Join(", ",
|
||||
team.Students
|
||||
.OrderBy(e => e == team.Captain)
|
||||
.ThenBy(e => e.FirstName)
|
||||
.Select(e => FormatStudentName(e, timeslot)));
|
||||
return TeamStudentNameFormatter.FormatStudentList(
|
||||
team,
|
||||
new TeamStudentNameFormatter.FormatOptions
|
||||
{
|
||||
Ordering = TeamStudentNameFormatter.OrderingStyle.CaptainFirst,
|
||||
MarkOverlaps = true,
|
||||
HasOverlaps = timeslot.StudentHasOverlaps,
|
||||
MarkAbsent = true,
|
||||
AbsentStudents = _absentStudents.ToList()
|
||||
});
|
||||
}
|
||||
|
||||
private string FormatStudentName(Student student, TeamScheduleTimeSlot timeslot)
|
||||
{
|
||||
var name = student.FirstName;
|
||||
if (timeslot.StudentHasOverlaps(student))
|
||||
name += "*";
|
||||
if (_absentStudents.Contains(student))
|
||||
name += " (absent)";
|
||||
return name;
|
||||
// Find the team this student belongs to for formatting context
|
||||
var team = _teams.FirstOrDefault(t => t.Students.Contains(student));
|
||||
if (team == null)
|
||||
{
|
||||
// No team context, use StudentNameFormatter directly
|
||||
return StudentNameFormatter.FormatStudentName(
|
||||
student,
|
||||
new StudentNameFormatter.FormatOptions
|
||||
{
|
||||
HasOverlap = timeslot.StudentHasOverlaps(student),
|
||||
IsAbsent = _absentStudents.Contains(student)
|
||||
});
|
||||
}
|
||||
|
||||
return TeamStudentNameFormatter.FormatStudentName(
|
||||
student,
|
||||
team,
|
||||
new TeamStudentNameFormatter.FormatOptions
|
||||
{
|
||||
MarkOverlaps = true,
|
||||
HasOverlaps = timeslot.StudentHasOverlaps,
|
||||
MarkAbsent = true,
|
||||
AbsentStudents = _absentStudents.ToList()
|
||||
});
|
||||
}
|
||||
|
||||
private void AppendUnscheduledStudents(StringBuilder sb, TeamScheduleTimeSlot timeslot)
|
||||
@@ -407,9 +431,12 @@
|
||||
|
||||
foreach (var student in timeslot.UnscheduledStudents)
|
||||
{
|
||||
var studentName = student.FirstName;
|
||||
if (_absentStudents.Contains(student))
|
||||
studentName += " (absent)";
|
||||
var studentName = StudentNameFormatter.FormatStudentName(
|
||||
student,
|
||||
new StudentNameFormatter.FormatOptions
|
||||
{
|
||||
IsAbsent = _absentStudents.Contains(student)
|
||||
});
|
||||
|
||||
var unassignedTeams = _solution.StudentUnassignedTeams(student);
|
||||
var teamsList = string.Join(", ", unassignedTeams.Select(e => e.ToString()));
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
@using Core.Calculation
|
||||
@using WebApp.Models
|
||||
@using Core.Utility
|
||||
|
||||
<MudStack>
|
||||
<MudText Typo="Typo.h6">@TimeSlotName</MudText>
|
||||
@@ -8,31 +9,54 @@
|
||||
var scheduledTeamIds = ScheduledTeams.Select(t => t.Id).ToHashSet();
|
||||
var removed = !scheduledTeamIds.Contains(team.Id);
|
||||
|
||||
<MudLink Typo="Typo.body1"
|
||||
Class="d-flex align-center"
|
||||
Color="Color.Default"
|
||||
OnClick="@(() => OnToggleTeam.InvokeAsync(team))">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Clear"
|
||||
Size="Size.Small"
|
||||
Class="@(removed ? "" : "d-none")">
|
||||
</MudIcon>
|
||||
@team -
|
||||
@foreach (var student in team.Students)
|
||||
{
|
||||
var overlap = StudentHasOverlaps(student);
|
||||
var isAbsent = AbsentStudents.Contains(student);
|
||||
var color = overlap ? Color.Warning : Color.Default;
|
||||
var suffix = GetStudentSuffix(overlap, isAbsent);
|
||||
|
||||
if (student != team.Students.First())
|
||||
{
|
||||
<MudText>, </MudText>
|
||||
<MudStack Row="true" Spacing="2" AlignItems="AlignItems.Center" Class="d-flex align-center">
|
||||
<MudStack Row="true" Spacing="1" AlignItems="AlignItems.Center">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Clear"
|
||||
Size="Size.Small"
|
||||
Class="@(removed ? "" : "d-none")"
|
||||
OnClick="@(() => OnToggleTeam.InvokeAsync(team))"
|
||||
Style="cursor: pointer;">
|
||||
</MudIcon>
|
||||
@{
|
||||
var teamMembers = TeamStudentNameFormatter.FormatStudentList(
|
||||
team,
|
||||
new TeamStudentNameFormatter.FormatOptions
|
||||
{
|
||||
Ordering = TeamStudentNameFormatter.OrderingStyle.None
|
||||
});
|
||||
}
|
||||
<MudText Typo="Typo.body2" Color="@color">
|
||||
@student.FirstName@suffix
|
||||
</MudText>
|
||||
}
|
||||
</MudLink>
|
||||
<MudTooltip Text="@teamMembers">
|
||||
<div @onclick="@(() => OnToggleTeam.InvokeAsync(team))" style="cursor: pointer; display: inline-block;">
|
||||
<MudChip T="string"
|
||||
Size="Size.Small"
|
||||
Color="Color.Default">
|
||||
@team
|
||||
</MudChip>
|
||||
</div>
|
||||
</MudTooltip>
|
||||
</MudStack>
|
||||
<MudStack Row="true" Spacing="1" Wrap="Wrap.Wrap" AlignItems="AlignItems.Center">
|
||||
@foreach (var student in team.Students)
|
||||
{
|
||||
var overlap = StudentHasOverlaps(student);
|
||||
var chipColor = overlap ? Color.Warning : Color.Default;
|
||||
var formattedName = TeamStudentNameFormatter.FormatStudentName(
|
||||
student,
|
||||
team,
|
||||
new TeamStudentNameFormatter.FormatOptions
|
||||
{
|
||||
MarkOverlaps = true,
|
||||
HasOverlaps = StudentHasOverlaps,
|
||||
MarkAbsent = true,
|
||||
AbsentStudents = AbsentStudents.ToList()
|
||||
});
|
||||
|
||||
<MudChip T="string" Size="Size.Small" Color="@chipColor" Variant="Variant.Outlined">
|
||||
@formattedName
|
||||
</MudChip>
|
||||
}
|
||||
</MudStack>
|
||||
</MudStack>
|
||||
}
|
||||
</MudStack>
|
||||
|
||||
@@ -54,11 +78,4 @@
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<Team> OnToggleTeam { get; set; }
|
||||
|
||||
private string GetStudentSuffix(bool overlap, bool isAbsent)
|
||||
{
|
||||
var suffix = overlap ? "*" : "";
|
||||
suffix += isAbsent ? " (absent)" : "";
|
||||
return suffix;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
@using Core.Calculation
|
||||
@using Core.Utility
|
||||
|
||||
@if (UnscheduledStudents.Any())
|
||||
{
|
||||
@@ -6,32 +7,51 @@
|
||||
<MudStack>
|
||||
@foreach (var student in UnscheduledStudents)
|
||||
{
|
||||
var isAbsent = AbsentStudents.Contains(student);
|
||||
<MudItem>
|
||||
<MudText Typo="Typo.body1" HtmlTag="i">
|
||||
@student.FirstName@(isAbsent ? " (absent)" : "")
|
||||
</MudText>
|
||||
@foreach (var unassignedTeam in UnassignedTeams(student))
|
||||
{
|
||||
var isPossibleAddition = PossibleAdditions.Contains(unassignedTeam, new TeamIdComparer());
|
||||
var scheduledTeamIds = ScheduledTeams.Select(t => t.Id).ToHashSet();
|
||||
var isScheduled = scheduledTeamIds.Contains(unassignedTeam.Id);
|
||||
var color = isPossibleAddition ? Color.Success : Color.Default;
|
||||
|
||||
if (unassignedTeam != UnassignedTeams(student).First())
|
||||
{
|
||||
<span>, </span>
|
||||
}
|
||||
<MudLink Typo="Typo.body2"
|
||||
Color="@color"
|
||||
OnClick="@(() => OnToggleTeam.InvokeAsync(unassignedTeam))">
|
||||
<MudIcon Icon="@Icons.Material.Filled.Check"
|
||||
Size="Size.Small"
|
||||
Class="@(isScheduled ? "" : "d-none")">
|
||||
</MudIcon>
|
||||
@unassignedTeam
|
||||
</MudLink>
|
||||
@{
|
||||
var formattedName = StudentNameFormatter.FormatStudentName(
|
||||
student,
|
||||
new StudentNameFormatter.FormatOptions
|
||||
{
|
||||
IsAbsent = AbsentStudents.Contains(student)
|
||||
});
|
||||
}
|
||||
<MudStack Row="true" Spacing="2" AlignItems="AlignItems.Center">
|
||||
<MudStack Row="true" Spacing="1" AlignItems="AlignItems.Center">
|
||||
<MudChip T="string" Size="Size.Small" Variant="Variant.Outlined" Class="font-style-italic">
|
||||
@formattedName
|
||||
</MudChip>
|
||||
</MudStack>
|
||||
<MudStack Row="true" Spacing="1" Wrap="Wrap.Wrap" AlignItems="AlignItems.Center">
|
||||
@foreach (var unassignedTeam in UnassignedTeams(student))
|
||||
{
|
||||
var isPossibleAddition = PossibleAdditions.Contains(unassignedTeam, new TeamIdComparer());
|
||||
var scheduledTeamIds = ScheduledTeams.Select(t => t.Id).ToHashSet();
|
||||
var isScheduled = scheduledTeamIds.Contains(unassignedTeam.Id);
|
||||
var chipColor = isPossibleAddition ? Color.Success : Color.Default;
|
||||
var teamMembers = TeamStudentNameFormatter.FormatStudentList(
|
||||
unassignedTeam,
|
||||
new TeamStudentNameFormatter.FormatOptions
|
||||
{
|
||||
Ordering = TeamStudentNameFormatter.OrderingStyle.None
|
||||
});
|
||||
|
||||
<MudTooltip Text="@teamMembers">
|
||||
<div @onclick="@(() => OnToggleTeam.InvokeAsync(unassignedTeam))" style="cursor: pointer; display: inline-block;">
|
||||
<MudChip T="string"
|
||||
Size="Size.Small"
|
||||
Color="@chipColor">
|
||||
@if (isScheduled)
|
||||
{
|
||||
<MudIcon Icon="@Icons.Material.Filled.Check" Size="Size.Small" Style="margin-right: 4px;" />
|
||||
}
|
||||
@unassignedTeam
|
||||
</MudChip>
|
||||
</div>
|
||||
</MudTooltip>
|
||||
}
|
||||
</MudStack>
|
||||
</MudStack>
|
||||
</MudItem>
|
||||
}
|
||||
</MudStack>
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
@using WebApp.Models
|
||||
@using WebApp.Components.Shared.Components
|
||||
@using Core.Validation
|
||||
@using Core.Utility
|
||||
@inject AppDbContext Context
|
||||
@inject WebApp.LocalStorageService LocalStorage
|
||||
@inject ValidationService ValidationService
|
||||
@@ -83,7 +84,12 @@
|
||||
@foreach (var team in teamsToDisplay)
|
||||
{
|
||||
var isCaptain = team.Captain != null && team.Captain.Equals(context.Item.Student);
|
||||
var teamMembers = string.Join(", ", team.Students.Select(s => s.FirstName));
|
||||
var teamMembers = TeamStudentNameFormatter.FormatStudentList(
|
||||
team,
|
||||
new TeamStudentNameFormatter.FormatOptions
|
||||
{
|
||||
Ordering = TeamStudentNameFormatter.OrderingStyle.None
|
||||
});
|
||||
|
||||
<MudTooltip Text="@teamMembers">
|
||||
<MudChip Size="Size.Small"
|
||||
|
||||
@@ -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