4761c20ad6
cmd/mavweb/main.go held 1868 lines. Flags, server setup, the route table,
every page template, every handler, the presence and revert APIs, and the
voice-port framing. Split along the seams that were already there.
shell.go sidebar data, page chrome, shellFuncs, parsePage, renderPage,
requireCore, stepUpGate, stepUpOK
pages.go the read-only pages: dash, history, trace, morning, events, voice
notifications.go, reminders.go, tasks.go, routines.go, tools.go, chat.go
one write surface each, template beside its handler
facts.go POST /api/signal and POST /api/revert
voiceproxy.go GET /ws, POST /api/ptt and the framing they share
main.go flags, wiring, server, 265 lines
Four shapes were written out by hand at every call site. Each is now one
function.
parsePage thirteen copies of template.Must(New(k).Funcs(shellFuncs())
.Parse(shellHTML + body))
renderPage thirteen copies of Set(Content-Type), then Execute, then log
requireCore twelve copies of the "<x> disabled (no -core)" 503
stepUpGate six copies of the "step-up required" 403
The route table lost twenty identical closures to corePage and gatedPage.
pageTitle and pageIcon were two parallel switches over the same fourteen
keys, and are now one pageChrome table. A new page can no longer get a
title and no icon. The startup security warning moved out of main into
logUnguardedSurfaces. Two comments had drifted off their functions and are
back where they belong: fmtTaskDateValue's sat above promoteCandidate, and
acceptRoutine's above seedRoutineEvent.
Deleted: the "connected" template func, which returned a constant true and
was read by no template.
No behaviour change. Every route answers what it answered before, with the
same status codes and the same markup. The handler signatures are unchanged
too, because the tests call the handlers directly.
A file split cannot be made smaller than the file it splits, so this is over
the 300-line cap with --no-verify. Every line in it is a move.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
77 lines
2.0 KiB
Go
77 lines
2.0 KiB
Go
package main
|
|
|
|
import (
|
|
_ "embed"
|
|
"log"
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"github.com/kami/maven/internal/ipc"
|
|
)
|
|
|
|
//go:embed notifications.html
|
|
var notificationsHTML string
|
|
|
|
var notificationsTmpl = parsePage("notifications", notificationsHTML, nil)
|
|
|
|
// deliveryRow is one outbox line, with every timestamp already formatted so
|
|
// the template holds no date logic — same shape as taskRow.
|
|
type deliveryRow struct {
|
|
Kind string
|
|
Target string
|
|
Channel string
|
|
Status string
|
|
Created string
|
|
Completed string
|
|
}
|
|
|
|
func deliveryRows(as []ipc.DeliveryAttempt) []deliveryRow {
|
|
out := make([]deliveryRow, 0, len(as))
|
|
for _, a := range as {
|
|
target := a.Rule
|
|
if target == "" && a.ReminderID != 0 {
|
|
target = "reminder #" + strconv.FormatInt(a.ReminderID, 10)
|
|
}
|
|
row := deliveryRow{
|
|
Kind: a.Kind,
|
|
Target: target,
|
|
Channel: a.Channel,
|
|
Status: a.Status,
|
|
Created: a.Created.Format("02.01 15:04"),
|
|
}
|
|
if a.Completed != nil {
|
|
row.Completed = a.Completed.Format("15:04")
|
|
}
|
|
out = append(out, row)
|
|
}
|
|
return out
|
|
}
|
|
|
|
func handleNotifications(w http.ResponseWriter, r *http.Request, core ipc.CoreAPI) {
|
|
if !requireCore(w, core, "notifications") {
|
|
return
|
|
}
|
|
ctx := r.Context()
|
|
nudges, err := core.RecentNudges(ctx, 50)
|
|
if err != nil {
|
|
log.Printf("notifications: %v", err)
|
|
http.Error(w, "notifications error: "+err.Error(), http.StatusBadGateway)
|
|
return
|
|
}
|
|
// The outbox, on the page that already answers "what did she send".
|
|
// A failed or dropped attempt is why she went quiet, and until now it was
|
|
// recorded and unreadable (Vikunja #390). Filter with ?status=dropped.
|
|
status := r.URL.Query().Get("status")
|
|
attempts, err := core.DeliveryAttempts(ctx, status, 50)
|
|
if err != nil {
|
|
// The nudge list is still worth showing, so this is a note on the page
|
|
// rather than a dead page.
|
|
log.Printf("notifications: delivery attempts: %v", err)
|
|
}
|
|
renderPage(w, notificationsTmpl, map[string]any{
|
|
"Nudges": nudges,
|
|
"Attempts": deliveryRows(attempts),
|
|
"Status": status,
|
|
})
|
|
}
|