fix: Kanban pulls and final approvals stop failing on stale or missing context
Sentry DTF-WEB-4..7 (12/11): - Pulling a card with no machine asks which machine takes it (gestão and admins); an operator always pulls to the machine of their session. - The alert before a pull only offers Feito/Adiar to the machine's own operator or management, as the machine sheet does. - A final-file approval from a dialog opened before the same approval went through reloads and says it was already approved, instead of the 409 "O pedido mudou". Built by Prensa; machine cards shared between the two choosers. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,26 @@
|
||||
ME, myMachine, move, load, openFilters, closeFilters, ROLE_NAMES and kanbanTheme (theme.js). */
|
||||
// ---- Machines and users ----------------------------------------------------
|
||||
|
||||
// One machine to choose: what it prints now, and who else is on it.
|
||||
function machineChoice(machine,mine=false){
|
||||
const b=node('button',undefined,'mchoice'+(mine?' on':''));b.type='button';b.setAttribute('aria-pressed',String(mine));
|
||||
b.dataset.machine=machine.id;
|
||||
const head=node('span',undefined,'mhead');head.append(node('b',machine.name));
|
||||
if(mine){const tick=node('span',undefined,'tick');tick.append(svgIcon(IC.check,'i s'));head.append(tick);}
|
||||
b.append(head,node('span',machine.products.map(p=>PRODUCT_LABEL[p]).join(' e ')||'Nenhum produto','sub'));
|
||||
const here=board.orders.filter(o=>o.state==='imp'&&!o.cancelled_at&&o.machine?.id===machine.id)
|
||||
.sort((x,y)=>(x.printing==='imprimindo'?0:1)-(y.printing==='imprimindo'?0:1));
|
||||
for(let i=0;i<Math.max(board.printing_cap||2,here.length);i++){
|
||||
const o=here[i],job=node('span',undefined,'job');
|
||||
if(o)job.append(node('i',undefined,o.printing==='ripando'?'ripmark':'runmark'),node('span','#'+o.number,'code'),node('em',o.printing==='ripando'?'ripando':'imprimindo'));
|
||||
else job.append(node('i',undefined,'freemark'),node('span','livre','free'));
|
||||
b.append(job);
|
||||
}
|
||||
if(machine.operators){const others=machine.operators.filter(op=>op.name!==(ME.name||ME.email));
|
||||
b.append(node('span',others.length?others.map(op=>op.name).join(', ')+(others.length>1?' estão nela':' está nela'):'Ninguém mais nela','who'));}
|
||||
return b;
|
||||
}
|
||||
|
||||
// "Em qual máquina você está?" (Dropstar's third round, item 12): after signing
|
||||
// in, required for the operator, and for Gestão and the administrators with
|
||||
// "Não estou em máquina". Per session: one person on two computers runs two
|
||||
@@ -23,21 +43,7 @@ function askMachine(again=false){
|
||||
// Each machine with what it is printing, and who is on it now.
|
||||
const list=node('div',undefined,'mchoices');
|
||||
for(const machine of (board.machines||[]).filter(x=>x.active)){
|
||||
const mine=current?.id===machine.id;
|
||||
const b=node('button',undefined,'mchoice'+(mine?' on':''));b.type='button';b.setAttribute('aria-pressed',String(mine));
|
||||
const head=node('span',undefined,'mhead');head.append(node('b',machine.name));
|
||||
if(mine){const tick=node('span',undefined,'tick');tick.append(svgIcon(IC.check,'i s'));head.append(tick);}
|
||||
b.append(head,node('span',machine.products.map(p=>PRODUCT_LABEL[p]).join(' e ')||'Nenhum produto','sub'));
|
||||
const here=board.orders.filter(o=>o.state==='imp'&&!o.cancelled_at&&o.machine?.id===machine.id)
|
||||
.sort((x,y)=>(x.printing==='imprimindo'?0:1)-(y.printing==='imprimindo'?0:1));
|
||||
for(let i=0;i<Math.max(board.printing_cap||2,here.length);i++){
|
||||
const o=here[i],job=node('span',undefined,'job');
|
||||
if(o)job.append(node('i',undefined,o.printing==='ripando'?'ripmark':'runmark'),node('span','#'+o.number,'code'),node('em',o.printing==='ripando'?'ripando':'imprimindo'));
|
||||
else job.append(node('i',undefined,'freemark'),node('span','livre','free'));
|
||||
b.append(job);
|
||||
}
|
||||
if(machine.operators){const others=machine.operators.filter(op=>op.name!==(ME.name||ME.email));
|
||||
b.append(node('span',others.length?others.map(op=>op.name).join(', ')+(others.length>1?' estão nela':' está nela'):'Ninguém mais nela','who'));}
|
||||
const b=machineChoice(machine,current?.id===machine.id);
|
||||
b.onclick=()=>choose(machine.id);list.append(b);
|
||||
}
|
||||
if(!list.children.length)list.append(node('p','Nenhuma máquina ativa. Peça ao Administrador para cadastrar em Usuários, Máquinas.','empty'));
|
||||
@@ -500,14 +506,19 @@ async function machineEntryForm(machineId, preset={}, data=null){
|
||||
|
||||
// The alert shown when a card is pulled between one file and the next. Resolves
|
||||
// true when the alert was resolved or postponed, false when the user backs out.
|
||||
// Only the machine's own operator (or management) may resolve it, as in the
|
||||
// machine sheet: the API refuses anyone else (DTF-WEB-5/6).
|
||||
function machineAlertDialog(order,machineId,alert){
|
||||
return new Promise(resolve=>{
|
||||
let decided=false;
|
||||
const machine=(board.machines||[]).find(row=>row.id===machineId);
|
||||
const allowed=ME?.role!=='operador'||myMachine()?.id===machineId;
|
||||
const made=node('button','Marcar como feito','btn pri');made.type='button';
|
||||
const later=node('button','Adiar uma vez','btn');later.type='button';
|
||||
const back=node('button','Voltar','btn ghost right');back.type='button';
|
||||
const modalEntry=modal('Antes do próximo arquivo',{text:alert.text,host:dialogHost(),width:520,
|
||||
role:'alertdialog',foot:[...(alert.snoozable?[later]:[]),back,made],
|
||||
body:allowed?[]:[node('p','Só quem está na '+(machine?.name||'máquina')+' resolve este aviso.','nnote')],
|
||||
role:'alertdialog',foot:allowed?[...(alert.snoozable?[later]:[]),back,made]:[back],
|
||||
onclose:()=>{if(!decided)resolve(false);}});
|
||||
back.onclick=()=>modalEntry.close();
|
||||
const run=async action=>{
|
||||
@@ -537,15 +548,53 @@ function machineAlertDialog(order,machineId,alert){
|
||||
});
|
||||
}
|
||||
|
||||
// Pulling a card to a machine always passes the sheet's blocking alert first,
|
||||
// then the server re-checks it under the machine's lock.
|
||||
async function pullTo(order, machineId){
|
||||
const target=machineId||order.machine?.id||myMachine()?.id||null;
|
||||
if(target){
|
||||
const machine=(board.machines||[]).find(row=>row.id===target);
|
||||
const alert=(machine?.alerts||[]).find(row=>row.blocking);
|
||||
if(alert&&!await machineAlertDialog(order,target,alert))return;
|
||||
// Pulling a card as management, with no session machine: which machine takes
|
||||
// it. The cards look like askMachine's, but the choice only applies to this
|
||||
// pull; the session machine does not change.
|
||||
function choosePullMachine(order){
|
||||
const family=order.snapshot.items.some(i=>i.mode==='uvfile'||i.mode==='uv')?'uv':'textil';
|
||||
const machines=(board.machines||[]).filter(m=>m.active&&m.products.includes(family));
|
||||
if(!machines.length){
|
||||
say('Nenhuma máquina ativa faz '+PRODUCT_LABEL[family]+'.',true);
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
return new Promise(resolve=>{
|
||||
let m=null, chosen=false;
|
||||
const list=node('div',undefined,'mchoices');
|
||||
for(const machine of machines){
|
||||
const b=machineChoice(machine);
|
||||
b.onclick=()=>{chosen=true;m.close();resolve(machine.id);};
|
||||
list.append(b);
|
||||
}
|
||||
const back=node('button','Voltar','btn ghost right');back.type='button';
|
||||
back.onclick=()=>m.close();
|
||||
m=modal('Qual máquina puxa este card?',{host:dialogHost(),width:620,body:[list],foot:[back],
|
||||
onclose:()=>{if(!chosen)resolve(null);}});
|
||||
});
|
||||
}
|
||||
|
||||
// Pulling a card to a machine always passes the sheet's blocking alert first,
|
||||
// then the server re-checks it under the machine's lock. An operator's pulls
|
||||
// always go to the machine of their session (DTF-WEB-4).
|
||||
async function pullTo(order, machineId){
|
||||
let target;
|
||||
if(ME?.role==='operador'){
|
||||
const mine=myMachine();
|
||||
if(!mine){askMachine(true);return;}
|
||||
if(machineId&&machineId!==mine.id){
|
||||
say('Você está na '+mine.name+': o que você puxa vai para ela.',true);return;
|
||||
}
|
||||
target=mine.id;
|
||||
}else{
|
||||
target=machineId||order.machine?.id||myMachine()?.id||null;
|
||||
if(!target){
|
||||
target=await choosePullMachine(order);
|
||||
if(!target)return;
|
||||
}
|
||||
}
|
||||
const machine=(board.machines||[]).find(row=>row.id===target);
|
||||
const alert=(machine?.alerts||[]).find(row=>row.blocking);
|
||||
if(alert&&!await machineAlertDialog(order,target,alert))return;
|
||||
try{
|
||||
await move(order,'imp','',target);
|
||||
}catch(e){
|
||||
|
||||
Reference in New Issue
Block a user