This commit is contained in:
seb
2026-10-31 23:39:12 +01:00
parent 545eb98191
commit ca28f56f3f
2 changed files with 38 additions and 47 deletions

View File

@@ -89,12 +89,23 @@ export const printerjob = {
/**
* POST /api/printerjob/cancel-all
* Cancels all pending/processing jobs, optionally scoped to an agentprinter.
* Falls back to listing and cancelling individual jobs if needed.
* Sends ~JA to clear printer buffer and cancels all queued jobs.
* @param {{ agentprinterId?: number }} [payload]
* → { success: true, cancelledCount: number, jobs: PrinterJob[] }
*/
async cancelAll({ agentprinterId } = {}) {
if (agentprinterId != null) {
try {
await this.createZplJob({
agentprinterId: Number(agentprinterId),
data: '~JA',
copiescount: 1,
});
} catch (e) {
console.warn('Failed to send ~JA to printer:', e);
}
}
try {
return await http('/api/printerjob/cancel-all', {
method: 'POST',

View File

@@ -27,8 +27,6 @@ export default class OnlinePrinterIcons extends PureComponent {
? companyAutomat.state.livePrinters
: [],
menuAnchor: null,
testingId: null,
cancellingId: null,
};
this.handleOpenMenu = this.handleOpenMenu.bind(this);
this.handleCloseMenu = this.handleCloseMenu.bind(this);
@@ -110,45 +108,33 @@ export default class OnlinePrinterIcons extends PureComponent {
this.setState({ menuAnchor: null });
}
async handleTestPrint(printer) {
handleTestPrint(printer) {
if (!printer?.id) return;
this.setState({ testingId: printer.id });
try {
await companyAutomat.actions.sendTestPrint(printer.id, {
this.handleCloseMenu();
companyAutomat.actions
.sendTestPrint(printer.id, {
model: printer.model || printer.type || 'Zebra',
});
enqueueSnackbar(
`Testdruck für ${printer.model || 'Drucker'} (#${printer.id}) an Warteschlange gesendet.`,
{ variant: 'success' },
);
} catch (err) {
notifyError(err);
} finally {
this.setState({ testingId: null, menuAnchor: null });
}
})
.then(() => {
enqueueSnackbar(
`Testdruck für ${printer.model || 'Drucker'} (#${printer.id}) an Warteschlange gesendet.`,
{ variant: 'success' },
);
})
.catch(notifyError);
}
async handleCancelAllJobs(printer) {
handleCancelAllJobs(printer) {
if (!printer?.id) return;
this.setState({ cancellingId: printer.id });
try {
const res = await companyAutomat.actions.cancelAllPrinterJobs(printer.id);
const count = res?.cancelledCount ?? 0;
if (count > 0) {
enqueueSnackbar(
`${count} Druckauftrag/Druckaufträge für ${printer.model || 'Drucker'} abgebrochen.`,
{ variant: 'info' },
);
} else {
enqueueSnackbar(`Keine offenen Aufträge für ${printer.model || 'Drucker'}.`, {
this.handleCloseMenu();
companyAutomat.actions
.cancelAllPrinterJobs(printer.id)
.then(() => {
enqueueSnackbar(`Druckaufträge für ${printer.model || 'Drucker'} abgebrochen.`, {
variant: 'info',
});
}
} catch (err) {
notifyError(err);
} finally {
this.setState({ cancellingId: null, menuAnchor: null });
}
})
.catch(notifyError);
}
handleOpenPrinterSettings() {
@@ -159,7 +145,7 @@ export default class OnlinePrinterIcons extends PureComponent {
}
render() {
const { menuAnchor, testingId, cancellingId } = this.state;
const { menuAnchor } = this.state;
const onlinePrinters = this.getOnlinePrinters();
if (onlinePrinters.length === 0) {
@@ -290,28 +276,22 @@ export default class OnlinePrinterIcons extends PureComponent {
<Divider />
<MenuItem
onClick={() => void this.handleTestPrint(activePrinter)}
disabled={testingId === activePrinter?.id || cancellingId === activePrinter?.id}
>
<MenuItem onClick={() => this.handleTestPrint(activePrinter)}>
<ListItemIcon>
<PrintOutlinedIcon fontSize="small" color="primary" />
</ListItemIcon>
<ListItemText
primary={testingId === activePrinter?.id ? 'Sendet Testdruck…' : 'Testdruck senden'}
primary="Testdruck senden"
secondary="Minimales ZPL-Etikett"
/>
</MenuItem>
<MenuItem
onClick={() => void this.handleCancelAllJobs(activePrinter)}
disabled={cancellingId === activePrinter?.id || testingId === activePrinter?.id}
>
<MenuItem onClick={() => this.handleCancelAllJobs(activePrinter)}>
<ListItemIcon>
<CancelScheduleSendOutlinedIcon fontSize="small" color="error" />
</ListItemIcon>
<ListItemText
primary={cancellingId === activePrinter?.id ? 'Wird abgebrochen…' : 'Alle Aufträge abbrechen'}
primary="Alle Aufträge abbrechen"
secondary="Warteschlange leeren"
/>
</MenuItem>