feat: import leftover student fields into notes and show them on the roster

Store leftover CSV columns on hidden student notes, move catalog import to /events/import, and persist Students index columns from Chapter Settings.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-29 23:55:03 -04:00
co-authored by Cursor
parent 4c91db37c2
commit 4cfd85b902
39 changed files with 2437 additions and 166 deletions
+104 -6
View File
@@ -1,5 +1,6 @@
@page "/settings/chapter"
@attribute [Authorize(Roles = AuthRoles.Administrator)]
@implements IAsyncDisposable
@using WebApp.Authentication
@using WebApp.Models
@using WebApp.Components.Shared.Components
@@ -7,12 +8,13 @@
@using Core.Models
@inject IConfiguration Configuration
@inject IChapterSettingsWriter ChapterSettingsWriter
@inject INotesService NotesService
@rendermode InteractiveServer
<PageHeader
Title="Chapter Settings"
Description="Configure chapter information. Changes take effect on next application restart." />
Description="Configure chapter information. Student index columns apply the next time you open Students. Printouts that cache chapter name or year may still need a restart." />
<MudContainer MaxWidth="MaxWidth.Large" Class="mt-4">
@@ -90,6 +92,41 @@
</MudGrid>
</MudPaper>
<MudPaper Class="pa-6 mb-4">
<MudText Typo="Typo.h5" Class="mb-4">Student Index Columns</MudText>
<MudText Typo="Typo.body2" Class="mb-3">
Field names from each student's imported notes table to show as extra Students index columns. Click a field found in notes to add or remove it, or type names (one per line).
</MudText>
@if (_availableFields.Count > 0)
{
<MudText Typo="Typo.subtitle2" Class="mb-2">Fields in student notes</MudText>
<MudStack Row="true" Spacing="1" Wrap="Wrap.Wrap" Class="mb-4">
@foreach (var field in _availableFields)
{
var selected = IsFieldSelected(field);
<MudChip T="string"
Size="Size.Small"
Color="@(selected ? Color.Primary : Color.Default)"
Variant="@(selected ? Variant.Filled : Variant.Outlined)"
OnClick="() => ToggleField(field)">
@field
</MudChip>
}
</MudStack>
}
else
{
<MudText Typo="Typo.caption" Class="mud-text-secondary mb-3">
No imported fields found in student notes yet.
</MudText>
}
<MudTextField @bind-Value="_noteFieldsText"
Label="Imported field columns"
Variant="Variant.Outlined"
Lines="5"
HelperText="Example: Interview Time" />
</MudPaper>
<MudPaper Class="pa-6">
<MudGrid>
<MudItem xs="12">
@@ -125,14 +162,52 @@
@code {
private Models.ChapterSettings? _settings;
private string _noteFieldsText = string.Empty;
private IReadOnlyList<string> _availableFields = [];
private bool _isSaving;
private string? _statusMessage;
private Severity _statusSeverity = Severity.Success;
private CancellationTokenSource? _cancellationTokenSource;
private bool _isDisposed;
protected override void OnInitialized()
{
_settings = Configuration.GetSection("ChapterSettings").Get<Models.ChapterSettings>()
?? new Models.ChapterSettings();
_cancellationTokenSource = new CancellationTokenSource();
_settings = Models.ChapterSettings.FromConfiguration(Configuration);
_noteFieldsText = string.Join(Environment.NewLine, _settings.StudentIndexNoteFields);
}
protected override async Task OnInitializedAsync()
{
try
{
var cancellationToken = _cancellationTokenSource?.Token ?? CancellationToken.None;
_availableFields = await NotesService.GetImportedFieldNamesAsync(cancellationToken);
}
catch (OperationCanceledException)
{
}
}
private IReadOnlyList<string> SelectedFields() =>
_noteFieldsText
.Split(['\r', '\n'], StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)
.Where(line => !string.IsNullOrWhiteSpace(line))
.ToList();
private bool IsFieldSelected(string field) =>
SelectedFields().Any(selected => selected.Equals(field, StringComparison.OrdinalIgnoreCase));
private void ToggleField(string field)
{
var selected = SelectedFields().ToList();
var index = selected.FindIndex(name => name.Equals(field, StringComparison.OrdinalIgnoreCase));
if (index >= 0)
selected.RemoveAt(index);
else
selected.Add(field);
_noteFieldsText = string.Join(Environment.NewLine, selected);
}
private async Task SaveSettings()
@@ -144,18 +219,41 @@
try
{
await ChapterSettingsWriter.WriteAsync(_settings);
_statusMessage = "Settings saved successfully! Changes will take effect on next application restart.";
_settings.StudentIndexNoteFields = [.. SelectedFields()];
var cancellationToken = _cancellationTokenSource?.Token ?? CancellationToken.None;
await ChapterSettingsWriter.WriteAsync(_settings, cancellationToken);
if (_isDisposed)
return;
_statusMessage = "Settings saved. Open Students again to see the updated index columns.";
_statusSeverity = Severity.Success;
}
catch (OperationCanceledException)
{
}
catch (Exception ex)
{
if (_isDisposed)
return;
_statusMessage = $"Error saving settings: {ex.Message}";
_statusSeverity = Severity.Error;
}
finally
{
_isSaving = false;
if (!_isDisposed)
_isSaving = false;
}
}
public async ValueTask DisposeAsync()
{
if (!_isDisposed)
{
_isDisposed = true;
_cancellationTokenSource?.Cancel();
_cancellationTokenSource?.Dispose();
_cancellationTokenSource = null;
}
await ValueTask.CompletedTask;
}
}