diff --git a/CHANGELOG.md b/CHANGELOG.md index cb9d0b5..6771e5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ All notable changes to Flypaper are documented in this file. The format follows ## [Unreleased] +### Changed + +- The dashboard's top 10 lists share one card with tabs (Länder, Provider, IPs, Ziele); the + selected tab survives the auto-refresh. + ## [0.3.0] - 2026-11-15 ### Added diff --git a/src/Flypaper.Web/Components/Pages/Dashboard/DashboardPage.razor b/src/Flypaper.Web/Components/Pages/Dashboard/DashboardPage.razor index e7e1f95..724a64e 100644 --- a/src/Flypaper.Web/Components/Pages/Dashboard/DashboardPage.razor +++ b/src/Flypaper.Web/Components/Pages/Dashboard/DashboardPage.razor @@ -21,6 +21,7 @@ @if (_data is { } data) { var active = Governor.ActiveConnections; + var tabs = TopTabs(data);
Gerade in der Falle @@ -62,17 +63,26 @@
- +
+

Top 10

+
+ @foreach (var tab in tabs) + { + var first = tab == tabs[0]; + + } +
+ @foreach (var tab in tabs) + { + + } +
@if (data.TotalCatches > 0) { -
- - - -
-

Letzte 50 Fänge

@@ -148,6 +158,23 @@ _loadedAt = DateTime.Now; } + private static IReadOnlyList 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 Entries, + bool ShowFlags = false, + Func? KeyFormatter = null, + Func? LabelFormatter = null); } diff --git a/src/Flypaper.Web/Components/Pages/Dashboard/TopTable.razor b/src/Flypaper.Web/Components/Pages/Dashboard/TopTable.razor index f81fbf6..2f5322a 100644 --- a/src/Flypaper.Web/Components/Pages/Dashboard/TopTable.razor +++ b/src/Flypaper.Web/Components/Pages/Dashboard/TopTable.razor @@ -1,44 +1,40 @@ @using System.Globalization @using Flypaper.Storage.Dashboard -
-

@Title

- @if (Entries.Count == 0) - { -

Noch keine Einträge.

- } - else - { - - - - - - - - - - - + +@if (Entries.Count == 0) +{ +

Noch keine Einträge.

+} +else +{ +
@KeyLabelFängeHaltezeit
+ + + + + + + + + + + + + + @foreach (var entry in Entries) + { + var share = (entry.Count * 100.0 / Entries[0].Count).ToString("0.#", CultureInfo.InvariantCulture); + + + + - - - @foreach (var entry in Entries) - { - var share = (entry.Count * 100.0 / Entries[0].Count).ToString("0.#", CultureInfo.InvariantCulture); - - - - - - } - -
@KeyLabelFängeHaltezeit
- } -
+ } + + +} @code { - [Parameter, EditorRequired] public required string Title { get; set; } - [Parameter, EditorRequired] public required string KeyLabel { get; set; } [Parameter, EditorRequired] public required IReadOnlyList Entries { get; set; } diff --git a/src/Flypaper.Web/wwwroot/app.css b/src/Flypaper.Web/wwwroot/app.css index d32b420..b575278 100644 --- a/src/Flypaper.Web/wwwroot/app.css +++ b/src/Flypaper.Web/wwwroot/app.css @@ -191,18 +191,45 @@ code { min-width: 0; } -.tops { - display: grid; - grid-template-columns: repeat(2, minmax(0, 1fr)); - gap: 16px; +.tops-card h2 { + margin-bottom: 10px; } -.tops > :last-child { - grid-column: 1 / -1; +.tabs { + display: flex; + gap: 2px; + margin: 0 -4px 8px; + padding: 0 4px; + overflow-x: auto; + border-bottom: 1px solid var(--border); + scrollbar-width: none; } -.tops > * { - min-width: 0; +.tabs button[role="tab"] { + flex: none; + margin-bottom: -1px; + padding: 7px 12px; + border: 0; + border-bottom: 2px solid transparent; + border-radius: 6px 6px 0 0; + background: none; + color: var(--muted); + font-weight: 500; +} + +.tabs button[role="tab"]:hover { + color: var(--text); +} + +.tabs button[role="tab"][aria-selected="true"] { + border-bottom-color: var(--accent); + color: var(--text); +} + +.tabs button[role="tab"]:focus-visible, +[role="tabpanel"]:focus-visible { + outline: 2px solid var(--accent); + outline-offset: -2px; } .top-table { @@ -754,8 +781,7 @@ button.danger { grid-column: span 3; } - .origin, - .tops { + .origin { grid-template-columns: minmax(0, 1fr); } } diff --git a/src/Flypaper.Web/wwwroot/dashboard.js b/src/Flypaper.Web/wwwroot/dashboard.js index 3fcc3d3..652d34e 100644 --- a/src/Flypaper.Web/wwwroot/dashboard.js +++ b/src/Flypaper.Web/wwwroot/dashboard.js @@ -52,3 +52,59 @@ save(expanded); })(); + +(() => { + const storageKey = "flypaper.tab"; + const tabs = [...document.querySelectorAll('[role="tab"]')]; + if (tabs.length === 0) { + return; + } + + const select = (tab, focus) => { + for (const other of tabs) { + const selected = other === tab; + other.setAttribute("aria-selected", String(selected)); + other.tabIndex = selected ? 0 : -1; + document.getElementById(other.getAttribute("aria-controls")).hidden = !selected; + } + + if (focus) { + tab.focus(); + } + + try { + sessionStorage.setItem(storageKey, tab.id); + } catch { + } + }; + + let stored = null; + try { + stored = sessionStorage.getItem(storageKey); + } catch { + } + + const initial = tabs.find(tab => tab.id === stored); + if (initial) { + select(initial, false); + } + + for (const tab of tabs) { + tab.addEventListener("click", () => select(tab, false)); + + tab.addEventListener("keydown", event => { + const index = tabs.indexOf(tab); + const target = { + ArrowRight: tabs[(index + 1) % tabs.length], + ArrowLeft: tabs[(index - 1 + tabs.length) % tabs.length], + Home: tabs[0], + End: tabs.at(-1) + }[event.key]; + + if (target) { + event.preventDefault(); + select(target, true); + } + }); + } +})();