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:
Scott Idem
2026-01-16 15:09:10 -05:00
parent 2db2aba6f9
commit 8b611e7875
11 changed files with 998 additions and 1521 deletions

View File

@@ -38,45 +38,57 @@ export async function load_ae_obj_id__event({
console.log(`*** load_ae_obj_id__event() *** event_id=${event_id}`); console.log(`*** load_ae_obj_id__event() *** event_id=${event_id}`);
} }
ae_promises.load__event_obj = await api try {
.get_ae_obj_v3({ const event_obj_get_result = await api.get_ae_obj_v3({
api_cfg: api_cfg, api_cfg: api_cfg,
obj_type: 'event', obj_type: 'event',
obj_id: event_id, obj_id: event_id,
view, view,
log_lvl: log_lvl log_lvl: log_lvl
})
.then(async function (event_obj_get_result) {
if (event_obj_get_result) {
if (try_cache) {
const processed_obj_li = await process_ae_obj__event_props({
obj_li: [event_obj_get_result],
log_lvl: log_lvl
});
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'event',
obj_li: processed_obj_li,
properties_to_save: properties_to_save,
log_lvl: log_lvl
});
}
return event_obj_get_result;
} else {
console.log('No results returned.');
return null;
}
})
.catch(function (error: any) {
console.log('No results returned or failed.', error);
}); });
if (event_obj_get_result) {
if (try_cache) {
const processed_obj_li = await process_ae_obj__event_props({
obj_li: [event_obj_get_result],
log_lvl: log_lvl
});
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'event',
obj_li: processed_obj_li,
properties_to_save: properties_to_save,
log_lvl: log_lvl
});
}
ae_promises.load__event_obj = event_obj_get_result;
} else {
console.log('No results returned from API.');
if (try_cache) {
if (log_lvl) console.log('Attempting to load from local cache...');
ae_promises.load__event_obj = await db_events.event.get(event_id);
} else {
ae_promises.load__event_obj = null;
}
}
} catch (error: any) {
console.log('API request failed.', error);
if (try_cache) {
if (log_lvl) console.log('Attempting to load from local cache after error...');
ae_promises.load__event_obj = await db_events.event.get(event_id);
} else {
ae_promises.load__event_obj = null;
}
}
if (ae_promises.load__event_obj) { if (ae_promises.load__event_obj) {
const current_event_id = ae_promises.load__event_obj.event_id || ae_promises.load__event_obj.id;
if (inc_device_li) { if (inc_device_li) {
ae_promises.load__event_obj.event_device_obj_li = await load_ae_obj_li__event_device({ ae_promises.load__event_obj.event_device_obj_li = await load_ae_obj_li__event_device({
api_cfg, api_cfg,
for_obj_type: 'event', for_obj_type: 'event',
for_obj_id: event_id, for_obj_id: current_event_id,
log_lvl log_lvl
}); });
} }
@@ -84,7 +96,7 @@ export async function load_ae_obj_id__event({
ae_promises.load__event_obj.event_location_obj_li = await load_ae_obj_li__event_location({ ae_promises.load__event_obj.event_location_obj_li = await load_ae_obj_li__event_location({
api_cfg, api_cfg,
for_obj_type: 'event', for_obj_type: 'event',
for_obj_id: event_id, for_obj_id: current_event_id,
log_lvl log_lvl
}); });
} }
@@ -92,7 +104,7 @@ export async function load_ae_obj_id__event({
ae_promises.load__event_obj.event_session_obj_li = await load_ae_obj_li__event_session({ ae_promises.load__event_obj.event_session_obj_li = await load_ae_obj_li__event_session({
api_cfg, api_cfg,
for_obj_type: 'event', for_obj_type: 'event',
for_obj_id: event_id, for_obj_id: current_event_id,
log_lvl log_lvl
}); });
} }
@@ -100,7 +112,7 @@ export async function load_ae_obj_id__event({
ae_promises.load__event_obj.event_badge_template_obj_li = ae_promises.load__event_obj.event_badge_template_obj_li =
await load_ae_obj_li__event_badge_template({ await load_ae_obj_li__event_badge_template({
api_cfg, api_cfg,
event_id, event_id: current_event_id,
log_lvl log_lvl
}); });
} }
@@ -118,6 +130,7 @@ export async function load_ae_obj_li__event({
enabled = 'enabled', enabled = 'enabled',
hidden = 'not_hidden', hidden = 'not_hidden',
view = 'default', view = 'default',
inc_session_li = false,
limit = 99, limit = 99,
offset = 0, offset = 0,
order_by_li = { start_datetime: 'DESC' } as const, order_by_li = { start_datetime: 'DESC' } as const,
@@ -131,6 +144,7 @@ export async function load_ae_obj_li__event({
enabled?: 'enabled' | 'all' | 'not_enabled'; enabled?: 'enabled' | 'all' | 'not_enabled';
hidden?: 'hidden' | 'all' | 'not_hidden'; hidden?: 'hidden' | 'all' | 'not_hidden';
view?: string; view?: string;
inc_session_li?: boolean;
limit?: number; limit?: number;
offset?: number; offset?: number;
order_by_li?: Record<string, 'ASC' | 'DESC'> | Record<string, 'ASC' | 'DESC'>[]; order_by_li?: Record<string, 'ASC' | 'DESC'> | Record<string, 'ASC' | 'DESC'>[];
@@ -176,7 +190,8 @@ export async function load_ae_obj_li__event({
}); });
} }
ae_promises.load__event_obj_li = await promise.then(async function (event_obj_li_get_result) { try {
const event_obj_li_get_result = await promise;
if (event_obj_li_get_result) { if (event_obj_li_get_result) {
let filtered_results = event_obj_li_get_result; let filtered_results = event_obj_li_get_result;
@@ -198,11 +213,41 @@ export async function load_ae_obj_li__event({
log_lvl: log_lvl log_lvl: log_lvl
}); });
} }
return filtered_results; ae_promises.load__event_obj_li = filtered_results;
} else { } else {
return []; console.log('No results returned from API.');
if (try_cache) {
if (log_lvl) console.log('Attempting to load from local cache...');
ae_promises.load__event_obj_li = await db_events.event
.where('account_id').equals(for_obj_id)
.toArray();
} else {
ae_promises.load__event_obj_li = [];
}
} }
}); } catch (error: any) {
console.log('API request failed.', error);
if (try_cache) {
if (log_lvl) console.log('Attempting to load from local cache after error...');
ae_promises.load__event_obj_li = await db_events.event
.where('account_id').equals(for_obj_id)
.toArray();
} else {
ae_promises.load__event_obj_li = [];
}
}
if (inc_session_li && ae_promises.load__event_obj_li) {
for (const event_obj of ae_promises.load__event_obj_li) {
const current_event_id = event_obj.event_id || event_obj.id;
event_obj.event_session_obj_li = await load_ae_obj_li__event_session({
api_cfg,
for_obj_type: 'event',
for_obj_id: current_event_id,
log_lvl
});
}
}
return ae_promises.load__event_obj_li; return ae_promises.load__event_obj_li;
} }

View File

@@ -29,60 +29,58 @@ export async function load_ae_obj_id__event_badge({
console.log(`*** load_ae_obj_id__event_badge() *** event_badge_id=${event_badge_id}`); console.log(`*** load_ae_obj_id__event_badge() *** event_badge_id=${event_badge_id}`);
} }
ae_promises.load__event_badge_obj = await api try {
.get_ae_obj_v3({ ae_promises.load__event_badge_obj = await api
api_cfg, .get_ae_obj_v3({
obj_type: 'event_badge', api_cfg,
obj_id: event_badge_id, obj_type: 'event_badge',
view, obj_id: event_badge_id,
log_lvl view,
}) log_lvl
.then(async function (badge_obj_get_result) { });
if (badge_obj_get_result) {
if (try_cache) {
const processed_obj_li = await process_ae_obj__event_badge_props({
obj_li: [badge_obj_get_result],
log_lvl
});
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'badge',
obj_li: processed_obj_li,
properties_to_save,
log_lvl
});
}
return badge_obj_get_result;
} else {
if (log_lvl) console.log('No results returned.');
return null;
}
})
.catch(function (error: any) {
console.log('No results returned or failed.', error);
});
if (inc_template) { if (ae_promises.load__event_badge_obj) {
if (try_cache) {
const processed_obj_li = await process_ae_obj__event_badge_props({
obj_li: [ae_promises.load__event_badge_obj],
log_lvl
});
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'badge',
obj_li: processed_obj_li,
properties_to_save,
log_lvl
});
}
} else {
console.log('No results returned from API.');
if (try_cache) {
if (log_lvl) console.log('Attempting to load from local cache...');
ae_promises.load__event_badge_obj = await db_events.badge.get(event_badge_id);
}
}
} catch (error: any) {
console.log('API request failed.', error);
if (try_cache) {
if (log_lvl) console.log('Attempting to load from local cache after error...');
ae_promises.load__event_badge_obj = await db_events.badge.get(event_badge_id);
} else {
ae_promises.load__event_badge_obj = null;
}
}
if (inc_template && ae_promises.load__event_badge_obj) {
// Load the templates for the event badge // Load the templates for the event badge
if (log_lvl) { const current_template_id = ae_promises.load__event_badge_obj.event_badge_template_id || ae_promises.load__event_badge_obj.event_badge_template_id_random;
console.log(`Need to load the template for the badge now`); if (current_template_id) {
ae_promises.load__event_badge_obj.event_badge_template = await load_ae_obj_id__event_badge_template({
api_cfg: api_cfg,
event_badge_template_id: current_template_id,
try_cache: try_cache,
log_lvl: log_lvl
});
} }
const load_event_badge_template_obj = load_ae_obj_id__event_badge_template({
api_cfg: api_cfg,
event_badge_template_id:
ae_promises.load__event_badge_obj?.event_badge_template_id_random,
log_lvl: log_lvl
}).then((event_badge_template_obj_li) => {
if (log_lvl) {
console.log(`event_badge_template_obj_li = `, event_badge_template_obj_li);
}
return event_badge_template_obj_li;
});
if (log_lvl) {
console.log(`event_badge_template_obj = `, load_event_badge_template_obj);
}
ae_promises.load__event_session_obj.event_badge_template = load_event_badge_template_obj;
} }
return ae_promises.load__event_badge_obj; return ae_promises.load__event_badge_obj;
@@ -120,63 +118,71 @@ export async function load_ae_obj_li__event_badge({
console.log(`*** load_ae_obj_li__event_badge() *** event_id=${event_id}`); console.log(`*** load_ae_obj_li__event_badge() *** event_id=${event_id}`);
} }
ae_promises.load__event_badge_obj_li = await api try {
.get_ae_obj_li_v3({ ae_promises.load__event_badge_obj_li = await api
api_cfg, .get_ae_obj_li_v3({
obj_type: 'event_badge', api_cfg,
for_obj_type: 'event', obj_type: 'event_badge',
for_obj_id: event_id, for_obj_type: 'event',
enabled: enabled, for_obj_id: event_id,
hidden: hidden, enabled: enabled,
view: view, hidden: hidden,
order_by_li: order_by_li, view: view,
limit: limit, order_by_li: order_by_li,
offset: offset, limit: limit,
log_lvl: log_lvl offset: offset,
})
.then(async function (badge_obj_li_get_result) {
if (badge_obj_li_get_result) {
if (try_cache) {
const processed_obj_li = await process_ae_obj__event_badge_props({
obj_li: badge_obj_li_get_result,
event_id,
log_lvl
});
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'badge',
obj_li: processed_obj_li,
properties_to_save,
log_lvl
});
}
return badge_obj_li_get_result;
} else {
return [];
}
})
.catch(function (error: any) {
console.log('No results returned or failed.', error);
});
if (inc_template) {
// Load the template for each badge
if (log_lvl) {
console.log(`Need to load the template for each badge now`);
}
for (const badge_obj of ae_promises.load__event_badge_obj_li) {
if (log_lvl) {
console.log(`Loading template for badge_obj: `, badge_obj);
}
const load_event_badge_template_obj = await load_ae_obj_id__event_badge_template({
api_cfg: api_cfg,
event_badge_template_id: badge_obj?.event_badge_template_id_random,
log_lvl: log_lvl log_lvl: log_lvl
}); });
if (log_lvl) {
console.log(`event_badge_template_obj = `, load_event_badge_template_obj); if (ae_promises.load__event_badge_obj_li) {
if (try_cache) {
const processed_obj_li = await process_ae_obj__event_badge_props({
obj_li: ae_promises.load__event_badge_obj_li,
event_id,
log_lvl
});
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'badge',
obj_li: processed_obj_li,
properties_to_save,
log_lvl
});
}
} else {
console.log('No results returned from API.');
if (try_cache) {
if (log_lvl) console.log('Attempting to load from local cache...');
ae_promises.load__event_badge_obj_li = await db_events.badge
.where('event_id').equals(event_id)
.toArray();
} else {
ae_promises.load__event_badge_obj_li = [];
}
}
} catch (error: any) {
console.log('API request failed.', error);
if (try_cache) {
if (log_lvl) console.log('Attempting to load from local cache after error...');
ae_promises.load__event_badge_obj_li = await db_events.badge
.where('event_id').equals(event_id)
.toArray();
} else {
ae_promises.load__event_badge_obj_li = [];
}
}
if (inc_template && ae_promises.load__event_badge_obj_li) {
for (const badge_obj of ae_promises.load__event_badge_obj_li) {
const current_template_id = badge_obj.event_badge_template_id || badge_obj.event_badge_template_id_random;
if (current_template_id) {
badge_obj.event_badge_template = await load_ae_obj_id__event_badge_template({
api_cfg: api_cfg,
event_badge_template_id: current_template_id,
try_cache: try_cache,
log_lvl: log_lvl
});
} }
badge_obj.event_badge_template = load_event_badge_template_obj;
} }
} }

View File

@@ -9,40 +9,18 @@ const ae_promises: key_val = {};
export const properties_to_save = [ export const properties_to_save = [
'id', 'id',
'event_badge_template_id', 'event_badge_template_id',
// 'event_badge_template_id_random',
'event_id', 'event_id',
// 'event_id_random',
'name', 'name',
'description', 'description',
// 'template_code',
// 'template_type',
// 'template_json',
// 'template_svg',
// 'template_css',
// 'template_html',
'logo_filename', 'logo_filename',
'logo_path', 'logo_path',
'header_path', 'header_path',
'secondary_header_path', 'secondary_header_path',
'footer_path', 'footer_path',
'header_row_1', 'header_row_1',
'header_row_2', 'header_row_2',
// 'footer_title',
// 'footer_left',
// 'footer_right',
// 'header_background',
// 'footer_background',
'badge_type_list', 'badge_type_list',
'ticket_list', 'ticket_list',
'ticket_1_text', 'ticket_1_text',
'ticket_2_text', 'ticket_2_text',
'ticket_3_text', 'ticket_3_text',
@@ -51,20 +29,12 @@ export const properties_to_save = [
'ticket_6_text', 'ticket_6_text',
'ticket_7_text', 'ticket_7_text',
'ticket_8_text', 'ticket_8_text',
// 'ticket_9_text',
// 'ticket_10_text',
'wireless_ssid', 'wireless_ssid',
'wireless_password', 'wireless_password',
'show_qr_front', 'show_qr_front',
'show_qr_back', 'show_qr_back',
'layout', 'layout',
'style_filename', 'style_filename',
// 'style_href',
// 'default',
'enable', 'enable',
'hide', 'hide',
'priority', 'priority',
@@ -73,8 +43,6 @@ export const properties_to_save = [
'notes', 'notes',
'created_on', 'created_on',
'updated_on', 'updated_on',
// Generated fields for sorting locally only
'tmp_sort_1', 'tmp_sort_1',
'tmp_sort_2' 'tmp_sort_2'
]; ];
@@ -94,39 +62,24 @@ async function _process_generic_props<T extends Record<string, any>>({
log_lvl?: number; log_lvl?: number;
specific_processor?: (obj: T) => Promise<T> | T; specific_processor?: (obj: T) => Promise<T> | T;
}): Promise<T[]> { }): Promise<T[]> {
if (log_lvl > 0) { if (!obj_li || obj_li.length === 0) return [];
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 [];
}
const processed_obj_li: T[] = []; const processed_obj_li: T[] = [];
for (const original_obj of obj_li) { for (const original_obj of obj_li) {
let processed_obj = { ...original_obj }; 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) { for (const key in processed_obj) {
if (key.endsWith('_random')) { 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]; (processed_obj as any)[newKey] = processed_obj[key];
} }
} }
// Ensure 'id' is set from '[obj_type]_id_random'
const randomIdKey = `${obj_type}_id_random`; const randomIdKey = `${obj_type}_id_random`;
if (processed_obj[randomIdKey]) { if (processed_obj[randomIdKey]) {
(processed_obj as any).id = 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 group = processed_obj.group ?? '0';
const priority = processed_obj.priority ? 1 : 0; const priority = processed_obj.priority ? 1 : 0;
const sort = processed_obj.sort ?? '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_1 = `${group}_${priority}_${sort}_${updated}`;
(processed_obj as any).tmp_sort_2 = `${group}_${priority}_${sort}_${name}_${updated}`; (processed_obj as any).tmp_sort_2 = `${group}_${priority}_${sort}_${name}_${updated}`;
// --- Specific Transformations ---
if (specific_processor) { if (specific_processor) {
processed_obj = await Promise.resolve(specific_processor(processed_obj)); 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 --- // --- PROCESS FUNCTION ---
export async function process_ae_obj__event_badge_template_props({ export async function process_ae_badge_template_props({
obj_li, obj_li,
log_lvl = 0 log_lvl = 0
}: { }: {
@@ -160,7 +112,6 @@ export async function process_ae_obj__event_badge_template_props({
obj_type: 'event_badge_template', obj_type: 'event_badge_template',
log_lvl, log_lvl,
specific_processor: (obj) => { 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.tmp_sort_1 = `${obj.group ?? ''}_${obj.priority ? '1' : '0'}_${
obj.sort?.toString().padStart(3, '0') ?? '' obj.sort?.toString().padStart(3, '0') ?? ''
}_${obj.updated_on ?? obj.created_on}`; }_${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}` `*** 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 try {
.get_ae_obj_id_crud({ ae_promises.load__event_badge_template_obj = await api
api_cfg, .get_ae_obj_id_crud({
obj_type: 'event_badge_template', api_cfg,
obj_id: event_badge_template_id, obj_type: 'event_badge_template',
use_alt_table: false, obj_id: event_badge_template_id,
use_alt_base: false, use_alt_table: false,
params, use_alt_base: false,
log_lvl params: {},
}) log_lvl
.then(async function (obj_get_result) { });
if (obj_get_result) {
if (try_cache) { if (ae_promises.load__event_badge_template_obj) {
const processed_obj_li = await process_ae_obj__event_badge_template_props({ if (try_cache) {
obj_li: [obj_get_result], const processed_obj_li = await process_ae_badge_template_props({
log_lvl obj_li: [ae_promises.load__event_badge_template_obj],
}); log_lvl
await db_save_ae_obj_li__ae_obj({ });
db_instance: db_events, await db_save_ae_obj_li__ae_obj({
table_name: 'badge_template', db_instance: db_events,
obj_li: processed_obj_li, table_name: 'badge_template',
properties_to_save, obj_li: processed_obj_li,
log_lvl properties_to_save,
}); log_lvl
} });
return obj_get_result;
} else {
if (log_lvl) console.log('No results returned.');
return null;
} }
}) } else {
.catch(function (error: any) { if (try_cache) {
console.log('No results returned or failed.', error); 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; 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; try_cache?: boolean;
log_lvl?: number; log_lvl?: number;
}) { }) {
if (log_lvl) { try {
console.log(`*** load_ae_obj_li__event_badge_template() *** event_id=${event_id}`); ae_promises.load__event_badge_template_obj_li = await api
} .get_ae_obj_li_for_obj_id_crud_v2({
const params_json: key_val = {}; api_cfg,
// ae_promises.load__event_badge_template_obj_li = await api.get_ae_obj_li_for_obj_id_crud({ obj_type: 'event_badge_template',
ae_promises.load__event_badge_template_obj_li = await api for_obj_type: 'event',
.get_ae_obj_li_for_obj_id_crud_v2({ for_obj_id: event_id,
api_cfg, use_alt_tbl: false,
obj_type: 'event_badge_template', use_alt_mdl: false,
for_obj_type: 'event', enabled,
for_obj_id: event_id, hidden,
use_alt_tbl: false, order_by_li,
use_alt_mdl: false, limit,
enabled, offset,
hidden, params_json: {},
order_by_li, params,
limit, log_lvl
offset, });
params_json,
params, if (ae_promises.load__event_badge_template_obj_li) {
log_lvl if (try_cache) {
}) const processed_obj_li = await process_ae_badge_template_props({
.then(async function (obj_li_get_result) { obj_li: ae_promises.load__event_badge_template_obj_li,
if (obj_li_get_result) { log_lvl
if (try_cache) { });
const processed_obj_li = await process_ae_obj__event_badge_template_props({ await db_save_ae_obj_li__ae_obj({
obj_li: obj_li_get_result, db_instance: db_events,
log_lvl table_name: 'badge_template',
}); obj_li: processed_obj_li,
await db_save_ae_obj_li__ae_obj({ properties_to_save,
db_instance: db_events, log_lvl
table_name: 'badge_template', });
obj_li: processed_obj_li,
properties_to_save,
log_lvl
});
}
return obj_li_get_result;
} else {
return [];
} }
}) } else {
.catch(function (error: any) { if (try_cache) {
console.log('No results returned or failed.', error); 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; 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; try_cache?: boolean;
log_lvl?: number; 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 ae_promises.create__event_badge_template = await api
.create_ae_obj_crud({ .create_ae_obj_crud({
api_cfg, api_cfg: api_cfg,
obj_type: 'event_badge_template', obj_type: 'event_badge_template',
fields: { fields: {
event_id_random: event_id, event_id_random: event_id,
@@ -337,27 +297,20 @@ export async function create_ae_obj__event_badge_template({
log_lvl log_lvl
}) })
.then(async function (obj_create_result) { .then(async function (obj_create_result) {
if (obj_create_result) { if (obj_create_result && try_cache) {
if (try_cache) { const processed_obj_li = await process_ae_badge_template_props({
const processed_obj_li = await process_ae_obj__event_badge_template_props({ obj_li: [obj_create_result],
obj_li: [obj_create_result], log_lvl
log_lvl });
}); db_save_ae_obj_li__ae_obj({
db_save_ae_obj_li__ae_obj({ db_instance: db_events,
db_instance: db_events, table_name: 'badge_template',
table_name: 'badge_template', obj_li: processed_obj_li,
obj_li: processed_obj_li, properties_to_save,
properties_to_save, log_lvl
log_lvl });
});
}
return obj_create_result;
} else {
return null;
} }
}) return obj_create_result;
.catch(function (error: any) {
console.log('No results returned or failed.', error);
}); });
return ae_promises.create__event_badge_template; return ae_promises.create__event_badge_template;
} }
@@ -377,11 +330,6 @@ export async function delete_ae_obj_id__event_badge_template({
try_cache?: boolean; try_cache?: boolean;
log_lvl?: number; 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 ae_promises.delete__event_badge_template_obj = await api
.delete_ae_obj_id_crud({ .delete_ae_obj_id_crud({
api_cfg, api_cfg,
@@ -392,16 +340,8 @@ export async function delete_ae_obj_id__event_badge_template({
method, method,
log_lvl log_lvl
}) })
.catch(function (error: any) {
console.log('No results returned or failed.', error);
})
.finally(function () { .finally(function () {
if (try_cache) { 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); 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; try_cache?: boolean;
log_lvl?: number; 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 ae_promises.update__event_badge_template_obj = await api
.update_ae_obj_id_crud({ .update_ae_obj_id_crud({
api_cfg, api_cfg,
@@ -440,32 +375,24 @@ export async function update_ae_obj__event_badge_template({
log_lvl log_lvl
}) })
.then(async function (obj_update_result) { .then(async function (obj_update_result) {
if (obj_update_result) { if (obj_update_result && try_cache) {
if (try_cache) { const processed_obj_li = await process_ae_badge_template_props({
const processed_obj_li = await process_ae_obj__event_badge_template_props({ obj_li: [obj_update_result],
obj_li: [obj_update_result], log_lvl
log_lvl });
}); db_save_ae_obj_li__ae_obj({
db_save_ae_obj_li__ae_obj({ db_instance: db_events,
db_instance: db_events, table_name: 'badge_template',
table_name: 'badge_template', obj_li: processed_obj_li,
obj_li: processed_obj_li, properties_to_save,
properties_to_save, log_lvl
log_lvl });
});
}
return obj_update_result;
} else {
return null;
} }
}) return obj_update_result;
.catch(function (error: any) {
console.log('No results returned or failed.', error);
}); });
return ae_promises.update__event_badge_template_obj; return ae_promises.update__event_badge_template_obj;
} }
// --- SEARCH FUNCTION ---
export async function search__event_badge_template({ export async function search__event_badge_template({
api_cfg, api_cfg,
event_id, event_id,
@@ -499,9 +426,6 @@ export async function search__event_badge_template({
try_cache?: boolean; try_cache?: boolean;
log_lvl?: number; log_lvl?: number;
}) { }) {
if (log_lvl) {
console.log(`*** search__event_badge_template() *** event_id=${event_id}`);
}
const params_json: key_val = {}; const params_json: key_val = {};
if (fulltext_search_qry_str && fulltext_search_qry_str.length > 2) { if (fulltext_search_qry_str && fulltext_search_qry_str.length > 2) {
params_json['ft_qry'] = { default_qry_str: fulltext_search_qry_str }; 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) { 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_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 ae_promises.load__event_badge_template_obj_li = await api
.get_ae_obj_li_for_obj_id_crud_v2({ .get_ae_obj_li_for_obj_id_crud_v2({
api_cfg, api_cfg,
@@ -529,27 +452,20 @@ export async function search__event_badge_template({
log_lvl log_lvl
}) })
.then(async function (obj_li_get_result) { .then(async function (obj_li_get_result) {
if (obj_li_get_result) { if (obj_li_get_result && try_cache) {
if (try_cache) { const processed_obj_li = await process_ae_badge_template_props({
const processed_obj_li = await process_ae_obj__event_badge_template_props({ obj_li: obj_li_get_result,
obj_li: obj_li_get_result, log_lvl
log_lvl });
}); await db_save_ae_obj_li__ae_obj({
await db_save_ae_obj_li__ae_obj({ db_instance: db_events,
db_instance: db_events, table_name: 'badge_template',
table_name: 'badge_template', obj_li: processed_obj_li,
obj_li: processed_obj_li, properties_to_save,
properties_to_save, log_lvl
log_lvl });
});
}
return obj_li_get_result;
} else {
return [];
} }
}) return obj_li_get_result || [];
.catch(function (error: any) {
console.log('No results returned or failed.', error);
}); });
return ae_promises.search__event_badge_template_obj_li; return ae_promises.load__event_badge_template_obj_li;
} }

View File

@@ -29,74 +29,68 @@ export async function load_ae_obj_id__event_device({
const params = {}; const params = {};
ae_promises.load__event_device_obj = await api try {
.get_ae_obj_id_crud({ ae_promises.load__event_device_obj = await api
api_cfg: api_cfg, .get_ae_obj_id_crud({
obj_type: 'event_device', api_cfg: api_cfg,
obj_id: event_device_id, // NOTE: This is the FQDN, not normally the ID. obj_type: 'event_device',
use_alt_table: true, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config. obj_id: event_device_id, // NOTE: This is the FQDN, not normally the ID.
use_alt_base: false, // NOTE: This will use the base_name_alt value instead of the base_name value in the API config. use_alt_table: true, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config.
params: params, use_alt_base: false, // NOTE: This will use the base_name_alt value instead of the base_name value in the API config.
log_lvl: log_lvl params: params,
}) log_lvl: log_lvl
.then(async function (event_device_obj_get_result) { });
if (event_device_obj_get_result) {
if (try_cache) {
const processed_obj_li = await process_ae_obj__event_device_props({
obj_li: [event_device_obj_get_result],
log_lvl
});
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'device',
obj_li: processed_obj_li,
properties_to_save,
log_lvl
});
if (log_lvl) {
console.log('DB save completed.');
}
// // This is expecting a list if (ae_promises.load__event_device_obj) {
// db_save_ae_obj_li__event_device({ if (try_cache) {
// obj_type: 'event_device', const processed_obj_li = await process_ae_obj__event_device_props({
// obj_li: [event_device_obj_get_result] obj_li: [ae_promises.load__event_device_obj],
// }); log_lvl
} });
return event_device_obj_get_result; await db_save_ae_obj_li__ae_obj({
} else { db_instance: db_events,
console.log('No results returned.'); table_name: 'device',
return null; obj_li: processed_obj_li,
properties_to_save,
log_lvl
});
} }
}) } else {
.catch(function (error: any) { console.log('No results returned from API.');
console.log('No results returned or failed.', error); if (try_cache) {
}); if (log_lvl) console.log('Attempting to load from local cache...');
ae_promises.load__event_device_obj = await db_events.device.get(event_device_id);
}
}
} catch (error: any) {
console.log('API request failed.', error);
if (try_cache) {
if (log_lvl) console.log('Attempting to load from local cache after error...');
ae_promises.load__event_device_obj = await db_events.device.get(event_device_id);
} else {
ae_promises.load__event_device_obj = null;
}
}
if (log_lvl) { if (log_lvl) {
console.log('ae_promises.load__event_device_obj:', ae_promises.load__event_device_obj); console.log('ae_promises.load__event_device_obj:', ae_promises.load__event_device_obj);
} }
if (!ae_promises?.load__event_device_obj) {
return null;
}
if (inc_location_id) { if (inc_location_id) {
// Load the location linked to this device // Load the location linked to this device
if (log_lvl) { const current_location_id = ae_promises.load__event_device_obj.event_location_id;
console.log(`Need to load the location id for the device now`); if (current_location_id) {
ae_promises.load__event_device_obj.event_location_obj = await load_ae_obj_id__event_location({
api_cfg: api_cfg,
event_location_id: current_location_id,
try_cache: try_cache,
log_lvl: log_lvl
});
} }
const load_event_location_obj_id = load_ae_obj_id__event_location({
api_cfg: api_cfg,
event_location_id: ae_promises.load__event_device_obj.event_location_id,
try_cache: try_cache,
log_lvl: log_lvl
});
if (log_lvl) {
console.log(`load_event_location_obj_id = `, load_event_location_obj_id);
}
ae_promises.load__event_device_obj.event_location_obj = load_event_location_obj_id;
} }
return ae_promises.load__event_device_obj; return ae_promises.load__event_device_obj;
@@ -143,102 +137,75 @@ export async function load_ae_obj_li__event_device({
); );
} }
// let enabled: string = (params.qry__enabled ?? 'enabled'); // all, disabled, enabled
// let hidden: string = (params.qry__hidden ?? 'all'); // all, hidden, not_hidden
// let limit: number = (params.qry__limit ?? 99); // 99
// let offset: number = (params.qry__offset ?? 0); // 0
const params_json: key_val = {}; const params_json: key_val = {};
// console.log('params_json:', params_json); try {
ae_promises.load__event_device_obj_li = await api
ae_promises.load__event_device_obj_li = await api .get_ae_obj_li_for_obj_id_crud_v2({
.get_ae_obj_li_for_obj_id_crud_v2({
api_cfg: api_cfg,
obj_type: 'event_device',
for_obj_type: for_obj_type,
for_obj_id: for_obj_id,
use_alt_tbl: true,
use_alt_mdl: false,
use_alt_exp: false,
enabled: enabled,
hidden: hidden,
order_by_li: order_by_li,
limit: limit,
offset: offset,
params_json: params_json,
params: params,
log_lvl: log_lvl
})
.then(async function (event_device_obj_li_get_result) {
if (event_device_obj_li_get_result) {
if (try_cache) {
// Process the results first
const processed_obj_li = await process_ae_obj__event_device_props({
obj_li: event_device_obj_li_get_result,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'device',
obj_li: processed_obj_li,
properties_to_save: properties_to_save,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('DB save completed.');
}
// db_save_ae_obj_li__event_device({
// obj_type: 'event_device',
// obj_li: event_device_obj_li_get_result
// });
}
return event_device_obj_li_get_result;
} else {
return [];
}
})
.catch(function (error: any) {
console.log('No results returned or failed.', error);
});
if (log_lvl) {
console.log(
'ae_promises.load__event_device_obj_li:',
ae_promises.load__event_device_obj_li
);
}
if (inc_location_id) {
// Load the location for the devices
if (log_lvl) {
console.log(`Need to load the location list for each device now`);
}
for (let i = 0; i < ae_promises.load__event_device_obj_li.length; i++) {
const event_device_obj = ae_promises.load__event_device_obj_li[i];
const load_event_location_obj_li = load_ae_obj_id__event_location({
api_cfg: api_cfg, api_cfg: api_cfg,
event_location_id: event_device_obj.event_location_id, obj_type: 'event_device',
try_cache: try_cache, for_obj_type: for_obj_type,
for_obj_id: for_obj_id,
use_alt_tbl: true,
use_alt_mdl: false,
use_alt_exp: false,
enabled: enabled,
hidden: hidden,
order_by_li: order_by_li,
limit: limit,
offset: offset,
params_json: params_json,
params: params,
log_lvl: log_lvl log_lvl: log_lvl
}).then((event_location_obj_li) => {
if (log_lvl) {
console.log(`event_location_obj_li = `, event_location_obj_li);
}
return event_location_obj_li;
}); });
if (log_lvl) { if (ae_promises.load__event_device_obj_li) {
console.log(`load_event_location_obj_li = `, load_event_location_obj_li); if (try_cache) {
const processed_obj_li = await process_ae_obj__event_device_props({
obj_li: ae_promises.load__event_device_obj_li,
log_lvl: log_lvl
});
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'device',
obj_li: processed_obj_li,
properties_to_save: properties_to_save,
log_lvl: log_lvl
});
}
} else {
console.log('No results returned from API.');
if (try_cache) {
if (log_lvl) console.log('Attempting to load from local cache...');
ae_promises.load__event_device_obj_li = await db_events.device
.where('event_id').equals(for_obj_id)
.toArray();
} else {
ae_promises.load__event_device_obj_li = [];
}
}
} catch (error: any) {
console.log('API request failed.', error);
if (try_cache) {
if (log_lvl) console.log('Attempting to load from local cache after error...');
ae_promises.load__event_device_obj_li = await db_events.device
.where('event_id').equals(for_obj_id)
.toArray();
} else {
ae_promises.load__event_device_obj_li = [];
}
}
if (inc_location_id && ae_promises.load__event_device_obj_li) {
for (let i = 0; i < ae_promises.load__event_device_obj_li.length; i++) {
const event_device_obj = ae_promises.load__event_device_obj_li[i];
if (event_device_obj.event_location_id) {
event_device_obj.event_location_obj = await load_ae_obj_id__event_location({
api_cfg: api_cfg,
event_location_id: event_device_obj.event_location_id,
try_cache: try_cache,
log_lvl: log_lvl
});
} }
} }
} }

View File

@@ -35,108 +35,83 @@ export async function load_ae_obj_id__event_location({
const params = {}; const params = {};
ae_promises.load__event_location_obj = await api try {
.get_ae_obj_id_crud({ ae_promises.load__event_location_obj = await api
api_cfg: api_cfg, .get_ae_obj_id_crud({
obj_type: 'event_location', api_cfg: api_cfg,
obj_id: event_location_id, // NOTE: This is the FQDN, not normally the ID. obj_type: 'event_location',
use_alt_table: true, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config. obj_id: event_location_id, // NOTE: This is the FQDN, not normally the ID.
use_alt_base: false, // NOTE: This will use the base_name_alt value instead of the base_name value in the API config. use_alt_table: true, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config.
params: params, use_alt_base: false, // NOTE: This will use the base_name_alt value instead of the base_name value in the API config.
log_lvl: log_lvl params: params,
}) log_lvl: log_lvl
.then(async function (event_location_obj_get_result) { });
if (event_location_obj_get_result) {
if (try_cache) {
const processed_obj_li = await process_ae_obj__event_location_props({
obj_li: [event_location_obj_get_result],
log_lvl
});
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'location',
obj_li: processed_obj_li,
properties_to_save,
log_lvl
});
if (log_lvl) {
console.log('DB save completed.');
}
// // This is expecting a list if (ae_promises.load__event_location_obj) {
// db_save_ae_obj_li__event_location({ if (try_cache) {
// obj_type: 'event_location', const processed_obj_li = await process_ae_obj__event_location_props({
// obj_li: [event_location_obj_get_result] obj_li: [ae_promises.load__event_location_obj],
// }); log_lvl
} });
return event_location_obj_get_result; await db_save_ae_obj_li__ae_obj({
} else { db_instance: db_events,
console.log('No results returned.'); table_name: 'location',
return null; obj_li: processed_obj_li,
properties_to_save,
log_lvl
});
} }
}) } else {
.catch(function (error: any) { console.log('No results returned from API.');
console.log('No results returned or failed.', error); if (try_cache) {
}); if (log_lvl) console.log('Attempting to load from local cache...');
ae_promises.load__event_location_obj = await db_events.location.get(event_location_id);
}
}
} catch (error: any) {
console.log('API request failed.', error);
if (try_cache) {
if (log_lvl) console.log('Attempting to load from local cache after error...');
ae_promises.load__event_location_obj = await db_events.location.get(event_location_id);
} else {
ae_promises.load__event_location_obj = null;
}
}
if (log_lvl) { if (log_lvl) {
console.log('ae_promises.load__event_location_obj:', ae_promises.load__event_location_obj); console.log('ae_promises.load__event_location_obj:', ae_promises.load__event_location_obj);
} }
if (ae_promises?.load__event_location_obj === null) { if (!ae_promises?.load__event_location_obj) {
console.log('No results returned.');
return null; return null;
} }
const current_location_id = ae_promises.load__event_location_obj.event_location_id || ae_promises.load__event_location_obj.id;
if (inc_file_li) { if (inc_file_li) {
// Load the files for the location // Load the files for the location
if (log_lvl) { ae_promises.load__event_location_obj.event_file_li = await load_ae_obj_li__event_file({
console.log(`Need to load the file list for the location now`);
}
const load_event_file_obj_li = load_ae_obj_li__event_file({
api_cfg: api_cfg, api_cfg: api_cfg,
for_obj_type: 'event_location', for_obj_type: 'event_location',
for_obj_id: event_location_id, for_obj_id: current_location_id,
enabled: 'all', enabled: 'all',
limit: 15, limit: 15,
try_cache: try_cache, try_cache: try_cache,
log_lvl: log_lvl log_lvl: log_lvl
}).then((event_file_obj_li) => {
if (log_lvl) {
console.log(`event_file_obj_li = `, event_file_obj_li);
}
return event_file_obj_li;
}); });
if (log_lvl) {
console.log(`load_event_file_obj_li = `, load_event_file_obj_li);
}
ae_promises.load__event_location_obj.event_file_li = load_event_file_obj_li;
} }
if (inc_session_li) { if (inc_session_li) {
// Load the sessions for the location // Load the sessions for the location
if (log_lvl) { ae_promises.load__event_location_obj.event_session_li = await load_ae_obj_li__event_session({
console.log(`Need to load the session list for the location now`);
}
const load_event_session_obj_li = load_ae_obj_li__event_session({
api_cfg: api_cfg, api_cfg: api_cfg,
for_obj_type: 'event_location', for_obj_type: 'event_location',
for_obj_id: event_location_id, for_obj_id: current_location_id,
enabled: 'all', enabled: 'all',
limit: 15, limit: 15,
try_cache: try_cache, try_cache: try_cache,
log_lvl: log_lvl log_lvl: log_lvl
}); });
if (log_lvl) {
console.log(`load_event_session_obj_li = `, load_event_session_obj_li);
}
ae_promises.load__event_location_obj.event_session_li = load_event_session_obj_li;
} }
return ae_promises.load__event_location_obj; return ae_promises.load__event_location_obj;
@@ -189,158 +164,109 @@ export async function load_ae_obj_li__event_location({
const params_json: key_val = {}; const params_json: key_val = {};
// console.log('params_json:', params_json); try {
ae_promises.load__event_location_obj_li = await api
.get_ae_obj_li_for_obj_id_crud_v2({
api_cfg: api_cfg,
obj_type: 'event_location',
for_obj_type: for_obj_type,
for_obj_id: for_obj_id,
use_alt_tbl: true, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config.
enabled: enabled,
hidden: hidden,
order_by_li: order_by_li,
limit: limit,
offset: offset,
params_json: params_json,
params: params,
log_lvl: log_lvl
});
// ae_promises.load__event_location_obj_li = await api.get_ae_obj_li_for_obj_id_crud({ if (ae_promises.load__event_location_obj_li) {
ae_promises.load__event_location_obj_li = await api if (try_cache) {
.get_ae_obj_li_for_obj_id_crud_v2({ const processed_obj_li = await process_ae_obj__event_location_props({
api_cfg: api_cfg, obj_li: ae_promises.load__event_location_obj_li,
obj_type: 'event_location', log_lvl: log_lvl
for_obj_type: for_obj_type, });
for_obj_id: for_obj_id, await db_save_ae_obj_li__ae_obj({
use_alt_tbl: true, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config. db_instance: db_events,
// use_alt_mdl: false, // NOTE: This will use the base_name_alt value instead of the base_name value table_name: 'location',
enabled: enabled, obj_li: processed_obj_li,
hidden: hidden, properties_to_save: properties_to_save,
order_by_li: order_by_li, log_lvl: log_lvl
limit: limit, });
offset: offset, }
params_json: params_json, } else {
params: params, console.log('No results returned from API.');
log_lvl: log_lvl if (try_cache) {
}) if (log_lvl) console.log('Attempting to load from local cache...');
.then(async function (event_location_obj_li_get_result) { ae_promises.load__event_location_obj_li = await db_events.location
if (event_location_obj_li_get_result) { .where('event_id').equals(for_obj_id)
if (try_cache) { .toArray();
// Process the results first
const processed_obj_li = await process_ae_obj__event_location_props({
obj_li: event_location_obj_li_get_result,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'location',
obj_li: processed_obj_li,
properties_to_save: properties_to_save,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('DB save completed.');
}
// db_save_ae_obj_li__event_location({
// obj_type: 'event_location',
// obj_li: event_location_obj_li_get_result
// });
}
return event_location_obj_li_get_result;
} else { } else {
return []; ae_promises.load__event_location_obj_li = [];
} }
})
.catch(function (error: any) {
console.log('No results returned or failed.', error);
});
if (log_lvl) {
console.log(
'ae_promises.load__event_location_obj_li:',
ae_promises.load__event_location_obj_li
);
}
if (inc_device_li) {
// Load the devices for the locations
if (log_lvl) {
console.log(`Need to load the device list for each location now`);
} }
for (let i = 0; i < ae_promises.load__event_location_obj_li.length; i++) { } catch (error: any) {
const event_location_obj = ae_promises.load__event_location_obj_li[i]; console.log('API request failed.', error);
const event_location_id = event_location_obj.event_location_id_random; if (try_cache) {
if (log_lvl) console.log('Attempting to load from local cache after error...');
const load_event_device_obj_li = load_ae_obj_li__event_device({ ae_promises.load__event_location_obj_li = await db_events.location
api_cfg: api_cfg, .where('event_id').equals(for_obj_id)
for_obj_type: 'event_location', .toArray();
for_obj_id: event_location_id, } else {
params: { qry__enabled: enabled, qry__limit: limit }, ae_promises.load__event_location_obj_li = [];
try_cache: try_cache,
log_lvl: log_lvl
}).then((event_device_obj_li) => {
if (log_lvl) {
console.log(`event_device_obj_li = `, event_device_obj_li);
}
return event_device_obj_li;
});
if (log_lvl) {
console.log(`load_event_device_obj_li = `, load_event_device_obj_li);
}
} }
} }
if (inc_file_li) { if (ae_promises.load__event_location_obj_li) {
// Load the files for the locations if (inc_device_li) {
if (log_lvl) { for (let i = 0; i < ae_promises.load__event_location_obj_li.length; i++) {
console.log(`Need to load the file list for each location now`); const event_location_obj = ae_promises.load__event_location_obj_li[i];
} const current_location_id = event_location_obj.event_location_id || event_location_obj.id;
for (let i = 0; i < ae_promises.load__event_location_obj_li.length; i++) {
const event_location_obj = ae_promises.load__event_location_obj_li[i];
const event_location_id = event_location_obj.event_location_id_random;
const load_event_file_obj_li = load_ae_obj_li__event_file({ event_location_obj.event_device_obj_li = await load_ae_obj_li__event_device({
api_cfg: api_cfg, api_cfg: api_cfg,
for_obj_type: 'event_location', for_obj_type: 'event_location',
for_obj_id: event_location_id, for_obj_id: current_location_id,
enabled: enabled, params: { qry__enabled: enabled, qry__limit: limit },
limit: limit, try_cache: try_cache,
try_cache: try_cache, log_lvl: log_lvl
log_lvl: log_lvl });
}).then((event_file_obj_li) => {
if (log_lvl) {
console.log(`event_file_obj_li = `, event_file_obj_li);
}
return event_file_obj_li;
});
if (log_lvl) {
console.log(`load_event_file_obj_li = `, load_event_file_obj_li);
} }
} }
}
if (inc_session_li) { if (inc_file_li) {
// Load the sessions for the locations for (let i = 0; i < ae_promises.load__event_location_obj_li.length; i++) {
if (log_lvl) { const event_location_obj = ae_promises.load__event_location_obj_li[i];
console.log(`Need to load the session list for each location now`); const current_location_id = event_location_obj.event_location_id || event_location_obj.id;
event_location_obj.event_file_li = await load_ae_obj_li__event_file({
api_cfg: api_cfg,
for_obj_type: 'event_location',
for_obj_id: current_location_id,
enabled: enabled,
limit: limit,
try_cache: try_cache,
log_lvl: log_lvl
});
}
} }
for (let i = 0; i < ae_promises.load__event_location_obj_li.length; i++) {
const event_location_obj = ae_promises.load__event_location_obj_li[i];
const event_location_id = event_location_obj.event_location_id_random;
const load_event_session_obj_li = load_ae_obj_li__event_session({ if (inc_session_li) {
api_cfg: api_cfg, for (let i = 0; i < ae_promises.load__event_location_obj_li.length; i++) {
for_obj_type: 'event_location', const event_location_obj = ae_promises.load__event_location_obj_li[i];
for_obj_id: event_location_id, const current_location_id = event_location_obj.event_location_id || event_location_obj.id;
enabled: enabled,
limit: limit,
try_cache: try_cache,
log_lvl: log_lvl
}).then((event_session_obj_li) => {
if (log_lvl) {
console.log(`event_session_obj_li = `, event_session_obj_li);
}
return event_session_obj_li;
});
if (log_lvl) { event_location_obj.event_session_li = await load_ae_obj_li__event_session({
console.log(`load_event_session_obj_li = `, load_event_session_obj_li); api_cfg: api_cfg,
for_obj_type: 'event_location',
for_obj_id: current_location_id,
enabled: enabled,
limit: limit,
try_cache: try_cache,
log_lvl: log_lvl
});
} }
} }
} }
@@ -406,12 +332,6 @@ export async function create_ae_obj__event_location({
if (log_lvl) { if (log_lvl) {
console.log('DB save completed.'); console.log('DB save completed.');
} }
// db_save_ae_obj_li__event_location(
// {
// obj_type: 'event_location',
// obj_li: [event_location_obj_create_result]
// });
} }
return event_location_obj_create_result; return event_location_obj_create_result;
} else { } else {
@@ -420,12 +340,8 @@ export async function create_ae_obj__event_location({
}) })
.catch(function (error: any) { .catch(function (error: any) {
console.log('No results returned or failed.', error); console.log('No results returned or failed.', error);
}) });
.finally(function () {});
if (log_lvl) {
console.log('ae_promises.create__event_location:', ae_promises.create__event_location);
}
return ae_promises.create__event_location; return ae_promises.create__event_location;
} }
@@ -475,13 +391,6 @@ export async function delete_ae_obj_id__event_location({
} }
}); });
if (log_lvl) {
console.log(
'ae_promises.delete__event_location_obj:',
ae_promises.delete__event_location_obj
);
}
return ae_promises.delete__event_location_obj; return ae_promises.delete__event_location_obj;
} }
@@ -543,10 +452,6 @@ export async function update_ae_obj__event_location({
if (log_lvl) { if (log_lvl) {
console.log('DB save completed.'); console.log('DB save completed.');
} }
// db_save_ae_obj_li__event_location({
// obj_type: 'event_location', obj_li: [event_location_obj_update_result]
// });
} }
return event_location_obj_update_result; return event_location_obj_update_result;
} else { } else {
@@ -555,15 +460,8 @@ export async function update_ae_obj__event_location({
}) })
.catch(function (error: any) { .catch(function (error: any) {
console.log('No results returned or failed.', error); console.log('No results returned or failed.', error);
}) });
.finally(function () {});
if (log_lvl) {
console.log(
'ae_promises.update__event_location_obj:',
ae_promises.update__event_location_obj
);
}
return ae_promises.update__event_location_obj; return ae_promises.update__event_location_obj;
} }
@@ -597,14 +495,14 @@ export async function search__event_location({
const enabled: 'enabled' | 'all' | 'not_enabled' = (params.qry__enabled as any) ?? 'enabled'; const enabled: 'enabled' | 'all' | 'not_enabled' = (params.qry__enabled as any) ?? 'enabled';
const hidden: 'hidden' | 'all' | 'not_hidden' = (params.qry__hidden as any) ?? 'not_hidden'; const hidden: 'hidden' | 'all' | 'not_hidden' = (params.qry__hidden as any) ?? 'not_hidden';
const limit: number = params.qry__limit ?? 25; // 99 const limit: number = params.qry__limit ?? 25;
const offset: number = params.qry__offset ?? 0; // 0 const offset: number = params.qry__offset ?? 0;
const params_json: key_val = {}; const params_json: key_val = {};
if (!fulltext_search_qry_str && !like_search_qry_str) { if (!fulltext_search_qry_str && !like_search_qry_str) {
console.log('No search string provided!!!'); console.log('No search string provided!!!');
return false; // Returning false instead of [] because no search was performed. return false;
} }
if (fulltext_search_qry_str || ft_presenter_search_qry_str) { if (fulltext_search_qry_str || ft_presenter_search_qry_str) {
@@ -618,18 +516,6 @@ export async function search__event_location({
} }
} }
// Use the AND (AND LIKE) query
// if (like_search_qry_str || like_presenter_search_qry_str) {
// params_json['and_like'] = {};
// if (like_search_qry_str && like_search_qry_str.length > 2) {
// params_json['and_like']['default_qry_str'] = like_search_qry_str;
// }
// if (like_presenter_search_qry_str && like_presenter_search_qry_str.length > 2) {
// params_json['and_like']['event_presenter_li_qry_str'] = like_presenter_search_qry_str;
// }
// }
// Use the AND (OR LIKE) query
if (like_search_qry_str || like_presentation_search_qry_str || like_presenter_search_qry_str) { if (like_search_qry_str || like_presentation_search_qry_str || like_presenter_search_qry_str) {
params_json['or_like'] = {}; params_json['or_like'] = {};
if (like_search_qry_str && like_search_qry_str.length > 2) { if (like_search_qry_str && like_search_qry_str.length > 2) {
@@ -646,10 +532,6 @@ export async function search__event_location({
params_json['and_qry'] = {}; params_json['and_qry'] = {};
// if (location_type_code) {
// params_json['and_qry']['location_type_code'] = location_type_code;
// }
const order_by_li = { const order_by_li = {
priority: 'DESC', priority: 'DESC',
sort: 'DESC', sort: 'DESC',
@@ -659,15 +541,13 @@ export async function search__event_location({
created_on: 'DESC' created_on: 'DESC'
} as const; } as const;
// ae_promises.load__event_location_obj_li = await api.get_ae_obj_li_for_obj_id_crud({
ae_promises.load__event_location_obj_li = await api ae_promises.load__event_location_obj_li = await api
.get_ae_obj_li_for_obj_id_crud_v2({ .get_ae_obj_li_for_obj_id_crud_v2({
api_cfg: api_cfg, api_cfg: api_cfg,
obj_type: 'event_location', obj_type: 'event_location',
for_obj_type: 'event', for_obj_type: 'event',
for_obj_id: event_id, for_obj_id: event_id,
use_alt_tbl: true, // NOTE: We want to use the alt table for location searching use_alt_tbl: true,
// use_alt_mdl: false,
enabled: enabled, enabled: enabled,
hidden: hidden, hidden: hidden,
order_by_li: order_by_li, order_by_li: order_by_li,
@@ -680,18 +560,10 @@ export async function search__event_location({
.then(async function (event_location_obj_li_get_result) { .then(async function (event_location_obj_li_get_result) {
if (event_location_obj_li_get_result) { if (event_location_obj_li_get_result) {
if (try_cache) { if (try_cache) {
// Process the results first
const processed_obj_li = await process_ae_obj__event_location_props({ const processed_obj_li = await process_ae_obj__event_location_props({
obj_li: event_location_obj_li_get_result, obj_li: event_location_obj_li_get_result,
log_lvl: log_lvl log_lvl: log_lvl
}); });
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
await db_save_ae_obj_li__ae_obj({ await db_save_ae_obj_li__ae_obj({
db_instance: db_events, db_instance: db_events,
table_name: 'location', table_name: 'location',
@@ -699,9 +571,6 @@ export async function search__event_location({
properties_to_save: properties_to_save, properties_to_save: properties_to_save,
log_lvl: log_lvl log_lvl: log_lvl
}); });
if (log_lvl) {
console.log('DB save completed.');
}
} }
return event_location_obj_li_get_result; return event_location_obj_li_get_result;
} else { } else {
@@ -710,15 +579,8 @@ export async function search__event_location({
}) })
.catch(function (error: any) { .catch(function (error: any) {
console.log('No results returned or failed.', error); console.log('No results returned or failed.', error);
}) });
.finally(function () {});
if (log_lvl) {
console.log(
'ae_promises.load__event_location_obj_li:',
ae_promises.load__event_location_obj_li
);
}
return ae_promises.load__event_location_obj_li; return ae_promises.load__event_location_obj_li;
} }
@@ -726,28 +588,17 @@ export async function search__event_location({
export const properties_to_save = [ export const properties_to_save = [
'id', 'id',
'event_location_id', 'event_location_id',
// 'event_location_id_random',
'external_id', 'external_id',
'code', 'code',
'type_code', 'type_code',
'event_id', 'event_id',
// 'event_id_random',
'name', 'name',
'description', 'description',
'passcode', 'passcode',
'hide_event_launcher', 'hide_event_launcher',
'alert', 'alert',
'alert_msg', 'alert_msg',
'data_json', 'data_json',
'enable', 'enable',
'hide', 'hide',
'priority', 'priority',
@@ -756,26 +607,15 @@ export const properties_to_save = [
'notes', 'notes',
'created_on', 'created_on',
'updated_on', 'updated_on',
// Generated fields for sorting locally only
'tmp_sort_1', 'tmp_sort_1',
'tmp_sort_2', 'tmp_sort_2',
// 'tmp_sort_a',
// 'tmp_sort_b',
// From SQL view
'file_count', 'file_count',
'file_count_all', 'file_count_all',
'internal_use_count', 'internal_use_count',
'event_file_id_li_json', 'event_file_id_li_json',
'event_name' 'event_name'
]; ];
/**
* 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>>({ async function _process_generic_props<T extends Record<string, any>>({
obj_li, obj_li,
obj_type, obj_type,
@@ -787,39 +627,24 @@ async function _process_generic_props<T extends Record<string, any>>({
log_lvl?: number; log_lvl?: number;
specific_processor?: (obj: T) => Promise<T> | T; specific_processor?: (obj: T) => Promise<T> | T;
}): Promise<T[]> { }): Promise<T[]> {
if (log_lvl > 0) { if (!obj_li || obj_li.length === 0) return [];
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 [];
}
const processed_obj_li: T[] = []; const processed_obj_li: T[] = [];
for (const original_obj of obj_li) { for (const original_obj of obj_li) {
let processed_obj = { ...original_obj }; 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) { for (const key in processed_obj) {
if (key.endsWith('_random')) { 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]; (processed_obj as any)[newKey] = processed_obj[key];
} }
} }
// Ensure 'id' is set from '[obj_type]_id_random'
const randomIdKey = `${obj_type}_id_random`; const randomIdKey = `${obj_type}_id_random`;
if (processed_obj[randomIdKey]) { if (processed_obj[randomIdKey]) {
(processed_obj as any).id = 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 group = processed_obj.group ?? '0';
const priority = processed_obj.priority ? 1 : 0; const priority = processed_obj.priority ? 1 : 0;
const sort = processed_obj.sort ?? '0'; const sort = processed_obj.sort ?? '0';
@@ -829,7 +654,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_1 = `${group}_${priority}_${sort}_${updated}`;
(processed_obj as any).tmp_sort_2 = `${group}_${priority}_${sort}_${name}_${updated}`; (processed_obj as any).tmp_sort_2 = `${group}_${priority}_${sort}_${name}_${updated}`;
// --- Specific Transformations ---
if (specific_processor) { if (specific_processor) {
processed_obj = await Promise.resolve(specific_processor(processed_obj)); processed_obj = await Promise.resolve(specific_processor(processed_obj));
} }
@@ -853,7 +677,6 @@ export async function process_ae_obj__event_location_props({
obj_type: 'event_location', obj_type: 'event_location',
log_lvl, log_lvl,
specific_processor: (obj) => { specific_processor: (obj) => {
// Event location-specific computed sort fields, overriding generic ones if needed
obj.tmp_sort_1 = `${obj.group ?? ''}_${obj.priority ? '1' : '0'}_${ obj.tmp_sort_1 = `${obj.group ?? ''}_${obj.priority ? '1' : '0'}_${
obj.sort?.toString().padStart(3, '0') ?? '' obj.sort?.toString().padStart(3, '0') ?? ''
}_${obj.updated_on ?? obj.created_on}`; }_${obj.updated_on ?? obj.created_on}`;
@@ -864,4 +687,4 @@ export async function process_ae_obj__event_location_props({
return obj; return obj;
} }
}); });
} }

View File

@@ -44,9 +44,8 @@ export async function load_ae_obj_id__event_session({
const params = {}; const params = {};
// $events_sess.badges.status_load__event_session_obj = 'loading'; try {
ae_promises.load__event_session_obj = await api ae_promises.load__event_session_obj = await api.get_ae_obj_id_crud({
.get_ae_obj_id_crud({
api_cfg: api_cfg, api_cfg: api_cfg,
obj_type: 'event_session', obj_type: 'event_session',
obj_id: event_session_id, // NOTE: This is the FQDN, not normally the ID. obj_id: event_session_id, // NOTE: This is the FQDN, not normally the ID.
@@ -54,94 +53,68 @@ export async function load_ae_obj_id__event_session({
use_alt_base: false, // NOTE: This will use the base_name_alt value instead of the base_name value in the API config. use_alt_base: false, // NOTE: This will use the base_name_alt value instead of the base_name value in the API config.
params: params, params: params,
log_lvl: log_lvl log_lvl: log_lvl
})
.then(async function (event_session_obj_get_result) {
if (event_session_obj_get_result) {
if (try_cache) {
// Process the results first
const processed_obj_li = await process_ae_obj__event_session_props({
obj_li: [event_session_obj_get_result],
log_lvl: log_lvl
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'session',
obj_li: processed_obj_li,
properties_to_save: properties_to_save,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('DB save completed.');
}
// // This is expecting a list
// db_save_ae_obj_li__event_session({
// obj_type: 'event_session',
// obj_li: [event_session_obj_get_result]
// });
}
return event_session_obj_get_result;
} else {
console.log('No results returned.');
return null;
}
})
.catch(function (error: any) {
console.log('No results returned or failed.', error);
}); });
if (ae_promises.load__event_session_obj) {
if (try_cache) {
const processed_obj_li = await process_ae_obj__event_session_props({
obj_li: [ae_promises.load__event_session_obj],
log_lvl: log_lvl
});
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'session',
obj_li: processed_obj_li,
properties_to_save: properties_to_save,
log_lvl: log_lvl
});
}
} else {
console.log('No results returned from API.');
if (try_cache) {
if (log_lvl) console.log('Attempting to load from local cache...');
ae_promises.load__event_session_obj = await db_events.session.get(event_session_id);
}
}
} catch (error: any) {
console.log('API request failed.', error);
if (try_cache) {
if (log_lvl) console.log('Attempting to load from local cache after error...');
ae_promises.load__event_session_obj = await db_events.session.get(event_session_id);
} else {
ae_promises.load__event_session_obj = null;
}
}
if (log_lvl) { if (log_lvl) {
console.log('ae_promises.load__event_session_obj:', ae_promises?.load__event_session_obj); console.log('ae_promises.load__event_session_obj:', ae_promises?.load__event_session_obj);
} }
if (ae_promises?.load__event_session_obj === null) { if (!ae_promises?.load__event_session_obj) {
console.log('No results returned.');
return null; return null;
} }
const current_session_id = ae_promises.load__event_session_obj.event_session_id || ae_promises.load__event_session_obj.id;
if (inc_file_li) { if (inc_file_li) {
// Load the files for the session // Load the files for the session
if (log_lvl) { ae_promises.load__event_session_obj.event_file_li = await load_ae_obj_li__event_file({
console.log(`Need to load the file list for the session now`);
}
const load_event_file_obj_li = load_ae_obj_li__event_file({
api_cfg: api_cfg, api_cfg: api_cfg,
for_obj_type: 'event_session', for_obj_type: 'event_session',
for_obj_id: event_session_id, for_obj_id: current_session_id,
enabled: enabled, enabled: enabled,
limit: 15, limit: 15,
try_cache: try_cache, try_cache: try_cache,
log_lvl: log_lvl log_lvl: log_lvl
}).then((event_file_obj_li) => {
if (log_lvl) {
console.log(`event_file_obj_li = `, event_file_obj_li);
}
return event_file_obj_li;
}); });
if (log_lvl) {
console.log(`load_event_file_obj_li = `, load_event_file_obj_li);
}
ae_promises.load__event_session_obj.event_file_li = load_event_file_obj_li;
} }
if (inc_presentation_li) { if (inc_presentation_li) {
// Load the presentations for the session // Load the presentations for the session
if (log_lvl) { ae_promises.load__event_session_obj.event_presentation_li = await load_ae_obj_li__event_presentation({
console.log(`Need to load the presentation list for the session now`);
}
// NOTE: The files will only be included if inc_all_file_li is true. 2025-09-17
const load_event_presentation_obj_li = load_ae_obj_li__event_presentation({
api_cfg: api_cfg, api_cfg: api_cfg,
for_obj_type: 'event_session', for_obj_type: 'event_session',
for_obj_id: event_session_id, for_obj_id: current_session_id,
inc_file_li: inc_all_file_li, inc_file_li: inc_all_file_li,
inc_presenter_li: inc_presenter_li, inc_presenter_li: inc_presenter_li,
enabled: enabled, // all, disabled, enabled enabled: enabled, // all, disabled, enabled
@@ -151,17 +124,7 @@ export async function load_ae_obj_id__event_session({
params: {}, params: {},
try_cache: try_cache, try_cache: try_cache,
log_lvl: log_lvl log_lvl: log_lvl
}).then((event_presentation_obj_li) => {
if (log_lvl) {
console.log(`event_presentation_obj_li = `, event_presentation_obj_li);
}
return event_presentation_obj_li;
}); });
if (log_lvl) {
console.log(`event_presentation_obj_li = `, load_event_presentation_obj_li);
}
ae_promises.load__event_session_obj.event_presentation_li = load_event_presentation_obj_li;
} }
return ae_promises.load__event_session_obj; return ae_promises.load__event_session_obj;
@@ -214,124 +177,89 @@ export async function load_ae_obj_li__event_session({
); );
} }
// let enabled: string = (params.qry__enabled ?? 'enabled'); // all, disabled, enabled
// let hidden: string = (params.qry__hidden ?? 'not_hidden'); // all, hidden, not_hidden
// let limit: number = (params.qry__limit ?? 99); // 99
// let offset: number = (params.qry__offset ?? 0); // 0
const params_json: key_val = {}; const params_json: key_val = {};
// console.log('params_json:', params_json); try {
ae_promises.load__event_session_obj_li = await api
.get_ae_obj_li_for_obj_id_crud_v2({
api_cfg: api_cfg,
obj_type: 'event_session',
for_obj_type: for_obj_type,
for_obj_id: for_obj_id,
use_alt_tbl: true, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config.
enabled: enabled,
hidden: hidden,
order_by_li: order_by_li,
limit: limit,
offset: offset,
params_json: params_json,
params: params,
log_lvl: log_lvl
});
// ae_promises.load__event_session_obj_li = await api.get_ae_obj_li_for_obj_id_crud({ if (ae_promises.load__event_session_obj_li) {
ae_promises.load__event_session_obj_li = await api if (try_cache) {
.get_ae_obj_li_for_obj_id_crud_v2({ const processed_obj_li = await process_ae_obj__event_session_props({
api_cfg: api_cfg, obj_li: ae_promises.load__event_session_obj_li,
obj_type: 'event_session', log_lvl: log_lvl
for_obj_type: for_obj_type, });
for_obj_id: for_obj_id, await db_save_ae_obj_li__ae_obj({
use_alt_tbl: true, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config. db_instance: db_events,
// use_alt_mdl: false, // NOTE: This will use the base_name_alt value instead of the base_name value table_name: 'session',
enabled: enabled, obj_li: processed_obj_li,
hidden: hidden, properties_to_save: properties_to_save,
order_by_li: order_by_li, log_lvl: log_lvl
limit: limit, });
offset: offset,
params_json: params_json,
params: params,
log_lvl: log_lvl
})
.then(async function (event_session_obj_li_get_result) {
if (event_session_obj_li_get_result) {
if (try_cache) {
// Process the results first
const processed_obj_li = await process_ae_obj__event_session_props({
obj_li: event_session_obj_li_get_result,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'session',
obj_li: processed_obj_li,
properties_to_save: properties_to_save,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('DB save completed.');
}
// db_save_ae_obj_li__event_session({
// obj_type: 'event_session',
// obj_li: event_session_obj_li_get_result
// });
}
return event_session_obj_li_get_result;
} else {
return [];
} }
}) } else {
.catch(function (error: any) { console.log('No results returned from API.');
console.log('No results returned or failed.', error); if (try_cache) {
}); if (log_lvl) console.log('Attempting to load from local cache...');
ae_promises.load__event_session_obj_li = await db_events.session
if (log_lvl) { .where('for_id').equals(for_obj_id)
console.log( .toArray();
'ae_promises.load__event_session_obj_li:', } else {
ae_promises.load__event_session_obj_li ae_promises.load__event_session_obj_li = [];
); }
}
} catch (error: any) {
console.log('API request failed.', error);
if (try_cache) {
if (log_lvl) console.log('Attempting to load from local cache after error...');
ae_promises.load__event_session_obj_li = await db_events.session
.where('for_id').equals(for_obj_id)
.toArray();
} else {
ae_promises.load__event_session_obj_li = [];
}
} }
if (inc_file_li) { if (inc_file_li && ae_promises.load__event_session_obj_li) {
// Load the files for the sessions
if (log_lvl) {
console.log(`Need to load the file list for each session now`);
}
for (let i = 0; i < ae_promises.load__event_session_obj_li.length; i++) { for (let i = 0; i < ae_promises.load__event_session_obj_li.length; i++) {
const event_session_obj = ae_promises.load__event_session_obj_li[i]; const event_session_obj = ae_promises.load__event_session_obj_li[i];
const event_session_id = event_session_obj.event_session_id_random; const current_session_id = event_session_obj.event_session_id || event_session_obj.id;
const load_event_file_obj_li = load_ae_obj_li__event_file({ event_session_obj.event_file_li = await load_ae_obj_li__event_file({
api_cfg: api_cfg, api_cfg: api_cfg,
for_obj_type: 'event_session', for_obj_type: 'event_session',
for_obj_id: event_session_id, for_obj_id: current_session_id,
enabled: enabled, enabled: enabled,
limit: limit, limit: limit,
try_cache: try_cache, try_cache: try_cache,
log_lvl: log_lvl log_lvl: log_lvl
}).then((event_file_obj_li) => {
if (log_lvl) {
console.log(`event_file_obj_li = `, event_file_obj_li);
}
return event_file_obj_li;
}); });
if (log_lvl) {
console.log(`load_event_file_obj_li = `, load_event_file_obj_li);
}
} }
} }
if (inc_presentation_li) { if (inc_presentation_li && ae_promises.load__event_session_obj_li) {
// Load the presentations for the sessions
if (log_lvl) {
console.log(`Need to load the presentation list for each session now`);
}
for (let i = 0; i < ae_promises.load__event_session_obj_li.length; i++) { for (let i = 0; i < ae_promises.load__event_session_obj_li.length; i++) {
const event_session_obj = ae_promises.load__event_session_obj_li[i]; const event_session_obj = ae_promises.load__event_session_obj_li[i];
const event_session_id = event_session_obj.event_session_id_random; const current_session_id = event_session_obj.event_session_id || event_session_obj.id;
// NOTE: The files will only be included if inc_all_file_li is true. 2025-09-17 event_session_obj.event_presentation_li = await load_ae_obj_li__event_presentation({
const load_event_presentation_obj_li = load_ae_obj_li__event_presentation({
api_cfg: api_cfg, api_cfg: api_cfg,
for_obj_type: 'event_session', for_obj_type: 'event_session',
for_obj_id: event_session_id, for_obj_id: current_session_id,
inc_file_li: inc_all_file_li, inc_file_li: inc_all_file_li,
inc_presenter_li: inc_presenter_li, inc_presenter_li: inc_presenter_li,
enabled: enabled, enabled: enabled,
@@ -341,26 +269,7 @@ export async function load_ae_obj_li__event_session({
params: params, params: params,
try_cache: try_cache, try_cache: try_cache,
log_lvl: log_lvl log_lvl: log_lvl
}).then((event_presentation_obj_li) => {
if (log_lvl) {
console.log(`event_presentation_obj_li = `, event_presentation_obj_li);
}
// if (try_cache) {
// console.log(`event_session_obj = `, event_session_obj);
// event_session_obj.event_presentation_li = event_presentation_obj_li;
// // Re-save the session object with the new presentation list
// db_save_ae_obj_li__event_session({
// obj_type: 'event_session',
// obj_li: event_session_obj
// });
// }
return event_presentation_obj_li;
}); });
if (log_lvl) {
console.log(`load_event_presentation_obj_li = `, load_event_presentation_obj_li);
}
} }
} }

View File

@@ -118,39 +118,24 @@ async function _process_generic_props<T extends Record<string, any>>({
log_lvl?: number; log_lvl?: number;
specific_processor?: (obj: T) => Promise<T> | T; specific_processor?: (obj: T) => Promise<T> | T;
}): Promise<T[]> { }): Promise<T[]> {
if (log_lvl > 0) { if (!obj_li || obj_li.length === 0) return [];
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 [];
}
const processed_obj_li: T[] = []; const processed_obj_li: T[] = [];
for (const original_obj of obj_li) { for (const original_obj of obj_li) {
let processed_obj = { ...original_obj }; 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) { for (const key in processed_obj) {
if (key.endsWith('_random')) { 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]; (processed_obj as any)[newKey] = processed_obj[key];
} }
} }
// Ensure 'id' is set from '[obj_type]_id_random'
const randomIdKey = `${obj_type}_id_random`; const randomIdKey = `${obj_type}_id_random`;
if (processed_obj[randomIdKey]) { if (processed_obj[randomIdKey]) {
(processed_obj as any).id = 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 group = processed_obj.group ?? '0';
const priority = processed_obj.priority ? 1 : 0; const priority = processed_obj.priority ? 1 : 0;
const sort = processed_obj.sort ?? '0'; const sort = processed_obj.sort ?? '0';
@@ -160,7 +145,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_1 = `${group}_${priority}_${sort}_${updated}`;
(processed_obj as any).tmp_sort_2 = `${group}_${priority}_${sort}_${name}_${updated}`; (processed_obj as any).tmp_sort_2 = `${group}_${priority}_${sort}_${name}_${updated}`;
// --- Specific Transformations ---
if (specific_processor) { if (specific_processor) {
processed_obj = await Promise.resolve(specific_processor(processed_obj)); processed_obj = await Promise.resolve(specific_processor(processed_obj));
} }
@@ -209,56 +193,48 @@ export async function load_ae_obj_id__exhibit({
try_cache?: boolean; try_cache?: boolean;
log_lvl?: number; log_lvl?: number;
}): Promise<ae_EventExhibit | null> { }): Promise<ae_EventExhibit | null> {
console.log(`*** load_ae_obj_id__exhibit() *** exhibit_id=${exhibit_id}`); if (log_lvl) {
console.log(`*** load_ae_obj_id__exhibit() *** exhibit_id=${exhibit_id}`);
}
const params = {}; try {
ae_promises.load__exhibit_obj = await api
.get_ae_obj_id_crud({
api_cfg: api_cfg,
obj_type: 'event_exhibit',
obj_id: exhibit_id,
use_alt_table: false,
use_alt_base: false,
params: {},
log_lvl: log_lvl
});
// $events_sess.exhibits.status_load__exhibit_obj = 'loading'; if (ae_promises.load__exhibit_obj) {
ae_promises.load__exhibit_obj = await api if (try_cache) {
.get_ae_obj_id_crud({ const processed_obj_li = await process_ae_obj__exhibit_props({
api_cfg: api_cfg, obj_li: [ae_promises.load__exhibit_obj],
obj_type: 'event_exhibit', log_lvl: log_lvl
obj_id: exhibit_id, // NOTE: This is the FQDN, not normally the ID. });
use_alt_table: false, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config. await db_save_ae_obj_li__ae_obj({
use_alt_base: false, // NOTE: This will use the base_name_alt value instead of the base_name value in the API config. db_instance: db_events,
params: params, table_name: 'exhibit',
log_lvl: log_lvl obj_li: processed_obj_li,
}) properties_to_save: properties_to_save,
.then(async function (exhibit_obj_get_result) { log_lvl: log_lvl
if (exhibit_obj_get_result) { });
if (try_cache) {
// Process the results first
const processed_obj_li = await process_ae_obj__exhibit_props({
obj_li: [exhibit_obj_get_result],
log_lvl: log_lvl
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'exhibit',
obj_li: processed_obj_li,
properties_to_save: properties_to_save,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('DB save completed.');
}
}
return exhibit_obj_get_result;
} else {
console.log('No results returned.');
return null;
} }
}) } else {
.catch(function (error: any) { if (try_cache) {
console.log('No results returned or failed.', error); ae_promises.load__exhibit_obj = await db_events.exhibit.get(exhibit_id);
}); }
}
} catch (error: any) {
if (try_cache) {
ae_promises.load__exhibit_obj = await db_events.exhibit.get(exhibit_id);
} else {
ae_promises.load__exhibit_obj = null;
}
}
return ae_promises.load__exhibit_obj; return ae_promises.load__exhibit_obj;
} }
@@ -277,100 +253,73 @@ export async function load_ae_obj_li__exhibit({
try_cache?: boolean; try_cache?: boolean;
log_lvl?: number; log_lvl?: number;
}): Promise<ae_EventExhibit[]> { }): Promise<ae_EventExhibit[]> {
console.log(`*** load_ae_obj_li__exhibit() *** event_id=${event_id}`); if (log_lvl) {
console.log(`*** load_ae_obj_li__exhibit() *** event_id=${event_id}`);
}
const enabled: 'enabled' | 'all' | 'not_enabled' = (params.qry__enabled as any) ?? 'enabled'; const enabled: 'enabled' | 'all' | 'not_enabled' = (params.qry__enabled as any) ?? 'enabled';
const hidden: 'hidden' | 'all' | 'not_hidden' = (params.qry__hidden as any) ?? 'not_hidden'; const hidden: 'hidden' | 'all' | 'not_hidden' = (params.qry__hidden as any) ?? 'not_hidden';
const limit: number = params.qry__limit ?? 99; // 99 const limit: number = params.qry__limit ?? 99;
const offset: number = params.qry__offset ?? 0; // 0 const offset: number = params.qry__offset ?? 0;
const params_json: key_val = {}; const params_json: key_val = {
// params_json['and_qry'] = {}; and_in_li: {
// params_json['and_qry']['license_max'] = 10; license_max: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
}
params_json['and_in_li'] = {
license_max: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
}; };
// if (fulltext_search_qry_str && fulltext_search_qry_str.length > 2) { try {
// params_json['ft_qry'] = { ae_promises.load__event_exhibit_obj_li = await api
// 'default_qry_str': fulltext_search_qry_str, .get_ae_obj_li_for_obj_id_crud({
// // 'location_address_json_ext': fulltext_search_qry_str, // JSON extracted text DB field api_cfg: api_cfg,
// // 'contact_li_json_ext': fulltext_search_qry_str, // JSON extracted text DB field obj_type: 'event_exhibit',
// }; for_obj_type: 'event',
// } for_obj_id: event_id,
use_alt_table: false,
use_alt_base: false,
enabled: enabled,
hidden: hidden,
order_by_li: { priority: 'DESC', sort: 'DESC', updated_on: 'DESC', created_on: 'DESC' },
limit: limit,
offset: offset,
params_json: params_json,
params: params,
log_lvl: log_lvl
});
// console.log('params_json:', params_json); if (ae_promises.load__event_exhibit_obj_li) {
// console.log(params_json); if (try_cache) {
const processed_obj_li = await process_ae_obj__exhibit_props({
// $events_sess.exhibits.status_qry__search = 'loading'; obj_li: ae_promises.load__event_exhibit_obj_li,
ae_promises.load__event_exhibit_obj_li = await api log_lvl: log_lvl
.get_ae_obj_li_for_obj_id_crud({ });
api_cfg: api_cfg, await db_save_ae_obj_li__ae_obj({
obj_type: 'event_exhibit', db_instance: db_events,
for_obj_type: 'event', table_name: 'exhibit',
for_obj_id: event_id, obj_li: processed_obj_li,
use_alt_table: false, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config. properties_to_save: properties_to_save,
use_alt_base: false, // NOTE: This will use the base_name_alt value instead of the base_name value in the API config. log_lvl: log_lvl
enabled: enabled, });
hidden: hidden,
order_by_li: { priority: 'DESC', sort: 'DESC', updated_on: 'DESC', created_on: 'DESC' },
// order_by_li: {'priority': 'DESC', 'sort': 'DESC', 'created_on': 'DESC', 'updated_on': 'DESC'},
limit: limit,
offset: offset,
params_json: params_json,
params: params,
log_lvl: log_lvl
})
.then(async function (exhibit_obj_li_get_result) {
// console.log('Badge list:', exhibit_obj_li_get_result);
if (exhibit_obj_li_get_result) {
if (try_cache) {
// Process the results first
const processed_obj_li = await process_ae_obj__exhibit_props({
obj_li: exhibit_obj_li_get_result,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'exhibit',
obj_li: processed_obj_li,
properties_to_save: properties_to_save,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('DB save completed.');
}
}
return exhibit_obj_li_get_result;
} else {
// $slct.exhibit_obj_li = [];
return [];
} }
}) } else {
.catch(function (error: any) { if (try_cache) {
console.log('No results returned or failed.', error); ae_promises.load__event_exhibit_obj_li = await db_events.exhibit
}) .where('event_id').equals(event_id)
.finally(function () { .toArray();
// $events_sess.exhibits.status_qry__search = 'done'; } else {
// console.log('Badge list:', exhibit_obj_li_get_result); ae_promises.load__event_exhibit_obj_li = [];
// return exhibit_obj_li_get_result; }
}); }
} catch (error: any) {
if (log_lvl) { if (try_cache) {
console.log( ae_promises.load__event_exhibit_obj_li = await db_events.exhibit
'ae_promises.load__event_exhibit_obj_li:', .where('event_id').equals(event_id)
ae_promises.load__event_exhibit_obj_li .toArray();
); } else {
ae_promises.load__event_exhibit_obj_li = [];
}
} }
return ae_promises.load__event_exhibit_obj_li; return ae_promises.load__event_exhibit_obj_li;
} }
@@ -382,62 +331,53 @@ export async function load_ae_obj_id__exhibit_tracking({
}: { }: {
api_cfg: any; api_cfg: any;
exhibit_tracking_id: string; exhibit_tracking_id: string;
params?: key_val;
try_cache?: boolean; try_cache?: boolean;
log_lvl?: number; log_lvl?: number;
}): Promise<ae_EventExhibitTracking | null> { }): Promise<ae_EventExhibitTracking | null> {
console.log( if (log_lvl) {
`*** load_ae_obj_id__exhibit_tracking() *** exhibit_tracking_id=${exhibit_tracking_id}` console.log(
); `*** load_ae_obj_id__exhibit_tracking() *** exhibit_tracking_id=${exhibit_tracking_id}`
);
}
const params = {}; try {
ae_promises.load__event_exhibit_tracking_obj = await api
.get_ae_obj_id_crud({
api_cfg: api_cfg,
obj_type: 'event_exhibit_tracking',
obj_id: exhibit_tracking_id,
use_alt_table: false,
use_alt_base: false,
params: {},
log_lvl: log_lvl
});
// $events_sess.exhibits.status_load__exhibit_tracking_obj = 'loading'; if (ae_promises.load__event_exhibit_tracking_obj) {
ae_promises.load__event_exhibit_tracking_obj = await api if (try_cache) {
.get_ae_obj_id_crud({ const processed_obj_li = await process_ae_obj__exhibit_tracking_props({
api_cfg: api_cfg, obj_li: [ae_promises.load__event_exhibit_tracking_obj],
obj_type: 'event_exhibit_tracking', log_lvl: log_lvl
obj_id: exhibit_tracking_id, // NOTE: This is the FQDN, not normally the ID. });
use_alt_table: false, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config. await db_save_ae_obj_li__ae_obj({
use_alt_base: false, // NOTE: This will use the base_name_alt value instead of the base_name value in the API config. db_instance: db_events,
params: params, table_name: 'exhibit_tracking',
log_lvl: log_lvl obj_li: processed_obj_li,
}) properties_to_save: properties_to_save_exhibit_tracking,
.then(async function (exhibit_tracking_obj_get_result) { log_lvl: log_lvl
if (exhibit_tracking_obj_get_result) { });
if (try_cache) {
// Process the results first
const processed_obj_li = await process_ae_obj__exhibit_tracking_props({
obj_li: [exhibit_tracking_obj_get_result],
log_lvl: log_lvl
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'exhibit_tracking',
obj_li: processed_obj_li,
properties_to_save: properties_to_save_exhibit_tracking,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('DB save completed.');
}
}
return exhibit_tracking_obj_get_result;
} else {
console.log('No results returned.');
return null;
} }
}) } else {
.catch(function (error: any) { if (try_cache) {
console.log('No results returned or failed.', error); ae_promises.load__event_exhibit_tracking_obj = await db_events.exhibit_tracking.get(exhibit_tracking_id);
}); }
}
} catch (error: any) {
if (try_cache) {
ae_promises.load__event_exhibit_tracking_obj = await db_events.exhibit_tracking.get(exhibit_tracking_id);
} else {
ae_promises.load__event_exhibit_tracking_obj = null;
}
}
return ae_promises.load__event_exhibit_tracking_obj; return ae_promises.load__event_exhibit_tracking_obj;
} }
@@ -456,80 +396,67 @@ export async function load_ae_obj_li__exhibit_tracking({
try_cache?: boolean; try_cache?: boolean;
log_lvl?: number; log_lvl?: number;
}): Promise<ae_EventExhibitTracking[]> { }): Promise<ae_EventExhibitTracking[]> {
console.log(`*** load_ae_obj_li__exhibit_tracking() *** exhibit_id=${exhibit_id}`); if (log_lvl) {
console.log(`*** load_ae_obj_li__exhibit_tracking() *** exhibit_id=${exhibit_id}`);
}
const enabled: 'enabled' | 'all' | 'not_enabled' = (params.qry__enabled as any) ?? 'enabled'; const enabled: 'enabled' | 'all' | 'not_enabled' = (params.qry__enabled as any) ?? 'enabled';
const hidden: 'hidden' | 'all' | 'not_hidden' = (params.qry__hidden as any) ?? 'all'; const hidden: 'hidden' | 'all' | 'not_hidden' = (params.qry__hidden as any) ?? 'all';
const limit: number = params.qry__limit ?? 99; // 99 const limit: number = params.qry__limit ?? 99;
const offset: number = params.qry__offset ?? 0; // 0 const offset: number = params.qry__offset ?? 0;
const params_json: key_val = {}; try {
ae_promises.load__event_exhibit_tracking_obj_li = await api
.get_ae_obj_li_for_obj_id_crud({
api_cfg: api_cfg,
obj_type: 'event_exhibit_tracking',
for_obj_type: 'event_exhibit',
for_obj_id: exhibit_id,
use_alt_table: false,
use_alt_base: false,
enabled: enabled,
hidden: hidden,
order_by_li: { priority: 'DESC', sort: 'DESC', updated_on: 'DESC', created_on: 'DESC' },
limit: limit,
offset: offset,
params_json: {},
params: params,
log_lvl: log_lvl
});
ae_promises.load__event_exhibit_tracking_obj_li = await api if (ae_promises.load__event_exhibit_tracking_obj_li) {
.get_ae_obj_li_for_obj_id_crud({ if (try_cache) {
api_cfg: api_cfg, const processed_obj_li = await process_ae_obj__exhibit_tracking_props({
obj_type: 'event_exhibit_tracking', obj_li: ae_promises.load__event_exhibit_tracking_obj_li,
for_obj_type: 'event_exhibit', log_lvl: log_lvl
for_obj_id: exhibit_id, });
use_alt_table: false, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config. await db_save_ae_obj_li__ae_obj({
use_alt_base: false, // NOTE: This will use the base_name_alt value instead of the base_name value in the API config. db_instance: db_events,
enabled: enabled, table_name: 'exhibit_tracking',
hidden: hidden, obj_li: processed_obj_li,
order_by_li: { priority: 'DESC', sort: 'DESC', updated_on: 'DESC', created_on: 'DESC' }, properties_to_save: properties_to_save_exhibit_tracking,
limit: limit, log_lvl: log_lvl
offset: offset, });
params_json: params_json,
params: params,
log_lvl: log_lvl
})
.then(async function (exhibit_tracking_obj_li_get_result) {
// console.log('Exhibit tracking list:', exhibit_tracking_obj_li_get_result);
if (exhibit_tracking_obj_li_get_result) {
if (try_cache) {
// Process the results first
const processed_obj_li = await process_ae_obj__exhibit_tracking_props({
obj_li: exhibit_tracking_obj_li_get_result,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('Processed object list:', processed_obj_li);
}
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'exhibit_tracking',
obj_li: processed_obj_li,
properties_to_save: properties_to_save_exhibit_tracking,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('DB save completed.');
}
}
return exhibit_tracking_obj_li_get_result;
} else {
// $slct.exhibit_tracking_obj_li = [];
return [];
} }
}) } else {
.catch(function (error: any) { if (try_cache) {
console.log('No results returned or failed.', error); ae_promises.load__event_exhibit_tracking_obj_li = await db_events.exhibit_tracking
}) .where('event_exhibit_id').equals(exhibit_id)
.finally(function () { .toArray();
// console.log('Exhibit tracking list:', exhibit_tracking_obj_li_get_result); } else {
// return exhibit_tracking_obj_li_get_result; ae_promises.load__event_exhibit_tracking_obj_li = [];
}); }
}
if (log_lvl) { } catch (error: any) {
console.log( if (try_cache) {
'ae_promises.load__event_exhibit_tracking_obj_li:', ae_promises.load__event_exhibit_tracking_obj_li = await db_events.exhibit_tracking
ae_promises.load__event_exhibit_tracking_obj_li .where('event_exhibit_id').equals(exhibit_id)
); .toArray();
} else {
ae_promises.load__event_exhibit_tracking_obj_li = [];
}
} }
return ae_promises.load__event_exhibit_tracking_obj_li; return ae_promises.load__event_exhibit_tracking_obj_li;
} }
@@ -551,13 +478,6 @@ export async function create_ae_obj__exhibit_tracking({
try_cache?: boolean; try_cache?: boolean;
log_lvl?: number; log_lvl?: number;
}): Promise<ae_EventExhibitTracking | null> { }): Promise<ae_EventExhibitTracking | null> {
console.log(
`*** handle_create_ae_obj__exhibit_tracking() *** exhibit_id=${exhibit_id}, event_badge_id=${event_badge_id}`
);
const params_json: key_val = {};
// $events_sess.exhibits.status_create__exhibit_tracking = 'loading';
ae_promises.create__event_exhibit_tracking = await api ae_promises.create__event_exhibit_tracking = await api
.create_ae_obj_crud({ .create_ae_obj_crud({
api_cfg: api_cfg, api_cfg: api_cfg,
@@ -572,54 +492,23 @@ export async function create_ae_obj__exhibit_tracking({
return_obj: true, return_obj: true,
log_lvl: log_lvl log_lvl: log_lvl
}) })
.then(async function (obj_create_result) {
.then(async function (exhibit_tracking_obj_create_result) { if (obj_create_result && try_cache) {
// console.log('Exhibit tracking create:', exhibit_tracking_obj_create_result); const processed_obj_li = await process_ae_obj__exhibit_tracking_props({
if (exhibit_tracking_obj_create_result) { obj_li: [obj_create_result],
if (try_cache) { log_lvl: log_lvl
// Process the results first });
const processed_obj_li = await process_ae_obj__exhibit_tracking_props({ await db_save_ae_obj_li__ae_obj({
obj_li: [exhibit_tracking_obj_create_result], db_instance: db_events,
log_lvl: log_lvl table_name: 'exhibit_tracking',
}); obj_li: processed_obj_li,
if (log_lvl) { properties_to_save: properties_to_save_exhibit_tracking,
console.log('Processed object list:', processed_obj_li); log_lvl: log_lvl
} });
// Save the updated results list to the database
if (log_lvl) {
console.log('Saving to DB...');
}
db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'exhibit_tracking',
obj_li: processed_obj_li,
properties_to_save: properties_to_save_exhibit_tracking,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('DB save completed.');
}
}
return exhibit_tracking_obj_create_result;
} else {
// $slct.exhibit_tracking_obj = [];
return null;
} }
}) return obj_create_result;
.catch(function (error: any) {
console.log('No results returned or failed.', error);
})
.finally(function () {
// console.log('Exhibit tracking create:', exhibit_tracking_obj_create_result);
// return exhibit_tracking_obj_create_result;
}); });
if (log_lvl) {
console.log(
'ae_promises.create__event_exhibit_tracking:',
ae_promises.create__event_exhibit_tracking
);
}
return ae_promises.create__event_exhibit_tracking; return ae_promises.create__event_exhibit_tracking;
} }
@@ -629,18 +518,16 @@ export async function update_ae_obj__exhibit_tracking({
exhibit_tracking_id, exhibit_tracking_id,
data, data,
params = {}, params = {},
try_cache = true,
log_lvl = 0 log_lvl = 0
}: { }: {
api_cfg: any; api_cfg: any;
exhibit_tracking_id: string; exhibit_tracking_id: string;
data: any; data: any;
params: key_val; params?: key_val;
log_lvl: number; try_cache?: boolean;
log_lvl?: number;
}): Promise<ae_EventExhibitTracking | null> { }): Promise<ae_EventExhibitTracking | null> {
console.log(
`*** handle_update_ae_obj__exhibit_tracking() *** exhibit_tracking_id=${exhibit_tracking_id}`
);
ae_promises.update__event_exhibit_tracking = await api ae_promises.update__event_exhibit_tracking = await api
.update_ae_obj_id_crud({ .update_ae_obj_id_crud({
api_cfg: api_cfg, api_cfg: api_cfg,
@@ -652,48 +539,23 @@ export async function update_ae_obj__exhibit_tracking({
return_obj: true, return_obj: true,
log_lvl: log_lvl log_lvl: log_lvl
}) })
.then(async function (exhibit_tracking_obj_update_result) { .then(async function (obj_update_result) {
if (exhibit_tracking_obj_update_result) { if (obj_update_result && try_cache) {
if (try_cache) { const processed_obj_li = await process_ae_obj__exhibit_tracking_props({
// Process the results first obj_li: [obj_update_result],
const processed_obj_li = await process_ae_obj__exhibit_tracking_props({ log_lvl: log_lvl
obj_li: [exhibit_tracking_obj_update_result], });
log_lvl: log_lvl await db_save_ae_obj_li__ae_obj({
}); db_instance: db_events,
if (log_lvl) { table_name: 'exhibit_tracking',
console.log('Processed object list:', processed_obj_li); obj_li: processed_obj_li,
} properties_to_save: properties_to_save_exhibit_tracking,
// Save the updated results list to the database log_lvl: log_lvl
if (log_lvl) { });
console.log('Saving to DB...');
}
db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'exhibit_tracking',
obj_li: processed_obj_li,
properties_to_save: properties_to_save_exhibit_tracking,
log_lvl: log_lvl
});
if (log_lvl) {
console.log('DB save completed.');
}
}
return exhibit_tracking_obj_update_result;
} else {
return null;
} }
}) return obj_update_result;
.catch(function (error: any) { });
console.log('No results returned or failed.', error);
})
.finally(function () {});
if (log_lvl) {
console.log(
'ae_promises.update__event_exhibit_tracking:',
ae_promises.update__event_exhibit_tracking
);
}
return ae_promises.update__event_exhibit_tracking; return ae_promises.update__event_exhibit_tracking;
} }
@@ -741,4 +603,4 @@ export async function download_export__event_exhibit_tracking({
); );
} }
return ae_promises.download__event_exhibit_tracking_export_file; return ae_promises.download__event_exhibit_tracking_export_file;
} }

View File

@@ -421,6 +421,7 @@ export interface ae_Event extends ae_BaseObj {
// Joined view fields // Joined view fields
event_location_obj_li?: ae_EventLocation[]; event_location_obj_li?: ae_EventLocation[];
event_session_obj_li?: ae_EventSession[]; event_session_obj_li?: ae_EventSession[];
event_badge_template_obj_li?: ae_EventBadgeTemplate[];
} }
/** /**

View File

@@ -4,6 +4,7 @@
import { ae_api } from '$lib/stores/ae_stores'; import { ae_api } from '$lib/stores/ae_stores';
import { events_slct } from '$lib/stores/ae_events_stores'; import { events_slct } from '$lib/stores/ae_events_stores';
import Comp_badge_obj_view from '../[badge_id]/ae_comp__badge_obj_view.svelte'; import Comp_badge_obj_view from '../[badge_id]/ae_comp__badge_obj_view.svelte';
import type { ae_EventBadge } from '$lib/types/ae_types';
interface Props { interface Props {
data: any; // PageData from SvelteKit data: any; // PageData from SvelteKit
@@ -17,8 +18,8 @@
let lq__filtered_badges = $derived( let lq__filtered_badges = $derived(
liveQuery(async () => { liveQuery(async () => {
const filters: { printed_status?: string; type_code?: string } = {}; const filters: { printed_status?: "all" | "printed" | "not_printed"; type_code?: string } = {};
if (printed_status_filter) filters.printed_status = printed_status_filter; if (printed_status_filter) filters.printed_status = printed_status_filter as any;
if (badge_type_code_filter) filters.type_code = badge_type_code_filter; if (badge_type_code_filter) filters.type_code = badge_type_code_filter;
// Fetch badges using the search function, with a high limit for bulk printing // Fetch badges using the search function, with a high limit for bulk printing
@@ -29,7 +30,7 @@
...filters, ...filters,
log_lvl: 0 log_lvl: 0
}); });
return result || []; return (result || []) as ae_EventBadge[];
}) })
); );
@@ -76,12 +77,10 @@
</a> </a>
</div> </div>
{#await lq__filtered_badges} {#if $lq__filtered_badges}
<p>Loading badges for printing...</p> {#if $lq__filtered_badges.length > 0}
{:then badges_to_print}
{#if badges_to_print.length > 0}
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4"> <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
{#each badges_to_print as badge_obj (badge_obj.event_badge_id_random)} {#each $lq__filtered_badges as badge_obj (badge_obj.event_badge_id_random)}
<div class="badge-print-container"> <div class="badge-print-container">
<Comp_badge_obj_view <Comp_badge_obj_view
{event_id} {event_id}
@@ -96,7 +95,7 @@
{:else} {:else}
<p>No badges found matching your criteria for printing.</p> <p>No badges found matching your criteria for printing.</p>
{/if} {/if}
{:catch error} {:else}
<p class="text-error-500">Error loading badges: {error.message}</p> <p>Loading badges for printing...</p>
{/await} {/if}
</section> </section>

View File

@@ -30,7 +30,7 @@ export async function load({ params, parent }) {
if (browser) { if (browser) {
// Load event location object // Load event location object
const load_event_location_obj = events_func.load_ae_obj_id__event_location({ const load_event_location_obj = await events_func.load_ae_obj_id__event_location({
api_cfg: ae_acct.api, api_cfg: ae_acct.api,
event_location_id: event_location_id, event_location_id: event_location_id,
try_cache: true try_cache: true
@@ -39,71 +39,45 @@ export async function load({ params, parent }) {
ae_acct.slct.event_location_obj = load_event_location_obj; ae_acct.slct.event_location_obj = load_event_location_obj;
// Load event sessions for the location // Load event sessions for the location
const load_event_session_obj_li = events_func const event_session_obj_li = await events_func.load_ae_obj_li__event_session({
.load_ae_obj_li__event_session({ api_cfg: ae_acct.api,
api_cfg: ae_acct.api, for_obj_type: 'event_location',
for_obj_type: 'event_location', for_obj_id: event_location_id,
for_obj_id: event_location_id, enabled: 'all',
enabled: 'all', limit: 50,
limit: 50, log_lvl: log_lvl
log_lvl: log_lvl });
})
.then((event_session_obj_li) => {
if (log_lvl) {
console.log(`event_session_obj_li = `, event_session_obj_li);
}
for (let index = 0; index < event_session_obj_li.length; index++) {
const event_session_obj = event_session_obj_li[index];
const event_session_id = event_session_obj.event_session_id_random;
const load_event_presentation_obj_li = if (event_session_obj_li) {
events_func.load_ae_obj_li__event_presentation({ for (let index = 0; index < event_session_obj_li.length; index++) {
api_cfg: ae_acct.api, const event_session_obj = event_session_obj_li[index];
for_obj_type: 'event_session', const event_session_id = event_session_obj.event_session_id || event_session_obj.id;
for_obj_id: event_session_id,
enabled: 'all',
limit: 25,
log_lvl: log_lvl
});
if (log_lvl) {
console.log(
`load_event_presentation_obj_li = `,
load_event_presentation_obj_li
);
}
event_session_obj_li[index].event_presentation_li =
load_event_presentation_obj_li;
}
return event_session_obj_li; const load_event_presentation_obj_li = await events_func.load_ae_obj_li__event_presentation({
}); api_cfg: ae_acct.api,
if (log_lvl) { for_obj_type: 'event_session',
console.log(`load_event_session_obj_li = `, load_event_session_obj_li); for_obj_id: event_session_id,
enabled: 'all',
limit: 25,
log_lvl: log_lvl
});
event_session_obj_li[index].event_presentation_li = load_event_presentation_obj_li;
}
} }
ae_acct.slct.event_session_obj_li = load_event_session_obj_li; ae_acct.slct.event_session_obj_li = event_session_obj_li;
const load_event_file_obj_li = await events_func const load_event_file_obj_li = await events_func.load_ae_obj_li__event_file({
.load_ae_obj_li__event_file({ api_cfg: ae_acct.api,
api_cfg: ae_acct.api, for_obj_type: 'event_location',
for_obj_type: 'event_location', for_obj_id: event_location_id,
for_obj_id: event_location_id, enabled: 'all',
enabled: 'all', hidden: 'all',
hidden: 'all', limit: 50,
limit: 50, log_lvl: log_lvl
log_lvl: log_lvl });
})
.then((event_file_obj_li) => {
if (log_lvl) {
console.log(`event_file_obj_li = `, event_file_obj_li);
}
return event_file_obj_li;
});
if (log_lvl) {
console.log(`load_event_file_obj_li = `, load_event_file_obj_li);
}
ae_acct.slct.event_file_obj_li = load_event_file_obj_li; ae_acct.slct.event_file_obj_li = load_event_file_obj_li;
const load_event_device_obj_li = events_func.load_ae_obj_li__event_device({ const load_event_device_obj_li = await events_func.load_ae_obj_li__event_device({
api_cfg: ae_acct.api, api_cfg: ae_acct.api,
for_obj_type: 'event_location', for_obj_type: 'event_location',
for_obj_id: event_location_id, for_obj_id: event_location_id,

View File

@@ -47,75 +47,50 @@ export async function load({ params, parent }) {
ae_acct.slct.event_session_obj = load_event_session_obj; ae_acct.slct.event_session_obj = load_event_session_obj;
// Load event presentations for the session // Load event presentations for the session
const load_event_presentation_obj_li = events_func const event_presentation_obj_li = await events_func.load_ae_obj_li__event_presentation({
.load_ae_obj_li__event_presentation({ api_cfg: ae_acct.api,
api_cfg: ae_acct.api, for_obj_type: 'event_session',
for_obj_type: 'event_session', for_obj_id: event_session_id,
for_obj_id: event_session_id, inc_presenter_li: true,
inc_presenter_li: true, enabled: 'all',
enabled: 'all', hidden: 'all',
hidden: 'all', limit: 19,
limit: 19, // params: {},
// params: {}, try_cache: true,
try_cache: true, log_lvl: 2
log_lvl: 2 });
})
.then((event_presentation_obj_li) => {
if (log_lvl) {
console.log(`event_presentation_obj_li = `, event_presentation_obj_li);
}
for (let index = 0; index < event_presentation_obj_li?.length; index++) {
const event_presentation_obj = event_presentation_obj_li[index];
const event_presentation_id =
event_presentation_obj.event_presentation_id_random;
const load_event_presenter_obj_li = events_func.load_ae_obj_li__event_presenter( if (event_presentation_obj_li) {
{ for (let index = 0; index < event_presentation_obj_li.length; index++) {
api_cfg: ae_acct.api, const event_presentation_obj = event_presentation_obj_li[index];
for_obj_type: 'event_presentation', const event_presentation_id = event_presentation_obj.event_presentation_id || event_presentation_obj.id;
for_obj_id: event_presentation_id,
enabled: 'all',
hidden: 'all',
limit: 19,
params: {},
try_cache: true,
log_lvl: 2
}
);
if (log_lvl) {
console.log(`load_event_presenter_obj_li = `, load_event_presenter_obj_li);
}
event_presentation_obj_li[index].event_presenter_li =
load_event_presenter_obj_li;
}
return event_presentation_obj_li; const load_event_presenter_obj_li = await events_func.load_ae_obj_li__event_presenter({
}); api_cfg: ae_acct.api,
if (log_lvl) { for_obj_type: 'event_presentation',
console.log(`load_event_presentation_obj_li = `, load_event_presentation_obj_li); for_obj_id: event_presentation_id,
enabled: 'all',
hidden: 'all',
limit: 19,
params: {},
try_cache: true,
log_lvl: 2
});
event_presentation_obj_li[index].event_presenter_li = load_event_presenter_obj_li;
}
} }
ae_acct.slct.event_presentation_obj_li = load_event_presentation_obj_li; ae_acct.slct.event_presentation_obj_li = event_presentation_obj_li;
// Load event files for the session // Load event files for the session
const load_event_file_obj_li = await events_func const load_event_file_obj_li = await events_func.load_ae_obj_li__event_file({
.load_ae_obj_li__event_file({ api_cfg: ae_acct.api,
api_cfg: ae_acct.api, for_obj_type: 'event_session',
for_obj_type: 'event_session', for_obj_id: event_session_id,
for_obj_id: event_session_id, enabled: 'all',
enabled: 'all', hidden: 'all',
hidden: 'all', limit: 50,
limit: 50, try_cache: true
try_cache: true });
})
.then((event_file_obj_li) => {
if (log_lvl) {
console.log(`event_file_obj_li = `, event_file_obj_li);
}
return event_file_obj_li;
});
if (log_lvl) {
console.log(`load_event_file_obj_li = `, load_event_file_obj_li);
}
ae_acct.slct.event_file_obj_li = load_event_file_obj_li; ae_acct.slct.event_file_obj_li = load_event_file_obj_li;
} }