Public: anyone can read this; the crew can change it.
The printed week sheet ends with the sentence naming who has not yet been told about each overdue date #250
Check · Review · Land · Live done — Landed and live in production.
mason/deal-clock:mason/248-the-printed-week-sheet-ends-with-the-sen → main 1 commit fork
4 files
changed +58
−3
README.md +3 −1
| @@ -63,7 +63,9 @@ looks like today. | ||
| 63 | 63 | 8. **Print the week.** Beside the **This week** heading tap **Print this |
| 64 | 64 | week** for a one-page sheet of the same rows, ready for the Monday office |
| 65 | 65 | meeting. It starts with the overdue Harbor View inspection, then the days |
| 66 | ahead, including the closing on 1418 Alder Lane. | |
| 66 | ahead, including the closing on 1418 Alder Lane. Each overdue row names who | |
| 67 | owes it and whether they were told ("Last told Nov 6" or "Not told yet"); | |
| 68 | declined and held drafts don't count. | |
| 67 | 69 | 9. **See People.** Open **People** in the header. Each person on your deals |
| 68 | 70 | appears once, with every open date they owe across all deals, soonest |
| 69 | 71 | first. Try Priya Nair, the lender on both 1418 Alder Lane and 9 Orchard Row. |
src/pages/week.ts +2 −2
| @@ -12,7 +12,7 @@ import { agent as defaults } from "../env.ts"; | ||
| 12 | 12 | import { asset, escape } from "../http.ts"; |
| 13 | 13 | import { STATUS } from "../timeline.ts"; |
| 14 | 14 | import type { Who } from "../who.ts"; |
| 15 | import { byDay, lateNote, owner, whereNote, thisWeek } from "../week.ts"; | |
| 15 | import { byDay, lateNote, owner, toldLine, whereNote, thisWeek } from "../week.ts"; | |
| 16 | 16 | import { clashLine, clashesLine } from "../overlap.ts"; |
| 17 | 17 | import { layout } from "./layout.ts"; |
| 18 | 18 | import { sideLabel } from "./side.ts"; |
| @@ -44,7 +44,7 @@ export function weekPage(input: { who: Who; agent?: Agent | undefined; deals: re | ||
| 44 | 44 | return `<li class="timeline-row" data-u="${urgencyOf(d, on)}"> |
| 45 | 45 | <p class="timeline-date">${escape(deal.address)} · ${sideLabel(deal.side)}</p> |
| 46 | 46 | <p class="timeline-label"><b>${escape(d.label)}${closingAt(deal, d)}</b></p> |
| 47 | <p class="timeline-owner">${escape(role)}${name === undefined ? "" : ` · ${escape(name)}`}</p> | |
| 47 | <p class="timeline-owner">${escape(role)}${name === undefined ? "" : ` · ${escape(name)}`}${toldLine(deal.sent, d, on) === "" ? "" : ` · ${escape(toldLine(deal.sent, d, on))}`}</p> | |
| 48 | 48 | ${d.kind === "closing" ? clashLine(deal.closingConflicts) : ""}${clashesLine(d.clashes)} |
| 49 | 49 | ${lateNote(d.due, on) === "" ? "" : `<p class="timeline-owner">${escape(lateNote(d.due, on))}</p>`} |
| 50 | 50 | ${d.note === "" ? "" : `<p class="timeline-owner">${escape(d.note)}</p>`} |
src/week.page.test.ts +38
| @@ -113,3 +113,41 @@ test("an overdue row on /week and on the clock carries its due date and how late | ||
| 113 | 113 | expect(await (await get("/week")).text()).toContain(words); |
| 114 | 114 | expect(await (await get("/")).text()).toContain(words); |
| 115 | 115 | }); |
| 116 | ||
| 117 | test("an overdue row says when its party was last told, or that they were not; a declined draft does not count", async () => { | |
| 118 | const { openDb } = await import("./db.ts"); | |
| 119 | const { createDeal, getDeal, sendReminder, declineReminder } = await import("./deals.ts"); | |
| 120 | const { drafts } = await import("./reminders.ts"); | |
| 121 | const { PARTY_LABEL } = await import("./deadlines.ts"); | |
| 122 | const db = openDb(dir); | |
| 123 | const me = { role: "user" as const, id: "u1", name: "alice" }; | |
| 124 | const on = dayOf(agent); | |
| 125 | const made = createDeal(db, me, { address: "5 Told Way", buyer: "Tess Told", seller: "Sol Seller", contractDate: addDays(on, -30), closingDate: addDays(on, 20), openAnyway: true }); | |
| 126 | if (!made.ok) throw new Error(made.message); | |
| 127 | const fresh = () => { | |
| 128 | const got = getDeal(db, me, { id: made.value.id }); | |
| 129 | if (!got.ok) throw new Error(got.message); | |
| 130 | return got.value; | |
| 131 | }; | |
| 132 | const overdue = fresh().deadlines.filter((d) => d.due < on && d.done_at === null && d.waived_at === null); | |
| 133 | const pick = (id: number) => drafts(fresh(), agent).find((d) => d.deadline_id === id && d.party_name !== ""); | |
| 134 | const withDraft = overdue.filter((d) => pick(d.id) !== undefined); | |
| 135 | expect(withDraft.length).toBeGreaterThanOrEqual(2); | |
| 136 | const [told, declined] = withDraft; | |
| 137 | const a = pick(told!.id)!; | |
| 138 | const ask = (d: typeof a) => ({ dealId: made.value.id, deadlineId: d.deadline_id, partyId: d.party_id, moment: d.moment }); | |
| 139 | expect(sendReminder(db, me, { ...ask(a), subject: "Hi", body: "Hello" }).ok).toBe(true); | |
| 140 | const b = pick(declined!.id)!; | |
| 141 | expect(declineReminder(db, me, { ...ask(b), reason: "told by phone", agent }).ok).toBe(true); | |
| 142 | forgetRationing(); | |
| 143 | const html = await (await get("/week")).text(); | |
| 144 | const row = (label: string) => html.split('<li class="timeline-row"').find((r) => r.includes("5 Told Way") && r.includes(`<b>${label}`))!; | |
| 145 | const sentOn = fresh().sent.find((m) => m.deadline_id === told!.id)!.sent_on; | |
| 146 | expect(row(told!.label)).toContain(`${PARTY_LABEL[told!.owes]}`); | |
| 147 | expect(row(told!.label)).toContain(`Last told ${spoken(sentOn)}`); | |
| 148 | expect(row(declined!.label)).toContain("Not told yet"); | |
| 149 | expect(row(declined!.label)).not.toContain("Last told"); | |
| 150 | // A date not yet overdue says nothing of being told. | |
| 151 | const coming = html.split('<li class="timeline-row"').filter((r) => r.includes('data-u="upcoming"') || r.includes('data-u="soon"')); | |
| 152 | for (const r of coming) expect(r).not.toContain("told"); | |
| 153 | }); |
src/week.ts +15
| @@ -85,6 +85,21 @@ export function lateNote(due: string, on: string): string { | ||
| 85 | 85 | return days < 1 ? "" : `due ${spoken(due)} · ${days} ${days === 1 ? "day" : "days"} late`; |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | /** | |
| 89 | * "Last told Nov 6" or "Not told yet" for an overdue date, from the deal's sent record (declined | |
| 90 | * and held drafts are never in it); "" for a date not yet overdue. | |
| 91 | */ | |
| 92 | export function toldLine( | |
| 93 | sent: readonly { deadline_id: number; sent_at: string; sent_on: string; id: number }[], | |
| 94 | d: { id: number; due: string }, | |
| 95 | on: string, | |
| 96 | ): string { | |
| 97 | if (d.due >= on) return ""; | |
| 98 | let last: { sent_at: string; sent_on: string; id: number } | undefined; | |
| 99 | for (const m of sent) if (m.deadline_id === d.id && (last === undefined || m.sent_at > last.sent_at || (m.sent_at === last.sent_at && m.id > last.id))) last = m; | |
| 100 | return last === undefined ? "Not told yet" : `Last told ${spoken(last.sent_on)}`; | |
| 101 | } | |
| 102 | ||
| 88 | 103 | /** The day heading a date sits under: overdue ones share one. */ |
| 89 | 104 | const dayHeading = (due: string, on: string): string => |
| 90 | 105 | due < on ? "Overdue" : due === on ? "Today" : spoken(due); |
new above
offline