ShtukbaseStandard
包文件→ .shtukbase/packages/lenses/kit/templates/overview.html

kit/templates/overview.html

181 行, 12.0 KB.

文件按包中的原样显示:代码及其注释不做翻译。

  1. <!--
  2. ---
  3. type: Lens
  4. title: {{title}}
  5. icon: {{icon}}
  6. description: {{description}}
  7. lensType: report
  8. render: live
  9. sources: {{sources}}
  10. generator: {{generator}}
  11. template: custom
  12. layer: {{layer}}
  13. data: {{data}}
  14. ---
  15. A layer overview from one template: how many records are in each collection, how many in each state
  16. of the layer's contours, what is stuck longer than the norm `maxDays`, open questions and the owner's gates for the layer.
  17. The shell is placed by the generator from templates/overview.html of the shtukbase-html-lenses kit; do not edit by hand.
  18. -->
  19. <!doctype html>
  20. <html lang="en">
  21. <head>
  22. <meta charset="utf-8">
  23. <meta name="viewport" content="width=device-width, initial-scale=1">
  24. <title>Layer overview</title>
  25. <link rel="stylesheet" href="{{lib}}/kit.css">
  26. <style>
  27. :root {
  28. --bg: #ffffff; --bg2: #f9f8f7; --lx-card: #ffffff; --ink: #2c2c2b; --lx-muted: #7d7a75; --faint: #a19e99;
  29. --line: #e6e5e3; --line2: #d4d3cf; --wash: rgba(33,27,23,.05); --lx-accent: #2783de; --lx-radius: 8px;
  30. --shadow: 0 0 0 1px rgba(15,15,15,.07), 0 1px 2px rgba(15,15,15,.06);
  31. --c-default: #8e8b87; --cb-default: rgba(42,28,0,.07); --cf-default: #494846; --ct-default: #f9f8f8;
  32. --c-gray: #8e8b87; --cb-gray: rgba(28,19,1,.11); --cf-gray: #494846; --ct-gray: #f2f2f1;
  33. --c-brown: #9f6b53; --cb-brown: rgba(127,51,0,.157); --cf-brown: #584437; --ct-brown: #f7f1ee;
  34. --c-orange: #d9730d; --cb-orange: rgba(196,88,0,.204); --cf-orange: #6a4222; --ct-orange: #fdf0e7;
  35. --c-yellow: #cb912f; --cb-yellow: rgba(209,156,0,.282); --cf-yellow: #655121; --ct-yellow: #fef6e6;
  36. --c-green: #448361; --cb-green: rgba(0,96,38,.157); --cf-green: #2a533c; --ct-green: #eff7ef;
  37. --c-blue: #337ea9; --cb-blue: rgba(0,118,217,.204); --cf-blue: #264a72; --ct-blue: #ebf3f8;
  38. --c-purple: #9065b0; --cb-purple: rgba(92,0,163,.14); --cf-purple: #553b69; --ct-purple: #f5f0f7;
  39. --c-pink: #c14c8a; --cb-pink: rgba(183,0,78,.153); --cf-pink: #68354e; --ct-pink: #fbf1f5;
  40. --c-red: #d44c47; --cb-red: rgba(206,24,0,.165); --cf-red: #6d3531; --ct-red: #fff2f0;
  41. --c-teal: #2b8a85; --cb-teal: rgba(0,128,120,.15); --cf-teal: #22524f; --ct-teal: #ecf6f5;
  42. font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  43. }
  44. * { box-sizing: border-box; }
  45. html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
  46. body { font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
  47. a { color: inherit; }
  48. * { box-sizing: border-box; }
  49. html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
  50. body { font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
  51. a { color: inherit; }
  52. .ov { max-width: 1180px; margin: 0 auto; padding: 18px 24px 40px; }
  53. .ov h1 { font-size: 26px; font-weight: 700; margin: 4px 0 2px; display: flex; gap: 10px; align-items: center; }
  54. .ov .sub { color: var(--lx-muted); font-size: 13px; display: flex; gap: 14px; flex-wrap: wrap; }
  55. .ov .sub a { color: var(--lx-accent); text-decoration: none; } .ov .sub a:hover { text-decoration: underline; }
  56. .ov h2 { font-size: 15px; font-weight: 600; margin: 26px 0 10px; display: flex; gap: 8px; align-items: baseline; }
  57. .ov h2 .n { color: var(--lx-muted); font-weight: 400; }
  58. .tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; }
  59. .tile { display: block; background: var(--lx-card); border-radius: var(--lx-radius); box-shadow: var(--shadow); padding: 9px 11px; text-decoration: none; }
  60. .tile:hover { background: color-mix(in srgb, var(--lx-card) 94%, var(--ink)); }
  61. .tile .t { font-size: 13px; color: var(--lx-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  62. .tile .v { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
  63. .ctr { display: grid; grid-template-columns: minmax(220px, 280px) 60px 1fr; gap: 6px 14px; align-items: center; }
  64. .ctr .nm a { text-decoration: none; font-weight: 500; } .ctr .nm a:hover { text-decoration: underline; }
  65. .ctr .tot { text-align: right; color: var(--lx-muted); font-variant-numeric: tabular-nums; }
  66. .bar { display: flex; height: 22px; border-radius: 5px; overflow: hidden; background: var(--bg2); }
  67. .bar span { background: var(--cc, var(--c-default)); min-width: 3px; }
  68. .legend { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 12px; color: var(--lx-muted); grid-column: 3; margin: -2px 0 8px; }
  69. .legend i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--cc); margin-right: 4px; }
  70. .legend b { color: var(--ink); font-weight: 500; }
  71. .legend .over { color: var(--c-red); }
  72. .list { display: flex; flex-direction: column; gap: 4px; }
  73. .row { display: flex; gap: 8px; align-items: center; background: var(--lx-card); box-shadow: var(--shadow); border-radius: var(--lx-radius); padding: 6px 10px; text-decoration: none; }
  74. .row:hover { background: color-mix(in srgb, var(--lx-card) 94%, var(--ink)); }
  75. .row .t { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  76. .row .m { color: var(--lx-muted); font-size: 12px; white-space: nowrap; }
  77. .row.stuck .m.age { color: var(--c-red); font-weight: 600; }
  78. .cx-chip { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; line-height: 20px; height: 20px; padding: 0 7px; border-radius: 10px; white-space: nowrap;
  79. background: var(--cb, var(--cb-default)); color: var(--cf, var(--cf-default)); flex-shrink: 0; }
  80. .cx-chip.dot::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--cc, var(--c-default)); }
  81. .cols2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 24px; }
  82. .cols2 > div { min-width: 0; }
  83. @media (max-width: 900px) { .cols2 { grid-template-columns: minmax(0, 1fr); } .ctr { grid-template-columns: 1fr 50px; } .ctr .bar, .legend { grid-column: 1 / -1; } }
  84. .empty { color: var(--faint); font-size: 13px; }
  85. .cx-missing { padding: 24px; color: var(--lx-muted); max-width: 640px; }
  86. .cx-missing code { background: var(--bg2); padding: 1px 4px; border-radius: 4px; font-size: 12px; }
  87. </style>
  88. <script>window.LENS_MANUAL = true;</script>
  89. <script src="{{lib}}/data.js"></script>
  90. <script src="{{lib}}/kit.js"></script>
  91. <script src="{{libLayer}}/overview.data.js"></script>
  92. </head>
  93. <body>
  94. <div class="ov" id="app"></div>
  95. <script>
  96. (function () {
  97. "use strict";
  98. const ROOT = "../"; // the root of the base from /<layer>/overview.html
  99. const app = document.getElementById("app");
  100. const O = (window.SHTUKS_LAYER || {}).overview;
  101. const COLORS = ["default", "gray", "brown", "orange", "yellow", "green", "blue", "purple", "pink", "red", "teal"];
  102. const tone = (c) => { c = COLORS.includes(c) ? c : "default"; return `--cc:var(--c-${c});--cb:var(--cb-${c});--cf:var(--cf-${c})`; };
  103. function h(tag, attrs, ...kids) {
  104. const e = document.createElement(tag);
  105. for (const [k, v] of Object.entries(attrs || {})) {
  106. if (v == null || v === false) continue;
  107. if (k.startsWith("on")) e.addEventListener(k.slice(2), v);
  108. else e.setAttribute(k, v === true ? "" : v);
  109. }
  110. for (const k of kids.flat(Infinity)) if (k != null && k !== false) e.append(k.nodeType ? k : String(k));
  111. return e;
  112. }
  113. const hasKit = () => !!(window.SHTUKS && window.Lens && Lens.open);
  114. const recLink = (id, cls, kids) => h("a", { class: cls, href: ROOT + encodeURI(id.replace(/^\//, "")), onclick: (e) => {
  115. if (hasKit() && window.SHTUKS.records[id] && !e.metaKey && !e.ctrlKey) { e.preventDefault(); Lens.open(id); }
  116. } }, kids);
  117. const plural = (n, a, b) => (n === 1 ? a : b);
  118. const IMPORTANCE = { critical: "important", normal: "medium", minor: "minor" }; // captions from the Questions schema
  119. const dd = (n) => n + " " + plural(n, "day", "days");
  120. if (!O) {
  121. app.append(h("div", { class: "cx-missing" }, h("h2", {}, "No overview data"),
  122. h("p", {}, "The lens reads ", h("code", {}, "lib/<layer>/overview.data.js"), ". Build it: ", h("code", {}, "build_overview_data.py --layer <layer>"))));
  123. return;
  124. }
  125. document.title = "Layer overview \"" + O.title + "\"";
  126. const now = Date.now() / 1000;
  127. const stuck = [];
  128. for (const c of O.contours) for (const s of c.stuck) {
  129. const d = Math.floor((now - s.since) / 86400);
  130. if (d > s.maxDays) stuck.push({ ...s, days: d, contour: c.title });
  131. }
  132. stuck.sort((a, b) => b.days - b.maxDays - (a.days - a.maxDays));
  133. const total = O.collections.reduce((a, c) => a + c.count, 0);
  134. const sub = h("div", { class: "sub" },
  135. h("span", {}, "Records: ", h("b", {}, total)), h("span", {}, "Contours: ", h("b", {}, O.contours.length)),
  136. h("span", {}, "Stuck: ", h("b", {}, stuck.length)), h("span", {}, "Open questions: ", h("b", {}, O.questions.length)),
  137. h("span", {}, "Owner gates: ", h("b", {}, O.gates.length)),
  138. O.ontology ? h("a", { href: O.ontology }, "Layer links →") : null,
  139. h("a", { href: ROOT + encodeURI(O.layer) + ".md" }, "Layer page →"));
  140. app.append(h("h1", {}, h("span", {}, O.icon || "🧭"), O.title), sub);
  141. app.append(h("h2", {}, "Collections", h("span", { class: "n" }, O.collections.length)),
  142. h("div", { class: "tiles" }, O.collections.map((c) => recLink(c.id, "tile", [h("div", { class: "t", title: c.id }, (c.icon ? c.icon + " " : "") + c.title), h("div", { class: "v" }, c.count)]))));
  143. const ctr = h("div", { class: "ctr" });
  144. for (const c of O.contours) {
  145. const bar = h("div", { class: "bar" });
  146. const legend = h("div", { class: "legend" });
  147. const over = {};
  148. for (const s of stuck) if (s.contour === c.title) over[s.state] = (over[s.state] || 0) + 1;
  149. for (const s of c.states) {
  150. if (s.count) bar.append(h("span", { style: tone(s.color) + ";flex:" + s.count, title: s.title + ": " + s.count }));
  151. legend.append(h("span", { style: tone(s.color) }, h("i", {}), s.title + " ", h("b", {}, s.count),
  152. s.maxDays != null ? " · norm " + dd(s.maxDays) : "", over[s.title] ? h("span", { class: "over" }, " · over the norm " + over[s.title]) : ""));
  153. }
  154. ctr.append(h("div", { class: "nm" }, h("a", { href: c.lens }, (c.icon || "🔁") + " " + c.title), c.cross ? " (cross-cutting)" : ""),
  155. h("div", { class: "tot" }, c.total), bar, h("div"), h("div"), legend);
  156. }
  157. app.append(h("h2", {}, "Contours", h("span", { class: "n" }, O.contours.length)), O.contours.length ? ctr : h("div", { class: "empty" }, "No contours"));
  158. app.append(h("h2", {}, "Stuck longer than the norm", h("span", { class: "n" }, stuck.length)),
  159. stuck.length ? h("div", { class: "list" }, stuck.map((s) => recLink(s.id, "row stuck", [
  160. h("span", { class: "cx-chip dot", style: tone(s.color) }, s.state), h("span", { class: "t" }, s.title),
  161. h("span", { class: "m" }, s.contour), h("span", { class: "m age" }, dd(s.days) + " / norm " + s.maxDays)])))
  162. : h("div", { class: "empty" }, O.contours.some((c) => c.states.some((s) => s.maxDays != null)) ? "Nothing is stuck." : "The states of the layer have no maxDays norms, so being stuck is not counted."));
  163. const qList = O.questions.map((q) => recLink(q.id, "row", [h("span", { class: "cx-chip dot", style: tone(q.color) }, q.status),
  164. h("span", { class: "t", title: q.title }, q.title),
  165. q.importance ? h("span", { class: "m" }, IMPORTANCE[q.importance] || q.importance) : null, q.due ? h("span", { class: "m" }, "by " + q.due) : null]));
  166. const gList = O.gates.map((g) => recLink(g.id, "row", [h("span", { class: "cx-chip dot", style: tone(g.color) }, g.status),
  167. h("span", { class: "t", title: g.title }, g.title),
  168. g.priority ? h("span", { class: "m" }, g.priority) : null, g.who ? h("span", { class: "m" }, g.who) : null, g.due ? h("span", { class: "m" }, "until " + g.due) : null]));
  169. app.append(h("div", { class: "cols2" },
  170. h("div", {}, h("h2", {}, "Open questions", h("span", { class: "n" }, qList.length)), qList.length ? h("div", { class: "list" }, qList) : h("div", { class: "empty" }, "The layer has no open questions.")),
  171. h("div", {}, h("h2", {}, "Owner gates", h("span", { class: "n" }, gList.length)), gList.length ? h("div", { class: "list" }, gList) : h("div", { class: "empty" }, "The layer has no owner tasks."))));
  172. const id = decodeURI(location.hash.slice(1));
  173. if (id && hasKit() && window.SHTUKS.records[id]) Lens.open(id);
  174. })();
  175. </script>
  176. </body>
  177. </html>