feat: Refactor dashboard template to extend base layout and improve structure

This commit is contained in:
2026-06-01 12:44:36 +02:00
parent bbc806bcef
commit b413c66ca4
2 changed files with 287 additions and 327 deletions
+128 -26
View File
@@ -3,44 +3,146 @@
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
<title>{{ title or "Arbitrade" }}</title> <title>{% block title %}{{ title or "Arbitrade" }}{% endblock %}</title>
<script src="https://unpkg.com/htmx.org@1.9.12"></script> <script src="https://unpkg.com/htmx.org@1.9.12"></script>
{% block head_scripts %}{% endblock %}
<style> <style>
:root {
--bg: #f4f7f5;
--ink: #122118;
--accent: #1f7a4c;
--card: #ffffff;
}
body { body {
margin: 0; margin: 0;
font-family: "Segoe UI", sans-serif; font-family: Arial, sans-serif;
color: var(--ink); background: #0b1220;
background: radial-gradient(circle at top, #e9f7ef, var(--bg)); color: #e5eefb;
} }
.wrap { .shell {
max-width: 720px; max-width: 1120px;
margin: 4rem auto; margin: 0 auto;
padding: 0 1rem; padding: 32px 20px 48px;
}
.hero {
display: flex;
justify-content: space-between;
gap: 24px;
align-items: end;
margin-bottom: 24px;
}
.title {
font-size: 2rem;
margin: 0 0 8px;
}
.subtitle {
margin: 0;
color: #9fb2d0;
}
.panel {
background: rgba(255, 255, 255, 0.04);
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 16px;
padding: 20px;
}
.grid {
display: grid;
gap: 16px;
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
} }
.card { .card {
background: var(--card); background: rgba(255, 255, 255, 0.04);
border: 1px solid #d8e7dd; border-radius: 14px;
border-radius: 12px; padding: 16px;
padding: 1.25rem; border: 1px solid rgba(255, 255, 255, 0.08);
box-shadow: 0 6px 24px rgba(18, 33, 24, 0.08);
} }
.badge { .label {
display: inline-block; color: #9fb2d0;
background: #d9f3e5; font-size: 0.85rem;
color: var(--accent); margin-bottom: 8px;
border-radius: 999px; }
padding: 0.2rem 0.6rem; .value {
font-size: 1.4rem;
font-weight: 700;
}
.meta {
margin-top: 18px;
color: #7f95b7;
font-size: 0.85rem; font-size: 0.85rem;
} }
.toolbar {
display: flex;
gap: 12px;
flex-wrap: wrap;
}
.toolbar form {
margin: 0;
}
.button {
display: inline-flex;
align-items: center;
justify-content: center;
border: 0;
cursor: pointer;
padding: 10px 14px;
border-radius: 999px;
background: #2d6cdf;
color: white;
text-decoration: none;
font: inherit;
}
.button.secondary {
background: transparent;
border: 1px solid rgba(255, 255, 255, 0.14);
}
.button.danger {
background: #ba3d4f;
}
.form-grid {
display: grid;
gap: 12px;
}
.field {
display: grid;
gap: 6px;
color: #9fb2d0;
font-size: 0.9rem;
}
.field input {
width: 100%;
box-sizing: border-box;
padding: 10px 12px;
border-radius: 10px;
border: 1px solid rgba(255, 255, 255, 0.14);
background: rgba(255, 255, 255, 0.04);
color: #e5eefb;
font: inherit;
}
.field.checkbox {
display: flex;
align-items: center;
gap: 8px;
}
.field.checkbox input {
width: auto;
}
.control-actions {
display: flex;
gap: 12px;
flex-wrap: wrap;
}
.chart-head {
display: flex;
justify-content: space-between;
align-items: center;
gap: 12px;
flex-wrap: wrap;
}
.chart-canvas {
width: 100%;
min-height: 260px;
}
</style> </style>
{% block extra_style %}{% endblock %}
</head> </head>
<body> <body>
<main class="wrap">{% block content %}{% endblock %}</main> <main class="{% block main_class %}shell{% endblock %}">
{% block content %}{% endblock %}
</main>
{% block scripts %}{% endblock %}
</body> </body>
</html> </html>
+159 -301
View File
@@ -1,311 +1,169 @@
<!doctype html> {% extends "base.html" %} {% block title %}{{ title }}{% endblock %} {% block
<html lang="en"> head_scripts %}
<head> <script defer src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js"></script>
<meta charset="utf-8" /> <script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.3/dist/chart.umd.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" /> {% endblock %} {% block main_class %}shell{% endblock %} {% block content %}
<title>{{ title }}</title> <section class="hero">
<script src="https://unpkg.com/htmx.org@1.9.12"></script> <div>
<script defer src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js"></script> <h1 class="title">Arbitrade Dashboard</h1>
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.3/dist/chart.umd.min.js"></script> <p class="subtitle">Live execution, P&amp;L, and system state.</p>
<style> </div>
body { <div class="toolbar">
margin: 0; <a
font-family: Arial, sans-serif; class="button"
background: #0b1220; href="{{ metrics_endpoint }}"
color: #e5eefb; hx-get="{{ metrics_endpoint }}"
} hx-target="#metrics-panel"
.shell { hx-swap="outerHTML"
max-width: 1120px; >Refresh metrics</a
margin: 0 auto; >
padding: 32px 20px 48px; <a class="button secondary" href="/health">Health</a>
} </div>
.hero { </section>
display: flex;
justify-content: space-between;
gap: 24px;
align-items: end;
margin-bottom: 24px;
}
.title {
font-size: 2rem;
margin: 0 0 8px;
}
.subtitle {
margin: 0;
color: #9fb2d0;
}
.panel {
background: rgba(255, 255, 255, 0.04);
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 16px;
padding: 20px;
}
.grid {
display: grid;
gap: 16px;
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}
.card {
background: rgba(255, 255, 255, 0.04);
border-radius: 14px;
padding: 16px;
border: 1px solid rgba(255, 255, 255, 0.08);
}
.label {
color: #9fb2d0;
font-size: 0.85rem;
margin-bottom: 8px;
}
.value {
font-size: 1.4rem;
font-weight: 700;
}
.meta {
margin-top: 18px;
color: #7f95b7;
font-size: 0.85rem;
}
.toolbar {
display: flex;
gap: 12px;
flex-wrap: wrap;
}
.toolbar form {
margin: 0;
}
.button {
display: inline-flex;
align-items: center;
justify-content: center;
border: 0;
cursor: pointer;
padding: 10px 14px;
border-radius: 999px;
background: #2d6cdf;
color: white;
text-decoration: none;
font: inherit;
}
.button.secondary {
background: transparent;
border: 1px solid rgba(255, 255, 255, 0.14);
}
.button.danger {
background: #ba3d4f;
}
.form-grid {
display: grid;
gap: 12px;
}
.field {
display: grid;
gap: 6px;
color: #9fb2d0;
font-size: 0.9rem;
}
.field input {
width: 100%;
box-sizing: border-box;
padding: 10px 12px;
border-radius: 10px;
border: 1px solid rgba(255, 255, 255, 0.14);
background: rgba(255, 255, 255, 0.04);
color: #e5eefb;
font: inherit;
}
.field.checkbox {
display: flex;
align-items: center;
gap: 8px;
}
.field.checkbox input {
width: auto;
}
.control-actions {
display: flex;
gap: 12px;
flex-wrap: wrap;
}
.chart-head {
display: flex;
justify-content: space-between;
align-items: center;
gap: 12px;
flex-wrap: wrap;
}
.chart-canvas {
width: 100%;
min-height: 260px;
}
</style>
</head>
<body>
<main class="shell">
<section class="hero">
<div>
<h1 class="title">Arbitrade Dashboard</h1>
<p class="subtitle">Live execution, P&amp;L, and system state.</p>
</div>
<div class="toolbar">
<a
class="button"
href="{{ metrics_endpoint }}"
hx-get="{{ metrics_endpoint }}"
hx-target="#metrics-panel"
hx-swap="outerHTML"
>Refresh metrics</a
>
<a class="button secondary" href="/health">Health</a>
</div>
</section>
<section <section
id="metrics-shell" id="metrics-shell"
hx-get="{{ metrics_endpoint }}" hx-get="{{ metrics_endpoint }}"
hx-target="this" hx-target="this"
hx-trigger="load, every 15s" hx-trigger="load, every 15s"
hx-swap="outerHTML" hx-swap="outerHTML"
> >
{% include "partials/metrics.html" %} {% include "partials/metrics.html" %}
</section> </section>
<section <section
id="overview-shell" id="overview-shell"
hx-get="{{ overview_endpoint }}" hx-get="{{ overview_endpoint }}"
hx-target="this" hx-target="this"
hx-trigger="load, every 10s" hx-trigger="load, every 10s"
hx-swap="outerHTML" hx-swap="outerHTML"
> >
{% include "partials/overview.html" %} {% include "partials/overview.html" %}
</section> </section>
<section <section
id="controls-shell" id="controls-shell"
hx-get="{{ controls_endpoint }}" hx-get="{{ controls_endpoint }}"
hx-target="this" hx-target="this"
hx-trigger="load, every 20s" hx-trigger="load, every 20s"
hx-swap="outerHTML" hx-swap="outerHTML"
> >
{% include "partials/controls.html" %} {% include "partials/controls.html" %}
</section> </section>
<section <section
id="charts-shell" id="charts-shell"
hx-get="{{ charts_endpoint }}" hx-get="{{ charts_endpoint }}"
hx-target="this" hx-target="this"
hx-trigger="load, every 30s" hx-trigger="load, every 30s"
hx-swap="outerHTML" hx-swap="outerHTML"
> >
{% include "partials/charts.html" %} {% include "partials/charts.html" %}
</section> </section>
{% endblock %} {% block scripts %}
<script>
window.arbitradeRenderCharts = (payload) => {
const chartHost = document.getElementById("opportunity-chart");
if (!chartHost || typeof Chart === "undefined") {
return;
}
<script> const existing = Chart.getChart(chartHost);
window.arbitradeRenderCharts = (payload) => { if (existing) {
const chartHost = document.getElementById("opportunity-chart"); existing.destroy();
if (!chartHost || typeof Chart === "undefined") { }
return;
}
const existing = Chart.getChart(chartHost); const data = JSON.parse(payload);
if (existing) { if (!data.has_chart_data) {
existing.destroy(); return;
} }
const data = JSON.parse(payload); new Chart(chartHost, {
if (!data.has_chart_data) { type: "line",
return; data: {
} labels: data.labels,
datasets: [
new Chart(chartHost, { {
type: "line", label: "Net %",
data: { data: data.net_pct_values,
labels: data.labels, borderColor: "#2d6cdf",
datasets: [ backgroundColor: "rgba(45, 108, 223, 0.18)",
{ tension: 0.3,
label: "Net %", fill: true,
data: data.net_pct_values, yAxisID: "y",
borderColor: "#2d6cdf", },
backgroundColor: "rgba(45, 108, 223, 0.18)", {
tension: 0.3, label: "Est profit USD",
fill: true, data: data.est_profit_values,
yAxisID: "y", borderColor: "#52c41a",
}, backgroundColor: "rgba(82, 196, 26, 0.12)",
{ tension: 0.3,
label: "Est profit USD", fill: false,
data: data.est_profit_values, yAxisID: "y1",
borderColor: "#52c41a", },
backgroundColor: "rgba(82, 196, 26, 0.12)", ],
tension: 0.3, },
fill: false, options: {
yAxisID: "y1", responsive: true,
}, maintainAspectRatio: false,
], interaction: {
mode: "index",
intersect: false,
},
plugins: {
legend: {
labels: {
color: "#e5eefb",
}, },
options: { },
responsive: true, },
maintainAspectRatio: false, scales: {
interaction: { x: {
mode: "index", ticks: {
intersect: false, color: "#9fb2d0",
}, maxRotation: 0,
plugins: { autoSkip: true,
legend: {
labels: {
color: "#e5eefb",
},
},
},
scales: {
x: {
ticks: {
color: "#9fb2d0",
maxRotation: 0,
autoSkip: true,
},
grid: {
color: "rgba(255, 255, 255, 0.06)",
},
},
y: {
position: "left",
ticks: {
color: "#9fb2d0",
},
grid: {
color: "rgba(255, 255, 255, 0.06)",
},
},
y1: {
position: "right",
ticks: {
color: "#9fb2d0",
},
grid: {
drawOnChartArea: false,
},
},
},
}, },
}); grid: {
}; color: "rgba(255, 255, 255, 0.06)",
},
},
y: {
position: "left",
ticks: {
color: "#9fb2d0",
},
grid: {
color: "rgba(255, 255, 255, 0.06)",
},
},
y1: {
position: "right",
ticks: {
color: "#9fb2d0",
},
grid: {
drawOnChartArea: false,
},
},
},
},
});
};
const stream = new EventSource("{{ stream_endpoint }}"); const stream = new EventSource("{{ stream_endpoint }}");
stream.addEventListener("metrics", (event) => { stream.addEventListener("metrics", (event) => {
const panel = document.getElementById("metrics-panel"); const panel = document.getElementById("metrics-panel");
if (panel) { if (panel) {
panel.outerHTML = JSON.parse(event.data); panel.outerHTML = JSON.parse(event.data);
} }
}); });
const overviewStream = new EventSource( const overviewStream = new EventSource("{{ overview_stream_endpoint }}");
"{{ overview_stream_endpoint }}", overviewStream.addEventListener("overview", (event) => {
); const panel = document.getElementById("overview-panel");
overviewStream.addEventListener("overview", (event) => { if (panel) {
const panel = document.getElementById("overview-panel"); panel.outerHTML = JSON.parse(event.data);
if (panel) { }
panel.outerHTML = JSON.parse(event.data); });
} </script>
}); {% endblock %}
</script>
</main>
</body>
</html>