Add comprehensive validation system with runtime configuration
Implements a flexible validation framework for student rankings, team assignments, and team composition with administrator-configurable rules and thresholds. Validation System: - Reflection-based rule discovery eliminates manual registration - Base classes (RequiredEventTypeRuleBase, EventCountThresholdRuleBase) reduce code duplication by ~250 lines - 12 validation rules covering event requirements, counts, and team constraints - Configurable severity levels (Warning/Error) per rule type - ValidationService with caching for optimal performance - Rules apply contextually (StudentRanking, StudentAssignment, TeamComposition) Configuration & Admin UI: - ValidationSettings admin page for editing thresholds and severity levels - ChapterSettings admin page for editing chapter information - Settings stored in Data/appsettings.json for runtime configuration - JSON config works in both development and production environments - Auto-creates Data directory and config template on first run User Experience: - ValidationWarnings component displays inline warnings/errors - Integrated in Event Ranking, Registration, and Team Assignment pages - Color-coded severity indicators (warning yellow, error red) - Includes "Too Many Regional Events" rule (max 3 recommended) Technical Improvements: - Template Method pattern for rule base classes - Singleton rule instances with lazy initialization - Configuration loaded via IConfiguration with fallback to defaults - Safe JSON updates preserve other appsettings sections
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
@using WebApp.Models
|
||||
|
||||
<span style=""></span>
|
||||
@if (EventDefinition.LevelOfEffort.HasValue)
|
||||
{
|
||||
<span class="numberCircle">@EventDefinition.LevelOfEffort</span>
|
||||
}
|
||||
<MudText Style="font-family: monospace; white-space: pre;">
|
||||
|
||||
@foreach (var charStr in _attributes.Select(c => c.ToString()))
|
||||
{
|
||||
if (AppIcons.IconTooltips.TryGetValue(charStr, out var tooltip))
|
||||
@@ -23,9 +29,7 @@
|
||||
|
||||
protected override void OnParametersSet()
|
||||
{
|
||||
_attributes = AppIcons.LevelOfEffortIcon(EventDefinition.LevelOfEffort);
|
||||
_attributes += " ";
|
||||
_attributes += EventDefinition.EventFormat == EventFormat.Individual ? AppIcons.IndividualEvent : " ";
|
||||
_attributes = EventDefinition.EventFormat == EventFormat.Individual ? AppIcons.IndividualEvent : " ";
|
||||
_attributes += EventDefinition.OnSiteActivity ? AppIcons.OnSiteActivity : " ";
|
||||
_attributes += EventDefinition.RegionalEvent ? AppIcons.RegionalEvent : " ";
|
||||
_attributes += EventDefinition.InterviewOrPresentation ? AppIcons.PresentationEvent : " ";
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
@attribute [Authorize]
|
||||
@using Microsoft.EntityFrameworkCore
|
||||
@using WebApp.Models
|
||||
@using Core.Validation
|
||||
@inject AppDbContext Context
|
||||
@inject ValidationService ValidationService
|
||||
@rendermode InteractiveServer
|
||||
|
||||
<PageTitle>Student Event Ranks - TSA Chapter Organizer</PageTitle>
|
||||
@@ -37,25 +39,7 @@ else
|
||||
<MudTh>@context.TsaYear</MudTh>
|
||||
<MudTd><MudButton StartIcon="@Icons.Material.Filled.TableChart" Href="@($"students/event-ranking-edit/{context.Id}")">Edit</MudButton></MudTd>
|
||||
<MudTd>
|
||||
@if (!context.RankedEvents.Any(re => re.OnSiteActivity))
|
||||
{
|
||||
<MudTooltip Text="No On-Site Activity">
|
||||
<MudText Style="font-weight:bolder" Color="Color.Warning">@AppIcons.OnSiteActivity</MudText>
|
||||
</MudTooltip>
|
||||
}
|
||||
@if (!context.RankedEvents.Any(re => re.RegionalEvent))
|
||||
{
|
||||
<MudTooltip Text="No Regional Event">
|
||||
<MudText Style="font-weight:bolder" Color="Color.Warning">@AppIcons.RegionalEvent</MudText>
|
||||
</MudTooltip>
|
||||
}
|
||||
|
||||
@if (context.RankedEvents.All(re => re.EventFormat != EventFormat.Individual))
|
||||
{
|
||||
<MudTooltip Text="No Individual Event">
|
||||
<MudText Style="font-weight:bolder" Color="Color.Warning">@AppIcons.IndividualEvent</MudText>
|
||||
</MudTooltip>
|
||||
}
|
||||
<ValidationWarnings Warnings="@GetStudentWarnings(context)" />
|
||||
</MudTd>
|
||||
@for (var i = 1; i <= 10; i++)
|
||||
{
|
||||
@@ -154,4 +138,9 @@ else
|
||||
|
||||
_maxEventStudentRankings = _eventStudentRankings.Max(esr => esr.StudentRanking.Length);
|
||||
}
|
||||
|
||||
private List<ValidationWarning> GetStudentWarnings(Student student)
|
||||
{
|
||||
return ValidationService.ValidateStudentRankings(student, ValidationContext.StudentRanking);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
@attribute [Authorize]
|
||||
@using Microsoft.EntityFrameworkCore
|
||||
@using WebApp.Models
|
||||
@using Core.Validation
|
||||
@inject AppDbContext Context
|
||||
@inject WebApp.LocalStorageService LocalStorage
|
||||
@inject ValidationService ValidationService
|
||||
|
||||
<PageTitle>Registration - TSA Chapter Organizer</PageTitle>
|
||||
|
||||
@@ -43,6 +45,11 @@
|
||||
</MudTooltip>
|
||||
</CellTemplate>
|
||||
</PropertyColumn>
|
||||
<TemplateColumn Title="Warnings" Sortable="false">
|
||||
<CellTemplate>
|
||||
<ValidationWarnings Warnings="@GetRegistrationWarnings(context.Item.Student)" />
|
||||
</CellTemplate>
|
||||
</TemplateColumn>
|
||||
@if (_showGrade)
|
||||
{
|
||||
<PropertyColumn Property="@(e => e.Student.Grade)" Title="Grade" Sortable="true" />
|
||||
@@ -239,6 +246,20 @@
|
||||
: data.OrderBy(sortExpression);
|
||||
}
|
||||
|
||||
private List<ValidationWarning> GetRegistrationWarnings(Student student)
|
||||
{
|
||||
// Create StudentEventStatistics from the student's teams
|
||||
var stats = new StudentEventStatistics
|
||||
{
|
||||
Student = student,
|
||||
Events = student.Teams?.Where(t => t?.Event != null)
|
||||
.Select(t => t.Event)
|
||||
.ToList() ?? new List<EventDefinition>()
|
||||
};
|
||||
|
||||
return ValidationService.ValidateStudentStatistics(stats, ValidationContext.StudentRegistration);
|
||||
}
|
||||
|
||||
public class StudentTeamInfo
|
||||
{
|
||||
public required Student Student { get; init; }
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
@page "/teams/assignment"
|
||||
@attribute [Authorize]
|
||||
@using Core.Calculation
|
||||
@using Core.Validation
|
||||
@using Microsoft.EntityFrameworkCore
|
||||
@using WebApp.Models
|
||||
@using EventAssignment = Core.Calculation.EventAssignment
|
||||
@inject AppDbContext Context
|
||||
@inject IDialogService DialogService
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject ValidationService ValidationService
|
||||
|
||||
<PageTitle>Event Assignment - TSA Chapter Organizer</PageTitle>
|
||||
|
||||
@@ -134,18 +136,8 @@
|
||||
<MudTd><b>@context.Student.FirstName</b></MudTd>
|
||||
<MudTd>@context.EventCount</MudTd>
|
||||
<MudTd>@context.TotalLevelOfEffort</MudTd>
|
||||
<MudTd>@if (!context.HasOnSiteActivity)
|
||||
{
|
||||
<MudTooltip Text="No On-Site Activity">
|
||||
<MudText Style="font-weight:bolder" Color="Color.Warning">@AppIcons.OnSiteActivity</MudText>
|
||||
</MudTooltip>
|
||||
}
|
||||
@if (!context.HasRegionalEvent)
|
||||
{
|
||||
<MudTooltip Text="No Regional Event">
|
||||
<MudText Style="font-weight:bolder" Color="Color.Warning">@AppIcons.RegionalEvent</MudText>
|
||||
</MudTooltip>
|
||||
}
|
||||
<MudTd>
|
||||
<ValidationWarnings Warnings="@GetStatisticsWarnings(context)" />
|
||||
</MudTd>
|
||||
</RowTemplate>
|
||||
<ChildRowContent>
|
||||
@@ -313,6 +305,7 @@
|
||||
public bool TestSwitch { get; set; } = false;
|
||||
|
||||
private readonly AssignmentParameters _parameters = new() { RequireOnSite = false, RequireRegional = false };
|
||||
private ValidationService _validationService = new ValidationService(ValidationConfiguration.Default);
|
||||
|
||||
private List<EventDefinition>? _events;
|
||||
private List<Student>? _students;
|
||||
@@ -367,6 +360,7 @@
|
||||
private async Task<TableData<Team>> SolveAssignments(TableState arg1, CancellationToken arg2)
|
||||
{
|
||||
_isSolving = true;
|
||||
UpdateValidationConfig();
|
||||
var eventAssignment = new EventAssignment(_events, _students, _parameters);
|
||||
foreach (var requirement in _assignmentRequirements)
|
||||
{
|
||||
@@ -396,6 +390,17 @@
|
||||
return new TableData<StudentEventStatistics> {Items = _statistics};
|
||||
}
|
||||
|
||||
private void UpdateValidationConfig()
|
||||
{
|
||||
var config = ValidationConfiguration.FromAssignmentParameters(_parameters);
|
||||
_validationService = new ValidationService(config);
|
||||
}
|
||||
|
||||
private List<ValidationWarning> GetStatisticsWarnings(StudentEventStatistics stats)
|
||||
{
|
||||
return _validationService.ValidateStudentStatistics(stats, ValidationContext.StudentAssignment);
|
||||
}
|
||||
|
||||
private async Task<TableData<AssignmentRequirement>> ReloadAssignmentRequirements(TableState arg1, CancellationToken arg2)
|
||||
{
|
||||
return new TableData<AssignmentRequirement> { Items = _assignmentRequirements };
|
||||
|
||||
Reference in New Issue
Block a user