Files
vctp2/components/views/snapshots.templ
T
nathan 98e92a8264
continuous-integration/drone/push Build is passing
updated UI
2026-04-17 15:21:27 +10:00

247 lines
6.2 KiB
Plaintext

package views
import (
"fmt"
"vctp/components/core"
)
type SnapshotEntry struct {
Label string
Link string
Count int64
Group string
}
type VcenterLink struct {
Name string
Link string
}
type VcenterTotalsEntry struct {
Snapshot string
RawTime int64
VmCount int64
VcpuTotal int64
RamTotalGB int64
}
type VcenterTotalsMeta struct {
ViewType string
TypeLabel string
HourlyLink string
DailyLink string
HourlyClass string
DailyClass string
}
type VcenterChartData struct {
ConfigJSON string
}
templ SnapshotHourlyList(entries []SnapshotEntry) {
@SnapshotListPage("Hourly Inventory Snapshots", "inventory snapshots captured hourly", entries)
}
templ SnapshotDailyList(entries []SnapshotEntry) {
@SnapshotListPage("Daily Inventory Snapshots", "daily summaries of hourly inventory snapshots", entries)
}
templ SnapshotMonthlyList(entries []SnapshotEntry) {
@SnapshotListPage("Monthly Inventory Snapshots", "monthly summary aggregated from daily snapshots", entries)
}
templ SnapshotListPage(title string, subtitle string, entries []SnapshotEntry) {
<!DOCTYPE html>
<html lang="en">
@core.Header()
<body class="flex flex-col min-h-screen web2-bg">
<main class="flex-grow web2-shell web2-card-grid">
<section class="web2-header web2-page-head">
@core.PageHeader(
"Snapshot Library",
title,
subtitle,
[]core.ActionLink{
{
Label: "Back to Dashboard",
Href: "/",
Class: "web2-button secondary",
},
},
)
</section>
<section class="web2-card">
@core.SectionHead("Available Exports", fmt.Sprintf("%d files", len(entries)))
<div class="web2-table-shell">
<table class="web2-table">
<thead>
<tr>
<th>Snapshot</th>
<th>Records</th>
<th class="text-right">Download</th>
</tr>
</thead>
<tbody>
for i, entry := range entries {
if entry.Group != "" && (i == 0 || entries[i-1].Group != entry.Group) {
<tr class="web2-group-row">
<td colspan="3" class="font-semibold">{ entry.Group }</td>
</tr>
}
<tr>
<td>
<div class="flex flex-col">
<span class="text-sm font-semibold">{ entry.Label }</span>
</div>
</td>
<td>
<span class="web2-badge">{ entry.Count } records</span>
</td>
<td class="text-right">
<a class="web2-link" href={ entry.Link }>Download XLSX</a>
</td>
</tr>
}
</tbody>
</table>
</div>
</section>
</main>
</body>
@core.Footer()
</html>
}
templ VcenterList(links []VcenterLink) {
<!DOCTYPE html>
<html lang="en">
@core.Header()
<body class="flex flex-col min-h-screen web2-bg">
<main class="flex-grow web2-shell web2-card-grid">
<section class="web2-header web2-page-head">
@core.PageHeader(
"vCenter Inventory",
"Monitored vCenters",
"Select a vCenter to view snapshot totals over time.",
[]core.ActionLink{
{
Label: "Back to Dashboard",
Href: "/",
Class: "web2-button secondary",
},
},
)
</section>
<section class="web2-card">
@core.SectionHead("vCenters", fmt.Sprintf("%d total", len(links)))
<div class="web2-table-shell">
<table class="web2-table">
<thead>
<tr>
<th>vCenter</th>
<th class="text-right">Totals</th>
</tr>
</thead>
<tbody>
for _, link := range links {
<tr>
<td class="font-semibold">{ link.Name }</td>
<td class="text-right">
<a class="web2-link" href={ link.Link }>View Totals</a>
</td>
</tr>
}
</tbody>
</table>
</div>
</section>
</main>
</body>
@core.Footer()
</html>
}
templ VcenterTotalsPage(vcenter string, entries []VcenterTotalsEntry, chart VcenterChartData, meta VcenterTotalsMeta) {
<!DOCTYPE html>
<html lang="en">
@core.Header()
<body class="flex flex-col min-h-screen web2-bg">
<main class="flex-grow web2-shell web2-shell-wide web2-card-grid">
<section class="web2-header web2-page-head">
@core.PageHeader(
"vCenter Totals",
"Totals for "+vcenter,
meta.TypeLabel+" snapshots of VM count, vCPU, and RAM over time.",
[]core.ActionLink{
{
Label: "All vCenters",
Href: "/vcenters",
Class: "web2-button secondary",
},
{
Label: "Dashboard",
Href: "/",
Class: "web2-button",
},
},
)
@core.SegmentedActions(
[]core.SegmentedLink{
{
Label: "Hourly Detail (45d)",
Href: meta.HourlyLink,
Class: meta.HourlyClass,
},
{
Label: "Daily Aggregated",
Href: meta.DailyLink,
Class: meta.DailyClass,
},
},
)
</section>
<section class="web2-card">
@core.SectionHead(meta.TypeLabel+" Snapshots", fmt.Sprintf("%d records", len(entries)))
if chart.ConfigJSON != "" {
<div class="mb-6 overflow-auto">
<div class="web3-chart-frame">
<canvas id="vcenter-totals-chart" class="web3-chart-canvas" role="img" aria-label="Totals over time" data-chart-config={ chart.ConfigJSON }></canvas>
<div id="vcenter-totals-tooltip" class="web3-chart-tooltip" aria-hidden="true"></div>
</div>
<script>
window.Web3Charts.renderFromDataset({
canvasId: "vcenter-totals-chart",
tooltipId: "vcenter-totals-tooltip",
})
</script>
</div>
}
<div class="web2-table-shell">
<table class="web2-table">
<thead>
<tr>
<th>Snapshot Time</th>
<th class="text-right">VMs</th>
<th class="text-right">vCPUs</th>
<th class="text-right">RAM (GB)</th>
</tr>
</thead>
<tbody>
for _, entry := range entries {
<tr>
<td>{ entry.Snapshot }</td>
<td class="text-right">{ entry.VmCount }</td>
<td class="text-right">{ entry.VcpuTotal }</td>
<td class="text-right">{ entry.RamTotalGB }</td>
</tr>
}
</tbody>
</table>
</div>
</section>
</main>
</body>
@core.Footer()
</html>
}