u
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user