Add filters to the dashboard catch list and filter by clicking top 10 rows
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8eeb7894a3
commit
9f07d41cb0
11 files changed
+771
-83
No files matched your search
@@ -1,5 +1,3 @@
|
||||
using Flypaper.Storage.Entities;
|
||||
|
||||
namespace Flypaper.Storage.Dashboard;
|
||||
|
||||
public sealed record DashboardData(
|
||||
@@ -10,7 +8,6 @@ public sealed record DashboardData(
|
||||
int UniqueIps,
|
||||
int UniqueIpsLast24Hours,
|
||||
TimeSpan TotalHoldTime,
|
||||
IReadOnlyList<TrapEventEntity> Recent,
|
||||
IReadOnlyList<TopEntry> TopIps,
|
||||
IReadOnlyList<TopEntry> TopTargets,
|
||||
IReadOnlyList<TopEntry> TopCountries,
|
||||
|
||||
@@ -6,7 +6,6 @@ namespace Flypaper.Storage.Dashboard;
|
||||
|
||||
public sealed class DashboardQueries(IDbContextFactory<FlypaperDbContext> dbContextFactory, TimeProvider timeProvider)
|
||||
{
|
||||
private const int RecentCount = 50;
|
||||
private const int TopCount = 10;
|
||||
|
||||
public async Task<DashboardData> GetAsync(CancellationToken ct = default)
|
||||
@@ -41,7 +40,6 @@ public sealed class DashboardQueries(IDbContextFactory<FlypaperDbContext> dbCont
|
||||
await events.Select(e => e.RemoteIp).Distinct().CountAsync(ct),
|
||||
await events.Where(e => e.StartedAt >= since).Select(e => e.RemoteIp).Distinct().CountAsync(ct),
|
||||
TimeSpan.FromMilliseconds(await catches.SumAsync(e => e.DurationMs, ct)),
|
||||
await events.OrderByDescending(e => e.Id).Take(RecentCount).ToListAsync(ct),
|
||||
await TopAsync(catches.GroupBy(e => e.RemoteIp), ct),
|
||||
await TopAsync(catches.Where(e => e.Target != null).GroupBy(e => e.Target!), ct),
|
||||
countries
|
||||
@@ -54,6 +52,71 @@ public sealed class DashboardQueries(IDbContextFactory<FlypaperDbContext> dbCont
|
||||
countries.ToDictionary(x => x.Key, x => x.Count, StringComparer.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
public async Task<RecentCatches> GetRecentAsync(RecentFilter filter, CancellationToken ct = default)
|
||||
{
|
||||
await using var db = await dbContextFactory.CreateDbContextAsync(ct);
|
||||
var events = Apply(db.TrapEvents.AsNoTracking(), filter);
|
||||
|
||||
var countries = await db.TrapEvents
|
||||
.Where(e => e.CountryCode != null)
|
||||
.GroupBy(e => e.CountryCode!)
|
||||
.Select(g => new CountryOption(g.Key, g.Max(e => e.Country)))
|
||||
.ToListAsync(ct);
|
||||
|
||||
return new RecentCatches(
|
||||
await events.OrderByDescending(e => e.StartedAt).ThenByDescending(e => e.Id)
|
||||
.Take(Math.Clamp(filter.Limit, 1, RecentFilter.MaxLimit))
|
||||
.ToListAsync(ct),
|
||||
await events.CountAsync(ct),
|
||||
countries);
|
||||
}
|
||||
|
||||
private IQueryable<TrapEventEntity> Apply(IQueryable<TrapEventEntity> events, RecentFilter filter)
|
||||
{
|
||||
if (filter.Window is { } window)
|
||||
{
|
||||
var since = timeProvider.GetUtcNow().UtcDateTime - window;
|
||||
events = events.Where(e => e.StartedAt >= since);
|
||||
}
|
||||
|
||||
if (filter.Outcome is { } outcome)
|
||||
{
|
||||
events = events.Where(e => e.Outcome == outcome);
|
||||
}
|
||||
|
||||
if (filter.CountryCode is { } country)
|
||||
{
|
||||
events = events.Where(e => e.CountryCode == country);
|
||||
}
|
||||
|
||||
if (filter.Asn is { } asn)
|
||||
{
|
||||
events = events.Where(e => e.Asn == asn);
|
||||
}
|
||||
|
||||
if (filter.Ip is { } ip)
|
||||
{
|
||||
events = events.Where(e => e.RemoteIp == ip);
|
||||
}
|
||||
|
||||
if (filter.Target is { } target)
|
||||
{
|
||||
events = events.Where(e => e.Target == target);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(filter.Search))
|
||||
{
|
||||
var pattern = $"%{filter.Search.Trim().Replace("\\", "\\\\").Replace("%", "\\%").Replace("_", "\\_")}%";
|
||||
events = events.Where(e =>
|
||||
EF.Functions.Like(e.RemoteIp, pattern, "\\")
|
||||
|| EF.Functions.Like(e.Provider!, pattern, "\\")
|
||||
|| EF.Functions.Like(e.Target!, pattern, "\\")
|
||||
|| EF.Functions.Like(e.ClientInfo!, pattern, "\\"));
|
||||
}
|
||||
|
||||
return events;
|
||||
}
|
||||
|
||||
private static async Task<IReadOnlyList<TopEntry>> TopAsync(
|
||||
IQueryable<IGrouping<string, TrapEventEntity>> groups,
|
||||
CancellationToken ct)
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
using Flypaper.Core.Models;
|
||||
using Flypaper.Storage.Entities;
|
||||
|
||||
namespace Flypaper.Storage.Dashboard;
|
||||
|
||||
public sealed record RecentFilter(
|
||||
TimeSpan? Window = null,
|
||||
TrapOutcome? Outcome = null,
|
||||
string? CountryCode = null,
|
||||
long? Asn = null,
|
||||
string? Ip = null,
|
||||
string? Target = null,
|
||||
string? Search = null,
|
||||
int Limit = RecentFilter.DefaultLimit)
|
||||
{
|
||||
public const int DefaultLimit = 50;
|
||||
public const int MaxLimit = 500;
|
||||
}
|
||||
|
||||
public sealed record RecentCatches(IReadOnlyList<TrapEventEntity> Items, int Total, IReadOnlyList<CountryOption> Countries);
|
||||
|
||||
public sealed record CountryOption(string Code, string? Name);
|
||||
@@ -0,0 +1,120 @@
|
||||
using System.Globalization;
|
||||
using System.Net;
|
||||
using Flypaper.Core.Models;
|
||||
using Flypaper.Storage.Dashboard;
|
||||
|
||||
namespace Flypaper.Web.Components.Pages.Dashboard;
|
||||
|
||||
public sealed record DashboardFilter(
|
||||
string? Zeit = null,
|
||||
string? Ausgang = null,
|
||||
string? Land = null,
|
||||
string? Provider = null,
|
||||
string? Ip = null,
|
||||
string? Ziel = null,
|
||||
string? Q = null,
|
||||
int Limit = RecentFilter.DefaultLimit)
|
||||
{
|
||||
public const string Anchor = "faenge";
|
||||
|
||||
public static readonly IReadOnlyList<(string Value, string Label)> Periods = [("", "Alles"), ("24h", "24 h"), ("7d", "7 Tage")];
|
||||
|
||||
public static readonly IReadOnlyList<(string Value, string Label)> Outcomes =
|
||||
[("", "Alle"), ("aufgegeben", "Aufgegeben"), ("zeitlimit", "Zeitlimit"), ("abgelehnt", "Abgelehnt")];
|
||||
|
||||
public bool IsEmpty => this with { Limit = RecentFilter.DefaultLimit } == new DashboardFilter();
|
||||
|
||||
public static DashboardFilter Parse(
|
||||
string? zeit,
|
||||
string? ausgang,
|
||||
string? land,
|
||||
string? provider,
|
||||
string? ip,
|
||||
string? ziel,
|
||||
string? q,
|
||||
string? limit)
|
||||
{
|
||||
var parsedLimit = int.TryParse(limit, NumberStyles.None, CultureInfo.InvariantCulture, out var value)
|
||||
? Math.Clamp(value, 1, RecentFilter.MaxLimit)
|
||||
: RecentFilter.DefaultLimit;
|
||||
|
||||
return new DashboardFilter(
|
||||
Known(Periods, zeit),
|
||||
Known(Outcomes, ausgang),
|
||||
Clean(land) is { Length: 2 } country && country.All(char.IsAsciiLetter) ? country.ToUpperInvariant() : null,
|
||||
Asn(provider) is { } asn ? $"AS{asn.ToString(CultureInfo.InvariantCulture)}" : null,
|
||||
IPAddress.TryParse(Clean(ip), out var address) ? address.ToString() : null,
|
||||
Clean(ziel),
|
||||
Clean(q),
|
||||
parsedLimit);
|
||||
}
|
||||
|
||||
public RecentFilter ToRecentFilter() => new(
|
||||
Zeit switch
|
||||
{
|
||||
"24h" => TimeSpan.FromHours(24),
|
||||
"7d" => TimeSpan.FromDays(7),
|
||||
_ => null
|
||||
},
|
||||
Ausgang switch
|
||||
{
|
||||
"aufgegeben" => TrapOutcome.ClientAborted,
|
||||
"zeitlimit" => TrapOutcome.Timeout,
|
||||
"abgelehnt" => TrapOutcome.Rejected,
|
||||
_ => null
|
||||
},
|
||||
Land,
|
||||
Asn(Provider),
|
||||
Ip,
|
||||
Ziel,
|
||||
Q,
|
||||
Limit);
|
||||
|
||||
public int NextLimit => Math.Min(Limit * 2, RecentFilter.MaxLimit);
|
||||
|
||||
public string Href(string anchor = Anchor)
|
||||
{
|
||||
var parts = new List<string>();
|
||||
Add(parts, "zeit", Zeit);
|
||||
Add(parts, "ausgang", Ausgang);
|
||||
Add(parts, "land", Land);
|
||||
Add(parts, "provider", Provider);
|
||||
Add(parts, "ip", Ip);
|
||||
Add(parts, "ziel", Ziel);
|
||||
Add(parts, "q", Q);
|
||||
if (Limit != RecentFilter.DefaultLimit)
|
||||
{
|
||||
Add(parts, "limit", Limit.ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
return parts.Count == 0 ? $"/#{anchor}" : $"/?{string.Join("&", parts)}#{anchor}";
|
||||
}
|
||||
|
||||
private static void Add(List<string> parts, string name, string? value)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(value))
|
||||
{
|
||||
parts.Add($"{name}={Uri.EscapeDataString(value)}");
|
||||
}
|
||||
}
|
||||
|
||||
private static string? Known(IReadOnlyList<(string Value, string Label)> options, string? value)
|
||||
{
|
||||
var clean = Clean(value)?.ToLowerInvariant();
|
||||
return clean is not null && options.Any(o => o.Value == clean) ? clean : null;
|
||||
}
|
||||
|
||||
private static long? Asn(string? value)
|
||||
{
|
||||
var clean = Clean(value);
|
||||
if (clean is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var digits = clean.StartsWith("AS", StringComparison.OrdinalIgnoreCase) ? clean[2..] : clean;
|
||||
return long.TryParse(digits, NumberStyles.None, CultureInfo.InvariantCulture, out var asn) ? asn : null;
|
||||
}
|
||||
|
||||
private static string? Clean(string? value) => string.IsNullOrWhiteSpace(value) ? null : value.Trim();
|
||||
}
|
||||
@@ -67,7 +67,10 @@
|
||||
<section class="origin">
|
||||
<WorldMap CatchesByCountry="data.CatchesByCountry" />
|
||||
<section class="card tops-card">
|
||||
<h2 id="tops-title">Top 10</h2>
|
||||
<div class="card-head">
|
||||
<h2 id="tops-title">Top 10</h2>
|
||||
<span class="hint">Klick filtert die Fänge</span>
|
||||
</div>
|
||||
<div class="tabs" role="tablist" aria-labelledby="tops-title">
|
||||
@foreach (var tab in tabs)
|
||||
{
|
||||
@@ -78,73 +81,148 @@
|
||||
@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" />
|
||||
<TopTable KeyLabel="@tab.KeyLabel" Entries="tab.Entries" ShowFlags="tab.ShowFlags" KeyFormatter="tab.KeyFormatter" LabelFormatter="tab.LabelFormatter"
|
||||
Href="entry => TopFilter(tab, entry).Href()" IsActive="entry => tab.Current(_filter) == entry.Key" />
|
||||
</div>
|
||||
}
|
||||
</section>
|
||||
</section>
|
||||
|
||||
@if (data.TotalCatches > 0)
|
||||
@if (data.TotalCatches > 0 || data.Rejected > 0)
|
||||
{
|
||||
<section class="card">
|
||||
var recent = _recent!;
|
||||
<section class="card recent-card" id="@DashboardFilter.Anchor">
|
||||
<div class="card-head">
|
||||
<h2>Letzte 50 Fänge</h2>
|
||||
<span class="hint">Zeile anklicken zum Aufklappen</span>
|
||||
<h2>Fänge <span class="count">· @Formatting.Number(recent.Total) Treffer</span></h2>
|
||||
<span class="hint">Filter gelten nur für diese Liste</span>
|
||||
</div>
|
||||
<div class="scroll">
|
||||
<table class="recent-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="c-time">Zeit</th>
|
||||
<th class="c-ip">IP</th>
|
||||
<th class="c-origin">Herkunft</th>
|
||||
<th class="c-provider">Provider</th>
|
||||
<th class="c-target">Ziel</th>
|
||||
<th class="c-agent">User-Agent</th>
|
||||
<th class="c-duration num">Dauer</th>
|
||||
<th class="c-bytes num">Bytes</th>
|
||||
<th class="c-outcome">Ausgang</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var trapEvent in data.Recent)
|
||||
<form class="filters" method="get" action="/#@DashboardFilter.Anchor">
|
||||
<label>
|
||||
<span>Zeitraum</span>
|
||||
<select name="zeit" data-autosubmit>
|
||||
@foreach (var (value, label) in DashboardFilter.Periods)
|
||||
{
|
||||
var started = trapEvent.StartedAt.ToLocalTime();
|
||||
var provider = Formatting.Provider(trapEvent.Asn, trapEvent.Provider);
|
||||
var target = Formatting.Target(trapEvent.Target);
|
||||
var duration = Formatting.Duration(TimeSpan.FromMilliseconds(trapEvent.DurationMs));
|
||||
var bytes = Formatting.Number(trapEvent.BytesSent);
|
||||
<tr data-expand="event:@trapEvent.Id" tabindex="0" aria-expanded="false" class="@(trapEvent.Outcome == TrapOutcome.Rejected ? "rejected" : null)">
|
||||
<td class="c-time"><span class="c-date">@started.ToString("dd.MM.") </span>@started.ToString("HH:mm:ss")</td>
|
||||
<td class="c-ip mono" title="@trapEvent.RemoteIp">@trapEvent.RemoteIp</td>
|
||||
<td class="c-origin" title="@Origin(trapEvent)">
|
||||
@if (trapEvent.CountryCode is { } countryCode)
|
||||
{
|
||||
@($"{Formatting.Flag(countryCode)} {countryCode}")
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="muted">–</span>
|
||||
}
|
||||
</td>
|
||||
<td class="c-provider" title="@provider">@provider</td>
|
||||
<td class="c-target mono" title="@target">
|
||||
@target
|
||||
<div class="extra extra-md">Provider: @(provider ?? "–")</div>
|
||||
<div class="extra extra-md">User-Agent: @(trapEvent.ClientInfo ?? "–")</div>
|
||||
<div class="extra extra-all">Herkunft: @(trapEvent.CountryCode is { } code ? $"{Formatting.Flag(code)} {code} · {Origin(trapEvent)}" : "–")</div>
|
||||
<div class="extra extra-sm">Dauer: @duration · Bytes: @bytes</div>
|
||||
<div class="extra extra-xs">Datum: @started.ToString("dd.MM.yyyy") · Ausgang: @OutcomeLabel(trapEvent.Outcome)</div>
|
||||
</td>
|
||||
<td class="c-agent" title="@trapEvent.ClientInfo">@trapEvent.ClientInfo</td>
|
||||
<td class="c-duration num">@duration</td>
|
||||
<td class="c-bytes num">@bytes</td>
|
||||
<td class="c-outcome"><span class="outcome @trapEvent.Outcome.ToString().ToLowerInvariant()">@OutcomeLabel(trapEvent.Outcome)</span></td>
|
||||
</tr>
|
||||
<option value="@value" selected="@(value == (_filter.Zeit ?? ""))">@label</option>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</select>
|
||||
</label>
|
||||
<label>
|
||||
<span>Ausgang</span>
|
||||
<select name="ausgang" data-autosubmit>
|
||||
@foreach (var (value, label) in DashboardFilter.Outcomes)
|
||||
{
|
||||
<option value="@value" selected="@(value == (_filter.Ausgang ?? ""))">@label</option>
|
||||
}
|
||||
</select>
|
||||
</label>
|
||||
<label>
|
||||
<span>Land</span>
|
||||
<select name="land" data-autosubmit>
|
||||
<option value="" selected="@(_filter.Land is null)">Alle</option>
|
||||
@foreach (var country in recent.Countries.OrderBy(c => CountryNames.Display(c.Code, c.Name), StringComparer.CurrentCulture))
|
||||
{
|
||||
<option value="@country.Code" selected="@(country.Code == _filter.Land)">@Formatting.Flag(country.Code) @CountryNames.Display(country.Code, country.Name)</option>
|
||||
}
|
||||
</select>
|
||||
</label>
|
||||
<label class="filter-search">
|
||||
<span>Suche</span>
|
||||
<input type="search" name="q" value="@_filter.Q" placeholder="IP, Provider, Ziel, User-Agent" />
|
||||
</label>
|
||||
@foreach (var (name, value) in new[] { ("provider", _filter.Provider), ("ip", _filter.Ip), ("ziel", _filter.Ziel) })
|
||||
{
|
||||
if (value is not null)
|
||||
{
|
||||
<input type="hidden" name="@name" value="@value" />
|
||||
}
|
||||
}
|
||||
<button type="submit">Filtern</button>
|
||||
</form>
|
||||
@if (!_filter.IsEmpty)
|
||||
{
|
||||
<div class="chips">
|
||||
@foreach (var (label, without) in Chips())
|
||||
{
|
||||
<a class="chip" href="@without.Href()" title="Filter entfernen">@label <span aria-hidden="true">✕</span></a>
|
||||
}
|
||||
<a class="chip-reset" href="@(new DashboardFilter().Href())">Alle Filter zurücksetzen</a>
|
||||
</div>
|
||||
}
|
||||
@if (recent.Items.Count == 0)
|
||||
{
|
||||
<p class="empty">Keine Fänge für diese Filter. <a href="@(new DashboardFilter().Href())">Filter zurücksetzen</a></p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="scroll">
|
||||
<table class="recent-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="c-time">Zeit</th>
|
||||
<th class="c-ip">IP</th>
|
||||
<th class="c-origin">Herkunft</th>
|
||||
<th class="c-provider">Provider</th>
|
||||
<th class="c-target">Ziel</th>
|
||||
<th class="c-agent">User-Agent</th>
|
||||
<th class="c-duration num">Dauer</th>
|
||||
<th class="c-bytes num">Bytes</th>
|
||||
<th class="c-outcome">Ausgang</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var (trapEvent, index) in recent.Items.Select((trapEvent, index) => (trapEvent, index)))
|
||||
{
|
||||
var started = trapEvent.StartedAt.ToLocalTime();
|
||||
var provider = Formatting.Provider(trapEvent.Asn, trapEvent.Provider);
|
||||
var target = Formatting.Target(trapEvent.Target);
|
||||
var duration = Formatting.Duration(TimeSpan.FromMilliseconds(trapEvent.DurationMs));
|
||||
var bytes = Formatting.Number(trapEvent.BytesSent);
|
||||
<tr id="f@(index)" data-expand="event:@trapEvent.Id" tabindex="0" aria-expanded="false" class="@(trapEvent.Outcome == TrapOutcome.Rejected ? "rejected" : null)">
|
||||
<td class="c-time"><span class="c-date">@started.ToString("dd.MM.") </span>@started.ToString("HH:mm:ss")</td>
|
||||
<td class="c-ip mono" title="@trapEvent.RemoteIp">@trapEvent.RemoteIp</td>
|
||||
<td class="c-origin" title="@Origin(trapEvent)">
|
||||
@if (trapEvent.CountryCode is { } countryCode)
|
||||
{
|
||||
@($"{Formatting.Flag(countryCode)} {countryCode}")
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="muted">–</span>
|
||||
}
|
||||
</td>
|
||||
<td class="c-provider" title="@provider">@provider</td>
|
||||
<td class="c-target mono" title="@target">
|
||||
@target
|
||||
<div class="extra extra-md">Provider: @(provider ?? "–")</div>
|
||||
<div class="extra extra-md">User-Agent: @(trapEvent.ClientInfo ?? "–")</div>
|
||||
<div class="extra extra-all">Herkunft: @(trapEvent.CountryCode is { } code ? $"{Formatting.Flag(code)} {code} · {Origin(trapEvent)}" : "–")</div>
|
||||
<div class="extra extra-sm">Dauer: @duration · Bytes: @bytes</div>
|
||||
<div class="extra extra-xs">Datum: @started.ToString("dd.MM.yyyy") · Ausgang: @OutcomeLabel(trapEvent.Outcome)</div>
|
||||
</td>
|
||||
<td class="c-agent" title="@trapEvent.ClientInfo">@trapEvent.ClientInfo</td>
|
||||
<td class="c-duration num">@duration</td>
|
||||
<td class="c-bytes num">@bytes</td>
|
||||
<td class="c-outcome"><span class="outcome @trapEvent.Outcome.ToString().ToLowerInvariant()">@OutcomeLabel(trapEvent.Outcome)</span></td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
@if (recent.Total > recent.Items.Count)
|
||||
{
|
||||
<div class="more">
|
||||
<span class="muted">@Formatting.Number(recent.Items.Count) von @Formatting.Number(recent.Total)</span>
|
||||
@if (_filter.Limit < RecentFilter.MaxLimit)
|
||||
{
|
||||
<a class="button ghost" href="@((_filter with { Limit = _filter.NextLimit }).Href($"f{recent.Items.Count}"))">Weitere laden</a>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="muted">· Für ältere Fänge die Filter eingrenzen</span>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
}
|
||||
</section>
|
||||
}
|
||||
}
|
||||
@@ -153,26 +231,91 @@
|
||||
|
||||
@code {
|
||||
private DashboardData? _data;
|
||||
private RecentCatches? _recent;
|
||||
private DashboardFilter _filter = new();
|
||||
private DateTime _loadedAt;
|
||||
|
||||
[SupplyParameterFromQuery(Name = "zeit")] public string? Zeit { get; set; }
|
||||
|
||||
[SupplyParameterFromQuery(Name = "ausgang")] public string? Ausgang { get; set; }
|
||||
|
||||
[SupplyParameterFromQuery(Name = "land")] public string? Land { get; set; }
|
||||
|
||||
[SupplyParameterFromQuery(Name = "provider")] public string? Provider { get; set; }
|
||||
|
||||
[SupplyParameterFromQuery(Name = "ip")] public string? Ip { get; set; }
|
||||
|
||||
[SupplyParameterFromQuery(Name = "ziel")] public string? Ziel { get; set; }
|
||||
|
||||
[SupplyParameterFromQuery(Name = "q")] public string? Q { get; set; }
|
||||
|
||||
[SupplyParameterFromQuery(Name = "limit")] public string? Limit { get; set; }
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
_filter = DashboardFilter.Parse(Zeit, Ausgang, Land, Provider, Ip, Ziel, Q, Limit);
|
||||
_data = await Queries.GetAsync();
|
||||
_recent = await Queries.GetRecentAsync(_filter.ToRecentFilter());
|
||||
_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)
|
||||
new("countries", "Länder", "Land", data.TopCountries, f => f.Land, (f, key) => f with { Land = key }, ShowFlags: true, LabelFormatter: CountryNames.Display),
|
||||
new("providers", "Provider", "Provider", data.TopProviders, f => f.Provider, (f, key) => f with { Provider = key }),
|
||||
new("ips", "IPs", "IP", data.TopIps, f => f.Ip, (f, key) => f with { Ip = key }),
|
||||
new("targets", "Ziele", "Ziel", data.TopTargets, f => f.Ziel, (f, key) => f with { Ziel = key }, KeyFormatter: Formatting.Target)
|
||||
];
|
||||
|
||||
private DashboardFilter TopFilter(TopTab tab, TopEntry entry) =>
|
||||
tab.Set(_filter with { Limit = RecentFilter.DefaultLimit }, tab.Current(_filter) == entry.Key ? null : entry.Key);
|
||||
|
||||
private IEnumerable<(string Label, DashboardFilter Without)> Chips()
|
||||
{
|
||||
var reset = _filter with { Limit = RecentFilter.DefaultLimit };
|
||||
if (_filter.Zeit is { } zeit)
|
||||
{
|
||||
yield return ($"Zeitraum: {DashboardFilter.Periods.First(p => p.Value == zeit).Label}", reset with { Zeit = null });
|
||||
}
|
||||
|
||||
if (_filter.Ausgang is { } ausgang)
|
||||
{
|
||||
yield return ($"Ausgang: {DashboardFilter.Outcomes.First(o => o.Value == ausgang).Label}", reset with { Ausgang = null });
|
||||
}
|
||||
|
||||
if (_filter.Land is { } land)
|
||||
{
|
||||
var name = _recent?.Countries.FirstOrDefault(c => c.Code == land)?.Name;
|
||||
yield return ($"Land: {CountryNames.Display(land, name)}", reset with { Land = null });
|
||||
}
|
||||
|
||||
if (_filter.Provider is { } provider)
|
||||
{
|
||||
var name = _data?.TopProviders.FirstOrDefault(p => p.Key == provider)?.Label
|
||||
?? _recent?.Items.FirstOrDefault()?.Provider;
|
||||
yield return ($"Provider: {(name is null ? provider : $"{name} ({provider})")}", reset with { Provider = null });
|
||||
}
|
||||
|
||||
if (_filter.Ip is { } ip)
|
||||
{
|
||||
yield return ($"IP: {ip}", reset with { Ip = null });
|
||||
}
|
||||
|
||||
if (_filter.Ziel is { } ziel)
|
||||
{
|
||||
yield return ($"Ziel: {Formatting.Target(ziel)}", reset with { Ziel = null });
|
||||
}
|
||||
|
||||
if (_filter.Q is { } q)
|
||||
{
|
||||
yield return ($"Suche: „{q}“", reset with { Q = null });
|
||||
}
|
||||
}
|
||||
|
||||
private static string OutcomeLabel(TrapOutcome outcome) => outcome switch
|
||||
{
|
||||
TrapOutcome.Timeout => "Zeitlimit",
|
||||
TrapOutcome.ClientAborted => "Abgebrochen",
|
||||
TrapOutcome.ClientAborted => "Aufgegeben",
|
||||
TrapOutcome.Rejected => "Abgelehnt",
|
||||
TrapOutcome.Completed => "Beendet",
|
||||
_ => outcome.ToString()
|
||||
@@ -186,6 +329,8 @@
|
||||
string Label,
|
||||
string KeyLabel,
|
||||
IReadOnlyList<TopEntry> Entries,
|
||||
Func<DashboardFilter, string?> Current,
|
||||
Func<DashboardFilter, string?, DashboardFilter> Set,
|
||||
bool ShowFlags = false,
|
||||
Func<string?, string?>? KeyFormatter = null,
|
||||
Func<string?, string?, string?>? LabelFormatter = null);
|
||||
|
||||
@@ -28,21 +28,25 @@ else
|
||||
var key = KeyFormatter?.Invoke(entry.Key) ?? entry.Key;
|
||||
var label = LabelFormatter is null ? entry.Label : LabelFormatter(entry.Key, entry.Label);
|
||||
var share = (entry.Count * 100.0 / Entries[0].Count).ToString("0.#", CultureInfo.InvariantCulture);
|
||||
<tr data-expand="@($"{KeyLabel}:{entry.Key}")" tabindex="0" aria-expanded="false">
|
||||
<td class="clip" title="@(label is null ? key : $"{label} · {key}")">
|
||||
@if (ShowFlags)
|
||||
{
|
||||
<span class="flag">@Formatting.Flag(entry.Key)</span>
|
||||
}
|
||||
@if (label is not null)
|
||||
{
|
||||
<span class="top-label">@label</span>
|
||||
<span class="top-key mono">@key</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="mono">@key</span>
|
||||
}
|
||||
var active = IsActive(entry);
|
||||
var title = label is null ? key : $"{label} · {key}";
|
||||
<tr data-href="@Href(entry)" class="@(active ? "active" : null)">
|
||||
<td class="clip" title="@title">
|
||||
<a href="@Href(entry)" aria-current="@(active ? "true" : null)" title="@(active ? $"Filter {title} entfernen" : $"Fänge filtern: {title}")">
|
||||
@if (ShowFlags)
|
||||
{
|
||||
<span class="flag">@Formatting.Flag(entry.Key)</span>
|
||||
}
|
||||
@if (label is not null)
|
||||
{
|
||||
<span class="top-label">@label</span>
|
||||
<span class="top-key mono">@key</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="mono">@key</span>
|
||||
}
|
||||
</a>
|
||||
</td>
|
||||
<td><span class="share-bar" style="--share: @(share)%"></span></td>
|
||||
<td class="num">@Formatting.Number(entry.Count)</td>
|
||||
@@ -63,4 +67,8 @@ else
|
||||
[Parameter] public Func<string?, string?>? KeyFormatter { get; set; }
|
||||
|
||||
[Parameter] public Func<string?, string?, string?>? LabelFormatter { get; set; }
|
||||
|
||||
[Parameter, EditorRequired] public required Func<TopEntry, string> Href { get; set; }
|
||||
|
||||
[Parameter, EditorRequired] public required Func<TopEntry, bool> IsActive { get; set; }
|
||||
}
|
||||
@@ -266,6 +266,143 @@ code {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.top-table tr[data-href] {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.top-table tr[data-href]:hover td {
|
||||
background-color: color-mix(in srgb, var(--text) 4%, transparent);
|
||||
}
|
||||
|
||||
.top-table tr.active td {
|
||||
background-color: color-mix(in srgb, var(--accent) 12%, transparent);
|
||||
}
|
||||
|
||||
.top-table tr.active td:first-child {
|
||||
box-shadow: inset 3px 0 0 var(--accent);
|
||||
}
|
||||
|
||||
.top-table td a {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.top-table td a:focus-visible {
|
||||
outline: 2px solid var(--accent);
|
||||
outline-offset: 2px;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.recent-card {
|
||||
scroll-margin-top: 16px;
|
||||
}
|
||||
|
||||
.recent-card h2 .count {
|
||||
color: var(--muted);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.recent-table tr[id] {
|
||||
scroll-margin-top: 80px;
|
||||
}
|
||||
|
||||
.filters {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(110px, 140px) minmax(120px, 150px) minmax(160px, 230px) minmax(180px, 1fr) auto;
|
||||
gap: 10px;
|
||||
align-items: end;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.filters label {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
min-width: 0;
|
||||
color: var(--muted);
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.filters button {
|
||||
border: 1px solid var(--border);
|
||||
background: var(--surface);
|
||||
color: var(--text);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.filters button:hover {
|
||||
border-color: var(--accent);
|
||||
}
|
||||
|
||||
.filters select,
|
||||
.filters input {
|
||||
padding: 7px 10px;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.chips {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 6px 8px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.chip {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
max-width: 100%;
|
||||
padding: 3px 6px 3px 10px;
|
||||
overflow: hidden;
|
||||
border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--border));
|
||||
border-radius: 999px;
|
||||
background: color-mix(in srgb, var(--accent) 10%, transparent);
|
||||
color: var(--text);
|
||||
font-size: 12.5px;
|
||||
text-decoration: none;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.chip span {
|
||||
color: var(--muted);
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.chip:hover span {
|
||||
color: var(--text);
|
||||
}
|
||||
|
||||
.chip-reset {
|
||||
color: var(--muted);
|
||||
font-size: 12.5px;
|
||||
}
|
||||
|
||||
.more {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 12px;
|
||||
padding-top: 14px;
|
||||
}
|
||||
|
||||
a.button {
|
||||
display: inline-block;
|
||||
padding: 7px 14px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 6px;
|
||||
color: var(--text);
|
||||
font-weight: 500;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a.button:hover {
|
||||
border-color: var(--accent);
|
||||
}
|
||||
|
||||
.share-bar {
|
||||
display: block;
|
||||
height: 6px;
|
||||
@@ -823,6 +960,14 @@ button.danger {
|
||||
.origin {
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
}
|
||||
|
||||
.filters {
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
.filter-search {
|
||||
grid-column: 1 / 3;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 599px) {
|
||||
@@ -843,6 +988,15 @@ button.danger {
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.filters {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
.filter-search,
|
||||
.filters button {
|
||||
grid-column: 1 / -1;
|
||||
}
|
||||
|
||||
.top-table .share,
|
||||
.top-table th:nth-child(2),
|
||||
.top-table td:nth-child(2),
|
||||
|
||||
@@ -108,3 +108,29 @@
|
||||
});
|
||||
}
|
||||
})();
|
||||
|
||||
(() => {
|
||||
const form = document.querySelector("form.filters");
|
||||
if (form) {
|
||||
form.addEventListener("submit", () => {
|
||||
for (const field of form.elements) {
|
||||
if (field.name && field.value === "") {
|
||||
field.disabled = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
for (const select of form.querySelectorAll("select[data-autosubmit]")) {
|
||||
select.addEventListener("change", () => form.requestSubmit());
|
||||
}
|
||||
}
|
||||
|
||||
for (const row of document.querySelectorAll("tr[data-href]")) {
|
||||
row.addEventListener("click", event => {
|
||||
if (event.target.closest("a") || !window.getSelection()?.isCollapsed) {
|
||||
return;
|
||||
}
|
||||
window.location.href = row.dataset.href;
|
||||
});
|
||||
}
|
||||
})();
|
||||
Reference in new issue
Block a user