feat: Add base_url and URB based QR code on labels

This commit is contained in:
samturner3
2024-08-26 18:02:31 +10:00
parent a0e9f10127
commit c54e11ca11
5 changed files with 55 additions and 21 deletions

View File

@@ -119,8 +119,13 @@
"showFilamentComment": "Poznámka k filamentu", "showFilamentComment": "Poznámka k filamentu",
"showVendorComment": "Poznámka k výrobci", "showVendorComment": "Poznámka k výrobci",
"useHTTPUrl": { "useHTTPUrl": {
"label": "Použít HTTP(S) URL", "label": "Odkaz na QR kód",
"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." "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", "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.", "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": { "currency": {
"label": "Měna" "label": "Měna"
}, },
"qr_code_url": { "base_url": {
"label": "URL pro QR kódy", "label": "Základní URL",
"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." "tooltip": "Základní adresa URL, která se má použít při generování funkcí, jako jsou QR kódy"
} }
}, },
"settings": "Nastavení" "settings": "Nastavení"

View File

@@ -116,8 +116,13 @@
"showFilamentComment": "Filament Comment", "showFilamentComment": "Filament Comment",
"showVendorComment": "Vendor Comment", "showVendorComment": "Vendor Comment",
"useHTTPUrl": { "useHTTPUrl": {
"label": "Use HTTP(S) link in QR code", "label": "QR code link",
"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." "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", "showQRCode": "Print QR Code",
"showQRCodeMode": { "showQRCodeMode": {
@@ -311,9 +316,9 @@
"currency": { "currency": {
"label": "Currency" "label": "Currency"
}, },
"qr_code_url": { "base_url": {
"label": "URL for QR codes", "label": "Base URL",
"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." "tooltip": "The base URL to use when generating features such as QR codes."
} }
}, },
"extra_fields": { "extra_fields": {

View File

@@ -1,8 +1,10 @@
import { useTranslate } from "@refinedev/core"; 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 { QRCodePrintSettings } from "./printing";
import PrintingDialog from "./printingDialog"; import PrintingDialog from "./printingDialog";
const { Text } = Typography;
interface QRCodeData { interface QRCodeData {
value: string; value: string;
label?: JSX.Element; label?: JSX.Element;
@@ -16,6 +18,9 @@ interface QRCodePrintingDialogProps {
extraSettings?: JSX.Element; extraSettings?: JSX.Element;
extraSettingsStart?: JSX.Element; extraSettingsStart?: JSX.Element;
extraButtons?: JSX.Element; extraButtons?: JSX.Element;
baseUrlRoot: string;
useHTTPUrl: boolean;
setUseHTTPUrl: (value: boolean) => void;
} }
const QRCodePrintingDialog: React.FC<QRCodePrintingDialogProps> = ({ const QRCodePrintingDialog: React.FC<QRCodePrintingDialogProps> = ({
@@ -25,6 +30,9 @@ const QRCodePrintingDialog: React.FC<QRCodePrintingDialogProps> = ({
extraSettings, extraSettings,
extraSettingsStart, extraSettingsStart,
extraButtons, extraButtons,
baseUrlRoot,
useHTTPUrl,
setUseHTTPUrl,
}) => { }) => {
const t = useTranslate(); const t = useTranslate();
@@ -87,6 +95,23 @@ const QRCodePrintingDialog: React.FC<QRCodePrintingDialogProps> = ({
buttonStyle="solid" buttonStyle="solid"
/> />
</Form.Item> </Form.Item>
{showQRCodeMode !== "no" && (
<>
<Form.Item
label={t("printing.qrcode.useHTTPUrl.label")}
tooltip={t("printing.qrcode.useHTTPUrl.tooltip")}
style={{ marginBottom: 0 }}
>
<Radio.Group onChange={(e) => setUseHTTPUrl(e.target.value)} value={useHTTPUrl}>
<Radio value={false}>{t("printing.qrcode.useHTTPUrl.options.default")}</Radio>
<Radio value={true}>{t("printing.qrcode.useHTTPUrl.options.url")}</Radio>
</Radio.Group>
</Form.Item>
<Form.Item label={t("printing.qrcode.useHTTPUrl.preview")}>
<Text> {useHTTPUrl ? `${baseUrlRoot}/spool/show/{id}` : `web+spoolman:s-{id}`}</Text>
</Form.Item>
</>
)}
<Form.Item label={t("printing.qrcode.showContent")}> <Form.Item label={t("printing.qrcode.showContent")}>
<Switch <Switch
checked={showContent} checked={showContent}
@@ -128,7 +153,6 @@ const QRCodePrintingDialog: React.FC<QRCodePrintingDialogProps> = ({
</Col> </Col>
</Row> </Row>
</Form.Item> </Form.Item>
{extraSettings} {extraSettings}
</> </>
} }

View File

@@ -1,7 +1,7 @@
import { CopyOutlined, DeleteOutlined, PlusOutlined, SaveOutlined } from "@ant-design/icons"; import { CopyOutlined, DeleteOutlined, PlusOutlined, SaveOutlined } from "@ant-design/icons";
import { useGetSetting } from "../../utils/querySettings"; import { useGetSetting } from "../../utils/querySettings";
import { useTranslate } from "@refinedev/core"; 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 TextArea from "antd/es/input/TextArea";
import { useState } from "react"; import { useState } from "react";
import { v4 as uuidv4 } from "uuid"; import { v4 as uuidv4 } from "uuid";
@@ -238,6 +238,9 @@ Lot Nr: {lot_nr}
curPreset.labelSettings = newSettings; curPreset.labelSettings = newSettings;
updateCurrentPreset(curPreset); updateCurrentPreset(curPreset);
}} }}
baseUrlRoot={baseUrlRoot}
useHTTPUrl={useHTTPUrl}
setUseHTTPUrl={setUseHTTPUrl}
extraSettingsStart={ extraSettingsStart={
<> <>
<Form.Item label={t("printing.generic.settings")}> <Form.Item label={t("printing.generic.settings")}>
@@ -323,9 +326,6 @@ Lot Nr: {lot_nr}
}} }}
/> />
</Form.Item> </Form.Item>
<Form.Item label={t("printing.qrcode.useHTTPUrl.label")} tooltip={t("printing.qrcode.useHTTPUrl.tooltip")}>
<Switch checked={useHTTPUrl} onChange={(checked) => setUseHTTPUrl(checked)} />
</Form.Item>
<Modal open={templateHelpOpen} footer={null} onCancel={() => setTemplateHelpOpen(false)}> <Modal open={templateHelpOpen} footer={null} onCancel={() => setTemplateHelpOpen(false)}>
<Table <Table
size="small" size="small"

View File

@@ -71,19 +71,19 @@ export function GeneralSettings() {
</Form.Item> </Form.Item>
<Form.Item <Form.Item
label={t("settings.general.qr_code_url.label")} label={t("settings.general.base_url.label")}
tooltip={t("settings.general.qr_code_url.tooltip")} tooltip={t("settings.general.base_url.tooltip")}
name="qr_code_url" name="base_url"
rules={[ rules={[
{ {
required: false, required: false,
}, },
{ {
pattern: /^https?:\/\/.*/, pattern: /^https?:\/\/.+(?<!\/)$/,
}, },
]} ]}
> >
<Input placeholder="https://example.com:8000/" /> <Input placeholder="https://example.com:8000" />
</Form.Item> </Form.Item>
<Form.Item wrapperCol={{ offset: 8, span: 16 }}> <Form.Item wrapperCol={{ offset: 8, span: 16 }}>