Merge pull request #461 from samturner3/master

Feature: Add option to use full URL in QR codes instead of web+spoolman: prefix
This commit is contained in:
Donkie
2024-08-26 20:23:25 +02:00
committed by GitHub
7 changed files with 92 additions and 3 deletions

View File

@@ -18,6 +18,11 @@ const QRCodeScannerModal: React.FC = () => {
setVisible(false);
navigate(`/spool/show/${match.groups.id}`);
}
const fullURLmatch = result.match(/^https?:\/\/[^/]+\/spool\/show\/(?<id>[0-9]+)$/);
if (fullURLmatch && fullURLmatch.groups) {
setVisible(false);
navigate(`/spool/show/${fullURLmatch.groups.id}`);
}
};
return (

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}

View File

@@ -1,4 +1,5 @@
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 } from "antd";
import TextArea from "antd/es/input/TextArea";
@@ -24,7 +25,13 @@ interface SpoolQRCodePrintingDialog {
const SpoolQRCodePrintingDialog: React.FC<SpoolQRCodePrintingDialog> = ({ spoolIds }) => {
const t = useTranslate();
const baseUrlSetting = useGetSetting("base_url");
const baseUrlRoot =
baseUrlSetting.data?.value !== undefined && JSON.parse(baseUrlSetting.data?.value) !== ""
? JSON.parse(baseUrlSetting.data?.value)
: window.location.origin;
const [messageApi, contextHolder] = message.useMessage();
const [useHTTPUrl, setUseHTTPUrl] = useSavedState("print-useHTTPUrl", false);
const itemQueries = useGetSpoolsByIds(spoolIds);
const items = itemQueries
@@ -231,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")}>
@@ -290,7 +300,7 @@ Lot Nr: {lot_nr}
</>
}
items={items.map((spool) => ({
value: `web+spoolman:s-${spool.id}`,
value: useHTTPUrl ? `${baseUrlRoot}/spool/show/${spool.id}` : `web+spoolman:s-${spool.id}`,
label: (
<p
style={{

View File

@@ -5,6 +5,7 @@ import { useGetSettings, useSetSetting } from "../../utils/querySettings";
export function GeneralSettings() {
const settings = useGetSettings();
const setBaseUrl = useSetSetting("base_url");
const setCurrency = useSetSetting("currency");
const [form] = Form.useForm();
const [messageApi, contextHolder] = message.useMessage();
@@ -15,6 +16,7 @@ export function GeneralSettings() {
if (settings.data) {
form.setFieldsValue({
currency: JSON.parse(settings.data.currency.value),
base_url: JSON.parse(settings.data.base_url.value),
});
}
}, [settings.data, form]);
@@ -27,11 +29,15 @@ export function GeneralSettings() {
}, [setCurrency.isSuccess, messageApi, t]);
// Handle form submit
const onFinish = (values: { currency: string }) => {
const onFinish = (values: { currency: string; base_url: string }) => {
// Check if the currency has changed
if (settings.data?.currency.value !== JSON.stringify(values.currency)) {
setCurrency.mutate(values.currency);
}
// Check if the base URL has changed
if (settings.data?.base_url.value !== JSON.stringify(values.base_url)) {
setBaseUrl.mutate(values.base_url);
}
};
return (
@@ -64,6 +70,22 @@ export function GeneralSettings() {
<Input />
</Form.Item>
<Form.Item
label={t("settings.general.base_url.label")}
tooltip={t("settings.general.base_url.tooltip")}
name="base_url"
rules={[
{
required: false,
},
{
pattern: /^https?:\/\/.+(?<!\/)$/,
},
]}
>
<Input placeholder="https://example.com:8000" />
</Form.Item>
<Form.Item wrapperCol={{ offset: 8, span: 16 }}>
<Button type="primary" htmlType="submit" loading={settings.isFetching || setCurrency.isLoading}>
{t("buttons.save")}