Open a job's details from its pill
The job view (D13): the job's title, linked to its page in Equipo in a new tab with "Open in Equipo" as its tooltip and an arrow on hover, focus and touch (D3, the only link there), the status, one sentence more, when it started (D19, startedText and its ask.js twin, refreshed each minute, the day in Base's time zone) and the link to the work once ready or done. Without scripts the <details> opens in place under the pill. ask.js makes it a popover beside the pill inside the chat (above when there is room), a sheet over a scrim on phones; Close, Escape, the scrim and a tap outside close it, focus moves to Close and back to the pill, and a redraw keeps it open. Pending copy rows for "Started ..." lines.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
11 files changed,
+783
−43
docs/copy-pending.md+11 −0internal/browsertest/cards_test.go+209 −1internal/browsertest/mobile_test.go+87 −0internal/equipo/equipotest/chat.go+28 −0internal/look/static/app.css+54 −5internal/look/static/ask.js+228 −28internal/web/app.go+4 −2internal/web/ask.go+43 −2internal/web/ask_internal_test.go+44 −0internal/web/templates/partials/chat.html+7 −3internal/webtest/ask_test.go+68 −2
diff --git a/docs/copy-pending.md b/docs/copy-pending.md| index 7c165f7..3a77a95 100644 |
| --- a/docs/copy-pending.md |
| +++ b/docs/copy-pending.md |
| @@ -377,3 +377,14 @@ Pending review (Task 18, job pills): a job shows as a pill in the chat. Its titl |
| |---|---|---| |
| | partials/chat.html, ask.js | PENDING: a job's pill, between the job's title and its status (drawn by the stylesheet, app.css) | {title} · {status} | |
| | partials/chat.html, ask.js | PENDING: the pill's name for screen readers | {title}, {status} | |
| + |
| +Pending review (Task 19, the job view, plan decision D19): when a job started, under its status in the job view. Base words it from the job's start time (server and ask.js, which moves it on every minute); the day is in Base's time zone. The view's title, status, sentence and link label come from the Assistant (Equipo's copy, the title's tooltip "Open in Equipo" among them); its Close reuses the panel's approved "Close". |
| + |
| +| File | Context | Text | |
| +|---|---|---| |
| +| ask.go, ask.js | PENDING: the job view, a job started less than a minute ago | Started just now | |
| +| ask.go, ask.js | PENDING: the job view, a job started a minute ago | Started 1 minute ago | |
| +| ask.go, ask.js | PENDING: the job view, a job started 2 to 59 minutes ago | Started {n} minutes ago | |
| +| ask.go, ask.js | PENDING: the job view, a job started an hour ago | Started 1 hour ago | |
| +| ask.go, ask.js | PENDING: the job view, a job started 2 to 23 hours ago | Started {n} hours ago | |
| +| ask.go, ask.js | PENDING: the job view, a job started a day ago or more (the day and month, such as "2 January") | Started on {2 January} | |
diff --git a/internal/browsertest/cards_test.go b/internal/browsertest/cards_test.go| index c102dd4..28dd0cf 100644 |
| --- a/internal/browsertest/cards_test.go |
| +++ b/internal/browsertest/cards_test.go |
| @@ -10,9 +10,11 @@ import ( |
| "time" |
| "github.com/chromedp/chromedp" |
| + "github.com/chromedp/chromedp/kb" |
| "amadan.net/rastrillo/rastrillo/harness" |
| + "amadan.net/carlos/base/internal/config" |
| "amadan.net/carlos/base/internal/equipo" |
| ) |
| @@ -112,7 +114,9 @@ func TestAskJobPillInPanel(t *testing.T) { |
| if (j.querySelector("summary.pill-main").getAttribute("aria-label") !== "Building your website, Getting started") p.push("name " + j.querySelector("summary").getAttribute("aria-label")); |
| if (j.querySelector(".state-mark svg")) p.push("working has an icon"); |
| if (!getComputedStyle(j.querySelector(".state-mark"), "::after").animationName.includes("turn")) p.push("working mark still"); |
| - if (/equipo/i.test(document.querySelector("#ask-panel").innerText) || document.querySelector('#ask-panel a[href*="/jobs/"]')) p.push("names Equipo or links its page"); |
| + if (/equipo/i.test(document.querySelector("#ask-panel").innerText)) p.push("names Equipo"); |
| + const pages = document.querySelectorAll('#ask-panel a[href*="/jobs/"]'); |
| + if (pages.length !== 1 || !pages[0].matches(".jobview > header > h3 > a.jv-title")) p.push("links the job's page outside the job view's title"); |
| return p.join("; "); })()`); got != "" { |
| t.Errorf("the working pill: %s", got) |
| } |
| @@ -286,3 +290,207 @@ func TestAskJobStatusStaysVisible(t *testing.T) { |
| }) |
| } |
| } |
| + |
| +// jobViewJS checks the open view of job id, docked on a wide screen: its |
| +// <details> is open and the summary says so; it is drawn whole and on top |
| +// (nothing covers its middle), inside the chat below its header, beside |
| +// the pill (side: above it when there is room, else below), with no |
| +// scrim; focus is on its Close; its title is the one link to the job's |
| +// page, in a new tab; its status says status. "" when all hold. |
| +func jobViewJS(id, status, side string) string { |
| + return `(() => { const j = document.querySelector('#ask-panel li.job[data-job="` + id + `"]'); |
| + if (!j) return "no job"; |
| + const d = j.querySelector("details"), s = j.querySelector("summary"), v = j.querySelector(".jobview"), p = []; |
| + if (!d.open) p.push("the details are closed"); |
| + if (s.getAttribute("aria-expanded") !== "true") p.push("aria-expanded " + s.getAttribute("aria-expanded")); |
| + if (!v.checkVisibility({ visibilityProperty: true })) return p.concat("the view is not drawn").join("; "); |
| + const r = v.getBoundingClientRect(), pill = j.querySelector(".pill").getBoundingClientRect(); |
| + const chat = document.querySelector("#ask-panel").getBoundingClientRect(), head = document.querySelector("#ask-panel .ask-head").getBoundingClientRect(); |
| + if (r.left < chat.left + 15.5 || r.right > chat.right - 15.5 || r.top < head.bottom || r.bottom > chat.bottom) p.push("outside the chat: " + JSON.stringify(r) + " in " + JSON.stringify(chat)); |
| + const room = pill.top - head.bottom - 8 >= r.height + 8; |
| + if (` + strconv.Quote(side) + ` === "above" && (!room || r.bottom > pill.top - 4 || pill.top - r.bottom > 12)) p.push("not just above the pill: view bottom " + r.bottom + ", pill top " + pill.top + ", room " + room); |
| + if (` + strconv.Quote(side) + ` === "below" && (room || r.top < pill.bottom + 4 || r.top - pill.bottom > 12)) p.push("not just below the pill: view top " + r.top + ", pill bottom " + pill.bottom + ", room above " + room); |
| + const mid = document.elementFromPoint(r.left + r.width / 2, r.top + r.height / 2); |
| + if (!v.contains(mid)) p.push("covered at its middle by " + (mid && mid.className)); |
| + const close = v.querySelector("[data-job-close]"); |
| + if (close.hidden || !close.checkVisibility()) p.push("no Close"); |
| + if (document.activeElement !== close) p.push("focus on " + document.activeElement.tagName + "." + document.activeElement.className); |
| + if (document.querySelector("#ask-panel .scrim")?.checkVisibility()) p.push("a scrim on a wide screen"); |
| + const pages = document.querySelectorAll('#ask-panel a[href*="/jobs/"]'), a = v.querySelector("h3 > a.jv-title"); |
| + if (!a || [...pages].some(l => !l.matches(".jobview > header > h3 > a.jv-title"))) p.push("the job's page is linked outside a job view's title"); |
| + else if (a.target !== "_blank" || a.rel !== "noopener" || a.title !== "Open in Equipo" || a.textContent !== j.querySelector(".pill-title").textContent) p.push("the title link: " + a.outerHTML); |
| + if (v.querySelector(".jv-stage").textContent !== ` + strconv.Quote(status) + `) p.push("status " + v.querySelector(".jv-stage").textContent); |
| + return p.join("; "); })()` |
| +} |
| + |
| +// closedViewJS is "" once job id's view is closed: the details shut, the |
| +// summary saying so, the view and any scrim gone, and focus back on the |
| +// pill's summary. |
| +func closedViewJS(id string) string { |
| + return `(() => { const j = document.querySelector('#ask-panel li.job[data-job="` + id + `"]'), p = []; |
| + if (!j) return "no job"; |
| + const s = j.querySelector("summary"); |
| + if (j.querySelector("details").open) p.push("the details are open"); |
| + if (s.getAttribute("aria-expanded") !== "false") p.push("aria-expanded " + s.getAttribute("aria-expanded")); |
| + if (j.querySelector(".jobview").checkVisibility()) p.push("the view shows"); |
| + if (document.querySelector("#ask-panel .scrim")?.checkVisibility()) p.push("the scrim shows"); |
| + if (document.activeElement !== s) p.push("focus on " + document.activeElement.tagName + "." + document.activeElement.className); |
| + return p.join("; "); })()` |
| +} |
| + |
| +// The job view on a wide screen (plan decision D13): tapping the pill opens |
| +// it as a popover beside the pill, inside the docked chat, with focus on |
| +// its Close; Escape closes it (and only it: the chat stays open), and |
| +// focus goes back to the pill. Close, a tap on the pill and a tap outside |
| +// close it too. A new revision while it is open keeps it open, with the |
| +// new status, and focus where it was. When it started moves on in words |
| +// as the server says it, the day in Base's time zone. |
| +func TestAskJobViewOpens(t *testing.T) { |
| + auckland, err := time.LoadLocation("Pacific/Auckland") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + rig, f, _ := askBaseWith(t, func(c *config.Config) { c.Timezone = auckland }) |
| + openPanel(t, rig) |
| + wait := func(js string) { |
| + t.Helper() |
| + drive(t, rig, chromedp.Poll[chromedp.Void](js, chromedp.WithPollingTimeout(10*time.Second))) |
| + } |
| + pending := func(js string) string { return harness.Evaluate[string](rig, js) } |
| + settle := func() { drive(t, rig, chromedp.Sleep(250*time.Millisecond)) } |
| + // A job at the top of the conversation, with no room above it: its |
| + // view opens below it. |
| + first := f.AskJob("Fixing the login") |
| + for _, line := range []string{"On it.", "Got it.", "I'll let you know.", "Anything else?", "Sure.", "On it."} { |
| + f.Say(line) |
| + } |
| + id := f.AskJob("Building your website") |
| + job := `#ask-panel li.job[data-job="` + id + `"]` |
| + summary, view := job+` summary`, job+` .jobview` |
| + wait(`!!document.querySelector(` + strconv.Quote(summary) + `) && document.querySelectorAll("#ask-panel .msg.coordinator").length === 6`) |
| + drive(t, rig, chromedp.Click(chromedp.CSS(`#ask-panel li.job[data-job="`+first+`"] summary`))) |
| + settle() |
| + if got := pending(jobViewJS(first, "Getting started", "below")); got != "" { |
| + t.Errorf("the first job, tapped open: %s", got) |
| + } |
| + // Tapping another pill closes the first view and opens its own. |
| + drive(t, rig, chromedp.Click(chromedp.CSS(summary))) |
| + settle() |
| + if got := pending(jobViewJS(id, "Getting started", "above")); got != "" { |
| + t.Errorf("tapped open: %s", got) |
| + } |
| + if n := harness.Evaluate[int](rig, `[...document.querySelectorAll("#ask-panel .jobview")].filter(v => v.checkVisibility()).length`); n != 1 { |
| + t.Errorf("%d job views show", n) |
| + } |
| + if got := pending(`(() => { const v = document.querySelector(` + strconv.Quote(view) + `); |
| + return [v.querySelector(".jv-detail")?.textContent, v.querySelector(".jv-started")?.textContent].join("|"); })()`); got != "Working out what's needed.|Started just now" { |
| + t.Errorf("the view's detail and when it started: %s", got) |
| + } |
| + // The title's arrow: hidden at rest where there is a pointer that |
| + // hovers; always there on a touch screen (headless Chromium may say |
| + // it is one). |
| + arrow := `getComputedStyle(document.querySelector(` + strconv.Quote(view+` .jv-title svg`) + `)).opacity` |
| + if got := pending(`matchMedia("(hover: none)").matches + " " + ` + arrow); got != "true 1" && got != "false 0" { |
| + t.Errorf("the title's arrow at rest (touch screen, opacity): %s", got) |
| + } |
| + rig.Screen("#ask-panel", "a working job's view, open beside its pill") |
| + for _, scheme := range []string{"dark", "light"} { |
| + drive(t, rig, prefersScheme(scheme), chromedp.Sleep(300*time.Millisecond)) |
| + mobileShot(t, rig, "jobview-working-desktop-"+scheme) |
| + checkContrast(t, rig, "the job view, "+scheme, view+" h3", view+" .jv-stage", view+" .jv-detail", view+" .jv-started") |
| + } |
| + // The title's arrow shows on keyboard focus (Shift+Tab from Close). |
| + drive(t, rig, chromedp.KeyEvent(kb.Tab, chromedp.KeyModifiers(chromedp.ModifierShift))) |
| + settle() |
| + if got := pending(`document.activeElement.className + " " + ` + arrow); got != "jv-title 1" { |
| + t.Errorf("the title focused: %s", got) |
| + } |
| + drive(t, rig, prefersScheme("dark")) |
| + |
| + // Escape closes the view, and the chat stays open. |
| + drive(t, rig, chromedp.KeyEvent(kb.Escape)) |
| + settle() |
| + if got := pending(closedViewJS(id)); got != "" { |
| + t.Errorf("after Escape: %s", got) |
| + } |
| + if !harness.Evaluate[bool](rig, settledJS) { |
| + t.Errorf("Escape on the job view closed the chat") |
| + } |
| + |
| + // Close, a second tap on the pill, and a tap outside it close it too. |
| + drive(t, rig, chromedp.Click(chromedp.CSS(summary))) |
| + settle() |
| + drive(t, rig, chromedp.Click(chromedp.CSS(view+` [data-job-close]`))) |
| + settle() |
| + if got := pending(closedViewJS(id)); got != "" { |
| + t.Errorf("after Close: %s", got) |
| + } |
| + drive(t, rig, chromedp.Click(chromedp.CSS(summary))) |
| + settle() |
| + drive(t, rig, chromedp.Click(chromedp.CSS(summary))) |
| + settle() |
| + if got := pending(closedViewJS(id)); got != "" { |
| + t.Errorf("after a second tap on the pill: %s", got) |
| + } |
| + drive(t, rig, chromedp.Click(chromedp.CSS(summary))) |
| + settle() |
| + drive(t, rig, chromedp.Click(chromedp.CSS(`#ask-panel .ask-head h2`))) |
| + settle() |
| + if got := pending(`(() => { const j = document.querySelector(` + strconv.Quote(job) + `); |
| + return j.querySelector("details").open + " " + j.querySelector(".jobview").checkVisibility() + " " + j.querySelector("summary").getAttribute("aria-expanded"); })()`); got != "false false false" { |
| + t.Errorf("after a tap outside: open, shown, expanded: %s", got) |
| + } |
| + |
| + // A new revision while it is open: still open, the new status, focus |
| + // on Close. |
| + drive(t, rig, chromedp.Click(chromedp.CSS(summary))) |
| + settle() |
| + f.SetJob(id, "working", "Building it", "Writing the pages.") |
| + wait(`document.querySelector(` + strconv.Quote(job) + `).dataset.revision === "2"`) |
| + settle() |
| + if got := pending(jobViewJS(id, "Building it", "above")); got != "" { |
| + t.Errorf("redrawn while open: %s", got) |
| + } |
| + try := equipo.Link{Label: "Try it", URL: "https://preview.example.test/"} |
| + f.SetJob(id, "ready", "Ready to try", "Have a look.", try) |
| + wait(`document.querySelector(` + strconv.Quote(job) + `).dataset.revision === "3"`) |
| + settle() |
| + if got := pending(jobViewJS(id, "Ready to try", "above")); got != "" { |
| + t.Errorf("ready, open: %s", got) |
| + } |
| + if got := pending(`(() => { const a = document.querySelector(` + strconv.Quote(view+` a.jv-go`) + `); return a ? a.textContent + " " + a.href + " " + a.target : "none"; })()`); got != "Try it https://preview.example.test/ _blank" { |
| + t.Errorf("a ready view's link: %s", got) |
| + } |
| + for _, scheme := range []string{"dark", "light"} { |
| + drive(t, rig, prefersScheme(scheme), chromedp.Sleep(300*time.Millisecond)) |
| + mobileShot(t, rig, "jobview-ready-desktop-"+scheme) |
| + checkContrast(t, rig, "a ready job's view, "+scheme, view+" h3", view+" .jv-stage", view+" .jv-go") |
| + } |
| + drive(t, rig, prefersScheme("dark")) |
| + for _, st := range []struct{ state, result string }{{"asking", "One question for you"}, {"done", "Done"}, {"stopped", "Stopped"}} { |
| + f.SetJob(id, st.state, st.result, "One sentence more.", try) |
| + wait(`document.querySelector(` + strconv.Quote(view+` .jv-stage`) + `).textContent === ` + strconv.Quote(st.result)) |
| + for _, scheme := range []string{"dark", "light"} { |
| + drive(t, rig, prefersScheme(scheme), chromedp.Sleep(300*time.Millisecond)) |
| + mobileShot(t, rig, "jobview-"+st.state+"-desktop-"+scheme) |
| + } |
| + drive(t, rig, prefersScheme("dark")) |
| + } |
| + |
| + // When it started, as the server words it: hours, then the day in |
| + // Base's time zone (Auckland's, a day ahead of UTC's evening). |
| + started := func(at time.Time, want string) { |
| + t.Helper() |
| + f.SetJobStarted(id, at) |
| + wait(`document.querySelector(` + strconv.Quote(view+` .jv-started`) + `)?.textContent === ` + strconv.Quote(want)) |
| + } |
| + started(time.Now().Add(-3*time.Hour-time.Minute), "Started 3 hours ago") |
| + old := time.Date(2026, 3, 4, 20, 0, 0, 0, time.UTC) |
| + started(old, "Started on "+old.In(auckland).Format("2 January")) |
| + if old.In(auckland).Day() == old.Day() { |
| + t.Fatalf("the day is the same in both zones") |
| + } |
| + if got := pending(jobViewJS(id, "Stopped", "above")); got != "" { |
| + t.Errorf("after the redraws: %s", got) |
| + } |
| +} |
diff --git a/internal/browsertest/mobile_test.go b/internal/browsertest/mobile_test.go| index c3272cd..6f9e5c9 100644 |
| --- a/internal/browsertest/mobile_test.go |
| +++ b/internal/browsertest/mobile_test.go |
| @@ -9,6 +9,7 @@ import ( |
| "os" |
| "path/filepath" |
| "regexp" |
| + "strconv" |
| "testing" |
| "time" |
| @@ -16,6 +17,7 @@ import ( |
| "amadan.net/rastrillo/rastrillo/harness" |
| + "amadan.net/carlos/base/internal/equipo" |
| "amadan.net/carlos/base/internal/equipo/equipotest" |
| ) |
| @@ -296,3 +298,88 @@ func TestAskPhoneUnchanged(t *testing.T) { |
| } |
| } |
| } |
| + |
| +// The job view on a phone (plan decision D13): a sheet from the foot of |
| +// the screen, over the dimmed chat (a scrim), the title's arrow always |
| +// showing. A tap on the scrim closes it, and focus goes back to the pill. |
| +// Without scripts the pill's <details> opens in place, under the pill. |
| +func TestAskJobViewIsASheetOnPhones(t *testing.T) { |
| + rig, f, _ := askBaseOn(t, nil, chromedp.EmulateViewport(390, 844, chromedp.EmulateMobile, chromedp.EmulateScale(3))) |
| + drive(t, rig, chromedp.Navigate(rig.Origin+"/"), chromedp.WaitVisible(chromedp.CSS("a.ask-field")), |
| + chromedp.Click(chromedp.CSS("a.ask-field")), chromedp.WaitVisible(chromedp.CSS(`#ask-panel textarea`)), |
| + chromedp.Poll[chromedp.Void](readJS, chromedp.WithPollingTimeout(5*time.Second)), |
| + chromedp.Poll[chromedp.Void](`document.querySelector("#ask-panel").getBoundingClientRect().top === 0`, chromedp.WithPollingTimeout(3*time.Second))) |
| + f.Say("On it.") |
| + id := f.AskJob("Building your website") |
| + job := `#ask-panel li.job[data-job="` + id + `"]` |
| + drive(t, rig, chromedp.WaitVisible(chromedp.CSS(job+" summary")), chromedp.Click(chromedp.CSS(job+" summary")), chromedp.Sleep(400*time.Millisecond)) |
| + sheet := `(() => { const j = document.querySelector(` + strconv.Quote(job) + `), v = j.querySelector(".jobview"), s = j.querySelector("summary"), p = []; |
| + if (!j.querySelector("details").open || s.getAttribute("aria-expanded") !== "true") p.push("not open"); |
| + if (!v.checkVisibility()) return p.concat("the view is not drawn").join("; "); |
| + const r = v.getBoundingClientRect(); |
| + if (Math.abs(r.bottom - innerHeight) > 0.5 || Math.abs(r.left) > 0.5 || Math.abs(r.right - innerWidth) > 0.5) p.push("not a sheet at the foot: " + JSON.stringify(r) + " in " + innerWidth + "x" + innerHeight); |
| + const mid = document.elementFromPoint(r.left + r.width / 2, r.top + r.height / 2); |
| + if (!v.contains(mid)) p.push("covered at its middle by " + (mid && mid.className)); |
| + const scrim = document.querySelector("#ask-panel .scrim"); |
| + if (!scrim || !scrim.checkVisibility()) p.push("no scrim"); |
| + else if (document.elementFromPoint(innerWidth / 2, 120) !== scrim) p.push("the chat is not behind the scrim: " + document.elementFromPoint(innerWidth / 2, 120)?.className); |
| + if (document.activeElement !== v.querySelector("[data-job-close]")) p.push("focus on " + document.activeElement.className); |
| + if (getComputedStyle(v.querySelector(".jv-title svg")).opacity !== "1") p.push("the title's arrow hides"); |
| + return p.join("; "); })()` |
| + if got := harness.Evaluate[string](rig, sheet); got != "" { |
| + t.Errorf("the job view on a phone: %s", got) |
| + } |
| + for _, scheme := range []string{"dark", "light"} { |
| + drive(t, rig, prefersScheme(scheme), chromedp.Sleep(300*time.Millisecond)) |
| + // Measured before the full-page shot, which leaves a phone's |
| + // screenshots cut short for a moment. |
| + checkContrast(t, rig, "the job view on a phone, "+scheme, job+" .jobview h3", job+" .jv-stage", job+" .jv-detail") |
| + mobileShot(t, rig, "jobview-working-phone-"+scheme) |
| + } |
| + drive(t, rig, prefersScheme("dark")) |
| + // A new revision keeps the sheet up. |
| + f.SetJob(id, "ready", "Ready to try", "Have a look.", equipo.Link{Label: "Try it", URL: "https://preview.example.test/"}) |
| + drive(t, rig, chromedp.Poll[chromedp.Void](`document.querySelector(`+strconv.Quote(job+" .jv-stage")+`).textContent === "Ready to try"`, chromedp.WithPollingTimeout(10*time.Second)), |
| + chromedp.Sleep(300*time.Millisecond)) |
| + if got := harness.Evaluate[string](rig, sheet); got != "" { |
| + t.Errorf("the job view on a phone, redrawn: %s", got) |
| + } |
| + for _, scheme := range []string{"dark", "light"} { |
| + drive(t, rig, prefersScheme(scheme), chromedp.Sleep(300*time.Millisecond)) |
| + mobileShot(t, rig, "jobview-ready-phone-"+scheme) |
| + } |
| + drive(t, rig, prefersScheme("dark")) |
| + |
| + // A tap on the scrim, above the sheet, closes it. |
| + drive(t, rig, chromedp.MouseClickXY(195, 120), chromedp.Sleep(300*time.Millisecond)) |
| + if got := harness.Evaluate[string](rig, `(() => { const j = document.querySelector(`+strconv.Quote(job)+`), s = j.querySelector("summary"), p = []; |
| + if (j.querySelector("details").open || s.getAttribute("aria-expanded") !== "false") p.push("still open"); |
| + if (j.querySelector(".jobview").checkVisibility()) p.push("the view shows"); |
| + if (document.querySelector("#ask-panel .scrim")?.checkVisibility()) p.push("the scrim shows"); |
| + if (document.activeElement !== s) p.push("focus on " + document.activeElement.className); |
| + if (!document.documentElement.classList.contains("phone-open")) p.push("the chat closed"); |
| + return p.join("; "); })()`); got != "" { |
| + t.Errorf("after a tap on the scrim: %s", got) |
| + } |
| + mobileShot(t, rig, "job-ready-phone-closed") |
| + |
| + // Without scripts: /ask, and the pill opens its view in place, just |
| + // under it, with no Close and no scrim. |
| + drive(t, rig, scriptsDisabled(true)) |
| + defer drive(t, rig, scriptsDisabled(false)) |
| + page := `.ask-page li.job[data-job="` + id + `"]` |
| + drive(t, rig, chromedp.Navigate(rig.Origin+"/ask"), chromedp.WaitVisible(chromedp.CSS(page+" summary")), |
| + chromedp.Click(chromedp.CSS(page+" summary")), chromedp.Sleep(200*time.Millisecond)) |
| + if got := harness.Evaluate[string](rig, `(() => { const j = document.querySelector(`+strconv.Quote(page)+`), v = j.querySelector(".jobview"), p = []; |
| + if (!j.querySelector("details").open) p.push("closed"); |
| + if (!v.checkVisibility()) return p.concat("the view is not drawn").join("; "); |
| + const r = v.getBoundingClientRect(), pill = j.querySelector(".pill").getBoundingClientRect(); |
| + if (r.top < pill.bottom || r.top - pill.bottom > 12 || r.left < pill.left - 0.5) p.push("not under the pill: " + JSON.stringify(r) + " pill " + JSON.stringify(pill)); |
| + if (v.querySelector("[data-job-close]").checkVisibility()) p.push("Close shows"); |
| + if (document.querySelector(".scrim")) p.push("a scrim"); |
| + if (v.querySelector(".jv-stage").textContent !== "Ready to try" || v.querySelector(".jv-go")?.textContent !== "Try it") p.push("its words: " + v.innerText); |
| + return p.join("; "); })()`); got != "" { |
| + t.Errorf("scripts off, the job view: %s", got) |
| + } |
| + mobileShot(t, rig, "jobview-ready-phone-noscript") |
| +} |
diff --git a/internal/equipo/equipotest/chat.go b/internal/equipo/equipotest/chat.go| index 432ba78..62be430 100644 |
| --- a/internal/equipo/equipotest/chat.go |
| +++ b/internal/equipo/equipotest/chat.go |
| @@ -157,6 +157,20 @@ func (f *Fake) AskJob(title string) string { |
| return c.ID |
| } |
| +// AskLegacyJob puts a job card in the conversation as Equipo draws a job |
| +// handed on before job threads (plan decision J7): it has no thread, so no |
| +// link to a page in Equipo. It returns the card's id. |
| +func (f *Fake) AskLegacyJob(title string) string { |
| + f.cmu.Lock() |
| + defer f.cmu.Unlock() |
| + now := time.Now().UTC() |
| + c := &card{ID: f.next("c"), Revision: 1, Kind: equipo.CardJob, State: equipo.JobWorking, Question: title, |
| + Options: []equipo.Option{}, Links: []equipo.Link{}, Result: "Getting started", Detail: "Working out what's needed.", StartedAt: &now} |
| + f.cards = append(f.cards, c) |
| + f.emit("card", "card", c.ID, c.Revision, "", *c) |
| + return c.ID |
| +} |
| + |
| // SetJob moves job card id to state with result and detail, and links |
| // before its Equipo link, which stays last: a new revision, announced. |
| func (f *Fake) SetJob(id, state, result, detail string, links ...equipo.Link) { |
| @@ -177,6 +191,20 @@ func (f *Fake) SetJob(id, state, result, detail string, links ...equipo.Link) { |
| } |
| } |
| +// SetJobStarted moves when job card id started to at: a new revision, |
| +// announced. |
| +func (f *Fake) SetJobStarted(id string, at time.Time) { |
| + f.cmu.Lock() |
| + defer f.cmu.Unlock() |
| + for _, c := range f.cards { |
| + if c.ID == id { |
| + at := at.UTC() |
| + c.StartedAt, c.Revision = &at, c.Revision+1 |
| + f.emit("card", "card", c.ID, c.Revision, "", *c) |
| + } |
| + } |
| +} |
| + |
| // AskOutcomeFor puts an open outcome card in the conversation that |
| // belongs to job card job, as Equipo mirrors a job's go-ahead or Publish. |
| func (f *Fake) AskOutcomeFor(job, question string, options []equipo.Option, links []equipo.Link) string { |
diff --git a/internal/look/static/app.css b/internal/look/static/app.css| index 0bf7762..f403657 100644 |
| --- a/internal/look/static/app.css |
| +++ b/internal/look/static/app.css |
| @@ -558,11 +558,48 @@ aside.ask-panel { position: absolute; top: 16px; right: 16px; bottom: 16px; widt |
| .job:not([data-state="working"]) .state-mark { background: var(--st); } |
| @keyframes turn { to { transform: rotate(1turn); } } |
| @keyframes glow { from { opacity: .45; } } |
| -/* The job view, opened from the pill, for now its status line, just below |
| - it. */ |
| -.job-toggle > .jobview { position: absolute; z-index: 5; top: calc(100% + 6px); left: 0; min-width: 200px; max-width: 100%; padding: 10px 16px; border-radius: 14px; |
| - background: var(--menu-base); box-shadow: inset 0 0 0 1px var(--pill-edge), 0 22px 48px -14px var(--menu-shadow); } |
| -.jv-stage { margin: 0; font-size: 14px; } |
| +/* The job view, opened from the pill: its title, the status, one sentence |
| + more, when it started, and the link to the work. Without scripts it |
| + opens in place, just under the pill. With them (ask.js) it is a popover |
| + in the top layer, anchored to the pill inside the chat, and on a phone a |
| + sheet from the foot of the screen over the dimmed chat (the scrim). It |
| + never sets display: the popover's own rules show and hide it. */ |
| +.jobview { width: min(320px, calc(100vw - 32px)); padding: 10px 10px 12px 16px; border: 0; border-radius: 16px; color: var(--frost); background: var(--menu-base); |
| + box-shadow: inset 0 0 0 1px var(--pill-edge), inset 0 1px 0 var(--menu-shine), 0 22px 48px -14px var(--menu-shadow); |
| + font-size: 14px; line-height: 1.45; white-space: normal; text-align: left; } |
| +.job-toggle > .jobview:not([popover]) { position: absolute; z-index: 5; top: calc(100% + 6px); left: 0; } |
| +.jobview[popover] { position: fixed; inset: auto; margin: 0; overflow: visible; animation: rise .18s var(--ease, cubic-bezier(.2,.8,.2,1)); } |
| +.jobview header { display: flex; align-items: center; gap: 10px; } |
| +.jobview header .state-mark { width: 26px; height: 26px; } |
| +.jobview header .state-mark svg { width: 14px; height: 14px; } |
| +.jobview h3 { flex: 1; min-width: 0; margin: 0; padding: 0; font-size: 16px; font-weight: 600; line-height: 1.35; letter-spacing: -0.01em; font-variation-settings: "STYL" 0; } |
| +.jobview h3:not(:has(a)) { padding: 11px 0; } |
| +/* The title is the quiet way into Equipo: it reads as a heading, in the |
| + heading's ink, with no underline until it is pointed at. A small arrow |
| + shows on hover and focus, and always on touch screens and phones. */ |
| +.jv-title { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; color: inherit; text-decoration: none; border-radius: 6px; } |
| +.jv-title:hover { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 4px; text-decoration-color: var(--haze); } |
| +.jv-title svg { flex: none; width: 13px; height: 13px; fill: none; stroke: var(--haze); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; |
| + opacity: 0; transition: opacity .15s; } |
| +.jv-title:hover svg, .jv-title:focus-visible svg { opacity: 1; } |
| +@media (hover: none) { .jv-title svg { opacity: 1; } } |
| +.jobview .round { flex: none; width: 44px; height: 44px; padding: 0; border: 0; border-radius: 50%; display: grid; place-items: center; cursor: pointer; |
| + color: var(--frost); background: none; transition: background .2s; } |
| +.jobview .round[hidden] { display: none; } |
| +.jobview .round:hover { background: var(--hover); } |
| +.jobview .round svg { width: 20px; height: 20px; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; fill: none; } |
| +/* Under the title, in line with it: the status, one sentence more, and |
| + when it started. */ |
| +.jobview > p { margin: 0 10px 0 36px; } |
| +.jv-stage { font-weight: 500; } |
| +.jobview > .jv-detail { margin-top: 2px; color: var(--haze); } |
| +.jobview > .jv-started { margin-top: 8px; color: var(--haze); font-size: 13px; } |
| +.jv-go { display: inline-flex; align-items: center; height: 44px; margin: 14px 10px 0 0; padding: 0 18px; border-radius: 10px; font-weight: 600; font-size: 15px; |
| + text-decoration: none; background: var(--btn); color: var(--btn-ink); } |
| +.scrim { position: absolute; inset: 0; z-index: 4; background: var(--scrim); border-radius: inherit; } |
| +.ask-page { position: relative; } |
| +@keyframes rise { from { opacity: 0; transform: translateY(6px); } } |
| +@keyframes sheet { from { transform: translateY(100%); } } |
| /* The person's decisions for a job (its go-ahead, Publish) hang under its |
| pill, joined to it by a thread line. */ |
| .job-cards { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; } |
| @@ -659,6 +696,16 @@ main { min-height: 100dvh; } |
| aside.ask-panel .msg { max-width: 92%; } |
| } |
| +/* Phones (the docked chat's and /ask's): the job view rises from the foot |
| + of the screen as a sheet, over the dimmed chat. */ |
| +@media (max-width: 640px) { |
| + .jobview[popover] { left: 0 !important; right: 0; top: auto !important; bottom: 0; width: auto; border-radius: 22px 22px 0 0; |
| + padding: 8px 8px calc(16px + env(safe-area-inset-bottom)) 20px; animation: sheet .28s var(--ease, cubic-bezier(.2,.8,.2,1)); } |
| + .jobview[popover]::before { content: ""; display: block; width: 36px; height: 4px; margin: 0 auto 2px; border-radius: 2px; background: var(--rule); transform: translateX(-6px); } |
| + .jobview[popover] .jv-go { width: calc(100% - 12px); justify-content: center; } |
| + .jv-title svg { opacity: 1; } |
| +} |
| + |
| /* Phones, beyond Home: the inner pages and /ask. */ |
| @media (max-width: 600px) { |
| .inner { padding: 10px; } |
| @@ -679,6 +726,8 @@ main { min-height: 100dvh; } |
| /* A working job's mark holds still: a quarter arc and a steady dot. */ |
| .job[data-state="working"] .state-mark::after, .job[data-state="working"] .state-mark::before { animation: none; } |
| .job[data-state="working"] .state-mark::after { transform: rotate(45deg); } |
| + /* The job view just shows: no rise, no sheet sliding up. */ |
| + .jobview[popover] { animation: none; } |
| } |
| /* Scratchpad's shared note: a field that grows past one control height. */ |
diff --git a/internal/look/static/ask.js b/internal/look/static/ask.js| index ff995d8..1cc3bd6 100644 |
| --- a/internal/look/static/ask.js |
| +++ b/internal/look/static/ask.js |
| @@ -26,6 +26,8 @@ function start(root) { |
| let retry = 0; |
| const json = { Accept: "application/json" }; |
| + // A phone: Home's chat comes up full screen, and a job view is a sheet. |
| + const phone = matchMedia("(max-width: 640px)"); |
| // The states that show the conversation: ready, and ready without a |
| // runner that can answer (none, or one too old), which adds a note. |
| @@ -298,10 +300,10 @@ function start(root) { |
| // A job, a pill, drawn as the server draws it (the ask-job template): its |
| // state's mark, the title and its status, and once there is something to |
| - // see (ready, done) the link to it. Its job page's link (rel) is never |
| - // drawn here. A newer revision redraws it in place, never a second; the |
| - // cards under it move to the new pill (ruling P6j), and so do loose cards |
| - // of the job, drawn before it was; an open job view stays open. |
| + // see (ready, done) the link to it. A newer revision redraws it in place, |
| + // never a second; the cards under it move to the new pill (ruling P6j), |
| + // and so do loose cards of the job, drawn before it was; an open job view |
| + // stays open, and focus stays where it was. |
| const jobStates = ["working", "asking", "ready", "done", "stopped"]; |
| const marks = { |
| asking: "M9.2 9.2a2.9 2.9 0 0 1 5.6 1c0 2-2.8 2.4-2.8 4.3M12 18.2h.01", |
| @@ -316,6 +318,36 @@ function start(root) { |
| if (text !== undefined) el.textContent = text; |
| return el; |
| } |
| + function para(cls, text) { |
| + const p = document.createElement("p"); |
| + p.className = cls; |
| + p.textContent = text; |
| + return p; |
| + } |
| + // icon is a 24-unit SVG of one path. |
| + function icon(d) { |
| + const svg = document.createElementNS(svgNS, "svg"); |
| + svg.setAttribute("viewBox", "0 0 24 24"); |
| + const path = document.createElementNS(svgNS, "path"); |
| + path.setAttribute("d", d); |
| + svg.append(path); |
| + return svg; |
| + } |
| + // A state's mark: working has none (it turns, in CSS). |
| + function stateMark(state) { |
| + const mark = span("state-mark"); |
| + mark.setAttribute("aria-hidden", "true"); |
| + if (marks[state]) mark.append(icon(marks[state])); |
| + return mark; |
| + } |
| + // goOf is where to see job c's work once there is something to see |
| + // (ready, done): its first link with no rel, as {href, label}, or null. |
| + function goOf(c) { |
| + if (c.state !== "ready" && c.state !== "done") return null; |
| + const go = (c.links || []).find((l) => l && !l.rel); |
| + const href = go && typeof go.url === "string" && webURL(go.url); |
| + return href ? { href, label: go.label || href } : null; |
| + } |
| function addJob(c) { |
| if (!c || !c.id || !jobStates.includes(c.state)) return; |
| const old = item("data-job", c.id); |
| @@ -330,27 +362,15 @@ function start(root) { |
| pill.className = "pill"; |
| const details = document.createElement("details"); |
| details.className = "job-toggle"; |
| - details.open = !!old && !!old.querySelector("details.job-toggle")?.open; |
| const summary = document.createElement("summary"); |
| summary.className = "pill-main"; |
| summary.setAttribute("aria-label", title + ", " + stage); |
| - const mark = span("state-mark"); |
| - mark.setAttribute("aria-hidden", "true"); |
| - if (marks[c.state]) { |
| - const svg = document.createElementNS(svgNS, "svg"); |
| - svg.setAttribute("viewBox", "0 0 24 24"); |
| - const path = document.createElementNS(svgNS, "path"); |
| - path.setAttribute("d", marks[c.state]); |
| - svg.append(path); |
| - mark.append(svg); |
| - } |
| - summary.append(mark, span("pill-title", title), span("pill-stage", stage)); |
| + summary.append(stateMark(c.state), span("pill-title", title), span("pill-stage", stage)); |
| details.append(summary, jobView(c)); |
| pill.append(details); |
| - const go = (c.links || []).find((l) => l && !l.rel); |
| - const href = go && typeof go.url === "string" && webURL(go.url); |
| - if ((c.state === "ready" || c.state === "done") && href) { |
| - const a = link(href, go.label || href); |
| + const go = goOf(c); |
| + if (go) { |
| + const a = link(go.href, go.label); |
| a.className = "pill-link"; |
| pill.append(a); |
| } |
| @@ -359,24 +379,201 @@ function start(root) { |
| if (old) list.append(...old.querySelectorAll(":scope > ol.job-cards > li")); |
| list.append(...thread.querySelectorAll(`:scope > [data-for="${CSS.escape(c.id)}"]`)); |
| li.append(pill, list); |
| + const focus = document.activeElement; |
| + const inView = !!old && !!old.querySelector(".jobview")?.contains(focus); |
| + const onPill = !!old && old.querySelector("summary") === focus; |
| + if (popovers) { |
| + summary.setAttribute("aria-expanded", "false"); |
| + } else { |
| + details.open = !!old && !!old.querySelector("details.job-toggle")?.open; |
| + } |
| if (old) old.replaceWith(li); |
| else thread.append(li); |
| + if (popovers && viewing === c.id) openView(li, inView, true); |
| + else if (onPill) summary.focus({ preventScroll: true }); |
| scroll(); |
| } |
| - // The job view, opened from the pill: for now, its status line (the |
| - // ask-jobview template). Its title, linked to the job's own page, goes |
| - // here: the only place that link is drawn. |
| + // The job view, opened from the pill, drawn as the server draws it (the |
| + // ask-jobview template): the title, linked to the job's own page (its |
| + // link with rel equipo, the link's label as its tooltip): the only place |
| + // that link is drawn. Then the status, one sentence more, when it |
| + // started, and the link to the work once there is something to see. |
| function jobView(c) { |
| const view = document.createElement("section"); |
| view.className = "jobview"; |
| view.setAttribute("aria-label", c.question || ""); |
| - const p = document.createElement("p"); |
| - p.className = "jv-stage"; |
| - p.textContent = c.result || ""; |
| - view.append(p); |
| + const header = document.createElement("header"); |
| + const h3 = document.createElement("h3"); |
| + const page = (c.links || []).find((l) => l && l.rel === "equipo"); |
| + const href = page && typeof page.url === "string" && webURL(page.url); |
| + if (href) { |
| + const a = link(href, c.question || ""); |
| + a.className = "jv-title"; |
| + if (page.label) a.title = page.label; |
| + const arrow = icon("M9 6h9v9M18 6L7 17"); |
| + arrow.setAttribute("aria-hidden", "true"); |
| + a.append(arrow); |
| + h3.append(a); |
| + } else h3.textContent = c.question || ""; |
| + const close = document.createElement("button"); |
| + close.className = "round"; |
| + close.type = "button"; |
| + close.dataset.jobClose = ""; |
| + close.setAttribute("aria-label", "Close"); |
| + const x = icon("M6 6l12 12M18 6L6 18"); |
| + x.setAttribute("aria-hidden", "true"); |
| + close.append(x); |
| + // Without the popover it opens in place, as without scripts: no Close. |
| + close.hidden = !popovers; |
| + header.append(stateMark(c.state), h3, close); |
| + view.append(header, para("jv-stage", c.result || "")); |
| + if (c.detail) view.append(para("jv-detail", c.detail)); |
| + const at = typeof c.started_at === "string" ? new Date(c.started_at) : null; |
| + if (at && !isNaN(at)) { |
| + const p = para("jv-started", startedText(at, Date.now())); |
| + p.dataset.at = c.started_at; |
| + view.append(p); |
| + } |
| + const go = goOf(c); |
| + if (go) { |
| + const a = link(go.href, go.label); |
| + a.className = "jv-go"; |
| + view.append(a); |
| + } |
| return view; |
| } |
| + // When a job started (plan decision D19), as the server says it |
| + // (startedText in ask.go): how long ago in minutes or hours, then from a |
| + // day on, the day in Base's time zone (the thread's data-zone; this |
| + // device's if the browser does not know it). It moves on every minute. |
| + const dayOf = (() => { |
| + const day = { day: "numeric", month: "long" }; |
| + try { |
| + return new Intl.DateTimeFormat("en-GB", { ...day, timeZone: thread.dataset.zone || undefined }); |
| + } catch { |
| + return new Intl.DateTimeFormat("en-GB", day); |
| + } |
| + })(); |
| + function startedText(at, now) { |
| + const m = Math.floor((now - at) / 60000), h = Math.floor(m / 60); |
| + if (!(m >= 1)) return "Started just now"; |
| + if (m === 1) return "Started 1 minute ago"; |
| + if (m < 60) return `Started ${m} minutes ago`; |
| + if (h === 1) return "Started 1 hour ago"; |
| + if (h < 24) return `Started ${h} hours ago`; |
| + return "Started on " + dayOf.format(at); |
| + } |
| + setInterval(() => { |
| + for (const p of thread.querySelectorAll(".jv-started[data-at]")) p.textContent = startedText(new Date(p.dataset.at), Date.now()); |
| + }, 60000); |
| + |
| + // The job view opens from its pill (plan decision D13): on a wide screen |
| + // a popover beside the pill inside the chat, above it when there is |
| + // room, else below; on a phone a sheet from the foot of the screen, over |
| + // the chat dimmed by a scrim. Focus goes to its Close; Close, Escape, a |
| + // tap on the pill again, on the scrim or anywhere outside close it, and |
| + // focus goes back to the pill (but for a tap outside, which puts focus |
| + // where it lands). One view is open at a time; viewing is its job's id, |
| + // kept while the job is redrawn. A browser with no popovers keeps the |
| + // <details> as it is without scripts, opening in place. |
| + const popovers = typeof HTMLElement.prototype.showPopover === "function"; |
| + let viewing = ""; |
| + const scrim = document.createElement("div"); |
| + scrim.className = "scrim"; |
| + scrim.hidden = true; |
| + root.append(scrim); |
| + const parts = (li) => { |
| + const details = li.querySelector("details.job-toggle"); |
| + return { details, summary: details.querySelector("summary"), view: details.querySelector(".jobview") }; |
| + }; |
| + // again: the job was redrawn with its view open, which stays put (no |
| + // rise, no sheet sliding up). |
| + function openView(li, focus, again) { |
| + if (viewing && viewing !== li.dataset.job) closeView(false); |
| + const { details, summary, view } = parts(li); |
| + viewing = li.dataset.job; |
| + if (again) view.style.animation = "none"; |
| + details.open = true; |
| + summary.setAttribute("aria-expanded", "true"); |
| + view.popover = "manual"; |
| + const close = view.querySelector("[data-job-close]"); |
| + close.hidden = false; |
| + if (!view.matches(":popover-open")) view.showPopover(); |
| + scrim.hidden = !phone.matches; |
| + place(); |
| + if (focus) close.focus({ preventScroll: true }); |
| + } |
| + function closeView(focus) { |
| + const li = viewing && item("data-job", viewing); |
| + viewing = ""; |
| + scrim.hidden = true; |
| + if (!li) return; |
| + const { details, summary, view } = parts(li); |
| + if (view.matches(":popover-open")) view.hidePopover(); |
| + details.open = false; |
| + summary.setAttribute("aria-expanded", "false"); |
| + if (focus) summary.focus({ preventScroll: true }); |
| + } |
| + // place anchors the open view to its pill, inside the chat and below |
| + // its header (as the mockup's place()); a phone's sheet is the CSS's. |
| + function place() { |
| + const li = viewing && item("data-job", viewing); |
| + if (!li) return; |
| + const view = parts(li).view; |
| + if (phone.matches) { |
| + view.style.left = view.style.top = ""; |
| + return; |
| + } |
| + const chat = root.getBoundingClientRect(), pill = li.querySelector(".pill").getBoundingClientRect(); |
| + const head = root.querySelector(".ask-head")?.getBoundingClientRect().bottom ?? chat.top; |
| + const w = view.offsetWidth, h = view.offsetHeight, above = pill.top - h - 8; |
| + const top = above >= head + 8 ? above : pill.bottom + 8; |
| + view.style.left = Math.max(chat.left + 16, Math.min(pill.left, chat.right - w - 16)) + "px"; |
| + view.style.top = Math.max(head + 8, Math.min(top, chat.bottom - h - 8)) + "px"; |
| + } |
| + if (popovers) { |
| + thread.addEventListener("click", (e) => { |
| + const summary = e.target.closest("summary.pill-main"); |
| + if (summary) { |
| + e.preventDefault(); |
| + const li = summary.closest("li.job"); |
| + if (viewing === li.dataset.job) closeView(true); |
| + else openView(li, true); |
| + } else if (e.target.closest("[data-job-close]")) closeView(true); |
| + }); |
| + // A <details> opened some other way (find in page) opens its view. |
| + thread.addEventListener("toggle", (e) => { |
| + if (!e.target.matches || !e.target.matches("details.job-toggle")) return; |
| + const li = e.target.closest("li.job"); |
| + if (e.target.open && viewing !== li.dataset.job) openView(li, false); |
| + else if (!e.target.open && viewing === li.dataset.job) closeView(false); |
| + }, true); |
| + scrim.addEventListener("click", () => closeView(true)); |
| + document.addEventListener("pointerdown", (e) => { |
| + if (!viewing || e.target === scrim) return; |
| + const li = item("data-job", viewing); |
| + if (li) { |
| + const { summary, view } = parts(li); |
| + if (view.contains(e.target) || summary.contains(e.target)) return; |
| + } |
| + closeView(false); |
| + }); |
| + // Escape closes the view before anything else hears it (the docked |
| + // chat stays open). |
| + document.addEventListener("keydown", (e) => { |
| + if (e.key !== "Escape" || !viewing || e.defaultPrevented) return; |
| + e.preventDefault(); |
| + closeView(true); |
| + }, true); |
| + thread.addEventListener("scroll", place); |
| + addEventListener("resize", () => { |
| + if (!viewing) return; |
| + scrim.hidden = !phone.matches; |
| + place(); |
| + }); |
| + } |
| + |
| const ended = (s) => s === "replied" || s === "failed" || s === "cancelled"; |
| // The field's end holds Stop while a turn runs, else Send once something |
| @@ -475,6 +672,8 @@ function start(root) { |
| } |
| show(s.state); |
| if (!chatting(s.state) || !live()) return; |
| + // An open job view stays open, with focus in it if it was. |
| + const focused = viewing && item("data-job", viewing)?.querySelector(".jobview")?.contains(document.activeElement); |
| thread.replaceChildren(); |
| pinned = true; |
| s.messages.forEach(addMessage); |
| @@ -483,6 +682,8 @@ function start(root) { |
| (j.cards || []).forEach(addCard); |
| } |
| s.cards.forEach(addCard); |
| + if (viewing && !item("data-job", viewing)) closeView(false); |
| + else if (focused) item("data-job", viewing).querySelector("[data-job-close]").focus({ preventScroll: true }); |
| setTurn(s.turn, s.status); |
| toBottom(); |
| listen(s.cursor); |
| @@ -603,7 +804,6 @@ function start(root) { |
| // comes up full screen over it (phone-open), not remembered. Each keeps |
| // its own state, so crossing 640px never strands the chat. |
| const html = document.documentElement; |
| - const phone = matchMedia("(max-width: 640px)"); |
| const home = document.getElementById("home"); |
| const bar = document.querySelector(".shell > .topbar"); |
| const slot = document.querySelector(".ask-slot"); |
diff --git a/internal/web/app.go b/internal/web/app.go| index c2f3a21..16fb289 100644 |
| --- a/internal/web/app.go |
| +++ b/internal/web/app.go |
| @@ -82,8 +82,10 @@ func App(d *db.DB, cfg config.Config, mailer mail.Sender, inst Installer, logger |
| if err != nil { |
| return nil, err |
| } |
| - // newKey gives each chat form its own request key when the page is drawn. |
| - pages, err := look.NewRenderer(sub, template.FuncMap{"newKey": equipo.NewKey}) |
| + // newKey gives each chat form its own request key when the page is |
| + // drawn; startedText says when a job started, as of then. |
| + pages, err := look.NewRenderer(sub, template.FuncMap{"newKey": equipo.NewKey, |
| + "startedText": func(at *time.Time) string { return startedText(*at, time.Now(), cfg.Timezone) }}) |
| if err != nil { |
| return nil, err |
| } |
diff --git a/internal/web/ask.go b/internal/web/ask.go| index e31d568..4cbf972 100644 |
| --- a/internal/web/ask.go |
| +++ b/internal/web/ask.go |
| @@ -5,6 +5,7 @@ import ( |
| "encoding/json" |
| "errors" |
| "net/http" |
| + "strconv" |
| "strings" |
| "sync" |
| "time" |
| @@ -163,7 +164,10 @@ type askView struct { |
| // Next is where connecting comes back to: home, settings or ask. |
| Next string |
| // Equipo is the "Open Equipo" link. |
| - Equipo string |
| + Equipo string |
| + // Zone is Base's time zone, the IANA name, for the day a job started |
| + // on (startedText) when the script draws it. |
| + Zone string |
| Messages []equipo.Message |
| // Jobs are the job cards, each with the cards that belong to it; |
| // Cards every other card shown. |
| @@ -194,6 +198,39 @@ func (j jobView) Go() *equipo.Link { |
| return nil |
| } |
| +// Equipo is the job's own page in Equipo, for templates: the job view's |
| +// title links there (plan decision D3), or nil. |
| +func (j jobView) Equipo() *equipo.Link { |
| + if l, ok := j.Card.Equipo(); ok { |
| + return &l |
| + } |
| + return nil |
| +} |
| + |
| +// startedText says when a job started (plan decision D19): how long ago |
| +// in minutes or hours, then from a day on, the day in Base's time zone |
| +// loc (nil: at as given). A start a little in the future, a clock behind |
| +// Equipo's, is just now. ask.js has the twin (startedText), and moves it |
| +// on every minute. |
| +func startedText(at, now time.Time, loc *time.Location) string { |
| + switch d := now.Sub(at); { |
| + case d < time.Minute: |
| + return "Started just now" |
| + case d < 2*time.Minute: |
| + return "Started 1 minute ago" |
| + case d < time.Hour: |
| + return "Started " + strconv.Itoa(int(d/time.Minute)) + " minutes ago" |
| + case d < 2*time.Hour: |
| + return "Started 1 hour ago" |
| + case d < 24*time.Hour: |
| + return "Started " + strconv.Itoa(int(d/time.Hour)) + " hours ago" |
| + } |
| + if loc != nil { |
| + at = at.In(loc) |
| + } |
| + return "Started on " + at.Format("2 January") |
| +} |
| + |
| // Shows reports whether the block for states (space-separated) shows now. |
| func (v askView) Shows(states string) bool { |
| for _, s := range strings.Fields(states) { |
| @@ -214,7 +251,11 @@ func homeState(state string) string { |
| } |
| func (a *app) newAskView(state, next string) askView { |
| - return askView{State: state, Next: next, Equipo: a.ask.client.Origin() + "/", Key: equipo.NewKey()} |
| + v := askView{State: state, Next: next, Equipo: a.ask.client.Origin() + "/", Key: equipo.NewKey()} |
| + if a.cfg.Timezone != nil { |
| + v.Zone = a.cfg.Timezone.String() |
| + } |
| + return v |
| } |
| // turnStatus is the line under the conversation while a turn runs. A |
diff --git a/internal/web/ask_internal_test.go b/internal/web/ask_internal_test.go| new file mode 100644 |
| index 0000000..606c2cd |
| --- /dev/null |
| +++ b/internal/web/ask_internal_test.go |
| @@ -0,0 +1,44 @@ |
| +package web |
| + |
| +import ( |
| + "testing" |
| + "time" |
| +) |
| + |
| +// "Started N minutes ago" (plan decision D19), at each boundary, and the |
| +// day in Base's time zone once a job is a day old. |
| +func TestStartedText(t *testing.T) { |
| + dublin, err := time.LoadLocation("Europe/Dublin") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + // 23:30 UTC on 1 July is 00:30 on 2 July in Dublin (IST, UTC+1). |
| + at := time.Date(2026, 7, 1, 23, 30, 0, 0, time.UTC) |
| + for _, c := range []struct { |
| + after time.Duration |
| + want string |
| + }{ |
| + {-time.Minute, "Started just now"}, // a clock a little behind Equipo's |
| + {0, "Started just now"}, |
| + {59 * time.Second, "Started just now"}, |
| + {60 * time.Second, "Started 1 minute ago"}, |
| + {119 * time.Second, "Started 1 minute ago"}, |
| + {2 * time.Minute, "Started 2 minutes ago"}, |
| + {59*time.Minute + 59*time.Second, "Started 59 minutes ago"}, |
| + {60 * time.Minute, "Started 1 hour ago"}, |
| + {2 * time.Hour, "Started 2 hours ago"}, |
| + {23*time.Hour + 59*time.Minute, "Started 23 hours ago"}, |
| + {24 * time.Hour, "Started on 2 July"}, |
| + {40 * 24 * time.Hour, "Started on 2 July"}, |
| + } { |
| + if got := startedText(at, at.Add(c.after), dublin); got != c.want { |
| + t.Errorf("startedText(%v after) = %q, want %q", c.after, got, c.want) |
| + } |
| + } |
| + if got := startedText(at, at.Add(24*time.Hour), time.UTC); got != "Started on 1 July" { |
| + t.Errorf("in UTC: %q", got) |
| + } |
| + if got := startedText(at, at.Add(24*time.Hour), nil); got != "Started on 1 July" { |
| + t.Errorf("with no zone (as given): %q", got) |
| + } |
| +} |
diff --git a/internal/web/templates/partials/chat.html b/internal/web/templates/partials/chat.html| index 1ae1eef..ec1a102 100644 |
| --- a/internal/web/templates/partials/chat.html |
| +++ b/internal/web/templates/partials/chat.html |
| @@ -15,8 +15,12 @@ |
| <ol class="job-cards">{{range .Cards}}{{template "ask-card" .}}{{end}}</ol></li>{{end}} |
| {{/* A job state's mark: working has none (the mark turns, in CSS); the rest are still icons. ask.js has the same paths (marks). */}} |
| {{define "ask-mark"}}{{if eq . "asking"}}<svg viewBox="0 0 24 24"><path d="M9.2 9.2a2.9 2.9 0 0 1 5.6 1c0 2-2.8 2.4-2.8 4.3M12 18.2h.01"/></svg>{{else if eq . "ready"}}<svg viewBox="0 0 24 24"><path d="M8 16L16 8M9.5 8H16v6.5"/></svg>{{else if eq . "done"}}<svg viewBox="0 0 24 24"><path d="M6 12.5l4 4 8-9"/></svg>{{else if eq . "stopped"}}<svg viewBox="0 0 24 24"><path d="M9.5 7.5v9M14.5 7.5v9"/></svg>{{end}}{{end}} |
| -{{/* The job view, opened from the pill: for now, its status line. Its title, linked to the job's own page (Card.Equipo), goes here: the only place that link is drawn. */}} |
| -{{define "ask-jobview"}}<section class="jobview" aria-label="{{.Question}}"><p class="jv-stage">{{.Result}}</p></section>{{end}} |
| +{{/* The job view, opened from the pill: its title, the status, one sentence more, when it started, and once there is something to see the link to it. The title links to the job's own page in Equipo (Card.Equipo, "Open in Equipo" as its tooltip, an arrow on hover and focus): the only place the chat links there, never a step the person must take. Without scripts it opens in place under the pill; the panel's script makes it a popover beside the pill, or a sheet on a phone, and shows Close (ask.js, jobView). */}} |
| +{{define "ask-jobview"}}<section class="jobview" aria-label="{{.Question}}"><header><span class="state-mark" aria-hidden="true">{{template "ask-mark" .State}}</span> |
| +<h3>{{with .Equipo}}<a class="jv-title" href="{{.URL}}" title="{{.Label}}" target="_blank" rel="noopener">{{$.Question}}<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M9 6h9v9M18 6L7 17"/></svg></a>{{else}}{{.Question}}{{end}}</h3> |
| +<button class="round" type="button" data-job-close aria-label="Close" hidden><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M6 6l12 12M18 6L6 18"/></svg></button></header> |
| +<p class="jv-stage">{{.Result}}</p>{{with .Detail}}<p class="jv-detail">{{.}}</p>{{end}}{{with .StartedAt}}<p class="jv-started">{{startedText .}}</p>{{end}} |
| +{{- if or (eq .State "ready") (eq .State "done")}}{{with .Go}}<a class="jv-go" href="{{.URL}}" target="_blank" rel="noopener">{{.Label}}</a>{{end}}{{end}}</section>{{end}} |
| {{define "ask-body"}}<div class="ask-note" data-when="connect"{{if not (.Shows "connect")}} hidden{{end}}> |
| <p>Set up Ask Base to start asking.</p> |
| <form method="post" action="/ask/connect"><input type="hidden" name="next" value="{{.Next}}"><button class="btn" type="submit">Set up Ask Base</button></form> |
| @@ -33,7 +37,7 @@ |
| <p>Ask Base isn't answering. Try again in a minute.</p> |
| </div> |
| <div class="ask-chat" data-when="ready norunner oldrunner"{{if not (.Shows "ready norunner oldrunner")}} hidden{{end}}> |
| -<div class="log"><ol class="thread" role="log" aria-label="Conversation"> |
| +<div class="log"><ol class="thread" role="log" aria-label="Conversation"{{with .Zone}} data-zone="{{.}}"{{end}}> |
| {{range .Messages}}{{if eq .Role "person"}}<li class="msg person" data-id="{{.ID}}">{{.Text}}</li>{{else}}<li class="msg coordinator" data-id="{{.ID}}">{{$.Rich .Text}}</li>{{end}} |
| {{end}}{{range .Jobs}}{{template "ask-job" .}} |
| {{end}}{{range .Cards}}{{template "ask-card" .}} |
diff --git a/internal/webtest/ask_test.go b/internal/webtest/ask_test.go| index 3ec9857..a2b627c 100644 |
| --- a/internal/webtest/ask_test.go |
| +++ b/internal/webtest/ask_test.go |
| @@ -1461,8 +1461,12 @@ func TestAskJobPill(t *testing.T) { |
| if strings.Contains(page, `data-card="`+id+`"`) || strings.Contains(job, "pill-link") { |
| t.Errorf("the job is drawn as a card, or links somewhere while working:\n%s", job) |
| } |
| - if strings.Contains(strings.ToLower(textOf(page)), "equipo") || strings.Contains(page, f.URL+"/jobs/") { |
| - t.Errorf("the chat names Equipo or links to the job's page there:\n%s", textOf(page)) |
| + if strings.Contains(strings.ToLower(textOf(page)), "equipo") { |
| + t.Errorf("the chat names Equipo:\n%s", textOf(page)) |
| + } |
| + // The job's page in Equipo is linked once: the job view's title. |
| + if n, in := strings.Count(page, f.URL+"/jobs/"), strings.Count(jobViewOf(t, job), f.URL+"/jobs/"); n != 1 || in != 1 { |
| + t.Errorf("the job's page is linked %d times, %d of them the job view's title:\n%s", n, in, page) |
| } |
| if !strings.Contains(page, `data-empty hidden`) { |
| t.Errorf("the empty line shows beside a job") |
| @@ -1481,6 +1485,68 @@ func TestAskJobPill(t *testing.T) { |
| } |
| } |
| +// jobViewOf is the job view inside a job's li. |
| +func jobViewOf(t *testing.T, job string) string { |
| + t.Helper() |
| + m := regexp.MustCompile(`(?s)<section class="jobview"[^>]*>.*?</section>`).FindString(job) |
| + if m == "" { |
| + t.Fatalf("no job view in:\n%s", job) |
| + } |
| + return m |
| +} |
| + |
| +// The job view, inside the pill's <details> (it opens there without |
| +// scripts): the title, linked to the job's page in Equipo in a new tab |
| +// with "Open in Equipo" as its tooltip (plan decision D3), the status, |
| +// one sentence more, and when it started (D19). A job with no page there |
| +// (a legacy hand-off, J7) has a plain title. Once there is something to |
| +// see, the view links to it as the pill does. |
| +func TestAskJobView(t *testing.T) { |
| + a, f := newAskApp(t) |
| + a.connectEquipo(f) |
| + id := f.AskJob("Building your website") |
| + page := a.get("/ask").Body |
| + view := jobViewOf(t, jobItem(t, page, id)) |
| + if !strings.HasPrefix(view, `<section class="jobview" aria-label="Building your website">`) { |
| + t.Errorf("the view's name:\n%s", view) |
| + } |
| + title := regexp.MustCompile(`(?s)<h3>(.*?)</h3>`).FindStringSubmatch(view) |
| + link := regexp.MustCompile(`^<a class="jv-title" href="([^"]*)" title="Open in Equipo" target="_blank" rel="noopener">Building your website<svg [^>]*aria-hidden="true">.*?</svg></a>$`) |
| + if title == nil || link.FindStringSubmatch(title[1]) == nil || !strings.HasPrefix(link.FindStringSubmatch(title[1])[1], f.URL+"/jobs/h_") { |
| + t.Errorf("the view's title is not its link to the job's page:\n%s", view) |
| + } |
| + expect(t, "status", view, `<p class="jv-stage">(.*?)</p>`, "Getting started") |
| + expect(t, "detail", view, `<p class="jv-detail">(.*?)</p>`, "Working out what's needed.") |
| + expect(t, "started", view, `<p class="jv-started">(.*?)</p>`, "Started just now") |
| + if !regexp.MustCompile(`<button class="round" type="button" data-job-close aria-label="Close" hidden>`).MatchString(view) { |
| + t.Errorf("Close is not there for the script, or shows without it:\n%s", view) |
| + } |
| + if strings.Contains(view, "jv-go") { |
| + t.Errorf("a working job's view links to its work:\n%s", view) |
| + } |
| + if strings.Contains(strings.ToLower(textOf(view)), "equipo") { |
| + t.Errorf("the view names Equipo in its text: %s", textOf(view)) |
| + } |
| + |
| + legacy := f.AskLegacyJob("Fixing the login") |
| + view = jobViewOf(t, jobItem(t, a.get("/ask").Body, legacy)) |
| + expect(t, "legacy title", view, `(?s)<h3>(.*?)</h3>`, "Fixing the login") |
| + if strings.Contains(view, "<a ") { |
| + t.Errorf("a job with no page in Equipo links somewhere:\n%s", view) |
| + } |
| + |
| + f.SetJob(id, "ready", "Ready to try", "Have a look.", equipo.Link{Label: "Try it", URL: "https://preview.example.test/"}) |
| + view = jobViewOf(t, jobItem(t, a.get("/ask").Body, id)) |
| + expect(t, "ready status", view, `<p class="jv-stage">(.*?)</p>`, "Ready to try") |
| + expect(t, "ready detail", view, `<p class="jv-detail">(.*?)</p>`, "Have a look.") |
| + if !strings.Contains(view, `<a class="jv-go" href="https://preview.example.test/" target="_blank" rel="noopener">Try it</a>`) { |
| + t.Errorf("a ready job's view does not link to its work:\n%s", view) |
| + } |
| + if title := regexp.MustCompile(`(?s)<h3>(.*?)</h3>`).FindStringSubmatch(view); title == nil || !link.MatchString(title[1]) { |
| + t.Errorf("a ready job's title lost its link:\n%s", view) |
| + } |
| +} |
| + |
| // The pill shows the status in every state, and a link beside it only |
| // once there is something to see: ready (the preview) and done (the site). |
| func TestAskJobStates(t *testing.T) { |