feat(go): M6.2 — adults page (table, filters, credits/debts/unmatched, Pay buttons)
All checks were successful
Deploy to K8s / deploy (push) Successful in 8s
All checks were successful
Deploy to K8s / deploy (push) Successful in 8s
- Extract AssembleAdults(ctx) from ServeAdults so HTML and JSON API share one reconcile path. - HTMLHandler gains *api.Handler; ServeAdults loads real data and renders adults.tmpl. - AdultsPageData view model + qrHref/qrHrefAll funcMap (URL-encode /qr params, YYYY-MM→MM/YYYY). - adults.tmpl: full reconcile table, per-cell status classes + cell-unpaid-current, Pay button hrefs, totals row, credits/debts/unmatched sections, filter controls, sheet links. - static/js/filters.js: NFD-normalize name filter + month-range column hiding; future months hidden by default. - TestAdultsPage asserts member name and cell text against fixture data. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -2,9 +2,12 @@ package web
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"fuj-management/go/internal/web/api"
|
||||
"html/template"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// PageData is the view model passed to every HTML template.
|
||||
@@ -13,6 +16,13 @@ type PageData struct {
|
||||
Build BuildInfo
|
||||
}
|
||||
|
||||
// AdultsPageData is the view model for the /adults HTML page.
|
||||
type AdultsPageData struct {
|
||||
PageData
|
||||
Data api.AdultsResponse
|
||||
Error string
|
||||
}
|
||||
|
||||
// Renderer parses and executes HTML templates from the embedded FS.
|
||||
type Renderer struct {
|
||||
tmpls map[string]*template.Template
|
||||
@@ -20,12 +30,43 @@ type Renderer struct {
|
||||
|
||||
var pageNames = []string{"adults", "juniors", "payments", "sync", "flush_cache"}
|
||||
|
||||
// qrHref builds the /qr query URL for a single-month Pay button.
|
||||
// rawMonth is "YYYY-MM"; it is converted to "MM/YYYY" in the QR message.
|
||||
func qrHref(account string, amount int, name, rawMonth string) string {
|
||||
// Convert "YYYY-MM" → "MM/YYYY" to match Python's showPayQR JS.
|
||||
if len(rawMonth) == 7 && rawMonth[4] == '-' {
|
||||
rawMonth = rawMonth[5:] + "/" + rawMonth[:4]
|
||||
}
|
||||
msg := name + ": " + rawMonth
|
||||
return "/qr?" + url.Values{
|
||||
"account": {account},
|
||||
"amount": {strconv.Itoa(amount)},
|
||||
"message": {msg},
|
||||
}.Encode()
|
||||
}
|
||||
|
||||
// qrHrefAll builds the /qr query URL for a Pay-All button.
|
||||
// rawPeriods is the "+" -joined MM/YYYY string from MemberRow.RawUnpaidPeriods.
|
||||
func qrHrefAll(account string, amount int, name, rawPeriods string) string {
|
||||
msg := name + ": " + rawPeriods
|
||||
return "/qr?" + url.Values{
|
||||
"account": {account},
|
||||
"amount": {strconv.Itoa(amount)},
|
||||
"message": {msg},
|
||||
}.Encode()
|
||||
}
|
||||
|
||||
var tmplFuncs = template.FuncMap{
|
||||
"qrHref": qrHref,
|
||||
"qrHrefAll": qrHrefAll,
|
||||
}
|
||||
|
||||
// NewRenderer parses all templates from the embedded FS.
|
||||
// A parse failure should be treated as a startup-time fatal error.
|
||||
func NewRenderer() (*Renderer, error) {
|
||||
tmpls := make(map[string]*template.Template, len(pageNames))
|
||||
for _, name := range pageNames {
|
||||
t, err := template.New("").ParseFS(templateFS,
|
||||
t, err := template.New("").Funcs(tmplFuncs).ParseFS(templateFS,
|
||||
"templates/base.tmpl",
|
||||
"templates/partials/nav.tmpl",
|
||||
"templates/partials/footer.tmpl",
|
||||
|
||||
Reference in New Issue
Block a user