Label template

This commit is contained in:
Eden Kirin
2023-07-31 14:45:16 +02:00
parent 6136d35dff
commit 13ddd7d2b4
2 changed files with 79 additions and 38 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 KiB

View File

@ -33,27 +33,51 @@ const TEMPLATES = {
^XZ ^XZ
`, `,
qrCodePos: { agencyLogo: {
dimensions: {
width: 260,
height: 73,
},
pos: {
x: 20,
y: 85,
},
},
qrCode: {
dimensions: {
width: 250,
height: 250,
},
pos: {
x: 300, x: 300,
y: 10, y: 10,
}, },
companyNamePos: { },
companyName: {
pos: {
x: 20, x: 20,
y: 10, y: 10,
}, },
machineModelPos: { },
machineModel: {
pos: {
x: 20, x: 20,
y: 180, y: 180,
}, },
masterSystemIdPos: { },
masterSystemId: {
pos: {
x: 20, x: 20,
y: 210, y: 210,
}, },
extMasterSystemIdIdPos: { },
extMasterSystemIdId: {
pos: {
x: 20, x: 20,
y: 55, y: 55,
}, },
}, },
},
}; };
function replaceTemplateVars(template, vars) { function replaceTemplateVars(template, vars) {
@ -69,25 +93,25 @@ function replaceTemplateVars(template, vars) {
return trimmed; return trimmed;
} }
function createInternalStickerZPL(templateName, vars) { function renderInternalStickerTemplate(templateName, vars) {
const template = TEMPLATES[templateName]; const template = TEMPLATES[templateName];
return replaceTemplateVars(template.content, { return replaceTemplateVars(template.content, {
qrCodeZPL: vars.qrCodeZPL, qrCodeZPL: vars.qrCodeZPL,
qrCodeXpos: template.qrCodePos.x, qrCodeXpos: template.qrCode.pos.x,
qrCodeYpos: template.qrCodePos.y, qrCodeYpos: template.qrCode.pos.y,
companyName: vars.companyName, companyName: vars.companyName,
companyNameXpos: template.companyNamePos.x, companyNameXpos: template.companyName.pos.x,
companyNameYpos: template.companyNamePos.y, companyNameYpos: template.companyName.pos.y,
machineModel: vars.machineModel, machineModel: vars.machineModel,
machineModelXpos: template.machineModelPos.x, machineModelXpos: template.machineModel.pos.x,
machineModelYpos: template.machineModelPos.y, machineModelYpos: template.machineModel.pos.y,
masterSystemId: vars.masterSystemId, masterSystemId: vars.masterSystemId,
masterSystemIdXpos: template.masterSystemIdPos.x, masterSystemIdXpos: template.masterSystemId.pos.x,
masterSystemIdYpos: template.masterSystemIdPos.y, masterSystemIdYpos: template.masterSystemId.pos.y,
extMasterSystemId: vars.extMasterSystemId, extMasterSystemId: vars.extMasterSystemId,
extMasterSystemIdXpos: template.extMasterSystemIdIdPos.x, extMasterSystemIdXpos: template.extMasterSystemIdId.pos.x,
extMasterSystemIdYpos: template.extMasterSystemIdIdPos.y, extMasterSystemIdYpos: template.extMasterSystemIdId.pos.y,
}); });
} }
@ -122,17 +146,34 @@ function imageToGRF(imgUrl, options) {
}); });
} }
imageToGRF("/assets/qr-code-example.jpeg", { function createInternalStickerZPL(options) {
width: 250, const templateName = "sticker-70x35";
height: 250, const template = TEMPLATES[templateName];
return new Promise((resolve, reject) => {
imageToGRF(options.qrCodeUrl, {
width: template.qrCode.dimensions.width,
height: template.qrCode.dimensions.height,
}).then((qrCodeZPL) => { }).then((qrCodeZPL) => {
const internalTicketZPL = createInternalStickerZPL("sticker-70x35", { const zpl = renderInternalStickerTemplate(templateName, {
qrCodeZPL: qrCodeZPL, qrCodeZPL,
...options,
});
resolve(zpl);
});
});
}
const options = {
qrCodeUrl: "/assets/qr-code-example.jpeg",
agencyLogoUrl: "/assets/agenzia-entrate-logo-color.png",
companyName: "Vandelay Industries", companyName: "Vandelay Industries",
machineModel: "Model XL-123", machineModel: "Model XL-123",
masterSystemId: "master-system-id", masterSystemId: "master-system-id",
extMasterSystemId: "ext-msid", extMasterSystemId: "ext-msid",
}); };
document.querySelector(`textarea[name="zpl"]`).value = internalTicketZPL; createInternalStickerZPL(options).then((zpl) => {
document.querySelector(`textarea[name="zpl"]`).value = zpl;
}); });