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

@@ -360,3 +360,9 @@ a.zap{display:inline-flex;align-items:center;gap:4px;vertical-align:bottom}
/* 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)}
/* "Atualizar" and how often it happens by itself, as one control. */
.refresh{display:inline-flex;align-items:stretch;border:1px solid var(--line2);border-radius:8px;overflow:hidden}
.refresh .btn{border:0;border-radius:0;display:inline-flex;align-items:center;gap:6px}
.refresh select{height:36px;padding:0 28px 0 10px;border:0;border-left:1px solid var(--line2);background:transparent;color:var(--muted);font:inherit;font-size:13.5px;font-weight:600;cursor:pointer}
.refresh select option{background:var(--card);color:var(--tx)}

View File

@@ -32,7 +32,13 @@
</div>
<span id="tiny" class="tinydot"></span>
<span id="who" class="who"></span>
<button class="btn ghost" id="refresh" type="button">Atualizar</button>
<div class="refresh">
<button class="btn ghost" id="refresh" type="button"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21 12a9 9 0 1 1-2.64-6.36"></path><path d="M21 3v6h-6"></path></svg>Atualizar</button>
<select id="refresh-every" aria-label="Atualizar sozinho a cada">
<option value="0">Desligado</option><option value="10">10 s</option><option value="30">30 s</option>
<option value="60">1 min</option><option value="300">5 min</option><option value="900">15 min</option>
</select>
</div>
<button class="btn ghost" id="logout" type="button">Sair</button>
</header>
<p id="status" role="status"></p>

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();