oficina / fichas Public

The frame, the card beside the list, the always-editable card, History and the scriptless edit form (level-up §3, §5)

- estilo's stacked bar: Card, Edit, View, Type and Help menus, the save
  state in the lead, Search, History and New <singular>, the account at
  its end; the rail below it with counts, New type and the fold (POST
  /view/rail, the fichas-rail cookie, no row, no event).
- The name opens the card beside a narrowed list (?card=); Next and
  Previous are computed over the whole ordered list, and a card not in
  the list says so. Every other cell links the edit form, field focused.
- The card's fields are quiet inputs carrying was; the edit form changes
  only fields that differ from their was, all or nothing, with a 409
  conflict page offering theirs and mine; Saved. Undo and Undone. Redo
  come back as one-button forms.
- POST /cards/{id}/fields/{key} (JSON with script, redirect without),
  POST /cards/{id}/undo, GET /cards/{id}/history with Restore this value.
- Superseded tests rewritten: the card is editable, the name opens the
  card beside the list, the account sits at the bar's end.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev 6eabb6f794c3e67e41f7bc66496ba586befaf2d2 parent 776e231
29 files changed, +2,005 −287
  • internal/fichas/app.go +7 −0
  • internal/fichas/card_handlers.go +197 −0
  • internal/fichas/contract_release.go +14 −0
  • internal/fichas/edit_handlers.go +341 −0
  • internal/fichas/frame.go +227 −0
  • internal/fichas/handlers.go +28 −127
  • internal/fichas/icons/icons.go +7 −0
  • internal/fichas/index.go +96 −17
  • internal/fichas/list.go +14 −2
  • internal/fichas/pane.go +208 −0
  • internal/fichas/render.go +28 −1
  • internal/fichas/static/frame.css +121 −0
  • internal/fichas/static/grid.css +303 −0
  • internal/fichas/static/grid.js +1 −0
  • internal/fichas/static/savestatus.css +41 −0
  • internal/fichas/templates/card_edit.html +23 −5
  • internal/fichas/templates/card_new.html +1 −1
  • internal/fichas/templates/card_show.html +4 −45
  • internal/fichas/templates/history.html +46 −0
  • internal/fichas/templates/index.html +60 −30
  • internal/fichas/templates/partials.html +162 −0
  • internal/fichas/templates/shell.html +20 −19
  • internal/fichastest/account_test.go +9 −10
  • internal/fichastest/designer_test.go +8 −5
  • internal/fichastest/listprefs_test.go +11 −4
  • internal/fichastest/surface_test.go +14 −12
  • internal/fichastest/uxfixes_test.go +1 −1
  • internal/fichastest/vendored_test.go +3 −0
  • scripts/writeestilo/main.go +10 −8
diff --git a/internal/fichas/app.go b/internal/fichas/app.go
index 27ed89f..52df7e9 100644
--- a/internal/fichas/app.go
+++ b/internal/fichas/app.go
@@ -130,6 +130,13 @@ func App(d *db.DB, cfg Config, logger *slog.Logger) (*http.ServeMux, *app, error
r.Get("/cards/{id}", a.showCard)
r.Get("/cards/{id}/edit", a.editCard)
r.Post("/cards/{id}", a.updateCard)
+ // Editing in place (level-up §5): one field, Undo and Redo, and
+ // the card's History.
+ r.Post("/cards/{id}/fields/{key}", a.setFieldValue)
+ r.Post("/cards/{id}/undo", a.undoEdit)
+ r.Get("/cards/{id}/history", a.cardHistory)
+ // The rail's fold: a preference cookie, no row, no event.
+ r.Post("/view/rail", a.foldRail)
r.Post("/cards/{id}/entries", a.addEntry)
// A destructive action gets its own URL, never a modal.
r.Get("/cards/{id}/delete", a.confirmDelete)
diff --git a/internal/fichas/card_handlers.go b/internal/fichas/card_handlers.go
new file mode 100644
index 0000000..bf9c1e7
--- /dev/null
+++ b/internal/fichas/card_handlers.go
@@ -0,0 +1,197 @@
+package fichas
+
+// A card's own pages: the full page, the scriptless edit form with its
+// all-or-nothing conflict page (level-up §5.2, §5.7), and History (§5.5).
+
+import (
+ "errors"
+ "net/http"
+ "strconv"
+
+ "gorm.io/gorm"
+)
+
+// showCard is a card on its own page: the same card the pane shows.
+func (a *app) showCard(w http.ResponseWriter, r *http.Request) {
+ id, ok := pathID(w, r)
+ if !ok {
+ return
+ }
+ card, err := LoadCard(r.Context(), a.db.G, a.sealer, id)
+ if err != nil {
+ a.notFoundOrFail(w, r, err)
+ return
+ }
+ entryFields, err := EntryFields(r.Context(), a.db.G, a.sealer, TypeCallLog)
+ if err != nil {
+ a.fail(w, r, err)
+ return
+ }
+ pane := cardPane{Card: card, CloseHref: typeHref(card.TypeKey)}
+ pane.EditedBy, pane.EditedAt = a.editedBy(r, card)
+ a.page(w, r, "card_show", map[string]any{
+ "TypeKey": card.TypeKey, "Card": card, "Pane": pane,
+ "EntryFields": entryFields, "Notice": noticeOf(r),
+ })
+}
+
+// editCard is the scriptless edit form, with ?field= focused (§5.7).
+func (a *app) editCard(w http.ResponseWriter, r *http.Request) {
+ id, ok := pathID(w, r)
+ if !ok {
+ return
+ }
+ card, err := LoadCard(r.Context(), a.db.G, a.sealer, id)
+ if err != nil {
+ a.notFoundOrFail(w, r, err)
+ return
+ }
+ a.page(w, r, "card_edit", map[string]any{
+ "TypeKey": card.TypeKey, "Card": card, "Was": wasOf(card.Fields),
+ "Focus": r.URL.Query().Get("field"), "Typed": false,
+ "Conflicts": map[string]*conflictChoice{},
+ "ReturnTo": localReturn(r.URL.Query().Get("return_to"), "/cards/"+strconv.FormatInt(id, 10)),
+ })
+}
+
+func wasOf(fields []FieldView) map[string]string {
+ out := make(map[string]string, len(fields))
+ for _, f := range fields {
+ out[f.Def.Key] = f.Value
+ }
+ return out
+}
+
+// updateCard is the edit form's POST. It sends was for every field it
+// shows and changes only the fields whose value differs from its was;
+// it is all or nothing (§5.2). A field posted with no was (a client
+// older than this form) is checked against the value now.
+func (a *app) updateCard(w http.ResponseWriter, r *http.Request) {
+ id, ok := pathID(w, r)
+ if !ok {
+ return
+ }
+ actor, err := a.actor(r)
+ if err != nil {
+ a.fail(w, r, err)
+ return
+ }
+ card, err := LoadCard(r.Context(), a.db.G, a.sealer, id)
+ if err != nil {
+ a.notFoundOrFail(w, r, err)
+ return
+ }
+ _ = r.ParseForm()
+ values, was, typed, problems := formEdit(r, card)
+ if len(problems) > 0 {
+ a.editAgain(w, r, http.StatusUnprocessableEntity, card, typed, was, problems, nil)
+ return
+ }
+ res, err := EditFields(r.Context(), a.db.G, a.sealer, id, actor, values, was)
+ if fe, ok := IsFormError(err); ok {
+ a.editAgain(w, r, http.StatusUnprocessableEntity, card, typed, was, fe, nil)
+ return
+ }
+ if c, ok := IsConflict(err); ok {
+ a.editAgain(w, r, http.StatusConflict, card, typed, was, nil, c)
+ return
+ }
+ if errors.Is(err, gorm.ErrRecordNotFound) {
+ notFound(w, r)
+ return
+ }
+ if err != nil {
+ a.fail(w, r, err)
+ return
+ }
+ if res.EventID == 0 {
+ a.backWith(w, r, id, "", "")
+ return
+ }
+ a.backWith(w, r, id, "saved", strconv.FormatInt(res.EventID, 10))
+}
+
+// formEdit reads the edit form: the canonical values that differ from
+// their was, every field's was, what was typed (to draw it again), and
+// what a person must fix.
+func formEdit(r *http.Request, card CardView) (values, was, typed map[string]string, problems FormError) {
+ values, was, typed, problems = map[string]string{}, map[string]string{}, map[string]string{}, FormError{}
+ for _, f := range card.Fields {
+ key := f.Def.Key
+ if _, posted := r.PostForm[key]; !posted {
+ continue
+ }
+ w, sent := r.PostForm["was."+key]
+ was[key] = f.Value
+ if sent {
+ was[key] = w[0]
+ }
+ typed[key] = r.PostForm.Get(key)
+ v, problem := postedValue(r, f.Def, was[key])
+ if problem != "" {
+ problems[key] = problem
+ continue
+ }
+ if normaliseValue(f.Def, v) != was[key] {
+ values[key] = v
+ }
+ }
+ return values, was, typed, problems
+}
+
+// editAgain draws the edit form again: with what was typed and the
+// problems beside it (422), or, after a conflict (409), each
+// conflicting field as two choices, theirs and mine, with theirs as its
+// new was, and the other fields as typed.
+func (a *app) editAgain(w http.ResponseWriter, r *http.Request, status int, card CardView, typed, was map[string]string, problems FormError, c *ConflictError) {
+ L := a.readerL(r)
+ conflicts := map[string]*conflictChoice{}
+ if c != nil {
+ for key, theirs := range c.Fields {
+ f := card.Field(key)
+ was[key] = theirs.Theirs
+ mine := typed[key]
+ conflicts[key] = &conflictChoice{
+ Theirs: editorSeed(L, f.Def, theirs.Theirs), Mine: mine,
+ TheirsText: orText(showValue(L, f.Def.Kind, theirs.Theirs), "nothing"),
+ MineText: orText(mine, "nothing"), By: personName(theirs.By),
+ }
+ }
+ }
+ shown := card
+ shown.Fields = withValues(card.Fields, typed)
+ a.pageStatus(w, r, status, "card_edit", map[string]any{
+ "TypeKey": card.TypeKey, "Card": shown, "Was": was, "Errors": problems,
+ "Conflicts": conflicts, "Typed": true,
+ "ReturnTo": localReturn(r.PostForm.Get("return_to"), "/cards/"+strconv.FormatInt(card.Card.ID, 10)),
+ })
+}
+
+// conflictChoice is one field's two values on the conflict page.
+type conflictChoice struct {
+ Theirs, Mine string // as they post: the editor's seed form
+ TheirsText, MineText string // as a person reads them
+ By string
+}
+
+// cardHistory is a card's History page (§5.5).
+func (a *app) cardHistory(w http.ResponseWriter, r *http.Request) {
+ id, ok := pathID(w, r)
+ if !ok {
+ return
+ }
+ card, err := LoadCard(r.Context(), a.db.G, a.sealer, id)
+ if err != nil {
+ a.notFoundOrFail(w, r, err)
+ return
+ }
+ items, err := CardHistory(r.Context(), a.db.G, a.sealer, id)
+ if err != nil {
+ a.notFoundOrFail(w, r, err)
+ return
+ }
+ a.page(w, r, "history", map[string]any{
+ "TypeKey": card.TypeKey, "Card": card, "Items": items, "Now": wasOf(card.Fields),
+ "Notice": noticeOf(r),
+ })
+}
diff --git a/internal/fichas/contract_release.go b/internal/fichas/contract_release.go
index d045d23..54938fc 100644
--- a/internal/fichas/contract_release.go
+++ b/internal/fichas/contract_release.go
@@ -2,6 +2,7 @@ package fichas
import (
"amadan.net/oficina/estilo.git/chrome"
+ "amadan.net/rastrillo/rastrillo/ui"
"crypto/ed25519"
"crypto/sha256"
"encoding/base64"
@@ -69,6 +70,10 @@ func loadContractRelease(getenv func(string) string, source string) (*ContractRe
type contractReleasePage struct {
Nav []NavItem
Account *chrome.Account
+ // The frame every shell page draws (level-up §3).
+ Bar chrome.Bar
+ L *ui.Localizer
+ Rail, Here string
Theme, Flow, Phase, Payload, Signature, Destination, Importer, Error string
Cards []CardView
@@ -83,6 +88,15 @@ func (a *app) contractPage(w http.ResponseWriter, r *http.Request, p contractRel
p.Nav, _ = a.nav(r, "")
address, _ := a.identity(r)
p.Account = a.account(r, address)
+ frame := map[string]any{}
+ if err := a.buildFrame(r, "contract_prepare", frame, p.Nav); err != nil {
+ a.fail(w, r, err)
+ return
+ }
+ p.Bar, _ = frame["Bar"].(chrome.Bar)
+ p.Rail, _ = frame["Rail"].(string)
+ p.Here, _ = frame["Here"].(string)
+ p.L = a.readerL(r)
p.Destination = a.cfg.ContractRelease.Destination
p.Importer = a.cfg.ContractRelease.Importer
if p.Phase == "send" {
diff --git a/internal/fichas/edit_handlers.go b/internal/fichas/edit_handlers.go
new file mode 100644
index 0000000..6eff832
--- /dev/null
+++ b/internal/fichas/edit_handlers.go
@@ -0,0 +1,341 @@
+package fichas
+
+// The HTTP side of editing in place (level-up §5.1–§5.3): one field at
+// a time with script (JSON back), the whole edit form without, and Undo.
+
+import (
+ "bytes"
+ "encoding/json"
+ "errors"
+ "net/http"
+ "net/url"
+ "strconv"
+ "strings"
+
+ "amadan.net/rastrillo/rastrillo/ui"
+ "github.com/go-chi/chi/v5"
+ "gorm.io/gorm"
+)
+
+// wantsJSON is a script's request: it asked for JSON back.
+func wantsJSON(r *http.Request) bool {
+ return strings.Contains(r.Header.Get("Accept"), "application/json")
+}
+
+func writeJSON(w http.ResponseWriter, status int, v any) {
+ w.Header().Set("Content-Type", "application/json; charset=utf-8")
+ w.Header().Set("Cache-Control", "no-store")
+ w.WriteHeader(status)
+ _ = json.NewEncoder(w).Encode(v)
+}
+
+// errReenter is a posted locale echo that names no locale Fichas reads
+// in: the page that posted it cannot be trusted to say what 1.500 meant.
+const errReenter = "Enter the value again."
+
+// echoedLocale is the locale the posting page was drawn in (§6.8), or
+// "" when the echo is missing or names no linked locale as rastrillo
+// spells it.
+func echoedLocale(r *http.Request, key string) string {
+ v := r.PostForm.Get(key + ".locale")
+ if id, ok := usableLocale(v); ok && id == v {
+ return v
+ }
+ return ""
+}
+
+// postedValue is one field's posted value, read in the page's locale and
+// made canonical; or a message saying what to fix.
+func postedValue(r *http.Request, def FieldDef, was string) (string, string) {
+ raw := strings.TrimSpace(r.PostForm.Get(def.Key))
+ if def.Kind != KindNumber {
+ return raw, ""
+ }
+ locale := echoedLocale(r, def.Key)
+ if locale == "" {
+ return "", errReenter
+ }
+ v, err := readNumberInput(locale, raw, was)
+ if err != nil {
+ return "", err.Error()
+ }
+ return v, ""
+}
+
+// setFieldValue is POST /cards/{id}/fields/{key}: one field, with what
+// the editor saw (was.<key>), read in the page's locale (<key>.locale).
+func (a *app) setFieldValue(w http.ResponseWriter, r *http.Request) {
+ id, ok := pathID(w, r)
+ if !ok {
+ return
+ }
+ actor, err := a.actor(r)
+ if err != nil {
+ a.fail(w, r, err)
+ return
+ }
+ _ = r.ParseForm()
+ card, err := LoadCard(r.Context(), a.db.G, a.sealer, id)
+ if err != nil {
+ a.notFoundOrFail(w, r, err)
+ return
+ }
+ key := chi.URLParam(r, "key")
+ f := card.Field(key)
+ if f.Def.Key == "" {
+ notFound(w, r)
+ return
+ }
+ was := r.PostForm.Get("was." + key)
+ value, problem := postedValue(r, f.Def, was)
+ if problem != "" {
+ a.refuseField(w, r, card, key, problem)
+ return
+ }
+ res, err := SetField(r.Context(), a.db.G, a.sealer, id, actor, key, value, was)
+ a.answerFieldEdit(w, r, card, f, res, err)
+}
+
+// answerFieldEdit says what a one-field edit did: JSON to a script, a
+// redirect to everyone else.
+func (a *app) answerFieldEdit(w http.ResponseWriter, r *http.Request, card CardView, f FieldView, res EditResult, err error) {
+ L := localizerFor(a.pageLocale(r, f.Def.Key))
+ if fe, ok := IsFormError(err); ok {
+ a.refuseField(w, r, card, f.Def.Key, fe[f.Def.Key])
+ return
+ }
+ if c, ok := IsConflict(err); ok {
+ theirs := c.Fields[f.Def.Key]
+ msg := conflictLine(L, f, theirs)
+ if !wantsJSON(r) {
+ a.backWith(w, r, card.Card.ID, "conflict", "1")
+ return
+ }
+ writeJSON(w, http.StatusConflict, map[string]any{
+ "message": msg, "theirs": theirs.Theirs, "seed": editorSeed(L, f.Def, theirs.Theirs),
+ "cell": a.cellHTML(L, card, f, theirs.Theirs),
+ })
+ return
+ }
+ if errors.Is(err, gorm.ErrRecordNotFound) {
+ notFound(w, r)
+ return
+ }
+ if err != nil {
+ a.fail(w, r, err)
+ return
+ }
+ now := res.Values[f.Def.Key]
+ msg := changedLine(L, f, now)
+ if !wantsJSON(r) {
+ if res.EventID != 0 {
+ a.backWith(w, r, card.Card.ID, "saved", strconv.FormatInt(res.EventID, 10))
+ return
+ }
+ a.backWith(w, r, card.Card.ID, "", "")
+ return
+ }
+ writeJSON(w, http.StatusOK, map[string]any{
+ "event": res.EventID, "message": msg, "value": now,
+ "seed": editorSeed(L, f.Def, now), "cell": a.cellHTML(L, card, f, now),
+ "outOfView": res.EventID != 0 && !a.stillInView(r, card, f.Def.Key, r.PostForm.Get("list")),
+ })
+}
+
+// pageLocale is the locale the posting page was drawn in, or the
+// reader's when the post carried none (a field with no number in it).
+func (a *app) pageLocale(r *http.Request, key string) string {
+ if l := echoedLocale(r, key); l != "" {
+ return l
+ }
+ return a.readerL(r).Format()
+}
+
+// refuseField answers a value a person must fix (422), writing nothing.
+func (a *app) refuseField(w http.ResponseWriter, r *http.Request, card CardView, key, problem string) {
+ if wantsJSON(r) {
+ writeJSON(w, http.StatusUnprocessableEntity, map[string]any{"error": problem})
+ return
+ }
+ a.backWith(w, r, card.Card.ID, "refused", "1")
+}
+
+// backWith returns a scriptless post to where it came from (return_to,
+// a local path only), or the card, with one notice in the query.
+func (a *app) backWith(w http.ResponseWriter, r *http.Request, cardID int64, name, value string) {
+ to := localReturn(r.PostForm.Get("return_to"), "/cards/"+strconv.FormatInt(cardID, 10))
+ if name != "" {
+ u, _ := url.Parse(to)
+ q := u.Query()
+ for _, n := range []string{"saved", "undone", "refused", "conflict"} {
+ q.Del(n)
+ }
+ q.Set(name, value)
+ u.RawQuery = q.Encode()
+ to = u.String()
+ }
+ http.Redirect(w, r, to, http.StatusSeeOther)
+}
+
+// localReturn is to when it is a path on this app, and fallback
+// otherwise: never another origin, never a scheme-relative //host.
+func localReturn(to, fallback string) string {
+ if !strings.HasPrefix(to, "/") || strings.HasPrefix(to, "//") || strings.ContainsAny(to, "\\\r\n\t") {
+ return fallback
+ }
+ u, err := url.Parse(to)
+ if err != nil || u.Host != "" || u.Scheme != "" {
+ return fallback
+ }
+ return u.RequestURI()
+}
+
+// showValue is a stored value as a reader sees it in a sentence.
+func showValue(L *ui.Localizer, kind, v string) string {
+ switch {
+ case v == "":
+ return ""
+ case kind == KindNumber:
+ return showNumber(L, v)
+ case kind == KindDate:
+ return displayDate(v)
+ case kind == KindURL:
+ return displayURL(v)
+ }
+ return v
+}
+
+// editorSeed is what an editor starts from: a number in the reader's
+// format without group marks (§6.8), anything else as stored.
+func editorSeed(L *ui.Localizer, def FieldDef, v string) string {
+ if def.Kind == KindNumber {
+ return seedNumber(L.Format(), v)
+ }
+ if def.Kind == KindURL && v != "" {
+ return displayURL(v)
+ }
+ return v
+}
+
+func changedLine(L *ui.Localizer, f FieldView, now string) string {
+ if now == "" {
+ return f.Label + " cleared."
+ }
+ return f.Label + " changed to " + showValue(L, f.Def.Kind, now) + "."
+}
+
+// conflictLine is §5.2's "Niamh changed this to Contacted a moment ago."
+func conflictLine(L *ui.Localizer, f FieldView, c Conflict) string {
+ who := "Someone"
+ if c.By != "" {
+ who = personName(c.By)
+ }
+ if c.Theirs == "" {
+ return who + " cleared this a moment ago."
+ }
+ return who + " changed this to " + showValue(L, f.Def.Kind, c.Theirs) + " a moment ago."
+}
+
+// cellHTML draws one table cell's contents as the list draws it.
+func (a *app) cellHTML(L *ui.Localizer, card CardView, f FieldView, v string) string {
+ f.Value = v
+ var buf bytes.Buffer
+ if err := pages["index"].ExecuteTemplate(&buf, "fichas-cell-value", map[string]any{"F": f, "L": L, "CardID": card.Card.ID}); err != nil {
+ a.logger.Error("drawing a cell", "err", err)
+ return ""
+ }
+ return buf.String()
+}
+
+// stillInView reports whether an edited card still belongs where it
+// was: it matches the list's search and filters, and the list is not
+// sorted by the field just changed (§5.1's "No longer in this view").
+// list is the list's query string, as the page posted it.
+func (a *app) stillInView(r *http.Request, card CardView, key, list string) bool {
+ q, err := url.ParseQuery(list)
+ if err != nil {
+ return true
+ }
+ fields, err := a.ix.Fields(card.TypeKey)
+ if err != nil {
+ return true
+ }
+ l := parseListValues(q, typeHref(card.TypeKey), fields)
+ if l.Sort == key {
+ return false
+ }
+ if err := a.ix.Sync(r.Context()); err != nil {
+ return true
+ }
+ return a.ix.Matches(card.TypeKey, l.query(), card.Card.ID)
+}
+
+// undoEdit is POST /cards/{id}/undo, naming the event to reverse (or an
+// Undo's event, to redo it).
+func (a *app) undoEdit(w http.ResponseWriter, r *http.Request) {
+ id, ok := pathID(w, r)
+ if !ok {
+ return
+ }
+ actor, err := a.actor(r)
+ if err != nil {
+ a.fail(w, r, err)
+ return
+ }
+ _ = r.ParseForm()
+ eventID, _ := strconv.ParseInt(r.PostForm.Get("event"), 10, 64)
+ res, err := Undo(r.Context(), a.db.G, a.sealer, id, actor, eventID)
+ if errors.Is(err, gorm.ErrRecordNotFound) {
+ notFound(w, r)
+ return
+ }
+ if err != nil {
+ a.fail(w, r, err)
+ return
+ }
+ card, err := LoadCard(r.Context(), a.db.G, a.sealer, id)
+ if err != nil {
+ a.notFoundOrFail(w, r, err)
+ return
+ }
+ L := a.readerL(r)
+ msg := undoLine(card, res)
+ if !wantsJSON(r) {
+ a.backWith(w, r, id, "undone", strconv.FormatInt(res.EventID, 10))
+ return
+ }
+ cells := map[string]map[string]string{}
+ for _, c := range res.Applied {
+ f := card.Field(c.Field)
+ cells[c.Field] = map[string]string{"cell": a.cellHTML(L, card, f, c.After), "value": c.After, "seed": editorSeed(L, f.Def, c.After)}
+ }
+ writeJSON(w, http.StatusOK, map[string]any{"event": res.EventID, "redo": res.Redo, "message": msg, "cells": cells})
+}
+
+// undoLine says what an Undo did, naming each field it left (§5.3).
+func undoLine(card CardView, res UndoResult) string {
+ var parts []string
+ switch {
+ case len(res.Applied) == 0:
+ parts = append(parts, "Nothing to undo.")
+ case res.Redo:
+ parts = append(parts, "Redone.")
+ default:
+ parts = append(parts, "Undone.")
+ }
+ for _, l := range res.Left {
+ label := card.Field(l.Field).Label
+ if label == "" {
+ label = "A field"
+ }
+ switch {
+ case l.Gone:
+ parts = append(parts, label+"'s old value can no longer be used, so it was left.")
+ case l.By != "":
+ parts = append(parts, label+" was changed again by "+personName(l.By)+", so it was left.")
+ default:
+ parts = append(parts, label+" was changed again, so it was left.")
+ }
+ }
+ return strings.Join(parts, " ")
+}
diff --git a/internal/fichas/frame.go b/internal/fichas/frame.go
new file mode 100644
index 0000000..4471055
--- /dev/null
+++ b/internal/fichas/frame.go
@@ -0,0 +1,227 @@
+package fichas
+
+// The frame (level-up §3): estilo's stacked bar, with Fichas' menus and
+// the save state in its slots, over the rail and the work.
+
+import (
+ "bytes"
+ "html/template"
+ "net/http"
+ "strconv"
+
+ "amadan.net/oficina/estilo.git/chrome"
+ "amadan.net/oficina/estilo.git/menu"
+ "amadan.net/oficina/estilo.git/savestatus"
+
+ "amadan.net/oficina/fichas/internal/fichas/icons"
+)
+
+// railCookie holds the rail's fold: "rail" (folded to icons) or "open".
+// Absent, CSS folds it from 800 to 1279px and opens it from 1280 (§3.3).
+const railCookie = "fichas-rail"
+
+func railState(r *http.Request) string {
+ if c, err := r.Cookie(railCookie); err == nil && (c.Value == "rail" || c.Value == "open") {
+ return c.Value
+ }
+ return ""
+}
+
+// foldRail is POST /view/rail: the fold is a preference, a cookie only.
+// It writes no row, logs no event, and returns only to a local path.
+func (a *app) foldRail(w http.ResponseWriter, r *http.Request) {
+ _ = r.ParseForm()
+ switch v := r.PostForm.Get("rail"); v {
+ case "rail", "open":
+ a.setPref(w, railCookie, v, prefMaxAge)
+ }
+ http.Redirect(w, r, localReturn(r.PostForm.Get("return_to"), "/"), http.StatusSeeOther)
+}
+
+// menuItem is one row of a menu: a link, a one-button form, a command a
+// script binds (disabled until it does), a dialog, or a divider.
+type menuItem struct {
+ Kind, Label, Href, Action, Key, Command, Dialog string
+ Fields map[string]string
+ Danger bool
+}
+
+type menuView struct {
+ ID, Title string
+ Items []menuItem
+}
+
+type menuBar struct {
+ Label string
+ Menus []menuView
+}
+
+// frameFacts is what the bar needs to know about a page.
+type frameFacts struct {
+ TypeKey, Singular, Title, Here string
+ CardID int64
+ Saving bool // an editing page: the lead shows the save state
+}
+
+// buildFrame puts the bar and the rail's state into a page's data.
+func (a *app) buildFrame(r *http.Request, name string, data map[string]any, nav []NavItem) error {
+ facts := frameFactsOf(r, name, data, nav)
+ menus, err := fragment(name, "fichas-menubar", menusFor(facts))
+ if err != nil {
+ return err
+ }
+ lead := template.HTML("")
+ if facts.Saving {
+ if lead, err = fragment(name, "estilo-save-status", saveState(r)); err != nil {
+ return err
+ }
+ }
+ links := make([]chrome.Link, 0, len(nav))
+ for _, n := range nav {
+ links = append(links, chrome.Link{Href: n.Href, Label: n.Label, Current: n.Current})
+ }
+ me, _ := a.identity(r)
+ account := a.account(r, me)
+ account.Rail = false
+ data["Bar"] = chrome.Bar{
+ App: chrome.App{Name: "Fichas", Slug: "fichas", Home: "/", Icon: assets.Path("static/brand/icon.svg")},
+ Context: facts.Title, Nav: links, NavLabel: "Types",
+ Actions: barActions(facts), Account: account, Sticky: true,
+ Labels: chrome.BarLabels{Skip: "Skip to content", Menu: "Menu"},
+ Menubar: menus, Lead: lead,
+ }
+ data["Rail"] = railState(r)
+ data["Here"] = orDefault(data["Here"], r.URL.RequestURI())
+ return nil
+}
+
+func orDefault(v any, def string) string {
+ if s, ok := v.(string); ok && s != "" {
+ return s
+ }
+ return def
+}
+
+// saveState is the lead's save state as the server knows it: "Saved"
+// after a scriptless save, blank otherwise; the script sets it as it
+// saves.
+func saveState(r *http.Request) savestatus.Data {
+ d := savestatus.Data{Saved: "Saved", Saving: "Saving…", Retrying: "Saving…", Failed: "Couldn't save", Label: "Save state"}
+ if r.URL.Query().Get("saved") != "" {
+ d.State = "saved"
+ }
+ return d
+}
+
+func frameFactsOf(r *http.Request, name string, data map[string]any, nav []NavItem) frameFacts {
+ f := frameFacts{Here: r.URL.RequestURI()}
+ f.TypeKey, _ = data["TypeKey"].(string)
+ for _, n := range nav {
+ if n.Current {
+ f.Singular, f.Title = n.Singular, n.Label
+ }
+ }
+ if c, ok := data["Card"].(CardView); ok && c.Card.ID != 0 {
+ f.CardID, f.Title, f.Singular = c.Card.ID, c.Title(), c.TypeLabel
+ }
+ if c, ok := data["Open"].(*CardView); ok && c != nil {
+ f.CardID = c.Card.ID
+ }
+ switch name {
+ case "fields":
+ f.Title = "Fields"
+ case "field_new":
+ f.Title = "New field"
+ case "field_edit":
+ f.Title = "Edit field"
+ case "type_new":
+ f.Title = "New type"
+ case "card_layout":
+ f.Title = "Card layout"
+ case "card_new":
+ f.Title = "New " + lower(f.Singular)
+ case "contract_prepare":
+ f.Title = "Contracts"
+ }
+ f.Saving = name == "index" || name == "card_show" || name == "card_edit" || name == "history"
+ return f
+}
+
+func menusFor(f frameFacts) menuBar {
+ newCard := menuItem{Kind: "link", Label: "New " + lower(orText(f.Singular, "card")), Href: "/cards/new"}
+ if f.TypeKey != "" {
+ newCard.Href += "?type=" + f.TypeKey
+ }
+ card := []menuItem{newCard}
+ if f.CardID != 0 {
+ id := strconv.FormatInt(f.CardID, 10)
+ card = append(card,
+ menuItem{Kind: "link", Label: "Open full page", Href: "/cards/" + id},
+ menuItem{Kind: "link", Label: "History", Href: "/cards/" + id + "/history"},
+ menuItem{Kind: "divider"},
+ menuItem{Kind: "link", Label: "Delete…", Href: "/cards/" + id + "/delete", Danger: true})
+ }
+ edit := []menuItem{
+ {Kind: "command", Label: "Undo", Command: "undo", Key: "⌘Z"},
+ {Kind: "command", Label: "Redo", Command: "redo", Key: "⇧⌘Z"},
+ }
+ view := []menuItem{}
+ typ := []menuItem{}
+ if f.TypeKey != "" {
+ base := typeHref(f.TypeKey)
+ view = append(view,
+ menuItem{Kind: "link", Label: "Table", Href: base},
+ menuItem{Kind: "link", Label: "Cards", Href: base + "?view=cards"},
+ menuItem{Kind: "divider"},
+ menuItem{Kind: "form", Label: "Comfortable", Action: base + "/view", Fields: map[string]string{"density": DensityComfortable, "return_to": f.Here}},
+ menuItem{Kind: "form", Label: "Compact", Action: base + "/view", Fields: map[string]string{"density": DensityCompact, "return_to": f.Here}},
+ menuItem{Kind: "divider"})
+ typ = append(typ,
+ menuItem{Kind: "link", Label: "Fields", Href: base + "/fields"},
+ menuItem{Kind: "link", Label: "Card layout", Href: base + "/layout"},
+ menuItem{Kind: "divider"})
+ }
+ view = append(view, menuItem{Kind: "form", Label: "Fold rail", Key: "⌘\\", Command: "fold", Action: "/view/rail", Fields: map[string]string{"rail": "rail", "return_to": f.Here}},
+ menuItem{Kind: "form", Label: "Unfold rail", Command: "fold", Action: "/view/rail", Fields: map[string]string{"rail": "open", "return_to": f.Here}})
+ typ = append(typ, menuItem{Kind: "link", Label: "New type", Href: "/types/new"})
+ help := []menuItem{{Kind: "dialog", Label: "Keyboard shortcuts", Dialog: "fichas-keys", Key: "?"}}
+ return menuBar{Label: "Fichas", Menus: []menuView{
+ {ID: "card", Title: "Card", Items: card},
+ {ID: "edit", Title: "Edit", Items: edit},
+ {ID: "view", Title: "View", Items: view},
+ {ID: "type", Title: "Type", Items: typ},
+ {ID: "help", Title: "Help", Items: help},
+ }}
+}
+
+func orText(s, def string) string {
+ if s == "" {
+ return def
+ }
+ return s
+}
+
+// barActions: Search, History on a card, and the primary New.
+func barActions(f frameFacts) []chrome.Action {
+ search := "/"
+ if f.TypeKey != "" {
+ search = typeHref(f.TypeKey) + "#q"
+ }
+ actions := []chrome.Action{{Item: menu.Item{Href: search, Label: "Search", Key: "⌘K"}, Icon: icons.Icon("search")}}
+ if f.CardID != 0 {
+ actions = append(actions, chrome.Action{Item: menu.Item{Href: "/cards/" + strconv.FormatInt(f.CardID, 10) + "/history", Label: "History"}, Icon: icons.Icon("history")})
+ }
+ if f.TypeKey != "" && f.Singular != "" {
+ actions = append(actions, chrome.Action{Item: menu.Item{Href: "/cards/new?type=" + f.TypeKey, Label: "New " + lower(f.Singular)}, Primary: true, Icon: icons.Icon("plus")})
+ }
+ return actions
+}
+
+// fragment executes one named template of a page into HTML for a slot.
+func fragment(page, name string, data any) (template.HTML, error) {
+ var buf bytes.Buffer
+ if err := pages[page].ExecuteTemplate(&buf, name, data); err != nil {
+ return "", err
+ }
+ return template.HTML(buf.String()), nil
+}
diff --git a/internal/fichas/handlers.go b/internal/fichas/handlers.go
index cf6058c..f112bfe 100644
--- a/internal/fichas/handlers.go
+++ b/internal/fichas/handlers.go
@@ -199,6 +199,8 @@ func (a *app) authOr500(w http.ResponseWriter, r *http.Request, which authRoute)
type NavItem struct {
Label, Href string
Current bool
+ Singular string
+ Count int
}
// page renders a shell page with what every shell page needs: the card
@@ -220,6 +222,10 @@ func (a *app) pageStatus(w http.ResponseWriter, r *http.Request, status int, nam
data["Account"] = a.account(r, me)
data["Theme"] = themeAttr(r)
data["L"] = a.readerL(r)
+ if err := a.buildFrame(r, name, data, nav); err != nil {
+ a.fail(w, r, err)
+ return
+ }
if status != http.StatusOK {
w.WriteHeader(status)
}
@@ -275,7 +281,7 @@ func (a *app) nav(r *http.Request, current string) ([]NavItem, error) {
}
var out []NavItem
for _, t := range a.ix.Types() {
- out = append(out, NavItem{Label: t.Plural, Href: typeHref(t.Key), Current: t.Key == current})
+ out = append(out, NavItem{Label: t.Plural, Href: typeHref(t.Key), Current: t.Key == current, Singular: t.Label, Count: t.Count})
}
return out, nil
}
@@ -316,62 +322,6 @@ func pluralLabel(s string) string {
return s + "s"
}
-// index is a card type's list, as a table or as cards, searched, filtered,
-// sorted and paged from the in-memory index. All of it lives in the URL
-// (list.go), so every state is a link and the page works with scripts off;
-// search.js only makes the search box update the results as you type.
-func (a *app) index(w http.ResponseWriter, r *http.Request) {
- ti, err := a.currentType(r)
- if err != nil {
- a.notFoundOrFail(w, r, err)
- return
- }
- fields, err := a.ix.Fields(ti.Key)
- if err != nil {
- a.fail(w, r, err)
- return
- }
- base := typeHref(ti.Key)
- l := parseList(r, base, fields)
- // A sort by a column this reader has hidden would order the rows by
- // something they cannot see, with no header to undo it: drop it.
- shown := shownColumns(r, ti.Key, fields)
- if l.Sort != "" && !shown[l.Sort] {
- l.Sort, l.Desc = "", false
- }
- res, err := a.ix.Query(ti.Key, l.query())
- if err != nil {
- a.fail(w, r, err)
- return
- }
- filtered := l.Q != "" || len(l.Filters) > 0
- reset := listState{base: base, View: l.View, Filters: map[string]string{}}
- a.page(w, r, "index", map[string]any{
- "TypeKey": ti.Key,
- "Result": res,
- "Cards": res.Cards,
- "Fields": fields,
- "Face": a.ix.Face(ti.Key),
- "View": l.View,
- "Q": l.Q,
- "Base": base,
- "Hidden": l.hidden(),
- "ClearHref": l.with(func(s *listState) { s.Q = "" }).href(),
- "Filters": l.filterMenus(fields),
- "Columns": l.columns(fields, shown),
- "Shown": shown,
- "Choices": columnChoices(fields, shown),
- "Density": densityOf(r),
- "Here": l.href(), // the list as shown: a dropped sort stays dropped
- "Pages": l.pages(res),
- "Count": countLine(a.readerL(r), res, filtered),
- "Filtered": filtered,
- "TableHref": l.with(func(s *listState) { s.View = "table" }).href(),
- "CardsHref": l.with(func(s *listState) { s.View = "cards" }).href(),
- "ResetHref": reset.href(),
- })
-}
-
func (a *app) newCard(w http.ResponseWriter, r *http.Request) {
ti, err := a.currentType(r)
if err != nil {
@@ -403,7 +353,23 @@ func (a *app) createCard(w http.ResponseWriter, r *http.Request) {
return
}
values := formValues(r, fields)
- card, err := CreateCard(r.Context(), a.db.G, a.sealer, ti.Key, actor, values)
+ // Numbers are read in the locale the form was drawn in (§6.8).
+ problems := FormError{}
+ for _, f := range fields {
+ if _, posted := values[f.Def.Key]; posted && f.Def.Kind == KindNumber {
+ v, problem := postedValue(r, f.Def, "")
+ if problem != "" {
+ problems[f.Def.Key] = problem
+ }
+ values[f.Def.Key] = v
+ }
+ }
+ var card Card
+ if len(problems) > 0 {
+ err = problems
+ } else {
+ card, err = CreateCard(r.Context(), a.db.G, a.sealer, ti.Key, actor, values)
+ }
if fe, ok := IsFormError(err); ok {
// Sent back with what was typed and a message beside each field
// that needs it, never a 500 and never an empty form.
@@ -431,73 +397,6 @@ func withValues(fields []FieldView, values map[string]string) []FieldView {
return out
}
-func (a *app) showCard(w http.ResponseWriter, r *http.Request) {
- id, ok := pathID(w, r)
- if !ok {
- return
- }
- card, err := LoadCard(r.Context(), a.db.G, a.sealer, id)
- if err != nil {
- a.notFoundOrFail(w, r, err)
- return
- }
- entryFields, err := EntryFields(r.Context(), a.db.G, a.sealer, TypeCallLog)
- if err != nil {
- a.fail(w, r, err)
- return
- }
- a.page(w, r, "card_show", map[string]any{
- "TypeKey": card.TypeKey,
- "Card": card,
- "EntryFields": entryFields,
- })
-}
-
-// editCard is the form, on its own URL. It used to BE the card page, which
-// put every field in an input the moment you opened a customer.
-func (a *app) editCard(w http.ResponseWriter, r *http.Request) {
- id, ok := pathID(w, r)
- if !ok {
- return
- }
- card, err := LoadCard(r.Context(), a.db.G, a.sealer, id)
- if err != nil {
- a.notFoundOrFail(w, r, err)
- return
- }
- a.page(w, r, "card_edit", map[string]any{"TypeKey": card.TypeKey, "Card": card})
-}
-
-func (a *app) updateCard(w http.ResponseWriter, r *http.Request) {
- id, ok := pathID(w, r)
- if !ok {
- return
- }
- actor, err := a.actor(r)
- if err != nil {
- a.fail(w, r, err)
- return
- }
- card, err := LoadCard(r.Context(), a.db.G, a.sealer, id)
- if err != nil {
- a.notFoundOrFail(w, r, err)
- return
- }
- values := formValues(r, card.Fields)
- err = UpdateCard(r.Context(), a.db.G, a.sealer, id, actor, values)
- if fe, ok := IsFormError(err); ok {
- card.Fields = withValues(card.Fields, values)
- a.pageStatus(w, r, http.StatusUnprocessableEntity, "card_edit", map[string]any{
- "TypeKey": card.TypeKey, "Card": card, "Errors": fe})
- return
- }
- if err != nil {
- a.fail(w, r, err)
- return
- }
- http.Redirect(w, r, "/cards/"+strconv.FormatInt(id, 10), http.StatusSeeOther)
-}
-
func (a *app) addEntry(w http.ResponseWriter, r *http.Request) {
id, ok := pathID(w, r)
if !ok {
@@ -521,15 +420,17 @@ func (a *app) addEntry(w http.ResponseWriter, r *http.Request) {
a.notFoundOrFail(w, r, lerr)
return
}
+ pane := cardPane{Card: card, CloseHref: typeHref(card.TypeKey)}
a.pageStatus(w, r, http.StatusUnprocessableEntity, "card_show", map[string]any{
- "TypeKey": card.TypeKey, "Card": card, "EntryFields": withValues(fields, values), "Errors": fe})
+ "TypeKey": card.TypeKey, "Card": card, "Pane": pane, "EntryFields": withValues(fields, values), "Errors": fe})
return
}
if err != nil {
a.notFoundOrFail(w, r, err)
return
}
- http.Redirect(w, r, "/cards/"+strconv.FormatInt(id, 10), http.StatusSeeOther)
+ // Back where the call was logged: the card beside the list, or its page.
+ http.Redirect(w, r, localReturn(r.PostForm.Get("return_to"), "/cards/"+strconv.FormatInt(id, 10)), http.StatusSeeOther)
}
// confirmDelete is a PAGE, not a modal: AGENTS.md requires a destructive
diff --git a/internal/fichas/icons/icons.go b/internal/fichas/icons/icons.go
index 75a082e..e669a90 100644
--- a/internal/fichas/icons/icons.go
+++ b/internal/fichas/icons/icons.go
@@ -20,6 +20,13 @@ package icons
import "html/template"
var icons = map[string]template.HTML{
+ "history": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/><path d="M12 7v5l4 2"/></svg>`,
+ "panel-left": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><rect width="18" height="18" x="3" y="3" rx="2"/><path d="M9 3v18"/></svg>`,
+ "maximize-2": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><path d="M15 3h6v6"/><path d="m21 3-7 7"/><path d="m3 21 7-7"/><path d="M9 21H3v-6"/></svg>`,
+ "arrow-left": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><path d="m12 19-7-7 7-7"/><path d="M19 12H5"/></svg>`,
+ "chevron-left": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><path d="m15 18-6-6 6-6"/></svg>`,
+ "chevron-right": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><path d="m9 18 6-6-6-6"/></svg>`,
+ "undo-2": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><path d="M9 14 4 9l5-5"/><path d="M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11"/></svg>`,
"users": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"/><path d="M16 3.128a4 4 0 0 1 0 7.744"/><path d="M22 21v-2a4 4 0 0 0-3-3.87"/><circle cx="9" cy="7" r="4"/></svg>`,
"truck": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><path d="M14 18V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v11a1 1 0 0 0 1 1h2"/><path d="M15 18H9"/><path d="M19 18h2a1 1 0 0 0 1-1v-3.65a1 1 0 0 0-.22-.624l-3.48-4.35A1 1 0 0 0 17.52 8H14"/><circle cx="17" cy="18" r="2"/><circle cx="7" cy="18" r="2"/></svg>`,
"phone": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><path d="M13.832 16.568a1 1 0 0 0 1.213-.303l.355-.465A2 2 0 0 1 17 15h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2A18 18 0 0 1 2 4a2 2 0 0 1 2-2h3a2 2 0 0 1 2 2v3a2 2 0 0 1-.8 1.6l-.468.351a1 1 0 0 0-.292 1.233 14 14 0 0 0 6.392 6.384"/></svg>`,
diff --git a/internal/fichas/index.go b/internal/fichas/index.go
index e8308b2..f9bdccb 100644
--- a/internal/fichas/index.go
+++ b/internal/fichas/index.go
@@ -378,22 +378,7 @@ func (ix *Index) Query(typeKey string, q Query) (Result, error) {
return Result{}, gorm.ErrRecordNotFound
}
- terms := searchTerms(q.Text)
- choice := map[string]bool{}
- for _, d := range ti.defs {
- if d.Kind == KindEnum {
- choice[d.Key] = true
- }
- }
-
- matched := make([]*indexedCard, 0, len(ti.cards))
- for _, ic := range ti.cards {
- if !matchesTerms(ic.search, terms) || !matchesFilters(ic.view, q.Filters, choice) {
- continue
- }
- matched = append(matched, ic)
- }
- sortCards(matched, ti, q)
+ matched := ix.ordered(ti, q)
res := Result{
Type: ti.ct, Label: ti.label, Plural: ti.plural, Fields: ti.blank,
@@ -430,6 +415,99 @@ func (ix *Index) Query(typeKey string, q Query) (Result, error) {
// matchesTerms: every term must appear somewhere. "bright ana" finds the card
// whose name has one and whose email has the other.
+// ordered is a query's whole list, matched and sorted. The caller holds
+// the lock.
+func (ix *Index) ordered(ti *typeIndex, q Query) []*indexedCard {
+ terms := searchTerms(q.Text)
+ choice := choiceKeys(ti)
+ matched := make([]*indexedCard, 0, len(ti.cards))
+ for _, ic := range ti.cards {
+ if !matchesTerms(ic.search, terms) || !matchesFilters(ic.view, q.Filters, choice) {
+ continue
+ }
+ matched = append(matched, ic)
+ }
+ sortCards(matched, ti, q)
+ return matched
+}
+
+// Position is where a card sits in a query's whole list, across pages:
+// what the card beside the list needs for "2 of 7" and Next and
+// Previous (§5.4).
+type Position struct {
+ At, Total int // 1-based
+ Prev, Next int64 // card ids, 0 at either end
+ PrevPage int
+ NextPage int
+ Page int // the page the card is on
+}
+
+// Position finds a card in a query's list; false when it is not in it.
+func (ix *Index) Position(typeKey string, q Query, cardID int64) (Position, bool) {
+ ix.mu.RLock()
+ defer ix.mu.RUnlock()
+ ti := ix.typeByKey(typeKey)
+ if ti == nil {
+ return Position{}, false
+ }
+ list := ix.ordered(ti, q)
+ per := q.PerPage
+ if per <= 0 {
+ per = 100
+ }
+ for i, ic := range list {
+ if ic.view.Card.ID != cardID {
+ continue
+ }
+ p := Position{At: i + 1, Total: len(list), Page: i/per + 1}
+ if i > 0 {
+ p.Prev, p.PrevPage = list[i-1].view.Card.ID, (i-1)/per+1
+ }
+ if i+1 < len(list) {
+ p.Next, p.NextPage = list[i+1].view.Card.ID, (i+1)/per+1
+ }
+ return p, true
+ }
+ return Position{}, false
+}
+
+// Matches reports whether a card is in a query's list: live, of the
+// type, and matching its search and filters.
+func (ix *Index) Matches(typeKey string, q Query, cardID int64) bool {
+ ix.mu.RLock()
+ defer ix.mu.RUnlock()
+ ti := ix.typeByKey(typeKey)
+ if ti == nil {
+ return false
+ }
+ ic, ok := ti.cards[cardID]
+ if !ok {
+ return false
+ }
+ return matchesTerms(ic.search, searchTerms(q.Text)) && matchesFilters(ic.view, q.Filters, choiceKeys(ti))
+}
+
+// typeByKey is the loaded type with this key, or nil. The caller holds
+// the lock.
+func (ix *Index) typeByKey(key string) *typeIndex {
+ for _, t := range ix.types {
+ if t.ct.Key == key {
+ return t
+ }
+ }
+ return nil
+}
+
+func choiceKeys(ti *typeIndex) map[string]bool {
+ choice := map[string]bool{}
+ for _, d := range ti.defs {
+ if d.Kind == KindEnum {
+ choice[d.Key] = true
+ }
+ }
+ return choice
+}
+
func matchesTerms(hay string, terms []string) bool {
for _, t := range terms {
if !strings.Contains(hay, t) {
@@ -542,6 +620,7 @@ func (ix *Index) Fields(typeKey string) ([]FieldView, error) {
// TypeInfo is a card type's names, for the sidebar and page titles.
type TypeInfo struct {
Key, Label, Plural string
+ Count int // live cards
}
// Types lists the card types in creation order. Call Sync first.
@@ -550,7 +629,7 @@ func (ix *Index) Types() []TypeInfo {
defer ix.mu.RUnlock()
out := make([]TypeInfo, 0, len(ix.types))
for _, t := range ix.types {
- out = append(out, TypeInfo{Key: t.ct.Key, Label: t.label, Plural: t.plural})
+ out = append(out, TypeInfo{Key: t.ct.Key, Label: t.label, Plural: t.plural, Count: len(t.cards)})
}
sort.Slice(out, func(i, j int) bool {
return out[i].Key == TypeCustomer || (out[j].Key != TypeCustomer && out[i].Key < out[j].Key)
diff --git a/internal/fichas/list.go b/internal/fichas/list.go
index 37c440b..aefe075 100644
--- a/internal/fichas/list.go
+++ b/internal/fichas/list.go
@@ -21,17 +21,26 @@ type listState struct {
Desc bool
Filters map[string]string
Page int
+ // Card is the card open beside the list (§5.4): navigation, not part
+ // of what the list shows.
+ Card int64
}
// parseList reads a list URL. Filters are read only for the type's choice
// fields, so an arbitrary query parameter cannot become a filter.
func parseList(r *http.Request, base string, fields []FieldView) listState {
- q := r.URL.Query()
+ return parseListValues(r.URL.Query(), base, fields)
+}
+
+// parseListValues is parseList over a query already parsed: the list a
+// cell edit was posted from (§5.1) reads its state this way.
+func parseListValues(q url.Values, base string, fields []FieldView) listState {
l := listState{base: base, View: q.Get("view"), Q: q.Get("q"), Sort: q.Get("sort"), Desc: q.Get("dir") == "desc", Filters: map[string]string{}}
if l.View != "cards" {
l.View = "table"
}
l.Page, _ = strconv.Atoi(q.Get("page"))
+ l.Card, _ = strconv.ParseInt(q.Get("card"), 10, 64)
for _, f := range fields {
if f.Def.Kind == KindEnum {
if v := q.Get(f.Def.Key); v != "" {
@@ -73,6 +82,9 @@ func (l listState) href() string {
if l.Page > 1 {
v.Set("page", strconv.Itoa(l.Page))
}
+ if l.Card > 0 {
+ v.Set("card", strconv.FormatInt(l.Card, 10))
+ }
if len(v) == 0 {
return l.base
}
@@ -88,7 +100,7 @@ func (l listState) with(change func(*listState)) listState {
for k, v := range l.Filters {
c.Filters[k] = v
}
- c.Page = 0
+ c.Page, c.Card = 0, 0
change(&c)
return c
}
diff --git a/internal/fichas/pane.go b/internal/fichas/pane.go
new file mode 100644
index 0000000..035ba77
--- /dev/null
+++ b/internal/fichas/pane.go
@@ -0,0 +1,208 @@
+package fichas
+
+// The list, and the card beside it (level-up §5.4). Every state lives in
+// the URL (list.go), so every state is a link and the page works with
+// scripts off; ?card= opens a card in a pane beside a narrowed list.
+
+import (
+ "net/http"
+ "strconv"
+ "time"
+)
+
+// index is a card type's list, as a table or as cards, searched,
+// filtered, sorted and paged from the in-memory index, with a card open
+// beside it when ?card= names one.
+func (a *app) index(w http.ResponseWriter, r *http.Request) {
+ ti, err := a.currentType(r)
+ if err != nil {
+ a.notFoundOrFail(w, r, err)
+ return
+ }
+ fields, err := a.ix.Fields(ti.Key)
+ if err != nil {
+ a.fail(w, r, err)
+ return
+ }
+ base := typeHref(ti.Key)
+ l := parseList(r, base, fields)
+ shown := shownColumns(r, ti.Key, fields)
+ if l.Sort != "" && !shown[l.Sort] {
+ l.Sort, l.Desc = "", false
+ }
+ data := map[string]any{"TypeKey": ti.Key, "Fields": fields, "Base": base, "Shown": shown}
+ if l.Card > 0 {
+ if !a.openCard(w, r, &l, ti, data) {
+ return
+ }
+ }
+ res, err := a.ix.Query(ti.Key, l.query())
+ if err != nil {
+ a.fail(w, r, err)
+ return
+ }
+ a.listData(r, l, res, fields, shown, data)
+ a.page(w, r, "index", data)
+}
+
+// listData is everything the list draws.
+func (a *app) listData(r *http.Request, l listState, res Result, fields []FieldView, shown map[string]bool, data map[string]any) {
+ filtered := l.Q != "" || len(l.Filters) > 0
+ reset := listState{base: l.base, View: l.View, Filters: map[string]string{}}
+ open := l
+ open.Page = 0
+ for k, v := range map[string]any{
+ "Result": res, "Cards": res.Cards, "Face": a.ix.Face(res.Type.Key),
+ "View": l.View, "Q": l.Q, "Hidden": l.hidden(),
+ "ClearHref": l.with(func(s *listState) { s.Q = "" }).href(),
+ "Filters": l.filterMenus(fields), "Columns": l.columns(fields, shown),
+ "Choices": columnChoices(fields, shown), "Density": densityOf(r),
+ "Here": l.href(), // the list as shown: a dropped sort stays dropped
+ "Pages": l.pages(res), "Count": countLine(a.readerL(r), res, filtered),
+ "Filtered": filtered,
+ "TableHref": l.with(func(s *listState) { s.View = "table" }).href(),
+ "CardsHref": l.with(func(s *listState) { s.View = "cards" }).href(),
+ "ResetHref": reset.href(), "List": open, "ListQuery": listQuery(open),
+ "Notice": noticeOf(r),
+ } {
+ data[k] = v
+ }
+}
+
+// listQuery is the list's state as a query string, which a cell edit
+// posts back so the server can say whether the card is still in it.
+func listQuery(l listState) string {
+ l.Card, l.Page = 0, 0
+ h := l.href()
+ if _, q, ok := cut(h, "?"); ok {
+ return q
+ }
+ return ""
+}
+
+func cut(s, sep string) (string, string, bool) {
+ for i := 0; i+len(sep) <= len(s); i++ {
+ if s[i:i+len(sep)] == sep {
+ return s[:i], s[i+len(sep):], true
+ }
+ }
+ return s, "", false
+}
+
+// OpenHref is this list with a card open beside it.
+func (l listState) OpenHref(id int64) string {
+ c := l
+ c.Card, c.Page = id, 0
+ return c.href()
+}
+
+// CloseHref is this list with no card open, on the page it was on.
+func (l listState) CloseHref() string {
+ c := l
+ c.Card = 0
+ return c.href()
+}
+
+// openCard loads the card named by ?card= and where it sits in the
+// list. A card not in the list still opens, marked "Not in this view",
+// with no Next or Previous. false when it answered the request itself.
+func (a *app) openCard(w http.ResponseWriter, r *http.Request, l *listState, ti TypeInfo, data map[string]any) bool {
+ card, err := LoadCard(r.Context(), a.db.G, a.sealer, l.Card)
+ if err == nil && card.TypeKey != ti.Key {
+ err = errNotFound
+ }
+ if err != nil {
+ a.notFoundOrFail(w, r, err)
+ return false
+ }
+ pane := cardPane{Card: card}
+ if pos, ok := a.ix.Position(ti.Key, l.query(), card.Card.ID); ok {
+ pane.Pos = &pos
+ if r.URL.Query().Get("page") == "" {
+ l.Page = pos.Page
+ }
+ if pos.Prev != 0 {
+ pane.PrevHref = l.OpenHref(pos.Prev)
+ }
+ if pos.Next != 0 {
+ pane.NextHref = l.OpenHref(pos.Next)
+ }
+ }
+ pane.CloseHref = l.CloseHref()
+ pane.EditedBy, pane.EditedAt = a.editedBy(r, card)
+ entryFields, err := EntryFields(r.Context(), a.db.G, a.sealer, TypeCallLog)
+ if err != nil {
+ a.fail(w, r, err)
+ return false
+ }
+ data["Open"] = &card
+ data["Pane"] = pane
+ data["EntryFields"] = entryFields
+ data["Card"] = card
+ return true
+}
+
+// cardPane is the card beside the list.
+type cardPane struct {
+ Card CardView
+ Pos *Position
+ PrevHref, NextHref string
+ CloseHref string
+ EditedBy string
+ EditedAt time.Time
+}
+
+// editedBy is "Edited by": the person behind the card's last created or
+// updated event made by a person (§6.1), and when.
+func (a *app) editedBy(r *http.Request, card CardView) (string, time.Time) {
+ var e Event
+ err := a.db.G.WithContext(r.Context()).
+ Where("object_kind = ? AND object_id = ? AND kind IN ? AND actor_id IS NOT NULL",
+ ObjectCard, card.Card.ID, []string{EventCreated, EventUpdated}).
+ Order("id desc").First(&e).Error
+ if err != nil {
+ return "", time.Time{}
+ }
+ address, err := memberAddress(a.db.G.WithContext(r.Context()), a.sealer, *e.ActorID)
+ if err != nil {
+ return "", e.CreatedAt
+ }
+ return personName(address), e.CreatedAt
+}
+
+// notice is the one-line answer a scriptless edit comes back with.
+type notice struct {
+ Kind string // saved, undone, refused, conflict
+ Text string
+ EventID string // for Saved's Undo and Undone's Redo
+}
+
+func noticeOf(r *http.Request) *notice {
+ q := r.URL.Query()
+ switch {
+ case q.Get("saved") != "":
+ return &notice{Kind: "saved", Text: "Saved.", EventID: digits(q.Get("saved"))}
+ case q.Get("undone") != "":
+ id := digits(q.Get("undone"))
+ if id == "" || id == "0" {
+ return &notice{Kind: "undone", Text: "Nothing to undo: it was changed again since."}
+ }
+ return &notice{Kind: "undone", Text: "Undone.", EventID: id}
+ // Refusals come back as a flag, never as text from the URL, so a
+ // crafted link cannot put words in Fichas' mouth.
+ case q.Get("refused") != "":
+ return &notice{Kind: "refused", Text: "That value could not be saved, so nothing was written."}
+ case q.Get("conflict") != "":
+ return &notice{Kind: "conflict", Text: "Someone changed that field since this page was drawn, so nothing was written."}
+ }
+ return nil
+}
+
+// digits is s when it is a positive number, "" otherwise: a notice's
+// event id goes into a form, never anything else from the URL.
+func digits(s string) string {
+ if n, err := strconv.ParseInt(s, 10, 64); err == nil && n >= 0 {
+ return strconv.FormatInt(n, 10)
+ }
+ return ""
+}
diff --git a/internal/fichas/render.go b/internal/fichas/render.go
index 0bf964a..365d10d 100644
--- a/internal/fichas/render.go
+++ b/internal/fichas/render.go
@@ -5,11 +5,13 @@ import (
"embed"
"fmt"
"html/template"
+ "log/slog"
"net/http"
"time"
"amadan.net/oficina/estilo.git/chrome"
"amadan.net/oficina/estilo.git/menu"
+ "amadan.net/oficina/estilo.git/savestatus"
"amadan.net/rastrillo/rastrillo"
"amadan.net/rastrillo/rastrillo/ui"
@@ -43,7 +45,7 @@ func init() {
"contract_prepare": "shell", "index": "shell", "card_new": "shell", "card_show": "shell",
"card_edit": "shell", "card_delete": "shell",
"fields": "shell", "field_new": "shell", "field_edit": "shell",
- "type_new": "shell", "card_layout": "shell",
+ "type_new": "shell", "card_layout": "shell", "history": "shell",
"signin": "layout", "errors": "layout",
}
for name, shell := range shells {
@@ -59,6 +61,11 @@ func init() {
"lower": lower,
"count": count,
"showNumber": showNumber,
+ "showValue": showValue,
+ "seed": editorSeed,
+ "personName": personName,
+ "editField": editField,
+ "telHref": telHref,
"errFor": errFor,
"yesNo": yesNo,
"displayURL": displayURL,
@@ -72,6 +79,7 @@ func init() {
// last word on any name.
t = template.Must(t.ParseFS(menu.Templates(), "templates/*.html"))
t = template.Must(t.ParseFS(chrome.Templates(), "templates/*.html"))
+ t = template.Must(t.Parse(savestatus.Template()))
pages[name] = template.Must(t.ParseFS(appFS, "templates/"+shell+".html", "templates/partials.html", "templates/"+name+".html"))
}
}
@@ -83,6 +91,7 @@ func init() {
func render(w http.ResponseWriter, name string, data any) {
var buf bytes.Buffer
if err := pages[name].ExecuteTemplate(&buf, "layout", data); err != nil {
+ slog.Error("render", "page", name, "err", err)
http.Error(w, "something went wrong", http.StatusInternalServerError)
return
}
@@ -113,6 +122,24 @@ func notFound(w http.ResponseWriter, r *http.Request) {
// system. Every page draws it, so the scheme is right in the first paint.
func themeAttr(r *http.Request) string { return chrome.ThemeAttr(chrome.Appearance(r)) }
+// telHref is a phone number's tel: link, or nothing when it is not one.
+func telHref(v string) template.URL {
+ if d := telDigits(v); d != "" && looksLikeAPhoneNumber(v) {
+ return template.URL("tel:" + d)
+ }
+ return ""
+}
+
+// editField is a field as the edit form first draws it: a number as its
+// seed in the reader's format (§6.8). Once the form has been posted,
+// what was typed is drawn again as typed.
+func editField(f FieldView, typed bool, L *ui.Localizer) FieldView {
+ if !typed && f.Def.Kind == KindNumber {
+ f.Value = seedNumber(L.Format(), f.Value)
+ }
+ return f
+}
+
// selectOptions turns a field's unsealed enum values into what
// ui's field-select wants, marking the current one selected.
//
diff --git a/internal/fichas/static/frame.css b/internal/fichas/static/frame.css
new file mode 100644
index 0000000..bff9179
--- /dev/null
+++ b/internal/fichas/static/frame.css
@@ -0,0 +1,121 @@
+/* frame.css — the frame (level-up §3): estilo's stacked bar over the rail
+ and the work. The bar is estilo's (chrome.css); this file lays out what
+ sits under it, and the rail (R1: its rows keep the 16px icon column and
+ the label on one centre line, TestRailIconsSitOnTheTextsCentreLine).
+
+ Breakpoints (§3.3): from 1280px the rail is open (232px); from 800 to
+ 1279px it folds to icons unless the reader chose otherwise (the
+ fichas-rail cookie, rendered as data-rail); below 800px it is gone and
+ the bar's Menu sheet carries the types. */
+
+/* The bar's own type links are the narrow Menu sheet's; on a wide screen
+ the rail has them. */
+@media (min-width: 800px) {
+ [estilo-bar-nav] { display: none; }
+}
+
+[fichas-app] {
+ --fichas-rail-w: 232px;
+ display: grid;
+ grid-template-columns: var(--fichas-rail-w) minmax(0, 1fr);
+ min-block-size: calc(100dvh - 56px);
+}
+[fichas-app][data-rail="rail"] { --fichas-rail-w: 56px; }
+@media (min-width: 800px) and (max-width: 1279.98px) {
+ [fichas-app]:not([data-rail]) { --fichas-rail-w: 56px; }
+}
+@media (max-width: 799.98px) {
+ [fichas-app] { display: block; }
+ [fichas-rail] { display: none; }
+}
+
+[fichas-main] { min-inline-size: 0; }
+[fichas-main] > [rst-page] { max-inline-size: none; }
+
+[fichas-rail] {
+ position: sticky;
+ inset-block-start: 56px;
+ align-self: start;
+ block-size: calc(100dvh - 56px);
+ display: flex;
+ flex-direction: column;
+ gap: 2px;
+ padding: 12px 8px;
+ border-inline-end: 1px solid var(--rst-line);
+ background: var(--rst-rail-bg, var(--rst-bg));
+ overflow-y: auto;
+ box-sizing: border-box;
+}
+[fichas-rail-item] {
+ display: grid;
+ grid-template-columns: 16px minmax(0, 1fr) auto;
+ align-items: center;
+ gap: 10px;
+ min-block-size: 36px;
+ padding: 0 10px;
+ border: 0;
+ border-radius: 8px;
+ background: none;
+ color: var(--rst-text-muted);
+ font: inherit;
+ font-size: var(--rst-fs-sm);
+ text-align: start;
+ text-decoration: none;
+ cursor: pointer;
+ inline-size: 100%;
+ box-sizing: border-box;
+}
+[fichas-rail-item] > .icon { inline-size: 16px; block-size: 16px; flex-shrink: 0; }
+[fichas-rail-item]:hover { background: var(--rst-surface-2); color: var(--rst-text); }
+[fichas-rail-item]:focus-visible { outline: 2px solid var(--rst-accent); outline-offset: -2px; }
+[fichas-rail-item][aria-current] { background: var(--rst-accent-soft); color: var(--rst-text); font-weight: 600; }
+[fichas-rail-item][aria-current] > .icon { color: var(--rst-accent); }
+[fichas-rail-label] { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
+[fichas-rail-count] { font-size: var(--rst-fs-xs); font-variant-numeric: tabular-nums; color: var(--rst-text-faint, var(--rst-text-muted)); }
+[fichas-rail-new] { color: var(--rst-text-muted); }
+[fichas-rail-rule] { border: 0; border-block-start: 1px solid var(--rst-line); margin: 8px 6px; }
+[fichas-rail-foot] { margin-block-start: auto; display: grid; }
+[fichas-kbd], [fichas-keys-dialog] kbd {
+ font: inherit;
+ font-size: var(--rst-fs-xs);
+ padding: 0 5px;
+ border: 1px solid var(--rst-line);
+ border-radius: 4px;
+ color: var(--rst-text-muted);
+ background: var(--rst-surface);
+}
+
+/* The fold: two buttons, one per state, and CSS shows the one that fits
+ what is on screen (Mapa build note 10). */
+[fichas-fold-to="open"] { display: none; }
+[fichas-app][data-rail="rail"] [fichas-fold-to="rail"] { display: none; }
+[fichas-app][data-rail="rail"] [fichas-fold-to="open"] { display: grid; }
+@media (min-width: 800px) and (max-width: 1279.98px) {
+ [fichas-app]:not([data-rail]) [fichas-fold-to="rail"] { display: none; }
+ [fichas-app]:not([data-rail]) [fichas-fold-to="open"] { display: grid; }
+}
+
+/* The rail folded to icons: the label stays in the accessibility tree
+ (and the row's title shows it), only the eye loses it. */
+[fichas-app][data-rail="rail"] [fichas-rail-item] { grid-template-columns: 16px; justify-content: center; padding: 0; }
+[fichas-app][data-rail="rail"] :is([fichas-rail-label], [fichas-rail-count], [fichas-kbd]) { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
+@media (min-width: 800px) and (max-width: 1279.98px) {
+ [fichas-app]:not([data-rail]) [fichas-rail-item] { grid-template-columns: 16px; justify-content: center; padding: 0; }
+ [fichas-app]:not([data-rail]) :is([fichas-rail-label], [fichas-rail-count], [fichas-kbd]) { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
+}
+
+/* Help's keys. */
+[fichas-keys-dialog] {
+ border: 0;
+ border-radius: 14px;
+ padding: var(--rst-sp-5);
+ max-inline-size: min(28rem, calc(100vw - 2rem));
+ background: var(--rst-surface);
+ color: var(--rst-text);
+ box-shadow: var(--rst-shadow-pop, 0 18px 40px -12px rgb(0 0 0 / 0.35));
+}
+[fichas-keys-dialog]::backdrop { background: rgb(15 20 30 / 0.35); }
+[fichas-keys-dialog] h2 { margin-block: 0 var(--rst-sp-3); font-size: var(--rst-fs-lg); }
+[fichas-keys-list] { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 0 0 var(--rst-sp-4); }
+[fichas-keys-list] dt { white-space: nowrap; }
+[fichas-keys-list] dd { margin: 0; color: var(--rst-text-muted); }
diff --git a/internal/fichas/static/grid.css b/internal/fichas/static/grid.css
new file mode 100644
index 0000000..dff9944
--- /dev/null
+++ b/internal/fichas/static/grid.css
@@ -0,0 +1,303 @@
+/* grid.css — editing in place (level-up §5): the table's cells and their
+ editors, the card beside the list, the card's quiet inputs, History,
+ the notices and the toast, and the phone's list of rows and sheet. */
+
+/* ---- The table. The name is a link to the card; every other cell is,
+ without script, a link to the edit form, and with script the grid's
+ cell (grid.js). */
+[fichas-grid] [fichas-title-cell] { text-align: start; font-weight: 600; }
+[fichas-title-link] { color: var(--rst-text); text-decoration: none; }
+[fichas-title-link]:hover { text-decoration: underline; }
+[fichas-cell-link] { display: block; color: inherit; text-decoration: none; min-block-size: 1.5em; }
+[fichas-cell-link]:hover { text-decoration: none; }
+[fichas-grid] td[data-field] { cursor: text; position: relative; }
+[fichas-grid] td[data-kind="enum"], [fichas-grid] td[data-kind="date"] { cursor: pointer; }
+[fichas-grid] td[data-field]:hover { background: var(--rst-row-tint-hover, var(--rst-surface-2)); }
+[fichas-grid][role="grid"] :is(td, th)[tabindex="0"],
+[fichas-grid][role="grid"] :is(td, th):focus-visible,
+[fichas-grid] [data-active] {
+ outline: 2px solid var(--rst-accent);
+ outline-offset: -2px;
+}
+[fichas-grid] tr[data-out-of-view] > * { opacity: 0.62; }
+[fichas-out-of-view] {
+ display: inline-flex;
+ align-items: center;
+ gap: 4px;
+ margin-inline-start: 8px;
+ font-size: var(--rst-fs-xs);
+ font-weight: 500;
+ color: var(--rst-text-muted);
+}
+[fichas-out-of-view] > .icon { inline-size: 12px; block-size: 12px; }
+[fichas-grid-help] { margin-block-start: var(--rst-sp-2); }
+
+/* The editor floats over its cell, at least as wide, so the table never
+ reflows under the person typing. */
+[fichas-editor] {
+ position: absolute;
+ inset: 0;
+ z-index: 3;
+ display: flex;
+ align-items: center;
+ min-inline-size: 100%;
+ background: var(--rst-surface);
+ box-shadow: 0 0 0 2px var(--rst-accent), 0 10px 24px -12px rgb(23 32 60 / 0.35);
+ border-radius: 2px;
+}
+[fichas-editor] input, [fichas-editor] select {
+ inline-size: 100%;
+ block-size: 100%;
+ min-block-size: 2.25rem;
+ border: 0;
+ padding: 0 12px;
+ font: inherit;
+ font-size: max(16px, 1em);
+ color: var(--rst-text);
+ background: transparent;
+ box-sizing: border-box;
+}
+[fichas-editor] input:focus, [fichas-editor] select:focus { outline: none; }
+[fichas-editor-error] {
+ position: absolute;
+ inset-block-start: calc(100% + 4px);
+ inset-inline-start: 0;
+ z-index: 4;
+ min-inline-size: 14rem;
+ padding: 6px 10px;
+ border-radius: 8px;
+ background: var(--rst-tone-negative-bg);
+ color: var(--rst-tone-negative-fg);
+ font-size: var(--rst-fs-sm);
+ box-shadow: var(--rst-shadow-pop, 0 8px 20px -8px rgb(0 0 0 / 0.3));
+}
+[fichas-editor-error] button { margin-inline-start: 6px; }
+
+/* A choice's picker: a listbox with a search box (§6.5). */
+[fichas-picker] {
+ position: absolute;
+ inset-block-start: calc(100% + 4px);
+ inset-inline-start: 0;
+ z-index: 4;
+ min-inline-size: 14rem;
+ max-block-size: 18rem;
+ overflow: auto;
+ padding: 6px;
+ border-radius: 12px;
+ background: var(--rst-surface);
+ box-shadow: 0 0 0 1px var(--rst-line), var(--rst-shadow-pop, 0 14px 30px -12px rgb(0 0 0 / 0.35));
+}
+[fichas-picker] input { inline-size: 100%; box-sizing: border-box; padding: 6px 10px; border: 1px solid var(--rst-line); border-radius: 8px; font: inherit; font-size: max(16px, 1em); margin-block-end: 4px; background: var(--rst-surface); color: var(--rst-text); }
+[fichas-picker] [role="listbox"] { list-style: none; margin: 0; padding: 0; }
+[fichas-picker] [role="option"] { padding: 6px 10px; border-radius: 8px; cursor: pointer; min-block-size: 32px; display: flex; align-items: center; }
+[fichas-picker] [role="option"][aria-selected="true"] { background: var(--rst-accent-soft); }
+[fichas-picker] [role="option"][data-current]::after { content: "✓"; margin-inline-start: auto; color: var(--rst-accent); }
+
+/* ---- The card beside the list (§5.4). */
+[fichas-split-view] {
+ display: grid;
+ grid-template-columns: 288px minmax(0, 1fr);
+ gap: 0;
+ margin-inline: calc(-1 * var(--rst-px, 24px));
+ margin-block-start: calc(-1 * var(--rst-py, 16px));
+ min-block-size: calc(100dvh - 56px);
+}
+[fichas-narrow] { border-inline-end: 1px solid var(--rst-line); min-inline-size: 0; }
+[fichas-narrow-head] {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ padding: 12px 14px;
+ border-block-end: 1px solid var(--rst-line);
+ font-weight: 600;
+ position: sticky;
+ inset-block-start: 56px;
+ background: var(--rst-bg);
+ z-index: 1;
+}
+[fichas-narrow-back] { display: inline-flex; color: var(--rst-text-muted); min-inline-size: 28px; min-block-size: 28px; align-items: center; justify-content: center; border-radius: 6px; }
+[fichas-narrow-back]:hover { background: var(--rst-surface-2); color: var(--rst-text); }
+[fichas-narrow-name] { flex: 1; }
+[fichas-narrow-count] { color: var(--rst-text-muted); font-weight: 500; font-variant-numeric: tabular-nums; }
+[fichas-narrow-list] { list-style: none; margin: 0; padding: 0; }
+[fichas-narrow-list] a {
+ display: grid;
+ gap: 4px;
+ padding: 12px 14px;
+ border-block-end: 1px solid var(--rst-line);
+ border-inline-start: 3px solid transparent;
+ color: var(--rst-text);
+ text-decoration: none;
+}
+[fichas-narrow-list] a:hover { background: var(--rst-surface-2); }
+[fichas-narrow-list] a[aria-current] { background: var(--rst-accent-soft); border-inline-start-color: var(--rst-accent); }
+[fichas-narrow-face] { display: flex; align-items: center; gap: 8px; font-size: var(--rst-fs-sm); }
+[fichas-pane] { padding: 20px clamp(16px, 3vw, 40px) 40px; min-inline-size: 0; }
+[fichas-full-card] { max-inline-size: 64rem; }
+
+[fichas-card-top] { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-block-end: 12px; }
+[fichas-card-steps] { display: flex; align-items: center; gap: 8px; margin-inline-end: auto; }
+[fichas-card-close] { display: inline-flex; align-items: center; justify-content: center; min-inline-size: 36px; min-block-size: 36px; border-radius: 999px; color: var(--rst-text-muted); }
+[fichas-card-close]:hover { background: var(--rst-surface-2); color: var(--rst-text); }
+[fichas-card-form] { display: grid; gap: 14px; }
+[fichas-card-heading] { margin: 0; }
+[fichas-card-meta] { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 0; color: var(--rst-text-muted); font-size: var(--rst-fs-sm); padding-block-end: 14px; border-block-end: 1px solid var(--rst-line); }
+[fichas-not-in-view] { display: inline-flex; align-items: center; gap: 4px; }
+[fichas-not-in-view] > .icon { inline-size: 14px; block-size: 14px; }
+[fichas-card-fields] { display: grid; grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr)); gap: 14px 24px; }
+[fichas-card-long] { display: grid; }
+[fichas-card-save] { display: flex; justify-content: flex-end; }
+/* With script each field saves on its own, so the form's button goes. */
+[data-fichas-live] [fichas-card-save] { display: none; }
+[fichas-card-log] { margin-block-start: 28px; display: grid; gap: 10px; max-inline-size: 44rem; }
+[fichas-card-log] h3 { margin: 0; font-size: var(--rst-fs-lg); }
+
+/* Quiet inputs: a field that reads as text until it is touched (§5.1). */
+[fichas-quiet-field] { display: grid; gap: 4px; min-inline-size: 0; }
+[fichas-quiet-label] { font-size: var(--rst-fs-sm); font-weight: 600; color: var(--rst-text-muted); }
+[fichas-quiet] {
+ inline-size: 100%;
+ box-sizing: border-box;
+ min-block-size: 36px;
+ padding: 6px 8px;
+ margin-inline: -8px;
+ border: 1px solid transparent;
+ border-radius: 8px;
+ background: transparent;
+ color: var(--rst-text);
+ font: inherit;
+ font-size: max(16px, 1em);
+}
+textarea[fichas-quiet] { resize: vertical; line-height: 1.5; }
+[fichas-quiet]:hover { border-color: var(--rst-line); }
+[fichas-quiet]:focus { outline: none; border-color: var(--rst-accent); box-shadow: 0 0 0 3px var(--rst-accent-soft); background: var(--rst-surface); }
+[fichas-quiet][aria-invalid="true"] { border-color: var(--rst-tone-negative-fg); }
+[fichas-quiet-field]:has([fichas-quiet-open]) { grid-template-columns: minmax(0, 1fr) auto; }
+[fichas-quiet-field]:has([fichas-quiet-open]) > [fichas-quiet-label] { grid-column: 1 / -1; }
+[fichas-quiet-open] { display: inline-flex; align-items: center; justify-content: center; min-inline-size: 36px; min-block-size: 36px; border-radius: 8px; color: var(--rst-text-muted); }
+[fichas-quiet-open]:hover { background: var(--rst-surface-2); color: var(--rst-accent); }
+[fichas-quiet-open] > .icon { inline-size: 15px; block-size: 15px; }
+[fichas-card-view] { display: block; }
+[fichas-live] { position: absolute; }
+[fichas-quiet-title] { font-size: clamp(1.5rem, 2.4vw, 2rem); font-weight: 700; letter-spacing: -0.01em; }
+[fichas-quiet-field][data-saving] [fichas-quiet] { border-color: var(--rst-line); }
+
+/* ---- Notices and the toast. */
+[fichas-notice] {
+ display: flex;
+ align-items: center;
+ gap: 12px;
+ margin-block-end: var(--rst-sp-3);
+ padding: 8px 12px;
+ border-radius: 10px;
+ background: var(--rst-surface-2);
+ font-size: var(--rst-fs-sm);
+}
+[fichas-notice] form { display: contents; }
+[fichas-notice="refused"], [fichas-notice="conflict"] { background: var(--rst-tone-warning-bg); color: var(--rst-tone-warning-fg); }
+[fichas-toasts] {
+ position: fixed;
+ inset-block-end: 20px;
+ inset-inline: 0;
+ display: grid;
+ justify-items: center;
+ gap: 8px;
+ pointer-events: none;
+ z-index: 40;
+}
+[fichas-toast] {
+ pointer-events: auto;
+ display: flex;
+ align-items: center;
+ gap: 14px;
+ max-inline-size: min(36rem, calc(100vw - 32px));
+ padding: 10px 12px 10px 16px;
+ border-radius: 12px;
+ background: var(--rst-text);
+ color: var(--rst-bg);
+ font-size: var(--rst-fs-sm);
+ box-shadow: 0 16px 34px -14px rgb(0 0 0 / 0.5);
+}
+[fichas-toast] button {
+ border: 0;
+ border-radius: 8px;
+ padding: 6px 10px;
+ min-block-size: 32px;
+ background: color-mix(in srgb, var(--rst-bg) 16%, transparent);
+ color: inherit;
+ font: inherit;
+ font-weight: 600;
+ cursor: pointer;
+}
+
+/* ---- History (§5.5), the edit form's conflicts, and page heads. */
+[fichas-page-head] { margin-block-end: var(--rst-sp-4); }
+[fichas-page-head] h1 { margin: 0 0 4px; }
+[fichas-page-head] a { display: inline-flex; align-items: center; gap: 4px; color: var(--rst-text-muted); }
+[fichas-history] { list-style: none; margin: 0; padding: 0; display: grid; max-inline-size: 48rem; }
+[fichas-history-item] { padding-block: 14px; border-block-end: 1px solid var(--rst-line); display: grid; gap: 8px; }
+[fichas-history-head] { margin: 0; }
+[fichas-history-head] time { color: var(--rst-text-muted); margin-inline-start: 6px; font-size: var(--rst-fs-sm); }
+[fichas-history-values] { display: grid; grid-template-columns: minmax(6rem, auto) 1fr; gap: 6px 16px; margin: 0; font-size: var(--rst-fs-sm); }
+[fichas-history-values] dt { color: var(--rst-text-muted); font-weight: 600; }
+[fichas-history-values] dd { margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
+[fichas-history-before] { text-decoration: line-through; color: var(--rst-text-muted); }
+[fichas-history-after] { font-weight: 600; }
+[fichas-restore] { display: inline; }
+[fichas-conflict] { border: 1px solid var(--rst-line); border-radius: 12px; padding: 12px 16px; margin: 0 0 var(--rst-sp-4); display: grid; gap: 8px; }
+[fichas-conflict] legend { font-weight: 600; padding-inline: 4px; }
+[fichas-conflict-choice] { display: flex; align-items: center; gap: 8px; min-block-size: 32px; }
+
+/* ---- Phones (§5.8): the table is a list of rows; a card is its own
+ screen with ‹ ›; a value opens a sheet. Inputs are at least 16px, so
+ iOS does not zoom, and every target at least 44px. */
+@media (max-width: 799.98px) {
+ [fichas-grid-wrap] { border-radius: 0; box-shadow: none; overflow: visible; }
+ [fichas-grid], [fichas-grid] tbody { display: block; }
+ [fichas-grid] thead { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip-path: inset(50%); }
+ [fichas-grid] tr {
+ display: grid;
+ grid-template-columns: minmax(0, 1fr) auto;
+ align-items: center;
+ gap: 4px 12px;
+ padding: 12px 4px;
+ border-block-end: 1px solid var(--rst-line);
+ }
+ [fichas-grid] :is(th, td) { display: none; padding: 0; border: 0; background: none; }
+ [fichas-grid] [fichas-title-cell] { display: block; grid-column: 1; }
+ [fichas-grid] [fichas-title-link] { display: flex; align-items: center; min-block-size: 44px; font-size: 1.05rem; }
+ /* the status pill, then the next two values */
+ [fichas-grid] td[data-kind="enum"] { display: block; grid-column: 2; grid-row: 1; justify-self: end; }
+ [fichas-grid] td[data-field]:not([data-kind="enum"]):nth-child(-n+4) { display: block; font-size: var(--rst-fs-sm); color: var(--rst-text-muted); }
+ [fichas-grid] [fichas-cell-link] { display: flex; align-items: center; min-block-size: 44px; }
+ [fichas-grid-help] { padding-inline: 4px; }
+
+ [fichas-split-view] { display: block; margin: 0; }
+ [fichas-narrow] { display: none; }
+ [fichas-pane] { padding: 4px 0 32px; }
+ [fichas-card-fields] { grid-template-columns: 1fr; }
+ [fichas-card-top] [rst-btn] { min-block-size: 44px; }
+ [fichas-card-close] { min-inline-size: 44px; min-block-size: 44px; }
+}
+
+/* The phone's edit sheet: a field's editor at the foot of the screen,
+ Save at its foot (§5.8). A modal <dialog>, so focus stays in it. */
+[fichas-sheet] {
+ margin: auto 0 0;
+ inline-size: 100%;
+ max-inline-size: 100%;
+ box-sizing: border-box;
+ border: 0;
+ border-radius: 18px 18px 0 0;
+ padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
+ background: var(--rst-surface);
+ color: var(--rst-text);
+ box-shadow: 0 -18px 40px -18px rgb(0 0 0 / 0.4);
+}
+[fichas-sheet]::backdrop { background: rgb(15 20 30 / 0.35); }
+[fichas-sheet] form { display: grid; gap: 12px; }
+[fichas-sheet] label { font-weight: 600; }
+[fichas-sheet] :is(input, select) { min-block-size: 44px; font-size: 16px; padding: 0 12px; border: 1px solid var(--rst-line); border-radius: 10px; background: var(--rst-surface); color: var(--rst-text); font-family: inherit; }
+[fichas-sheet-foot] { display: flex; justify-content: flex-end; gap: 8px; }
+[fichas-sheet-foot] button { min-block-size: 44px; }
+[fichas-sheet-error] { color: var(--rst-tone-negative-fg); margin: 0; font-size: var(--rst-fs-sm); }
diff --git a/internal/fichas/static/grid.js b/internal/fichas/static/grid.js
new file mode 100644
index 0000000..d79ae12
--- /dev/null
+++ b/internal/fichas/static/grid.js
@@ -0,0 +1 @@
+(function () { "use strict"; })();
diff --git a/internal/fichas/static/savestatus.css b/internal/fichas/static/savestatus.css
new file mode 100644
index 0000000..1f829b3
--- /dev/null
+++ b/internal/fichas/static/savestatus.css
@@ -0,0 +1,41 @@
+[estilo-save-status] {
+ box-sizing: border-box;
+ display: inline-block;
+ font-size: var(--rst-fs-sm);
+ line-height: 1.4;
+ margin: 0;
+ overflow-wrap: anywhere;
+}
+[estilo-save-status~="inline"] {
+ color: var(--rst-text-muted);
+ min-inline-size: 8ch;
+ min-block-size: 1em;
+}
+[estilo-save-status~="inline"]:not([data-state="saved"]) {
+ color: var(--rst-text);
+ font-weight: 600;
+}
+[estilo-save-status~="floating"] {
+ position: fixed;
+ inset-inline-end: var(--rst-sp-4);
+ inset-block-end: var(--rst-sp-4);
+ max-inline-size: min(22em, calc(100vw - var(--rst-sp-4) - var(--rst-sp-4)));
+ min-inline-size: 1px;
+ min-block-size: 1px;
+ pointer-events: none;
+}
+[estilo-save-status~="floating"]:not(:empty) {
+ padding: var(--rst-sp-2) var(--rst-sp-3);
+ border-radius: var(--rst-radius-sm);
+ box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
+ background: var(--rst-tone-neutral-bg);
+ color: var(--rst-tone-neutral-fg);
+}
+[estilo-save-status~="floating"][data-state="failed"]:not(:empty) {
+ background: var(--rst-tone-negative-bg);
+ color: var(--rst-tone-negative-fg);
+ font-weight: 600;
+}
+@media print {
+ [estilo-save-status] { display: none; }
+}
diff --git a/internal/fichas/templates/card_edit.html b/internal/fichas/templates/card_edit.html
index 02c4910..84f3da6 100644
--- a/internal/fichas/templates/card_edit.html
+++ b/internal/fichas/templates/card_edit.html
@@ -1,13 +1,31 @@
{{define "title"}}Edit {{.Card.Title}} · Fichas{{end}}
{{define "content"}}
-{{$c := .Card}}
-<header fichas-appbar>
- <h1 fichas-appbar-title>Edit {{$c.Title}} <span>{{$c.TypeLabel}}</span></h1>
+{{$c := .Card}}{{$L := .L}}
+<header fichas-page-head>
+ <h1>Edit {{$c.Title}} <span fichas-meta>{{$c.TypeLabel}}</span></h1>
</header>
+{{if .Conflicts}}<div rst-callout="warning" role="alert"><div rst-callout-body><p>Someone changed {{if eq (len .Conflicts) 1}}a field{{else}}some fields{{end}} while you were editing, so nothing was saved. Choose which value to keep for each, then save again.</p></div></div>{{end}}
+
+{{/* The scriptless edit form (§5.2, §5.7): was rides beside every field,
+ and only the fields whose value differs from it are changed. After a
+ conflict, each conflicting field offers theirs and mine. */}}
<form method="post" action="/cards/{{$c.Card.ID}}" fichas-form novalidate>
- {{range $f := $c.Fields}}{{template "fichas-input" (dict "F" $f "Error" (errFor $.Errors $f.Def.Key))}}{{end}}
- {{template "form-foot" (dict "Submit" "Save changes" "CancelHref" (printf "/cards/%d" $c.Card.ID) "CancelLabel" "Cancel")}}
+ <input type="hidden" name="return_to" value="{{.ReturnTo}}">
+ {{range $f := $c.Fields}}
+ <input type="hidden" name="was.{{$f.Def.Key}}" value="{{index $.Was $f.Def.Key}}">
+ {{with index $.Conflicts $f.Def.Key}}
+ <fieldset fichas-conflict id="{{$f.Def.Key}}">
+ <legend>{{$f.Label}}</legend>
+ {{if eq $f.Def.Kind "number"}}<input type="hidden" name="{{$f.Def.Key}}.locale" value="{{$L.Format}}">{{end}}
+ <label fichas-conflict-choice><input type="radio" name="{{$f.Def.Key}}" value="{{.Theirs}}" checked> Keep theirs: <strong>{{.TheirsText}}</strong>{{with .By}} <span fichas-meta>({{.}}'s)</span>{{end}}</label>
+ <label fichas-conflict-choice><input type="radio" name="{{$f.Def.Key}}" value="{{.Mine}}"> Use mine: <strong>{{.MineText}}</strong></label>
+ </fieldset>
+ {{else}}
+ {{template "fichas-input" (dict "F" (editField $f $.Typed $L) "Error" (errFor $.Errors $f.Def.Key) "Autofocus" (eq $.Focus $f.Def.Key) "L" $L)}}
+ {{end}}
+ {{end}}
+ {{template "form-foot" (dict "Submit" "Save changes" "CancelHref" .ReturnTo "CancelLabel" "Cancel")}}
</form>
<div fichas-danger-zone>
diff --git a/internal/fichas/templates/card_new.html b/internal/fichas/templates/card_new.html
index 5730340..6557565 100644
--- a/internal/fichas/templates/card_new.html
+++ b/internal/fichas/templates/card_new.html
@@ -6,7 +6,7 @@
<form method="post" action="/cards" fichas-form novalidate>
<input type="hidden" name="type" value="{{.TypeKey}}">
- {{range $i, $f := .Fields}}{{template "fichas-input" (dict "F" $f "Error" (errFor $.Errors $f.Def.Key) "Autofocus" (eq $i 0))}}{{end}}
+ {{range $i, $f := .Fields}}{{template "fichas-input" (dict "F" $f "Error" (errFor $.Errors $f.Def.Key) "Autofocus" (eq $i 0) "L" $.L)}}{{end}}
{{template "form-foot" (dict "Submit" (printf "Save this %s" (lower .Type.Label)) "CancelHref" (printf "/t/%s" .TypeKey) "CancelLabel" "Cancel")}}
</form>
{{end}}
diff --git a/internal/fichas/templates/card_show.html b/internal/fichas/templates/card_show.html
index da9d59e..ac9007d 100644
--- a/internal/fichas/templates/card_show.html
+++ b/internal/fichas/templates/card_show.html
@@ -1,49 +1,8 @@
{{define "title"}}{{.Card.Title}} · Fichas{{end}}
{{define "content"}}
-{{$c := .Card}}
-<header fichas-appbar>
- <h1 fichas-appbar-title>{{$c.Title}} <span>{{$c.TypeLabel}} · updated <time title="{{$c.Card.UpdatedAt.Format "2 January 2006, 15:04"}}">{{ago $c.Card.UpdatedAt}}</time></span></h1>
- <div fichas-appbar-actions><a rst-btn="primary" href="/cards/{{$c.Card.ID}}/edit">{{icon "pencil"}} Edit</a></div>
-</header>
-
-<div fichas-split>
- <section>
- <div rst-box>
- <div rst-box-head><h2>Call log</h2></div>
- <form method="post" action="/cards/{{$c.Card.ID}}/entries">
- {{range $f := .EntryFields}}{{if eq $f.Def.Key "f_body"}}
- {{template "field-textarea" (dict "Name" $f.Def.Key "Label" "Log a call" "Rows" 2 "Value" $f.Value "Error" (errFor $.Errors $f.Def.Key) "Hint" "⌘↩ to save")}}
- {{end}}{{end}}
- {{template "form-foot" (dict "Submit" "Log this call")}}
- </form>
- {{if $c.Entries}}
- <ol fichas-timeline>
- {{range $c.Entries}}
- <li><time datetime="{{.Entry.CreatedAt.Format "2006-01-02"}}" title="{{.Entry.CreatedAt.Format "2 January 2006, 15:04"}}">{{ago .Entry.CreatedAt}}</time><p>{{.Body}}</p></li>
- {{end}}
- </ol>
- {{else}}
- <p fichas-meta>No calls logged yet. Each one you add here builds this customer's history.</p>
- {{end}}
- </div>
- </section>
-
- <aside>
- <div rst-box>
- <div rst-box-head><h2>Details</h2></div>
- {{/* rastrillo's detail-list markup, written out because its partial
- has no link slot and a web address should be one. */}}
- <dl rst-detail>
- {{range $c.DetailItems}}<dt>{{.Label}}</dt><dd>{{if .Href}}<a fichas-link href="{{.Href}}"{{if .External}} target="_blank" rel="noopener noreferrer"{{end}}>{{.Value}}</a>{{else}}{{.Value}}{{end}}</dd>
- {{end}}
- </dl>
- </div>
- {{range $c.LongFields}}
- <div rst-box>
- <div rst-box-head><h2>{{.Label}}</h2></div>
- <p fichas-prose>{{.Value}}</p>
- </div>
- {{end}}
- </aside>
+<h1 class="rst-sr-only">{{.Card.Title}}</h1>
+{{template "fichas-notice" (dict "N" .Notice "Card" .Card.Card.ID "Here" .Here)}}
+<div fichas-full-card>
+{{template "fichas-card" (dict "P" .Pane "L" .L "Here" .Here "EntryFields" .EntryFields "Errors" .Errors "Pane" false)}}
</div>
{{end}}
diff --git a/internal/fichas/templates/history.html b/internal/fichas/templates/history.html
new file mode 100644
index 0000000..d87cc1d
--- /dev/null
+++ b/internal/fichas/templates/history.html
@@ -0,0 +1,46 @@
+{{define "title"}}History of {{.Card.Title}} · Fichas{{end}}
+{{define "content"}}{{$c := .Card}}{{$L := .L}}
+<header fichas-page-head>
+ <h1>History of {{$c.Title}}</h1>
+ <p fichas-meta><a href="/cards/{{$c.Card.ID}}">{{icon "arrow-left"}} Back to the card</a></p>
+</header>
+{{template "fichas-notice" (dict "N" .Notice "Card" $c.Card.ID "Here" .Here)}}
+<p fichas-meta>Each change to this {{lower $c.TypeLabel}}, newest first. For 90 days a change keeps the values it replaced, and any of them can be put back; after that it keeps who changed what, and when.</p>
+<ol fichas-history>
+{{range .Items}}{{$item := .}}
+ <li fichas-history-item>
+ <p fichas-history-head>
+ <strong>{{if .Who}}{{personName .Who}}{{else}}Fichas{{end}}</strong>
+ {{if eq .Kind "created"}}created this {{lower $c.TypeLabel}}
+ {{else if eq .Kind "entry_added"}}logged a call
+ {{else if .Undo}}undid an earlier change
+ {{else if .Redo}}redid a change
+ {{else}}changed {{range $i, $f := .Fields}}{{if $i}}, {{end}}{{$f.Label}}{{end}}{{end}}
+ <time datetime="{{.When.Format "2006-01-02T15:04:05Z07:00"}}" title="{{.When.Format "2 January 2006, 15:04"}}">{{ago .When}}</time>
+ </p>
+ {{if and .Held .Fields (ne .Kind "entry_added")}}
+ <dl fichas-history-values>
+ {{range .Fields}}{{if .Key}}
+ <dt>{{.Label}}</dt>
+ <dd>
+ <span fichas-history-before>{{with showValue $L .Kind .Before}}{{.}}{{else}}<span fichas-empty-cell>empty</span>{{end}}</span>
+ <span aria-hidden="true"> → </span><span class="rst-sr-only"> to </span>
+ <span fichas-history-after>{{with showValue $L .Kind .After}}{{.}}{{else}}<span fichas-empty-cell>empty</span>{{end}}</span>
+ {{$now := index $.Now .Key}}{{if and (ne $item.Kind "created") (ne $now .Before)}}
+ <form method="post" action="/cards/{{$c.Card.ID}}/fields/{{.Key}}" fichas-restore>
+ <input type="hidden" name="was.{{.Key}}" value="{{$now}}">
+ <input type="hidden" name="{{.Key}}" value="{{seed $L ($c.Field .Key).Def .Before}}">
+ {{if eq .Kind "number"}}<input type="hidden" name="{{.Key}}.locale" value="{{$L.Format}}">{{end}}
+ <input type="hidden" name="return_to" value="{{$.Here}}">
+ <button rst-btn="sm" type="submit">{{icon "undo-2"}}Restore this value</button>
+ </form>{{end}}
+ </dd>
+ {{end}}{{end}}
+ </dl>
+ {{end}}
+ </li>
+{{else}}
+ <li fichas-meta>No changes yet.</li>
+{{end}}
+</ol>
+{{end}}
diff --git a/internal/fichas/templates/index.html b/internal/fichas/templates/index.html
index 2b7b752..97a920b 100644
--- a/internal/fichas/templates/index.html
+++ b/internal/fichas/templates/index.html
@@ -1,9 +1,8 @@
-{{define "title"}}{{.Result.Plural}} · Fichas{{end}}
+{{define "title"}}{{with .Open}}{{.Title}} · {{end}}{{.Result.Plural}} · Fichas{{end}}
{{define "content"}}
-<header fichas-appbar>
- <h1 fichas-appbar-title>{{.Result.Plural}}{{if .Result.All}} <span>{{number $.L .Result.All}} {{if eq .Result.All 1}}record{{else}}records{{end}}</span>{{end}}</h1>
- <div fichas-appbar-actions><a rst-btn="primary" href="/cards/new?type={{.TypeKey}}">{{icon "plus"}} Add a {{lower .Result.Label}}</a></div>
-</header>
+<h1 class="rst-sr-only">{{.Result.Plural}}</h1>
+{{template "fichas-notice" (dict "N" .Notice "Card" (or (and .Open .Open.Card.ID) 0) "Here" .Here)}}
+{{if .Open}}{{template "fichas-split" .}}{{else}}
{{if .Result.All}}
<div fichas-toolbar id="list-toolbar" data-live-region>
@@ -49,40 +48,18 @@
<div id="results" data-live-results data-live-region>
{{if .Cards}}
- {{if eq .View "table"}}
- <div fichas-grid-wrap>
- <table fichas-grid data-density="{{.Density}}">
- <thead><tr>
- {{range .Columns}}<th scope="col"{{with .Sort}} aria-sort="{{.}}"{{end}}><a href="{{.Href}}">{{.Label}}{{if eq .Sort "ascending"}} <span aria-hidden="true">↑</span>{{else if eq .Sort "descending"}} <span aria-hidden="true">↓</span>{{end}}</a></th>{{end}}
- </tr></thead>
- <tbody>
- {{range $c := .Cards}}
- <tr>
- {{range $f := $c.Fields}}{{if and (not (isLong $f.Def)) (index $.Shown $f.Def.Key)}}{{$v := $f.Value}}
- {{/* The title's link covers the whole row (fichas.css), so a row opens its card. */}}
- {{if $c.IsTitle $f.Def.Key}}<td><a fichas-row-link href="/cards/{{$c.Card.ID}}">{{$c.Title}}</a></td>
- {{else if not $v}}<td><span fichas-empty-cell>—</span></td>
- {{else if eq $f.Def.Kind "enum"}}<td>{{template "status-pill" (dict "Label" $v "Tone" (stageTone $v))}}</td>
- {{else if eq $f.Def.Kind "date"}}<td><time datetime="{{$v}}" title="{{$v}}">{{dateAgo $v}}</time></td>
- {{else if eq $f.Def.Kind "url"}}<td>{{with safeHref $v}}<a fichas-link href="{{.}}" target="_blank" rel="noopener noreferrer">{{displayURL $v}}</a>{{else}}{{$v}}{{end}}</td>
- {{else}}<td>{{$v}}</td>{{end}}
- {{end}}{{end}}
- {{if index $.Shown "_last_call"}}<td>{{with $c.Latest}}<time datetime="{{.Entry.CreatedAt.Format "2006-01-02"}}" title="{{.Entry.CreatedAt.Format "2 January 2006, 15:04"}}">{{ago .Entry.CreatedAt}}</time>{{else}}<span fichas-empty-cell>never</span>{{end}}</td>{{end}}
- </tr>
- {{end}}
- </tbody>
- </table>
- </div>
+ {{if eq .View "table"}}{{template "fichas-table" .}}
{{else}}
<ul fichas-card-grid>
{{range $c := .Cards}}{{$face := $c.Face $.Face}}
<li><article rst-card>
- <h2 fichas-card-title><a href="/cards/{{$c.Card.ID}}">{{$c.Title}}</a>{{with $face.Pill}}{{template "status-pill" (dict "Label" . "Tone" (stageTone .))}}{{end}}</h2>
+ <h2 fichas-card-title><a href="{{$.List.OpenHref $c.Card.ID}}">{{$c.Title}}</a>{{with $face.Pill}}{{template "status-pill" (dict "Label" . "Tone" (stageTone .))}}{{end}}</h2>
{{range $face.Lines}}
{{if eq .Kind "call"}}<p fichas-card-quote>{{.Value}}</p>
{{else if eq .Kind "date"}}<p fichas-meta>{{.Label}} <time datetime="{{.Date}}" title="{{.Date}}">{{dateAgo .Date}}</time></p>
{{else if eq .Kind "longtext"}}<p fichas-meta fichas-clamp>{{.Value}}</p>
{{else if eq .Kind "url"}}<p fichas-meta>{{displayURL .Value}}</p>
+ {{else if eq .Kind "number"}}<p fichas-meta>{{.Label}} <span fichas-number>{{showNumber $.L .Value}}</span></p>
{{else}}<p fichas-meta>{{.Value}}</p>{{end}}
{{end}}
</article></li>
@@ -110,3 +87,56 @@
<p><a rst-btn href="{{.Base}}/fields">{{icon "pencil"}} Set up its fields first</a></p>
{{end}}
{{end}}
+{{end}}
+
+{{/* fichas-table: the list as a table (§5.1, §5.7). The name opens the
+ card beside the list; every other cell is, without script, a link to
+ the edit form with that field focused, and with script, the editor
+ for its field (grid.js). Each cell carries what its editor needs:
+ the field, its kind, the stored value (was) and the editor's seed. */}}
+{{define "fichas-table"}}
+ <div fichas-grid-wrap>
+ <table fichas-grid data-density="{{.Density}}" data-list="{{.ListQuery}}" data-here="{{.Here}}" aria-label="{{.Result.Plural}}" aria-describedby="fichas-grid-help">
+ <thead><tr>
+ {{range .Columns}}<th scope="col"{{with .Sort}} aria-sort="{{.}}"{{end}}><a href="{{.Href}}">{{.Label}}{{if eq .Sort "ascending"}} <span aria-hidden="true">↑</span>{{else if eq .Sort "descending"}} <span aria-hidden="true">↓</span>{{end}}</a></th>{{end}}
+ </tr></thead>
+ <tbody>
+ {{range $c := .Cards}}
+ <tr data-card="{{$c.Card.ID}}">
+ {{range $f := $c.Fields}}{{if and (not (isLong $f.Def)) (index $.Shown $f.Def.Key)}}
+ {{if $c.IsTitle $f.Def.Key}}<th scope="row" fichas-title-cell><a fichas-title-link href="{{$.List.OpenHref $c.Card.ID}}">{{$c.Title}}</a></th>
+ {{else}}<td data-field="{{$f.Def.Key}}" data-kind="{{$f.Def.Kind}}" data-label="{{$f.Label}}" data-was="{{$f.Value}}" data-seed="{{seed $.L $f.Def $f.Value}}"{{if eq $f.Def.Kind "enum"}} data-options="{{range $i, $o := $f.Options}}{{if $i}}{{"\n"}}{{end}}{{$o}}{{end}}"{{end}}><a fichas-cell-link href="/cards/{{$c.Card.ID}}/edit?field={{$f.Def.Key}}&amp;return_to={{$.Here}}#{{$f.Def.Key}}">{{template "fichas-cell-value" (dict "F" $f "L" $.L)}}<span class="rst-sr-only">, change {{$f.Label}}</span></a></td>{{end}}
+ {{end}}{{end}}
+ {{if index $.Shown "_last_call"}}<td data-readonly>{{with $c.Latest}}<time datetime="{{.Entry.CreatedAt.Format "2006-01-02"}}" title="{{.Entry.CreatedAt.Format "2 January 2006, 15:04"}}">{{ago .Entry.CreatedAt}}</time>{{else}}<span fichas-empty-cell>never</span>{{end}}</td>{{end}}
+ </tr>
+ {{end}}
+ </tbody>
+ </table>
+ </div>
+ <p fichas-grid-help id="fichas-grid-help" fichas-meta>Click a cell to change it; the name opens the card beside the list.</p>
+{{end}}
+
+{{/* fichas-split: the card beside a narrowed list (§5.4). */}}
+{{define "fichas-split"}}{{$open := .Open}}
+<div fichas-split-view>
+ <nav fichas-narrow aria-label="{{.Result.Plural}}">
+ <div fichas-narrow-head>
+ <a fichas-narrow-back href="{{.Pane.CloseHref}}" aria-label="Back to the list">{{icon "arrow-left"}}</a>
+ <span fichas-narrow-name>{{.Result.Plural}}</span>
+ <span fichas-narrow-count>{{number $.L .Result.Total}}</span>
+ </div>
+ <ol fichas-narrow-list>
+ {{range $c := .Cards}}{{$face := $c.Face $.Face}}
+ <li><a href="{{$.List.OpenHref $c.Card.ID}}"{{if eq $c.Card.ID $open.Card.ID}} aria-current="true"{{end}}>
+ <strong>{{$c.Title}}</strong>
+ <span fichas-narrow-face>{{with $face.Pill}}{{template "status-pill" (dict "Label" . "Tone" (stageTone .))}}{{end}}{{range $i, $l := $face.Lines}}{{if and (eq $i 0) (ne $l.Kind "call")}}<span fichas-meta>{{if eq $l.Kind "date"}}{{dateAgo $l.Date}}{{else if eq $l.Kind "number"}}{{showNumber $.L $l.Value}}{{else}}{{$l.Value}}{{end}}</span>{{end}}{{end}}</span>
+ </a></li>
+ {{end}}
+ </ol>
+ {{with .Pages}}{{template "pagination" (dict "Items" . "Label" "Pages of results")}}{{end}}
+ </nav>
+ <section fichas-pane aria-label="{{$open.Title}}">
+ {{template "fichas-card" (dict "P" .Pane "L" .L "Here" .Here "EntryFields" .EntryFields "Errors" .Errors "Pane" true)}}
+ </section>
+</div>
+{{end}}
diff --git a/internal/fichas/templates/partials.html b/internal/fichas/templates/partials.html
index 5fe9a73..97c3d53 100644
--- a/internal/fichas/templates/partials.html
+++ b/internal/fichas/templates/partials.html
@@ -23,6 +23,7 @@
stricter than the server's) never runs; the server's message shows
beside the field instead. */}}
<div rst-field><label rst-field-label for="{{$f.Def.Key}}">{{$f.Label}}</label>
+ {{- if eq $f.Def.Kind "number"}}<input type="hidden" name="{{$f.Def.Key}}.locale" value="{{.L.Format}}">{{end}}
<input rst-input id="{{$f.Def.Key}}" name="{{$f.Def.Key}}"
{{- if eq $f.Def.Kind "email"}} type="email" inputmode="email" autocomplete="email" autocapitalize="none" autocorrect="off" spellcheck="false" placeholder="name@example.com"
{{- else if eq $f.Def.Kind "phone"}} type="tel" inputmode="tel" autocomplete="tel" placeholder="+353 1 555 0100"
@@ -35,3 +36,164 @@
{{template "field" (dict "ID" $f.Def.Key "Name" $f.Def.Key "Label" $f.Label "Value" $f.Value "Error" .Error "Autofocus" .Autofocus)}}
{{- end -}}
{{end}}
+
+{{/* fichas-rail: the rail (level-up §3.2, R1): each type with its icon
+ and count, New type below a rule, and the fold at its foot. The fold
+ is two submit buttons, one per state; CSS shows the one that fits
+ what is on screen, so it works with scripts off and with no cookie.
+ Below 800px the bar's Menu sheet carries the types instead. */}}
+{{define "fichas-rail"}}<nav fichas-rail aria-label="Types">
+ {{- range .Nav}}
+ <a fichas-rail-item href="{{.Href}}"{{if .Current}} aria-current="page"{{end}} title="{{.Label}}">{{icon "users"}}<span fichas-rail-label>{{.Label}}</span><span fichas-rail-count>{{number $.L .Count}}</span></a>
+ {{- end}}
+ <hr fichas-rail-rule>
+ <a fichas-rail-item fichas-rail-new href="/types/new" title="New type">{{icon "plus"}}<span fichas-rail-label>New type</span></a>
+ <form fichas-rail-foot method="post" action="/view/rail" data-busy="false">
+ <input type="hidden" name="return_to" value="{{.Here}}">
+ <button fichas-rail-item fichas-fold-to="rail" type="submit" name="rail" value="rail" aria-keyshortcuts="Meta+Backslash Control+Backslash" title="Fold rail">{{icon "panel-left"}}<span fichas-rail-label>Fold rail</span><kbd fichas-kbd aria-hidden="true">⌘\</kbd></button>
+ <button fichas-rail-item fichas-fold-to="open" type="submit" name="rail" value="open" aria-keyshortcuts="Meta+Backslash Control+Backslash" title="Unfold rail">{{icon "panel-left"}}<span fichas-rail-label>Unfold rail</span></button>
+ </form>
+</nav>{{end}}
+
+{{/* fichas-menubar: Card, Edit, View, Type, Help (§3.1). Each menu is a
+ <details> in estilo's exclusive group, so it opens with no script. A
+ command row is disabled until grid.js binds it; a form row is a real
+ POST, so it works with scripts off. Data: menuBar. */}}
+{{define "fichas-menubar"}}<nav estilo-menubar aria-label="{{.Label}}">
+ {{- range .Menus}}<details estilo-menubar-menu name="estilo-menus" id="fichas-menu-{{.ID}}">
+ <summary estilo-menubar-title>{{.Title}}</summary>
+ <div estilo-menu>
+ {{- range .Items}}
+ {{- if eq .Kind "divider"}}<hr>
+ {{- else if eq .Kind "link"}}<a estilo-menu-item{{if .Danger}}="danger"{{end}} href="{{.Href}}">{{template "fichas-menu-body" .}}</a>
+ {{- else if eq .Kind "form"}}<form method="post" action="{{.Action}}"{{with .Command}} data-fichas-menu="{{.}}"{{end}}>{{range $name, $value := .Fields}}<input type="hidden" name="{{$name}}" value="{{$value}}">{{end}}<button estilo-menu-item type="submit">{{template "fichas-menu-body" .}}</button></form>
+ {{- else if eq .Kind "dialog"}}<button estilo-menu-item type="button" commandfor="{{.Dialog}}" command="show-modal">{{template "fichas-menu-body" .}}</button>
+ {{- else}}<button estilo-menu-item type="button" data-fichas-command="{{.Command}}" disabled>{{template "fichas-menu-body" .}}</button>
+ {{- end}}
+ {{- end}}
+ </div>
+ </details>{{end}}
+</nav>{{end}}
+{{define "fichas-menu-body"}}<span estilo-menu-label>{{.Label}}</span>{{with .Key}}<kbd estilo-menu-key aria-hidden="true">{{.}}</kbd>{{end}}{{end}}
+
+{{/* fichas-keys: Help's list of keys (§5.6). */}}
+{{define "fichas-keys"}}<dialog fichas-keys-dialog id="fichas-keys" aria-labelledby="fichas-keys-title">
+ <h2 id="fichas-keys-title">Keyboard shortcuts</h2>
+ <dl fichas-keys-list>
+ <dt><kbd>←</kbd> <kbd>→</kbd> <kbd>↑</kbd> <kbd>↓</kbd></dt><dd>Move between cells</dd>
+ <dt><kbd>Enter</kbd></dt><dd>Change the cell; in a cell, save and move down</dd>
+ <dt>Typing</dt><dd>Replace the cell's value with what you type</dd>
+ <dt><kbd>Esc</kbd></dt><dd>Cancel a change; again, leave the table</dd>
+ <dt><kbd>Delete</kbd></dt><dd>Clear the cell</dd>
+ <dt><kbd>Tab</kbd></dt><dd>In a cell, save and move right</dd>
+ <dt><kbd>⌘Z</kbd> <kbd>⇧⌘Z</kbd></dt><dd>Undo and redo your changes</dd>
+ <dt><kbd>J</kbd> <kbd>K</kbd></dt><dd>Next and previous card, beside the list</dd>
+ <dt><kbd>⌘K</kbd></dt><dd>Search</dd>
+ <dt><kbd>⌘\</kbd></dt><dd>Fold the rail</dd>
+ </dl>
+ <form method="dialog"><button rst-btn type="submit">Close</button></form>
+</dialog>{{end}}
+
+{{/* fichas-cell-value: what a table cell shows for one field, as the
+ list draws it and as an edit draws it again. Keys: F (FieldView), L. */}}
+{{define "fichas-cell-value"}}{{$f := .F}}{{$v := $f.Value}}
+{{- if not $v}}<span fichas-empty-cell>—</span>
+{{- else if eq $f.Def.Kind "enum"}}{{template "status-pill" (dict "Label" $v "Tone" (stageTone $v))}}
+{{- else if eq $f.Def.Kind "date"}}<time datetime="{{$v}}" title="{{$v}}">{{dateAgo $v}}</time>
+{{- else if eq $f.Def.Kind "number"}}<span fichas-number>{{showNumber .L $v}}</span>
+{{- else if eq $f.Def.Kind "url"}}{{displayURL $v}}
+{{- else}}{{$v}}{{end}}{{end}}
+
+{{/* fichas-notice: what a scriptless edit comes back with: "Saved.
+ Undo", "Undone. Redo", or why nothing was written. Keys: N
+ (*notice), Card (the card id). */}}
+{{define "fichas-notice"}}{{with .N}}<div fichas-notice="{{.Kind}}" role="status">
+ <span>{{.Text}}</span>
+ {{- if and .EventID (ne .EventID "0")}}<form method="post" action="/cards/{{$.Card}}/undo"><input type="hidden" name="event" value="{{.EventID}}"><input type="hidden" name="return_to" value="{{$.Here}}"><button rst-btn="sm" type="submit">{{if eq .Kind "undone"}}Redo{{else}}Undo{{end}}</button></form>{{end}}
+</div>{{end}}{{end}}
+
+{{/* fichas-quiet: one field on the card, a quiet input that is always
+ editable (§5.1). Its was rides beside it, and a number's locale.
+ With script it saves when it loses focus; without, the card's Save
+ button posts them all. Keys: F, L, Error. */}}
+{{define "fichas-quiet"}}{{$f := .F}}{{$id := printf "card-%s" $f.Def.Key}}
+<div fichas-quiet-field data-field="{{$f.Def.Key}}" data-kind="{{$f.Def.Kind}}">
+ <label fichas-quiet-label for="{{$id}}">{{$f.Label}}</label>
+ <input type="hidden" name="was.{{$f.Def.Key}}" value="{{$f.Value}}">
+ {{- if eq $f.Def.Kind "enum"}}
+ <select fichas-quiet id="{{$id}}" name="{{$f.Def.Key}}"{{if .Error}} aria-invalid="true" aria-describedby="{{$id}}-error"{{end}}>{{range options $f.Options $f.Value}}<option value="{{.Value}}"{{if .Selected}} selected{{end}}>{{.Label}}</option>{{end}}</select>
+ {{- else if eq $f.Def.Kind "date"}}
+ <input fichas-quiet type="date" id="{{$id}}" name="{{$f.Def.Key}}" value="{{$f.Value}}"{{if .Error}} aria-invalid="true" aria-describedby="{{$id}}-error"{{end}}>
+ {{- else if isLong $f.Def}}
+ <textarea fichas-quiet id="{{$id}}" name="{{$f.Def.Key}}" rows="3"{{if .Error}} aria-invalid="true" aria-describedby="{{$id}}-error"{{end}}>{{$f.Value}}</textarea>
+ {{- else}}
+ {{- if eq $f.Def.Kind "number"}}<input type="hidden" name="{{$f.Def.Key}}.locale" value="{{.L.Format}}">{{end}}
+ <input fichas-quiet id="{{$id}}" name="{{$f.Def.Key}}" value="{{seed .L $f.Def $f.Value}}"
+ {{- if eq $f.Def.Kind "email"}} type="email" inputmode="email" autocomplete="off" autocapitalize="none" spellcheck="false"
+ {{- else if eq $f.Def.Kind "phone"}} type="tel" inputmode="tel" autocomplete="off"
+ {{- else if eq $f.Def.Kind "number"}} type="text" inputmode="decimal" fichas-number
+ {{- else if eq $f.Def.Kind "url"}} type="text" inputmode="url" autocapitalize="none" spellcheck="false"
+ {{- else}} type="text"{{end}}{{if .Error}} aria-invalid="true" aria-describedby="{{$id}}-error"{{end}}>
+ {{- with $f.Value}}
+ {{- if eq $f.Def.Kind "url"}}{{with safeHref .}}<a fichas-quiet-open href="{{.}}" target="_blank" rel="noopener noreferrer">{{icon "maximize-2"}}<span class="rst-sr-only">Visit {{displayURL $f.Value}}</span></a>{{end}}
+ {{- else if eq $f.Def.Kind "email"}}<a fichas-quiet-open href="mailto:{{.}}">{{icon "maximize-2"}}<span class="rst-sr-only">Write to {{.}}</span></a>
+ {{- else if eq $f.Def.Kind "phone"}}{{with telHref .}}<a fichas-quiet-open href="{{.}}">{{icon "phone"}}<span class="rst-sr-only">Call {{$f.Value}}</span></a>{{end}}{{end}}
+ {{- end}}
+ {{- end}}
+ {{if .Error}}<p rst-field-error id="{{$id}}-error">{{.Error}}</p>{{end}}
+</div>{{end}}
+
+{{/* fichas-card: the card, beside the list or on its own page (§5.4):
+ its title, who edited it last, where it sits in the list, its fields
+ as quiet inputs, its long text, and the call log. Keys: P (cardPane),
+ L, Here, EntryFields, Errors, Pane (bool: beside the list). */}}
+{{define "fichas-card"}}{{$c := .P.Card}}{{$L := .L}}
+<article fichas-card-view data-card="{{$c.Card.ID}}" aria-labelledby="card-title-{{$c.Card.ID}}">
+ {{if .Pane}}<div fichas-card-top>
+ <div fichas-card-steps>
+ {{with .P.PrevHref}}<a rst-btn="sm" rel="prev" href="{{.}}" data-fichas-step="prev">{{icon "chevron-left"}}Previous</a>{{end}}
+ {{with .P.NextHref}}<a rst-btn="sm" rel="next" href="{{.}}" data-fichas-step="next">Next{{icon "chevron-right"}}</a>{{end}}
+ {{if or .P.PrevHref .P.NextHref}}<span fichas-meta aria-hidden="true"><kbd fichas-kbd>J</kbd> <kbd fichas-kbd>K</kbd> next and previous</span>{{end}}
+ </div>
+ <a rst-btn="sm" href="/cards/{{$c.Card.ID}}">{{icon "maximize-2"}}Full page</a>
+ <a rst-btn="sm" href="/cards/{{$c.Card.ID}}/history">{{icon "history"}}History</a>
+ <a fichas-card-close href="{{.P.CloseHref}}" aria-label="Close the card" aria-keyshortcuts="Escape" data-fichas-close>{{icon "x"}}</a>
+ </div>{{end}}
+ <form method="post" action="/cards/{{$c.Card.ID}}" fichas-card-form data-card="{{$c.Card.ID}}" novalidate>
+ <input type="hidden" name="return_to" value="{{.Here}}">
+ {{range $c.Fields}}{{if $c.IsTitle .Def.Key}}
+ <input type="hidden" name="was.{{.Def.Key}}" value="{{.Value}}">
+ <h2 fichas-card-heading id="card-title-{{$c.Card.ID}}"><label class="rst-sr-only" for="card-{{.Def.Key}}">{{.Label}}</label><input fichas-quiet fichas-quiet-title data-field="{{.Def.Key}}" data-kind="{{.Def.Kind}}" id="card-{{.Def.Key}}" name="{{.Def.Key}}" value="{{.Value}}" autocomplete="off"{{with errFor $.Errors .Def.Key}} aria-invalid="true"{{end}}></h2>
+ {{with errFor $.Errors .Def.Key}}<p rst-field-error>{{.}}</p>{{end}}
+ {{end}}{{end}}
+ <p fichas-card-meta>
+ <span>{{$c.TypeLabel}}</span>
+ {{with .P.EditedBy}}<span>Edited by {{.}} <time datetime="{{$.P.EditedAt.Format "2006-01-02T15:04:05Z07:00"}}" title="{{$.P.EditedAt.Format "2 January 2006, 15:04"}}">{{ago $.P.EditedAt}}</time></span>{{end}}
+ {{if .Pane}}{{with .P.Pos}}<span>{{number $L .At}} of {{number $L .Total}}</span>{{else}}<span fichas-not-in-view>{{icon "info"}}Not in this view</span>{{end}}{{end}}
+ </p>
+ <div fichas-card-fields>
+ {{range $c.Fields}}{{if and (not ($c.IsTitle .Def.Key)) (not (isLong .Def))}}{{template "fichas-quiet" (dict "F" . "L" $L "Error" (errFor $.Errors .Def.Key))}}{{end}}{{end}}
+ </div>
+ {{range $c.Fields}}{{if and (not ($c.IsTitle .Def.Key)) (isLong .Def)}}<div fichas-card-long>{{template "fichas-quiet" (dict "F" . "L" $L "Error" (errFor $.Errors .Def.Key))}}</div>{{end}}{{end}}
+ <div fichas-card-save><button rst-btn="primary" type="submit">Save changes</button></div>
+ </form>
+ <section fichas-card-log aria-labelledby="call-log-{{$c.Card.ID}}">
+ <h3 id="call-log-{{$c.Card.ID}}">Call log</h3>
+ <form method="post" action="/cards/{{$c.Card.ID}}/entries">
+ <input type="hidden" name="return_to" value="{{.Here}}">
+ {{range $f := .EntryFields}}{{if eq $f.Def.Key "f_body"}}
+ {{template "field-textarea" (dict "Name" $f.Def.Key "Label" "Log a call" "Rows" 2 "Value" $f.Value "Error" (errFor $.Errors $f.Def.Key) "Hint" "⌘↩ to save")}}
+ {{end}}{{end}}
+ {{template "form-foot" (dict "Submit" "Log this call")}}
+ </form>
+ {{if $c.Entries}}
+ <ol fichas-timeline>
+ {{range $c.Entries}}
+ <li><time datetime="{{.Entry.CreatedAt.Format "2006-01-02"}}" title="{{.Entry.CreatedAt.Format "2 January 2006, 15:04"}}">{{ago .Entry.CreatedAt}}</time><p>{{.Body}}</p></li>
+ {{end}}
+ </ol>
+ {{else}}
+ <p fichas-meta>No calls logged yet. Each one you add here builds this {{lower $c.TypeLabel}}'s history.</p>
+ {{end}}
+ </section>
+</article>{{end}}
diff --git a/internal/fichas/templates/shell.html b/internal/fichas/templates/shell.html
index 881c89f..bffa1dd 100644
--- a/internal/fichas/templates/shell.html
+++ b/internal/fichas/templates/shell.html
@@ -12,12 +12,15 @@
<link rel="stylesheet" href="{{asset "static/busy.css"}}">
<link rel="stylesheet" href="{{asset "static/theme.css"}}">
<link rel="stylesheet" href="{{asset "static/brand/brand.css"}}">
-{{/* The account menu at the rail's foot is estilo's: its panel and rows
- (menu.css), the account itself (chrome.css), and the script that
- closes it on Escape or an outside click (chrome.js). */}}
+{{/* estilo's bar (chrome.css), its menus and the account (menu.css),
+ the save state in its lead (savestatus.css), and chrome.js, which
+ closes a menu on Escape or an outside click. */}}
<link rel="stylesheet" href="{{asset "static/menu.css"}}">
<link rel="stylesheet" href="{{asset "static/chrome.css"}}">
+<link rel="stylesheet" href="{{asset "static/savestatus.css"}}">
<link rel="stylesheet" href="{{asset "static/fichas.css"}}">
+<link rel="stylesheet" href="{{asset "static/frame.css"}}">
+<link rel="stylesheet" href="{{asset "static/grid.css"}}">
<script defer src="{{asset "static/rastrillo.js"}}"></script>
<script defer src="{{asset "static/busy.js"}}"></script>
<script defer src="{{asset "static/shortcuts.js"}}"></script>
@@ -29,28 +32,26 @@
{{iconAssets}}
<script defer src="{{asset "static/select.js"}}"></script>
<script defer src="{{asset "static/datetime.js"}}"></script>
+{{/* The script layer for editing in place (level-up §5): the grid's
+ keys, click to edit, the toast with Undo, J and K. Every screen
+ works without it. */}}
+<script defer src="{{asset "static/grid.js"}}"></script>
</head>
-<body>
-{{/* rastrillo's sidebar shell (ui/layouts/sidebar.html), with the app's
- own head. Sign-in and errors keep the plain column in layout.html:
- Calma keeps app chrome out of the place the suite meets you. */}}
-<div rst-shell-sidebar>
-<a rst-skip href="#main">{{T "rastrillo.ui.shell_skip"}}</a>
-<details rst-shell-chrome><summary>{{icon "menu"}}{{T "rastrillo.ui.shell_menu"}}</summary></details>
-<aside rst-shell-rail>
-<a rst-shell-brand href="/"><span estilo-brand><img estilo-brand-icon src="{{asset "static/brand/icon.svg"}}" alt="">Fichas</span></a>
-<nav rst-shell-nav>
-{{range .Nav}}<a href="{{.Href}}"{{if .Current}} aria-current="page"{{end}}>{{icon "users"}} {{.Label}}</a>
-{{end}}<a href="/types/new">{{icon "plus"}} New type</a>
-</nav>
-<div rst-shell-rail-foot>{{template "estilo-account" .Account}}</div>
-</aside>
-<main rst-shell-main id="main">
+<body data-locale="{{.L.Format}}">
+<a rst-skip href="#main">Skip to content</a>
+{{template "estilo-bar" .Bar}}
+<div fichas-app{{with .Rail}} data-rail="{{.}}"{{end}}>
+{{template "fichas-rail" .}}
+<main fichas-main id="main">
<div rst-page>
{{template "content" .}}
</div>
</main>
</div>
+{{template "fichas-keys"}}
+<div fichas-toasts>
+ <p fichas-live role="status" aria-live="polite" aria-atomic="true" class="rst-sr-only"></p>
+</div>
</body>
</html>
{{end}}
diff --git a/internal/fichastest/account_test.go b/internal/fichastest/account_test.go
index 1d2d673..27273ea 100644
--- a/internal/fichastest/account_test.go
+++ b/internal/fichastest/account_test.go
@@ -33,25 +33,24 @@ func appWith(t *testing.T, adjust func(*fichas.Config)) http.Handler {
return mux
}
-// The rail's foot is the suite's account menu (Paul, 2026-10-01: "put any
-// shared stuff in the bottom left and maybe roll it into a dropup"):
-// estilo's, at the rail's foot, carrying what every app's carries. Before,
-// the foot was the bare address and a bordered Sign out button.
-func TestTheRailFootIsTheAccountMenu(t *testing.T) {
+// The account is the suite's account menu, estilo's, carrying what every
+// app's carries. It sat at the rail's foot (Paul, 2026-10-01); the level-up
+// moves it to the end of the bar, as Docs', Slides' and Mapa's (level-up
+// §2, §3.1), and the rail's foot holds the fold.
+func TestTheBarEndsWithTheAccountMenu(t *testing.T) {
body := get(t, newApp(t), "/").Body.String()
- foot := body[strings.Index(body, "<div rst-shell-rail-foot>"):]
- foot = foot[:strings.Index(foot, "</aside>")]
+ foot := body[strings.Index(body, "<header estilo-bar"):]
+ foot = foot[:strings.Index(foot, "</header>")]
for _, want := range []string{
- `<details estilo-account="rail" name="estilo-menus">`,
+ `<details estilo-account name="estilo-menus">`,
`aria-label="Account: ` + TestOwner + `"`,
- `<span estilo-account-who dir="auto">` + TestOwner + `</span>`,
`<span estilo-menu-identity-label>Signed in as</span>`,
`<form estilo-appearance method="post" action="/appearance" role="group" aria-labelledby="estilo-appearance"`,
`<input type="hidden" name="return_to" value="/">`,
`<form method="post" action="/signout">`,
} {
if !strings.Contains(foot, want) {
- t.Errorf("the rail's foot lacks %s:\n%s", want, foot)
+ t.Errorf("the bar lacks %s:\n%s", want, foot)
}
}
if n := strings.Count(body, ">Sign out<"); n != 1 {
diff --git a/internal/fichastest/designer_test.go b/internal/fichastest/designer_test.go
index 09b8e05..8c86e89 100644
--- a/internal/fichastest/designer_test.go
+++ b/internal/fichastest/designer_test.go
@@ -123,11 +123,14 @@ func TestTheDomainIsALinkAndForgiving(t *testing.T) {
t.Fatalf("a domain without https://: status %d\n%s", rec.Code, rec.Body.String())
}
show := get(t, h, rec.Header().Get("Location")).Body.String()
- if !strings.Contains(show, `href="https://brightwater.example"`) || !strings.Contains(show, ">brightwater.example</a>") {
- t.Error("the read view does not link the address, or shows the protocol")
- }
- if !strings.Contains(get(t, h, "/").Body.String(), `href="https://brightwater.example"`) {
- t.Error("the table does not link the address")
+ // The card's field is the editor (level-up §5.1), with a link beside
+ // it to visit the address; the table's cell edits, so it links the
+ // edit form instead.
+ if !strings.Contains(show, `href="https://brightwater.example"`) || !strings.Contains(show, `value="brightwater.example"`) {
+ t.Error("the card does not link the address, or shows the protocol")
+ }
+ if list := get(t, h, "/").Body.String(); !strings.Contains(list, ">brightwater.example<") || strings.Contains(list, `href="https://brightwater.example"`) {
+ t.Error("the table does not show the address as typed, or links out of a cell that edits")
}
edit := get(t, h, rec.Header().Get("Location")+"/edit").Body.String()
if !strings.Contains(edit, `inputmode="url"`) || strings.Contains(edit, `type="url"`) {
diff --git a/internal/fichastest/listprefs_test.go b/internal/fichastest/listprefs_test.go
index 9d6cb1d..8720168 100644
--- a/internal/fichastest/listprefs_test.go
+++ b/internal/fichastest/listprefs_test.go
@@ -115,12 +115,19 @@ func TestAViewChangeOnlyReturnsToAList(t *testing.T) {
}
}
-// Every row opens its card: the title's link is the row's link.
-func TestEveryRowLinksToItsCard(t *testing.T) {
+// The name opens the card beside the list (level-up §5.4, D1); the
+// stretched row link of 2026-11-12 is gone, because every other cell
+// edits its own field.
+func TestTheNameOpensTheCardBesideTheList(t *testing.T) {
h := newApp(t)
path := createACustomer(t, h, "Cnoc Teoranta")
- if body := get(t, h, "/").Body.String(); !strings.Contains(body, `<a fichas-row-link href="`+path+`">Cnoc Teoranta</a>`) {
- t.Fatal("the row's title is not the row link")
+ id := strings.TrimPrefix(path, "/cards/")
+ body := get(t, h, "/").Body.String()
+ if !strings.Contains(body, `<a fichas-title-link href="/t/t_customer?card=`+id+`">Cnoc Teoranta</a>`) {
+ t.Fatal("the name is not a link to the card beside the list")
+ }
+ if strings.Contains(body, "fichas-row-link") {
+ t.Fatal("the stretched row link is still there")
}
}
diff --git a/internal/fichastest/surface_test.go b/internal/fichastest/surface_test.go
index 4893bf0..356d765 100644
--- a/internal/fichastest/surface_test.go
+++ b/internal/fichastest/surface_test.go
@@ -138,23 +138,25 @@ func TestNoPageNeedsJavaScript(t *testing.T) {
}
}
-// The card page used to BE the edit form: opening a customer put every
-// field in an input. Reading and editing are separate views now.
-func TestTheCardPageIsReadOnly(t *testing.T) {
+// The card is always editable (level-up §5.1): every field a quiet input
+// carrying what it was drawn with, so a save never crosses a teammate's
+// (§5.2). It used to be a read view with an Edit page; the Edit page
+// stays, as the scriptless cell's target (§5.7).
+func TestTheCardIsAlwaysEditable(t *testing.T) {
h := newApp(t)
path := createACustomer(t, h, "Cnoc Teoranta")
body := get(t, h, path).Body.String()
- for _, field := range []string{`name="f_name"`, `name="f_email"`, `name="f_stage"`} {
- if strings.Contains(body, field) {
- t.Errorf("the read view has an input for %s", field)
+ for _, field := range []string{`name="f_name"`, `name="f_email"`, `name="f_stage"`, `name="was.f_name" value="Cnoc Teoranta"`, `name="was.f_email"`} {
+ if !strings.Contains(body, field) {
+ t.Errorf("the card has no %s", field)
}
}
- if !strings.Contains(body, `href="`+path+`/edit"`) {
- t.Error("the read view does not link to editing")
+ if !strings.Contains(body, `href="`+path+`/history"`) {
+ t.Error("the card does not link to its History")
}
- // Logging a call stays on the read view: it is adding, not editing.
+ // Logging a call stays on the card: it is adding, not editing.
if !strings.Contains(body, `name="f_body"`) {
- t.Error("the read view lost the log-a-call form")
+ t.Error("the card lost the log-a-call form")
}
}
@@ -170,8 +172,8 @@ func TestEditingHasItsOwnPage(t *testing.T) {
}
// Saving lands back on the read view, not on the form.
save := post(t, h, path, url.Values{"f_name": {"Cnoc Teoranta"}, "f_notes": {"renewal is due in March"}})
- if loc := save.Header().Get("Location"); loc != path {
- t.Errorf("saving redirected to %q, want the read view %q", loc, path)
+ if loc := save.Header().Get("Location"); !strings.HasPrefix(loc, path+"?saved=") {
+ t.Errorf("saving redirected to %q, want the card with Saved. Undo", loc)
}
}
diff --git a/internal/fichastest/uxfixes_test.go b/internal/fichastest/uxfixes_test.go
index 6abe04a..d11272a 100644
--- a/internal/fichastest/uxfixes_test.go
+++ b/internal/fichastest/uxfixes_test.go
@@ -27,7 +27,7 @@ func TestACardNeedsAName(t *testing.T) {
path := createACustomer(t, h, "Cnoc Teoranta")
rec := post(t, h, path, url.Values{"f_name": {""}})
if rec.Code != http.StatusUnprocessableEntity || !strings.Contains(rec.Body.String(), "Give it a name.") {
- t.Errorf("an edit to an empty name: status %d", rec.Code)
+ t.Errorf("an edit to an empty name: status %d %s", rec.Code, rec.Body.String())
}
}
diff --git a/internal/fichastest/vendored_test.go b/internal/fichastest/vendored_test.go
index b875a8a..5f46884 100644
--- a/internal/fichastest/vendored_test.go
+++ b/internal/fichastest/vendored_test.go
@@ -4,6 +4,7 @@ import (
"amadan.net/oficina/estilo.git/busy"
"amadan.net/oficina/estilo.git/chrome"
"amadan.net/oficina/estilo.git/menu"
+ "amadan.net/oficina/estilo.git/savestatus"
"amadan.net/oficina/estilo.git/sky"
"amadan.net/oficina/estilo.git/theme"
"bytes"
@@ -126,6 +127,8 @@ func TestDoorFilesAreEstilos(t *testing.T) {
// that closes it on Escape or an outside click.
"menu.css": menu.CSS(),
"chrome.js": chrome.JS(),
+ // The bar's save state (level-up §3.1).
+ "savestatus.css": savestatus.CSS(),
} {
got, err := os.ReadFile(filepath.Join("..", "fichas", "static", name))
if err != nil {
diff --git a/scripts/writeestilo/main.go b/scripts/writeestilo/main.go
index b284d72..5640174 100644
--- a/scripts/writeestilo/main.go
+++ b/scripts/writeestilo/main.go
@@ -13,6 +13,7 @@ import (
"amadan.net/oficina/estilo.git/busy"
"amadan.net/oficina/estilo.git/chrome"
"amadan.net/oficina/estilo.git/menu"
+ "amadan.net/oficina/estilo.git/savestatus"
"amadan.net/oficina/estilo.git/sky"
"amadan.net/oficina/estilo.git/theme"
)
@@ -23,14 +24,15 @@ func main() {
panic("estilo's theme ring has no fichas")
}
for name, body := range map[string][]byte{
- "theme.css": css,
- "rastrillo.js": busy.ShimJS(),
- "busy.js": busy.JS(),
- "busy.css": busy.CSS(),
- "chrome.css": chrome.CSS(),
- "sky.css": sky.CSS(),
- "menu.css": menu.CSS(),
- "chrome.js": chrome.JS(),
+ "theme.css": css,
+ "rastrillo.js": busy.ShimJS(),
+ "busy.js": busy.JS(),
+ "busy.css": busy.CSS(),
+ "chrome.css": chrome.CSS(),
+ "sky.css": sky.CSS(),
+ "menu.css": menu.CSS(),
+ "chrome.js": chrome.JS(),
+ "savestatus.css": savestatus.CSS(),
} {
if err := os.WriteFile("internal/fichas/static/"+name, body, 0o644); err != nil {
panic(err)