u
This commit is contained in:
@@ -89,12 +89,23 @@ export const printerjob = {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* POST /api/printerjob/cancel-all
|
* POST /api/printerjob/cancel-all
|
||||||
* Cancels all pending/processing jobs, optionally scoped to an agentprinter.
|
* Sends ~JA to clear printer buffer and cancels all queued jobs.
|
||||||
* Falls back to listing and cancelling individual jobs if needed.
|
|
||||||
* @param {{ agentprinterId?: number }} [payload]
|
* @param {{ agentprinterId?: number }} [payload]
|
||||||
* → { success: true, cancelledCount: number, jobs: PrinterJob[] }
|
* → { success: true, cancelledCount: number, jobs: PrinterJob[] }
|
||||||
*/
|
*/
|
||||||
async cancelAll({ agentprinterId } = {}) {
|
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 {
|
try {
|
||||||
return await http('/api/printerjob/cancel-all', {
|
return await http('/api/printerjob/cancel-all', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
|||||||
@@ -27,8 +27,6 @@ export default class OnlinePrinterIcons extends PureComponent {
|
|||||||
? companyAutomat.state.livePrinters
|
? companyAutomat.state.livePrinters
|
||||||
: [],
|
: [],
|
||||||
menuAnchor: null,
|
menuAnchor: null,
|
||||||
testingId: null,
|
|
||||||
cancellingId: null,
|
|
||||||
};
|
};
|
||||||
this.handleOpenMenu = this.handleOpenMenu.bind(this);
|
this.handleOpenMenu = this.handleOpenMenu.bind(this);
|
||||||
this.handleCloseMenu = this.handleCloseMenu.bind(this);
|
this.handleCloseMenu = this.handleCloseMenu.bind(this);
|
||||||
@@ -110,45 +108,33 @@ export default class OnlinePrinterIcons extends PureComponent {
|
|||||||
this.setState({ menuAnchor: null });
|
this.setState({ menuAnchor: null });
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleTestPrint(printer) {
|
handleTestPrint(printer) {
|
||||||
if (!printer?.id) return;
|
if (!printer?.id) return;
|
||||||
this.setState({ testingId: printer.id });
|
this.handleCloseMenu();
|
||||||
try {
|
companyAutomat.actions
|
||||||
await companyAutomat.actions.sendTestPrint(printer.id, {
|
.sendTestPrint(printer.id, {
|
||||||
model: printer.model || printer.type || 'Zebra',
|
model: printer.model || printer.type || 'Zebra',
|
||||||
});
|
})
|
||||||
enqueueSnackbar(
|
.then(() => {
|
||||||
`Testdruck für ${printer.model || 'Drucker'} (#${printer.id}) an Warteschlange gesendet.`,
|
enqueueSnackbar(
|
||||||
{ variant: 'success' },
|
`Testdruck für ${printer.model || 'Drucker'} (#${printer.id}) an Warteschlange gesendet.`,
|
||||||
);
|
{ variant: 'success' },
|
||||||
} catch (err) {
|
);
|
||||||
notifyError(err);
|
})
|
||||||
} finally {
|
.catch(notifyError);
|
||||||
this.setState({ testingId: null, menuAnchor: null });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleCancelAllJobs(printer) {
|
handleCancelAllJobs(printer) {
|
||||||
if (!printer?.id) return;
|
if (!printer?.id) return;
|
||||||
this.setState({ cancellingId: printer.id });
|
this.handleCloseMenu();
|
||||||
try {
|
companyAutomat.actions
|
||||||
const res = await companyAutomat.actions.cancelAllPrinterJobs(printer.id);
|
.cancelAllPrinterJobs(printer.id)
|
||||||
const count = res?.cancelledCount ?? 0;
|
.then(() => {
|
||||||
if (count > 0) {
|
enqueueSnackbar(`Druckaufträge für ${printer.model || 'Drucker'} abgebrochen.`, {
|
||||||
enqueueSnackbar(
|
|
||||||
`${count} Druckauftrag/Druckaufträge für ${printer.model || 'Drucker'} abgebrochen.`,
|
|
||||||
{ variant: 'info' },
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
enqueueSnackbar(`Keine offenen Aufträge für ${printer.model || 'Drucker'}.`, {
|
|
||||||
variant: 'info',
|
variant: 'info',
|
||||||
});
|
});
|
||||||
}
|
})
|
||||||
} catch (err) {
|
.catch(notifyError);
|
||||||
notifyError(err);
|
|
||||||
} finally {
|
|
||||||
this.setState({ cancellingId: null, menuAnchor: null });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleOpenPrinterSettings() {
|
handleOpenPrinterSettings() {
|
||||||
@@ -159,7 +145,7 @@ export default class OnlinePrinterIcons extends PureComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { menuAnchor, testingId, cancellingId } = this.state;
|
const { menuAnchor } = this.state;
|
||||||
const onlinePrinters = this.getOnlinePrinters();
|
const onlinePrinters = this.getOnlinePrinters();
|
||||||
|
|
||||||
if (onlinePrinters.length === 0) {
|
if (onlinePrinters.length === 0) {
|
||||||
@@ -290,28 +276,22 @@ export default class OnlinePrinterIcons extends PureComponent {
|
|||||||
|
|
||||||
<Divider />
|
<Divider />
|
||||||
|
|
||||||
<MenuItem
|
<MenuItem onClick={() => this.handleTestPrint(activePrinter)}>
|
||||||
onClick={() => void this.handleTestPrint(activePrinter)}
|
|
||||||
disabled={testingId === activePrinter?.id || cancellingId === activePrinter?.id}
|
|
||||||
>
|
|
||||||
<ListItemIcon>
|
<ListItemIcon>
|
||||||
<PrintOutlinedIcon fontSize="small" color="primary" />
|
<PrintOutlinedIcon fontSize="small" color="primary" />
|
||||||
</ListItemIcon>
|
</ListItemIcon>
|
||||||
<ListItemText
|
<ListItemText
|
||||||
primary={testingId === activePrinter?.id ? 'Sendet Testdruck…' : 'Testdruck senden'}
|
primary="Testdruck senden"
|
||||||
secondary="Minimales ZPL-Etikett"
|
secondary="Minimales ZPL-Etikett"
|
||||||
/>
|
/>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
|
|
||||||
<MenuItem
|
<MenuItem onClick={() => this.handleCancelAllJobs(activePrinter)}>
|
||||||
onClick={() => void this.handleCancelAllJobs(activePrinter)}
|
|
||||||
disabled={cancellingId === activePrinter?.id || testingId === activePrinter?.id}
|
|
||||||
>
|
|
||||||
<ListItemIcon>
|
<ListItemIcon>
|
||||||
<CancelScheduleSendOutlinedIcon fontSize="small" color="error" />
|
<CancelScheduleSendOutlinedIcon fontSize="small" color="error" />
|
||||||
</ListItemIcon>
|
</ListItemIcon>
|
||||||
<ListItemText
|
<ListItemText
|
||||||
primary={cancellingId === activePrinter?.id ? 'Wird abgebrochen…' : 'Alle Aufträge abbrechen'}
|
primary="Alle Aufträge abbrechen"
|
||||||
secondary="Warteschlange leeren"
|
secondary="Warteschlange leeren"
|
||||||
/>
|
/>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
|
|||||||
Reference in New Issue
Block a user