Show device count on rack cards in overview
Each rack card now displays the number of devices inside (racked + unplaced). Introduced a RackCard wrapper in the overview handler to pair each rack with its precomputed count.master
parent
444441861b
commit
3434d02e78
|
|
@ -7,8 +7,13 @@ import (
|
||||||
"lostcavewireplanner/internal/models"
|
"lostcavewireplanner/internal/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type RackCard struct {
|
||||||
|
Rack models.Rack
|
||||||
|
DeviceCount int
|
||||||
|
}
|
||||||
|
|
||||||
type OverviewData struct {
|
type OverviewData struct {
|
||||||
Racks []models.Rack
|
Racks []RackCard
|
||||||
Devices []models.Device
|
Devices []models.Device
|
||||||
Connections []models.Connection
|
Connections []models.Connection
|
||||||
AllModels []models.DeviceModel
|
AllModels []models.DeviceModel
|
||||||
|
|
@ -34,8 +39,22 @@ func (h *Handlers) Overview(w http.ResponseWriter, r *http.Request) {
|
||||||
allModels = []models.DeviceModel{}
|
allModels = []models.DeviceModel{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var rackCards []RackCard
|
||||||
|
for _, r := range racks {
|
||||||
|
racked, _ := h.Store.DeviceGetByRackID(r.ID)
|
||||||
|
unracked, _ := h.Store.DeviceGetUnrackedByRackID(r.ID)
|
||||||
|
count := 0
|
||||||
|
if racked != nil {
|
||||||
|
count += len(racked)
|
||||||
|
}
|
||||||
|
if unracked != nil {
|
||||||
|
count += len(unracked)
|
||||||
|
}
|
||||||
|
rackCards = append(rackCards, RackCard{Rack: r, DeviceCount: count})
|
||||||
|
}
|
||||||
|
|
||||||
h.render(w, "overview.html", OverviewData{
|
h.render(w, "overview.html", OverviewData{
|
||||||
Racks: racks,
|
Racks: rackCards,
|
||||||
Devices: devices,
|
Devices: devices,
|
||||||
Connections: connections,
|
Connections: connections,
|
||||||
AllModels: allModels,
|
AllModels: allModels,
|
||||||
|
|
@ -90,8 +109,20 @@ func renderOverviewError(h *Handlers, w http.ResponseWriter, errMsg string) {
|
||||||
if allModels == nil {
|
if allModels == nil {
|
||||||
allModels = []models.DeviceModel{}
|
allModels = []models.DeviceModel{}
|
||||||
}
|
}
|
||||||
data := OverviewData{Racks: racks, Devices: devices, Connections: connections, AllModels: allModels, Error: errMsg}
|
var rackCards []RackCard
|
||||||
h.render(w, "overview.html", data)
|
for _, r := range racks {
|
||||||
|
racked, _ := h.Store.DeviceGetByRackID(r.ID)
|
||||||
|
unracked, _ := h.Store.DeviceGetUnrackedByRackID(r.ID)
|
||||||
|
count := 0
|
||||||
|
if racked != nil {
|
||||||
|
count += len(racked)
|
||||||
|
}
|
||||||
|
if unracked != nil {
|
||||||
|
count += len(unracked)
|
||||||
|
}
|
||||||
|
rackCards = append(rackCards, RackCard{Rack: r, DeviceCount: count})
|
||||||
|
}
|
||||||
|
h.render(w, "overview.html", OverviewData{Racks: rackCards, Devices: devices, Connections: connections, AllModels: allModels, Error: errMsg})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handlers) renderError(w http.ResponseWriter, page string, errMsg string) {
|
func (h *Handlers) renderError(w http.ResponseWriter, page string, errMsg string) {
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,10 @@
|
||||||
<h2>Racks</h2>
|
<h2>Racks</h2>
|
||||||
<div class="grid">
|
<div class="grid">
|
||||||
{{range .Racks}}
|
{{range .Racks}}
|
||||||
<a href="/racks/{{.ID}}" class="card">
|
<a href="/racks/{{.Rack.ID}}" class="card">
|
||||||
<strong>{{.Name}}</strong>
|
<strong>{{.Rack.Name}}</strong>
|
||||||
<span>{{.RackType}} / {{.Depth}} / {{.HeightUnits}}U</span>
|
<span>{{.Rack.RackType}} / {{.Rack.Depth}} / {{.Rack.HeightUnits}}U · {{.DeviceCount}} device{{if ne .DeviceCount 1}}s{{end}}</span>
|
||||||
{{if .Comment}}<small>{{.Comment}}</small>{{end}}
|
{{if .Rack.Comment}}<small>{{.Rack.Comment}}</small>{{end}}
|
||||||
</a>
|
</a>
|
||||||
{{else}}
|
{{else}}
|
||||||
<div class="empty-state">No racks yet. Create one below.</div>
|
<div class="empty-state">No racks yet. Create one below.</div>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue