diff --git a/app/api/operator.py b/app/api/operator.py index 4d5153c..d0399c9 100644 --- a/app/api/operator.py +++ b/app/api/operator.py @@ -624,6 +624,33 @@ def thumbnail(uid: UUID, user=Depends(operator)): return Response(bytes(row['data']), media_type=row['mime'], headers={'Cache-Control': 'private, max-age=86400', 'Content-Disposition': 'inline'}) +@router.get('/api/operator/queue/finals') +def queue_finals(user=Depends(operator)): + """The approved final files of every order in the print queue, in queue + order, each named after its order so a folder of them stays readable. The + browser downloads them straight from storage: a zip of multi-GB sheets + would go through the server.""" + with db.connect() as c: + rows = c.execute(f'''SELECT o.number,f.item_index,u.object_key,u.name FROM dtf_local.orders o + JOIN dtf_local.order_files f ON f.order_id=o.id JOIN dtf_local.uploads u ON u.id=f.upload_id + WHERE o.state='fil' AND o.cancelled_at IS NULL AND {FINAL_OK} + ORDER BY COALESCE(o.queue_key, extract(epoch FROM o.created_at)),o.id,f.item_index,f.created_at''').fetchall() + files, names = [], set() + for row in rows: + prefix = f"pedido-{row['number']}-item-{row['item_index'] + 1}" + name = row['name'] if row['name'].startswith(prefix) else f"{prefix}-{row['name']}" + stem, dot, ext = name.rpartition('.') + copy = 2 + while name in names: + name = f'{stem} ({copy}).{ext}' if dot else f'{ext} ({copy})' + copy += 1 + names.add(name) + files.append({'number': row['number'], 'item': row['item_index'] + 1, 'name': name, + 'url': storage.download(row['object_key'], name)}) + audit('queue_finals_downloaded', operator=user, files=len(files)) + return {'files': files} + + @router.get('/api/operator/uploads/{uid}/download') def download(uid: UUID, user=Depends(operator)): with db.connect() as c: diff --git a/tests/workflow_test.py b/tests/workflow_test.py index b1eda1f..0c44267 100644 --- a/tests/workflow_test.py +++ b/tests/workflow_test.py @@ -61,7 +61,13 @@ def run(): link=customer.call('/customer/orders/'+oid+'/files/'+final['id']+'/download') assert urlopen(link['url']).read()==b'LOCAL FINAL VERSION ONE' guest=Client();guest.call('/session');guest.call('/customer/orders/'+oid+'/files/'+final['id']+'/download',expected=404) - version=move('fil',version);version=move('imp',version);version=move('cor',version) + version=move('fil',version) + # The print queue's files come named after their order, straight from storage. + queued=customer.call('/operator/queue/finals',operator=True)['files'] + mine=[f for f in queued if urlopen(f['url']).read()==b'LOCAL FINAL VERSION ONE'] + assert len(mine)==1 and mine[0]['name'].startswith('pedido-%d-item-1-' % mine[0]['number']), queued + customer.call('/operator/queue/finals',expected=401) + version=move('imp',version);version=move('cor',version) customer.call('/customer/orders/'+oid+'/files/'+final['id']+'/download',expected=404) premature_final=upload_bytes(customer,b'FINAL BEFORE CUSTOMER CORRECTION',order_id=oid) version=customer.call('/operator/orders/'+oid+'/final-files', diff --git a/web/kanban.css b/web/kanban.css index c31bb6e..14265d1 100644 --- a/web/kanban.css +++ b/web/kanban.css @@ -95,6 +95,8 @@ main{padding:0 24px 24px} .col-head .swatch{width:10px;height:10px;border-radius:3px;background:var(--c)} .col-head .n{margin-left:auto;font-family:var(--mono);font-size:13.5px;color:var(--muted)} .col-head small{font-size:13.5px;color:var(--faint)} +.col-head .col-sub{justify-content:space-between;min-height:30px} +.col-head .col-sub small{white-space:nowrap} .col .empty{font-size:13.5px;color:var(--faint);padding:8px 2px} .card{text-align:left;display:flex;flex-direction:column;gap:8px;padding:12px;border-radius:10px;border:1px solid var(--line2);background:var(--card);width:100%} .card:hover,.card.open{border-color:var(--line3);background:#1E2226} diff --git a/web/kanban.js b/web/kanban.js index 89b4bb1..e4effcb 100644 --- a/web/kanban.js +++ b/web/kanban.js @@ -172,6 +172,16 @@ function download(uid){return async()=>{ const result=await api('/uploads/'+uid+'/download'); const link=node('a');link.href=result.url;link.referrerPolicy='no-referrer';link.download=result.name;link.click(); };} +async function downloadQueue(){ + const {files}=await api('/queue/finals'); + if(!files.length){say('Nenhum arquivo final aprovado na fila.');return;} + say('Baixando '+files.length+(files.length>1?' arquivos':' arquivo')+' da fila… Se o navegador perguntar, permita vários downloads.',false,8000); + // One at a time: browsers drop clicks that come too close together. + for(const file of files){ + const link=node('a');link.href=file.url;link.referrerPolicy='no-referrer';link.download=file.name;link.click(); + await new Promise(r=>setTimeout(r,700)); + } +} function manifest(production){ const url=URL.createObjectURL(new Blob([JSON.stringify(production,null,2)],{type:'application/json'})); const link=node('a');link.href=url;link.download='dtf-layout-'+production.sources[0].upload_id.slice(0,8)+'.json'; @@ -315,7 +325,13 @@ function renderBoard(){ // Finished orders are a recent window, not the whole history: say so. const count=state==='fin'&&board.finished_total>orders.length?orders.length+' de '+board.finished_total:String(orders.length); line.append(swatch,node('h2',title),node('span',count,'n')); - head.append(line,node('small',orders.length?metres(total)+' no total':'vazio')); + const sub=node('div',undefined,'col-sub');sub.append(node('small',orders.length?metres(total)+' no total':'vazio')); + // The print queue's files, all at once, to import into FlexiPRINT. + if(state==='fil'&&orders.length){ + const all=downloadButton('Baixar todos',downloadQueue,'btn ghost small');all.title='Baixar os arquivos finais de todos os pedidos da fila'; + sub.append(all); + } + head.append(line,sub); column.append(head); for(const order of orders)column.append(card(order)); if(state==='fin'&&finishedMore&&filter==='all')moreButton(column,true,loadOlderFinished);