From 153e891d6e57e77565fa62f81364bcb123266641 Mon Sep 17 00:00:00 2001 From: Donkie Date: Sat, 12 Aug 2023 15:36:49 +0200 Subject: [PATCH] Client: Added toggles for all label contents Can now print spool/filament/vendor comments on the labels. Translated label contents --- client/public/locales/en/common.json | 13 +- client/public/locales/sv/common.json | 14 +- .../printing/qrCodePrintingDialog.tsx | 9 +- .../printing/spoolQrCodePrintingDialog.tsx | 135 ++++++++++++++++++ .../src/components/selectAndPrintDialog.tsx | 67 +-------- 5 files changed, 170 insertions(+), 68 deletions(-) create mode 100644 client/src/components/printing/spoolQrCodePrintingDialog.tsx diff --git a/client/public/locales/en/common.json b/client/public/locales/en/common.json index 6a31a2e..7b1f608 100644 --- a/client/public/locales/en/common.json +++ b/client/public/locales/en/common.json @@ -85,9 +85,20 @@ "qrcode": { "button": "Print QR Codes", "title": "QR Code Printing", + "spoolWeight": "Spool Weight: {{weight}}", + "lotNr": "Lot Nr: {{lot}}", + "bedTemp": "BT: {{temp}}", + "extruderTemp": "ET: {{temp}}", "textSize": "Content Text Size", "showSpoolmanIcon": "Show Spoolman Icon", - "showContent": "Print Label" + "showVendor": "Vendor", + "showContent": "Print Label", + "showLotNr": "Lot Nr", + "showSpoolWeight": "Spool Weight", + "showTemperatures": "Temperatures", + "showSpoolComment": "Spool Comment", + "showFilamentComment": "Filament Comment", + "showVendorComment": "Vendor Comment" }, "spoolSelect": { "title": "Select Spools", diff --git a/client/public/locales/sv/common.json b/client/public/locales/sv/common.json index 6b709d3..777e3be 100644 --- a/client/public/locales/sv/common.json +++ b/client/public/locales/sv/common.json @@ -65,6 +65,7 @@ "paperSize": "Papperstyp", "showBorder": "Visa ram", "previewScale": "Skala förhandsgranskning", + "skipItems": "Hoppa över objekt", "contentSettings": "Innehållsinställningar", "layoutSettings": "Layoutinställningar", "marginLeft": "Marginal - vänster", @@ -84,9 +85,20 @@ "qrcode": { "button": "Skriv ut QR-koder", "title": "QR-kod utskrift", + "spoolWeight": "Spolvikt: {{weight}}", + "lotNr": "Batch: {{lot}}", + "bedTemp": "BT: {{temp}}", + "extruderTemp": "ET: {{temp}}", "textSize": "Textstorlek", "showSpoolmanIcon": "Visa Spoolman-ikon", - "showContent": "Visa QR-kodsinnehåll" + "showContent": "Etikett", + "showVendor": "Leverantör", + "showLotNr": "Batchnummer", + "showSpoolWeight": "Spolvikt", + "showTemperatures": "Temperaturer", + "showSpoolComment": "Spolkommentar", + "showFilamentComment": "Filamentkommentar", + "showVendorComment": "Leverantörskommentar" }, "spoolSelect": { "title": "Välj spolar", diff --git a/client/src/components/printing/qrCodePrintingDialog.tsx b/client/src/components/printing/qrCodePrintingDialog.tsx index 900d83b..db87814 100644 --- a/client/src/components/printing/qrCodePrintingDialog.tsx +++ b/client/src/components/printing/qrCodePrintingDialog.tsx @@ -13,9 +13,10 @@ interface QRCodePrintingDialogProps { visible: boolean; items: QRCodeData[]; onCancel: () => void; + extraSettings?: JSX.Element; } -const QRCodePrintingDialog: React.FC = ({ visible, items, onCancel }) => { +const QRCodePrintingDialog: React.FC = ({ visible, items, onCancel, extraSettings }) => { const t = useTranslate(); const [showContent, setShowContent] = useSavedState("print-showContent", true); @@ -28,7 +29,7 @@ const QRCodePrintingDialog: React.FC = ({ visible, it
= ({ visible, it setShowSpoolmanIcon(checked)} /> + {extraSettings} } style={` @@ -90,10 +92,11 @@ const QRCodePrintingDialog: React.FC = ({ visible, it display: flex; width: 100%; max-height: 100%; + justify-content: center; } .print-page .print-qrcode-container { - max-width: 50%; + max-width: ${showContent ? "50%" : "100%"}; display: flex; } diff --git a/client/src/components/printing/spoolQrCodePrintingDialog.tsx b/client/src/components/printing/spoolQrCodePrintingDialog.tsx new file mode 100644 index 0000000..b4ad9c3 --- /dev/null +++ b/client/src/components/printing/spoolQrCodePrintingDialog.tsx @@ -0,0 +1,135 @@ +import { Form, Switch } from "antd"; +import { IFilament } from "../../pages/filaments/model"; +import { ISpool } from "../../pages/spools/model"; +import QRCodePrintingDialog from "./qrCodePrintingDialog"; +import { useSavedState } from "../../utils/saveload"; +import { useTranslate } from "@refinedev/core"; + +interface SpoolQRCodePrintingDialog { + visible: boolean; + items: ISpool[]; + onCancel: () => void; +} + +const SpoolQRCodePrintingDialog: React.FC = ({ visible, items, onCancel }) => { + const t = useTranslate(); + + const [showVendor, setShowVendor] = useSavedState("print-showVendor", true); + const [showLotNr, setShowLotNr] = useSavedState("print-showLotNr", true); + const [showSpoolWeight, setShowSpoolWeight] = useSavedState("print-showSpoolWeight", true); + const [showTemperatures, setShowTemperatures] = useSavedState("print-showTemperatures", true); + const [showSpoolComment, setShowSpoolComment] = useSavedState("print-showSpoolComment", false); + const [showFilamentComment, setShowFilamentComment] = useSavedState("print-showFilamentComment", false); + const [showVendorComment, setShowVendorComment] = useSavedState("print-showVendorComment", false); + + const formatFilament = (filament: IFilament) => { + let vendorPrefix = ""; + if (showVendor && filament.vendor) { + vendorPrefix = `${filament.vendor.name} - `; + } + let name = filament.name; + if (!name) { + name = `Filament #${filament.id}`; + } + return `${vendorPrefix}${name}`; + }; + + return ( + + {formatFilament(spool.filament)} +
+ + #{spool.id} + {spool.filament.material && <> - {spool.filament.material}} + + {showSpoolWeight && ( + <> +
+ {t("printing.qrcode.spoolWeight", { weight: `${spool.filament.spool_weight ?? "?"} g` })} + + )} + {showTemperatures && tempLine && ( + <> +
+ {tempLine} + + )} + {showLotNr && ( + <> +
+ {t("printing.qrcode.lotNr", { lot: spool.lot_nr ?? "?" })} + + )} + {showSpoolComment && spool.comment && ( + <> +
+ {spool.comment} + + )} + {showFilamentComment && spool.filament.comment && ( + <> +
+ {spool.filament.comment} + + )} + {showVendorComment && spool.filament.vendor?.comment && ( + <> +
+ {spool.filament.vendor.comment} + + )} +

+ ), + errorLevel: "H", + }; + })} + extraSettings={ + <> + + setShowVendor(checked)} /> + + + setShowSpoolWeight(checked)} /> + + + setShowTemperatures(checked)} /> + + + setShowLotNr(checked)} /> + + + setShowSpoolComment(checked)} /> + + + setShowFilamentComment(checked)} /> + + + setShowVendorComment(checked)} /> + + + } + /> + ); +}; + +export default SpoolQRCodePrintingDialog; diff --git a/client/src/components/selectAndPrintDialog.tsx b/client/src/components/selectAndPrintDialog.tsx index 6d84887..cb3af08 100644 --- a/client/src/components/selectAndPrintDialog.tsx +++ b/client/src/components/selectAndPrintDialog.tsx @@ -2,12 +2,11 @@ import React from "react"; import SpoolSelectModal from "./spoolSelectModal"; -import QRCodePrintingDialog from "./printing/qrCodePrintingDialog"; import { Button } from "antd"; import { ISpool } from "../pages/spools/model"; import { PrinterOutlined } from "@ant-design/icons"; import { useTranslate } from "@refinedev/core"; -import { IFilament } from "../pages/filaments/model"; +import SpoolQRCodePrintingDialog from "./printing/spoolQrCodePrintingDialog"; const SelectAndPrint: React.FC = () => { const t = useTranslate(); @@ -15,18 +14,6 @@ const SelectAndPrint: React.FC = () => { const [step, setStep] = React.useState(0); const [selectedSpools, setSelectedSpools] = React.useState([]); - const formatFilament = (filament: IFilament) => { - let vendorPrefix = ""; - if (filament.vendor) { - vendorPrefix = `${filament.vendor.name} - `; - } - let name = filament.name; - if (!name) { - name = `ID: ${filament.id}`; - } - return `${vendorPrefix}${name}`; - }; - return ( <>