feat: add label preview functionality to barcode templates with backend rendering and UI modal
Build and Push Multi-Platform Images / build-and-push (push) Successful in 33s

This commit is contained in:
2026-05-07 23:52:39 +02:00
parent 71502df7b4
commit 71b447154d
4 changed files with 107 additions and 4 deletions
@@ -155,6 +155,39 @@ export class LabelPrintAgentService {
await this.callUrl('RELEASE', job);
}
async renderPreview(templateId: number, fieldValues: Record<string, string>): Promise<Buffer> {
const template = await this.templateRepo.findOne({ where: { Id: templateId } });
if (!template) throw new NotFoundException('Template nicht gefunden');
if (!template.LabelLayout?.length) throw new BadRequestException('Kein Layout definiert');
const vars: Record<string, string> = { ...fieldValues };
for (const field of template.LabelInputFields ?? []) {
if (field.type === 'date' && fieldValues[field.name]) {
const parts = fieldValues[field.name].split('-');
if (parts.length === 3) {
vars[`${field.name}.year`] = parts[0];
vars[`${field.name}.month`] = parts[1];
vars[`${field.name}.day`] = parts[2];
}
}
}
if (template.LabelGetUrl) {
const url = applyVars(template.LabelGetUrl, vars);
try {
vars['number'] = (await (await fetch(url)).text()).trim();
} catch (err: any) {
this.logger.warn(`GET-URL fehlgeschlagen (${url}): ${err.message}`);
}
}
return this.renderer.render(
template.LabelLayout,
template.LabelWidthMm ?? 57,
template.LabelHeightMm ?? 32,
vars,
);
}
private async callUrl(type: 'PRINTED' | 'RELEASE', job: LabelPrintJob): Promise<void> {
const template = job.BarcodeTemplateId
? await this.templateRepo.findOne({ where: { Id: job.BarcodeTemplateId } })