feat: acceptable time per stage with late cards and alerts (front 11)
All checks were successful
Build and deploy / Validate source (push) Successful in 4s
Build and deploy / Integration suite on a real stack (push) Successful in 4m24s
Build and deploy / Secret scan and release gate (push) Successful in 5s
Build and deploy / Publish images (push) Successful in 1m0s

Gestão edits the hours and the responsible for each column. A card past the
limit turns yellow, twice the limit red, and the board lists it under
Atrasados. Números compares the real median with the limit and counts the
passages that exceeded it in the period and today.
This commit is contained in:
Cauê Faleiros
2026-11-06 12:52:53 -03:00
parent 7e22262280
commit bdff73b76b
7 changed files with 216 additions and 9 deletions

View File

@@ -234,6 +234,14 @@ main{padding:0}
.col{display:flex;flex-direction:column;gap:8px;min-width:0;min-height:240px;background:var(--lane);border-radius:14px;padding:8px;transition:background .15s,box-shadow .15s}
.col.allowed{box-shadow:inset 0 0 0 1.5px color-mix(in srgb,var(--acc) 40%,transparent)}
.col.target{box-shadow:inset 0 0 0 2px var(--acc);background:color-mix(in srgb,var(--acc) 5%,var(--lane))}
.latebar{display:flex;align-items:center;gap:8px;flex-wrap:wrap;margin:0 0 10px;padding:9px 12px;border:1px solid var(--ln2);border-radius:9px;background:var(--sf);font-size:12px}
.latebar[hidden]{display:none}
.latebar>b{color:var(--bad);font-family:inherit;font-size:12px}
.latechip{display:inline-flex;align-items:center;gap:5px;border:1px solid var(--ln2);border-radius:7px;background:var(--sf3);color:var(--tx);padding:4px 7px;font:inherit;font-size:11px;cursor:pointer}
.latechip:hover{border-color:var(--bad)}
.latechip i{width:7px;height:7px;border-radius:999px;background:var(--warn)}
.latechip.bad i{background:var(--bad)}
.latebar .btn{margin-left:auto;min-height:28px;font-size:11px}
.colhead{display:flex;align-items:center;gap:10px;padding:8px 8px 6px}
.coltx{display:flex;flex-direction:column;gap:1px;min-width:0;flex:1}
.colhead h2{margin:0;font-size:14px;font-weight:650;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}

View File

@@ -98,6 +98,7 @@
</div>
<div class="filtertags" id="filter-tags"></div>
</div>
<div id="latebar" class="latebar" hidden></div>
<div class="board" id="kan"></div>
</section>
<section id="tab-quotes" hidden>
@@ -140,7 +141,7 @@
<table class="table"><tbody id="stats-rework-printers"></tbody></table>
<h3>Aguardando autorização</h3><ul class="plainlist" id="stats-rework-pending"></ul></details></section>
<section class="panel clip s6"><div class="phead"><h2>Tempo em cada etapa</h2><span class="hint tip-l" tabindex="0" data-tip="Tempo mediano por pedido: quem voltou para a etapa soma cada passagem. O tempo em Aguardando contato não conta."><svg class="i s" viewBox="0 0 20 20" aria-hidden="true"><path d="M2.75 10a7.25 7.25 0 1 0 14.5 0a7.25 7.25 0 1 0 -14.5 0 M10 9v4.5 M10 6.25v.75"></path></svg></span></div>
<table class="table"><thead><tr><th scope="col">Etapa</th><th scope="col" class="r">Mediana</th><th scope="col">Agora</th></tr></thead><tbody id="stats-stages"></tbody></table></section>
<table class="table"><thead><tr><th scope="col">Etapa</th><th scope="col" class="r">Mediana</th><th scope="col" class="r">Aceitável</th><th scope="col" class="r">Estouros</th><th scope="col">Agora</th></tr></thead><tbody id="stats-stages"></tbody></table></section>
</div>
<section class="panel clip"><div class="phead"><h2>Velocidade do site e do Prumo</h2><span class="hint tip-l" tabindex="0" data-tip="Média e p95 do que o cliente sente, por pedido pago no período: abrir a página, subir o arquivo (MB/s), a conferência do Prumo, a montagem das avulsas, a geração do arquivo final por 10 m e o tempo do evento de pagamento até o card. Referências: página < 3 s; conferência < 30 s; geração < 2 min por 10 m; card em até 1 min."><svg class="i s" viewBox="0 0 20 20" aria-hidden="true"><path d="M2.75 10a7.25 7.25 0 1 0 14.5 0a7.25 7.25 0 1 0 -14.5 0 M10 9v4.5 M10 6.25v.75"></path></svg></span></div>
<table class="table"><thead><tr><th scope="col">Etapa</th><th scope="col" class="r">Média</th><th scope="col" class="r">p95</th><th scope="col" class="r">Amostras</th></tr></thead><tbody id="stats-speed"></tbody></table></section>

View File

@@ -16,7 +16,6 @@ const productName=item=>PRODUCT[item.mode]+(item.split?' · folha '+item.split.p
', '+(item.stroke_class==='C3'?'chapado':'traço fino'):'');
const SHORT={file:'Têxtil folha',avulsa:'Têxtil avulsa',uvfile:'UV folha',uv:'UV avulsa'};
const EVENTS={payment_approved:'Pagamento aprovado',production_started:'Produção iniciada',correction_needed:'Correção necessária',ready:'Pedido pronto',cancelled:'Pedido cancelado'};
const LATE_HOURS=4;
// Payment outcomes are recorded by the API in English; operators read Portuguese.
function outcomeText(outcome){
const rules=[
@@ -677,7 +676,7 @@ function printState(order){
return {text:items>1&&ready?ready+' de '+items+' pronto':'Preparar à mão',tone:'warn'};
return {text:'Sem arquivo gerado',tone:'warn'};
}
const stalled=order=>['rec','tra','imp','rev'].includes(order.state)&&Date.now()-new Date(order.updated_at)>LATE_HOURS*3600000;
const stalled=order=>!!order.late;
// "Aguardando contato": a word with the customer is needed before printing.
// A mark on the card, not a stage; a finished order no longer needs it.
const waitingContact=order=>!!order.contact_since&&!order.cancelled_at&&order.state!=='fin';
@@ -742,6 +741,7 @@ const FILTER_TESTS={
entrega:o=>!!o.snapshot.destination,
retirada:o=>!o.snapshot.destination,
parados:stalled,
atrasados:stalled,
contato:waitingContact,
prova:proofPending,
manual:o=>['rec','tra'].includes(o.state)&&!finalDone(o)&&(o.print_files||[]).some(r=>
@@ -761,7 +761,7 @@ function filterKinds(){
const kinds=[
{key:'delivery',label:'Envio',options:[['entrega','Entrega'],['retirada','Retirada']]},
{key:'origin',label:'Origem',options:Object.entries(ORIGINS)},
{key:'status',label:'Situação',options:[['parados','Parados há mais de '+LATE_HOURS+' h','Parados'],
{key:'status',label:'Situação',options:[['atrasados','Fora do tempo aceitável','Atrasados'],
['contato','Aguardando contato'],['prova','Prova a conferir'],['manual','Preparar à mão'],['cancelados','Cancelados']]}];
// A machine, when there is more than one to tell apart.
const machines=(board.machines||[]).filter(m=>m.active||m.open_orders);
@@ -842,7 +842,27 @@ const GLYPH={
const orderMetres=o=>o.snapshot.items.reduce((t,i)=>t+Number(i.billed_metres),0);
// On a phone the board shows one stage at a time, picked from the chips above it.
let phoneCol='rec';
// Atrasados (front 11): the cards past the stage limit, with the person
// responsible for that column, above the board.
function renderLatebar(){
const bar=$('latebar');
const late=board.orders.filter(o=>!o.cancelled_at&&o.late)
.sort((a,b)=>(b.state_hours||0)-(a.state_hours||0));
if(!late.length){bar.hidden=true;bar.replaceChildren();return;}
bar.hidden=false;
const head=node('b','Atrasados ('+late.length+')');bar.replaceChildren(head);
late.slice(0,10).forEach(o=>{
const chip=node('button',undefined,'latechip'+(o.late==='bad'?' bad':''));
chip.type='button';chip.append(node('i'),node('span','#'+o.number+' · '+board.states[o.state]));
chip.title=(o.state_hours??'?')+' h nesta etapa · limite '+(o.limit_hours??'?')+
' h · responsável: '+(o.limit_by||'—');
chip.onclick=()=>openPanel(o.id);bar.append(chip);
});
if(late.length>10)bar.append(node('span','+'+(late.length-10),'lbl'));
if(may('manage'))bar.append(button('Editar tempos',()=>stageLimitsDialog(),'btn ghost'));
}
function renderBoard(){
renderLatebar();
renderFilters();
const active=board.orders.filter(o=>['rec','tra','imp'].includes(o.state)&&!o.cancelled_at);
const open=board.orders.filter(o=>o.state!=='fin'&&!o.cancelled_at).length;
@@ -1049,9 +1069,10 @@ function card(order,place){
c.setAttribute('aria-label','Pedido #'+order.number+', '+who.title+': '+step);
const top=node('span',undefined,'ctop'), info=node('span',undefined,'cinfo');
const row=node('span',undefined,'crow');
const late=stalled(order)&&!order.cancelled_at;
const age=node('span',shortAgo(order.updated_at),'age'+(late?' late tip-l':''));
if(late)age.dataset.tip='Parado: sem mudar de etapa desde '+when(order.updated_at);
const late=!!order.late&&!order.cancelled_at;
const age=node('span',shortAgo(order.state_since||order.updated_at),'age'+(late?' late tip-l'+(order.late==='bad'?' late2':''):''));
if(late)age.dataset.tip='Fora do tempo: '+(order.state_hours??'?')+' h nesta etapa · limite '+
(order.limit_hours??'?')+' h · responsável: '+(order.limit_by||'—');
row.append(node('span','#'+order.number,'num'),originTag(order),age);
const name=node('span',who.title,'cname');name.title=[who.legal,who.mail].filter(Boolean).join(' · ')||who.title;
const meta=node('span',undefined,'cmeta');meta.append(node('span',productLine(s.items)));
@@ -1194,6 +1215,31 @@ function formDialog(title,{text,fields=[],label='Salvar',tone='pri',host,width,n
}
// The old name, for the dialogs of Usuários and the rework.
function dialog(title,fields,onsave){return formDialog(title,{fields,onsave:async()=>{await onsave();}});}
// Front 11: Gestão edits the acceptable time and the person responsible for
// each column. The cards read the same table on the next board refresh.
const STAGE_LABELS={rec:'Arte recebida',tra:'Arte conferida',imp:'Imprimindo',rev:'Revisão',fin:'Finalizado sem retirada'};
function stageLimitsDialog(){
api('/stage-limits').then(({limits})=>{
const current=Object.fromEntries((limits||[]).map(limit=>[limit.state,limit]));
const inputs={},fields=[];
for(const state of ['rec','tra','imp','rev','fin']){
const limit=current[state]||{hours:2,responsible:''};
const hours=node('input');hours.type='number';hours.min='0.1';hours.step='0.5';hours.value=limit.hours;
const who=node('input');who.value=limit.responsible||'';who.maxLength=80;
inputs[state]={hours,who};
fields.push(field(STAGE_LABELS[state]+' (horas)',hours,state==='fin'?'Use 72 para 3 dias.':''));
fields.push(field('Responsável por '+STAGE_LABELS[state].toLowerCase(),who));
}
formDialog('Tempos aceitáveis por etapa',{host:$('drawer'),width:640,fields,
note:'Amarelo ao passar do limite; vermelho no dobro.',
onsave:async()=>{
const limits=Object.entries(inputs).map(([state,{hours,who}])=>({
state,hours:Number(hours.value),responsible:who.value.trim()}));
await api('/stage-limits',{limits});
say('Tempos aceitáveis atualizados.');await load();
}});
}).catch(error=>say(error.message,true));
}
function field(label,input,hint){
const l=node('label',undefined,'fld');l.append(label,input);if(hint)l.append(node('small',hint));return l;
}
@@ -2565,10 +2611,13 @@ async function loadStats(){
const tr=node('tr'),name=node('td'),line=node('span',undefined,'stagecell');
line.append(svgIcon(GLYPH[state],'sg'+(state==='cor'?' cor':'')),board.states[state]);name.append(line);
const st=data.stages[state], now=data.waiting[state];
const limit=data.stage_limits?.[state], late=data.late?.[state]||{count:0,today:0};
// Orders; when some came back to the stage, how many times it was entered.
const passed=st?plural(st.orders,'pedido','pedidos')+(st.passages>st.orders?', '+st.passages+' passagens':''):'nenhum';
name.append(node('span',passed,'sub'));
tr.append(name,node('td',st?duration(st.median_hours):'—','r strong'),
node('td',limit?duration(limit.hours):'—','r'),
node('td',late.count?String(late.count)+(late.today?' · '+late.today+' hoje':''):'—','r'),
node('td',now?plural(now.orders,'pedido','pedidos')+', o mais antigo há '+duration(now.oldest_hours):'nenhum','muted'));
return tr;}));
// Speed (item 0.12): average and p95 of what the customer feels.