code wiki / _hdl_build / nx_shopping.nx
nx_shopping.nx source
↩ module page · 43 lines · 3103 B
1// nx_shopping.nx -- LIB: renders a sovereign no-JS SHOPPING LIST from the inventory's low-stock items (qty
2// below par). The supply-chain management output: after meals deplete the pantry, this is what to buy and how
3// much. Boundary-escaped names. Another consumer of the universal inventory. license_tier: ORIGINAL
4import "nx_inventory.nx"
5import "nx_syscalls.nx"
6
7func sh_render_list(prefix: *u8, domain: *u8, title: *u8, out: *u8) -> i64 {
8 var o: i64 = 0
9 o = as_append(out, o, "<!doctype html><html lang='en'><head><meta charset='utf-8'><meta name='viewport' content='width=device-width,initial-scale=1'><title>Shopping list</title><style>body{margin:0;font-family:system-ui,sans-serif;color:#16202e;background:#f3f7f4;line-height:1.5}.card{max-width:560px;margin:0 auto;padding:24px 22px}header{background:#1f7a44;color:#fff;padding:22px;border-radius:0 0 12px 12px}header h1{margin:0;font-size:1.4rem}h2{font-size:1.05rem;color:#1f7a44;margin:20px 0 8px}table{border-collapse:collapse;width:100%;background:#fff;border-radius:10px;overflow:hidden;box-shadow:0 1px 0 #d9e4dd}th{text-align:left;background:#e7f1ea;padding:8px 12px;color:#33503f}td{padding:8px 12px;border-top:1px solid #eef3f0}td.q{font-weight:700;white-space:nowrap}.empty{background:#fff;border-radius:10px;padding:18px;text-align:center;color:#4a6a57}.ftr{margin-top:22px;color:#7a8a80;font-size:.82rem;text-align:center}</style></head><body><header><h1>" as *u8)
10 o = as_append_escaped(out, o, title, as_len(title))
11 o = as_append(out, o, "</h1></header><div class='card'>" as *u8)
12
13 let ids: *i64 = sys_mmap(8 * 256) as *i64
14 let need: *i64 = sys_mmap(8 * 256) as *i64
15 let n: i64 = iv_low_stock(prefix, domain, ids, need)
16
17 o = as_append(out, o, "<h2>Buy " as *u8)
18 o = iv_num(out, o, n)
19 o = as_append(out, o, " item(s)</h2>" as *u8)
20 if n == 0 {
21 o = as_append(out, o, "<div class='empty'>Everything is stocked — nothing to buy.</div>" as *u8)
22 } else {
23 o = as_append(out, o, "<table><tr><th>Item</th><th>Buy</th><th>Aisle</th></tr>" as *u8)
24 let f: *u8 = sys_mmap(128)
25 var i: i64 = 0
26 while i < n {
27 o = as_append(out, o, "<tr><td>" as *u8)
28 iv_field_of(prefix, domain, ids[i] as *u8, 0, f); o = as_append_escaped(out, o, f, as_len(f)) // name
29 o = as_append(out, o, "</td><td class='q'>" as *u8)
30 o = iv_num(out, o, need[i])
31 o = as_append(out, o, " " as *u8)
32 iv_field_of(prefix, domain, ids[i] as *u8, 3, f); o = as_append_escaped(out, o, f, as_len(f)) // unit
33 o = as_append(out, o, "</td><td>" as *u8)
34 iv_field_of(prefix, domain, ids[i] as *u8, 1, f); o = as_append_escaped(out, o, f, as_len(f)) // category/aisle
35 o = as_append(out, o, "</td></tr>" as *u8)
36 i = i + 1
37 }
38 o = as_append(out, o, "</table>" as *u8)
39 }
40 o = as_append(out, o, "<p class='ftr'>Generated by the Nishi inventory engine — sovereign, no tracking.</p></div></body></html>" as *u8)
41 out[o] = 0 as u8
42 return o
43}