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

@@ -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.