Files
paperlessmanager/paperless-frontend/src/api/barcode-templates.ts
T
2026-05-07 22:46:29 +02:00

73 lines
2.1 KiB
TypeScript

import api from './client';
export type BarcodeActionType = 'SEND_TO_PAPERLESS' | 'SEND_BY_EMAIL';
export interface LabelInputField {
name: string;
label: string;
type: 'text' | 'number' | 'date';
}
export type LabelElement =
| { type: 'text'; content: string; x: number; y: number; fontSize: number; bold?: boolean; align?: 'left' | 'center' | 'right'; maxWidth?: number }
| { type: 'qr'; content: string; x: number; y: number; sizeMm: number }
| { type: 'line'; x1: number; y1: number; x2: number; y2: number; lineWidth?: number };
export interface BarcodeTemplate {
Id: number;
Name: string;
Regex: string;
SplitBefore: boolean;
DateinameTemplate: string | null;
Actions: BarcodeActionType[];
LabelEnabled: boolean;
LabelWidthMm: number | null;
LabelHeightMm: number | null;
LabelInputFields: LabelInputField[] | null;
LabelGetUrl: string | null;
LabelPrintedUrl: string | null;
LabelReleaseUrl: string | null;
LabelLayout: LabelElement[] | null;
CreatedAt: string;
UpdatedAt: string;
}
export interface BarcodeTemplateInput {
Name: string;
Regex: string;
SplitBefore: boolean;
DateinameTemplate?: string | null;
Actions: BarcodeActionType[];
LabelEnabled?: boolean;
LabelWidthMm?: number | null;
LabelHeightMm?: number | null;
LabelInputFields?: LabelInputField[] | null;
LabelGetUrl?: string | null;
LabelPrintedUrl?: string | null;
LabelReleaseUrl?: string | null;
LabelLayout?: LabelElement[] | null;
}
export const BARCODE_ACTION_LABELS: Record<BarcodeActionType, string> = {
SEND_TO_PAPERLESS: 'Datei an Paperless senden',
SEND_BY_EMAIL: 'Datei per E-Mail senden',
};
export const barcodeTemplatesApi = {
list: () =>
api.get<BarcodeTemplate[]>('/api/barcode-templates').then((r) => r.data),
create: (input: BarcodeTemplateInput) =>
api
.post<BarcodeTemplate>('/api/barcode-templates', input)
.then((r) => r.data),
update: (id: number, input: Partial<BarcodeTemplateInput>) =>
api
.put<BarcodeTemplate>(`/api/barcode-templates/${id}`, input)
.then((r) => r.data),
remove: (id: number) =>
api.delete(`/api/barcode-templates/${id}`).then((r) => r.data),
};