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:
@@ -44,9 +44,8 @@ export async function load_ae_obj_id__event_session({
|
||||
|
||||
const params = {};
|
||||
|
||||
// $events_sess.badges.status_load__event_session_obj = 'loading';
|
||||
ae_promises.load__event_session_obj = await api
|
||||
.get_ae_obj_id_crud({
|
||||
try {
|
||||
ae_promises.load__event_session_obj = await api.get_ae_obj_id_crud({
|
||||
api_cfg: api_cfg,
|
||||
obj_type: 'event_session',
|
||||
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.
|
||||
params: params,
|
||||
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) {
|
||||
console.log('ae_promises.load__event_session_obj:', ae_promises?.load__event_session_obj);
|
||||
}
|
||||
|
||||
if (ae_promises?.load__event_session_obj === null) {
|
||||
console.log('No results returned.');
|
||||
if (!ae_promises?.load__event_session_obj) {
|
||||
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) {
|
||||
// Load the files for the session
|
||||
if (log_lvl) {
|
||||
console.log(`Need to load the file list for the session now`);
|
||||
}
|
||||
const load_event_file_obj_li = load_ae_obj_li__event_file({
|
||||
ae_promises.load__event_session_obj.event_file_li = await load_ae_obj_li__event_file({
|
||||
api_cfg: api_cfg,
|
||||
for_obj_type: 'event_session',
|
||||
for_obj_id: event_session_id,
|
||||
for_obj_id: current_session_id,
|
||||
enabled: enabled,
|
||||
limit: 15,
|
||||
try_cache: try_cache,
|
||||
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) {
|
||||
// Load the presentations for the session
|
||||
if (log_lvl) {
|
||||
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({
|
||||
ae_promises.load__event_session_obj.event_presentation_li = await load_ae_obj_li__event_presentation({
|
||||
api_cfg: api_cfg,
|
||||
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_presenter_li: inc_presenter_li,
|
||||
enabled: enabled, // all, disabled, enabled
|
||||
@@ -151,17 +124,7 @@ export async function load_ae_obj_id__event_session({
|
||||
params: {},
|
||||
try_cache: try_cache,
|
||||
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;
|
||||
@@ -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 = {};
|
||||
|
||||
// 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({
|
||||
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.
|
||||
// use_alt_mdl: false, // NOTE: This will use the base_name_alt value instead of the base_name value
|
||||
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_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 [];
|
||||
if (ae_promises.load__event_session_obj_li) {
|
||||
if (try_cache) {
|
||||
const processed_obj_li = await process_ae_obj__event_session_props({
|
||||
obj_li: ae_promises.load__event_session_obj_li,
|
||||
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
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(function (error: any) {
|
||||
console.log('No results returned or failed.', error);
|
||||
});
|
||||
|
||||
if (log_lvl) {
|
||||
console.log(
|
||||
'ae_promises.load__event_session_obj_li:',
|
||||
ae_promises.load__event_session_obj_li
|
||||
);
|
||||
} 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_li = await db_events.session
|
||||
.where('for_id').equals(for_obj_id)
|
||||
.toArray();
|
||||
} else {
|
||||
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) {
|
||||
// Load the files for the sessions
|
||||
if (log_lvl) {
|
||||
console.log(`Need to load the file list for each session now`);
|
||||
}
|
||||
if (inc_file_li && ae_promises.load__event_session_obj_li) {
|
||||
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_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,
|
||||
for_obj_type: 'event_session',
|
||||
for_obj_id: event_session_id,
|
||||
for_obj_id: current_session_id,
|
||||
enabled: enabled,
|
||||
limit: limit,
|
||||
try_cache: try_cache,
|
||||
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) {
|
||||
// Load the presentations for the sessions
|
||||
if (log_lvl) {
|
||||
console.log(`Need to load the presentation list for each session now`);
|
||||
}
|
||||
if (inc_presentation_li && ae_promises.load__event_session_obj_li) {
|
||||
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_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
|
||||
const load_event_presentation_obj_li = load_ae_obj_li__event_presentation({
|
||||
event_session_obj.event_presentation_li = await load_ae_obj_li__event_presentation({
|
||||
api_cfg: api_cfg,
|
||||
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_presenter_li: inc_presenter_li,
|
||||
enabled: enabled,
|
||||
@@ -341,26 +269,7 @@ export async function load_ae_obj_li__event_session({
|
||||
params: params,
|
||||
try_cache: try_cache,
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user