diff --git a/web/kanban-board.js b/web/kanban-board.js index cb477d3..51eaa5b 100644 --- a/web/kanban-board.js +++ b/web/kanban-board.js @@ -606,8 +606,9 @@ async function loadOlderFinished(){ const fresh=page.orders.filter(o=>!known.has(o.id)); olderFinished.push(...fresh);board.orders.push(...fresh);finishedMore=page.has_more;renderBoard(); } -async function move(order,state,reason='',machine=null){ - await api('/orders/'+order.id+'/move',{state,version:order.version,reason,...(machine?{machine_id:machine}:{})}); +// `options` goes to api(): pullMove expects the 409 it answers itself. +async function move(order,state,reason='',machine=null,options={}){ + await api('/orders/'+order.id+'/move',{state,version:order.version,reason,...(machine?{machine_id:machine}:{})},options); await load(); } diff --git a/web/kanban-numbers.js b/web/kanban-numbers.js index 4abf90e..eccf68c 100644 --- a/web/kanban-numbers.js +++ b/web/kanban-numbers.js @@ -356,6 +356,9 @@ function statsChart(box,daily){ if(avg>0){const a=node('span',undefined,'avg');a.style.bottom=100*avg/ceiling+'%';plot.append(a);} const bars=node('div',undefined,'bars'),axis=node('div',undefined,'axis');axis.setAttribute('aria-hidden','true'); bars.style.gridTemplateColumns=axis.style.gridTemplateColumns='repeat('+daily.length+',minmax(0,1fr))'; + // 90 days on a phone left the gaps no room for the bars (under 1 px each): + // past a month the gap is 1 px. + bars.classList.toggle('dense',daily.length>31);axis.classList.toggle('dense',daily.length>31); // A phone has room for fewer dates under the bars. const every=Math.ceil(daily.length/(PHONE.matches?5:10)); daily.forEach((d,i)=>{ @@ -363,7 +366,8 @@ function statsChart(box,daily){ b.style.animationDelay=Math.min(i*12,400)+'ms'; b.dataset.tip=shortDay(d.day)+': '+metres(d.metres)+', '+plural(d.orders,'pedido','pedidos'); if(i<3)b.classList.add('tip-r');else if(i>daily.length-4)b.classList.add('tip-l'); - bars.append(b);axis.append(node('span',(daily.length-1-i)%every===0?shortDay(d.day):'')); + // The last date ends at the chart's edge instead of running past it. + bars.append(b);axis.append(node('span',(daily.length-1-i)%every===0?shortDay(d.day):'',i===daily.length-1?'end':undefined)); }); plot.append(bars,axis); plot.setAttribute('role','img');plot.setAttribute('aria-label','Metros vendidos por dia, '+daily.length+' dias, média de '+metres(avg)); diff --git a/web/kanban-order.js b/web/kanban-order.js index f53d250..255f534 100644 --- a/web/kanban-order.js +++ b/web/kanban-order.js @@ -588,11 +588,14 @@ function readyFinals(order){ // form dialog then closes itself. Anything else is still an error, and the // version is never resent blindly. async function saveFinalFiles(order, files, note){ + const path='/orders/'+order.id+'/final-files'; try{ - await api('/orders/'+order.id+'/final-files',{version:order.version,files,note}); + // The first 409 is expected: it is answered below, so it is not reported; + // one this function does not answer is (reportRefusal). + await api(path,{version:order.version,files,note},{expected:[409]}); return false; }catch(error){ - if(error.status!==409||!String(error.message).startsWith('O pedido mudou'))throw error; + if(error.status!==409||!String(error.message).startsWith('O pedido mudou'))throw reportRefusal(path,error); await load(); const fresh=(board.orders||[]).find(row=>row.id===order.id); if(fresh&&(finalDone(fresh)||!['rec','cor'].includes(fresh.state))){ @@ -603,10 +606,10 @@ async function saveFinalFiles(order, files, note){ // these finals: the person already confirmed them, so try once more with // the fresh version; the server checks everything again (Sentry DTF-WEB-7). if(fresh&&!fresh.cancelled_at){ - await api('/orders/'+order.id+'/final-files',{version:fresh.version,files,note}); + await api(path,{version:fresh.version,files,note}); return false; } - throw error; + throw reportRefusal(path,error); } } // A customer's correction or an original may not be the transparent 300 DPI diff --git a/web/kanban-users.js b/web/kanban-users.js index 9ea0cc1..9e11493 100644 --- a/web/kanban-users.js +++ b/web/kanban-users.js @@ -716,14 +716,16 @@ async function pullTo(order, machineId){ // it still waits in Arte conferida, pull once more with the fresh version; // the server checks everything again (Sentry DTF-WEB-K, as DTF-WEB-7). async function pullMove(order,target){ + const path='/orders/'+order.id+'/move'; try{ - await move(order,'imp','',target); + // The first 409 is answered below, so it is not reported (as saveFinalFiles). + await move(order,'imp','',target,{expected:[409]}); }catch(error){ - if(error.status!==409||!String(error.message).startsWith('O pedido mudou'))throw error; + if(error.status!==409||!String(error.message).startsWith('O pedido mudou'))throw reportRefusal(path,error); await load(); const fresh=(board.orders||[]).find(row=>row.id===order.id); if(fresh?.state==='imp'&&fresh.machine?.id===target){say('O pedido já estava imprimindo nesta máquina.');return;} - if(!fresh||fresh.cancelled_at||fresh.state!=='tra')throw error; + if(!fresh||fresh.cancelled_at||fresh.state!=='tra')throw reportRefusal(path,error); await move(fresh,'imp','',target); } } diff --git a/web/kanban.css b/web/kanban.css index 76e9e4e..1ff8109 100644 --- a/web/kanban.css +++ b/web/kanban.css @@ -894,6 +894,10 @@ select.inp{appearance:none;-webkit-appearance:none;padding-right:32px;background .gl{position:absolute;left:0;right:0;border-top:1px solid var(--ln2)} .avg{position:absolute;left:0;right:0;border-top:1.5px dashed var(--tx2);z-index:1;pointer-events:none} .axis{position:absolute;left:0;right:0;top:100%;display:grid;gap:4px;margin-top:8px;font-size:11.5px;color:var(--tx3);text-align:center;white-space:nowrap} +/* A date wider than its bar stays centred under it; the last one ends at the edge. */ +.axis span{display:flex;justify-content:center} +.axis span.end{justify-content:flex-end} +.bars.dense,.axis.dense{gap:1px} .charttable{padding:0 20px 16px;font-size:13px;color:var(--tx2)} .charttable summary{cursor:pointer;width:max-content} .charttable .table{margin-top:8px} diff --git a/web/kanban.js b/web/kanban.js index 2ffbf08..4c6b79c 100644 --- a/web/kanban.js +++ b/web/kanban.js @@ -265,6 +265,13 @@ async function api(path,body,options={}){ } return d; } +// A 409 a caller expected (api's options.expected: [409]) and then could not +// answer is still reported, as api() would have; any other status api() +// already reported. Returns the error to rethrow. +function reportRefusal(path,error){ + if(error?.status===409)window.dtfObservability?.apiError?.(path,error.status,error.message); + return error; +} function download(uid,orderId){return async()=>{ const result=await api('/uploads/'+uid+'/download'+(orderId?'?order_id='+encodeURIComponent(orderId):'')); const link=node('a');link.href=result.url;link.referrerPolicy='no-referrer';link.download=result.name;link.click();