feat: Minhas folhas on the Site: save a cart item to the account, order it again with the files already on the server, edit it without sending them again (Rodada 5, B9)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -26,7 +26,8 @@
|
||||
residue:item.residueAccepted||0,
|
||||
stroke:item.strokeClass||null,strokeChoice:item.strokeChoice||null,
|
||||
sheets:(item.partes||[]).map(part=>part.production),
|
||||
files:(item.localFiles||[]).map(file=>({name:file.name,size:file.size,lastModified:file.lastModified}))
|
||||
files:[...(item.localFiles||[]),...(item.savedFiles||[])]
|
||||
.map(file=>({name:file.name,size:file.size,lastModified:file.lastModified}))
|
||||
})),treatment:ajusteSnapshot(),coupon:cupomCode()});
|
||||
}
|
||||
// The quote this browser is paying, forgotten. clearDraft also empties the
|
||||
@@ -149,6 +150,7 @@
|
||||
}).catch(()=>{});
|
||||
window.dtfSessionReady=ready;
|
||||
window.dtfApi=api;
|
||||
window.dtfMensagem=message;
|
||||
ready.catch(error => { status.textContent = error.message; });
|
||||
// One message line under the steps. Its tone says what it is: a refusal or
|
||||
// a missing field is an error (red), a cart that changed a warning, a
|
||||
@@ -269,7 +271,9 @@
|
||||
}
|
||||
}
|
||||
})();
|
||||
e.promise.then(()=>{e.done=true;if(window.dtfTimings)T.uploadEnd=performance.now();falhas.delete(k);pintaEnvio();},
|
||||
e.promise.then(id=>{e.id=id;e.done=true;if(window.dtfTimings)T.uploadEnd=performance.now();falhas.delete(k);pintaEnvio();
|
||||
// "Salvar em Minhas folhas" waits for the item's files: the cart repaints when one lands.
|
||||
if(window.dtfContaAberta&&typeof pintaPedido==='function')pintaPedido();},
|
||||
error=>{envios.delete(k);if(error?.name!=='AbortError'){falhas.set(k,{file,error});
|
||||
// A refusal with a status already went to Sentry as an API error (DTF-WEB-15).
|
||||
if(!error?.status)window.dtfObservability?.uiError?.('Envio de arquivo falhou: '+(error?.message||'erro no envio'),'site');}pintaEnvio();});
|
||||
@@ -279,11 +283,23 @@
|
||||
}
|
||||
// Each file's upload as the product page shows it, under the uploader.
|
||||
window.dtfEnvio={
|
||||
enviar:file=>{if(!falhas.has(chaveArquivo(file)))enviar(file).catch(()=>{});},
|
||||
enviar:file=>{
|
||||
if(falhas.has(chaveArquivo(file)))return Promise.resolve(null);
|
||||
const p=enviar(file); p.catch(()=>{}); return p;
|
||||
},
|
||||
estado:file=>{const k=chaveArquivo(file),e=envios.get(k),f=falhas.get(k);
|
||||
return f?{fase:'falhou',erro:f.error?.message||'erro no envio'}
|
||||
:!e?null:e.done?{fase:'pronto'}:e.sent>=file.size?{fase:'verificando'}:{fase:'enviando',enviado:e.sent};},
|
||||
deNovo:file=>{falhas.delete(chaveArquivo(file));enviar(file).catch(()=>{});pintaEnvio();},
|
||||
// A file already on the server (a saved sheet opened for editing): its id
|
||||
// is known, so a later enviar(file) resolves at once and sends nothing.
|
||||
conhecido:(file,uploadId)=>{
|
||||
const k=chaveArquivo(file);
|
||||
falhas.delete(k);
|
||||
envios.set(k,{file,sent:file.size,done:true,id:uploadId,failed:null,
|
||||
stop:new AbortController(),promise:Promise.resolve(uploadId)});
|
||||
},
|
||||
idDe:file=>{const e=envios.get(chaveArquivo(file));return e&&e.done?(e.id??null):null;},
|
||||
// A file taken off the page, and in no cart item, stops going.
|
||||
manter:files=>{
|
||||
const quero=new Set([...files,...pedido.flatMap(it=>it.localFiles||[]),...(itemAtual?.localFiles||[])].map(chaveArquivo));
|
||||
@@ -495,7 +511,8 @@
|
||||
// One item carries at most 200 files (app/core/models.py); a bigger cart
|
||||
// line is refused here, with the reason, never by the generic 422.
|
||||
const semCap=cart.flatMap(line=>line.partes?.length?line.partes:[line]);
|
||||
if (semCap.some(item=>(item.localFiles||[]).length>200))
|
||||
const totalArquivos=item=>(item.localFiles||[]).length+(item.savedFiles||[]).length;
|
||||
if (semCap.some(item=>totalArquivos(item)>200))
|
||||
return message('Este item tem mais de 200 arquivos. Divida em dois itens.','error');
|
||||
const initialCart=cartSnapshot();
|
||||
busy = true;
|
||||
@@ -511,11 +528,17 @@
|
||||
? line.partes.map((part,i)=>({...line,...part,split:{group:'f'+index,part:i+1,of:line.partes.length}}))
|
||||
: [line]);
|
||||
for (const item of sheets) {
|
||||
if (!item.localFiles?.length) throw new Error('Selecione novamente os arquivos deste item.');
|
||||
const locais=item.localFiles||[], salvos=item.savedFiles||[];
|
||||
if (!locais.length && !salvos.length) throw new Error('Selecione novamente os arquivos deste item.');
|
||||
const uploads=[];
|
||||
for (const [index,file] of item.localFiles.entries()) {
|
||||
uploads.push(await upload(file));
|
||||
enviaFoto(uploads[index], item.fotos?.[index]);
|
||||
if (salvos.length) {
|
||||
// A sheet kept in Minhas folhas: the server already has the files.
|
||||
for (const saved of salvos) uploads.push(saved.upload_id);
|
||||
} else {
|
||||
for (const [index,file] of locais.entries()) {
|
||||
uploads.push(await upload(file));
|
||||
enviaFoto(uploads[index], item.fotos?.[index]);
|
||||
}
|
||||
}
|
||||
// Layout versions the server takes: 3 since 2026-10-21, 2 for a cart saved before.
|
||||
if (![2,3].includes(item.production?.version) || item.production.sources?.length!==uploads.length)
|
||||
|
||||
Reference in New Issue
Block a user