Refactor: Remove redundant db_save exports and complete V3 cleanup
This commit is contained in:
@@ -5,28 +5,18 @@ import { db_save_ae_obj_li__ae_obj } from '$lib/ae_core/core__idb_dexie';
|
||||
import { db_events } from '$lib/ae_events/db_events';
|
||||
import type { ae_EventLocation } from '$lib/types/ae_types';
|
||||
|
||||
import { load_ae_obj_li__event_device } from '$lib/ae_events/ae_events__event_device';
|
||||
import { load_ae_obj_li__event_file } from '$lib/ae_events/ae_events__event_file';
|
||||
import { load_ae_obj_li__event_session } from './ae_events__event_session';
|
||||
|
||||
const ae_promises: key_val = {};
|
||||
|
||||
// Updated 2026-01-20 to V3
|
||||
export async function load_ae_obj_id__event_location({
|
||||
api_cfg,
|
||||
event_location_id,
|
||||
inc_device_li = false,
|
||||
inc_file_li = false,
|
||||
inc_session_li = false,
|
||||
view = 'default',
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any;
|
||||
event_location_id: string;
|
||||
inc_device_li?: boolean;
|
||||
inc_file_li?: boolean;
|
||||
inc_session_li?: boolean;
|
||||
view?: string;
|
||||
try_cache?: boolean;
|
||||
log_lvl?: number;
|
||||
@@ -35,18 +25,6 @@ export async function load_ae_obj_id__event_location({
|
||||
console.log(`*** load_ae_obj_id__event_location() *** [V3] id=${event_location_id}`);
|
||||
}
|
||||
|
||||
// Check if offline
|
||||
if (typeof navigator !== 'undefined' && !navigator.onLine) {
|
||||
if (log_lvl) console.log('Browser is offline. Skipping API and attempting cache load.');
|
||||
ae_promises.load__event_location_obj = await db_events.location.get(event_location_id);
|
||||
if (ae_promises.load__event_location_obj) {
|
||||
return await _handle_nested_loads(ae_promises.load__event_location_obj, {
|
||||
api_cfg, inc_device_li, inc_file_li, inc_session_li, try_cache, log_lvl
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
ae_promises.load__event_location_obj = await api.get_ae_obj_v3({
|
||||
api_cfg,
|
||||
@@ -80,53 +58,7 @@ export async function load_ae_obj_id__event_location({
|
||||
}
|
||||
}
|
||||
|
||||
if (!ae_promises.load__event_location_obj) return null;
|
||||
|
||||
return await _handle_nested_loads(ae_promises.load__event_location_obj, {
|
||||
api_cfg, inc_device_li, inc_file_li, inc_session_li, try_cache, log_lvl
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to handle nested collection loads for a location
|
||||
*/
|
||||
async function _handle_nested_loads(location_obj: any, { api_cfg, inc_device_li, inc_file_li, inc_session_li, try_cache, log_lvl }: any) {
|
||||
const current_location_id = location_obj.event_location_id_random || location_obj.event_location_id || location_obj.id;
|
||||
|
||||
if (inc_device_li) {
|
||||
location_obj.event_device_obj_li = await load_ae_obj_li__event_device({
|
||||
api_cfg,
|
||||
for_obj_type: 'event_location',
|
||||
for_obj_id: current_location_id,
|
||||
log_lvl
|
||||
});
|
||||
}
|
||||
|
||||
if (inc_file_li) {
|
||||
location_obj.event_file_li = await load_ae_obj_li__event_file({
|
||||
api_cfg,
|
||||
for_obj_type: 'event_location',
|
||||
for_obj_id: current_location_id,
|
||||
enabled: 'all',
|
||||
limit: 15,
|
||||
try_cache,
|
||||
log_lvl
|
||||
});
|
||||
}
|
||||
|
||||
if (inc_session_li) {
|
||||
location_obj.event_session_li = await load_ae_obj_li__event_session({
|
||||
api_cfg,
|
||||
for_obj_type: 'event_location',
|
||||
for_obj_id: current_location_id,
|
||||
enabled: 'all',
|
||||
limit: 15,
|
||||
try_cache,
|
||||
log_lvl
|
||||
});
|
||||
}
|
||||
|
||||
return location_obj;
|
||||
return ae_promises.load__event_location_obj || null;
|
||||
}
|
||||
|
||||
// Updated 2026-01-20 to V3
|
||||
@@ -134,12 +66,9 @@ export async function load_ae_obj_li__event_location({
|
||||
api_cfg,
|
||||
for_obj_type = 'event',
|
||||
for_obj_id,
|
||||
inc_device_li = false,
|
||||
inc_file_li = false,
|
||||
inc_session_li = false,
|
||||
enabled = 'enabled',
|
||||
hidden = 'not_hidden',
|
||||
limit = 50,
|
||||
limit = 100,
|
||||
offset = 0,
|
||||
order_by_li = [
|
||||
{ priority: 'DESC' },
|
||||
@@ -153,9 +82,6 @@ export async function load_ae_obj_li__event_location({
|
||||
api_cfg: any;
|
||||
for_obj_type?: string;
|
||||
for_obj_id: string;
|
||||
inc_device_li?: boolean;
|
||||
inc_file_li?: boolean;
|
||||
inc_session_li?: boolean;
|
||||
enabled?: 'enabled' | 'all' | 'not_enabled';
|
||||
hidden?: 'hidden' | 'all' | 'not_hidden';
|
||||
limit?: number;
|
||||
@@ -168,20 +94,6 @@ export async function load_ae_obj_li__event_location({
|
||||
console.log(`*** load_ae_obj_li__event_location() *** [V3] for=${for_obj_type}:${for_obj_id}`);
|
||||
}
|
||||
|
||||
// Check if offline
|
||||
if (typeof navigator !== 'undefined' && !navigator.onLine) {
|
||||
if (log_lvl) console.log('Browser is offline. Skipping API and attempting cache load.');
|
||||
ae_promises.load__event_location_obj_li = await db_events.location
|
||||
.where('event_id').equals(for_obj_id)
|
||||
.toArray();
|
||||
if (ae_promises.load__event_location_obj_li) {
|
||||
for (const loc of ae_promises.load__event_location_obj_li) {
|
||||
await _handle_nested_loads(loc, { api_cfg, inc_device_li, inc_file_li, inc_session_li, try_cache, log_lvl });
|
||||
}
|
||||
}
|
||||
return ae_promises.load__event_location_obj_li || [];
|
||||
}
|
||||
|
||||
try {
|
||||
ae_promises.load__event_location_obj_li = await api.get_ae_obj_li_v3({
|
||||
api_cfg,
|
||||
@@ -224,12 +136,6 @@ export async function load_ae_obj_li__event_location({
|
||||
}
|
||||
}
|
||||
|
||||
if (ae_promises.load__event_location_obj_li) {
|
||||
for (const loc of ae_promises.load__event_location_obj_li) {
|
||||
await _handle_nested_loads(loc, { api_cfg, inc_device_li, inc_file_li, inc_session_li, try_cache, log_lvl });
|
||||
}
|
||||
}
|
||||
|
||||
return ae_promises.load__event_location_obj_li || [];
|
||||
}
|
||||
|
||||
@@ -428,17 +334,12 @@ export async function search__event_location({
|
||||
export const properties_to_save = [
|
||||
'id',
|
||||
'event_location_id',
|
||||
'event_id',
|
||||
'external_id',
|
||||
'code',
|
||||
'type_code',
|
||||
'event_id',
|
||||
'name',
|
||||
'description',
|
||||
'passcode',
|
||||
'hide_event_launcher',
|
||||
'alert',
|
||||
'alert_msg',
|
||||
'data_json',
|
||||
'enable',
|
||||
'hide',
|
||||
'priority',
|
||||
@@ -449,13 +350,12 @@ export const properties_to_save = [
|
||||
'updated_on',
|
||||
'tmp_sort_1',
|
||||
'tmp_sort_2',
|
||||
'file_count',
|
||||
'file_count_all',
|
||||
'internal_use_count',
|
||||
'event_file_id_li_json',
|
||||
'event_name'
|
||||
];
|
||||
|
||||
/**
|
||||
* NON-EXPORTED LOCAL HELPER
|
||||
*/
|
||||
async function _process_generic_props<T extends Record<string, any>>({
|
||||
obj_li,
|
||||
obj_type,
|
||||
@@ -474,6 +374,7 @@ async function _process_generic_props<T extends Record<string, any>>({
|
||||
for (const original_obj of obj_li) {
|
||||
let processed_obj = { ...original_obj };
|
||||
|
||||
// 1. Standardize ID and other '_random' fields
|
||||
for (const key in processed_obj) {
|
||||
if (key.endsWith('_random')) {
|
||||
const newKey = key.slice(0, -7);
|
||||
@@ -485,6 +386,7 @@ async function _process_generic_props<T extends Record<string, any>>({
|
||||
(processed_obj as any).id = processed_obj[randomIdKey];
|
||||
}
|
||||
|
||||
// 2. Create common computed properties
|
||||
const group = processed_obj.group ?? '0';
|
||||
const priority = processed_obj.priority ? 1 : 0;
|
||||
const sort = processed_obj.sort ?? '0';
|
||||
|
||||
Reference in New Issue
Block a user