Combine dashboard top 10 lists into one tabbed card
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f5bcc55a29
commit
393ebcdf0c
5 files changed
+163
-53
No files matched your search
@@ -21,6 +21,7 @@
|
||||
@if (_data is { } data)
|
||||
{
|
||||
var active = Governor.ActiveConnections;
|
||||
var tabs = TopTabs(data);
|
||||
<section class="metrics">
|
||||
<div class="metric metric-hero @(active > 0 ? "live" : null)">
|
||||
<span class="label">Gerade in der Falle</span>
|
||||
@@ -62,17 +63,26 @@
|
||||
|
||||
<section class="origin">
|
||||
<WorldMap CatchesByCountry="data.CatchesByCountry" />
|
||||
<TopTable Title="Top 10 Länder" KeyLabel="Land" Entries="data.TopCountries" ShowFlags="true" LabelFormatter="CountryNames.Display" />
|
||||
<section class="card tops-card">
|
||||
<h2 id="tops-title">Top 10</h2>
|
||||
<div class="tabs" role="tablist" aria-labelledby="tops-title">
|
||||
@foreach (var tab in tabs)
|
||||
{
|
||||
var first = tab == tabs[0];
|
||||
<button type="button" role="tab" id="tab-@tab.Id" aria-controls="panel-@tab.Id" aria-selected="@(first ? "true" : "false")" tabindex="@(first ? 0 : -1)">@tab.Label</button>
|
||||
}
|
||||
</div>
|
||||
@foreach (var tab in tabs)
|
||||
{
|
||||
<div role="tabpanel" id="panel-@tab.Id" aria-labelledby="tab-@tab.Id" tabindex="0" hidden="@(tab != tabs[0])">
|
||||
<TopTable KeyLabel="@tab.KeyLabel" Entries="tab.Entries" ShowFlags="tab.ShowFlags" KeyFormatter="tab.KeyFormatter" LabelFormatter="tab.LabelFormatter" />
|
||||
</div>
|
||||
}
|
||||
</section>
|
||||
</section>
|
||||
|
||||
@if (data.TotalCatches > 0)
|
||||
{
|
||||
<section class="tops">
|
||||
<TopTable Title="Top 10 Provider" KeyLabel="Provider" Entries="data.TopProviders" />
|
||||
<TopTable Title="Top 10 IPs" KeyLabel="IP" Entries="data.TopIps" />
|
||||
<TopTable Title="Top 10 Ziele" KeyLabel="Ziel" Entries="data.TopTargets" KeyFormatter="Formatting.Target" />
|
||||
</section>
|
||||
|
||||
<section class="card">
|
||||
<div class="card-head">
|
||||
<h2>Letzte 50 Fänge</h2>
|
||||
@@ -148,6 +158,23 @@
|
||||
_loadedAt = DateTime.Now;
|
||||
}
|
||||
|
||||
private static IReadOnlyList<TopTab> TopTabs(DashboardData data) =>
|
||||
[
|
||||
new("countries", "Länder", "Land", data.TopCountries, ShowFlags: true, LabelFormatter: CountryNames.Display),
|
||||
new("providers", "Provider", "Provider", data.TopProviders),
|
||||
new("ips", "IPs", "IP", data.TopIps),
|
||||
new("targets", "Ziele", "Ziel", data.TopTargets, KeyFormatter: Formatting.Target)
|
||||
];
|
||||
|
||||
private static string Origin(TrapEventEntity trapEvent) =>
|
||||
string.Join(", ", new[] { trapEvent.City, CountryNames.Display(trapEvent.CountryCode, trapEvent.Country) }.Where(part => !string.IsNullOrEmpty(part)));
|
||||
|
||||
private sealed record TopTab(
|
||||
string Id,
|
||||
string Label,
|
||||
string KeyLabel,
|
||||
IReadOnlyList<TopEntry> Entries,
|
||||
bool ShowFlags = false,
|
||||
Func<string?, string?>? KeyFormatter = null,
|
||||
Func<string?, string?, string?>? LabelFormatter = null);
|
||||
}
|
||||
@@ -1,44 +1,40 @@
|
||||
@using System.Globalization
|
||||
@using Flypaper.Storage.Dashboard
|
||||
<section class="card">
|
||||
<h2>@Title</h2>
|
||||
@if (Entries.Count == 0)
|
||||
{
|
||||
<p class="empty">Noch keine Einträge.</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<table class="top-table">
|
||||
<colgroup>
|
||||
<col />
|
||||
<col class="count" />
|
||||
<col class="hold" />
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>@KeyLabel</th>
|
||||
<th class="num">Fänge</th>
|
||||
<th class="num">Haltezeit</th>
|
||||
|
||||
@if (Entries.Count == 0)
|
||||
{
|
||||
<p class="empty">Noch keine Einträge.</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<table class="top-table">
|
||||
<colgroup>
|
||||
<col />
|
||||
<col class="count" />
|
||||
<col class="hold" />
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>@KeyLabel</th>
|
||||
<th class="num">Fänge</th>
|
||||
<th class="num">Haltezeit</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var entry in Entries)
|
||||
{
|
||||
var share = (entry.Count * 100.0 / Entries[0].Count).ToString("0.#", CultureInfo.InvariantCulture);
|
||||
<tr data-expand="@($"{KeyLabel}:{entry.Key}")" tabindex="0" aria-expanded="false" style="--share: @(share)%">
|
||||
<td class="mono clip bar" title="@Display(entry)">@(ShowFlags ? $"{Formatting.Flag(entry.Key)} " : "")@Display(entry)</td>
|
||||
<td class="num">@entry.Count.ToString("N0")</td>
|
||||
<td class="num">@Formatting.Duration(entry.HoldTime)</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var entry in Entries)
|
||||
{
|
||||
var share = (entry.Count * 100.0 / Entries[0].Count).ToString("0.#", CultureInfo.InvariantCulture);
|
||||
<tr data-expand="@($"{KeyLabel}:{entry.Key}")" tabindex="0" aria-expanded="false" style="--share: @(share)%">
|
||||
<td class="mono clip bar" title="@Display(entry)">@(ShowFlags ? $"{Formatting.Flag(entry.Key)} " : "")@Display(entry)</td>
|
||||
<td class="num">@entry.Count.ToString("N0")</td>
|
||||
<td class="num">@Formatting.Duration(entry.HoldTime)</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
</section>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
|
||||
@code {
|
||||
[Parameter, EditorRequired] public required string Title { get; set; }
|
||||
|
||||
[Parameter, EditorRequired] public required string KeyLabel { get; set; }
|
||||
|
||||
[Parameter, EditorRequired] public required IReadOnlyList<TopEntry> Entries { get; set; }
|
||||
|
||||
Reference in new issue
Block a user