feat: Kanban columns are queues, and a card can be dragged up or down
Some checks failed
Build and deploy / Validate source (push) Successful in 4s
Build and deploy / Integration suite on a real stack (push) Failing after 3m24s
Build and deploy / Secret scan and release gate (push) Successful in 8s
Build and deploy / Publish images (push) Has been skipped

Each column is sorted explicitly by payment time, first paid on top, however
the board's list was put together (older finished orders, one opened from the
search). A card dragged within its column lands between the two it was
dropped between (queue_key, halfway between their keys) and keeps that place
for everyone; moving to another stage clears it. Reordering is not activity:
the stalled clock keeps running.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-10-02 16:57:31 -03:00
parent d7b1eaae6d
commit 894e75fd94
5 changed files with 114 additions and 12 deletions

View File

@@ -356,3 +356,7 @@ a.zap{display:inline-flex;align-items:center;gap:4px;vertical-align:bottom}
/* The order code the customer sees, beside the operators' number. */
.ocode{display:inline-flex;align-items:center;gap:6px;font-size:13px;color:var(--muted)}
/* Where a card dragged within its column will land. */
.card.drop-before{box-shadow:0 -3px 0 0 var(--accent)}
.card.drop-after{box-shadow:0 3px 0 0 var(--accent)}

View File

@@ -300,7 +300,9 @@ function renderBoard(){
$('board-summary').textContent=metres(queued)+' em produção';
$('kan').replaceChildren(...Object.entries(board.states).map(([state,title])=>{
const column=node('section',undefined,'col');column.dataset.state=state;column.style.setProperty('--c',STAGE_COLORS[state]);
const orders=board.orders.filter(o=>o.state===state&&matches(o));
// A queue: the order paid first is on top, the newest at the bottom, however
// the list was put together (older finished ones, one opened from the search).
const orders=board.orders.filter(o=>o.state===state&&matches(o)).sort((a,b)=>queueKey(a)-queueKey(b)||a.number-b.number);
const total=orders.reduce((s,o)=>s+o.snapshot.items.reduce((t,i)=>t+Number(i.billed_metres),0),0);
const head=node('div',undefined,'col-head');const line=node('div');
const swatch=node('span',undefined,'swatch');swatch.style.setProperty('--c',STAGE_COLORS[state]);
@@ -313,11 +315,18 @@ function renderBoard(){
if(state==='fin'&&finishedMore&&filter==='all')moreButton(column,true,loadOlderFinished);
// Dragging only goes forward to the next stage. Going back or asking for a
// correction needs a reason, so those happen in the order panel.
column.ondragover=e=>{if(!column.classList.contains('allowed'))return;e.preventDefault();column.classList.add('target');};
column.ondragleave=()=>column.classList.remove('target');
column.ondragover=e=>{
if(dragging?.state===state&&state!=='fin'){e.preventDefault();markDrop(column,e.clientY);return;}
if(!column.classList.contains('allowed'))return;e.preventDefault();column.classList.add('target');};
column.ondragleave=e=>{if(!column.contains(e.relatedTarget)){column.classList.remove('target');clearDrop();}};
column.ondrop=async e=>{e.preventDefault();column.classList.remove('target');
const order=board.orders.find(o=>o.id===e.dataTransfer.getData('text/plain'));
if(order&&order.state!==state)try{await move(order,state);}catch(error){say(error.message,true);}};
if(!order)return;
try{
if(order.state!==state)await move(order,state);
else if(state!=='fin')await reorder(order,column,e.clientY);
}catch(error){say(error.message,true);}
finally{clearDrop();}};
return column;
}));
}
@@ -345,14 +354,44 @@ function card(order){
if(flags.children.length)c.append(flags);
c.onclick=()=>openPanel(order.id);
c.ondragstart=e=>{
dragging=order;
e.dataTransfer.setData('text/plain',order.id);
const forward=board.transitions[order.state].filter(s=>s!=='cor');
for(const col of document.querySelectorAll('.col[data-state]'))col.classList.toggle('allowed',forward.includes(col.dataset.state));
say(forward.length?'Mover para '+forward.map(s=>board.states[s]).join(' ou '):'Pedido finalizado',false,60000);
say((forward.length?'Mover para '+forward.map(s=>board.states[s]).join(' ou ')+', ou ':'')+'arraste para cima ou para baixo para mudar a prioridade',false,60000);
};
c.ondragend=()=>{for(const col of document.querySelectorAll('.col'))col.classList.remove('allowed','target');say('');};
c.ondragend=()=>{dragging=null;clearDrop();for(const col of document.querySelectorAll('.col'))col.classList.remove('allowed','target');say('');};
return c;
}
// The column's queue: payment time, unless an operator dragged the card to
// another place (queue_key, seconds like the payment time).
const queueKey=o=>o.queue_key!=null?Number(o.queue_key):new Date(o.created_at).getTime()/1000;
let dragging=null;
// Where a card dropped at this height lands: the card it goes before, if any.
function dropTarget(column,y){
const cards=[...column.querySelectorAll('.card')].filter(c=>c.dataset.card!==dragging?.id);
return cards.find(c=>{const r=c.getBoundingClientRect();return y<r.top+r.height/2;})||null;
}
function markDrop(column,y){
clearDrop();
const target=dropTarget(column,y);
if(target)target.classList.add('drop-before');
else{const cards=[...column.querySelectorAll('.card')].filter(c=>c.dataset.card!==dragging?.id);cards.at(-1)?.classList.add('drop-after');}
}
function clearDrop(){for(const c of document.querySelectorAll('.drop-before,.drop-after'))c.classList.remove('drop-before','drop-after');}
async function reorder(order,column,y){
const target=dropTarget(column,y);
const cards=[...column.querySelectorAll('.card')].map(c=>c.dataset.card).filter(id=>id!==order.id);
const at=target?cards.indexOf(target.dataset.card):cards.length;
const after=cards[at-1]||null, before=cards[at]||null;
if(!after&&!before)return;
// Dropped where it already was: nothing to save.
const current=[...column.querySelectorAll('.card')].map(c=>c.dataset.card);
const was=current.indexOf(order.id);
if(current[was-1]===(after||undefined)&&current[was+1]===(before||undefined))return;
await api('/orders/'+order.id+'/queue',{after,before});
await load();
}
async function loadOlderFinished(){
const shown=board.orders.filter(o=>o.state==='fin').sort((a,b)=>a.created_at<b.created_at?-1:1);
const oldest=shown[0];const params=new URLSearchParams({limit:'50'});