The table: Comfortable and Compact, columns you choose, rows that open
Paul, 2026-11-12: the list is "a bit squished" for him, others will want
it denser; he should choose the columns he sees; and the whole row
should be clickable, unless inline editing is planned. It is not: if a
spreadsheet-style editor comes, it will be a mode of its own (as
Arrange cards is), so a click on a row in the list always opens the card.
- View menu beside Fields (table view): Density, Comfortable (the new
default, 51px rows at 13.5px) or Compact (34px at 12.5px), applied at
once (no busy hold); and a Columns checklist with the title locked on.
- Both are the reader's own, per device, in cookies, as Appearance is.
Columns per type, stored as the HIDDEN keys, so a field added later
shows up for everyone; keys are opaque, so the cookie names no field.
POST /t/{type}/view returns only to that type's list or /.
- The title's link is stretched over its row: works with scripts off,
middle-click opens a tab, one tab stop, focus ring on the row; a
link of the row's own (the domain) stays on top. Checked in Chromium
(TestARowOpensItsCard) and WebKit (Playwright, by hand).
- Lucide sliders-horizontal added for the View button.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
9 files changed,
+470
−26
internal/fichas/app.go+1 −0internal/fichas/handlers.go+6 −1internal/fichas/icons/icons.go+19 −18internal/fichas/list.go+6 −2internal/fichas/listprefs.go+162 −0internal/fichas/static/fichas.css+84 −0internal/fichas/templates/index.html+34 −5internal/fichastest/browser_test.go+35 −0internal/fichastest/listprefs_test.go+123 −0
CI passed — run details
CI log
=== vet === go vet ./... go vet -tags browser ./internal/fichastest/ === fmt === === test === go test ./... ? amadan.net/oficina/fichas/cmd/fichas [no test files] ok amadan.net/oficina/fichas/internal/fichas 1.907s ? amadan.net/oficina/fichas/internal/fichas/icons [no test files] ok amadan.net/oficina/fichas/internal/fichas/seal 0.009s ok amadan.net/oficina/fichas/internal/fichastest 1.026s ? amadan.net/oficina/fichas/scripts/mockups [no test files] ? amadan.net/oficina/fichas/scripts/preview [no test files] ? amadan.net/oficina/fichas/scripts/writeestilo [no test files] === migration-check === go tool rastrillo migration check rastrillo migration check: models and migrations agree
diff --git a/internal/fichas/app.go b/internal/fichas/app.go| index 7bbb093..811dd9f 100644 |
| --- a/internal/fichas/app.go |
| +++ b/internal/fichas/app.go |
| @@ -113,6 +113,7 @@ func App(d *db.DB, cfg Config, logger *slog.Logger) (*http.ServeMux, *app, error |
| r.Get("/t/{type}/fields", a.fieldsPage) |
| r.Get("/t/{type}/fields/new", a.newField) |
| r.Post("/t/{type}/fields", a.createField) |
| + r.Post("/t/{type}/view", a.saveView) |
| r.Get("/t/{type}/layout", a.layoutPage) |
| r.Post("/t/{type}/layout", a.saveLayout) |
| r.Get("/fields/{key}/edit", a.editField) |
diff --git a/internal/fichas/handlers.go b/internal/fichas/handlers.go| index f8989eb..f305a09 100644 |
| --- a/internal/fichas/handlers.go |
| +++ b/internal/fichas/handlers.go |
| @@ -339,6 +339,7 @@ func (a *app) index(w http.ResponseWriter, r *http.Request) { |
| } |
| filtered := l.Q != "" || len(l.Filters) > 0 |
| reset := listState{base: base, View: l.View, Filters: map[string]string{}} |
| + shown := shownColumns(r, ti.Key, fields) |
| a.page(w, r, "index", map[string]any{ |
| "TypeKey": ti.Key, |
| "Result": res, |
| @@ -351,7 +352,11 @@ func (a *app) index(w http.ResponseWriter, r *http.Request) { |
| "Hidden": l.hidden(), |
| "ClearHref": l.with(func(s *listState) { s.Q = "" }).href(), |
| "Filters": l.filterMenus(fields), |
| - "Columns": l.columns(fields), |
| + "Columns": l.columns(fields, shown), |
| + "Shown": shown, |
| + "Choices": columnChoices(fields, shown), |
| + "Density": densityOf(r), |
| + "Here": r.URL.RequestURI(), |
| "Pages": l.pages(res), |
| "Count": countLine(res, filtered), |
| "Filtered": filtered, |
diff --git a/internal/fichas/icons/icons.go b/internal/fichas/icons/icons.go| index 9ec9501..75a082e 100644 |
| --- a/internal/fichas/icons/icons.go |
| +++ b/internal/fichas/icons/icons.go |
| @@ -20,24 +20,25 @@ package icons |
| import "html/template" |
| var icons = map[string]template.HTML{ |
| - "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>`, |
| - "pencil": `<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="M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z"/><path d="m15 5 4 4"/></svg>`, |
| - "layout-grid": `<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="7" height="7" x="3" y="3" rx="1"/><rect width="7" height="7" x="14" y="3" rx="1"/><rect width="7" height="7" x="14" y="14" rx="1"/><rect width="7" height="7" x="3" y="14" rx="1"/></svg>`, |
| - "clock": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><circle cx="12" cy="12" r="10"/><path d="M12 6v6l4 2"/></svg>`, |
| - "alert-triangle": `<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="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z"/><path d="M12 9v4"/><path d="M12 17h.01"/></svg>`, |
| - "check": `<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="M20 6 9 17l-5-5"/></svg>`, |
| - "check-circle": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><circle cx="12" cy="12" r="10"/><path d="m9 12 2 2 4-4"/></svg>`, |
| - "chevron-down": `<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="m6 9 6 6 6-6"/></svg>`, |
| - "help-circle": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><circle cx="12" cy="12" r="10"/><path d="M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"/><path d="M12 17h.01"/></svg>`, |
| - "info": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><circle cx="12" cy="12" r="10"/><path d="M12 16v-4"/><path d="M12 8h.01"/></svg>`, |
| - "kebab": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><circle cx="12" cy="12" r="1"/><circle cx="12" cy="5" r="1"/><circle cx="12" cy="19" r="1"/></svg>`, |
| - "menu": `<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="M4 12h16"/><path d="M4 6h16"/><path d="M4 18h16"/></svg>`, |
| - "plus": `<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="M5 12h14"/><path d="M12 5v14"/></svg>`, |
| - "search": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><circle cx="11" cy="11" r="8"/><path d="m21 21-4.3-4.3"/></svg>`, |
| - "x": `<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="M18 6 6 18"/><path d="m6 6 12 12"/></svg>`, |
| - "x-circle": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><circle cx="12" cy="12" r="10"/><path d="m15 9-6 6"/><path d="m9 9 6 6"/></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>`, |
| + "pencil": `<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="M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z"/><path d="m15 5 4 4"/></svg>`, |
| + "layout-grid": `<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="7" height="7" x="3" y="3" rx="1"/><rect width="7" height="7" x="14" y="3" rx="1"/><rect width="7" height="7" x="14" y="14" rx="1"/><rect width="7" height="7" x="3" y="14" rx="1"/></svg>`, |
| + "clock": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><circle cx="12" cy="12" r="10"/><path d="M12 6v6l4 2"/></svg>`, |
| + "alert-triangle": `<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="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z"/><path d="M12 9v4"/><path d="M12 17h.01"/></svg>`, |
| + "check": `<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="M20 6 9 17l-5-5"/></svg>`, |
| + "check-circle": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><circle cx="12" cy="12" r="10"/><path d="m9 12 2 2 4-4"/></svg>`, |
| + "chevron-down": `<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="m6 9 6 6 6-6"/></svg>`, |
| + "help-circle": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><circle cx="12" cy="12" r="10"/><path d="M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"/><path d="M12 17h.01"/></svg>`, |
| + "info": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><circle cx="12" cy="12" r="10"/><path d="M12 16v-4"/><path d="M12 8h.01"/></svg>`, |
| + "kebab": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><circle cx="12" cy="12" r="1"/><circle cx="12" cy="5" r="1"/><circle cx="12" cy="19" r="1"/></svg>`, |
| + "menu": `<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="M4 12h16"/><path d="M4 6h16"/><path d="M4 18h16"/></svg>`, |
| + "plus": `<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="M5 12h14"/><path d="M12 5v14"/></svg>`, |
| + "sliders-horizontal": `<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="M10 5H3"/><path d="M12 19H3"/><path d="M14 3v4"/><path d="M16 17v4"/><path d="M21 12h-9"/><path d="M21 19h-5"/><path d="M21 5h-7"/><path d="M8 10v4"/><path d="M8 12H3"/></svg>`, |
| + "search": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><circle cx="11" cy="11" r="8"/><path d="m21 21-4.3-4.3"/></svg>`, |
| + "x": `<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="M18 6 6 18"/><path d="m6 6 12 12"/></svg>`, |
| + "x-circle": `<svg class="icon" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" viewBox="0 0 24 24"><circle cx="12" cy="12" r="10"/><path d="m15 9-6 6"/><path d="m9 9 6 6"/></svg>`, |
| } |
| // Icon renders one icon by its Lucide slug. An unknown slug renders |
diff --git a/internal/fichas/list.go b/internal/fichas/list.go| index e42aa13..c137c4a 100644 |
| --- a/internal/fichas/list.go |
| +++ b/internal/fichas/list.go |
| @@ -124,10 +124,14 @@ type column struct { |
| } |
| // columns are the table's headers: every field that is not long text, then |
| -// the latest call. Clicking a header sorts by it; clicking it again flips. |
| -func (l listState) columns(fields []FieldView) []column { |
| +// the latest call, less those this reader hid (listprefs.go). Clicking a |
| +// header sorts by it; clicking it again flips. |
| +func (l listState) columns(fields []FieldView, shown map[string]bool) []column { |
| var out []column |
| add := func(label, key string) { |
| + if !shown[key] { |
| + return |
| + } |
| c := column{Label: label} |
| first := key == SortLastCall // most recent call first is the useful default |
| if l.Sort == key { |
diff --git a/internal/fichas/listprefs.go b/internal/fichas/listprefs.go| new file mode 100644 |
| index 0000000..771770f |
| --- /dev/null |
| +++ b/internal/fichas/listprefs.go |
| @@ -0,0 +1,162 @@ |
| +package fichas |
| + |
| +// The table's view preferences (Paul, 2026-11-12): how dense its rows are, |
| +// and which columns it shows. Both are one person's, on one device, in |
| +// cookies, as Appearance is: they change how a list looks to its reader |
| +// and nothing about the records. Columns are remembered per card type; |
| +// density is one choice for every list. |
| +// |
| +// The columns cookie holds what is HIDDEN, not what is shown, so a field |
| +// added later appears in every reader's table without anyone opting in. |
| +// Keys are opaque (f_ plus hex), so the cookie names no field. |
| + |
| +import ( |
| + "net/http" |
| + "strings" |
| +) |
| + |
| +const ( |
| + densityCookie = "fichas-density" |
| + // DensityComfortable is the default: room to read a row. |
| + DensityComfortable = "comfortable" |
| + // DensityCompact fits more rows on a screen. |
| + DensityCompact = "compact" |
| + // a year: a preference outlives a session. |
| + prefMaxAge = 365 * 24 * 3600 |
| +) |
| + |
| +// densityOf is the request's density. |
| +func densityOf(r *http.Request) string { |
| + if c, err := r.Cookie(densityCookie); err == nil && c.Value == DensityCompact { |
| + return DensityCompact |
| + } |
| + return DensityComfortable |
| +} |
| + |
| +func columnsCookie(typeKey string) string { return "fichas-hide-" + typeKey } |
| + |
| +// ColumnChoice is one row of the Columns checklist. |
| +type ColumnChoice struct { |
| + Key, Label string |
| + Shown bool |
| + // Locked is the title column: every row is named by it and opens |
| + // its card from it, so it cannot be hidden. |
| + Locked bool |
| +} |
| + |
| +// listColumns are the keys a table can show, in order, with their labels: |
| +// every field that is not long text, then the latest call. |
| +func listColumns(fields []FieldView) (keys []string, labels map[string]string) { |
| + labels = map[string]string{} |
| + for _, f := range fields { |
| + if !isLong(f.Def) { |
| + keys = append(keys, f.Def.Key) |
| + labels[f.Def.Key] = f.Label |
| + } |
| + } |
| + keys = append(keys, SortLastCall) |
| + labels[SortLastCall] = "Last call" |
| + return keys, labels |
| +} |
| + |
| +// typeTitleKey is the field a type's cards are named by: Name where the |
| +// type has it, otherwise its first field (CardView.titleKey's rule). |
| +func typeTitleKey(fields []FieldView) string { |
| + for _, f := range fields { |
| + if f.Def.Key == FieldName { |
| + return FieldName |
| + } |
| + } |
| + if len(fields) > 0 { |
| + return fields[0].Def.Key |
| + } |
| + return "" |
| +} |
| + |
| +// shownColumns is the set of column keys this reader sees for a type. |
| +func shownColumns(r *http.Request, typeKey string, fields []FieldView) map[string]bool { |
| + hidden := map[string]bool{} |
| + if c, err := r.Cookie(columnsCookie(typeKey)); err == nil { |
| + for _, k := range strings.Split(c.Value, ".") { |
| + hidden[k] = true |
| + } |
| + } |
| + title := typeTitleKey(fields) |
| + keys, _ := listColumns(fields) |
| + shown := map[string]bool{} |
| + for _, k := range keys { |
| + if !hidden[k] || k == title { |
| + shown[k] = true |
| + } |
| + } |
| + return shown |
| +} |
| + |
| +// columnChoices is the Columns checklist for a type. |
| +func columnChoices(fields []FieldView, shown map[string]bool) []ColumnChoice { |
| + keys, labels := listColumns(fields) |
| + title := typeTitleKey(fields) |
| + out := make([]ColumnChoice, 0, len(keys)) |
| + for _, k := range keys { |
| + out = append(out, ColumnChoice{Key: k, Label: labels[k], Shown: shown[k], Locked: k == title}) |
| + } |
| + return out |
| +} |
| + |
| +// saveView is POST /t/{type}/view: a density, or the columns to show. |
| +// It answers with the list it came from. |
| +func (a *app) saveView(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 |
| + } |
| + _ = r.ParseForm() |
| + switch d := r.PostForm.Get("density"); d { |
| + case DensityComfortable, DensityCompact: |
| + setPref(w, densityCookie, d) |
| + } |
| + if r.PostForm.Get("columns") == "1" { |
| + show := map[string]bool{} |
| + for _, k := range r.PostForm["show"] { |
| + show[k] = true |
| + } |
| + keys, _ := listColumns(fields) |
| + title := typeTitleKey(fields) |
| + var hide []string |
| + for _, k := range keys { |
| + if !show[k] && k != title { |
| + hide = append(hide, k) |
| + } |
| + } |
| + if len(hide) == 0 { |
| + http.SetCookie(w, &http.Cookie{Name: columnsCookie(ti.Key), Path: "/", MaxAge: -1, HttpOnly: true, SameSite: http.SameSiteLaxMode}) |
| + } else { |
| + setPref(w, columnsCookie(ti.Key), strings.Join(hide, ".")) |
| + } |
| + } |
| + http.Redirect(w, r, listReturn(r.PostForm.Get("return_to"), typeHref(ti.Key)), http.StatusSeeOther) |
| +} |
| + |
| +func setPref(w http.ResponseWriter, name, value string) { |
| + http.SetCookie(w, &http.Cookie{Name: name, Value: value, Path: "/", MaxAge: prefMaxAge, HttpOnly: true, SameSite: http.SameSiteLaxMode}) |
| +} |
| + |
| +// listReturn is where a view change lands: the list it was made on (its |
| +// search, sort and filters kept), or the type's list. Only this type's |
| +// list or the home list: never another path, and never another origin. |
| +func listReturn(to, base string) string { |
| + if strings.ContainsAny(to, "\\\r\n\t") { |
| + return base |
| + } |
| + path, _, _ := strings.Cut(to, "?") |
| + if path == base || path == "/" { |
| + return to |
| + } |
| + return base |
| +} |
diff --git a/internal/fichas/static/fichas.css b/internal/fichas/static/fichas.css| index dae61c4..8918648 100644 |
| --- a/internal/fichas/static/fichas.css |
| +++ b/internal/fichas/static/fichas.css |
| @@ -205,6 +205,90 @@ |
| /* ---- The record bar sits under the view switch, full width, with room. */ |
| [fichas-toolbar] + [rst-lbar] { margin-block-end: var(--rst-sp-4); } |
| +/* ---- The table's density (listprefs.go). Comfortable is the default: |
| + room to read a row (Paul, 2026-11-12: the old rows were "a bit |
| + squished"). Compact fits more on a screen, for those who want it. */ |
| +[fichas-grid][data-density="comfortable"] { font-size: 0.84375rem; } |
| +[fichas-grid][data-density="comfortable"] th, |
| +[fichas-grid][data-density="comfortable"] td { padding: 0.8125rem 0.6875rem; } |
| +[fichas-grid][data-density="comfortable"] thead th { font-size: var(--rst-fs-sm); padding-block: 0.625rem; } |
| +[fichas-grid][data-density="compact"] th, |
| +[fichas-grid][data-density="compact"] td { padding: 0.3125rem 0.625rem; } |
| + |
| +/* ---- A row opens its card: the title's link is stretched over the |
| + whole row, so it works with scripts off, middle-clicks into a new tab, |
| + and stays one tab stop. A link of the row's own (a domain) sits above |
| + the stretch and keeps working. The row shows the focus ring. */ |
| +[fichas-grid] tbody tr { position: relative; } |
| +[fichas-row-link]::after { content: ""; position: absolute; inset: 0; } |
| +[fichas-grid] tbody td a:not([fichas-row-link]) { position: relative; z-index: 1; } |
| +[fichas-grid] tbody tr:hover [fichas-row-link] { text-decoration: none; } |
| +[fichas-row-link]:focus-visible { outline: none; } |
| +[fichas-grid] tbody tr:has([fichas-row-link]:focus-visible) { |
| + outline: 2px solid var(--rst-accent); |
| + outline-offset: -2px; |
| +} |
| + |
| +/* ---- The View menu: density and columns, beside Fields. */ |
| +[fichas-toolbar-end] { display: flex; align-items: center; gap: var(--rst-sp-2); } |
| +[fichas-view-menu] { position: relative; } |
| +/* No height cap: the dropdown's 320px scroll would hide the apply |
| + button below the checklist. */ |
| +[fichas-view-panel] { min-inline-size: 15rem; max-block-size: none; overflow: visible; padding: var(--rst-sp-3); } |
| +[fichas-view-panel] hr { margin-block: var(--rst-sp-3); } |
| +[fichas-view-heading] { |
| + margin: 0 0 var(--rst-sp-2); |
| + padding: 0; |
| + color: var(--rst-text-muted); |
| + font-size: var(--rst-fs-xs); |
| + font-weight: 600; |
| +} |
| +[fichas-view-seg] { |
| + display: grid; |
| + grid-template-columns: 1fr 1fr; |
| + gap: 2px; |
| + padding: 2px; |
| + border-radius: 8px; |
| + background: var(--rst-surface-2); |
| +} |
| +[fichas-view-seg] button { |
| + padding: 0.375rem var(--rst-sp-2); |
| + border: 0; |
| + border-radius: 6px; |
| + background: none; |
| + color: var(--rst-text-muted); |
| + font: inherit; |
| + font-size: var(--rst-fs-sm); |
| + font-weight: 600; |
| + cursor: pointer; |
| +} |
| +[fichas-view-seg] button[aria-pressed="true"] { |
| + background: var(--rst-surface); |
| + color: var(--rst-text); |
| + box-shadow: 0 1px 2px rgb(23 32 60 / 0.12); |
| +} |
| +[fichas-view-columns] { margin: 0 0 var(--rst-sp-3); padding: 0; border: 0; } |
| +[fichas-view-check] { |
| + display: flex; |
| + align-items: center; |
| + gap: var(--rst-sp-2); |
| + padding: 0.3125rem 0; |
| + font-size: var(--rst-fs-sm); |
| + cursor: pointer; |
| +} |
| +[fichas-view-check]:has(input:disabled) { color: var(--rst-text-muted); cursor: default; } |
| +/* The dropdown styles every button in it as a menu row; this one is the |
| + panel's action, filled as a primary is. */ |
| +[fichas-view-panel] [fichas-view-apply] { |
| + padding: 0.5rem var(--rst-sp-3); |
| + border-radius: var(--rst-radius-sm); |
| + background: var(--rst-accent); |
| + color: var(--rst-on-accent); |
| + font-weight: 600; |
| + text-align: center; |
| +} |
| +[fichas-view-panel] [fichas-view-apply]:hover { background: var(--rst-accent-strong); } |
| + |
| /* ---- Sidebar icons on the text's centre line, not above its baseline. */ |
| [rst-shell-nav] a { display: flex; align-items: center; gap: var(--rst-sp-2); } |
| [rst-shell-nav] a .icon { flex-shrink: 0; } |
diff --git a/internal/fichas/templates/index.html b/internal/fichas/templates/index.html| index ac2e6b6..b1abba5 100644 |
| --- a/internal/fichas/templates/index.html |
| +++ b/internal/fichas/templates/index.html |
| @@ -11,7 +11,35 @@ |
| (dict "Label" "Table" "Href" .TableHref "Current" (eq .View "table")) |
| (dict "Label" "Cards" "Href" .CardsHref "Current" (eq .View "cards"))))}} |
| {{if eq .View "cards"}}<a rst-btn href="{{.Base}}/layout">{{icon "layout-grid"}} Arrange cards</a> |
| - {{else}}<a rst-btn href="{{.Base}}/fields">{{icon "pencil"}} Fields</a>{{end}} |
| + {{else}}<div fichas-toolbar-end> |
| + {{/* The reader's own view of the table (listprefs.go): density, and |
| + which columns. Forms in a disclosure, so it works with scripts off. */}} |
| + <details rst-dropdown name="rst-menus" fichas-view-menu> |
| + <summary rst-btn>{{icon "sliders-horizontal"}} View</summary> |
| + <div rst-dropdown-menu fichas-view-panel> |
| + <form method="post" action="{{.Base}}/view" data-busy="false"> |
| + <input type="hidden" name="return_to" value="{{.Here}}"> |
| + <p fichas-view-heading id="view-density">Density</p> |
| + <div fichas-view-seg role="group" aria-labelledby="view-density"> |
| + <button type="submit" name="density" value="comfortable" aria-pressed="{{eq .Density "comfortable"}}">Comfortable</button> |
| + <button type="submit" name="density" value="compact" aria-pressed="{{eq .Density "compact"}}">Compact</button> |
| + </div> |
| + </form> |
| + <hr> |
| + <form method="post" action="{{.Base}}/view"> |
| + <input type="hidden" name="return_to" value="{{.Here}}"> |
| + <input type="hidden" name="columns" value="1"> |
| + <fieldset fichas-view-columns> |
| + <legend fichas-view-heading>Columns</legend> |
| + {{range .Choices}}<label fichas-view-check><input type="checkbox" name="show" value="{{.Key}}"{{if or .Shown .Locked}} checked{{end}}{{if .Locked}} disabled{{end}}> {{.Label}}</label> |
| + {{end}} |
| + </fieldset> |
| + <button fichas-view-apply type="submit">Show these columns</button> |
| + </form> |
| + </div> |
| + </details> |
| + <a rst-btn href="{{.Base}}/fields">{{icon "pencil"}} Fields</a> |
| + </div>{{end}} |
| </div> |
| <div rst-lbar data-live-search> |
| @@ -23,22 +51,23 @@ |
| {{if .Cards}} |
| {{if eq .View "table"}} |
| <div fichas-grid-wrap> |
| - <table fichas-grid> |
| + <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 not (isLong $f.Def)}}{{$v := $f.Value}} |
| - {{if $c.IsTitle $f.Def.Key}}<td><a href="/cards/{{$c.Card.ID}}">{{$c.Title}}</a></td> |
| + {{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}} |
| - <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> |
| + {{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> |
diff --git a/internal/fichastest/browser_test.go b/internal/fichastest/browser_test.go| index 358136e..0369497 100644 |
| --- a/internal/fichastest/browser_test.go |
| +++ b/internal/fichastest/browser_test.go |
| @@ -347,3 +347,38 @@ func send[P any](command cdp.Command[P, cdp.Empty], params P) chromedp.Action[ch |
| return err |
| }) |
| } |
| + |
| +// TestARowOpensItsCard: a click anywhere on a row opens its card, and a |
| +// link of the row's own (the domain) is still what a click on it reaches. |
| +func TestARowOpensItsCard(t *testing.T) { |
| + var id int64 |
| + rig := browserApp(t, func(ctx context.Context, d *db.DB, cfg fichas.Config) { |
| + m, _ := fichas.EnsureMember(ctx, d.G, cfg.Sealer, TestOwner) |
| + c, err := fichas.CreateCard(ctx, d.G, cfg.Sealer, fichas.TypeCustomer, fichas.Person(m.ID), |
| + map[string]string{fichas.FieldName: "Brightwater Labs", fichas.FieldDomain: "brightwater.example", fichas.FieldPhone: "+353 1 555 0142"}) |
| + if err != nil { |
| + t.Fatalf("seed: %v", err) |
| + } |
| + id = c.ID |
| + }) |
| + var domainOnTop bool |
| + var path string |
| + rig.Run( |
| + chromedp.Navigate(rig.Origin+"/"), |
| + chromedp.WaitVisible(`[fichas-grid] tbody tr`), |
| + harness.Into(&domainOnTop, chromedp.Evaluate[bool](`(() => { |
| + const a = document.querySelector('[fichas-grid] tbody a[fichas-link]'), r = a.getBoundingClientRect() |
| + return document.elementFromPoint(r.left + r.width / 2, r.top + r.height / 2) === a |
| + })()`)), |
| + // The phone's cell: plain text, far from the title. |
| + chromedp.Click(`[fichas-grid] tbody tr td:nth-child(4)`), |
| + chromedp.WaitVisible(`textarea[name="f_body"]`), |
| + harness.Into(&path, chromedp.Evaluate[string](`location.pathname`)), |
| + ) |
| + if !domainOnTop { |
| + t.Error("the row's link covers the domain link: a click on the domain would open the card") |
| + } |
| + if path != "/cards/"+itoa(id) { |
| + t.Fatalf("a click on the row's phone cell went to %q, want the card", path) |
| + } |
| +} |
diff --git a/internal/fichastest/listprefs_test.go b/internal/fichastest/listprefs_test.go| new file mode 100644 |
| index 0000000..3a23fa3 |
| --- /dev/null |
| +++ b/internal/fichastest/listprefs_test.go |
| @@ -0,0 +1,123 @@ |
| +package fichastest |
| + |
| +import ( |
| + "net/http" |
| + "net/http/httptest" |
| + "net/url" |
| + "strings" |
| + "testing" |
| + |
| + "amadan.net/oficina/fichas/internal/fichas" |
| +) |
| + |
| +// withCookies GETs target carrying the cookies a response set. |
| +func withCookies(t *testing.T, h http.Handler, target string, from *httptest.ResponseRecorder) string { |
| + t.Helper() |
| + req := httptest.NewRequest(http.MethodGet, target, nil) |
| + for _, c := range from.Result().Cookies() { |
| + if c.MaxAge >= 0 { |
| + req.AddCookie(c) |
| + } |
| + } |
| + rec := httptest.NewRecorder() |
| + h.ServeHTTP(rec, req) |
| + if rec.Code != http.StatusOK { |
| + t.Fatalf("GET %s: status %d", target, rec.Code) |
| + } |
| + return rec.Body.String() |
| +} |
| + |
| +// Comfortable is the default; Compact is a choice that sticks, and the |
| +// change lands back on the list it was made on, its search kept. |
| +func TestDensityIsTheReadersChoice(t *testing.T) { |
| + h := newApp(t) |
| + createACustomer(t, h, "Cnoc Teoranta") |
| + if body := get(t, h, "/").Body.String(); !strings.Contains(body, `data-density="comfortable"`) { |
| + t.Fatal("the table is not comfortable by default") |
| + } |
| + back := "/t/" + fichas.TypeCustomer + "?q=cnoc" |
| + rec := post(t, h, "/t/"+fichas.TypeCustomer+"/view", url.Values{"density": {"compact"}, "return_to": {back}}) |
| + if rec.Code != http.StatusSeeOther || rec.Header().Get("Location") != back { |
| + t.Fatalf("POST view: %d to %q, want 303 to %q", rec.Code, rec.Header().Get("Location"), back) |
| + } |
| + body := withCookies(t, h, back, rec) |
| + if !strings.Contains(body, `data-density="compact"`) { |
| + t.Fatal("Compact did not stick") |
| + } |
| + if !strings.Contains(body, `value="compact" aria-pressed="true"`) { |
| + t.Fatal("the View menu does not show Compact as chosen") |
| + } |
| +} |
| + |
| +// Hiding a column drops its header and its cells; the title column cannot |
| +// be hidden, because every row is named by it and opens its card from it. |
| +func TestColumnsAreTheReadersChoice(t *testing.T) { |
| + h := newApp(t) |
| + createACustomer(t, h, "Cnoc Teoranta") // email ana@example.com |
| + base := "/t/" + fichas.TypeCustomer |
| + // Show only Stage: Name, Email, Domain and the rest unticked. |
| + rec := post(t, h, base+"/view", url.Values{"columns": {"1"}, "show": {fichas.FieldStage}, "return_to": {base}}) |
| + if rec.Code != http.StatusSeeOther { |
| + t.Fatalf("POST view: %d", rec.Code) |
| + } |
| + body := withCookies(t, h, base, rec) |
| + grid := body[strings.Index(body, "<table fichas-grid"):] |
| + grid = grid[:strings.Index(grid, "</table>")] |
| + if strings.Contains(grid, "ana@example.com") || strings.Contains(grid, ">Email<") { |
| + t.Errorf("a hidden column is still drawn:\n%s", grid) |
| + } |
| + if !strings.Contains(grid, "Cnoc Teoranta") || !strings.Contains(grid, ">Name<") { |
| + t.Errorf("the title column was hidden:\n%s", grid) |
| + } |
| + if !strings.Contains(grid, ">Stage<") || !strings.Contains(grid, "Lead") { |
| + t.Errorf("a column left ticked is gone:\n%s", grid) |
| + } |
| + if strings.Contains(grid, "Last call") { |
| + t.Error("Last call was unticked but still shows") |
| + } |
| + // The checklist says what is shown, and the title is locked on. |
| + if !strings.Contains(body, `value="`+fichas.FieldName+`" checked disabled`) { |
| + t.Error("the title column is not locked on in the checklist") |
| + } |
| + if strings.Contains(body, `value="`+fichas.FieldEmail+`" checked`) { |
| + t.Error("the checklist shows Email as shown") |
| + } |
| + |
| + // Ticking everything again forgets the choice. |
| + all := url.Values{"columns": {"1"}, "return_to": {base}} |
| + for _, k := range []string{fichas.FieldDomain, fichas.FieldEmail, fichas.FieldPhone, fichas.FieldStage, fichas.FieldNextAction, fichas.SortLastCall} { |
| + all.Add("show", k) |
| + } |
| + rec = post(t, h, base+"/view", all) |
| + var cleared bool |
| + for _, c := range rec.Result().Cookies() { |
| + if strings.HasPrefix(c.Name, "fichas-hide-") && c.MaxAge < 0 { |
| + cleared = true |
| + } |
| + } |
| + if !cleared { |
| + t.Error("showing every column did not clear the cookie") |
| + } |
| +} |
| + |
| +// A view change goes back only to a list: never another path, never |
| +// another origin. |
| +func TestAViewChangeOnlyReturnsToAList(t *testing.T) { |
| + h := newApp(t) |
| + base := "/t/" + fichas.TypeCustomer |
| + for _, to := range []string{"//evil.example/", "https://evil.example/", "/cards/1/delete", "/\\evil.example", "/t/other"} { |
| + rec := post(t, h, base+"/view", url.Values{"density": {"compact"}, "return_to": {to}}) |
| + if loc := rec.Header().Get("Location"); loc != base { |
| + t.Errorf("return_to %q went to %q, want %q", to, loc, base) |
| + } |
| + } |
| +} |
| + |
| +// Every row opens its card: the title's link is the row's link. |
| +func TestEveryRowLinksToItsCard(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") |
| + } |
| +} |