Pack print: A4 upright pages, small pictures at their size, card sides on one sheet
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:
1 parent
506221ecd0
commit
1f526f17f9
16 files changed
+724
-73
No files matched your search
+33
-2
@@ -89,6 +89,7 @@ pub const PERSON_KINDS: &[Kind] = &[
|
||||
),
|
||||
k("tm30-receipt", "TM.30 receipt", Some("addresses")),
|
||||
k("work-permit", "Work permit", Some("work-permits")),
|
||||
k("id-card", "ID card (pink card or other)", None),
|
||||
k("pnd91", "Income tax return (PND.91)", None),
|
||||
// made by the app when the client signs through their link
|
||||
k("agreement", "Signed agreement", None),
|
||||
@@ -108,6 +109,15 @@ pub const COMPANY_KINDS: &[Kind] = &[
|
||||
k("other", "Other", None),
|
||||
];
|
||||
|
||||
/// The kinds that are cards with two sides: uploaded as two pictures at
|
||||
/// once, the first is the front and the second the back, and the pack
|
||||
/// prints both on one A4 sheet.
|
||||
pub const CARD_KINDS: &[&str] = &["id-card", "work-permit"];
|
||||
|
||||
pub fn is_card(kind: &str) -> bool {
|
||||
CARD_KINDS.contains(&kind)
|
||||
}
|
||||
|
||||
pub fn kind(owner: Owner, slug: &str) -> Option<&'static Kind> {
|
||||
owner.kinds().iter().find(|k| k.slug == slug)
|
||||
}
|
||||
@@ -218,6 +228,8 @@ pub struct Document {
|
||||
pub uploaded_by: String,
|
||||
pub uploaded_at: DateTime<Utc>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
/// The front this document is the back of (a card's two sides).
|
||||
pub back_of: Option<i64>,
|
||||
}
|
||||
|
||||
impl Document {
|
||||
@@ -333,15 +345,34 @@ fn sorted(owner: Owner, mut docs: Vec<Document>) -> Vec<Document> {
|
||||
.position(|k| k.slug == d.kind)
|
||||
.unwrap_or(usize::MAX)
|
||||
};
|
||||
// a card's back sorts as its front, right after it
|
||||
let front = |d: &Document| d.back_of.unwrap_or(d.id);
|
||||
let fronts: std::collections::HashMap<i64, Option<NaiveDate>> =
|
||||
docs.iter().map(|d| (d.id, d.dated_on)).collect();
|
||||
let dated = |d: &Document| match d.back_of {
|
||||
Some(f) => fronts.get(&f).copied().unwrap_or(d.dated_on),
|
||||
None => d.dated_on,
|
||||
};
|
||||
docs.sort_by(|a, b| {
|
||||
rank(a)
|
||||
.cmp(&rank(b))
|
||||
.then(b.dated_on.cmp(&a.dated_on))
|
||||
.then(b.id.cmp(&a.id))
|
||||
.then(dated(b).cmp(&dated(a)))
|
||||
.then(front(b).cmp(&front(a)))
|
||||
.then(a.back_of.is_some().cmp(&b.back_of.is_some()))
|
||||
});
|
||||
docs
|
||||
}
|
||||
|
||||
/// Makes `back` the back side of `front`.
|
||||
pub async fn set_back(tx: &mut Transaction<'_, Postgres>, back: i64, front: i64) -> Result<()> {
|
||||
sqlx::query("UPDATE documents SET back_of = $2 WHERE id = $1")
|
||||
.bind(back)
|
||||
.bind(front)
|
||||
.execute(&mut **tx)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn list(db: &PgPool, owner: Owner) -> Result<Vec<Document>> {
|
||||
let docs: Vec<Document> = sqlx::query_as(
|
||||
"SELECT * FROM documents \
|
||||
|
||||
Reference in new issue
Block a user