Merge pull request 'Add page range control for print preview' (#20) from cursor/resume-mid-print-pages into main

This commit was merged in pull request #20.
This commit is contained in:
2026-10-05 19:55:18 +00:00

View File

@@ -36,7 +36,7 @@
z-index: 100;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}
.preview-controls button {
background: #3b82f6;
color: white;
@@ -57,8 +57,28 @@
cursor: wait;
}
.preview-controls .page-range {
display: inline-flex;
align-items: center;
gap: 8px;
margin-right: 12px;
font-family: sans-serif;
font-size: 14px;
vertical-align: middle;
}
.preview-controls .page-range input {
width: 4.5em;
padding: 8px 6px;
font-size: 16px;
border: 1px solid #475569;
border-radius: 6px;
background: #0f172a;
color: #fff;
}
.page-wrapper {
margin-top: 80px; /* Space for controls */
margin-top: 110px; /* Space for controls */
display: flex;
flex-direction: column;
align-items: center;
@@ -78,6 +98,25 @@
page-break-after: always;
}
.a4-page.skip-print {
opacity: 0.4;
}
.page-badge {
position: absolute;
top: 8px;
right: 8px;
z-index: 2;
background: #1e293b;
color: #fff;
font-family: sans-serif;
font-size: 12px;
font-weight: bold;
padding: 4px 8px;
border-radius: 4px;
pointer-events: none;
}
/* CSS Grid for the 4 slips */
.slip-grid {
display: grid;
@@ -120,6 +159,15 @@
box-shadow: none;
width: 100%;
height: 100vh; /* Fill printed page */
opacity: 1;
}
.a4-page.skip-print {
display: none !important;
}
.page-badge {
display: none;
}
}
</style>
@@ -128,16 +176,24 @@
<div class="preview-controls">
<p style="margin-bottom: 10px; font-family: sans-serif;">
Order #{{ order.id }} — {{ order.product.code }} <br>
{{ order.canister_count }} Canisters ({{ order.canister_pages }} Pages) |
{{ order.canister_count }} Canisters ({{ order.canister_pages }} Pages) |
{{ order.box_count }} Boxes ({{ order.box_pages }} Pages)
</p>
<label class="page-range">
Pages
<input id="start-from" type="number" min="1" max="{{ pages|length }}" value="1" {% if not pages %}disabled{% endif %}>
–
<input id="end-at" type="number" min="1" max="{{ pages|length }}" value="{{ pages|length }}" {% if not pages %}disabled{% endif %}>
/ {{ pages|length }}
</label>
<button id="btn-print" type="button" disabled>🖨️ Print Now</button>
<button type="button" onclick="window.close()" style="background:#64748b; margin-left: 10px;">Close</button>
</div>
<div class="page-wrapper">
{% for page in pages %}
<div class="a4-page">
<div class="a4-page" data-page="{{ forloop.counter }}">
<div class="page-badge">Page {{ forloop.counter }} / {{ pages|length }}</div>
<div class="slip-grid">
{% for weight in page.slips %}
<div class="slip-quadrant">
@@ -157,6 +213,10 @@
const FIELDS = ['batch', 'date', 'next', 'weight'];
const varsEl = document.getElementById('calibration-vars');
const btn = document.getElementById('btn-print');
const startInput = document.getElementById('start-from');
const endInput = document.getElementById('end-at');
const pages = document.querySelectorAll('.a4-page');
const total = pages.length;
function cssFromCal(cal) {
const lines = [':root {'];
@@ -177,11 +237,49 @@
return lines.join('\n');
}
function clampPage(n) {
if (!total) return 1;
n = parseInt(n, 10);
if (isNaN(n) || n < 1) return 1;
if (n > total) return total;
return n;
}
function applySkip() {
let start = clampPage(startInput.value);
let end = clampPage(endInput.value);
if (start > end) end = start;
startInput.value = start;
endInput.value = end;
pages.forEach(function (el) {
const pageNum = parseInt(el.getAttribute('data-page'), 10);
el.classList.toggle('skip-print', pageNum < start || pageNum > end);
});
}
function seedFromQuery() {
const params = new URLSearchParams(window.location.search);
const from = params.get('from');
const to = params.get('to');
if (from != null) startInput.value = clampPage(from);
if (to != null) endInput.value = clampPage(to);
applySkip();
}
function enablePrint() {
btn.disabled = false;
btn.onclick = function () { window.print(); };
btn.onclick = function () {
applySkip();
window.print();
};
}
startInput.addEventListener('change', applySkip);
startInput.addEventListener('input', applySkip);
endInput.addEventListener('change', applySkip);
endInput.addEventListener('input', applySkip);
seedFromQuery();
fetch('/api/calibration', { cache: 'no-store' })
.then(function (res) {
if (!res.ok) throw new Error('HTTP ' + res.status);