feat(go): M6.3 — juniors page (table, filters, credits/debts, Pay buttons)
- Extract AssembleJuniors(ctx) from ServeJuniors JSON handler so HTML
and JSON share the same view-model path (mirrors AssembleAdults pattern)
- Add JuniorsPageData wrapper in render.go
- Wire HTMLHandler.ServeJuniors to AssembleJuniors + render template
- Replace 4-line placeholder juniors.tmpl with full template:
member table, name filter, month-range filter, totals row,
Credits + Debts sections, Pay / Pay All buttons via /qr links
(no Unmatched section — matches Python juniors.html parity)
- J/A attendance breakdown ("3/500 CZK (4:2J,1A)") and "?" sentinel
rendered via MonthCell.Text from buildJuniorMemberRow, no extra
template logic needed
- All tests pass; make parity reports 3/3 routes OK
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -55,14 +55,23 @@ func (h *Handler) AssembleAdults(ctx context.Context) (AdultsResponse, error) {
|
||||
|
||||
// ServeJuniors handles GET /api/juniors.
|
||||
func (h *Handler) ServeJuniors(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
members, sortedMonths, txns, exceptions, err := h.loadAll(ctx, false)
|
||||
resp, err := h.AssembleJuniors(r.Context())
|
||||
if err != nil {
|
||||
h.writeError(w, r, err)
|
||||
return
|
||||
}
|
||||
writeJSON(w, resp)
|
||||
}
|
||||
|
||||
// AssembleJuniors loads all data and builds the juniors view model.
|
||||
// Shared between the JSON API route and the HTML handler.
|
||||
func (h *Handler) AssembleJuniors(ctx context.Context) (JuniorsResponse, error) {
|
||||
members, sortedMonths, txns, exceptions, err := h.loadAll(ctx, false)
|
||||
if err != nil {
|
||||
return JuniorsResponse{}, err
|
||||
}
|
||||
result := domreconcile.Reconcile(members, sortedMonths, txns, exceptions, time.Now().Year())
|
||||
writeJSON(w, buildJuniorsResponse(members, sortedMonths, result, txns, h.Config, time.Now().Format("2006-01")))
|
||||
return buildJuniorsResponse(members, sortedMonths, result, txns, h.Config, time.Now().Format("2006-01")), nil
|
||||
}
|
||||
|
||||
// ServePayments handles GET /api/payments.
|
||||
|
||||
@@ -33,7 +33,18 @@ func (h *HTMLHandler) ServeAdults(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (h *HTMLHandler) ServeJuniors(w http.ResponseWriter, r *http.Request) {
|
||||
h.renderer.Render(w, "juniors", PageData{Active: "juniors", Build: h.build})
|
||||
data, err := h.apiHandler.AssembleJuniors(r.Context())
|
||||
if err != nil {
|
||||
h.renderer.Render(w, "juniors", JuniorsPageData{
|
||||
PageData: PageData{Active: "juniors", Build: h.build},
|
||||
Error: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
h.renderer.Render(w, "juniors", JuniorsPageData{
|
||||
PageData: PageData{Active: "juniors", Build: h.build},
|
||||
Data: data,
|
||||
})
|
||||
}
|
||||
|
||||
func (h *HTMLHandler) ServePayments(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -23,6 +23,13 @@ type AdultsPageData struct {
|
||||
Error string
|
||||
}
|
||||
|
||||
// JuniorsPageData is the view model for the /juniors HTML page.
|
||||
type JuniorsPageData struct {
|
||||
PageData
|
||||
Data api.JuniorsResponse
|
||||
Error string
|
||||
}
|
||||
|
||||
// Renderer parses and executes HTML templates from the embedded FS.
|
||||
type Renderer struct {
|
||||
tmpls map[string]*template.Template
|
||||
|
||||
@@ -1,5 +1,121 @@
|
||||
{{define "title"}}Juniors{{end}}
|
||||
{{define "content"}}
|
||||
<h1>Juniors Dashboard</h1>
|
||||
<p class="description">Coming in M6.3</p>
|
||||
|
||||
{{if .Error}}
|
||||
<div class="description">Error loading data: {{.Error}}</div>
|
||||
{{else}}
|
||||
|
||||
<div class="description">
|
||||
Balances calculated by matching Google Sheet payments against attendance fees.<br>
|
||||
Source: <a href="{{.Data.AttendanceURL}}" target="_blank" rel="noopener">Attendance Sheet</a> |
|
||||
<a href="{{.Data.PaymentsURL}}" target="_blank" rel="noopener">Payments Ledger</a>
|
||||
</div>
|
||||
|
||||
<div class="filter-container" id="filterContainer" data-current-month="{{.Data.CurrentMonth}}">
|
||||
<div class="filter-item">
|
||||
<label class="filter-label" for="nameFilter">Member</label>
|
||||
<input id="nameFilter" class="filter-input" type="text" placeholder="Filter by name…">
|
||||
</div>
|
||||
<div class="filter-item">
|
||||
<label class="filter-label" for="fromMonth">From</label>
|
||||
<select id="fromMonth" class="filter-select">
|
||||
<option value="">All</option>
|
||||
{{range $i, $m := .Data.Months}}
|
||||
<option value="{{$i}}">{{$m}}</option>
|
||||
{{end}}
|
||||
</select>
|
||||
</div>
|
||||
<div class="filter-item">
|
||||
<label class="filter-label" for="toMonth">To</label>
|
||||
<select id="toMonth" class="filter-select">
|
||||
<option value="">All</option>
|
||||
{{range $i, $m := .Data.Months}}
|
||||
<option value="{{$i}}">{{$m}}</option>
|
||||
{{end}}
|
||||
</select>
|
||||
</div>
|
||||
<div class="filter-item">
|
||||
<button id="applyFilter" class="filter-select" type="button" style="cursor: pointer;">Apply</button>
|
||||
<button id="clearFilter" class="filter-select" type="button" style="cursor: pointer;">All</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{if .Data.Results}}
|
||||
<div class="table-container">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Member</th>
|
||||
{{range $i, $m := .Data.Months}}
|
||||
<th data-month-idx="{{$i}}" data-raw-month="{{index $.Data.RawMonths $i}}">{{$m}}</th>
|
||||
{{end}}
|
||||
<th>Balance</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{range $row := .Data.Results}}
|
||||
<tr class="member-row" data-name="{{$row.Name}}">
|
||||
<td class="member-name">{{$row.Name}}</td>
|
||||
{{range $i, $cell := $row.Months}}
|
||||
<td data-month-idx="{{$i}}" title="{{$cell.Tooltip}}"
|
||||
class="{{if eq $cell.Status "empty"}}cell-empty{{else if and (or (eq $cell.Status "unpaid") (eq $cell.Status "partial")) (ge $cell.RawMonth $.Data.CurrentMonth)}}cell-unpaid-current{{else if or (eq $cell.Status "unpaid") (eq $cell.Status "partial")}}cell-unpaid{{else if eq $cell.Status "ok"}}cell-ok{{end}}{{if $cell.Overridden}} cell-overridden{{end}}">
|
||||
{{$cell.Text}}
|
||||
{{if and (or (eq $cell.Status "unpaid") (eq $cell.Status "partial")) (lt $cell.RawMonth $.Data.CurrentMonth)}}
|
||||
<a class="pay-btn" href="{{qrHref $.Data.BankAccount $cell.Amount $row.Name $cell.RawMonth}}">Pay</a>
|
||||
{{end}}
|
||||
</td>
|
||||
{{end}}
|
||||
<td class="{{if lt $row.Balance 0}}balance-neg{{else if gt $row.Balance 0}}balance-pos{{end}}" style="position: relative;">
|
||||
{{$row.Balance}}
|
||||
{{if gt $row.PayableAmount 0}}
|
||||
<a class="pay-btn" href="{{qrHrefAll $.Data.BankAccount $row.PayableAmount $row.Name $row.RawUnpaidPeriods}}">Pay All</a>
|
||||
{{end}}
|
||||
</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
<tr class="totals-row" style="font-weight: bold; background-color: #111; border-top: 2px solid #333;">
|
||||
<td style="text-align: left; padding: 6px 8px;">TOTAL</td>
|
||||
{{range $i, $t := .Data.Totals}}
|
||||
<td data-month-idx="{{$i}}" data-raw-month="{{index $.Data.RawMonths $i}}" class="{{if eq $t.Status "ok"}}cell-ok{{else if eq $t.Status "unpaid"}}cell-unpaid{{else if eq $t.Status "surplus"}}cell-overridden{{end}}" style="padding-top: 4px; padding-bottom: 4px;">
|
||||
<span style="font-size: 0.6em; font-weight: normal; color: #666; text-transform: lowercase; display: block; margin-bottom: 2px;">received / expected</span>
|
||||
{{$t.Text}}
|
||||
</td>
|
||||
{{end}}
|
||||
<td></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{{else}}
|
||||
<div class="description">No members found.</div>
|
||||
{{end}}
|
||||
|
||||
{{if .Data.Credits}}
|
||||
<h2>Credits (Advance Payments / Surplus)</h2>
|
||||
<div class="list-container">
|
||||
{{range .Data.Credits}}
|
||||
<div class="list-item">
|
||||
<span class="list-item-name">{{.Name}}</span>
|
||||
<span class="list-item-val">{{.Amount}} CZK</span>
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
{{if .Data.Debts}}
|
||||
<h2>Debts (Missing Payments)</h2>
|
||||
<div class="list-container">
|
||||
{{range .Data.Debts}}
|
||||
<div class="list-item">
|
||||
<span class="list-item-name">{{.Name}}</span>
|
||||
<span class="list-item-val" style="color: #ff3333;">{{.Amount}} CZK</span>
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
{{end}}
|
||||
|
||||
<script src="/static/js/filters.js" defer></script>
|
||||
{{end}}
|
||||
|
||||
Reference in New Issue
Block a user