feat(offline): implement Dexie fallbacks and fix type stability in Events module
- 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.
This commit is contained in:
@@ -9,40 +9,18 @@ const ae_promises: key_val = {};
|
||||
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',
|
||||
|
||||
'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',
|
||||
@@ -51,20 +29,12 @@ export const properties_to_save = [
|
||||
'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',
|
||||
@@ -73,8 +43,6 @@ export const properties_to_save = [
|
||||
'notes',
|
||||
'created_on',
|
||||
'updated_on',
|
||||
|
||||
// Generated fields for sorting locally only
|
||||
'tmp_sort_1',
|
||||
'tmp_sort_2'
|
||||
];
|
||||
@@ -94,39 +62,24 @@ async function _process_generic_props<T extends Record<string, any>>({
|
||||
log_lvl?: number;
|
||||
specific_processor?: (obj: T) => Promise<T> | T;
|
||||
}): Promise<T[]> {
|
||||
if (log_lvl > 0) {
|
||||
console.log(
|
||||
`*** _process_generic_props: Processing ${obj_li.length} objects of type "${obj_type}" ***`
|
||||
);
|
||||
}
|
||||
|
||||
if (!obj_li || obj_li.length === 0) {
|
||||
if (log_lvl > 0) console.log('No objects to process.');
|
||||
return [];
|
||||
}
|
||||
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 };
|
||||
|
||||
// --- Common Transformations ---
|
||||
|
||||
// 1. Standardize ID and other '_random' fields
|
||||
// The API often returns fields like 'person_id_random', which need to be aliased to 'person_id'.
|
||||
for (const key in processed_obj) {
|
||||
if (key.endsWith('_random')) {
|
||||
const newKey = key.slice(0, -7); // Remove '_random' suffix
|
||||
const newKey = key.slice(0, -7);
|
||||
(processed_obj as any)[newKey] = processed_obj[key];
|
||||
}
|
||||
}
|
||||
// Ensure 'id' is set from '[obj_type]_id_random'
|
||||
const randomIdKey = `${obj_type}_id_random`;
|
||||
if (processed_obj[randomIdKey]) {
|
||||
(processed_obj as any).id = processed_obj[randomIdKey];
|
||||
}
|
||||
|
||||
// 2. Create common computed properties for client-side sorting.
|
||||
const group = processed_obj.group ?? '0';
|
||||
const priority = processed_obj.priority ? 1 : 0;
|
||||
const sort = processed_obj.sort ?? '0';
|
||||
@@ -136,7 +89,6 @@ async function _process_generic_props<T extends Record<string, any>>({
|
||||
(processed_obj as any).tmp_sort_1 = `${group}_${priority}_${sort}_${updated}`;
|
||||
(processed_obj as any).tmp_sort_2 = `${group}_${priority}_${sort}_${name}_${updated}`;
|
||||
|
||||
// --- Specific Transformations ---
|
||||
if (specific_processor) {
|
||||
processed_obj = await Promise.resolve(specific_processor(processed_obj));
|
||||
}
|
||||
@@ -148,7 +100,7 @@ async function _process_generic_props<T extends Record<string, any>>({
|
||||
}
|
||||
|
||||
// --- PROCESS FUNCTION ---
|
||||
export async function process_ae_obj__event_badge_template_props({
|
||||
export async function process_ae_badge_template_props({
|
||||
obj_li,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
@@ -160,7 +112,6 @@ export async function process_ae_obj__event_badge_template_props({
|
||||
obj_type: 'event_badge_template',
|
||||
log_lvl,
|
||||
specific_processor: (obj) => {
|
||||
// Event badge template-specific computed sort fields, overriding generic ones if needed
|
||||
obj.tmp_sort_1 = `${obj.group ?? ''}_${obj.priority ? '1' : '0'}_${
|
||||
obj.sort?.toString().padStart(3, '0') ?? ''
|
||||
}_${obj.updated_on ?? obj.created_on}`;
|
||||
@@ -190,41 +141,46 @@ export async function load_ae_obj_id__event_badge_template({
|
||||
`*** load_ae_obj_id__event_badge_template() *** event_badge_template_id=${event_badge_template_id}`
|
||||
);
|
||||
}
|
||||
const 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) {
|
||||
const 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;
|
||||
|
||||
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
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(function (error: any) {
|
||||
console.log('No results returned or failed.', error);
|
||||
});
|
||||
} 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;
|
||||
}
|
||||
|
||||
@@ -257,51 +213,58 @@ export async function load_ae_obj_li__event_badge_template({
|
||||
try_cache?: boolean;
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** load_ae_obj_li__event_badge_template() *** event_id=${event_id}`);
|
||||
}
|
||||
const 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) {
|
||||
const 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 [];
|
||||
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
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(function (error: any) {
|
||||
console.log('No results returned or failed.', error);
|
||||
});
|
||||
} 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;
|
||||
}
|
||||
|
||||
@@ -320,12 +283,9 @@ export async function create_ae_obj__event_badge_template({
|
||||
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,
|
||||
api_cfg: api_cfg,
|
||||
obj_type: 'event_badge_template',
|
||||
fields: {
|
||||
event_id_random: event_id,
|
||||
@@ -337,27 +297,20 @@ export async function create_ae_obj__event_badge_template({
|
||||
log_lvl
|
||||
})
|
||||
.then(async function (obj_create_result) {
|
||||
if (obj_create_result) {
|
||||
if (try_cache) {
|
||||
const 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;
|
||||
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
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(function (error: any) {
|
||||
console.log('No results returned or failed.', error);
|
||||
return obj_create_result;
|
||||
});
|
||||
return ae_promises.create__event_badge_template;
|
||||
}
|
||||
@@ -377,11 +330,6 @@ export async function delete_ae_obj_id__event_badge_template({
|
||||
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,
|
||||
@@ -392,16 +340,8 @@ export async function delete_ae_obj_id__event_badge_template({
|
||||
method,
|
||||
log_lvl
|
||||
})
|
||||
.catch(function (error: any) {
|
||||
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);
|
||||
}
|
||||
});
|
||||
@@ -423,11 +363,6 @@ export async function update_ae_obj__event_badge_template({
|
||||
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,
|
||||
@@ -440,32 +375,24 @@ export async function update_ae_obj__event_badge_template({
|
||||
log_lvl
|
||||
})
|
||||
.then(async function (obj_update_result) {
|
||||
if (obj_update_result) {
|
||||
if (try_cache) {
|
||||
const 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;
|
||||
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
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(function (error: any) {
|
||||
console.log('No results returned or failed.', error);
|
||||
return obj_update_result;
|
||||
});
|
||||
return ae_promises.update__event_badge_template_obj;
|
||||
}
|
||||
|
||||
// --- SEARCH FUNCTION ---
|
||||
export async function search__event_badge_template({
|
||||
api_cfg,
|
||||
event_id,
|
||||
@@ -499,9 +426,6 @@ export async function search__event_badge_template({
|
||||
try_cache?: boolean;
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** search__event_badge_template() *** event_id=${event_id}`);
|
||||
}
|
||||
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 };
|
||||
@@ -509,8 +433,7 @@ export async function search__event_badge_template({
|
||||
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,
|
||||
@@ -529,27 +452,20 @@ export async function search__event_badge_template({
|
||||
log_lvl
|
||||
})
|
||||
.then(async function (obj_li_get_result) {
|
||||
if (obj_li_get_result) {
|
||||
if (try_cache) {
|
||||
const 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 [];
|
||||
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
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(function (error: any) {
|
||||
console.log('No results returned or failed.', error);
|
||||
return obj_li_get_result || [];
|
||||
});
|
||||
return ae_promises.search__event_badge_template_obj_li;
|
||||
}
|
||||
return ae_promises.load__event_badge_template_obj_li;
|
||||
}
|
||||
Reference in New Issue
Block a user