/** * Skrift – Interface „Testdruck generieren & drucken" * --------------------------------------------------------------------------- * Button im test_prints-Datensatz: erzeugt aus Template + Text ein SVG und * reiht es als Druck-Job für die gewählte Maschine ein * (POST /skrift-orders/test-print). Datensatz vorher speichern. * * Von Hand als ESM (kein Build) – Vue + SDK stellt Directus zur Laufzeit bereit. */ import { defineComponent, ref, inject, h } from 'vue'; import { useApi } from '@directus/extensions-sdk'; const TestPrintButton = defineComponent({ setup() { const api = useApi(); const values = inject('values', ref({})); const busy = ref(false); const msg = ref(''); const err = ref(''); async function ausloesen() { const id = values && values.value ? values.value.id : null; if (!id) { err.value = 'Bitte den Datensatz zuerst speichern.'; return; } busy.value = true; err.value = ''; msg.value = ''; try { const res = await api.post('/skrift-orders/test-print', { id }); msg.value = `Generiert & eingereiht (Job ${res.data?.job}, Ordner ${res.data?.ref}).`; } catch (e) { const d = e && e.response && e.response.data; err.value = (d && (d.error + (d.detail ? ' – ' + d.detail : ''))) || (e && e.message) || 'Fehler.'; } finally { busy.value = false; } } return () => h('div', { style: 'display:flex;flex-direction:column;gap:8px;' }, [ h('button', { type: 'button', disabled: busy.value, onClick: ausloesen, style: 'align-self:flex-start;cursor:pointer;border:1px solid var(--primary);background:var(--primary);color:#fff;border-radius:6px;padding:8px 18px;font:inherit;', }, busy.value ? 'Wird generiert …' : 'Generieren & drucken'), msg.value ? h('div', { style: 'color:var(--success, #2e7d32);font-size:13px;' }, msg.value) : null, err.value ? h('div', { style: 'color:var(--danger, #c62828);font-size:13px;' }, err.value) : null, h('div', { style: 'color:var(--foreground-subdued);font-size:12px;' }, 'Hinweis: Datensatz mit Template, Format, Maschine und Text speichern, dann klicken.'), ]); }, }); export default { id: 'skrift-testprint-button', name: 'Testdruck', icon: 'science', description: 'Generiert einen Testdruck und reiht ihn zum Drucken ein.', component: TestPrintButton, types: ['alias'], localTypes: ['presentation'], group: 'presentation', options: null, };