Printing Debug

This commit is contained in:
2026-09-07 11:18:13 +10:00
parent 8bc71792e3
commit eb986581e4
5 changed files with 123 additions and 25 deletions
+15
View File
@@ -400,3 +400,18 @@ tr.row-bad td { background: #fdf0f2; }
vertical-align: -2px;
margin-right: 2px;
}
pre.raw {
margin: 0 0 14px;
padding: 12px;
background: var(--paper);
border: 1px solid var(--rule);
border-radius: 3px;
font-family: ui-monospace, Menlo, Consolas, monospace;
font-size: 12.5px;
line-height: 1.45;
white-space: pre-wrap;
word-break: break-word;
max-height: 320px;
overflow: auto;
}
+55 -12
View File
@@ -689,6 +689,7 @@ async function loadSites() {
<button class="ghost" data-preview-badge="${s.id}">Preview badge</button>
<button class="ghost" data-bitmap="${s.id}">Bitmap preview</button>
${s.printer.enabled ? `<button class="ghost" data-test-print="${s.id}">Test print</button>` : ''}
${s.printer.enabled ? `<button class="ghost" data-print-diag="${s.id}">Diagnostics</button>` : ''}
</div>
</div>
<dl class="site-meta">
@@ -740,6 +741,17 @@ async function loadSites() {
window.open(`/admin/api/sites/${btn.dataset.bitmap}/badge-bitmap`, '_blank')
)
);
$$('[data-print-diag]').forEach((btn) =>
btn.addEventListener('click', async () => {
const d = await api(`/sites/${btn.dataset.printDiag}/printer-diagnostics`);
openModal(
'Printer diagnostics',
`<pre class="raw">${esc(JSON.stringify(d, null, 2))}</pre>`,
null,
{ saveLabel: 'Close', hideCancel: true }
);
})
);
$$('[data-test-print]').forEach((btn) =>
btn.addEventListener('click', async () => {
btn.disabled = true;
@@ -748,7 +760,17 @@ async function loadSites() {
await api(`/sites/${btn.dataset.testPrint}/test-print`, { method: 'POST' });
toast('Sent to the printer.');
} catch (err) {
toast(err.message, true);
// Show the printer's own words as well as the summary, because a refusal
// usually names the reason and the summary cannot cover every case.
const raw = err.payload?.raw;
openModal(
'The printer refused the job',
`<p>${esc(err.message)}</p>
${err.payload?.command ? `<p class="hint">Command:</p><pre class="raw">${esc(err.payload.command)}</pre>` : ''}
${raw ? `<p class="hint">What the printer and brother_ql said:</p><pre class="raw">${esc(raw)}</pre>` : ''}`,
null,
{ saveLabel: 'Close', hideCancel: true }
);
} finally {
btn.disabled = false;
btn.textContent = 'Test print';
@@ -764,16 +786,29 @@ async function loadSites() {
* 62 mm is for a different printer.
*/
const LABEL_PRESETS = [
{ id: 'dk22205-90', label: 'Brother DK-22205 continuous, cut at 90 mm', w: 62, h: 90, photo: true },
{ id: 'dk11202', label: 'Brother DK-11202 die-cut 62 × 100 mm', w: 62, h: 100, photo: true },
{ id: 'dk22251-90', label: 'Brother DK-22251 black/red continuous, cut at 90 mm', w: 62, h: 90, photo: true, accent: true },
{ id: 'dk11208', label: 'Brother DK-11208 die-cut 38 × 90 mm', w: 38, h: 90, photo: false },
{ id: 'dk11209', label: 'Brother DK-11209 die-cut 29 × 62 mm', w: 29, h: 62, photo: false },
{ id: 'dk11201', label: 'Brother DK-11201 die-cut 29 × 90 mm', w: 29, h: 90, photo: false },
{ id: 'card', label: 'Card size 86 × 54 mm (not a QL-820NWB size)', w: 86, h: 54, photo: true },
{ id: 'dymo99014', label: 'Dymo 99014 101 × 54 mm', w: 101, h: 54, photo: true },
{ id: 'dk22205-90', label: 'Brother DK-22205 continuous, cut at 90 mm', w: 62, h: 90, photo: true, roll: '62' },
{ id: 'dk11202', label: 'Brother DK-11202 die-cut 62 × 100 mm', w: 62, h: 100, photo: true, roll: '62' },
{ id: 'dk22251-90', label: 'Brother DK-22251 black/red continuous, cut at 90 mm', w: 62, h: 90, photo: true, roll: '62red', accent: true },
{ id: 'dk11208', label: 'Brother DK-11208 die-cut 38 × 90 mm', w: 38, h: 90, photo: false, roll: '62' },
{ id: 'dk11209', label: 'Brother DK-11209 die-cut 29 × 62 mm', w: 29, h: 62, photo: false, roll: '62' },
{ id: 'dk11201', label: 'Brother DK-11201 die-cut 29 × 90 mm', w: 29, h: 90, photo: false, roll: '62' },
{ id: 'card', label: 'Card size 86 × 54 mm (not a QL-820NWB size)', w: 86, h: 54, photo: true, roll: '62' },
{ id: 'dymo99014', label: 'Dymo 99014 101 × 54 mm', w: 101, h: 54, photo: true, roll: '62' },
];
/**
* Which preset the saved settings correspond to. Dimensions alone are ambiguous —
* DK-22205 and DK-22251 are both 62 x 90 — so the roll type decides between them.
*/
function matchingPreset(site) {
return LABEL_PRESETS.find(
(p) =>
Number(site.badge.widthMm) === p.w &&
Number(site.badge.heightMm) === p.h &&
p.roll === (site.printer.label === '62red' ? '62red' : '62')
);
}
function openSiteModal(site) {
openModal(
`Edit ${site.name}`,
@@ -787,11 +822,11 @@ function openSiteModal(site) {
<option value="">Custom size</option>
${LABEL_PRESETS.map(
(p) =>
`<option value="${p.id}" ${
Number(site.badge.widthMm) === p.w && Number(site.badge.heightMm) === p.h ? 'selected' : ''
}>${esc(p.label)}</option>`
`<option value="${p.id}" ${matchingPreset(site)?.id === p.id ? 'selected' : ''}>${esc(p.label)}</option>`
).join('')}
</select></label>
<p class="hint">A shortcut that fills in the boxes below. The size, the roll type and the
colour option are what actually get saved.</p>
<div class="modal-row">
${field('Width (mm)', 'widthMm', site.badge.widthMm, 'number')}
${field('Height (mm)', 'heightMm', site.badge.heightMm, 'number')}
@@ -1083,6 +1118,14 @@ function wireBadgePreset() {
height.value = preset.h;
$('#badge-photo').checked = preset.photo;
$('#badge-accent').checked = Boolean(preset.accent);
// The preset knows which roll it describes, so keep the two in step. Picking
// the DK-22251 preset while the roll stayed on "black only" is what makes the
// printer refuse the job.
const roll = $('#modal-form [name="printerLabel"]');
if (roll && preset.roll) {
roll.value = preset.roll;
roll.dispatchEvent(new Event('change'));
}
check();
});