Pack print: A4 upright pages, small pictures at their size, card sides on one sheet
CI / secret scan (push) Successful in 6s
CI / fmt, clippy, tests (push) Successful in 43s
CI / release (push) Skipped

Every page of the pack is now A4 upright, so it prints as one stack. A
PDF page or a whole-page picture that lies wider than tall is turned
onto the page (a small one that fits as it is stays as it is), and a
PDF page is only made smaller, never larger.

A picture never prints larger than its resolution allows (the JFIF or
PNG dpi, else 150 dpi), nor larger than its kind's box: passport pages,
visas and stamps 180 x 128 mm, cards 130 x 90 mm, and a phone's
screenshot (the TDAC, or any picture about twice as tall as wide)
150 x 75 mm. These print at the top of the page.

Cards: a new kind "ID card", and the work permit, take two pictures in
one upload as front and back (migration 0008 documents.back_of). The
Documents tab marks them front/back, lists them together and offers
"Print both sides" (.../documents/{id}/sides.pdf); the pack prints both
on one sheet. The client link takes ID cards too. The demo seeds a TDAC
screenshot and an ID card's two sides.

Checks: fmt, clippy, 108 unit and 57 integration tests (print sizes,
dpi reading, the back following its front, the paired upload, its
audit and the sides PDF); the demo pack's pages checked as images.
The Documents tab's actions stack on a phone, so none is cut off.
This commit is contained in:
grabowski committed 2026-11-21 18:30:43 +07:00
1 parent 506221ecd0
commit 1f526f17f9
16 files changed
+724 -73

No files matched your search

+41
View File
@@ -846,6 +846,32 @@ pub fn assess(f: &Facts, on: NaiveDate) -> Vec<Item> {
}
}
}
let all: Vec<&Document> = f.person_docs.iter().chain(&f.company_docs).collect();
for it in &mut out {
it.docs = with_backs(&it.docs, &all);
}
out
}
/// A card's two sides print together: a back chosen stands for its front,
/// and each front is followed by its back.
fn with_backs(ids: &[i64], docs: &[&Document]) -> Vec<i64> {
let mut out: Vec<i64> = Vec::new();
for id in ids {
let front = docs
.iter()
.find(|d| d.id == *id)
.and_then(|d| d.back_of)
.filter(|f| docs.iter().any(|d| d.id == *f))
.unwrap_or(*id);
if out.contains(&front) {
continue;
}
out.push(front);
if let Some(back) = docs.iter().find(|d| d.back_of == Some(front)) {
out.push(back.id);
}
}
out
}
@@ -1045,6 +1071,7 @@ mod tests {
uploaded_by: "test".into(),
uploaded_at: at,
updated_at: at,
back_of: None,
};
match link {
Some(("passports", r)) => x.passport_id = Some(r),
@@ -1441,4 +1468,18 @@ mod tests {
"a, b and c"
);
}
#[test]
fn a_cards_back_prints_after_its_front() {
let mut f = facts();
let mut front = doc(5, "work-permit", Some(("work-permits", 81)), None);
front.content_type = "image/jpeg".into();
// the back has the higher id, so it is the newest: it stands for
// the front, which prints first
let mut back = doc(6, "work-permit", Some(("work-permits", 81)), None);
back.back_of = Some(5);
f.person_docs = vec![front, back];
let it = find(&assess(&f, d(ON)), "work-permit").clone();
assert_eq!(it.docs, [5, 6], "{it:?}");
}
}