Add lawyer's summary print: records with lawyer-level fields only (Fixes #30)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
23
src/app.js
23
src/app.js
@@ -828,6 +828,26 @@
|
||||
r.notes ? h('p', { class: 'pnotes' }, r.notes) : null);
|
||||
}
|
||||
|
||||
// The lawyer's summary: just the records with lawyer-level fields, as one compact list.
|
||||
function printSummary(doc) {
|
||||
const groups = summaryGroups(doc);
|
||||
const list = groups.length ? groups.map((s) => h('section', { class: 'psumsec' },
|
||||
h('h2', {}, s.section),
|
||||
s.groups.map((g) => [g.title == null ? null : h('h3', { class: 'psubhead' }, g.title),
|
||||
g.records.map((r) => h('div', { class: 'prec' }, h('h3', {}, r.title),
|
||||
h('table', {}, h('tbody', {}, r.fields.map((f) => h('tr', {}, h('th', {}, f.label), h('td', { class: 'psecret' }, f.value || '(not set)')))))))])))
|
||||
: h('p', {}, 'Nothing to list: no record has a lawyer-level field.');
|
||||
printRoot.replaceChildren(h('table', { class: 'ptable' },
|
||||
h('thead', {}, h('tr', {}, h('td', {}, headerEl(doc)))),
|
||||
h('tbody', {}, h('tr', {}, h('td', {},
|
||||
h('section', { class: 'pcover psumcover' },
|
||||
h('h1', {}, (doc.meta.title || 'Final Wishes') + ": lawyer's summary"),
|
||||
doc.meta.owner ? h('p', { class: 'powner' }, 'Prepared by ' + doc.meta.owner) : null,
|
||||
h('p', {}, 'Last update: ' + doc.meta.lastUpdated),
|
||||
h('p', { class: 'pnote warn' }, "This is the LAWYER'S SUMMARY. It lists only the accounts and details a lawyer needs, in clear text. Keep it locked away.")),
|
||||
list)))));
|
||||
}
|
||||
|
||||
function printItem(it, numbered) {
|
||||
return h('li', { class: 'pitem ' + it.status },
|
||||
box(it.status), h('strong', {}, it.text), it.status === 'tbd' ? h('span', { class: 'ptag' }, 'TBD') : null,
|
||||
@@ -836,6 +856,7 @@
|
||||
|
||||
function buildPrintDoc(rawMode) {
|
||||
const mode = normalizeMode(rawMode);
|
||||
if (mode === 'summary') return printSummary(state.doc);
|
||||
const doc = state.doc;
|
||||
const kept = mode === 'complete' ? 'This copy INCLUDES passwords, PINs and other secrets. Keep it locked away (fire safe or sealed envelope).'
|
||||
: mode === 'lawyer' ? "This is the LAWYER'S VIEW. It includes account numbers and other details a lawyer needs, but the most private secrets (passwords, PINs, balances) are WITHHELD. Keep it locked away."
|
||||
@@ -867,12 +888,14 @@
|
||||
|
||||
function openPrintDialog() {
|
||||
const n = countByLevel(state.doc);
|
||||
const sum = summaryCounts(state.doc);
|
||||
const plural = (c) => c + ' secret value' + (c === 1 ? '' : 's');
|
||||
const radio = (value, checked, text) => h('label', { class: 'radio' }, h('input', { type: 'radio', name: 'mode', value, checked }), ' ' + text);
|
||||
const dlg = h('dialog', { class: 'card', 'aria-label': 'Print options' },
|
||||
h('h3', {}, 'Print'),
|
||||
radio('masked', true, 'Withhold secrets (safe overview; ' + plural(n.lawyer + n.secret) + ' hidden)'),
|
||||
radio('lawyer', false, "Lawyer's view (shows " + n.lawyer + ' lawyer-level value' + (n.lawyer === 1 ? '' : 's') + '; ' + plural(n.secret) + ' hidden)'),
|
||||
radio('summary', false, "Lawyer's summary (a short list of " + sum.records + ' record' + (sum.records === 1 ? '' : 's') + ' with lawyer-level values, ' + sum.values + ' value' + (sum.values === 1 ? '' : 's') + ')'),
|
||||
radio('complete', false, 'Include secrets (full copy: store it securely)'),
|
||||
h('div', { class: 'row' },
|
||||
btn('Cancel', () => { dlg.close(); dlg.remove(); }),
|
||||
|
||||
32
src/print.js
32
src/print.js
@@ -1,12 +1,14 @@
|
||||
import { defaultHeaderFields, isSequence } from './model.js';
|
||||
import { printGroups } from './ops.js';
|
||||
|
||||
// Pure helpers for the printed document. No DOM; tested in Node.
|
||||
// build.js strips `export` when bundling.
|
||||
|
||||
// Print views: 'masked' (no secrets), 'lawyer' (lawyer-level secrets shown, the
|
||||
// rest withheld) and 'complete' (everything). A boolean is accepted for older
|
||||
// callers: true is 'complete', false is 'masked'.
|
||||
export const PRINT_MODES = ['masked', 'lawyer', 'complete'];
|
||||
// callers: true is 'complete', false is 'masked'. 'summary' is the lawyer's summary:
|
||||
// it shows lawyer-level values like 'lawyer' does, but lists only those records (see summaryGroups).
|
||||
export const PRINT_MODES = ['masked', 'lawyer', 'complete', 'summary'];
|
||||
export function normalizeMode(mode) {
|
||||
if (mode === true) return 'complete';
|
||||
return PRINT_MODES.includes(mode) ? mode : 'masked';
|
||||
@@ -18,7 +20,7 @@ export function normalizeMode(mode) {
|
||||
export function isHidden(item, mode) {
|
||||
if (!item.secret) return false;
|
||||
const m = normalizeMode(mode);
|
||||
return m === 'complete' ? false : m === 'lawyer' ? !item.lawyer : true;
|
||||
return m === 'complete' ? false : m === 'masked' ? true : !item.lawyer;
|
||||
}
|
||||
|
||||
// What to print for a field. Secrets are either shown or withheld; an empty
|
||||
@@ -90,6 +92,30 @@ export function usesView(doc, frame, mode) {
|
||||
|
||||
// How many filled-in secret values the document holds: { lawyer, secret } where
|
||||
// `lawyer` counts lawyer-level ones and `secret` the plain ones. Empty ones don't count.
|
||||
// What the lawyer's summary lists: [{ section, groups: [{ title, records: [{ title, fields }] }] }].
|
||||
// A record qualifies if it has a lawyer-level text field (secret + lawyer); only those fields are
|
||||
// listed. Image fields, plain secrets and normal fields never are. Sections and sub-tabs with
|
||||
// no qualifying record are left out; order is the document's.
|
||||
export function summaryGroups(doc) {
|
||||
const lawyerFields = (r) => r.fields.filter((f) => f.secret && f.lawyer && f.kind !== 'image');
|
||||
const out = [];
|
||||
for (const s of doc.sections) {
|
||||
if (s.kind !== 'records') continue;
|
||||
const groups = printGroups(s)
|
||||
.map((g) => ({ title: g.title, records: g.entries.filter((r) => !isSequence(r)).map((r) => ({ title: r.title, fields: lawyerFields(r) })).filter((r) => r.fields.length) }))
|
||||
.filter((g) => g.records.length);
|
||||
if (groups.length) out.push({ section: s.title, groups });
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// { records, values } the lawyer's summary would list, for the print dialog.
|
||||
export function summaryCounts(doc) {
|
||||
let records = 0, values = 0;
|
||||
for (const s of summaryGroups(doc)) for (const g of s.groups) for (const r of g.records) { records++; values += r.fields.length; }
|
||||
return { records, values };
|
||||
}
|
||||
|
||||
export function countByLevel(doc) {
|
||||
const n = { lawyer: 0, secret: 0 };
|
||||
const add = (x) => { n[x.lawyer ? 'lawyer' : 'secret']++; };
|
||||
|
||||
@@ -100,6 +100,9 @@ dialog.lightbox { max-width: 92vw; max-height: 92vh; overflow: auto; } .bigimg {
|
||||
.pnote { border: 1.5pt solid #000; padding: 8pt 10pt; font: 600 10.5pt system-ui, sans-serif; }
|
||||
.pnote.warn { border-width: 3pt; }
|
||||
.ptoc { columns: 2; padding-left: 1.2em; }
|
||||
.pcover.psumcover { break-after: auto; }
|
||||
.pcover.psumcover h1 { font-size: 20pt; margin: 0 0 .1in; }
|
||||
.psumsec h2 { break-after: avoid; }
|
||||
.psec { break-before: page; }
|
||||
.psec:first-of-type { break-before: auto; }
|
||||
h2 { font-size: 17pt; border-bottom: 1pt solid #000; padding-bottom: 3pt; margin: 0 0 10pt; break-after: avoid; }
|
||||
|
||||
Reference in New Issue
Block a user