Client: Added some info to qr code printing label

This commit is contained in:
Donkie
2023-08-09 18:50:04 +02:00
parent 3dc678a575
commit ec80973f96
6 changed files with 82 additions and 21 deletions

View File

@@ -82,7 +82,7 @@
"title": "QR Code Printing", "title": "QR Code Printing",
"textSize": "Content Text Size", "textSize": "Content Text Size",
"showSpoolmanIcon": "Show Spoolman Icon", "showSpoolmanIcon": "Show Spoolman Icon",
"showContent": "Show QR Code Content" "showContent": "Print Label"
}, },
"spoolSelect": { "spoolSelect": {
"title": "Select Spools", "title": "Select Spools",

View File

@@ -160,14 +160,10 @@ const PrintingDialog: React.FC<PrintingDialogProps> = ({
<div <div
key={index} key={index}
style={{ style={{
display: "flex",
justifyContent: "center",
alignItems: "center",
width: `${ width: `${
(paperWidth - marginLeft - marginRight) / paperColumns (paperWidth - marginLeft - marginRight) / paperColumns
}mm`, }mm`,
height: `${calculatedRowHeight}mm`, height: `${calculatedRowHeight}mm`,
flexDirection: "column",
border: borderShowMode === "grid" ? "1px solid #000" : "none", border: borderShowMode === "grid" ? "1px solid #000" : "none",
}} }}
> >

View File

@@ -5,7 +5,7 @@ import { useTranslate } from "@refinedev/core";
interface QRCodeData { interface QRCodeData {
value: string; value: string;
label?: string; label?: JSX.Element;
errorLevel?: "L" | "M" | "Q" | "H"; errorLevel?: "L" | "M" | "Q" | "H";
} }
@@ -26,7 +26,7 @@ const QRCodePrintingDialog: React.FC<QRCodePrintingDialogProps> = ({
"print-showContent", "print-showContent",
true true
); );
const [textSize, setTextSize] = useSavedState("print-textSize", 5); const [textSize, setTextSize] = useSavedState("print-textSize", 3);
const [showSpoolmanIcon, setShowSpoolmanIcon] = useSavedState( const [showSpoolmanIcon, setShowSpoolmanIcon] = useSavedState(
"print-showSpoolmanIcon", "print-showSpoolmanIcon",
true true
@@ -34,7 +34,15 @@ const QRCodePrintingDialog: React.FC<QRCodePrintingDialogProps> = ({
const elements = items.map((item) => { const elements = items.map((item) => {
return ( return (
<> <div
style={{
display: "flex",
justifyContent: "center",
width: "100%",
maxHeight: "100%",
flexDirection: "row",
}}
>
<QRCode <QRCode
className="print-qrcode" className="print-qrcode"
icon={showSpoolmanIcon ? "/favicon.ico" : undefined} icon={showSpoolmanIcon ? "/favicon.ico" : undefined}
@@ -46,12 +54,12 @@ const QRCodePrintingDialog: React.FC<QRCodePrintingDialogProps> = ({
{showContent && ( {showContent && (
<div <div
className="print-qrcode-title" className="print-qrcode-title"
style={{ textAlign: "center", color: "#000" }} style={{ textAlign: "left", color: "#000", overflow: "hidden" }}
> >
{item.label ?? item.value} {item.label ?? item.value}
</div> </div>
)} )}
</> </div>
); );
}); });
@@ -74,8 +82,8 @@ const QRCodePrintingDialog: React.FC<QRCodePrintingDialogProps> = ({
<Slider <Slider
disabled={!showContent} disabled={!showContent}
tooltip={{ formatter: (value) => `${value} mm` }} tooltip={{ formatter: (value) => `${value} mm` }}
min={3} min={2}
max={15} max={7}
value={textSize} value={textSize}
step={0.1} step={0.1}
onChange={(value) => { onChange={(value) => {
@@ -113,6 +121,7 @@ const QRCodePrintingDialog: React.FC<QRCodePrintingDialogProps> = ({
} }
.print-page .print-qrcode-title { .print-page .print-qrcode-title {
width: 100%;
font-size: ${textSize}mm; font-size: ${textSize}mm;
} }

View File

@@ -7,12 +7,26 @@ import { Button } from "antd";
import { ISpool } from "../pages/spools/model"; import { ISpool } from "../pages/spools/model";
import { PrinterOutlined } from "@ant-design/icons"; import { PrinterOutlined } from "@ant-design/icons";
import { useTranslate } from "@refinedev/core"; import { useTranslate } from "@refinedev/core";
import { IFilament } from "../pages/filaments/model";
const SelectAndPrint: React.FC = () => { const SelectAndPrint: React.FC = () => {
const t = useTranslate(); const t = useTranslate();
const [step, setStep] = React.useState(0); const [step, setStep] = React.useState(0);
const [selectedSpools, setSelectedSpools] = React.useState<ISpool[]>([]); const [selectedSpools, setSelectedSpools] = React.useState<ISpool[]>([]);
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 ( return (
<> <>
<Button <Button
@@ -40,11 +54,53 @@ const SelectAndPrint: React.FC = () => {
onCancel={() => { onCancel={() => {
setStep(1); setStep(1);
}} }}
items={selectedSpools.map((spool) => ({ items={selectedSpools.map(function (spool) {
value: `web+spoolman:s-${spool.id}`, const temps = [];
label: `s-${spool.id}`, if (spool.filament.settings_extruder_temp) {
errorLevel: "H", temps.push(`ET: ${spool.filament.settings_extruder_temp} °C`);
}))} }
if (spool.filament.settings_bed_temp) {
temps.push(`BT: ${spool.filament.settings_bed_temp} °C`);
}
const tempLine = temps.join(" - ");
return {
value: `web+spoolman:s-${spool.id}`,
label: (
<p
style={{
padding: "1mm 1mm 1mm 0",
}}
>
<b>{formatFilament(spool.filament)}</b>
<br />
<b>
#{spool.id}
{spool.filament.material && <> - {spool.filament.material}</>}
</b>
{spool.filament.spool_weight && (
<>
<br />
Spool Weight: {spool.filament.spool_weight ?? "?"} g
</>
)}
{tempLine && (
<>
<br />
{tempLine}
</>
)}
{spool.lot_nr && (
<>
<br />
Lot Nr: {spool.lot_nr}
</>
)}
</p>
),
errorLevel: "H",
};
})}
/> />
</> </>
); );

View File

@@ -41,8 +41,8 @@ export const SpoolCreate: React.FC<
if (!name) { if (!name) {
name = `ID: ${item.id}`; name = `ID: ${item.id}`;
} }
let material = "" let material = "";
if (item.material) { if (item.material) {
material = ` - ${item.material}`; material = ` - ${item.material}`;
} }
const label = `${vendorPrefix}${name}${material}`; const label = `${vendorPrefix}${name}${material}`;

View File

@@ -25,8 +25,8 @@ export const SpoolEdit: React.FC<IResourceComponentsProps> = () => {
if (!name) { if (!name) {
name = `ID: ${item.id}`; name = `ID: ${item.id}`;
} }
let material = "" let material = "";
if (item.material) { if (item.material) {
material = ` - ${item.material}`; material = ` - ${item.material}`;
} }
const label = `${vendorPrefix}${name}${material}`; const label = `${vendorPrefix}${name}${material}`;