@blueshed/joined 0.0.0-stage → 0.1.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/skills/joined/SKILL.md +17 -0
- package/.claude/skills/joined/reference.md +768 -0
- package/LICENSE +19 -0
- package/README.md +115 -2
- package/docs/design.md +148 -0
- package/docs/introduction.md +193 -0
- package/docs/learning.md +76 -0
- package/docs/stories.md +82 -0
- package/examples/app.css +27 -0
- package/examples/cafe/books.html +38 -0
- package/examples/cafe/books.json +13 -0
- package/examples/cafe/books.ts +64 -0
- package/examples/cafe/cafe.css +512 -0
- package/examples/cafe/front.html +115 -0
- package/examples/cafe/front.ts +7 -0
- package/examples/cafe/generated/books.elements.ts +52 -0
- package/examples/cafe/generated/books.queries.ts +11 -0
- package/examples/cafe/generated/books.rules.ts +42 -0
- package/examples/cafe/generated/kitchen.elements.ts +87 -0
- package/examples/cafe/generated/kitchen.queries.ts +47 -0
- package/examples/cafe/generated/kitchen.rules.ts +98 -0
- package/examples/cafe/generated/menu.elements.ts +61 -0
- package/examples/cafe/generated/menu.queries.ts +28 -0
- package/examples/cafe/generated/menu.rules.ts +65 -0
- package/examples/cafe/generated/order.elements.ts +87 -0
- package/examples/cafe/generated/order.queries.ts +47 -0
- package/examples/cafe/generated/order.rules.ts +95 -0
- package/examples/cafe/generated/staff.elements.ts +55 -0
- package/examples/cafe/generated/staff.queries.ts +27 -0
- package/examples/cafe/generated/staff.rules.ts +59 -0
- package/examples/cafe/generated/supplies.elements.ts +62 -0
- package/examples/cafe/generated/supplies.queries.ts +43 -0
- package/examples/cafe/generated/supplies.rules.ts +84 -0
- package/examples/cafe/generated/till.elements.ts +93 -0
- package/examples/cafe/generated/till.queries.ts +57 -0
- package/examples/cafe/generated/till.rules.ts +113 -0
- package/examples/cafe/index.html +70 -0
- package/examples/cafe/kitchen.css +107 -0
- package/examples/cafe/kitchen.html +39 -0
- package/examples/cafe/kitchen.ts +125 -0
- package/examples/cafe/menu.html +55 -0
- package/examples/cafe/menu.json +41 -0
- package/examples/cafe/menu.ts +84 -0
- package/examples/cafe/migrations/001-cafe.ts +11 -0
- package/examples/cafe/order.html +37 -0
- package/examples/cafe/order.ts +45 -0
- package/examples/cafe/rail-drag.ts +30 -0
- package/examples/cafe/routes.ts +32 -0
- package/examples/cafe/staff.json +20 -0
- package/examples/cafe/stories.jsonl +43 -0
- package/examples/cafe/supplies.html +77 -0
- package/examples/cafe/supplies.json +33 -0
- package/examples/cafe/supplies.ts +170 -0
- package/examples/cafe/till.json +95 -0
- package/examples/cafe/till.ts +122 -0
- package/examples/cafe/trust.ts +20 -0
- package/examples/cafe/views.ts +171 -0
- package/examples/docs.ts +28 -0
- package/examples/film.jpg +0 -0
- package/examples/hello/generated/elements.ts +45 -0
- package/examples/hello/generated/queries.ts +24 -0
- package/examples/hello/generated/rules.ts +45 -0
- package/examples/hello/hello.css +27 -0
- package/examples/hello/hello.json +1 -0
- package/examples/hello/index.html +32 -0
- package/examples/hello/migrations/001-hello.ts +6 -0
- package/examples/hello/page.ts +49 -0
- package/examples/hello/routes.ts +6 -0
- package/examples/hello/stories.jsonl +3 -0
- package/examples/index.html +146 -0
- package/examples/page.ts +11 -0
- package/examples/people/adding.ts +20 -0
- package/examples/people/generated/elements.ts +68 -0
- package/examples/people/generated/queries.ts +28 -0
- package/examples/people/generated/rules.ts +85 -0
- package/examples/people/links.ts +124 -0
- package/examples/people/migrations/001-people.ts +6 -0
- package/examples/people/migrations/002-add-people-member-and-guard-people.ts +7 -0
- package/examples/people/migrations/003-add-people-rank-and-guard-people.ts +7 -0
- package/examples/people/order.ts +61 -0
- package/examples/people/people.css +65 -0
- package/examples/people/people.json +26 -0
- package/examples/people/routes.ts +12 -0
- package/examples/people/stories.jsonl +20 -0
- package/examples/people/trust.ts +14 -0
- package/examples/people/view.ts +115 -0
- package/examples/routes.ts +11 -0
- package/examples/trip/answer-rows.ts +70 -0
- package/examples/trip/answers.ts +11 -0
- package/examples/trip/bar.ts +89 -0
- package/examples/trip/calendar-map.css +709 -0
- package/examples/trip/calendar-map.ts +249 -0
- package/examples/trip/drags.ts +143 -0
- package/examples/trip/drawer.ts +250 -0
- package/examples/trip/event-form.ts +199 -0
- package/examples/trip/generated/elements.ts +144 -0
- package/examples/trip/generated/queries.ts +46 -0
- package/examples/trip/generated/rules.ts +239 -0
- package/examples/trip/holding.ts +61 -0
- package/examples/trip/ics.ts +117 -0
- package/examples/trip/index.html +82 -0
- package/examples/trip/line-stops.ts +92 -0
- package/examples/trip/line-words.ts +79 -0
- package/examples/trip/line.ts +121 -0
- package/examples/trip/map.ts +234 -0
- package/examples/trip/mercator.ts +28 -0
- package/examples/trip/migrations/001-trip.ts +7 -0
- package/examples/trip/migrations/002-add-events-zone-and-guard-events.ts +7 -0
- package/examples/trip/migrations/003-guard-events-and-create-events_asked-and-more.ts +9 -0
- package/examples/trip/migrations/004-create-stays.ts +6 -0
- package/examples/trip/migrations/005-guard-events-and-create-events_arrives-and-more.ts +8 -0
- package/examples/trip/month.ts +87 -0
- package/examples/trip/other-weeks.ts +67 -0
- package/examples/trip/page.ts +121 -0
- package/examples/trip/peek.ts +71 -0
- package/examples/trip/people-chips.ts +74 -0
- package/examples/trip/place-search.ts +51 -0
- package/examples/trip/places.ts +34 -0
- package/examples/trip/routes.ts +27 -0
- package/examples/trip/shell.ts +39 -0
- package/examples/trip/stays.css +51 -0
- package/examples/trip/stays.ts +68 -0
- package/examples/trip/stories.jsonl +72 -0
- package/examples/trip/time.ts +46 -0
- package/examples/trip/told.ts +48 -0
- package/examples/trip/trip.json +69 -0
- package/examples/trip/trust.ts +51 -0
- package/examples/trip/week.ts +237 -0
- package/examples/trip/words.ts +4 -0
- package/examples/trip/writes.ts +91 -0
- package/examples/trip/zones.ts +16 -0
- package/examples/trips/card.ts +149 -0
- package/examples/trips/generated/elements.ts +60 -0
- package/examples/trips/generated/queries.ts +28 -0
- package/examples/trips/generated/rules.ts +62 -0
- package/examples/trips/index.html +47 -0
- package/examples/trips/map.ts +52 -0
- package/examples/trips/migrations/001-trips.ts +8 -0
- package/examples/trips/new-trip.ts +46 -0
- package/examples/trips/page.ts +9 -0
- package/examples/trips/routes.ts +7 -0
- package/examples/trips/stories.jsonl +12 -0
- package/examples/trips/trips.css +183 -0
- package/examples/trips/trips.json +7 -0
- package/examples/weeks/derive.ts +23 -0
- package/examples/weeks/generated/elements.ts +52 -0
- package/examples/weeks/generated/rules.ts +33 -0
- package/examples/weeks/routes.ts +4 -0
- package/examples/weeks/weeks.json +1 -0
- package/examples/welcome.css +299 -0
- package/package.json +55 -4
- package/src/attachment.ts +70 -0
- package/src/cli.ts +52 -0
- package/src/client.ts +98 -0
- package/src/compile.ts +2034 -0
- package/src/css.d.ts +5 -0
- package/src/definitions.ts +268 -0
- package/src/demo.css +29 -0
- package/src/demo.ts +42 -0
- package/src/draft.ts +69 -0
- package/src/engine.ts +288 -0
- package/src/file-value.ts +13 -0
- package/src/files.ts +187 -0
- package/src/follow.ts +56 -0
- package/src/hues.ts +3 -0
- package/src/icon-names.ts +77 -0
- package/src/icon.png +0 -0
- package/src/icons.ts +32 -0
- package/src/keep.ts +33 -0
- package/src/link.ts +31 -0
- package/src/mcp.ts +252 -0
- package/src/members/demo.ts +53 -0
- package/src/members/generated/elements.ts +68 -0
- package/src/members/generated/queries.ts +29 -0
- package/src/members/generated/rules.ts +65 -0
- package/src/members/group.ts +294 -0
- package/src/members/keys.ts +221 -0
- package/src/members/members.json +9 -0
- package/src/members/migrations/001-members.ts +6 -0
- package/src/members/migrations/002-guard-members.ts +11 -0
- package/src/members/migrations/003-add-members-act-and-guard-members.ts +7 -0
- package/src/members/panel.css +208 -0
- package/src/members/panel.ts +398 -0
- package/src/members/routes.ts +4 -0
- package/src/members/stories.jsonl +27 -0
- package/src/members/trust.ts +116 -0
- package/src/migrate.ts +597 -0
- package/src/migrations/001-joined.ts +13 -0
- package/src/migrations/002-group-keys.ts +16 -0
- package/src/migrations/003-change-inverse.ts +10 -0
- package/src/migrations/004-change-followed.ts +6 -0
- package/src/ops.ts +61 -0
- package/src/page.css +79 -0
- package/src/page.ts +413 -0
- package/src/parts.css +471 -0
- package/src/parts.ts +152 -0
- package/src/server.ts +862 -0
- package/src/settings.ts +94 -0
- package/src/starter.ts +89 -0
- package/src/store.ts +815 -0
- package/src/stories.ts +387 -0
- package/src/toast.ts +52 -0
- package/src/together.ts +167 -0
- package/src/tokens.css +85 -0
- package/src/tokens.json +457 -0
- package/src/upkeep.ts +86 -0
- package/src/visitors.ts +43 -0
- package/src/write.ts +567 -0
- package/starter/CLAUDE.md +37 -0
- package/starter/gitignore +3 -0
- package/starter/tests/hello-page.test.ts +14 -0
- package/starter/tests/hello.test.ts +8 -0
- package/starter/tsconfig.json +17 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// Written by src/compile.ts from examples/cafe/stories.jsonl: change the stories, not this.
|
|
2
|
+
|
|
3
|
+
// Each collection is an element, defined here: on a page, it holds the document, and its items
|
|
4
|
+
// are put inside it. Each item is an element, defined by the page: as it is, or by a view that
|
|
5
|
+
// extends it. A field is an attribute (a list of ids as IDREFS: "1 3"), and an item's key the
|
|
6
|
+
// document's id for it. How an item looks is the app's: its view, or a display holding the
|
|
7
|
+
// collection draws it. Ops go up as an "ops" event, for the page to send to till, with why they
|
|
8
|
+
// were made if it's said; only the ops the stories allow can be sent. Each returns its write's answer.
|
|
9
|
+
|
|
10
|
+
import { hold, letGo, type Answer } from "joined/page";
|
|
11
|
+
|
|
12
|
+
// the document an element is of: its collection's doc attribute (an instance of a kind, shelf:1), or till
|
|
13
|
+
const docOf = (el: Element) => el.closest("[doc]")?.getAttribute("doc") ?? "till";
|
|
14
|
+
// an element's ops go up as an "ops" event; what it returns is the write's answer, done or refused
|
|
15
|
+
const send = (from: Element, ops: object[], why?: string) => new Promise<Answer>((answer) => from.dispatchEvent(new CustomEvent("ops", { bubbles: true, composed: true, detail: { doc: docOf(from), ops, why, answer } })));
|
|
16
|
+
|
|
17
|
+
/** An order's fields, as the stories give them. */
|
|
18
|
+
export type JOrderData = { "customer": string; "status"?: string; "placed"?: string; "code"?: string; "total"?: number };
|
|
19
|
+
/** An add of an order, as it's sent: its fields as the stories write them. */
|
|
20
|
+
export type JOrderValue = { "customer": string; "status"?: string; "placed"?: string; "code"?: string; "total"?: number };
|
|
21
|
+
|
|
22
|
+
/** <j-order key>: customer (string), status (string), placed (instant), code (string), total (integer), each an attribute. */
|
|
23
|
+
export class JOrder extends HTMLElement {
|
|
24
|
+
static observedAttributes = ["customer","status","placed","code","total","may"];
|
|
25
|
+
#data?: JOrderData;
|
|
26
|
+
/** Its id in the document. */
|
|
27
|
+
get key() { return Number(this.getAttribute("key")); }
|
|
28
|
+
get path() { return `/orders/${this.key}`; }
|
|
29
|
+
/** Its fields, read from its attributes once and again when one changes: frozen, since they're shared. */
|
|
30
|
+
get data(): JOrderData {
|
|
31
|
+
return (this.#data ??= Object.freeze({ "customer": this.getAttribute("customer") ?? "", "status": this.getAttribute("status") ?? undefined, "placed": this.getAttribute("placed") ?? undefined, "code": this.getAttribute("code") ?? undefined, "total": this.hasAttribute("total") ? Number(this.getAttribute("total")) : undefined }) as JOrderData);
|
|
32
|
+
}
|
|
33
|
+
/** How a view shows it, drawn again whenever an attribute changes (what its person may do, its may, too). */
|
|
34
|
+
draw?(): void;
|
|
35
|
+
attributeChangedCallback() { this.#data = undefined; this.draw?.(); }
|
|
36
|
+
/** Replace some of its fields (status): one write for all of them. */
|
|
37
|
+
replace(fields: Partial<Pick<JOrderData, "status">>, why?: string) {
|
|
38
|
+
return send(this, Object.entries(fields).filter(([, value]) => value !== undefined).map(([field, value]) => ({ op: "replace", path: `${this.path}/${field.replace(".", "/")}`, value })), why);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** <j-orders>: the document's orders, each a <j-order> inside it. */
|
|
43
|
+
export class JOrders extends HTMLElement {
|
|
44
|
+
connectedCallback() { hold(this, docOf(this), "orders", "j-order", {"customer":"string","status":"string","placed":"instant","code":"string","total":"integer"}); }
|
|
45
|
+
disconnectedCallback() { letGo(this); }
|
|
46
|
+
/** Its orders, as the document has them. */
|
|
47
|
+
get items() { return [...this.children].filter((el): el is JOrder => el.localName === "j-order"); }
|
|
48
|
+
/** Add orders: one write for all of them. */
|
|
49
|
+
add(...values: JOrderValue[]) { return send(this, values.map((value) => ({ op: "add", path: "/orders/-", value }))); }
|
|
50
|
+
}
|
|
51
|
+
customElements.define("j-orders", JOrders);
|
|
52
|
+
|
|
53
|
+
/** A line's fields, as the stories give them. */
|
|
54
|
+
export type JLineData = { "order": number; "item": number; "qty": number; "name"?: string; "price"?: number };
|
|
55
|
+
/** An add of a line, as it's sent: its fields as the stories write them. */
|
|
56
|
+
export type JLineValue = { "order": number | `$${number}`; "item": number | `$${number}`; "qty": number; "name"?: string; "price"?: number };
|
|
57
|
+
|
|
58
|
+
/** <j-line key>: order (an id in orders), item (an id in items), qty (integer), name (string), price (integer), each an attribute. */
|
|
59
|
+
export class JLine extends HTMLElement {
|
|
60
|
+
static observedAttributes = ["order","item","qty","name","price","may"];
|
|
61
|
+
#data?: JLineData;
|
|
62
|
+
/** Its id in the document. */
|
|
63
|
+
get key() { return Number(this.getAttribute("key")); }
|
|
64
|
+
get path() { return `/lines/${this.key}`; }
|
|
65
|
+
/** Its fields, read from its attributes once and again when one changes: frozen, since they're shared. */
|
|
66
|
+
get data(): JLineData {
|
|
67
|
+
return (this.#data ??= Object.freeze({ "order": Number(this.getAttribute("order")), "item": Number(this.getAttribute("item")), "qty": Number(this.getAttribute("qty")), "name": this.getAttribute("name") ?? undefined, "price": this.hasAttribute("price") ? Number(this.getAttribute("price")) : undefined }) as JLineData);
|
|
68
|
+
}
|
|
69
|
+
/** How a view shows it, drawn again whenever an attribute changes (what its person may do, its may, too). */
|
|
70
|
+
draw?(): void;
|
|
71
|
+
attributeChangedCallback() { this.#data = undefined; this.draw?.(); }
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** <j-lines>: the document's lines, each a <j-line> inside it. */
|
|
75
|
+
export class JLines extends HTMLElement {
|
|
76
|
+
connectedCallback() { hold(this, docOf(this), "lines", "j-line", {"order":"integer","item":"integer","qty":"integer","name":"string","price":"integer"}); }
|
|
77
|
+
disconnectedCallback() { letGo(this); }
|
|
78
|
+
/** Its lines, as the document has them. */
|
|
79
|
+
get items() { return [...this.children].filter((el): el is JLine => el.localName === "j-line"); }
|
|
80
|
+
/** Add lines: one write for all of them. */
|
|
81
|
+
add(...values: JLineValue[]) { return send(this, values.map((value) => ({ op: "add", path: "/lines/-", value }))); }
|
|
82
|
+
}
|
|
83
|
+
customElements.define("j-lines", JLines);
|
|
84
|
+
|
|
85
|
+
/** An op on till the stories allow, in any of its collections. */
|
|
86
|
+
export type TillOp =
|
|
87
|
+
| { op: "add"; path: "/orders/-"; value: JOrderValue }
|
|
88
|
+
| { op: "replace"; path: `/orders/${number}/status`; value: string }
|
|
89
|
+
| { op: "add"; path: "/lines/-"; value: JLineValue };
|
|
90
|
+
|
|
91
|
+
/** One write to till across its collections (a move with its legs): sent from an element of it, checked
|
|
92
|
+
* whole by its rules, and made whole or not at all. */
|
|
93
|
+
export function write(from: Element, ops: TillOp[], why?: string) { return send(from, ops, why); }
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Written by src/compile.ts from examples/cafe/stories.jsonl: change the stories, not this.
|
|
2
|
+
|
|
3
|
+
/** Each collection's item, as one row of its table (`t`) is it: what the query gathers, and what the store keeps of a
|
|
4
|
+
* row a write changes, before and after, to tell each document holding it. */
|
|
5
|
+
export const items: Record<string, string> = {
|
|
6
|
+
"orders": "json_patch('{}', json_object('id', t.id,\n 'customer', t.\"customer\",\n 'status', t.\"status\",\n 'placed', t.\"placed\",\n 'code', t.\"code\",\n 'total', t.\"total\"))",
|
|
7
|
+
"lines": "json_patch('{}', json_object('id', t.id,\n 'order', t.\"order\",\n 'item', t.\"item\",\n 'qty', t.\"qty\",\n 'name', t.\"name\",\n 'price', t.\"price\"))"
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
/** till, whole, as one statement over its tables (SQLite): its parameters $doc, and its window's, $code. */
|
|
11
|
+
export const query = `SELECT json_object('version', COALESCE((SELECT version FROM documents WHERE name = $doc), 0),
|
|
12
|
+
'orders', json((SELECT json_group_array(json_patch('{}', json_object('id', t.id,
|
|
13
|
+
'customer', t."customer",
|
|
14
|
+
'status', t."status",
|
|
15
|
+
'placed', t."placed",
|
|
16
|
+
'code', t."code",
|
|
17
|
+
'total', t."total")) ORDER BY t.id)
|
|
18
|
+
FROM "orders" t WHERE ($code IS NULL OR t."code" = $code) AND ((t."status" IN ('placed', 'being made', 'ready')) OR t.id IN (SELECT x.id FROM "orders" x WHERE x."status" IN ('collected', 'cancelled') ORDER BY x."placed" DESC, x.id DESC LIMIT 8)))),
|
|
19
|
+
'lines', json((SELECT json_group_array(json_patch('{}', json_object('id', t.id,
|
|
20
|
+
'order', t."order",
|
|
21
|
+
'item', t."item",
|
|
22
|
+
'qty', t."qty",
|
|
23
|
+
'name', t."name",
|
|
24
|
+
'price', t."price")) ORDER BY t.id)
|
|
25
|
+
FROM "lines" t WHERE (t."order" IN (SELECT p.id FROM "orders" p WHERE ($code IS NULL OR p."code" = $code) AND ((p."status" IN ('placed', 'being made', 'ready')) OR p.id IN (SELECT x.id FROM "orders" x WHERE x."status" IN ('collected', 'cancelled') ORDER BY x."placed" DESC, x.id DESC LIMIT 8))))))) AS doc`;
|
|
26
|
+
|
|
27
|
+
/** Its rules over values (definitions' takes, gives and totals), as triggers the store makes in its database: run in
|
|
28
|
+
* each write's transaction, and told as any change is. */
|
|
29
|
+
export const triggers: string[] = [
|
|
30
|
+
"CREATE TEMP TRIGGER IF NOT EXISTS \"joined_takes_lines_while\" AFTER UPDATE OF \"status\" ON main.\"orders\" WHEN (NEW.\"status\" IS NOT 'cancelled') IS NOT (OLD.\"status\" IS NOT 'cancelled') BEGIN UPDATE \"items\" SET \"stock\" = \"stock\" - (CASE WHEN NEW.\"status\" IS NOT 'cancelled' THEN 1 ELSE -1 END) * (SELECT COALESCE(SUM(i.\"qty\"), 0) FROM \"lines\" i WHERE i.\"order\" = NEW.id AND i.\"item\" = \"items\".id) WHERE id IN (SELECT \"item\" FROM \"lines\" WHERE \"order\" = NEW.id); END",
|
|
31
|
+
"CREATE TEMP TRIGGER IF NOT EXISTS \"joined_takes_lines_add\" AFTER INSERT ON main.\"lines\" WHEN (SELECT o.\"status\" FROM \"orders\" o WHERE o.id = NEW.\"order\") IS NOT 'cancelled' BEGIN UPDATE \"items\" SET \"stock\" = \"stock\" - NEW.\"qty\" WHERE id = NEW.\"item\"; END",
|
|
32
|
+
"CREATE TEMP TRIGGER IF NOT EXISTS \"joined_takes_lines_remove\" AFTER DELETE ON main.\"lines\" WHEN (SELECT o.\"status\" FROM \"orders\" o WHERE o.id = OLD.\"order\") IS NOT 'cancelled' BEGIN UPDATE \"items\" SET \"stock\" = \"stock\" + OLD.\"qty\" WHERE id = OLD.\"item\"; END",
|
|
33
|
+
"CREATE TEMP TRIGGER IF NOT EXISTS \"joined_takes_lines_replace\" AFTER UPDATE OF \"qty\", \"item\" ON main.\"lines\" BEGIN UPDATE \"items\" SET \"stock\" = \"stock\" + OLD.\"qty\" WHERE id = OLD.\"item\" AND (SELECT o.\"status\" FROM \"orders\" o WHERE o.id = OLD.\"order\") IS NOT 'cancelled'; UPDATE \"items\" SET \"stock\" = \"stock\" - NEW.\"qty\" WHERE id = NEW.\"item\" AND (SELECT o.\"status\" FROM \"orders\" o WHERE o.id = NEW.\"order\") IS NOT 'cancelled'; END",
|
|
34
|
+
"CREATE TEMP TRIGGER IF NOT EXISTS \"joined_takes_lines_none\" BEFORE UPDATE OF \"stock\" ON main.\"items\" BEGIN SELECT RAISE(ABORT, 'The kitchen has ' || OLD.\"stock\" || ' of ' || OLD.\"name\" || ': not enough to take ' || (OLD.\"stock\" - NEW.\"stock\") || '.') WHERE NEW.\"stock\" < 0; END",
|
|
35
|
+
"CREATE TEMP TRIGGER IF NOT EXISTS \"joined_totals_orders_total_add\" AFTER INSERT ON main.\"lines\" BEGIN UPDATE \"orders\" SET \"total\" = (SELECT COALESCE(SUM(i.\"qty\" * i.\"price\"), 0) FROM \"lines\" i WHERE i.\"order\" = NEW.\"order\") WHERE id = NEW.\"order\"; END",
|
|
36
|
+
"CREATE TEMP TRIGGER IF NOT EXISTS \"joined_totals_orders_total_remove\" AFTER DELETE ON main.\"lines\" BEGIN UPDATE \"orders\" SET \"total\" = (SELECT COALESCE(SUM(i.\"qty\" * i.\"price\"), 0) FROM \"lines\" i WHERE i.\"order\" = OLD.\"order\") WHERE id = OLD.\"order\"; END",
|
|
37
|
+
"CREATE TEMP TRIGGER IF NOT EXISTS \"joined_totals_orders_total_replace\" AFTER UPDATE ON main.\"lines\" BEGIN UPDATE \"orders\" SET \"total\" = (SELECT COALESCE(SUM(i.\"qty\" * i.\"price\"), 0) FROM \"lines\" i WHERE i.\"order\" = OLD.\"order\") WHERE id = OLD.\"order\"; UPDATE \"orders\" SET \"total\" = (SELECT COALESCE(SUM(i.\"qty\" * i.\"price\"), 0) FROM \"lines\" i WHERE i.\"order\" = NEW.\"order\") WHERE id = NEW.\"order\"; END"
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
/** Its items, its query and its triggers, as Postgres says them. */
|
|
41
|
+
export const postgres = {
|
|
42
|
+
"items": {
|
|
43
|
+
"orders": "json_strip_nulls(json_build_object('id', t.id,\n 'customer', t.\"customer\",\n 'status', t.\"status\",\n 'placed', t.\"placed\",\n 'code', t.\"code\",\n 'total', t.\"total\"))",
|
|
44
|
+
"lines": "json_strip_nulls(json_build_object('id', t.id,\n 'order', t.\"order\",\n 'item', t.\"item\",\n 'qty', t.\"qty\",\n 'name', t.\"name\",\n 'price', t.\"price\"))"
|
|
45
|
+
},
|
|
46
|
+
"query": "SELECT json_build_object('version', COALESCE((SELECT version FROM documents WHERE name = $doc), 0),\n 'orders', (SELECT COALESCE(json_agg(json_strip_nulls(json_build_object('id', t.id,\n 'customer', t.\"customer\",\n 'status', t.\"status\",\n 'placed', t.\"placed\",\n 'code', t.\"code\",\n 'total', t.\"total\")) ORDER BY t.id), '[]')\n FROM \"orders\" t WHERE ($code IS NULL OR t.\"code\" = $code) AND ((t.\"status\" IN ('placed', 'being made', 'ready')) OR t.id IN (SELECT x.id FROM \"orders\" x WHERE x.\"status\" IN ('collected', 'cancelled') ORDER BY x.\"placed\" DESC, x.id DESC LIMIT 8))),\n 'lines', (SELECT COALESCE(json_agg(json_strip_nulls(json_build_object('id', t.id,\n 'order', t.\"order\",\n 'item', t.\"item\",\n 'qty', t.\"qty\",\n 'name', t.\"name\",\n 'price', t.\"price\")) ORDER BY t.id), '[]')\n FROM \"lines\" t WHERE (t.\"order\" IN (SELECT p.id FROM \"orders\" p WHERE ($code IS NULL OR p.\"code\" = $code) AND ((p.\"status\" IN ('placed', 'being made', 'ready')) OR p.id IN (SELECT x.id FROM \"orders\" x WHERE x.\"status\" IN ('collected', 'cancelled') ORDER BY x.\"placed\" DESC, x.id DESC LIMIT 8)))))) AS doc",
|
|
47
|
+
"triggers": [
|
|
48
|
+
"CREATE OR REPLACE FUNCTION \"joined_takes_lines_while_fn\"() RETURNS trigger LANGUAGE plpgsql AS $joined$ BEGIN IF (NEW.\"status\" IS DISTINCT FROM 'cancelled') IS DISTINCT FROM (OLD.\"status\" IS DISTINCT FROM 'cancelled') THEN UPDATE \"items\" SET \"stock\" = \"stock\" - (CASE WHEN NEW.\"status\" IS DISTINCT FROM 'cancelled' THEN 1 ELSE -1 END) * (SELECT COALESCE(SUM(i.\"qty\"), 0) FROM \"lines\" i WHERE i.\"order\" = NEW.id AND i.\"item\" = \"items\".id) WHERE id IN (SELECT \"item\" FROM \"lines\" WHERE \"order\" = NEW.id); END IF; IF TG_OP = 'DELETE' THEN RETURN OLD; END IF; RETURN NEW; END $joined$; CREATE OR REPLACE TRIGGER \"joined_takes_lines_while\" AFTER UPDATE OF \"status\" ON \"orders\" FOR EACH ROW EXECUTE FUNCTION \"joined_takes_lines_while_fn\"()",
|
|
49
|
+
"CREATE OR REPLACE FUNCTION \"joined_takes_lines_add_fn\"() RETURNS trigger LANGUAGE plpgsql AS $joined$ BEGIN IF (SELECT o.\"status\" FROM \"orders\" o WHERE o.id = NEW.\"order\") IS DISTINCT FROM 'cancelled' THEN UPDATE \"items\" SET \"stock\" = \"stock\" - NEW.\"qty\" WHERE id = NEW.\"item\"; END IF; IF TG_OP = 'DELETE' THEN RETURN OLD; END IF; RETURN NEW; END $joined$; CREATE OR REPLACE TRIGGER \"joined_takes_lines_add\" AFTER INSERT ON \"lines\" FOR EACH ROW EXECUTE FUNCTION \"joined_takes_lines_add_fn\"()",
|
|
50
|
+
"CREATE OR REPLACE FUNCTION \"joined_takes_lines_remove_fn\"() RETURNS trigger LANGUAGE plpgsql AS $joined$ BEGIN IF (SELECT o.\"status\" FROM \"orders\" o WHERE o.id = OLD.\"order\") IS DISTINCT FROM 'cancelled' THEN UPDATE \"items\" SET \"stock\" = \"stock\" + OLD.\"qty\" WHERE id = OLD.\"item\"; END IF; IF TG_OP = 'DELETE' THEN RETURN OLD; END IF; RETURN NEW; END $joined$; CREATE OR REPLACE TRIGGER \"joined_takes_lines_remove\" AFTER DELETE ON \"lines\" FOR EACH ROW EXECUTE FUNCTION \"joined_takes_lines_remove_fn\"()",
|
|
51
|
+
"CREATE OR REPLACE FUNCTION \"joined_takes_lines_replace_fn\"() RETURNS trigger LANGUAGE plpgsql AS $joined$ BEGIN UPDATE \"items\" SET \"stock\" = \"stock\" + OLD.\"qty\" WHERE id = OLD.\"item\" AND (SELECT o.\"status\" FROM \"orders\" o WHERE o.id = OLD.\"order\") IS DISTINCT FROM 'cancelled'; UPDATE \"items\" SET \"stock\" = \"stock\" - NEW.\"qty\" WHERE id = NEW.\"item\" AND (SELECT o.\"status\" FROM \"orders\" o WHERE o.id = NEW.\"order\") IS DISTINCT FROM 'cancelled'; IF TG_OP = 'DELETE' THEN RETURN OLD; END IF; RETURN NEW; END $joined$; CREATE OR REPLACE TRIGGER \"joined_takes_lines_replace\" AFTER UPDATE OF \"qty\", \"item\" ON \"lines\" FOR EACH ROW EXECUTE FUNCTION \"joined_takes_lines_replace_fn\"()",
|
|
52
|
+
"CREATE OR REPLACE FUNCTION \"joined_takes_lines_none_fn\"() RETURNS trigger LANGUAGE plpgsql AS $joined$ BEGIN IF NEW.\"stock\" < 0 THEN RAISE EXCEPTION '%', 'The kitchen has ' || OLD.\"stock\" || ' of ' || OLD.\"name\" || ': not enough to take ' || (OLD.\"stock\" - NEW.\"stock\") || '.'; END IF; IF TG_OP = 'DELETE' THEN RETURN OLD; END IF; RETURN NEW; END $joined$; CREATE OR REPLACE TRIGGER \"joined_takes_lines_none\" BEFORE UPDATE OF \"stock\" ON \"items\" FOR EACH ROW EXECUTE FUNCTION \"joined_takes_lines_none_fn\"()",
|
|
53
|
+
"CREATE OR REPLACE FUNCTION \"joined_totals_orders_total_add_fn\"() RETURNS trigger LANGUAGE plpgsql AS $joined$ BEGIN UPDATE \"orders\" SET \"total\" = (SELECT COALESCE(SUM(i.\"qty\" * i.\"price\"), 0) FROM \"lines\" i WHERE i.\"order\" = NEW.\"order\") WHERE id = NEW.\"order\"; IF TG_OP = 'DELETE' THEN RETURN OLD; END IF; RETURN NEW; END $joined$; CREATE OR REPLACE TRIGGER \"joined_totals_orders_total_add\" AFTER INSERT ON \"lines\" FOR EACH ROW EXECUTE FUNCTION \"joined_totals_orders_total_add_fn\"()",
|
|
54
|
+
"CREATE OR REPLACE FUNCTION \"joined_totals_orders_total_remove_fn\"() RETURNS trigger LANGUAGE plpgsql AS $joined$ BEGIN UPDATE \"orders\" SET \"total\" = (SELECT COALESCE(SUM(i.\"qty\" * i.\"price\"), 0) FROM \"lines\" i WHERE i.\"order\" = OLD.\"order\") WHERE id = OLD.\"order\"; IF TG_OP = 'DELETE' THEN RETURN OLD; END IF; RETURN NEW; END $joined$; CREATE OR REPLACE TRIGGER \"joined_totals_orders_total_remove\" AFTER DELETE ON \"lines\" FOR EACH ROW EXECUTE FUNCTION \"joined_totals_orders_total_remove_fn\"()",
|
|
55
|
+
"CREATE OR REPLACE FUNCTION \"joined_totals_orders_total_replace_fn\"() RETURNS trigger LANGUAGE plpgsql AS $joined$ BEGIN UPDATE \"orders\" SET \"total\" = (SELECT COALESCE(SUM(i.\"qty\" * i.\"price\"), 0) FROM \"lines\" i WHERE i.\"order\" = OLD.\"order\") WHERE id = OLD.\"order\"; UPDATE \"orders\" SET \"total\" = (SELECT COALESCE(SUM(i.\"qty\" * i.\"price\"), 0) FROM \"lines\" i WHERE i.\"order\" = NEW.\"order\") WHERE id = NEW.\"order\"; IF TG_OP = 'DELETE' THEN RETURN OLD; END IF; RETURN NEW; END $joined$; CREATE OR REPLACE TRIGGER \"joined_totals_orders_total_replace\" AFTER UPDATE ON \"lines\" FOR EACH ROW EXECUTE FUNCTION \"joined_totals_orders_total_replace_fn\"()"
|
|
56
|
+
]
|
|
57
|
+
};
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// Written by src/compile.ts from examples/cafe/stories.jsonl: change the stories, not this.
|
|
2
|
+
|
|
3
|
+
export type Op = { op: "add" | "replace" | "remove"; path: string; value?: any };
|
|
4
|
+
|
|
5
|
+
/** The document, and each collection: its element, the element its items are, their fields, those an add needs, and
|
|
6
|
+
* what each link is to. */
|
|
7
|
+
export const doc = "till";
|
|
8
|
+
export const collections = {
|
|
9
|
+
"orders": {
|
|
10
|
+
"place": "j-orders",
|
|
11
|
+
"tag": "j-order",
|
|
12
|
+
"fields": {
|
|
13
|
+
"customer": "string",
|
|
14
|
+
"status": "string",
|
|
15
|
+
"placed": "instant",
|
|
16
|
+
"code": "string",
|
|
17
|
+
"total": "integer"
|
|
18
|
+
},
|
|
19
|
+
"needs": [
|
|
20
|
+
"customer"
|
|
21
|
+
],
|
|
22
|
+
"links": {},
|
|
23
|
+
"fills": {
|
|
24
|
+
"status": "placed",
|
|
25
|
+
"placed": "now",
|
|
26
|
+
"code": "random",
|
|
27
|
+
"total": 0
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"lines": {
|
|
31
|
+
"place": "j-lines",
|
|
32
|
+
"tag": "j-line",
|
|
33
|
+
"fields": {
|
|
34
|
+
"order": "integer",
|
|
35
|
+
"item": "integer",
|
|
36
|
+
"qty": "integer",
|
|
37
|
+
"name": "string",
|
|
38
|
+
"price": "integer"
|
|
39
|
+
},
|
|
40
|
+
"needs": [
|
|
41
|
+
"order",
|
|
42
|
+
"item",
|
|
43
|
+
"qty"
|
|
44
|
+
],
|
|
45
|
+
"links": {
|
|
46
|
+
"order": "orders",
|
|
47
|
+
"item": "items"
|
|
48
|
+
},
|
|
49
|
+
"copies": {
|
|
50
|
+
"from": "item",
|
|
51
|
+
"fields": [
|
|
52
|
+
"name",
|
|
53
|
+
"price"
|
|
54
|
+
],
|
|
55
|
+
"to": "items",
|
|
56
|
+
"at": "menu"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
} as const;
|
|
60
|
+
/** Whether every story is anonymous, none told as a member: where every app's is, the project has no members. */
|
|
61
|
+
export const anonymous = false;
|
|
62
|
+
/** What kind of document till is, by the flows it uses: static, changed only with a release (a page reads it, and
|
|
63
|
+
* never subscribes); read-only, live, but no page writes it (derived); or shared, its members' to write. */
|
|
64
|
+
export const type = "shared";
|
|
65
|
+
/** It holds only some of its tables' rows (its definitions' where): a change to any of them moves its version,
|
|
66
|
+
* and each page holding it is told what changed of it. */
|
|
67
|
+
export const view = true;
|
|
68
|
+
export const reads = ["lines","orders"];
|
|
69
|
+
/** Who may hold it at all (its where's holds), each a role; null, anyone. */
|
|
70
|
+
export const mayHold = ["till","manager"];
|
|
71
|
+
/** The parts of till a page may hold alone, by its query's parameters (its definitions' window): null, none. */
|
|
72
|
+
export const window = {"orders":{"code":"code"}};
|
|
73
|
+
/** Each field whose value moves only as the stories move it, each step by its roles (its definitions' moves). */
|
|
74
|
+
export const moves = {"orders":"status"};
|
|
75
|
+
/** The field holding an item's own code: a page holding till by it is the item's guest (its definitions' guests). */
|
|
76
|
+
export const guests = {"orders":"code"};
|
|
77
|
+
/** The document as one statement over its tables (generated/till.queries.ts). */
|
|
78
|
+
export { query, postgres, items, triggers } from "./till.queries.ts";
|
|
79
|
+
|
|
80
|
+
/** till is one document. */
|
|
81
|
+
export const kind = null;
|
|
82
|
+
|
|
83
|
+
/** Each grant, read off the stories: the roles whose stories do it (a member: anyone). An op no story
|
|
84
|
+
* does isn't one. */
|
|
85
|
+
export const grants: Record<string, string[]> = {
|
|
86
|
+
"add lines": [
|
|
87
|
+
"till"
|
|
88
|
+
],
|
|
89
|
+
"add orders": [
|
|
90
|
+
"till"
|
|
91
|
+
],
|
|
92
|
+
"replace orders.status:placed>cancelled": [
|
|
93
|
+
"till"
|
|
94
|
+
],
|
|
95
|
+
"replace orders.status:ready>collected": [
|
|
96
|
+
"till"
|
|
97
|
+
]
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/** Who someone is to till (and to an item of it, `at`), beyond a member: each role whose who-path finds them. */
|
|
101
|
+
export function rolesOf(m: number, read: (doc: string) => any, doc: string, at?: any): string[] {
|
|
102
|
+
const item: any = at;
|
|
103
|
+
return [
|
|
104
|
+
(read("staff")["posts"] ?? []).some((i: any) => String(i["role"]) === "manager" && (i["members"] === m || (Array.isArray(i["members"]) && i["members"].includes(m)))) ? "manager" : "",
|
|
105
|
+
(read("staff")["posts"] ?? []).some((i: any) => String(i["role"]) === "till" && (i["members"] === m || (Array.isArray(i["members"]) && i["members"].includes(m)))) ? "till" : "",
|
|
106
|
+
(read("staff")["posts"] ?? []).some((i: any) => String(i["role"]) === "kitchen" && (i["members"] === m || (Array.isArray(i["members"]) && i["members"].includes(m)))) ? "kitchen" : "",
|
|
107
|
+
(item?.["buyer"] === m || (Array.isArray(item?.["buyer"]) && item?.["buyer"].includes(m))) ? "buyer" : "",
|
|
108
|
+
(item?.["supplier"] === m || (Array.isArray(item?.["supplier"]) && item?.["supplier"].includes(m))) ? "supplier" : "",
|
|
109
|
+
].filter(Boolean);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** What someone sees: all of till, as it has no owns. */
|
|
113
|
+
export const sees = null;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<title>joined: the cafe's till</title>
|
|
7
|
+
<link rel="stylesheet" href="joined/tokens.css" />
|
|
8
|
+
<link rel="stylesheet" href="joined/page.css" />
|
|
9
|
+
<link rel="stylesheet" href="../app.css" />
|
|
10
|
+
<link rel="stylesheet" href="./cafe.css" />
|
|
11
|
+
</head>
|
|
12
|
+
<body data-flavour="tangerine">
|
|
13
|
+
<a class="brand" href="/"><img src="joined/icon.png" alt="" width="28" height="28" />joined</a>
|
|
14
|
+
<header class="band">
|
|
15
|
+
<h1>The till</h1>
|
|
16
|
+
<p class="lead">
|
|
17
|
+
Type their name, how many of each, and place it: the cafe prices it, numbers it, and gives it a link for the
|
|
18
|
+
customer. The kitchen sees it at once.
|
|
19
|
+
</p>
|
|
20
|
+
<nav class="bar">
|
|
21
|
+
<members-panel></members-panel>
|
|
22
|
+
<a href="/cafe">The cafe</a> <a href="/cafe/till" data-holds="till" aria-current="page">Till</a>
|
|
23
|
+
<a href="/cafe/menu" data-holds="menu">Menu</a>
|
|
24
|
+
<a href="/cafe/kitchen" data-holds="kitchen">Kitchen</a>
|
|
25
|
+
<a href="/cafe/supplies" data-holds="supplies">Supplies</a>
|
|
26
|
+
<a href="/cafe/books" data-holds="books">Books</a>
|
|
27
|
+
</nav>
|
|
28
|
+
</header>
|
|
29
|
+
<main class="cafe till">
|
|
30
|
+
<section class="card" aria-label="New order">
|
|
31
|
+
<h2>New order</h2>
|
|
32
|
+
<form class="place">
|
|
33
|
+
<j-items doc="menu" aria-label="The menu"></j-items>
|
|
34
|
+
<div class="order" aria-label="The order">
|
|
35
|
+
<label
|
|
36
|
+
>For<input
|
|
37
|
+
name="customer"
|
|
38
|
+
placeholder="Their name"
|
|
39
|
+
aria-label="Their name"
|
|
40
|
+
required
|
|
41
|
+
maxlength="40"
|
|
42
|
+
autocomplete="off"
|
|
43
|
+
/></label>
|
|
44
|
+
<ul class="lines"></ul>
|
|
45
|
+
<p class="total"><span>Total</span><b>£0.00</b></p>
|
|
46
|
+
<button class="act ink" data-icon="check">Place order</button>
|
|
47
|
+
<p class="said" role="status"></p>
|
|
48
|
+
</div>
|
|
49
|
+
</form>
|
|
50
|
+
</section>
|
|
51
|
+
<section class="card board" aria-label="Orders">
|
|
52
|
+
<div class="heads">
|
|
53
|
+
<h2>In the kitchen</h2>
|
|
54
|
+
<h2>Ready to collect</h2>
|
|
55
|
+
<h2>Finished</h2>
|
|
56
|
+
</div>
|
|
57
|
+
<j-orders doc="till"></j-orders>
|
|
58
|
+
<j-lines doc="till"></j-lines>
|
|
59
|
+
</section>
|
|
60
|
+
</main>
|
|
61
|
+
<dialog class="ask">
|
|
62
|
+
<h2></h2>
|
|
63
|
+
<footer>
|
|
64
|
+
<button type="button" class="act" name="keep">Never mind</button>
|
|
65
|
+
<button type="button" class="act danger" name="sure">Cancel it</button>
|
|
66
|
+
</footer>
|
|
67
|
+
</dialog>
|
|
68
|
+
<script type="module" src="./till.ts"></script>
|
|
69
|
+
</body>
|
|
70
|
+
</html>
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/* <kitchen-rail>'s look, adopted in its shadow (with joined's parts): a kitchen's screen, read from across the room,
|
|
2
|
+
in large type. Its colours are the cafe's, as the till's and a customer's order are drawn: a ticket a card in its
|
|
3
|
+
edge, ink words, how long it's waited a tag in the page's flavour (stronger as it's made, outlined when ready,
|
|
4
|
+
filled when late, after ten minutes), and a late ticket edged in the flavour. Light and dark as the device asks. */
|
|
5
|
+
:host {
|
|
6
|
+
display: block;
|
|
7
|
+
}
|
|
8
|
+
/* its columns, by where an order is, side by side where there's room; the one a ticket may go to marked as it's
|
|
9
|
+
held over it */
|
|
10
|
+
.rail {
|
|
11
|
+
display: grid;
|
|
12
|
+
grid-template-columns: repeat(3, minmax(0, 1fr));
|
|
13
|
+
gap: var(--space-12);
|
|
14
|
+
}
|
|
15
|
+
@media (max-width: 40rem) {
|
|
16
|
+
.rail {
|
|
17
|
+
grid-template-columns: minmax(0, 1fr);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
section {
|
|
21
|
+
min-height: 8rem;
|
|
22
|
+
border-radius: 4px;
|
|
23
|
+
}
|
|
24
|
+
section[over] {
|
|
25
|
+
outline: 2px dashed var(--ink);
|
|
26
|
+
outline-offset: 2px;
|
|
27
|
+
}
|
|
28
|
+
h3 {
|
|
29
|
+
margin: 0 0 var(--space-8);
|
|
30
|
+
font: var(--font-label);
|
|
31
|
+
color: var(--muted);
|
|
32
|
+
}
|
|
33
|
+
ol {
|
|
34
|
+
display: grid;
|
|
35
|
+
gap: var(--space-8);
|
|
36
|
+
margin: 0;
|
|
37
|
+
padding: 0;
|
|
38
|
+
list-style: none;
|
|
39
|
+
}
|
|
40
|
+
/* a ticket: who, how long they've waited, large; what to make, one to a line; its one move, the width of it */
|
|
41
|
+
.ticket {
|
|
42
|
+
display: grid;
|
|
43
|
+
gap: var(--space-8);
|
|
44
|
+
padding: var(--space-12);
|
|
45
|
+
border: 1px solid var(--edge);
|
|
46
|
+
border-radius: 4px;
|
|
47
|
+
background: var(--card);
|
|
48
|
+
color: var(--ink);
|
|
49
|
+
}
|
|
50
|
+
.ticket[late] {
|
|
51
|
+
border-color: var(--flavour-deep);
|
|
52
|
+
box-shadow: inset 0 0 0 1px var(--flavour-deep);
|
|
53
|
+
}
|
|
54
|
+
.head {
|
|
55
|
+
display: flex;
|
|
56
|
+
justify-content: space-between;
|
|
57
|
+
align-items: baseline;
|
|
58
|
+
gap: var(--space-8);
|
|
59
|
+
margin: 0;
|
|
60
|
+
}
|
|
61
|
+
.head b {
|
|
62
|
+
font: var(--font-heading);
|
|
63
|
+
}
|
|
64
|
+
.wait {
|
|
65
|
+
padding: 0 var(--space-8);
|
|
66
|
+
border-radius: 99px;
|
|
67
|
+
background: var(--flavour-tint);
|
|
68
|
+
color: var(--flavour-ink);
|
|
69
|
+
font: var(--font-heading);
|
|
70
|
+
white-space: nowrap;
|
|
71
|
+
}
|
|
72
|
+
.ticket[data-status="being made"] .wait {
|
|
73
|
+
background: color-mix(in srgb, var(--flavour) 24%, transparent);
|
|
74
|
+
}
|
|
75
|
+
.ticket[data-status="ready"] .wait {
|
|
76
|
+
background: none;
|
|
77
|
+
box-shadow: inset 0 0 0 1px var(--flavour-deep);
|
|
78
|
+
}
|
|
79
|
+
.ticket[late] .wait {
|
|
80
|
+
background: var(--flavour-solid);
|
|
81
|
+
color: var(--on-flavour);
|
|
82
|
+
}
|
|
83
|
+
ul {
|
|
84
|
+
margin: 0;
|
|
85
|
+
padding: 0;
|
|
86
|
+
list-style: none;
|
|
87
|
+
font: var(--font-heading);
|
|
88
|
+
font-weight: 400;
|
|
89
|
+
}
|
|
90
|
+
.acts {
|
|
91
|
+
margin: 0;
|
|
92
|
+
}
|
|
93
|
+
.acts .act {
|
|
94
|
+
width: 100%;
|
|
95
|
+
justify-content: center;
|
|
96
|
+
min-height: 44px;
|
|
97
|
+
}
|
|
98
|
+
/* a ticket picked up: over the rest, following the pointer */
|
|
99
|
+
.ticket[dragged] {
|
|
100
|
+
position: relative;
|
|
101
|
+
z-index: 1;
|
|
102
|
+
cursor: grabbing;
|
|
103
|
+
}
|
|
104
|
+
.said:not(:empty) {
|
|
105
|
+
margin: 0;
|
|
106
|
+
color: var(--danger);
|
|
107
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<title>joined: the cafe's kitchen</title>
|
|
7
|
+
<link rel="stylesheet" href="joined/tokens.css" />
|
|
8
|
+
<link rel="stylesheet" href="joined/page.css" />
|
|
9
|
+
<link rel="stylesheet" href="../app.css" />
|
|
10
|
+
<link rel="stylesheet" href="./cafe.css" />
|
|
11
|
+
</head>
|
|
12
|
+
<body data-flavour="strawberry">
|
|
13
|
+
<a class="brand" href="/"><img src="joined/icon.png" alt="" width="28" height="28" />joined</a>
|
|
14
|
+
<header class="band">
|
|
15
|
+
<h1>The kitchen</h1>
|
|
16
|
+
<p class="lead">
|
|
17
|
+
The tickets, oldest first, each with how long it's waited: late after ten minutes. Start one, then mark it ready
|
|
18
|
+
(or drag it to the next column), where it waits until the till hands it over.
|
|
19
|
+
</p>
|
|
20
|
+
<nav class="bar">
|
|
21
|
+
<members-panel></members-panel>
|
|
22
|
+
<a href="/cafe">The cafe</a> <a href="/cafe/till" data-holds="till">Till</a>
|
|
23
|
+
<a href="/cafe/menu" data-holds="menu">Menu</a>
|
|
24
|
+
<a href="/cafe/kitchen" data-holds="kitchen" aria-current="page">Kitchen</a>
|
|
25
|
+
<a href="/cafe/supplies" data-holds="supplies">Supplies</a>
|
|
26
|
+
<a href="/cafe/books" data-holds="books">Books</a>
|
|
27
|
+
</nav>
|
|
28
|
+
</header>
|
|
29
|
+
<main class="cafe kitchen">
|
|
30
|
+
<section class="card rail" aria-label="Tickets">
|
|
31
|
+
<kitchen-rail>
|
|
32
|
+
<j-orders doc="kitchen"></j-orders>
|
|
33
|
+
<j-lines doc="kitchen"></j-lines>
|
|
34
|
+
</kitchen-rail>
|
|
35
|
+
</section>
|
|
36
|
+
</main>
|
|
37
|
+
<script type="module" src="./kitchen.ts"></script>
|
|
38
|
+
</body>
|
|
39
|
+
</html>
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// The kitchen's page: its rail, <kitchen-rail>, a display. It holds the kitchen's document (its orders placed, being
|
|
2
|
+
// made or ready, and their lines: <j-orders> and <j-lines>) and never shows it: it watches them and draws a ticket for
|
|
3
|
+
// each order in its shadow, in a column for where it is, oldest first, with its lines, how long it's waited (late
|
|
4
|
+
// after ten minutes, until it's ready) and the move the kitchen makes next, Start and then Ready, where its person
|
|
5
|
+
// may (the order's may): its button, or the ticket dragged to the next column (./rail-drag.ts). Ready, it waits there
|
|
6
|
+
// until the till hands it over, and leaves the kitchen's document, and its ticket the rail. A change makes again only
|
|
7
|
+
// the tickets whose orders it changed (keep); each minute the waits are said again. It's the smallest display to
|
|
8
|
+
// copy: the trip's calendar (../trip/calendar-map.ts) is the same, grown.
|
|
9
|
+
|
|
10
|
+
import "joined/panel";
|
|
11
|
+
import "joined/toast";
|
|
12
|
+
import { keep, type Row } from "joined/keep";
|
|
13
|
+
import { PARTS, said } from "joined/parts";
|
|
14
|
+
import * as kitchen from "./generated/kitchen.rules.ts";
|
|
15
|
+
import { JLine, JOrder } from "./generated/kitchen.elements.ts";
|
|
16
|
+
import { dragged } from "./rail-drag.ts";
|
|
17
|
+
import { waitedSince, waitOf } from "./views.ts";
|
|
18
|
+
import STYLE from "./kitchen.css" with { type: "text" };
|
|
19
|
+
|
|
20
|
+
// its look, one sheet shared by every rail on the page
|
|
21
|
+
const SHEET = new CSSStyleSheet();
|
|
22
|
+
SHEET.replaceSync(STYLE);
|
|
23
|
+
/** The move the kitchen makes on an order where it is: its words, and the status it's to. */
|
|
24
|
+
const NEXT: Record<string, { words: string; to: string }> = {
|
|
25
|
+
placed: { words: "Start", to: "being made" },
|
|
26
|
+
"being made": { words: "Ready", to: "ready" },
|
|
27
|
+
};
|
|
28
|
+
/** The rail's columns, by where an order is. */
|
|
29
|
+
const COLUMNS = { placed: "Placed", "being made": "Being made", ready: "Ready" };
|
|
30
|
+
|
|
31
|
+
class KitchenRail extends HTMLElement {
|
|
32
|
+
#root = this.attachShadow({ mode: "open" });
|
|
33
|
+
#rail = Object.assign(document.createElement("div"), { className: "rail" });
|
|
34
|
+
/** Each column, by where its orders are: its section, its list, and the tickets kept in it. */
|
|
35
|
+
#columns = new Map(
|
|
36
|
+
Object.entries(COLUMNS).map(([status, words]) => {
|
|
37
|
+
const section = Object.assign(document.createElement("section"), { ariaLabel: words }),
|
|
38
|
+
list = document.createElement("ol");
|
|
39
|
+
section.append(Object.assign(document.createElement("h3"), { textContent: words }), list);
|
|
40
|
+
this.#rail.append(section);
|
|
41
|
+
return [status, { section, list, kept: new Map<string, { shows: string; el: HTMLElement }>() }];
|
|
42
|
+
}),
|
|
43
|
+
);
|
|
44
|
+
// what it holds, live lists: read as they are on each change, never searched for
|
|
45
|
+
#orders = this.getElementsByTagName(kitchen.collections.orders.tag) as HTMLCollectionOf<JOrder>;
|
|
46
|
+
#lines = this.getElementsByTagName(kitchen.collections.lines.tag) as HTMLCollectionOf<JLine>;
|
|
47
|
+
#watching = new MutationObserver(() => this.#draw());
|
|
48
|
+
#ticking?: ReturnType<typeof setInterval>;
|
|
49
|
+
// on the page, it watches what it holds and the clock; off it, neither
|
|
50
|
+
connectedCallback() {
|
|
51
|
+
if (!this.#rail.parentNode) ((this.#root.adoptedStyleSheets = [PARTS, SHEET]), this.#root.append(this.#rail));
|
|
52
|
+
this.#watching.observe(this, { subtree: true, childList: true, attributes: true });
|
|
53
|
+
this.#ticking = setInterval(() => this.#draw(), 60_000);
|
|
54
|
+
this.#draw();
|
|
55
|
+
}
|
|
56
|
+
disconnectedCallback() {
|
|
57
|
+
this.#watching.disconnect();
|
|
58
|
+
clearInterval(this.#ticking);
|
|
59
|
+
}
|
|
60
|
+
/** Its tickets, each in its column in the order the document has them, made again only when what it shows has
|
|
61
|
+
* changed. */
|
|
62
|
+
#draw() {
|
|
63
|
+
const lines = new Map<number, string[]>();
|
|
64
|
+
for (const l of this.#lines)
|
|
65
|
+
(lines.get(l.data.order) ?? lines.set(l.data.order, []).get(l.data.order)!).push(
|
|
66
|
+
`${l.data.qty} × ${l.data.name}`,
|
|
67
|
+
);
|
|
68
|
+
for (const [status, { list, kept }] of this.#columns)
|
|
69
|
+
keep(
|
|
70
|
+
list,
|
|
71
|
+
kept,
|
|
72
|
+
[...this.#orders].filter((o) => o.data.status === status).map((o) => this.#ticket(o, lines.get(o.key) ?? [])),
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
/** An order's ticket: its number and customer, its total, where it is and how long it's waited, its lines, and
|
|
76
|
+
* its next move, where its person may make it. */
|
|
77
|
+
#ticket(order: JOrder, lines: string[]): Row {
|
|
78
|
+
const { customer, status = "", placed = "" } = order.data,
|
|
79
|
+
waited = waitedSince(placed),
|
|
80
|
+
next = NEXT[status],
|
|
81
|
+
may = !!next && order.matches(`[may~="replace:status>${encodeURIComponent(next.to)}"]`);
|
|
82
|
+
return {
|
|
83
|
+
key: String(order.key),
|
|
84
|
+
shows: JSON.stringify([customer, status, waited, lines, may]),
|
|
85
|
+
make: () => {
|
|
86
|
+
const ticket = Object.assign(document.createElement("li"), { className: "ticket" });
|
|
87
|
+
ticket.dataset.status = status;
|
|
88
|
+
ticket.toggleAttribute("late", status !== "ready" && waited >= 10);
|
|
89
|
+
const head = Object.assign(document.createElement("p"), { className: "head" }),
|
|
90
|
+
acts = Object.assign(document.createElement("p"), { className: "acts" }),
|
|
91
|
+
why = Object.assign(document.createElement("p"), { className: "said", role: "status" });
|
|
92
|
+
// read from across the room: who, and how long they've waited, large; its column says where it is
|
|
93
|
+
head.append(
|
|
94
|
+
Object.assign(document.createElement("b"), { textContent: `#${order.key} ${customer}` }),
|
|
95
|
+
Object.assign(document.createElement("span"), { className: "wait", textContent: waitOf(waited) }),
|
|
96
|
+
);
|
|
97
|
+
const list = document.createElement("ul");
|
|
98
|
+
list.append(...lines.map((words) => Object.assign(document.createElement("li"), { textContent: words })));
|
|
99
|
+
if (may) {
|
|
100
|
+
const go = Object.assign(document.createElement("button"), {
|
|
101
|
+
type: "button",
|
|
102
|
+
className: "act ink",
|
|
103
|
+
textContent: next!.words,
|
|
104
|
+
ariaLabel: `${next!.words} #${order.key} ${customer}`,
|
|
105
|
+
});
|
|
106
|
+
const move = () => said(why, order.replace({ status: next!.to }));
|
|
107
|
+
go.addEventListener("click", move);
|
|
108
|
+
acts.append(go);
|
|
109
|
+
// or dragged to the next column: pressed anywhere on it but its button
|
|
110
|
+
ticket.addEventListener("pointerdown", (e) => {
|
|
111
|
+
if (!(e.target as Element).closest("button"))
|
|
112
|
+
dragged(e, ticket, this.#columns.get(next!.to)!.section, move);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
ticket.append(head, list, acts, why);
|
|
116
|
+
return ticket;
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// defined last, once all they draw with is made: the document's elements, then the rail that draws them
|
|
123
|
+
customElements.define(kitchen.collections.orders.tag, JOrder);
|
|
124
|
+
customElements.define(kitchen.collections.lines.tag, JLine);
|
|
125
|
+
customElements.define("kitchen-rail", KitchenRail);
|