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

@@ -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<QRCodePrintingDialogProps> = ({
@@ -25,6 +30,9 @@ const QRCodePrintingDialog: React.FC<QRCodePrintingDialogProps> = ({
extraSettings,
extraSettingsStart,
extraButtons,
baseUrlRoot,
useHTTPUrl,
setUseHTTPUrl,
}) => {
const t = useTranslate();
@@ -87,6 +95,23 @@ const QRCodePrintingDialog: React.FC<QRCodePrintingDialogProps> = ({
buttonStyle="solid"
/>
</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")}>
<Switch
checked={showContent}
@@ -128,7 +153,6 @@ const QRCodePrintingDialog: React.FC<QRCodePrintingDialogProps> = ({
</Col>
</Row>
</Form.Item>
{extraSettings}
</>
}

View File

@@ -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={
<>
<Form.Item label={t("printing.generic.settings")}>
@@ -323,9 +326,6 @@ Lot Nr: {lot_nr}
}}
/>
</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)}>
<Table
size="small"

View File

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