Work on badge printing and the actual badge layout.
This commit is contained in:
@@ -34,6 +34,7 @@ import {
|
||||
|
||||
import {
|
||||
generate_qr_code,
|
||||
js_generate_qr_code,
|
||||
} from "$lib/ae_core/core__qr_code";
|
||||
|
||||
import {
|
||||
@@ -697,6 +698,7 @@ let export_obj = {
|
||||
handle_update_ae_obj_id_crud: handle_update_ae_obj_id_crud,
|
||||
update_ae_obj_id_crud_v2: update_ae_obj_id_crud_v2,
|
||||
handle_download_export__obj_type: handle_download_export__obj_type,
|
||||
generate_qr_code: generate_qr_code
|
||||
generate_qr_code: generate_qr_code,
|
||||
js_generate_qr_code: js_generate_qr_code,
|
||||
};
|
||||
export let core_func = export_obj;
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import QRCode from 'qrcode'
|
||||
|
||||
import type { key_val } from '$lib/ae_stores';
|
||||
import { api } from '$lib/api';
|
||||
|
||||
@@ -136,4 +138,103 @@ export async function generate_qr_code(
|
||||
|
||||
// If not returning a blob, return the raw API response
|
||||
return ae_promises.generate_qr_code;
|
||||
}
|
||||
|
||||
|
||||
// Updated 2025-10-09
|
||||
/**
|
||||
* Generates a QR code image as a Base64 data URL based on provided parameters.
|
||||
*
|
||||
* NOTE: This function handles the data formatting and QR generation,
|
||||
* but does NOT handle server-side logic like file saving, disk path checks,
|
||||
* or database lookups (like redis_lookup_id_random).
|
||||
*
|
||||
* @param {string} qr_type - The type of data format ('mecard', 'vcard', 'obj', 'kv', 'js', 'str').
|
||||
* @param {Object} params - An object containing all necessary query parameters (n, fn, url, email, etc.).
|
||||
* @param {string} qr_id - A unique ID (unused in pure client-side generation, but kept for context).
|
||||
* @returns {Promise<string>} A promise that resolves to a Base64 data URL of the QR code image.
|
||||
* @throws {Error} If the qr_type is unknown or data is missing.
|
||||
*/
|
||||
export async function js_generate_qr_code(qr_type, params = {}) {
|
||||
const {
|
||||
n = '', fn = '', org = '', url = '', email = '', tel = '',
|
||||
adr_poa = '', adr_ext = '', adr_str = '', adr_loc = '', adr_reg = '', adr_postal = '', adr_country = '',
|
||||
obj_type, obj_id, key, val, js, str
|
||||
} = params;
|
||||
|
||||
console.log(`*** js_generate_qr_code() *** qr_type=${qr_type}`, params);
|
||||
|
||||
let qrData = null;
|
||||
|
||||
// --- 1. Replicate Data Formatting Logic ---
|
||||
switch (qr_type) {
|
||||
case 'mecard':
|
||||
// Format: MECARD:N:name;EMAIL:email;ADR:address;;
|
||||
// Note: The original Python code had adr, but we'll use n and email as a minimum.
|
||||
qrData = `MECARD:N:${n};EMAIL:${email};;`;
|
||||
// You can enhance this with other MeCard fields if needed.
|
||||
break;
|
||||
|
||||
case 'vcard':
|
||||
// Format: BEGIN:VCARD...END:VCARD
|
||||
qrData = `BEGIN:VCARD\nVERSION:3.0\nN:${n}\nFN:${fn}\nORG:${org}\nEMAIL:${email}\n`;
|
||||
|
||||
if (url) { qrData += `URL:${url}\n`; }
|
||||
if (tel) { qrData += `TEL:${tel}\n`; }
|
||||
if (adr_loc) {
|
||||
// ADR format: TYPE=postal:Po box;Ext;Street;Locality;Region;Postal code;Country
|
||||
qrData += `ADR:${adr_poa};${adr_ext};${adr_str};${adr_loc};${adr_reg};${adr_postal};${adr_country}\n`;
|
||||
}
|
||||
qrData += 'END:VCARD';
|
||||
break;
|
||||
|
||||
case 'obj':
|
||||
// Custom format: OBJ:ot:obj_type,oi:obj_id
|
||||
if (!obj_type || !obj_id) throw new Error('Missing obj_type or obj_id for type "obj".');
|
||||
qrData = `OBJ:ot:${obj_type},oi:${obj_id}`;
|
||||
break;
|
||||
|
||||
case 'kv':
|
||||
// Custom format: KV:k:"key",v:"val"
|
||||
if (!key || !val) throw new Error('Missing key or val for type "kv".');
|
||||
qrData = `KV:k:"${key}",v:"${val}"`;
|
||||
break;
|
||||
|
||||
case 'js':
|
||||
// Assumes 'js' is a stringified JSON object
|
||||
if (!js) throw new Error('Missing js string for type "js".');
|
||||
qrData = `JS:${js}`;
|
||||
break;
|
||||
|
||||
case 'str':
|
||||
// Raw string data
|
||||
if (!str) throw new Error('Missing raw string data for type "str".');
|
||||
qrData = str;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Error(`Unknown QR type: ${qr_type}`);
|
||||
}
|
||||
|
||||
if (!qrData) {
|
||||
throw new Error('Failed to create QR code data string.');
|
||||
}
|
||||
|
||||
// --- 2. Generate QR Code Image ---
|
||||
try {
|
||||
// Options match the Python 'qrcode' library defaults closely:
|
||||
// error_correction = qrcode.constants.ERROR_CORRECT_M
|
||||
// box_size = 10, border = 1
|
||||
const dataUrl = await QRCode.toDataURL(qrData, {
|
||||
errorCorrectionLevel: 'M',
|
||||
margin: 1, // Corresponds to border
|
||||
scale: 10, // Corresponds to box_size
|
||||
type: 'image/png',
|
||||
});
|
||||
console.log('Generated QR code data URL:', dataUrl);
|
||||
return dataUrl;
|
||||
} catch (error) {
|
||||
console.error('Error generating QR code:', error);
|
||||
throw new Error('Could not generate QR code image.');
|
||||
}
|
||||
}
|
||||
@@ -18,14 +18,55 @@ export const properties_to_save = [
|
||||
'name',
|
||||
'description',
|
||||
|
||||
'template_code',
|
||||
'template_type',
|
||||
'template_json',
|
||||
'template_svg',
|
||||
'template_css',
|
||||
'template_html',
|
||||
// 'template_code',
|
||||
// 'template_type',
|
||||
// 'template_json',
|
||||
// 'template_svg',
|
||||
// 'template_css',
|
||||
// 'template_html',
|
||||
|
||||
'default',
|
||||
'logo_filename',
|
||||
'logo_path',
|
||||
|
||||
'header_path',
|
||||
'secondary_header_path',
|
||||
'footer_path',
|
||||
|
||||
'header_row_1',
|
||||
'header_row_2',
|
||||
|
||||
// 'footer_title',
|
||||
// 'footer_left',
|
||||
// 'footer_right',
|
||||
// 'header_background',
|
||||
// 'footer_background',
|
||||
|
||||
'badge_type_list',
|
||||
'ticket_list',
|
||||
|
||||
'ticket_1_text',
|
||||
'ticket_2_text',
|
||||
'ticket_3_text',
|
||||
'ticket_4_text',
|
||||
'ticket_5_text',
|
||||
'ticket_6_text',
|
||||
'ticket_7_text',
|
||||
'ticket_8_text',
|
||||
// 'ticket_9_text',
|
||||
// 'ticket_10_text',
|
||||
|
||||
'wireless_ssid',
|
||||
'wireless_password',
|
||||
|
||||
'show_qr_front',
|
||||
'show_qr_back',
|
||||
|
||||
'layout',
|
||||
'style_filename',
|
||||
// 'style_href',
|
||||
|
||||
|
||||
// 'default',
|
||||
'enable',
|
||||
'hide',
|
||||
'priority',
|
||||
@@ -70,14 +111,38 @@ export async function process_ae_obj__event_badge_template_props({
|
||||
name: obj.name,
|
||||
description: obj.description,
|
||||
|
||||
template_code: obj.template_code,
|
||||
template_type: obj.template_type,
|
||||
template_json: obj.template_json,
|
||||
template_svg: obj.template_svg,
|
||||
template_css: obj.template_css,
|
||||
template_html: obj.template_html,
|
||||
logo_filename: obj.logo_filename,
|
||||
logo_path: obj.logo_path,
|
||||
|
||||
default: obj.default,
|
||||
header_path: obj.header_path,
|
||||
secondary_header_path: obj.secondary_header_path,
|
||||
footer_path: obj.footer_path,
|
||||
|
||||
header_row_1: obj.header_row_1,
|
||||
header_row_2: obj.header_row_2,
|
||||
|
||||
badge_type_list: obj.badge_type_list,
|
||||
ticket_list: obj.ticket_list,
|
||||
|
||||
ticket_1_text: obj.ticket_1_text,
|
||||
ticket_2_text: obj.ticket_2_text,
|
||||
ticket_3_text: obj.ticket_3_text,
|
||||
ticket_4_text: obj.ticket_4_text,
|
||||
ticket_5_text: obj.ticket_5_text,
|
||||
ticket_6_text: obj.ticket_6_text,
|
||||
ticket_7_text: obj.ticket_7_text,
|
||||
ticket_8_text: obj.ticket_8_text,
|
||||
|
||||
wireless_ssid: obj.wireless_ssid,
|
||||
wireless_password: obj.wireless_password,
|
||||
|
||||
show_qr_front: obj.show_qr_front,
|
||||
show_qr_back: obj.show_qr_back,
|
||||
|
||||
layout: obj.layout,
|
||||
style_filename: obj.style_filename,
|
||||
|
||||
// default: obj.default,
|
||||
enable: obj.enable,
|
||||
hide: obj.hide,
|
||||
priority: obj.priority,
|
||||
|
||||
@@ -198,7 +198,55 @@ export interface Badge_template {
|
||||
event_id: string;
|
||||
event_id_random: string;
|
||||
|
||||
name: string;
|
||||
description?: null|string;
|
||||
|
||||
logo_filename?: null|string;
|
||||
logo_path?: null|string;
|
||||
|
||||
header_path?: null|string;
|
||||
secondary_header_path?: null|string;
|
||||
footer_path?: null|string;
|
||||
|
||||
header_row_1?: null|string;
|
||||
header_row_2?: null|string;
|
||||
|
||||
badge_type_list?: any; // This is an array of objects with code and name
|
||||
badge_type_info_kv?: any; // This is a key value list with code as the key and name as the value. Use this for exhibitor, presenter, attendee, staff, vip, etc.
|
||||
other_info_kv?: any; // This is a key value list with code as the key and name as the value. Use this for other custom fields.
|
||||
|
||||
ticket_list?: any; // This is an array of objects with num, code, and name
|
||||
|
||||
ticket_1_text?: null|string;
|
||||
ticket_2_text?: null|string;
|
||||
ticket_3_text?: null|string;
|
||||
ticket_4_text?: null|string;
|
||||
ticket_5_text?: null|string;
|
||||
ticket_6_text?: null|string;
|
||||
ticket_7_text?: null|string;
|
||||
ticket_8_text?: null|string;
|
||||
|
||||
wireless_ssid?: null|string;
|
||||
wireless_password?: null|string;
|
||||
|
||||
show_qr_front: boolean;
|
||||
show_qr_back: boolean;
|
||||
|
||||
layout?: null|string;
|
||||
style_filename?: null|string;
|
||||
|
||||
enable: null|boolean;
|
||||
hide?: null|boolean;
|
||||
priority?: null|boolean
|
||||
sort?: null|number;
|
||||
group?: null|string;
|
||||
notes?: null|string;
|
||||
created_on: Date;
|
||||
updated_on?: null|Date;
|
||||
|
||||
// Generated fields for sorting locally only
|
||||
|
||||
// Additional fields for convenience (database views)
|
||||
}
|
||||
|
||||
// Updated 2024-10-16
|
||||
|
||||
Reference in New Issue
Block a user