From 942fc42d5f0a7fc333d9acd9fda14478e25e5990 Mon Sep 17 00:00:00 2001 From: Eli Ribble Date: Thu, 13 Nov 2025 15:05:05 +0000 Subject: [PATCH] Show dashboard numbers with commas for readability --- html.go | 18 ++++++++++++++++++ templates/dashboard.html | 6 +++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/html.go b/html.go index e30fc190..8023d9c1 100644 --- a/html.go +++ b/html.go @@ -11,6 +11,7 @@ import ( "log/slog" "net/http" "os" + "strconv" "strings" "time" @@ -112,6 +113,22 @@ func (bt *BuiltTemplate) ExecuteTemplate(w io.Writer, data any) error { } } +func bigNumber(n int) string { + // Convert the number to a string + numStr := strconv.FormatInt(int64(n), 10) + + // Add commas every three digits from the right + var result strings.Builder + for i, char := range numStr { + if i > 0 && (len(numStr)-i)%3 == 0 { + result.WriteByte(',') + } + result.WriteRune(char) + } + + return result.String() +} + func extractInitials(name string) string { parts := strings.Fields(name) var initials strings.Builder @@ -321,6 +338,7 @@ func htmlSignup(w http.ResponseWriter, path string) { func makeFuncMap() template.FuncMap { funcMap := template.FuncMap{ + "bigNumber": bigNumber, "timeElapsed": timeElapsed, "timeSince": timeSince, } diff --git a/templates/dashboard.html b/templates/dashboard.html index 58d5fa7b..1ae6594e 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -99,7 +99,7 @@ body {
Service Requests
-

{{ .CountServiceRequests }}

+

{{ .CountServiceRequests | bigNumber }}

12% @@ -117,7 +117,7 @@ body {

Mosquito Sources
-

{{ .CountMosquitoSources }}

+

{{ .CountMosquitoSources | bigNumber }}

8% @@ -135,7 +135,7 @@ body {

Inspections
-

{{ .CountInspections }}

+

{{ .CountInspections | bigNumber }}

15%