From 30ee5b7caed64b60b4f2aab9af2448766e8704c0 Mon Sep 17 00:00:00 2001 From: Michal Kunc Date: Sat, 10 Feb 2024 00:09:39 +0100 Subject: [PATCH 1/7] Add option to use full URL in QR codes instead of `web+spoolman:` prefix --- client/public/locales/cs/common.json | 3 ++- client/public/locales/en/common.json | 3 ++- .../src/components/printing/spoolQrCodePrintingDialog.tsx | 6 +++++- client/src/components/qrCodeScanner.tsx | 5 +++++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/client/public/locales/cs/common.json b/client/public/locales/cs/common.json index 8d81cb6..bbc6f69 100644 --- a/client/public/locales/cs/common.json +++ b/client/public/locales/cs/common.json @@ -105,7 +105,8 @@ "showTemperatures": "Teploty", "showSpoolComment": "Poznámka k cívce", "showFilamentComment": "Poznámka k filamentu", - "showVendorComment": "Poznámka k výrobci" + "showVendorComment": "Poznámka k výrobci", + "useHTTPUrl": "Použít HTTP(S) odkaz v QR kódu" }, "spoolSelect": { "title": "Vybrat cívky", diff --git a/client/public/locales/en/common.json b/client/public/locales/en/common.json index 53160f8..348a687 100644 --- a/client/public/locales/en/common.json +++ b/client/public/locales/en/common.json @@ -106,7 +106,8 @@ "showTemperatures": "Temperatures", "showSpoolComment": "Spool Comment", "showFilamentComment": "Filament Comment", - "showVendorComment": "Vendor Comment" + "showVendorComment": "Vendor Comment", + "useHTTPUrl": "Use HTTP(S) link in QR code" }, "spoolSelect": { "title": "Select Spools", diff --git a/client/src/components/printing/spoolQrCodePrintingDialog.tsx b/client/src/components/printing/spoolQrCodePrintingDialog.tsx index b4ad9c3..0d20d10 100644 --- a/client/src/components/printing/spoolQrCodePrintingDialog.tsx +++ b/client/src/components/printing/spoolQrCodePrintingDialog.tsx @@ -21,6 +21,7 @@ const SpoolQRCodePrintingDialog: React.FC = ({ visibl const [showSpoolComment, setShowSpoolComment] = useSavedState("print-showSpoolComment", false); const [showFilamentComment, setShowFilamentComment] = useSavedState("print-showFilamentComment", false); const [showVendorComment, setShowVendorComment] = useSavedState("print-showVendorComment", false); + const [useHTTPUrl, setUseHTTPUrl] = useSavedState("print-useHTTPUrl", false); const formatFilament = (filament: IFilament) => { let vendorPrefix = ""; @@ -49,7 +50,7 @@ const SpoolQRCodePrintingDialog: React.FC = ({ visibl const tempLine = temps.join(" - "); return { - value: `web+spoolman:s-${spool.id}`, + value: useHTTPUrl ? `${window.location.origin}/spool/show/${spool.id}` : `web+spoolman:s-${spool.id}`, label: (

= ({ visibl setShowVendorComment(checked)} /> + + setUseHTTPUrl(checked)} /> + } /> diff --git a/client/src/components/qrCodeScanner.tsx b/client/src/components/qrCodeScanner.tsx index 8f6713d..0106600 100644 --- a/client/src/components/qrCodeScanner.tsx +++ b/client/src/components/qrCodeScanner.tsx @@ -18,6 +18,11 @@ const QRCodeScannerModal: React.FC = () => { setVisible(false); navigate(`/spool/show/${match.groups.id}`); } + const fullURLmatch = result.match(/^https?:\/\/[^/]+\/spool\/show\/(?[0-9]+)$/); + if (fullURLmatch && fullURLmatch.groups) { + setVisible(false); + navigate(`/spool/show/${fullURLmatch.groups.id}`); + } }; return ( From 8c19efa2c40232762abf38774a778b14f6c85e0f Mon Sep 17 00:00:00 2001 From: Michal Kunc Date: Mon, 4 Mar 2024 00:43:20 +0100 Subject: [PATCH 2/7] Add QR Code base URL setting --- client/public/locales/cs/common.json | 4 +++ client/public/locales/en/common.json | 9 +++++- .../printing/spoolQrCodePrintingDialog.tsx | 9 ++++-- client/src/pages/settings/generalSettings.tsx | 28 ++++++++++++++++++- spoolman/settings.py | 1 + 5 files changed, 46 insertions(+), 5 deletions(-) diff --git a/client/public/locales/cs/common.json b/client/public/locales/cs/common.json index bbc6f69..0a1c636 100644 --- a/client/public/locales/cs/common.json +++ b/client/public/locales/cs/common.json @@ -327,6 +327,10 @@ "tab": "Obecné", "currency": { "label": "Měna" + }, + "qr_code_url": { + "label": "URL pro QR kódy", + "tooltip": "Základ URL pro generování QR kódů. Pokud můžete přistupovat ke svému Spoolmanovi přes více URL, nastavte zde vaší 'kanonickou' URL instance Spoolmana." } } } diff --git a/client/public/locales/en/common.json b/client/public/locales/en/common.json index 348a687..470efe2 100644 --- a/client/public/locales/en/common.json +++ b/client/public/locales/en/common.json @@ -107,7 +107,10 @@ "showSpoolComment": "Spool Comment", "showFilamentComment": "Filament Comment", "showVendorComment": "Vendor Comment", - "useHTTPUrl": "Use HTTP(S) link in QR code" + "useHTTPUrl": { + "label": "Use HTTP(S) link in QR code", + "tooltip": "Uses either the base URL specified in settings, or the current page URL if not set." + } }, "spoolSelect": { "title": "Select Spools", @@ -265,6 +268,10 @@ "tab": "General", "currency": { "label": "Currency" + }, + "qr_code_url": { + "label": "URL for QR codes", + "tooltip": "The base URL to use when generating QR codes. If you can access your Spoolman via multiple URLs, set this to the 'canonical' URL of your Spoolman instance." } }, "extra_fields": { diff --git a/client/src/components/printing/spoolQrCodePrintingDialog.tsx b/client/src/components/printing/spoolQrCodePrintingDialog.tsx index 0d20d10..4a2dcd2 100644 --- a/client/src/components/printing/spoolQrCodePrintingDialog.tsx +++ b/client/src/components/printing/spoolQrCodePrintingDialog.tsx @@ -3,6 +3,7 @@ import { IFilament } from "../../pages/filaments/model"; import { ISpool } from "../../pages/spools/model"; import QRCodePrintingDialog from "./qrCodePrintingDialog"; import { useSavedState } from "../../utils/saveload"; +import { useGetSetting } from "../../utils/querySettings"; import { useTranslate } from "@refinedev/core"; interface SpoolQRCodePrintingDialog { @@ -13,6 +14,8 @@ interface SpoolQRCodePrintingDialog { const SpoolQRCodePrintingDialog: React.FC = ({ visible, items, onCancel }) => { const t = useTranslate(); + const baseUrlSetting = useGetSetting("qr_code_url"); + const baseUrlRoot = baseUrlSetting.data?.value !== undefined && JSON.parse(baseUrlSetting.data?.value) !== "" ? JSON.parse(baseUrlSetting.data?.value) : window.location.origin; const [showVendor, setShowVendor] = useSavedState("print-showVendor", true); const [showLotNr, setShowLotNr] = useSavedState("print-showLotNr", true); @@ -21,7 +24,7 @@ const SpoolQRCodePrintingDialog: React.FC = ({ visibl const [showSpoolComment, setShowSpoolComment] = useSavedState("print-showSpoolComment", false); const [showFilamentComment, setShowFilamentComment] = useSavedState("print-showFilamentComment", false); const [showVendorComment, setShowVendorComment] = useSavedState("print-showVendorComment", false); - const [useHTTPUrl, setUseHTTPUrl] = useSavedState("print-useHTTPUrl", false); + const [useHTTPUrl, setUseHTTPUrl] = useSavedState("print-useHTTPUrl", baseUrlSetting.data?.value !== ""); const formatFilament = (filament: IFilament) => { let vendorPrefix = ""; @@ -50,7 +53,7 @@ const SpoolQRCodePrintingDialog: React.FC = ({ visibl const tempLine = temps.join(" - "); return { - value: useHTTPUrl ? `${window.location.origin}/spool/show/${spool.id}` : `web+spoolman:s-${spool.id}`, + value: useHTTPUrl ? `${baseUrlRoot}/spool/show/${spool.id}` : `web+spoolman:s-${spool.id}`, label: (

= ({ visibl setShowVendorComment(checked)} /> - + setUseHTTPUrl(checked)} /> diff --git a/client/src/pages/settings/generalSettings.tsx b/client/src/pages/settings/generalSettings.tsx index c8c2f42..b28e2af 100644 --- a/client/src/pages/settings/generalSettings.tsx +++ b/client/src/pages/settings/generalSettings.tsx @@ -15,6 +15,7 @@ export function GeneralSettings() { if (settings.data) { form.setFieldsValue({ currency: JSON.parse(settings.data.currency.value), + qr_code_url: JSON.parse(settings.data.qr_code_url.value), }); } }, [settings.data, form]); @@ -27,7 +28,7 @@ export function GeneralSettings() { }, [setSetting.isSuccess, messageApi, t]); // Handle form submit - const onFinish = (values: { currency: string }) => { + const onFinish = (values: { currency: string, qr_code_url: string }) => { // Check if the currency has changed if (settings.data?.currency.value !== JSON.stringify(values.currency)) { setSetting.mutate({ @@ -35,6 +36,13 @@ export function GeneralSettings() { value: JSON.stringify(values.currency), }); } + // Check if the QR code URL has changed + if (settings.data?.qr_code_url.value !== JSON.stringify(values.qr_code_url)) { + setSetting.mutate({ + key: "qr_code_url", + value: JSON.stringify(values.qr_code_url), + }); + } }; return ( @@ -67,6 +75,24 @@ export function GeneralSettings() { + + + +