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:
@@ -29,74 +29,68 @@ export async function load_ae_obj_id__event_device({
|
||||
|
||||
const params = {};
|
||||
|
||||
ae_promises.load__event_device_obj = await api
|
||||
.get_ae_obj_id_crud({
|
||||
api_cfg: api_cfg,
|
||||
obj_type: 'event_device',
|
||||
obj_id: event_device_id, // NOTE: This is the FQDN, not normally the ID.
|
||||
use_alt_table: true, // NOTE: This will use the table_name_alt value instead of the table_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,
|
||||
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.');
|
||||
}
|
||||
try {
|
||||
ae_promises.load__event_device_obj = await api
|
||||
.get_ae_obj_id_crud({
|
||||
api_cfg: api_cfg,
|
||||
obj_type: 'event_device',
|
||||
obj_id: event_device_id, // NOTE: This is the FQDN, not normally the ID.
|
||||
use_alt_table: true, // NOTE: This will use the table_name_alt value instead of the table_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,
|
||||
log_lvl: log_lvl
|
||||
});
|
||||
|
||||
// // This is expecting a list
|
||||
// db_save_ae_obj_li__event_device({
|
||||
// obj_type: 'event_device',
|
||||
// obj_li: [event_device_obj_get_result]
|
||||
// });
|
||||
}
|
||||
return event_device_obj_get_result;
|
||||
} else {
|
||||
console.log('No results returned.');
|
||||
return null;
|
||||
if (ae_promises.load__event_device_obj) {
|
||||
if (try_cache) {
|
||||
const processed_obj_li = await process_ae_obj__event_device_props({
|
||||
obj_li: [ae_promises.load__event_device_obj],
|
||||
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,
|
||||
log_lvl
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(function (error: any) {
|
||||
console.log('No results returned or failed.', error);
|
||||
});
|
||||
} 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 = 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) {
|
||||
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) {
|
||||
// Load the location linked to this device
|
||||
if (log_lvl) {
|
||||
console.log(`Need to load the location id for the device now`);
|
||||
const current_location_id = ae_promises.load__event_device_obj.event_location_id;
|
||||
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;
|
||||
@@ -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 = {};
|
||||
|
||||
// console.log('params_json:', params_json);
|
||||
|
||||
ae_promises.load__event_device_obj_li = await api
|
||||
.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({
|
||||
try {
|
||||
ae_promises.load__event_device_obj_li = await api
|
||||
.get_ae_obj_li_for_obj_id_crud_v2({
|
||||
api_cfg: api_cfg,
|
||||
event_location_id: event_device_obj.event_location_id,
|
||||
try_cache: try_cache,
|
||||
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((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) {
|
||||
console.log(`load_event_location_obj_li = `, load_event_location_obj_li);
|
||||
if (ae_promises.load__event_device_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
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user