feat: the Kanban refreshes by itself, every 10 s to 15 min, and says what is new
All checks were successful
Build and deploy / Validate source (push) Successful in 6s
Build and deploy / Integration suite on a real stack (push) Successful in 2m37s
Build and deploy / Secret scan and release gate (push) Successful in 5s
Build and deploy / Publish images (push) Successful in 52s

Beside "Atualizar", a picker sets how often the Kanban reloads by itself (off,
10 s, 30 s, 1, 5 or 15 min; 30 s by default, remembered by each browser). It
waits while the operator types, drags or has an order open, and with the tab
hidden it still looks at most once a minute. A new order in "Arte recebida"
or a new quote to review shows a notice, and the count goes into the tab's
title until the operator looks at it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-10-02 18:03:21 -03:00
parent c3c56a7f21
commit 4b804a2c85
3 changed files with 70 additions and 4 deletions

View File

@@ -221,14 +221,17 @@ function itemPreview(item){
// ---- Loading and tabs ------------------------------------------------------
async function load(){
// What the last load saw, so the next one can tell what is new.
let seenOrders=null, seenPending=null, unseen=0;
async function load(quiet=false){
try{
board=absorb(await api('/board'));
noticeNew(quiet);
const known=new Set(board.orders.map(o=>o.id));
board.orders.push(...olderFinished.filter(o=>!known.has(o.id)));
if(finishedMore===null)finishedMore=board.finished_total>board.finished_shown;
$('login').hidden=true;$('app').hidden=false;
say('Atualizado às '+new Date().toLocaleTimeString('pt-BR')+tinyNotice,false,tinyNotice?6000:2500);
if(!quiet)say('Atualizado às '+new Date().toLocaleTimeString('pt-BR')+tinyNotice,false,tinyNotice?6000:2500);
render();
}catch(e){
if(e.status===401||e.status===503){$('app').hidden=true;$('login').hidden=false;$('drawer').hidden=true;}
@@ -1106,5 +1109,56 @@ document.addEventListener('keydown',e=>{
});
$('login').onsubmit=async e=>{e.preventDefault();try{await api('/login',{email:$('email').value,password:$('password').value});await load();}catch(error){say(error.message,true);}finally{$('password').value='';}};
$('logout').onclick=async()=>{await api('/logout',{});for(const key of Object.keys(localStorage))if(key.startsWith('dtf-'))localStorage.removeItem(key);location.reload();};
$('refresh').onclick=load;
$('refresh').onclick=()=>load();
// ---- Refreshing by itself --------------------------------------------------
// New orders and quotes to review since the last load: a notice, and the
// count in the tab's title until the operator looks at the tab.
function noticeNew(quiet){
const orders=new Set(board.orders.map(o=>o.id));
const fresh=seenOrders?board.orders.filter(o=>!seenOrders.has(o.id)&&o.state==='rec'&&!o.cancelled_at):[];
const reviews=seenPending===null?0:Math.max(0,board.pending_total-seenPending);
seenOrders=orders;seenPending=board.pending_total;
if(!fresh.length&&!reviews)return;
const parts=[];
if(fresh.length)parts.push(fresh.length===1?'Novo pedido #'+fresh[0].number:fresh.length+' pedidos novos');
if(reviews)parts.push(reviews===1?'1 cotação nova para revisar':reviews+' cotações novas para revisar');
say(parts.join(' · '),false,10000);
if(document.hidden||quiet){unseen+=fresh.length+reviews;document.title='('+unseen+') Kanban DTF';}
}
document.addEventListener('visibilitychange',()=>{if(!document.hidden){unseen=0;document.title='Kanban DTF';}});
addEventListener('focus',()=>{unseen=0;document.title='Kanban DTF';});
// Every N seconds, chosen beside "Atualizar" and remembered by this browser.
// Never under the operator's hands: not while typing, dragging or with an
// order open. With the Kanban's tab hidden it still looks, at most once a
// minute, so the tab's title can say a new order arrived.
let autoTimer=null, lastAuto=0;
function busy(){
const a=document.activeElement;
const typing=!!(a&&a.matches&&a.matches('input,textarea,select')&&a.id!=='refresh-every');
return $('app').hidden||!!dragging||!$('drawer').hidden||typing;
}
function autoRefresh(){
if(busy())return;
if(document.hidden&&Date.now()-lastAuto<60000)return;
lastAuto=Date.now();
load(true).catch(()=>{});
}
function scheduleAuto(){
clearInterval(autoTimer);
const secs=Number($('refresh-every').value);
if(secs)autoTimer=setInterval(autoRefresh,secs*1000);
}
(()=>{
let saved='30';
try{saved=localStorage.getItem('dtf-refresh-every')??'30';}catch(_){}
$('refresh-every').value=[...$('refresh-every').options].some(o=>o.value===saved)?saved:'30';
$('refresh-every').onchange=()=>{
try{localStorage.setItem('dtf-refresh-every',$('refresh-every').value);}catch(_){}
scheduleAuto();$('refresh-every').blur();
};
scheduleAuto();
})();
load();