diff --git a/app/api/operator.py b/app/api/operator.py index d415136..9e021e9 100644 --- a/app/api/operator.py +++ b/app/api/operator.py @@ -1327,7 +1327,7 @@ class FolderSync(StrictModel): @router.post('/api/operator/queue/folder') def queue_folder(body: FolderSync, request: Request, user=Depends(can('print'))): """What the Kanban's automatic folders should hold. `early` is Dropstar's - three folders (2026-10-26): the files of orders in Arte recebida and Arte + stage folders (2026-10-26): the files of orders in Arte recebida and Arte conferida, and, for the orders the folders already hold, their files while they print, are checked in Revisão and sit in Finalizado, so one taken out of a folder can be fetched again when the order moves on. With `since`, diff --git a/tests/browser_test.mjs b/tests/browser_test.mjs index e60f192..2f4ce73 100644 --- a/tests/browser_test.mjs +++ b/tests/browser_test.mjs @@ -250,13 +250,26 @@ try{ await kanban.eval('syncFolder(true)'); await waitFor(async()=>!(await savedFiles('2. Arte conferida')).includes('pedido-0-item-1-excluido.png'),'deleted order file removed',30000); } - if(state==='fin'){ - // Finalized: the file goes to Finalizado, out of the queue. + if(state==='rev'||state==='fin'){ + // In Revisão the file leaves the queue for 4. Revisão; finalized, it + // goes on to 5. Finalizado (Dropstar's numbering, 2026-10-30). const prefix='DTF-'+await kanban.eval(`board.orders.find(o=>o.id==='${oid}').number`)+'-item-1'; + const [now,before]=state==='rev'?['4. Revisão','2. Arte conferida']:['5. Finalizado','4. Revisão']; await waitFor(()=>kanban.eval('!FOLDER.busy'),'folder idle',60000); await kanban.eval('syncFolder(true)'); - await waitFor(async()=>(await savedFiles('3. Finalizado')).some(n=>n.startsWith(prefix)),'final file in Finalizado',30000); - assert.equal((await savedFiles('2. Arte conferida')).some(n=>n.startsWith(prefix)),false); + await waitFor(async()=>(await savedFiles(now)).some(n=>n.startsWith(prefix)),'final file in '+now,30000); + assert.equal((await savedFiles(before)).some(n=>n.startsWith(prefix)),false); + } + if(state==='fin'){ + // The folder of before the numbering goes once nothing is left in it. + const folders=()=>kanban.eval(`(async()=>{const out=[];for await(const [name,h] of window.picked.entries())if(h.kind==='directory')out.push(name);return out.sort();})()`); + await kanban.eval(`window.picked.getDirectoryHandle('3. Finalizado',{create:true})`); + await waitFor(()=>kanban.eval('!FOLDER.busy'),'folder idle',60000); + await kanban.eval('syncFolder(true)'); + await waitFor(async()=>!(await folders()).includes('3. Finalizado'),'old Finalizado folder removed',30000); + const tree=await folders(); + for(const name of ['1. Arte recebida','2. Arte conferida','3. Imprimindo','4. Revisão','5. Finalizado','Recibos']) + assert.ok(tree.includes(name),name+' missing from '+tree.join(', ')); } } // Undo a mistaken move from the panel: one stage back with an internal reason. diff --git a/web/kanban.js b/web/kanban.js index 63d2bea..1070c7d 100644 --- a/web/kanban.js +++ b/web/kanban.js @@ -207,7 +207,7 @@ function download(uid){return async()=>{ const link=node('a');link.href=result.url;link.referrerPolicy='no-referrer';link.download=result.name;link.click(); };} // ---- Automatic folder ------------------------------------------------------ -// The orders' files, kept by this browser in Dropstar's three folders +// The orders' files, kept by this browser in Dropstar's folders // (2026-10-26) inside the one chosen, while the Kanban is open. It is switched // on in Integrações, on a computer of the factory that reaches the server's // folder: the folder belongs to that browser, not to the account. Chrome and @@ -223,11 +223,16 @@ const kv=(()=>{let opened;const open=()=>opened||(opened=new Promise((ok,fail)=> return {get:k=>run('readonly',s=>s.get(k)),set:(k,v)=>run('readwrite',s=>s.put(v,k)),del:k=>run('readwrite',s=>s.delete(k))};})(); const BRAVE_FLAG='brave://flags/#file-system-access-api'; // Where an order's file is, by its stage: it arrives in Arte recebida, moves -// to Arte conferida (the queue) with the card and stays there while it prints -// and is checked in Revisão, then goes to Finalizado, kept 30 days. Correção, -// a cancellation or a deletion takes it out; a replaced final is swapped. -// Numbered so a folder listing shows them in the flow's order. -const STAGE_FOLDERS={rec:'1. Arte recebida',tra:'2. Arte conferida',imp:'2. Arte conferida',rev:'2. Arte conferida',fin:'3. Finalizado'}; +// to Arte conferida (the queue) with the card and stays there while it +// prints, goes to Revisão with the card, then to Finalizado, kept 30 days. +// Correção, a cancellation or a deletion takes it out; a replaced final is +// swapped. Numbered as Dropstar set them (2026-10-30), so a folder listing +// shows the flow's order; 3. Imprimindo is where the machines' hot folders go. +const STAGE_FOLDERS={rec:'1. Arte recebida',tra:'2. Arte conferida',imp:'2. Arte conferida',rev:'4. Revisão',fin:'5. Finalizado'}; +const PRINTING_FOLDER='3. Imprimindo'; +// The names before 2026-10-30: their files move to the new ones, and the old +// folder goes once it is empty. +const OLD_FOLDERS=['3. Finalizado']; const KEEP_FINISHED_DAYS=30; // The pickup receipts (item 14): the counter's print queue watches this one. const RECEIPTS_FOLDER='Recibos'; @@ -290,12 +295,12 @@ function folderCard(){ ? integration({name,state:FOLDER.error?'Verificar':'Ligada',tone:FOLDER.error?'warn':'ok', summary:FOLDER.error||FOLDER.status||'Baixando na pasta de downloads do Firefox · '+folderCount(), details:how,extra:[ghost('Desligar',()=>setDownloads(false))]}) - : integration({name,state:'Desligada',tone:'off',summary:'No Firefox, baixa sozinho os arquivos que entram em Arte conferida; as três pastas pedem o Chrome ou o Edge.', + : integration({name,state:'Desligada',tone:'off',summary:'No Firefox, baixa sozinho os arquivos que entram em Arte conferida; as pastas do fluxo pedem o Chrome ou o Edge.', actions:[act('Ligar',()=>setDownloads(true))],details:how}); }else if(!h){ - row=integration({name,state:'Desligada',tone:'off',summary:'Salva sozinho os arquivos dos pedidos em três pastas, Arte recebida, Arte conferida e Finalizado, e o recibo de cada retirada em Recibos.', + row=integration({name,state:'Desligada',tone:'off',summary:'Salva sozinho os arquivos dos pedidos nas pastas do fluxo, de 1. Arte recebida a 5. Finalizado, e o recibo de cada retirada em Recibos.', actions:[act('Escolher pasta',chooseFolder)], - details:[node('p','Escolha uma vez a pasta principal, na rede do servidor: o Kanban cria dentro dela as três pastas e move o arquivo conforme o card anda. '+ + details:[node('p','Escolha uma vez a pasta principal, na rede do servidor: o Kanban cria dentro dela as pastas do fluxo e move o arquivo conforme o card anda. '+ 'Os arquivos levam o número do pedido no nome. Funciona neste computador, com o Kanban aberto e um usuário que vê todos os pedidos, como o de Gestão.')]}); }else if(!FOLDER.granted){ row=integration({name,state:'Liberar',tone:'warn',summary:'O navegador pede um clique para voltar a salvar em “'+h.name+'”.', @@ -305,8 +310,8 @@ function folderCard(){ summary:FOLDER.error||FOLDER.status||'Salvando em “'+h.name+'” · '+folderCount(), details:[['Pasta','“'+h.name+'”'],['Arquivos salvos',String(FOLDER.saved.size)], ['Último',FOLDER.last?FOLDER.last.toLocaleTimeString('pt-BR',{hour:'2-digit',minute:'2-digit'}):'—'], - node('p','Dentro de “'+h.name+'”: o arquivo do pedido chega em Arte recebida, passa para Arte conferida quando o card vai para lá '+ - '(e fica lá enquanto imprime e na Revisão) e vai para Finalizado quando o pedido é finalizado, onde fica '+KEEP_FINISHED_DAYS+' dias.'), + node('p','Dentro de “'+h.name+'”: o arquivo do pedido chega em '+STAGE_FOLDERS.rec+', passa para '+STAGE_FOLDERS.tra+' quando o card vai para lá '+ + 'e fica lá enquanto imprime, vai para '+STAGE_FOLDERS.rev+' com o card e para '+STAGE_FOLDERS.fin+' quando o pedido é finalizado, onde fica '+KEEP_FINISHED_DAYS+' dias.'), node('p','Pedido de retirada que chega em Finalizado: o recibo para a bobina de 80 mm vai para '+RECEIPTS_FOLDER+', uma vez só, por um dos computadores com a pasta ligada.'), node('p','Pedido cancelado, excluído ou devolvido para correção: o arquivo sai das pastas. Arquivo trocado: a versão antiga sai. '+ 'Pedidos que já estavam imprimindo quando a pasta foi escolhida não são baixados. Se este computador ficar desligado, '+ @@ -367,14 +372,14 @@ async function writeWhole(dir,name,source){ await whole.write(await temp.getFile());await whole.close();await dir.removeEntry(temp.name);} } const stageDir=name=>FOLDER.handle.getDirectoryHandle(name,{create:true}); -// The three folders exist from the moment the main one is chosen, empty or not. -const makeStageFolders=()=>Promise.all([...new Set(Object.values(STAGE_FOLDERS))].map(stageDir)); +// The flow's folders exist from the moment the main one is chosen, empty or not. +const makeStageFolders=()=>Promise.all([...new Set([...Object.values(STAGE_FOLDERS),PRINTING_FOLDER,RECEIPTS_FOLDER])].map(stageDir)); // Remove a saved file from its folder; one already gone (someone took it) is fine. async function removeSaved(rec){ const dir=await stageDir(rec.folder); await dir.removeEntry(rec.name).catch(e=>{if(e.name!=='NotFoundError')throw e;}); } -// To another of the three folders. False when the file is no longer where it was. +// To another of the flow's folders. False when the file is no longer where it was. async function moveSaved(rec,to){ const from=await stageDir(rec.folder), dest=await stageDir(to);let file; try{file=await from.getFileHandle(rec.name);}catch(e){if(e.name==='NotFoundError')return false;throw e;} @@ -414,7 +419,7 @@ async function syncFolder(force=false){ let removed=0, moved=0, saved=0; const record=async(uid,file,folder)=>{ FOLDER.saved.set(uid,{order:file.order,item:file.item,name:file.name,folder, - ...(folder===STAGE_FOLDERS.fin?{at:Date.now()}:{})}); + ...(folder===STAGE_FOLDERS.fin?{at:file.at||Date.now()}:{})}); FOLDER.last=new Date();await keepSaved();}; if(stages)for(const [uid,rec] of [...FOLDER.saved]){ if(!rec.order||!rec.folder)continue; @@ -429,6 +434,8 @@ async function syncFolder(force=false){ if(now&&now.upload_id===uid){await fetchInto(await stageDir(target),now);await record(uid,now,target);moved++;} else{FOLDER.saved.delete(uid);await keepSaved();} } + if(stages)for(const old of OLD_FOLDERS) + if(![...FOLDER.saved.values()].some(r=>r.folder===old))await FOLDER.handle.removeEntry(old).catch(()=>{}); // New files, each into its stage's folder: the server sends those in Arte // recebida and Arte conferida, and the orders paid since the folders were // chosen in any stage, so what passed while this computer was off comes in