From 0088158dc007ee2b704432b46b6abe0db6b3b961 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=AA=20Faleiros?= Date: Mon, 26 Oct 2026 17:25:01 -0300 Subject: [PATCH] feat: the three folders are created when the main one is chosen, numbered in the flow's order Tried on a local Kanban with Dropstar's flow: the folders appeared only with the first file, and a listing showed Arte conferida before Arte recebida. - "1. Arte recebida", "2. Arte conferida" and "3. Finalizado" are created as soon as the main folder is chosen or released, and again on every round if someone deletes one - numbered, a folder listing shows them in the order the file moves Co-Authored-By: Claude Opus 5.5 --- docs/CONTEXT.md | 10 ++++++---- tests/browser_test.mjs | 20 ++++++++++---------- web/kanban.js | 11 ++++++++--- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/docs/CONTEXT.md b/docs/CONTEXT.md index 25c741f..02ebf5d 100644 --- a/docs/CONTEXT.md +++ b/docs/CONTEXT.md @@ -340,10 +340,12 @@ Dropstar's three folders (asked 2026-10-23, agreed 2026-10-26): the Kanban, open in Chrome or Edge on a factory computer that reaches the server's folder, signed in with a profile that sees every order (Gestão), keeps the orders' files in three folders it creates inside the one chosen in -Integrações ("Pastas dos pedidos"): Arte recebida (the file arrives when the -order does), Arte conferida (the queue; the file moves there with the card -and stays while it prints and is checked in Revisão) and Finalizado (when the -order is released, kept 30 days there). Correção, a cancellation or a +Integrações ("Pastas dos pedidos"), numbered to sort in the flow's order: +"1. Arte recebida" (the file arrives when the order does), "2. Arte +conferida" (the queue; the file moves there with the card and stays while it +prints and is checked in Revisão) and "3. Finalizado" (when the order is +released, kept 30 days there). They are created as soon as the main folder +is chosen. Correção, a cancellation or a deletion takes the file out; a replaced final is swapped. Orders already printing when the folder is chosen are not downloaded. A file someone took out is fetched again only when its order moves on (`POST diff --git a/tests/browser_test.mjs b/tests/browser_test.mjs index 9c55306..c3e4c22 100644 --- a/tests/browser_test.mjs +++ b/tests/browser_test.mjs @@ -222,8 +222,8 @@ try{ // Approved before the queue: already on this computer, in Arte recebida. const early='DTF-'+await kanban.eval(`board.orders.find(o=>o.id==='${oid}').number`)+'-item-1'; await kanban.eval('syncFolder(true)'); - await waitFor(async()=>(await savedFiles('Arte recebida')).some(n=>n.startsWith(early)&&!n.endsWith('.baixando')),'final file saved in Arte recebida',45000); - assert.equal((await savedFiles('Arte conferida')).some(n=>n.startsWith(early)),false); + await waitFor(async()=>(await savedFiles('1. Arte recebida')).some(n=>n.startsWith(early)&&!n.endsWith('.baixando')),'final file saved in Arte recebida',45000); + assert.equal((await savedFiles('2. Arte conferida')).some(n=>n.startsWith(early)),false); } await waitFor(()=>kanban.eval(`!!document.querySelector('[data-order="${oid}"] [data-move="${state}"]')`),'move to '+title); await kanban.click(`[data-order="${oid}"] [data-move="${state}"]`); @@ -231,28 +231,28 @@ try{ if(state==='tra'){ // Entering the queue moves its file to Arte conferida, whole and named after the order. const prefix='DTF-'+await kanban.eval(`board.orders.find(o=>o.id==='${oid}').number`)+'-item-1'; - await waitFor(async()=>(await savedFiles('Arte conferida')).some(n=>n.startsWith(prefix)&&!n.endsWith('.baixando')),'final file in Arte conferida',45000); + await waitFor(async()=>(await savedFiles('2. Arte conferida')).some(n=>n.startsWith(prefix)&&!n.endsWith('.baixando')),'final file in Arte conferida',45000); // Other orders the earlier suites left in the queue may still be coming // down: only once the round ends must no half-written file be left. await waitFor(()=>kanban.eval('!FOLDER.busy'),'folder round finished',60000); - assert.equal((await savedFiles('Arte conferida')).some(n=>n.endsWith('.baixando')),false); - assert.equal((await savedFiles('Arte recebida')).some(n=>n.startsWith(prefix)),false); + assert.equal((await savedFiles('2. Arte conferida')).some(n=>n.endsWith('.baixando')),false); + assert.equal((await savedFiles('1. Arte recebida')).some(n=>n.startsWith(prefix)),false); // A file whose order was deleted leaves the folder. - await kanban.eval(`(async()=>{const dir=await window.picked.getDirectoryHandle('Arte conferida',{create:true}); + await kanban.eval(`(async()=>{const dir=await window.picked.getDirectoryHandle('2. Arte conferida',{create:true}); const f=await dir.getFileHandle('pedido-0-item-1-excluido.png',{create:true}); const w=await f.createWritable();await w.write('x');await w.close(); - FOLDER.saved.set(crypto.randomUUID(),{order:crypto.randomUUID(),item:1,name:'pedido-0-item-1-excluido.png',folder:'Arte conferida'});})()`); + FOLDER.saved.set(crypto.randomUUID(),{order:crypto.randomUUID(),item:1,name:'pedido-0-item-1-excluido.png',folder:'2. Arte conferida'});})()`); await waitFor(()=>kanban.eval('!FOLDER.busy'),'folder idle',60000); await kanban.eval('syncFolder(true)'); - await waitFor(async()=>!(await savedFiles('Arte conferida')).includes('pedido-0-item-1-excluido.png'),'deleted order file removed',30000); + 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. const prefix='DTF-'+await kanban.eval(`board.orders.find(o=>o.id==='${oid}').number`)+'-item-1'; await waitFor(()=>kanban.eval('!FOLDER.busy'),'folder idle',60000); await kanban.eval('syncFolder(true)'); - await waitFor(async()=>(await savedFiles('Finalizado')).some(n=>n.startsWith(prefix)),'final file in Finalizado',30000); - assert.equal((await savedFiles('Arte conferida')).some(n=>n.startsWith(prefix)),false); + 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); } } // 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 eb94e47..49d8dd8 100644 --- a/web/kanban.js +++ b/web/kanban.js @@ -226,7 +226,8 @@ const BRAVE_FLAG='brave://flags/#file-system-access-api'; // 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. -const STAGE_FOLDERS={rec:'Arte recebida',tra:'Arte conferida',imp:'Arte conferida',rev:'Arte conferida',fin:'Finalizado'}; +// 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'}; const KEEP_FINISHED_DAYS=30; const FOLDER={mode:'showDirectoryPicker' in window?'folder':/Firefox\//.test(navigator.userAgent)?'downloads':'none', brave:!!navigator.brave,handle:null,granted:false,downloads:false, @@ -320,11 +321,12 @@ async function chooseFolder(){ FOLDER.handle=handle;FOLDER.granted=true;FOLDER.lastSig=null;FOLDER.error='';FOLDER.last=null; FOLDER.saved=await loadSaved(); await kv.set('folder',handle).catch(()=>{}); - paintFolder();say('Os arquivos dos pedidos vão ser salvos nas três pastas dentro de “'+handle.name+'”.');syncFolder(); + await makeStageFolders(); + paintFolder();say('Pastas '+[...new Set(Object.values(STAGE_FOLDERS))].join(', ')+' criadas dentro de “'+handle.name+'”.');syncFolder(true); } async function releaseFolder(){ FOLDER.granted=(await FOLDER.handle.requestPermission({mode:'readwrite'}))==='granted'; - FOLDER.lastSig=null;FOLDER.error='';paintFolder();if(FOLDER.granted)syncFolder(); + FOLDER.lastSig=null;FOLDER.error='';if(FOLDER.granted)await makeStageFolders();paintFolder();if(FOLDER.granted)syncFolder(true); } async function forgetFolder(){ FOLDER.handle=null;FOLDER.granted=false;FOLDER.error='';FOLDER.status=''; @@ -352,6 +354,8 @@ 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)); // 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); @@ -389,6 +393,7 @@ async function syncFolder(force=false){ if(!force&&sig===FOLDER.lastSig)return; FOLDER.busy=true; try{ + if(stages)await makeStageFolders(); const held=stages?[...new Set([...FOLDER.saved.values()].map(r=>r.order).filter(Boolean))].slice(-1000):[]; const {files,states}=await api('/queue/folder',{early:stages,held}); const wanted=new Map(files.map(f=>[f.order+':'+f.item,f]));