Refactor UI assets and harden quality checks

This commit is contained in:
StasonJatham committed 2026-06-17 23:18:00 +02:00
1 parent 23ab466c52
commit 4ecc8eb874
62 files changed
+3314 -3206

No files matched your search

+51 -18
View File
@@ -1,12 +1,49 @@
from __future__ import annotations
from collections.abc import Mapping
from dataclasses import dataclass
from datetime import datetime
from .components import _event_label
from .html_utils import attr, escape
@dataclass(frozen=True, slots=True)
class _AdminEventRow:
created_raw: str
hostname_raw: str
detail_raw: str
created: str
hostname: str
status: str
ipv4: str
ipv6: str
count: str
detail: str
def _admin_event_row_view(event: Mapping[str, object]) -> _AdminEventRow:
created_raw = _event_text(event, "created_at")
hostname_raw = _event_text(event, "hostname")
detail_raw = _event_text(event, "detail")
return _AdminEventRow(
created_raw=created_raw,
hostname_raw=hostname_raw,
detail_raw=detail_raw,
created=escape(_short_time(created_raw)),
hostname=escape(hostname_raw),
status=escape(_event_label(event.get("status"))),
ipv4=escape(_event_text(event, "ipv4")),
ipv6=escape(_event_text(event, "ipv6")),
count=escape(event.get("count") or 1),
detail=escape(detail_raw),
)
def _event_text(event: Mapping[str, object], key: str) -> str:
return str(event.get(key) or "-")
def _account_row(account: Mapping[str, object], csrf: str = "", admin_path: str = "/admin") -> str:
raw_hostname = str(account["hostname"])
hostname = escape(raw_hostname)
@@ -30,15 +67,18 @@ def _account_row(account: Mapping[str, object], csrf: str = "", admin_path: str
<form method="post" action="{safe_admin_path}/hostnames/rotate" class="admin-action-group">
<input type="hidden" name="csrf" value="{attr(csrf)}">
<input type="hidden" name="hostname" value="{hostname_attr}">
<button name="action" value="update" class="btn btn-sm btn-light rounded-pill" title="Create a new update URL" aria-label="New update URL for {hostname_attr}">Update URL</button>
<button name="action" value="management" class="btn btn-sm btn-light rounded-pill" title="Create a new dashboard link" aria-label="New dashboard link for {hostname_attr}">Dashboard</button>
<button name="action" value="update" class="btn btn-sm btn-light rounded-pill"
title="Create a new update URL" aria-label="New update URL for {hostname_attr}">Update URL</button>
<button name="action" value="management" class="btn btn-sm btn-light rounded-pill"
title="Create a new dashboard link" aria-label="New dashboard link for {hostname_attr}">Dashboard</button>
</form>
</td>
<td class="cell-delete">
<form method="post" action="{safe_admin_path}/hostnames/delete">
<input type="hidden" name="csrf" value="{attr(csrf)}">
<input type="hidden" name="hostname" value="{hostname_attr}">
<button class="btn btn-sm btn-outline-danger rounded-pill" title="Delete hostname" aria-label="Delete {hostname_attr}">Delete</button>
<button class="btn btn-sm btn-outline-danger rounded-pill" title="Delete hostname"
aria-label="Delete {hostname_attr}">Delete</button>
</form>
</td>
</tr>
@@ -53,7 +93,8 @@ def _admin_table_toolbar(table_id: str, search_label: str) -> str:
<div class="d-flex align-items-center justify-content-between gap-3 flex-column flex-md-row mb-3">
<label class="w-100 mb-0" for="{safe_id}-search">
<span class="visually-hidden">{safe_label}</span>
<input id="{safe_id}-search" class="form-control" type="search" placeholder="{safe_label}" data-table-search autocomplete="off">
<input id="{safe_id}-search" class="form-control" type="search" placeholder="{safe_label}"
data-table-search autocomplete="off">
</label>
<div class="d-flex align-items-center gap-2 flex-shrink-0">
<span class="small text-secondary text-nowrap" data-table-count>0-0 of 0</span>
@@ -79,21 +120,13 @@ def _admin_table_pagination() -> str:
def _event_row(event: Mapping[str, object]) -> str:
created_raw = str(event.get("created_at") or "-")
hostname_raw = str(event.get("hostname") or "-")
detail_raw = str(event.get("detail") or "-")
created = escape(_short_time(created_raw))
hostname = escape(hostname_raw)
status = escape(_event_label(event.get("status")))
ipv4 = escape(event.get("ipv4") or "-")
ipv6 = escape(event.get("ipv6") or "-")
count = escape(event.get("count") or 1)
detail = escape(detail_raw)
row = _admin_event_row_view(event)
return (
f'<tr><td class="cell-time" title="{attr(created_raw)}">{created}</td>'
f'<td class="cell-hostname" title="{attr(hostname_raw)}">{hostname}</td>'
f'<td class="cell-status">{status}</td><td class="cell-ip">{ipv4}</td><td class="cell-ip">{ipv6}</td>'
f'<td class="cell-count">{count}</td><td class="cell-detail" title="{attr(detail_raw)}">{detail}</td></tr>'
f'<tr><td class="cell-time" title="{attr(row.created_raw)}">{row.created}</td>'
f'<td class="cell-hostname" title="{attr(row.hostname_raw)}">{row.hostname}</td>'
f'<td class="cell-status">{row.status}</td><td class="cell-ip">{row.ipv4}</td>'
f'<td class="cell-ip">{row.ipv6}</td><td class="cell-count">{row.count}</td>'
f'<td class="cell-detail" title="{attr(row.detail_raw)}">{row.detail}</td></tr>'
)