fix: concluir recuperacao de exportacoes e consolidar candidata QA
tests / ci (push) Canceled after 0s
tests / ci (push) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
import {
|
||||
validateDossierAttachments,
|
||||
type DossierAttachment,
|
||||
} from './project-dossier-report.ts';
|
||||
|
||||
export type DossierExportOperation =
|
||||
| 'word'
|
||||
| 'package'
|
||||
| 'pdf'
|
||||
| 'csv'
|
||||
| 'attachments';
|
||||
const messages: Record<DossierExportOperation, string> = {
|
||||
word: 'Não foi possível gerar o relatório Word.',
|
||||
package: 'Não foi possível preparar o pacote de anexos.',
|
||||
pdf: 'Não foi possível preparar a versão para PDF.',
|
||||
csv: 'Não foi possível preparar o ficheiro CSV.',
|
||||
attachments: 'Não foi possível ler os anexos seleccionados.',
|
||||
};
|
||||
let failureSequence = 0;
|
||||
|
||||
export function dossierExportFailure(
|
||||
operation: DossierExportOperation,
|
||||
cause: unknown,
|
||||
log: (message: string, detail: unknown) => void = console.error,
|
||||
): string {
|
||||
const reference = `EXP-${Date.now().toString(36)}-${++failureSequence}`;
|
||||
// Local diagnostics only: never send dossier values or file contents.
|
||||
log('[InvesteMoz exportação]', { reference, operation, cause });
|
||||
return `${messages[operation]} Os dados, as secções e os anexos foram mantidos. Tente novamente pelo mesmo botão. Referência: ${reference}.`;
|
||||
}
|
||||
|
||||
/** Synchronous acquisition prevents a second click before React renders busy. */
|
||||
export class DossierExportGate {
|
||||
private active = false;
|
||||
async run(task: () => Promise<void>): Promise<boolean> {
|
||||
if (this.active) return false;
|
||||
this.active = true;
|
||||
try {
|
||||
await task();
|
||||
return true;
|
||||
} finally {
|
||||
this.active = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function prepareDossierAttachments(
|
||||
current: DossierAttachment[],
|
||||
incoming: File[],
|
||||
): Promise<{
|
||||
attachments: DossierAttachment[];
|
||||
duplicateCount: number;
|
||||
problem?: string;
|
||||
}> {
|
||||
for (const file of incoming) {
|
||||
const problem = validateDossierAttachments([file]);
|
||||
if (problem)
|
||||
return { attachments: current, duplicateCount: 0, problem };
|
||||
}
|
||||
const identity = async (file: File) => {
|
||||
const hash = await crypto.subtle.digest(
|
||||
'SHA-256',
|
||||
await file.arrayBuffer(),
|
||||
);
|
||||
return `${file.name}:${Array.from(new Uint8Array(hash), (b) => b.toString(16).padStart(2, '0')).join('')}`;
|
||||
};
|
||||
const known = new Set(
|
||||
await Promise.all(current.map((item) => identity(item.file))),
|
||||
);
|
||||
const added: DossierAttachment[] = [];
|
||||
let duplicateCount = 0;
|
||||
for (const file of incoming) {
|
||||
const key = await identity(file);
|
||||
if (known.has(key)) {
|
||||
duplicateCount++;
|
||||
continue;
|
||||
}
|
||||
known.add(key);
|
||||
added.push({ file, include: true, caption: '' });
|
||||
}
|
||||
const problem = validateDossierAttachments(
|
||||
[...current, ...added].map((item) => item.file),
|
||||
);
|
||||
return {
|
||||
attachments: problem ? current : [...current, ...added],
|
||||
duplicateCount,
|
||||
problem: problem ?? undefined,
|
||||
};
|
||||
}
|
||||
@@ -659,8 +659,13 @@ export async function createProjectDossierPrintHtml(
|
||||
content.push('<p>Não há informação fornecida nesta secção.</p>');
|
||||
content.push('</section>');
|
||||
}
|
||||
// Page margin boxes reserve footer space on every printed page. A fixed
|
||||
// body element can overlap fragmented tables in Chromium's print layout.
|
||||
const printFooter = JSON.stringify(
|
||||
`InvesteMoz · Relatório privado · ${model.version}`,
|
||||
).replaceAll('<', '\\3c ');
|
||||
return `<!doctype html><html lang="pt-MZ"><head><meta charset="utf-8"><title>Relatório — ${escapeHtml(model.title)}</title><style>
|
||||
@page{size:A4;margin:18mm 17mm 20mm}*{box-sizing:border-box}body{font:10.5pt/1.45 Arial,sans-serif;color:#17211f;margin:0}h1{font-size:24pt;color:#123b35;margin:0 0 7mm}h2{font-size:16pt;color:#123b35;border-bottom:1px solid #b8c9c3;padding-bottom:2mm;margin:8mm 0 3mm;break-after:avoid}h3{font-size:12pt;color:#27675c;break-after:avoid}p{white-space:pre-wrap}table{width:100%;border-collapse:collapse;table-layout:fixed;margin:3mm 0 5mm;break-inside:auto}th,td{border:1px solid #cbd5d1;padding:5px 6px;text-align:left;vertical-align:top;overflow-wrap:anywhere}th{background:#123b35;color:white}tr{break-inside:avoid}.report-table th:first-child,.report-table td:first-child{width:22%}.report-table th:last-child,.report-table td:last-child{width:32%}.report-table td:last-child{font-size:9pt;color:#40524d}.annex-table{table-layout:fixed;font-size:9pt}thead{display:table-header-group}.private{padding:3mm;background:#fff4df;border-left:3px solid #b66a0c;font-weight:bold}section{break-inside:auto}figure{margin:5mm auto;text-align:center;break-inside:avoid}img{max-width:100%;max-height:210mm;object-fit:contain}figcaption{font-style:italic;color:#52615d}pre{white-space:pre-wrap;overflow-wrap:anywhere;font:9.5pt/1.4 Arial,sans-serif}@media screen{body{max-width:1040px;margin:24px auto;padding:24px}table{font-size:11pt}}@media screen{body{max-width:1040px;margin:24px auto;padding:24px}table{font-size:11pt}}@media print{a{color:inherit;text-decoration:none}.no-print{display:none}th{color:#17211f;background:#edf4f1}footer{position:fixed;bottom:-14mm;left:0;right:0;font-size:9pt;color:#40524d}}
|
||||
@page{size:A4;margin:18mm 17mm 20mm;@bottom-left{content:${printFooter};font:9pt/1.3 Arial,sans-serif;color:#40524d;vertical-align:middle;width:80%}@bottom-right{content:counter(page) " / " counter(pages);font:9pt/1.3 Arial,sans-serif;color:#40524d;vertical-align:middle}}*{box-sizing:border-box}body{font:10.5pt/1.45 Arial,sans-serif;color:#17211f;margin:0}h1{font-size:24pt;color:#123b35;margin:0 0 7mm}h2{font-size:16pt;color:#123b35;border-bottom:1px solid #b8c9c3;padding-bottom:2mm;margin:8mm 0 3mm;break-after:avoid}h3{font-size:12pt;color:#27675c;break-after:avoid}p{white-space:pre-wrap}table{width:100%;border-collapse:collapse;table-layout:fixed;margin:3mm 0 5mm;break-inside:auto}th,td{border:1px solid #cbd5d1;padding:5px 6px;text-align:left;vertical-align:top;overflow-wrap:anywhere}th{background:#123b35;color:white}tr{break-inside:avoid}.report-table th:first-child,.report-table td:first-child{width:22%}.report-table th:last-child,.report-table td:last-child{width:32%}.report-table td:last-child{font-size:9pt;color:#40524d}.annex-table{table-layout:fixed;font-size:9pt}thead{display:table-header-group}.private{padding:3mm;background:#fff4df;border-left:3px solid #b66a0c;font-weight:bold}section{break-inside:auto}figure{margin:5mm auto;text-align:center;break-inside:avoid}img{max-width:100%;max-height:210mm;object-fit:contain}figcaption{font-style:italic;color:#52615d}pre{white-space:pre-wrap;overflow-wrap:anywhere;font:9.5pt/1.4 Arial,sans-serif}@media screen{body{max-width:1040px;margin:24px auto;padding:24px}table{font-size:11pt}}@media screen{body{max-width:1040px;margin:24px auto;padding:24px}table{font-size:11pt}}@media print{a{color:inherit;text-decoration:none}.no-print{display:none}th{color:#17211f;background:#edf4f1}footer{display:none}}
|
||||
</style></head><body><h1>InvesteMoz<br>Relatório consolidado do projecto</h1><p><strong>${escapeHtml(model.title)}</strong><br>Gerado em ${escapeHtml(new Date(model.generatedAt).toLocaleString('pt-MZ'))}<br>Versão/revisão: ${escapeHtml(model.version)}</p><p class="private">Documento privado. O portal não publica nem partilha este conteúdo.</p>${content.join('')}<footer><small>InvesteMoz · Relatório privado · ${escapeHtml(model.version)}</small></footer><script>window.addEventListener('load',()=>setTimeout(()=>window.print(),350));</script></body></html>`;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user