From c54e11ca1162b6a7e3a224243df88244e5f4f9b3 Mon Sep 17 00:00:00 2001 From: samturner3 Date: Mon, 26 Aug 2024 18:02:31 +1000 Subject: [PATCH] feat: Add base_url and URB based QR code on labels --- client/public/locales/cs/common.json | 15 ++++++---- client/public/locales/en/common.json | 15 ++++++---- .../pages/printing/qrCodePrintingDialog.tsx | 28 +++++++++++++++++-- .../printing/spoolQrCodePrintingDialog.tsx | 8 +++--- client/src/pages/settings/generalSettings.tsx | 10 +++---- 5 files changed, 55 insertions(+), 21 deletions(-) diff --git a/client/public/locales/cs/common.json b/client/public/locales/cs/common.json index 00de426..bcbe56f 100644 --- a/client/public/locales/cs/common.json +++ b/client/public/locales/cs/common.json @@ -119,8 +119,13 @@ "showFilamentComment": "Poznámka k filamentu", "showVendorComment": "Poznámka k výrobci", "useHTTPUrl": { - "label": "Použít HTTP(S) URL", - "tooltip": "Použít HTTP(S) odkaz v QR kódu. Pokud je vypnuto, použije se speciální kód, který půjde načíst pouze skrz skener v aplikaci Spoolman." + "label": "Odkaz na QR kód", + "tooltip": "Použije proprietární odkaz, který bude fungovat pouze v případě, že bude skenován pomocí funkce skenování Spoolman (výchozí). Adresa URL používá buď základní adresu URL zadanou v nastavení, nebo adresu URL aktuální stránky, pokud není nastavena.", + "options": { + "default": "Výchozí", + "url": "URL" + }, + "preview": "Náhled:" }, "template": "Šablona štítku", "templateHelp": "Pomocí {} vložíte hodnoty objektu cívky jako text. Například {id} bude nahrazeno ID cívky nebo {filament.material} bude nahrazeno materiálem cívky. Text uzavřete dvojitou hvězdičkou **, aby byl tučný. Kliknutím na tlačítko zobrazíte seznam všech dostupných značek.", @@ -379,9 +384,9 @@ "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." + "base_url": { + "label": "Základní URL", + "tooltip": "Základní adresa URL, která se má použít při generování funkcí, jako jsou QR kódy" } }, "settings": "Nastavení" diff --git a/client/public/locales/en/common.json b/client/public/locales/en/common.json index b3fb9b3..e79e120 100644 --- a/client/public/locales/en/common.json +++ b/client/public/locales/en/common.json @@ -116,8 +116,13 @@ "showFilamentComment": "Filament Comment", "showVendorComment": "Vendor Comment", "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. If disabled will use proprietary link that will work only if scanned from Spoolman's scanning feature." + "label": "QR code link", + "tooltip": "Will use proprietary link that will work only if scanned from Spoolman's scanning feature (default). URL uses either the base URL specified in settings, or the current page URL if not set.", + "options": { + "default": "Default", + "url": "URL" + }, + "preview": "Preview:" }, "showQRCode": "Print QR Code", "showQRCodeMode": { @@ -311,9 +316,9 @@ "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." + "base_url": { + "label": "Base URL", + "tooltip": "The base URL to use when generating features such as QR codes." } }, "extra_fields": { diff --git a/client/src/pages/printing/qrCodePrintingDialog.tsx b/client/src/pages/printing/qrCodePrintingDialog.tsx index bf2fd6f..d3a51b1 100644 --- a/client/src/pages/printing/qrCodePrintingDialog.tsx +++ b/client/src/pages/printing/qrCodePrintingDialog.tsx @@ -1,8 +1,10 @@ import { useTranslate } from "@refinedev/core"; -import { Col, Form, InputNumber, QRCode, Radio, RadioChangeEvent, Row, Slider, Switch } from "antd"; +import { Col, Form, InputNumber, QRCode, Radio, RadioChangeEvent, Row, Slider, Switch, Typography } from "antd"; import { QRCodePrintSettings } from "./printing"; import PrintingDialog from "./printingDialog"; +const { Text } = Typography; + interface QRCodeData { value: string; label?: JSX.Element; @@ -16,6 +18,9 @@ interface QRCodePrintingDialogProps { extraSettings?: JSX.Element; extraSettingsStart?: JSX.Element; extraButtons?: JSX.Element; + baseUrlRoot: string; + useHTTPUrl: boolean; + setUseHTTPUrl: (value: boolean) => void; } const QRCodePrintingDialog: React.FC = ({ @@ -25,6 +30,9 @@ const QRCodePrintingDialog: React.FC = ({ extraSettings, extraSettingsStart, extraButtons, + baseUrlRoot, + useHTTPUrl, + setUseHTTPUrl, }) => { const t = useTranslate(); @@ -87,6 +95,23 @@ const QRCodePrintingDialog: React.FC = ({ buttonStyle="solid" /> + {showQRCodeMode !== "no" && ( + <> + + setUseHTTPUrl(e.target.value)} value={useHTTPUrl}> + {t("printing.qrcode.useHTTPUrl.options.default")} + {t("printing.qrcode.useHTTPUrl.options.url")} + + + + {useHTTPUrl ? `${baseUrlRoot}/spool/show/{id}` : `web+spoolman:s-{id}`} + + + )} = ({ - {extraSettings} } diff --git a/client/src/pages/printing/spoolQrCodePrintingDialog.tsx b/client/src/pages/printing/spoolQrCodePrintingDialog.tsx index b11ad67..40a6b7c 100644 --- a/client/src/pages/printing/spoolQrCodePrintingDialog.tsx +++ b/client/src/pages/printing/spoolQrCodePrintingDialog.tsx @@ -1,7 +1,7 @@ import { CopyOutlined, DeleteOutlined, PlusOutlined, SaveOutlined } from "@ant-design/icons"; import { useGetSetting } from "../../utils/querySettings"; import { useTranslate } from "@refinedev/core"; -import { Button, Flex, Form, Input, Modal, Popconfirm, Select, Table, Typography, message, Switch } from "antd"; +import { Button, Flex, Form, Input, Modal, Popconfirm, Select, Table, Typography, message } from "antd"; import TextArea from "antd/es/input/TextArea"; import { useState } from "react"; import { v4 as uuidv4 } from "uuid"; @@ -238,6 +238,9 @@ Lot Nr: {lot_nr} curPreset.labelSettings = newSettings; updateCurrentPreset(curPreset); }} + baseUrlRoot={baseUrlRoot} + useHTTPUrl={useHTTPUrl} + setUseHTTPUrl={setUseHTTPUrl} extraSettingsStart={ <> @@ -323,9 +326,6 @@ Lot Nr: {lot_nr} }} /> - - setUseHTTPUrl(checked)} /> - setTemplateHelpOpen(false)}> - +