feat(ar1-admin): bottone Anteprima PDF wirato a BE /admin/ar1-templates/:id/preview-pdf
Rimosso toast 'TODO' dal bottone eye icon in Tab Template. Ora:
1. chiama Ar1Service.previewTemplatePdf(row.id) (nuovo metodo, ritorna Blob)
2. crea URL.createObjectURL + window.open('_blank')
3. revokeObjectURL dopo 60s (cleanup)
4. toast info iniziale 'Generazione anteprima...' + error toast su fail
Service: +1 metodo previewTemplatePdf(templateId) che torna Promise<Blob>
usando buildHeadersMultipart (nessun Content-Type per risposta binaria).
This commit is contained in:
@@ -416,9 +416,16 @@ const Ar1AdminConfig = () => {
|
||||
|
||||
const tplActiveActionsTpl = (row) => (
|
||||
<div style={{ display: 'flex', gap: 4 }}>
|
||||
<Button icon="pi pi-eye" rounded text severity="info" tooltip="Anteprima PDF (dati mock)" onClick={() => {
|
||||
// Anteprima PDF: apre endpoint dummy (TODO backend — fallback: mostra un alert)
|
||||
if (toast.current) toast.current.show({ severity: 'info', summary: 'Anteprima', detail: `TODO: anteprima PDF ${row.variant} v${row.version}` });
|
||||
<Button icon="pi pi-eye" rounded text severity="info" tooltip="Anteprima PDF (dati di esempio)" onClick={async () => {
|
||||
try {
|
||||
if (toast.current) toast.current.show({ severity: 'info', summary: 'Generazione anteprima...', detail: 'Attendere qualche secondo', life: 3000 });
|
||||
const blob = await Ar1Service.previewTemplatePdf(row.id);
|
||||
const url = URL.createObjectURL(blob);
|
||||
window.open(url, '_blank');
|
||||
setTimeout(() => URL.revokeObjectURL(url), 60000);
|
||||
} catch (e) {
|
||||
if (toast.current) toast.current.show({ severity: 'error', summary: 'Errore anteprima', detail: e.message || 'Generazione PDF fallita' });
|
||||
}
|
||||
}} />
|
||||
<Button icon="pi pi-pencil" rounded text tooltip="Modifica layout grafico" onClick={() => openEditLayout(row)} disabled={row.status === 'ARCHIVED'} />
|
||||
<Button icon="pi pi-plus-circle" rounded text severity="warning" tooltip="Nuova versione" onClick={() => openNewVersion(row.variant)} />
|
||||
|
||||
@@ -210,6 +210,12 @@ const Ar1Service = {
|
||||
},
|
||||
|
||||
// ---------- ADMIN: document categories (per dropdown) ----------
|
||||
previewTemplatePdf(templateId) {
|
||||
return fetch(`${BASE_URL}/admin/ar1-templates/${templateId}/preview-pdf`, {
|
||||
method: 'POST', mode: 'cors', headers: buildHeadersMultipart()
|
||||
}).then(r => { if (!r.ok) throw new Error(`HTTP ${r.status}`); return r.blob(); });
|
||||
},
|
||||
|
||||
listDocumentCategories(onSuccess, onError) {
|
||||
fetch(`${BASE_URL}/admin/document-categories`, {
|
||||
method: 'GET', mode: 'cors', headers: buildHeaders()
|
||||
|
||||
Reference in New Issue
Block a user