feat: merge report-only customers into Customers page, rename tab

- Customers page now shows ALL customers: both pre-configured (managed)
  and report-only (manual) — merged from customer_configs + reports tables
- Renamed "Configurations" → "Customers" in navigation tabs
- Renamed "+ New Configuration" → "+ Add Customer"
- Status column with ok/warn/down badges, version column, managed/manual badge

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-20 15:27:05 +01:00
parent b07132f617
commit cb425d8086
6 changed files with 115 additions and 24 deletions
+78 -3
View File
@@ -5,7 +5,9 @@ import (
"fmt" "fmt"
"net/http" "net/http"
"regexp" "regexp"
"sort"
"strings" "strings"
"time"
"gitea.dooplex.hu/admin/felhom-hub/internal/configgen" "gitea.dooplex.hu/admin/felhom-hub/internal/configgen"
"gitea.dooplex.hu/admin/felhom-hub/internal/store" "gitea.dooplex.hu/admin/felhom-hub/internal/store"
@@ -13,7 +15,19 @@ import (
var validCustomerID = regexp.MustCompile(`^[a-zA-Z0-9.\-]+$`) var validCustomerID = regexp.MustCompile(`^[a-zA-Z0-9.\-]+$`)
// handleConfigList shows all customer configurations. // customerListEntry is a merged view of a customer from both configs and reports.
type customerListEntry struct {
CustomerID string
CustomerName string
Domain string
HasConfig bool
OverallStatus string // ok, warn, down, disabled, "" if no reports
ControllerVersion string
TimeSinceReport time.Duration
ConfigCreatedAt time.Time
}
// handleConfigList shows all customers (merged from configs + reports).
func (s *Server) handleConfigList(w http.ResponseWriter, r *http.Request) { func (s *Server) handleConfigList(w http.ResponseWriter, r *http.Request) {
configs, err := s.store.ListCustomerConfigs() configs, err := s.store.ListCustomerConfigs()
if err != nil { if err != nil {
@@ -22,12 +36,73 @@ func (s *Server) handleConfigList(w http.ResponseWriter, r *http.Request) {
return return
} }
customers, err := s.store.GetCustomers()
if err != nil {
s.logger.Printf("[ERROR] Failed to list customers: %v", err)
http.Error(w, "Internal error", http.StatusInternalServerError)
return
}
// Build merged map keyed by customer_id
merged := make(map[string]*customerListEntry)
for _, cfg := range configs {
merged[cfg.CustomerID] = &customerListEntry{
CustomerID: cfg.CustomerID,
CustomerName: cfg.CustomerName,
Domain: cfg.Domain,
HasConfig: true,
ConfigCreatedAt: cfg.CreatedAt,
}
}
for _, c := range customers {
status := "ok"
if c.HealthStatus == "disabled" {
status = "disabled"
} else if c.TimeSinceReport > time.Hour {
status = "down"
} else if c.TimeSinceReport > 30*time.Minute || c.HealthStatus == "warn" {
status = "warn"
} else if c.HealthStatus == "fail" {
status = "down"
}
if entry, ok := merged[c.CustomerID]; ok {
// Config exists — enrich with report data
entry.OverallStatus = status
entry.ControllerVersion = c.ControllerVersion
entry.TimeSinceReport = c.TimeSinceReport
if entry.CustomerName == "" {
entry.CustomerName = c.CustomerName
}
} else {
// Report-only customer (no config)
merged[c.CustomerID] = &customerListEntry{
CustomerID: c.CustomerID,
CustomerName: c.CustomerName,
OverallStatus: status,
ControllerVersion: c.ControllerVersion,
TimeSinceReport: c.TimeSinceReport,
}
}
}
// Sort by customer_id
entries := make([]customerListEntry, 0, len(merged))
for _, e := range merged {
entries = append(entries, *e)
}
sort.Slice(entries, func(i, j int) bool {
return entries[i].CustomerID < entries[j].CustomerID
})
data := struct { data := struct {
Configs []store.CustomerConfig Customers []customerListEntry
ActiveNav string ActiveNav string
Flash string Flash string
}{ }{
Configs: configs, Customers: entries,
ActiveNav: "configs", ActiveNav: "configs",
Flash: r.URL.Query().Get("flash"), Flash: r.URL.Query().Get("flash"),
} }
@@ -12,11 +12,11 @@
<h1>Felhom Hub</h1> <h1>Felhom Hub</h1>
<nav class="nav-links"> <nav class="nav-links">
<a href="/" class="nav-link">Dashboard</a> <a href="/" class="nav-link">Dashboard</a>
<a href="/configs" class="nav-link active">Configurations</a> <a href="/configs" class="nav-link active">Customers</a>
</nav> </nav>
</header> </header>
<a href="/configs" class="back-link">&larr; All Configurations</a> <a href="/configs" class="back-link">&larr; All customers</a>
{{if .Flash}} {{if .Flash}}
<div class="flash flash-success"> <div class="flash flash-success">
@@ -123,7 +123,7 @@
</div> </div>
<footer> <footer>
<p>Felhom Hub — Configuration Management</p> <p>Felhom Hub — Customer Management</p>
</footer> </footer>
</div> </div>
+3 -3
View File
@@ -3,7 +3,7 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Felhom Hub — {{if .IsNew}}New Configuration{{else}}Edit {{.Config.CustomerID}}{{end}}</title> <title>Felhom Hub — {{if .IsNew}}Add Customer{{else}}Edit {{.Config.CustomerID}}{{end}}</title>
<link rel="stylesheet" href="/style.css"> <link rel="stylesheet" href="/style.css">
</head> </head>
<body> <body>
@@ -12,12 +12,12 @@
<h1>Felhom Hub</h1> <h1>Felhom Hub</h1>
<nav class="nav-links"> <nav class="nav-links">
<a href="/" class="nav-link">Dashboard</a> <a href="/" class="nav-link">Dashboard</a>
<a href="/configs" class="nav-link active">Configurations</a> <a href="/configs" class="nav-link active">Customers</a>
</nav> </nav>
</header> </header>
<a href="{{if .IsNew}}/configs{{else}}/configs/{{.Config.CustomerID}}{{end}}" class="back-link">&larr; Back</a> <a href="{{if .IsNew}}/configs{{else}}/configs/{{.Config.CustomerID}}{{end}}" class="back-link">&larr; Back</a>
<h2>{{if .IsNew}}New Customer Configuration{{else}}Edit: {{.Config.CustomerID}}{{end}}</h2> <h2>{{if .IsNew}}Add Customer{{else}}Edit: {{.Config.CustomerID}}{{end}}</h2>
{{if .Error}} {{if .Error}}
<div class="flash flash-error">{{.Error}}</div> <div class="flash flash-error">{{.Error}}</div>
+29 -13
View File
@@ -3,7 +3,7 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Felhom Hub — Configurations</title> <title>Felhom Hub — Customers</title>
<link rel="stylesheet" href="/style.css"> <link rel="stylesheet" href="/style.css">
</head> </head>
<body> <body>
@@ -12,25 +12,25 @@
<h1>Felhom Hub</h1> <h1>Felhom Hub</h1>
<nav class="nav-links"> <nav class="nav-links">
<a href="/" class="nav-link">Dashboard</a> <a href="/" class="nav-link">Dashboard</a>
<a href="/configs" class="nav-link active">Configurations</a> <a href="/configs" class="nav-link active">Customers</a>
</nav> </nav>
</header> </header>
{{if .Flash}} {{if .Flash}}
<div class="flash flash-success"> <div class="flash flash-success">
{{if eq .Flash "deleted"}}Configuration deleted.{{end}} {{if eq .Flash "deleted"}}Customer configuration deleted.{{end}}
</div> </div>
{{end}} {{end}}
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem;"> <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem;">
<h2 style="margin: 0;">Customer Configurations</h2> <h2 style="margin: 0;">Customers</h2>
<a href="/configs/new" class="btn">+ New Configuration</a> <a href="/configs/new" class="btn">+ Add Customer</a>
</div> </div>
{{if not .Configs}} {{if not .Customers}}
<div class="empty-state"> <div class="empty-state">
<p>No customer configurations yet.</p> <p>No customers yet.</p>
<p class="hint">Create a configuration to pre-provision a customer node.</p> <p class="hint">Add a customer configuration or wait for a controller to report in.</p>
</div> </div>
{{else}} {{else}}
<table class="dashboard-table"> <table class="dashboard-table">
@@ -39,16 +39,32 @@
<th>Customer ID</th> <th>Customer ID</th>
<th>Name</th> <th>Name</th>
<th>Domain</th> <th>Domain</th>
<th>Created</th> <th>Status</th>
<th>Version</th>
<th>Config</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{{range .Configs}} {{range .Customers}}
<tr onclick="window.location='/configs/{{.CustomerID}}'"> <tr onclick="window.location='{{if .HasConfig}}/configs/{{.CustomerID}}{{else}}/customers/{{.CustomerID}}{{end}}'">
<td><code>{{.CustomerID}}</code></td> <td><code>{{.CustomerID}}</code></td>
<td>{{if .CustomerName}}{{.CustomerName}}{{else}}<span class="text-muted"></span>{{end}}</td> <td>{{if .CustomerName}}{{.CustomerName}}{{else}}<span class="text-muted"></span>{{end}}</td>
<td>{{if .Domain}}{{.Domain}}{{else}}<span class="text-muted"></span>{{end}}</td> <td>{{if .Domain}}{{.Domain}}{{else}}<span class="text-muted"></span>{{end}}</td>
<td>{{timeAgo .CreatedAt}}</td> <td>
{{if .OverallStatus}}
<span class="status-badge status-badge-{{.OverallStatus}}">{{.OverallStatus}}</span>
{{else}}
<span class="text-muted"></span>
{{end}}
</td>
<td>{{if .ControllerVersion}}<code>{{.ControllerVersion}}</code>{{else}}<span class="text-muted"></span>{{end}}</td>
<td>
{{if .HasConfig}}
<span class="status-badge status-badge-ok">managed</span>
{{else}}
<span class="status-badge status-badge-disabled">manual</span>
{{end}}
</td>
</tr> </tr>
{{end}} {{end}}
</tbody> </tbody>
@@ -56,7 +72,7 @@
{{end}} {{end}}
<footer> <footer>
<p>Felhom Hub — Configuration Management</p> <p>Felhom Hub — Customer Management</p>
</footer> </footer>
</div> </div>
</body> </body>
+1 -1
View File
@@ -12,7 +12,7 @@
<header> <header>
<nav class="nav-links" style="margin-bottom: 0.5rem;"> <nav class="nav-links" style="margin-bottom: 0.5rem;">
<a href="/" class="nav-link">Dashboard</a> <a href="/" class="nav-link">Dashboard</a>
<a href="/configs" class="nav-link">Configurations</a> <a href="/configs" class="nav-link">Customers</a>
</nav> </nav>
<a href="/" class="back-link">&larr; Back to Dashboard</a> <a href="/" class="back-link">&larr; Back to Dashboard</a>
<h1> <h1>
+1 -1
View File
@@ -13,7 +13,7 @@
<h1>Felhom Hub</h1> <h1>Felhom Hub</h1>
<nav class="nav-links"> <nav class="nav-links">
<a href="/" class="nav-link active">Dashboard</a> <a href="/" class="nav-link active">Dashboard</a>
<a href="/configs" class="nav-link">Configurations</a> <a href="/configs" class="nav-link">Customers</a>
</nav> </nav>
</header> </header>