Critical tables page
This commit is contained in:
272
src/RolemasterDb.App/Components/Pages/Tables.razor
Normal file
272
src/RolemasterDb.App/Components/Pages/Tables.razor
Normal file
@@ -0,0 +1,272 @@
|
||||
@page "/tables"
|
||||
@using System
|
||||
@using System.Collections.Generic
|
||||
@using System.Diagnostics.CodeAnalysis
|
||||
@inject LookupService LookupService
|
||||
|
||||
<PageTitle>Critical Tables</PageTitle>
|
||||
|
||||
<section class="hero-panel">
|
||||
<span class="eyebrow">Critical Tables</span>
|
||||
<h1 class="page-title">Browse every imported table</h1>
|
||||
<p class="lede">The authority on this page is the SQLite data that the importer maintains. Switch tables to see the full roll matrix, grouped columns, and affix legend for each import.</p>
|
||||
</section>
|
||||
|
||||
<section class="panel tables-page">
|
||||
<div class="table-selector">
|
||||
<label for="critical-table-select">Critical table</label>
|
||||
<select
|
||||
id="critical-table-select"
|
||||
class="input-shell"
|
||||
value="@selectedTableSlug"
|
||||
@onchange="HandleTableChanged"
|
||||
disabled="@isReferenceDataLoading || (referenceData?.CriticalTables.Count ?? 0) == 0">
|
||||
@if (referenceData is null)
|
||||
{
|
||||
<option value="">Loading tables...</option>
|
||||
}
|
||||
else
|
||||
{
|
||||
@foreach (var table in referenceData.CriticalTables)
|
||||
{
|
||||
<option value="@table.Key">@table.Label</option>
|
||||
}
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
@if (referenceData is null)
|
||||
{
|
||||
<p class="muted">Loading reference data...</p>
|
||||
}
|
||||
else if (!referenceData.CriticalTables.Any())
|
||||
{
|
||||
<p class="muted">No critical tables have been imported yet.</p>
|
||||
}
|
||||
else if (isDetailLoading)
|
||||
{
|
||||
<p class="muted">Loading the selected table...</p>
|
||||
}
|
||||
else if (!string.IsNullOrWhiteSpace(detailError))
|
||||
{
|
||||
<p class="error-text">@detailError</p>
|
||||
}
|
||||
else if (tableDetail is null)
|
||||
{
|
||||
<p class="muted">The selected table could not be loaded.</p>
|
||||
}
|
||||
else if (tableDetail is { } detail)
|
||||
{
|
||||
<div class="table-shell">
|
||||
<header>
|
||||
<span class="eyebrow">@detail.SourceDocument</span>
|
||||
<h2 class="panel-title">@detail.DisplayName</h2>
|
||||
@if (!string.IsNullOrWhiteSpace(detail.Notes))
|
||||
{
|
||||
<p class="muted">@detail.Notes</p>
|
||||
}
|
||||
</header>
|
||||
|
||||
<div class="table-scroll">
|
||||
<table class="critical-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="roll-band-header" rowspan="2">Roll band</th>
|
||||
@if (detail.Groups.Count > 0)
|
||||
{
|
||||
foreach (var group in detail.Groups)
|
||||
{
|
||||
<th colspan="@detail.Columns.Count">@group.Label</th>
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
<th colspan="@detail.Columns.Count">Columns</th>
|
||||
}
|
||||
</tr>
|
||||
<tr>
|
||||
@if (detail.Groups.Count > 0)
|
||||
{
|
||||
foreach (var group in detail.Groups)
|
||||
{
|
||||
foreach (var column in detail.Columns)
|
||||
{
|
||||
<th>
|
||||
<span>@column.Label</span>
|
||||
<small>@column.Role</small>
|
||||
</th>
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var column in detail.Columns)
|
||||
{
|
||||
<th>
|
||||
<span>@column.Label</span>
|
||||
<small>@column.Role</small>
|
||||
</th>
|
||||
}
|
||||
}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var rollBand in detail.RollBands)
|
||||
{
|
||||
<tr>
|
||||
<th class="roll-band-header">@rollBand.Label</th>
|
||||
@if (detail.Groups.Count > 0)
|
||||
{
|
||||
foreach (var group in detail.Groups)
|
||||
{
|
||||
foreach (var column in detail.Columns)
|
||||
{
|
||||
<td>
|
||||
@RenderCell(rollBand.Label, group.Key, column.Key)
|
||||
</td>
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var column in detail.Columns)
|
||||
{
|
||||
<td>
|
||||
@RenderCell(rollBand.Label, null, column.Key)
|
||||
</td>
|
||||
}
|
||||
}
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
@{
|
||||
var legendEntries = detail.Legend ?? Array.Empty<CriticalTableLegendEntry>();
|
||||
}
|
||||
|
||||
@if (legendEntries.Count > 0)
|
||||
{
|
||||
<div class="critical-legend">
|
||||
<h4>Affix legend</h4>
|
||||
<div class="legend-grid">
|
||||
@foreach (var entry in legendEntries)
|
||||
{
|
||||
<div class="legend-item" title="@entry.Tooltip">
|
||||
<span class="legend-symbol">@entry.Symbol</span>
|
||||
<div>
|
||||
<strong>@entry.Label</strong>
|
||||
<span class="muted">@entry.Description</span>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</section>
|
||||
|
||||
@code {
|
||||
private LookupReferenceData? referenceData;
|
||||
private CriticalTableDetail? tableDetail;
|
||||
private string selectedTableSlug = string.Empty;
|
||||
private bool isDetailLoading;
|
||||
private bool isReferenceDataLoading = true;
|
||||
private string? detailError;
|
||||
private Dictionary<(string RollBand, string? GroupKey, string ColumnKey), CriticalTableCellDetail>? cellIndex;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
referenceData = await LookupService.GetReferenceDataAsync();
|
||||
isReferenceDataLoading = false;
|
||||
|
||||
selectedTableSlug = referenceData?.CriticalTables.FirstOrDefault()?.Key ?? string.Empty;
|
||||
await LoadTableDetailAsync();
|
||||
}
|
||||
|
||||
private async Task HandleTableChanged(ChangeEventArgs args)
|
||||
{
|
||||
selectedTableSlug = args.Value?.ToString() ?? string.Empty;
|
||||
await LoadTableDetailAsync();
|
||||
}
|
||||
|
||||
private async Task LoadTableDetailAsync()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(selectedTableSlug))
|
||||
{
|
||||
tableDetail = null;
|
||||
cellIndex = null;
|
||||
return;
|
||||
}
|
||||
|
||||
isDetailLoading = true;
|
||||
detailError = null;
|
||||
tableDetail = null;
|
||||
cellIndex = null;
|
||||
|
||||
try
|
||||
{
|
||||
tableDetail = await LookupService.GetCriticalTableAsync(selectedTableSlug);
|
||||
if (tableDetail is null)
|
||||
{
|
||||
detailError = "The selected table could not be loaded.";
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
detailError = exception.Message;
|
||||
}
|
||||
finally
|
||||
{
|
||||
isDetailLoading = false;
|
||||
BuildCellIndex();
|
||||
}
|
||||
}
|
||||
|
||||
private void BuildCellIndex()
|
||||
{
|
||||
if (tableDetail?.Cells is null)
|
||||
{
|
||||
cellIndex = null;
|
||||
return;
|
||||
}
|
||||
|
||||
cellIndex = new Dictionary<(string, string?, string), CriticalTableCellDetail>();
|
||||
foreach (var cell in tableDetail.Cells)
|
||||
{
|
||||
cellIndex[(cell.RollBand, cell.GroupKey, cell.ColumnKey)] = cell;
|
||||
}
|
||||
}
|
||||
|
||||
private RenderFragment RenderCell(string rollBand, string? groupKey, string columnKey) => builder =>
|
||||
{
|
||||
if (TryGetCell(rollBand, groupKey, columnKey, out var cell))
|
||||
{
|
||||
builder.OpenComponent(0, typeof(CompactCriticalCell));
|
||||
builder.AddAttribute(1, "Description", cell.Description ?? string.Empty);
|
||||
builder.AddAttribute(2, "Effects", cell.Effects ?? Array.Empty<CriticalEffectLookupResponse>());
|
||||
builder.AddAttribute(3, "Branches", cell.Branches ?? Array.Empty<CriticalBranchLookupResponse>());
|
||||
builder.CloseComponent();
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.OpenElement(4, "span");
|
||||
builder.AddAttribute(5, "class", "empty-cell");
|
||||
builder.AddContent(6, "—");
|
||||
builder.CloseElement();
|
||||
}
|
||||
};
|
||||
|
||||
private bool TryGetCell(string rollBand, string? groupKey, string columnKey, [NotNullWhen(true)] out CriticalTableCellDetail? cell)
|
||||
{
|
||||
if (cellIndex is null)
|
||||
{
|
||||
cell = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
return cellIndex.TryGetValue((rollBand, groupKey, columnKey), out cell);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user