- Offline Resilience: Added local Dexie fallbacks to load_ae_obj_id__* and load_ae_obj_li__* functions for Events, Sessions, Locations, Exhibits, and Badges. - Type Safety: Standardized ae_Event and ae_EventSession interfaces in ae_types.ts; resolved Promise assignment errors in load functions (+page.ts). - Bug Fixes: Corrected duplication in ae_events__event_location.ts and ae_events__event_badge_template.ts; fixed missing try_cache parameters. - UI Stability: Fixed Dexie LiveQuery subscription pattern in bulk print view and ensured proper property access in layout load functions.
471 lines
14 KiB
TypeScript
471 lines
14 KiB
TypeScript
import type { key_val } from '$lib/stores/ae_stores';
|
|
import { api } from '$lib/api/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';
|
|
|
|
const ae_promises: key_val = {};
|
|
|
|
// --- PROPERTIES TO SAVE ---
|
|
export const properties_to_save = [
|
|
'id',
|
|
'event_badge_template_id',
|
|
'event_id',
|
|
'name',
|
|
'description',
|
|
'logo_filename',
|
|
'logo_path',
|
|
'header_path',
|
|
'secondary_header_path',
|
|
'footer_path',
|
|
'header_row_1',
|
|
'header_row_2',
|
|
'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',
|
|
'wireless_ssid',
|
|
'wireless_password',
|
|
'show_qr_front',
|
|
'show_qr_back',
|
|
'layout',
|
|
'style_filename',
|
|
'enable',
|
|
'hide',
|
|
'priority',
|
|
'sort',
|
|
'group',
|
|
'notes',
|
|
'created_on',
|
|
'updated_on',
|
|
'tmp_sort_1',
|
|
'tmp_sort_2'
|
|
];
|
|
|
|
/**
|
|
* NON-EXPORTED LOCAL HELPER
|
|
* Processes a list of Aether objects by applying common and specific transformations.
|
|
*/
|
|
async function _process_generic_props<T extends Record<string, any>>({
|
|
obj_li,
|
|
obj_type,
|
|
log_lvl = 0,
|
|
specific_processor
|
|
}: {
|
|
obj_li: T[];
|
|
obj_type: string;
|
|
log_lvl?: number;
|
|
specific_processor?: (obj: T) => Promise<T> | T;
|
|
}): Promise<T[]> {
|
|
if (!obj_li || obj_li.length === 0) return [];
|
|
|
|
const processed_obj_li: T[] = [];
|
|
|
|
for (const original_obj of obj_li) {
|
|
let processed_obj = { ...original_obj };
|
|
|
|
for (const key in processed_obj) {
|
|
if (key.endsWith('_random')) {
|
|
const newKey = key.slice(0, -7);
|
|
(processed_obj as any)[newKey] = processed_obj[key];
|
|
}
|
|
}
|
|
const randomIdKey = `${obj_type}_id_random`;
|
|
if (processed_obj[randomIdKey]) {
|
|
(processed_obj as any).id = processed_obj[randomIdKey];
|
|
}
|
|
|
|
const group = processed_obj.group ?? '0';
|
|
const priority = processed_obj.priority ? 1 : 0;
|
|
const sort = processed_obj.sort ?? '0';
|
|
const updated = processed_obj.updated_on ?? processed_obj.created_on;
|
|
const name = processed_obj.name ?? '';
|
|
|
|
(processed_obj as any).tmp_sort_1 = `${group}_${priority}_${sort}_${updated}`;
|
|
(processed_obj as any).tmp_sort_2 = `${group}_${priority}_${sort}_${name}_${updated}`;
|
|
|
|
if (specific_processor) {
|
|
processed_obj = await Promise.resolve(specific_processor(processed_obj));
|
|
}
|
|
|
|
processed_obj_li.push(processed_obj as T);
|
|
}
|
|
|
|
return processed_obj_li;
|
|
}
|
|
|
|
// --- PROCESS FUNCTION ---
|
|
export async function process_ae_badge_template_props({
|
|
obj_li,
|
|
log_lvl = 0
|
|
}: {
|
|
obj_li: any[];
|
|
log_lvl?: number;
|
|
}) {
|
|
return _process_generic_props({
|
|
obj_li,
|
|
obj_type: 'event_badge_template',
|
|
log_lvl,
|
|
specific_processor: (obj) => {
|
|
obj.tmp_sort_1 = `${obj.group ?? ''}_${obj.priority ? '1' : '0'}_${
|
|
obj.sort?.toString().padStart(3, '0') ?? ''
|
|
}_${obj.updated_on ?? obj.created_on}`;
|
|
obj.tmp_sort_2 = `${obj.group ?? ''}_${obj.priority ? '1' : '0'}_${
|
|
obj.sort?.toString().padStart(3, '0') ?? ''
|
|
}_${obj.updated_on}_${obj.created_on}`;
|
|
|
|
return obj;
|
|
}
|
|
});
|
|
}
|
|
|
|
// --- 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}`
|
|
);
|
|
}
|
|
|
|
try {
|
|
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
|
|
});
|
|
|
|
if (ae_promises.load__event_badge_template_obj) {
|
|
if (try_cache) {
|
|
const processed_obj_li = await process_ae_badge_template_props({
|
|
obj_li: [ae_promises.load__event_badge_template_obj],
|
|
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
|
|
});
|
|
}
|
|
} else {
|
|
if (try_cache) {
|
|
ae_promises.load__event_badge_template_obj = await db_events.badge_template.get(event_badge_template_id);
|
|
}
|
|
}
|
|
} catch (error: any) {
|
|
if (try_cache) {
|
|
ae_promises.load__event_badge_template_obj = await db_events.badge_template.get(event_badge_template_id);
|
|
} else {
|
|
ae_promises.load__event_badge_template_obj = null;
|
|
}
|
|
}
|
|
|
|
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',
|
|
name: 'ASC',
|
|
updated_on: 'DESC',
|
|
created_on: 'DESC'
|
|
} as const,
|
|
params = {},
|
|
try_cache = true,
|
|
log_lvl = 0
|
|
}: {
|
|
api_cfg: any;
|
|
event_id: string;
|
|
enabled?: 'enabled' | 'all' | 'not_enabled' | undefined;
|
|
hidden?: 'hidden' | 'all' | 'not_hidden' | undefined;
|
|
limit?: number;
|
|
offset?: number;
|
|
order_by_li?: key_val;
|
|
params?: key_val;
|
|
try_cache?: boolean;
|
|
log_lvl?: number;
|
|
}) {
|
|
try {
|
|
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
|
|
});
|
|
|
|
if (ae_promises.load__event_badge_template_obj_li) {
|
|
if (try_cache) {
|
|
const processed_obj_li = await process_ae_badge_template_props({
|
|
obj_li: ae_promises.load__event_badge_template_obj_li,
|
|
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
|
|
});
|
|
}
|
|
} else {
|
|
if (try_cache) {
|
|
ae_promises.load__event_badge_template_obj_li = await db_events.badge_template
|
|
.where('event_id').equals(event_id)
|
|
.toArray();
|
|
} else {
|
|
ae_promises.load__event_badge_template_obj_li = [];
|
|
}
|
|
}
|
|
} catch (error: any) {
|
|
if (try_cache) {
|
|
ae_promises.load__event_badge_template_obj_li = await db_events.badge_template
|
|
.where('event_id').equals(event_id)
|
|
.toArray();
|
|
} else {
|
|
ae_promises.load__event_badge_template_obj_li = [];
|
|
}
|
|
}
|
|
|
|
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;
|
|
}) {
|
|
ae_promises.create__event_badge_template = await api
|
|
.create_ae_obj_crud({
|
|
api_cfg: 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 && try_cache) {
|
|
const processed_obj_li = await process_ae_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;
|
|
});
|
|
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;
|
|
}) {
|
|
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
|
|
})
|
|
.finally(function () {
|
|
if (try_cache) {
|
|
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;
|
|
}) {
|
|
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 && try_cache) {
|
|
const processed_obj_li = await process_ae_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;
|
|
});
|
|
return ae_promises.update__event_badge_template_obj;
|
|
}
|
|
|
|
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'
|
|
} as const,
|
|
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?: 'enabled' | 'all' | 'not_enabled' | undefined;
|
|
hidden?: 'hidden' | 'all' | 'not_hidden' | undefined;
|
|
limit?: number;
|
|
offset?: number;
|
|
order_by_li?: key_val;
|
|
params?: key_val;
|
|
try_cache?: boolean;
|
|
log_lvl?: number;
|
|
}) {
|
|
const 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 };
|
|
}
|
|
|
|
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 && try_cache) {
|
|
const processed_obj_li = await process_ae_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 || [];
|
|
});
|
|
return ae_promises.load__event_badge_template_obj_li;
|
|
} |