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() { + + + +