diff --git a/internal/handlers/overview.go b/internal/handlers/overview.go index 88a1aaa..f65af8c 100644 --- a/internal/handlers/overview.go +++ b/internal/handlers/overview.go @@ -7,8 +7,13 @@ import ( "lostcavewireplanner/internal/models" ) +type RackCard struct { + Rack models.Rack + DeviceCount int +} + type OverviewData struct { - Racks []models.Rack + Racks []RackCard Devices []models.Device Connections []models.Connection AllModels []models.DeviceModel @@ -34,8 +39,22 @@ func (h *Handlers) Overview(w http.ResponseWriter, r *http.Request) { 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{ - Racks: racks, + Racks: rackCards, Devices: devices, Connections: connections, AllModels: allModels, @@ -90,8 +109,20 @@ func renderOverviewError(h *Handlers, w http.ResponseWriter, errMsg string) { if allModels == nil { allModels = []models.DeviceModel{} } - data := OverviewData{Racks: racks, Devices: devices, Connections: connections, AllModels: allModels, Error: errMsg} - h.render(w, "overview.html", data) + 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{Racks: rackCards, Devices: devices, Connections: connections, AllModels: allModels, Error: errMsg}) } func (h *Handlers) renderError(w http.ResponseWriter, page string, errMsg string) { diff --git a/templates/overview.html b/templates/overview.html index 8be446d..d7d87b6 100644 --- a/templates/overview.html +++ b/templates/overview.html @@ -6,10 +6,10 @@