More serious work on badge printing. Working on the templates and actually implementing the printable badge.
This commit is contained in:
479
src/lib/ae_events/ae_events__event_badge_template.ts
Normal file
479
src/lib/ae_events/ae_events__event_badge_template.ts
Normal file
@@ -0,0 +1,479 @@
|
||||
import type { key_val } from '$lib/ae_stores';
|
||||
import { api } from '$lib/api';
|
||||
import { db_save_ae_obj_li__ae_obj } from "$lib/ae_core/core__idb_dexie";
|
||||
import { db_events } from "$lib/ae_events/db_events";
|
||||
|
||||
let ae_promises: key_val = {};
|
||||
|
||||
|
||||
// --- PROPERTIES TO SAVE ---
|
||||
export const properties_to_save = [
|
||||
'id',
|
||||
'event_badge_template_id',
|
||||
'event_badge_template_id_random',
|
||||
|
||||
'event_id',
|
||||
'event_id_random',
|
||||
|
||||
'name',
|
||||
'description',
|
||||
|
||||
'template_code',
|
||||
'template_type',
|
||||
'template_json',
|
||||
'template_svg',
|
||||
'template_css',
|
||||
'template_html',
|
||||
|
||||
'default',
|
||||
'enable',
|
||||
'hide',
|
||||
'priority',
|
||||
'sort',
|
||||
'group',
|
||||
'notes',
|
||||
'created_on',
|
||||
'updated_on',
|
||||
|
||||
// Generated fields for sorting locally only
|
||||
'tmp_sort_1',
|
||||
'tmp_sort_2',
|
||||
];
|
||||
|
||||
|
||||
// --- PROCESS FUNCTION ---
|
||||
export async function process_ae_obj__event_badge_template_props({
|
||||
obj_li,
|
||||
log_lvl = 0,
|
||||
}: {
|
||||
obj_li: any[];
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** process_ae_obj__event_badge_template_props() ***`, obj_li);
|
||||
}
|
||||
if (!obj_li || obj_li.length === 0) {
|
||||
if (log_lvl) console.log('No objects to process.');
|
||||
return [];
|
||||
}
|
||||
const processed_obj_li = [];
|
||||
for (const obj of obj_li) {
|
||||
if (log_lvl) console.log(`Processing ae_obj event_badge_template:`, obj);
|
||||
let processed_obj = {
|
||||
id: obj.event_badge_template_id_random,
|
||||
event_badge_template_id: obj.event_badge_template_id_random,
|
||||
event_badge_template_id_random: obj.event_badge_template_id_random,
|
||||
|
||||
event_id: obj.event_id_random,
|
||||
event_id_random: obj.event_id_random,
|
||||
|
||||
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,
|
||||
|
||||
default: obj.default,
|
||||
enable: obj.enable,
|
||||
hide: obj.hide,
|
||||
priority: obj.priority,
|
||||
sort: obj.sort,
|
||||
group: obj.group,
|
||||
notes: obj.notes,
|
||||
created_on: obj.created_on,
|
||||
updated_on: obj.updated_on,
|
||||
|
||||
tmp_sort_1: `${obj.group}_${obj.priority}_${obj.sort}_${obj.updated_on ?? obj.created_on}`,
|
||||
tmp_sort_2: `${obj.group}_${obj.priority}_${obj.sort}_${obj.updated_on}_${obj.created_on}`,
|
||||
};
|
||||
processed_obj_li.push(processed_obj);
|
||||
}
|
||||
return processed_obj_li;
|
||||
}
|
||||
|
||||
|
||||
// --- DB SAVE FUNCTION ---
|
||||
export async function db_save_ae_obj_li__event_badge_template({
|
||||
obj_type,
|
||||
obj_li,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
obj_type: string,
|
||||
obj_li: any[],
|
||||
log_lvl?: number
|
||||
}) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** db_save_ae_obj_li__event_badge_template() *** obj_type=${obj_type}`, obj_li);
|
||||
}
|
||||
if (!obj_li || obj_li.length === 0) {
|
||||
if (log_lvl) console.log('No objects to save.');
|
||||
return [];
|
||||
}
|
||||
return await db_save_ae_obj_li__ae_obj({
|
||||
db_instance: db_events,
|
||||
table_name: 'badge_template',
|
||||
obj_li,
|
||||
properties_to_save,
|
||||
log_lvl,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// --- CRUD FUNCTIONS ---
|
||||
export async function load_ae_obj_id__event_badge_template({
|
||||
api_cfg,
|
||||
event_badge_template_id,
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any,
|
||||
event_badge_template_id: string,
|
||||
try_cache?: boolean,
|
||||
log_lvl?: number
|
||||
}) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** load_ae_obj_id__event_badge_template() *** event_badge_template_id=${event_badge_template_id}`);
|
||||
}
|
||||
let params = {};
|
||||
ae_promises.load__event_badge_template_obj = await api.get_ae_obj_id_crud({
|
||||
api_cfg,
|
||||
obj_type: 'event_badge_template',
|
||||
obj_id: event_badge_template_id,
|
||||
use_alt_table: false,
|
||||
use_alt_base: false,
|
||||
params,
|
||||
log_lvl
|
||||
})
|
||||
.then(async function (obj_get_result) {
|
||||
if (obj_get_result) {
|
||||
if (try_cache) {
|
||||
let processed_obj_li = await process_ae_obj__event_badge_template_props({
|
||||
obj_li: [obj_get_result],
|
||||
log_lvl
|
||||
});
|
||||
await db_save_ae_obj_li__ae_obj({
|
||||
db_instance: db_events,
|
||||
table_name: 'badge_template',
|
||||
obj_li: processed_obj_li,
|
||||
properties_to_save,
|
||||
log_lvl,
|
||||
});
|
||||
}
|
||||
return obj_get_result;
|
||||
} else {
|
||||
if (log_lvl) console.log('No results returned.');
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log('No results returned or failed.', error);
|
||||
});
|
||||
return ae_promises.load__event_badge_template_obj;
|
||||
}
|
||||
|
||||
export async function load_ae_obj_li__event_badge_template({
|
||||
api_cfg,
|
||||
event_id,
|
||||
enabled = 'enabled',
|
||||
hidden = 'not_hidden',
|
||||
limit = 49,
|
||||
offset = 0,
|
||||
order_by_li = {'priority': 'DESC', 'sort': 'DESC', 'updated_on': 'DESC', 'created_on': 'DESC'},
|
||||
params = {},
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any,
|
||||
event_id: string,
|
||||
enabled?: string,
|
||||
hidden?: string,
|
||||
limit?: number,
|
||||
offset?: number,
|
||||
order_by_li?: key_val,
|
||||
params?: key_val,
|
||||
try_cache?: boolean,
|
||||
log_lvl?: number
|
||||
}) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** load_ae_obj_li__event_badge_template() *** event_id=${event_id}`);
|
||||
}
|
||||
let params_json: key_val = {};
|
||||
// ae_promises.load__event_badge_template_obj_li = await api.get_ae_obj_li_for_obj_id_crud({
|
||||
ae_promises.load__event_badge_template_obj_li = await api.get_ae_obj_li_for_obj_id_crud_v2({
|
||||
api_cfg,
|
||||
obj_type: 'event_badge_template',
|
||||
for_obj_type: 'event',
|
||||
for_obj_id: event_id,
|
||||
use_alt_tbl: false,
|
||||
use_alt_mdl: false,
|
||||
enabled,
|
||||
hidden,
|
||||
order_by_li,
|
||||
limit,
|
||||
offset,
|
||||
params_json,
|
||||
params,
|
||||
log_lvl
|
||||
})
|
||||
.then(async function (obj_li_get_result) {
|
||||
if (obj_li_get_result) {
|
||||
if (try_cache) {
|
||||
let processed_obj_li = await process_ae_obj__event_badge_template_props({
|
||||
obj_li: obj_li_get_result,
|
||||
log_lvl
|
||||
});
|
||||
await db_save_ae_obj_li__ae_obj({
|
||||
db_instance: db_events,
|
||||
table_name: 'badge_template',
|
||||
obj_li: processed_obj_li,
|
||||
properties_to_save,
|
||||
log_lvl,
|
||||
});
|
||||
}
|
||||
return obj_li_get_result;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log('No results returned or failed.', error);
|
||||
});
|
||||
return ae_promises.load__event_badge_template_obj_li;
|
||||
}
|
||||
|
||||
export async function create_ae_obj__event_badge_template({
|
||||
api_cfg,
|
||||
event_id,
|
||||
data_kv,
|
||||
params = {},
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any,
|
||||
event_id: string,
|
||||
data_kv: key_val,
|
||||
params?: key_val,
|
||||
try_cache?: boolean,
|
||||
log_lvl?: number
|
||||
}) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** create_ae_obj__event_badge_template() *** event_id=${event_id}`);
|
||||
}
|
||||
ae_promises.create__event_badge_template = await api.create_ae_obj_crud({
|
||||
api_cfg,
|
||||
obj_type: 'event_badge_template',
|
||||
fields: {
|
||||
event_id_random: event_id,
|
||||
...data_kv
|
||||
},
|
||||
key: api_cfg.api_crud_super_key,
|
||||
params,
|
||||
return_obj: true,
|
||||
log_lvl
|
||||
})
|
||||
.then(async function (obj_create_result) {
|
||||
if (obj_create_result) {
|
||||
if (try_cache) {
|
||||
let processed_obj_li = await process_ae_obj__event_badge_template_props({
|
||||
obj_li: [obj_create_result],
|
||||
log_lvl
|
||||
});
|
||||
db_save_ae_obj_li__ae_obj({
|
||||
db_instance: db_events,
|
||||
table_name: 'badge_template',
|
||||
obj_li: processed_obj_li,
|
||||
properties_to_save,
|
||||
log_lvl,
|
||||
});
|
||||
}
|
||||
return obj_create_result;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log('No results returned or failed.', error);
|
||||
});
|
||||
return ae_promises.create__event_badge_template;
|
||||
}
|
||||
|
||||
export async function delete_ae_obj_id__event_badge_template({
|
||||
api_cfg,
|
||||
event_badge_template_id,
|
||||
method = 'delete',
|
||||
params = {},
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any,
|
||||
event_badge_template_id: string,
|
||||
method?: string,
|
||||
params?: key_val,
|
||||
try_cache?: boolean,
|
||||
log_lvl?: number
|
||||
}) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** delete_ae_obj_id__event_badge_template() *** event_badge_template_id=${event_badge_template_id}`);
|
||||
}
|
||||
ae_promises.delete__event_badge_template_obj = await api.delete_ae_obj_id_crud({
|
||||
api_cfg,
|
||||
obj_type: 'event_badge_template',
|
||||
obj_id: event_badge_template_id,
|
||||
key: api_cfg.api_crud_super_key,
|
||||
params,
|
||||
method,
|
||||
log_lvl
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log('No results returned or failed.', error);
|
||||
})
|
||||
.finally(function () {
|
||||
if (try_cache) {
|
||||
if (log_lvl) {
|
||||
console.log(`Attempting to remove IDB entry for event_badge_template_id=${event_badge_template_id}`);
|
||||
}
|
||||
db_events.badge_template.delete(event_badge_template_id);
|
||||
}
|
||||
});
|
||||
return ae_promises.delete__event_badge_template_obj;
|
||||
}
|
||||
|
||||
export async function update_ae_obj__event_badge_template({
|
||||
api_cfg,
|
||||
event_badge_template_id,
|
||||
data_kv,
|
||||
params = {},
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any,
|
||||
event_badge_template_id: string,
|
||||
data_kv: key_val,
|
||||
params?: key_val,
|
||||
try_cache?: boolean,
|
||||
log_lvl?: number
|
||||
}) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** update_ae_obj__event_badge_template() *** event_badge_template_id=${event_badge_template_id}`);
|
||||
}
|
||||
ae_promises.update__event_badge_template_obj = await api.update_ae_obj_id_crud({
|
||||
api_cfg,
|
||||
obj_type: 'event_badge_template',
|
||||
obj_id: event_badge_template_id,
|
||||
fields: data_kv,
|
||||
key: api_cfg.api_crud_super_key,
|
||||
params,
|
||||
return_obj: true,
|
||||
log_lvl
|
||||
})
|
||||
.then(async function (obj_update_result) {
|
||||
if (obj_update_result) {
|
||||
if (try_cache) {
|
||||
let processed_obj_li = await process_ae_obj__event_badge_template_props({
|
||||
obj_li: [obj_update_result],
|
||||
log_lvl
|
||||
});
|
||||
db_save_ae_obj_li__ae_obj({
|
||||
db_instance: db_events,
|
||||
table_name: 'badge_template',
|
||||
obj_li: processed_obj_li,
|
||||
properties_to_save,
|
||||
log_lvl,
|
||||
});
|
||||
}
|
||||
return obj_update_result;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log('No results returned or failed.', error);
|
||||
});
|
||||
return ae_promises.update__event_badge_template_obj;
|
||||
}
|
||||
|
||||
// --- SEARCH FUNCTION ---
|
||||
export async function search__event_badge_template({
|
||||
api_cfg,
|
||||
event_id,
|
||||
fulltext_search_qry_str,
|
||||
like_search_qry_str = null,
|
||||
enabled = 'enabled',
|
||||
hidden = 'not_hidden',
|
||||
limit = 25,
|
||||
offset = 0,
|
||||
order_by_li = {'priority': 'DESC', 'sort': 'DESC', 'name': 'ASC', 'updated_on': 'DESC', 'created_on': 'DESC'},
|
||||
params = {},
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any,
|
||||
event_id: string,
|
||||
fulltext_search_qry_str?: null|string,
|
||||
like_search_qry_str?: null|string,
|
||||
enabled?: string,
|
||||
hidden?: string,
|
||||
limit?: number,
|
||||
offset?: number,
|
||||
order_by_li?: key_val,
|
||||
params?: key_val,
|
||||
try_cache?: boolean,
|
||||
log_lvl?: number
|
||||
}) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** search__event_badge_template() *** event_id=${event_id}`);
|
||||
}
|
||||
let params_json: key_val = {};
|
||||
if (fulltext_search_qry_str && fulltext_search_qry_str.length > 2) {
|
||||
params_json['ft_qry'] = { 'default_qry_str': fulltext_search_qry_str };
|
||||
}
|
||||
if (like_search_qry_str && like_search_qry_str.length > 2) {
|
||||
params_json['and_like'] = { 'default_qry_str': like_search_qry_str };
|
||||
}
|
||||
params_json['and_qry'] = {};
|
||||
// ae_promises.search__event_badge_template_obj_li = await api.get_ae_obj_li_for_obj_id_crud({
|
||||
ae_promises.load__event_badge_template_obj_li = await api.get_ae_obj_li_for_obj_id_crud_v2({
|
||||
api_cfg,
|
||||
obj_type: 'event_badge_template',
|
||||
for_obj_type: 'event',
|
||||
for_obj_id: event_id,
|
||||
use_alt_tbl: false,
|
||||
use_alt_mdl: false,
|
||||
enabled,
|
||||
hidden,
|
||||
order_by_li,
|
||||
limit,
|
||||
offset,
|
||||
params_json,
|
||||
params,
|
||||
log_lvl
|
||||
})
|
||||
.then(async function (obj_li_get_result) {
|
||||
if (obj_li_get_result) {
|
||||
if (try_cache) {
|
||||
let processed_obj_li = await process_ae_obj__event_badge_template_props({
|
||||
obj_li: obj_li_get_result,
|
||||
log_lvl
|
||||
});
|
||||
await db_save_ae_obj_li__ae_obj({
|
||||
db_instance: db_events,
|
||||
table_name: 'badge_template',
|
||||
obj_li: processed_obj_li,
|
||||
properties_to_save,
|
||||
log_lvl,
|
||||
});
|
||||
}
|
||||
return obj_li_get_result;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log('No results returned or failed.', error);
|
||||
});
|
||||
return ae_promises.search__event_badge_template_obj_li;
|
||||
}
|
||||
Reference in New Issue
Block a user