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

183 lines
5.4 KiB
Plaintext

package views
import (
"fmt"
"vctp/components/core"
)
type VmTraceEntry struct {
Snapshot string
RawTime int64
Name string
VmId string
VmUuid string
Vcenter string
ResourcePool string
VcpuCount int64
RamGB int64
ProvisionedDisk float64
CreationTime string
DeletionTime string
}
type VmTraceChart struct {
ConfigJSON string
}
type VmTraceMeta struct {
ViewType string
TypeLabel string
HourlyLink string
DailyLink string
HourlyClass string
DailyClass string
}
type VmTraceDiagnosticLine struct {
Label string
Value string
}
type VmTraceDiagnostics struct {
Visible bool
Lines []VmTraceDiagnosticLine
}
templ VmTracePage(query string, display_query string, vm_id string, vm_uuid string, vm_name string, creationLabel string, deletionLabel string, creationApprox bool, entries []VmTraceEntry, chart VmTraceChart, meta VmTraceMeta, diagnostics VmTraceDiagnostics) {
<!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(
"VM Trace",
"Snapshot history"+display_query,
"Timeline of vCPU, RAM, and resource pool changes across "+meta.TypeLabel+" snapshots.",
[]core.ActionLink{
{
Label: "Dashboard",
Href: "/",
Class: "web2-button secondary",
},
},
)
<form method="get" action="/vm/trace" class="web2-form-grid">
<input type="hidden" name="view" value={ meta.ViewType }/>
<div class="web2-field">
<label class="web2-label" for="vm_id">VM ID</label>
<input class="web2-input" type="text" id="vm_id" name="vm_id" value={ vm_id } placeholder="vm-12345"/>
</div>
<div class="web2-field">
<label class="web2-label" for="vm_uuid">VM UUID</label>
<input class="web2-input" type="text" id="vm_uuid" name="vm_uuid" value={ vm_uuid } placeholder="uuid..."/>
</div>
<div class="web2-field">
<label class="web2-label" for="name">Name</label>
<input class="web2-input" type="text" id="name" name="name" value={ vm_name } placeholder="VM name"/>
</div>
<div class="web2-form-actions web2-form-actions-full">
<button class="web3-button active" type="submit">Load VM Trace</button>
<a class="web3-button" href="/vm/trace">Clear</a>
</div>
</form>
@core.SegmentedActions(
[]core.SegmentedLink{
{
Label: "Hourly Detail",
Href: meta.HourlyLink,
Class: meta.HourlyClass,
},
{
Label: "Daily Aggregated",
Href: meta.DailyLink,
Class: meta.DailyClass,
},
},
)
</section>
<section class="web2-card">
@core.SectionHead(meta.TypeLabel+" Timeline", fmt.Sprintf("%d samples", len(entries)))
if chart.ConfigJSON != "" {
<div class="mb-6 overflow-auto">
<div class="web3-chart-frame">
<canvas id="vm-trace-chart" class="web3-chart-canvas" role="img" aria-label="VM timeline" data-chart-config={ chart.ConfigJSON }></canvas>
<div id="vm-trace-tooltip" class="web3-chart-tooltip" aria-hidden="true"></div>
</div>
<script>
window.Web3Charts.renderFromDataset({
canvasId: "vm-trace-chart",
tooltipId: "vm-trace-tooltip",
})
</script>
</div>
}
<div class="grid gap-3 md:grid-cols-2 mb-4">
<div class="web2-subcard">
<p class="web2-subcard-label">Creation Time</p>
<p class="web2-subcard-value">{ creationLabel }</p>
if creationApprox {
<p class="web2-muted web2-caption mt-1">Approximate (earliest snapshot)</p>
}
</div>
<div class="web2-subcard">
<p class="web2-subcard-label">Deletion Time</p>
<p class="web2-subcard-value">{ deletionLabel }</p>
</div>
</div>
if diagnostics.Visible && len(diagnostics.Lines) > 0 {
<details class="web2-subcard mb-4">
<summary class="web2-details-summary">Lifecycle diagnostics</summary>
<div class="mt-3 web2-table-shell">
<table class="web2-table">
<tbody>
for _, line := range diagnostics.Lines {
<tr>
<td class="font-semibold w-72">{ line.Label }</td>
<td class="web2-muted">{ line.Value }</td>
</tr>
}
</tbody>
</table>
</div>
</details>
}
<div class="web2-table-shell">
<table class="web2-table">
<thead>
<tr>
<th>Snapshot</th>
<th>VM Name</th>
<th>VmId</th>
<th>VmUuid</th>
<th>Vcenter</th>
<th>Resource Pool</th>
<th class="text-right">vCPUs</th>
<th class="text-right">RAM (GB)</th>
<th class="text-right">Disk</th>
</tr>
</thead>
<tbody>
for _, e := range entries {
<tr>
<td>{ e.Snapshot }</td>
<td>{ e.Name }</td>
<td>{ e.VmId }</td>
<td>{ e.VmUuid }</td>
<td>{ e.Vcenter }</td>
<td>{ e.ResourcePool }</td>
<td class="text-right">{ e.VcpuCount }</td>
<td class="text-right">{ e.RamGB }</td>
<td class="text-right">{ fmt.Sprintf("%.1f", e.ProvisionedDisk) }</td>
</tr>
}
</tbody>
</table>
</div>
</section>
</main>
</body>
@core.Footer()
</html>
}