Code clean up.

This commit is contained in:
Scott Idem
2024-11-19 19:24:55 -05:00
parent 9ded8f7c7e
commit 90a74e5ce7
2 changed files with 143 additions and 139 deletions

View File

@@ -9,14 +9,14 @@ import { browser } from '$app/environment';
import { Modal } from 'flowbite-svelte'; import { Modal } from 'flowbite-svelte';
import type { key_val } from '$lib/ae_stores'; // import type { key_val } from '$lib/ae_stores';
import { ae_util } from '$lib/ae_utils/ae_utils'; import { ae_util } from '$lib/ae_utils/ae_utils';
import { idaa_loc, idaa_sess, idaa_slct, idaa_trig, idaa_prom } from '$lib/ae_idaa_stores'; import { idaa_loc, idaa_sess, idaa_slct, idaa_trig, idaa_prom } from '$lib/ae_idaa_stores';
// import Element_data_store from '$lib/element_data_store_v2.svelte'; // import Element_data_store from '$lib/element_data_store_v2.svelte';
// import Comp_event_session_obj_li from '../../events_pres_mgmt/ae_comp__event_session_obj_li.svelte'; // import Comp_event_session_obj_li from '../../events_pres_mgmt/ae_comp__event_session_obj_li.svelte';
import { liveQuery } from "dexie"; import { liveQuery } from "dexie";
import { core_func } from '$lib/ae_core/ae_core_functions'; // import { core_func } from '$lib/ae_core/ae_core_functions';
import { db_events } from "$lib/ae_events/db_events"; import { db_events } from "$lib/ae_events/db_events";
import { ae_snip, ae_loc, ae_sess, ae_api, ae_trig, slct, slct_trigger } from '$lib/ae_stores'; import { ae_snip, ae_loc, ae_sess, ae_api, ae_trig, slct, slct_trigger } from '$lib/ae_stores';
import { events_func } from '$lib/ae_events_functions'; import { events_func } from '$lib/ae_events_functions';
@@ -79,6 +79,8 @@ $: lq_new__event_obj_li = liveQuery(async () => {
}); });
// This (event_li trigger for IDAA) is not currently being used.
// Updated 2024-11-19
$: if ($idaa_trig.event_li) { $: if ($idaa_trig.event_li) {
$idaa_trig.event_li = false; $idaa_trig.event_li = false;
@@ -108,6 +110,7 @@ $: if ($idaa_trig.event_li) {
} }
// Updated 2024-11-19
$: if ($idaa_trig.event_li_qry) { $: if ($idaa_trig.event_li_qry) {
$idaa_trig.event_li_qry = false; $idaa_trig.event_li_qry = false;

View File

@@ -8,7 +8,7 @@ import { ae_util } from '$lib/ae_utils/ae_utils';
import { ae_snip, ae_loc, ae_sess, ae_api, ae_trig, slct, slct_trigger } from '$lib/ae_stores'; import { ae_snip, ae_loc, ae_sess, ae_api, ae_trig, slct, slct_trigger } from '$lib/ae_stores';
import { core_func } from '$lib/ae_core/ae_core_functions'; import { core_func } from '$lib/ae_core/ae_core_functions';
import { idaa_loc, idaa_sess, idaa_slct, idaa_trig, idaa_prom } from '$lib/ae_idaa_stores'; import { idaa_loc, idaa_sess, idaa_slct, idaa_trig, idaa_prom } from '$lib/ae_idaa_stores';
import { events_func } from '$lib/ae_events_functions'; // import { events_func } from '$lib/ae_events_functions';
export let log_lvl = 0; export let log_lvl = 0;
export let event_id_random_li: Array<string>; export let event_id_random_li: Array<string>;
@@ -16,11 +16,11 @@ export let event_id_random_li: Array<string>;
// export let container_class_li = []; // export let container_class_li = [];
let ae_promises: key_val = {}; let ae_promises: key_val = {};
let ae_tmp: key_val = {}; // let ae_tmp: key_val = {};
let ae_trigger: any = null; // let ae_trigger: any = null;
let ae_triggers: key_val = {}; // let ae_triggers: key_val = {};
let search_submit_results: any = null; // let search_submit_results: any = null;
onMount(() => { onMount(() => {
console.log('** AE IDAA Mounted: ** Query - Recovery Meeting (Event) Obj'); console.log('** AE IDAA Mounted: ** Query - Recovery Meeting (Event) Obj');
@@ -32,157 +32,158 @@ if ($idaa_loc.recovery_meetings.qry__fulltext_str && $idaa_loc.recovery_meetings
// Updated 2024-10-01 // Updated 2024-10-01
$: if (ae_trigger == 'load__event_obj_li') { // $: if (ae_trigger == 'load__event_obj_li') {
if (log_lvl) { // if (log_lvl) {
console.log('*** TEST SEARCH - load__event_obj_li == load__event_obj_li ***'); // console.log('*** TEST SEARCH - load__event_obj_li == load__event_obj_li ***');
} // }
ae_trigger = null; // ae_trigger = null;
if ($idaa_sess.recovery_meetings.qry_status == 'loading') { // $idaa_trig.event_li_qry = true;
console.log('*** $idaa_sess.recovery_meetings.qry_status == loading ***'); // if ($idaa_sess.recovery_meetings.qry_status == 'loading') {
// console.log('*** $idaa_sess.recovery_meetings.qry_status == loading ***');
setTimeout(() => { // setTimeout(() => {
console.log("Delayed for X second."); // console.log("Delayed for X second.");
// ae_trigger = null; // // ae_trigger = null;
// handle_qry__event({ft_qry_str: $idaa_loc.recovery_meetings.qry__fulltext_str}); // // handle_qry__event({ft_qry_str: $idaa_loc.recovery_meetings.qry__fulltext_str});
$idaa_trig.event_li_qry = true; // $idaa_trig.event_li_qry = true;
}, 250); // }, 250);
} else { // } else {
console.log('*** $idaa_sess.recovery_meetings.qry_status != loading ***'); // console.log('*** $idaa_sess.recovery_meetings.qry_status != loading ***');
// ae_trigger = null; // // ae_trigger = null;
// handle_qry__event({ft_qry_str: $idaa_loc.recovery_meetings.qry__fulltext_str}); // // handle_qry__event({ft_qry_str: $idaa_loc.recovery_meetings.qry__fulltext_str});
$idaa_trig.event_li_qry = true; // $idaa_trig.event_li_qry = true;
} // }
} // }
async function handle_qry__event( // async function handle_qry__event(
{ // {
ft_qry_str = '', // ft_qry_str = '',
and_physical = $idaa_loc.recovery_meetings.qry__physical, // and_physical = $idaa_loc.recovery_meetings.qry__physical,
and_virtual = $idaa_loc.recovery_meetings.qry__virtual, // and_virtual = $idaa_loc.recovery_meetings.qry__virtual,
and_type = $idaa_loc.recovery_meetings.qry__type, // and_type = $idaa_loc.recovery_meetings.qry__type,
order_by_li = $idaa_loc.recovery_meetings.qry__order_by_li, // order_by_li = $idaa_loc.recovery_meetings.qry__order_by_li,
search_delay = 0, // search_delay = 0,
max_tries = 5, // max_tries = 5,
params = { // params = {
'qry__enabled': $idaa_loc.recovery_meetings.qry__enabled ?? 'enabled', // 'qry__enabled': $idaa_loc.recovery_meetings.qry__enabled ?? 'enabled',
'qry__hidden': $idaa_loc.recovery_meetings.qry__hidden ?? 'not_hidden', // 'qry__hidden': $idaa_loc.recovery_meetings.qry__hidden ?? 'not_hidden',
'qry__limit': $idaa_loc.recovery_meetings.qry__limit ?? 35, // 'qry__limit': $idaa_loc.recovery_meetings.qry__limit ?? 35,
}, // },
try_cache = true, // try_cache = true,
log_lvl = 1, // log_lvl = 1,
}: { // }: {
ft_qry_str?: string, // ft_qry_str?: string,
and_physical?: null|boolean, // and_physical?: null|boolean,
and_virtual?: null|boolean, // and_virtual?: null|boolean,
and_type?: null|string, // and_type?: null|string,
order_by_li?: key_val, // order_by_li?: key_val,
search_delay?: number, // In milliseconds // search_delay?: number, // In milliseconds
max_tries?: number, // max_tries?: number,
params?: key_val, // params?: key_val,
try_cache?: boolean, // try_cache?: boolean,
log_lvl?: number, // log_lvl?: number,
} // }
) { // ) {
console.log('handle_qry__event()'); // console.log('handle_qry__event()');
if ($idaa_sess.recovery_meetings?.qry__status != null && $idaa_sess.recovery_meetings?.qry__status != 'done') { // if ($idaa_sess.recovery_meetings?.qry__status != null && $idaa_sess.recovery_meetings?.qry__status != 'done') {
console.log('*** TEST SEARCH - $idaa_sess.recovery_meetings.qry__status != done ***'); // console.log('*** TEST SEARCH - $idaa_sess.recovery_meetings.qry__status != done ***');
// WARNING: This is a temporary fix for the search string. It needs to be fixed in the future. Using lk_search_str for now. // // WARNING: This is a temporary fix for the search string. It needs to be fixed in the future. Using lk_search_str for now.
$idaa_sess.recovery_meetings.status_qry__last_request_str = ft_qry_str; // $idaa_sess.recovery_meetings.status_qry__last_request_str = ft_qry_str;
// We want to delay the initial search request to give the previous search request to finish. // // We want to delay the initial search request to give the previous search request to finish.
let random_delay = Math.floor(Math.random() * 50); // let random_delay = Math.floor(Math.random() * 50);
search_delay += 50+random_delay; // search_delay += 50+random_delay;
} // }
log_lvl = 1; // log_lvl = 1;
let count = 0; // let count = 0;
let request_loop = setInterval(() => { // let request_loop = setInterval(() => {
count++; // count++;
if (log_lvl) { // if (log_lvl) {
console.log(`*** TEST SEARCH - Search delay: ${search_delay} *** loop count=${count}`); // console.log(`*** TEST SEARCH - Search delay: ${search_delay} *** loop count=${count}`);
} // }
if (count >= max_tries) { // if (count >= max_tries) {
console.log('*** TEST SEARCH - Max tries reached ***'); // console.log('*** TEST SEARCH - Max tries reached ***');
clearInterval(request_loop); // clearInterval(request_loop);
} // }
if ($idaa_sess.recovery_meetings?.qry__status != null && $idaa_sess.recovery_meetings?.qry__status != 'done') { // if ($idaa_sess.recovery_meetings?.qry__status != null && $idaa_sess.recovery_meetings?.qry__status != 'done') {
let random_delay = Math.floor(Math.random() * 25); // let random_delay = Math.floor(Math.random() * 25);
search_delay += 25+random_delay; // search_delay += 25+random_delay;
console.log(`*** TEST SEARCH - $idaa_sess.recovery_meetings.qry__status == loading wait *** search_delay=${search_delay}`); // console.log(`*** TEST SEARCH - $idaa_sess.recovery_meetings.qry__status == loading wait *** search_delay=${search_delay}`);
// $idaa_sess.status_qry__last_request_str = ft_qry_str; // // $idaa_sess.status_qry__last_request_str = ft_qry_str;
} else { // } else {
console.log('*** TEST SEARCH - $idaa_sess.recovery_meetings.qry__status != loading ***'); // console.log('*** TEST SEARCH - $idaa_sess.recovery_meetings.qry__status != loading ***');
$idaa_sess.recovery_meetings.qry__status = 'loading'; // $idaa_sess.recovery_meetings.qry__status = 'loading';
(and_physical) ?? null; // (and_physical) ?? null;
(and_virtual) ?? null; // (and_virtual) ?? null;
(and_type) ?? null; // (and_type) ?? null;
// if (and_type) and_type = and_type; // // if (and_type) and_type = and_type;
// if (!and_type) { // // if (!and_type) {
// and_type = null; // // and_type = null;
// } // // }
console.log(`TEST - and_physical: ${and_physical}; and_virtual: ${and_virtual}; and_type: ${and_type}; ft_qry_str: ${ft_qry_str}; params:`, params); // console.log(`TEST - and_physical: ${and_physical}; and_virtual: ${and_virtual}; and_type: ${and_type}; ft_qry_str: ${ft_qry_str}; params:`, params);
// search_submit_results = events_func.qry_ae_obj_li__event({ // // search_submit_results = events_func.qry_ae_obj_li__event({
// api_cfg: $ae_api, // // api_cfg: $ae_api,
// for_obj_type: 'account', // // for_obj_type: 'account',
// for_obj_id: $ae_loc.account_id, // // for_obj_id: $ae_loc.account_id,
// order_by_li: order_by_li, // // order_by_li: order_by_li,
// qry_conference: false, // // qry_conference: false,
// qry_physical: and_physical, // // qry_physical: and_physical,
// qry_virtual: and_virtual, // // qry_virtual: and_virtual,
// qry_type: and_type, // // qry_type: and_type,
// qry_str: ft_qry_str, // // qry_str: ft_qry_str,
// params: params, // // params: params,
// try_cache: try_cache, // // try_cache: try_cache,
// log_lvl: log_lvl, // // log_lvl: log_lvl,
// }) // // })
// .then(function (search_results) { // // .then(function (search_results) {
// // Processing the results from the search. // // // Processing the results from the search.
// $idaa_sess.recovery_meetings.qry__status = 'processing'; // // $idaa_sess.recovery_meetings.qry__status = 'processing';
// $idaa_slct.event_obj_li = search_results; // // $idaa_slct.event_obj_li = search_results;
// console.log(search_results); // // console.log(search_results);
// // $idaa_sess.recovery_meetings.qry__status = 'done'; // // // $idaa_sess.recovery_meetings.qry__status = 'done';
// if (log_lvl) { // // if (log_lvl) {
// console.log('TEST SEARCH - Search done. Pulling out the event_id_randoms.'); // // console.log('TEST SEARCH - Search done. Pulling out the event_id_randoms.');
// } // // }
// // console.log(`TEST search: ${$lq_kv__event_obj_li}`); // // // console.log(`TEST search: ${$lq_kv__event_obj_li}`);
// // event_id_random_li = []; // // // event_id_random_li = [];
// // We need to loop through the array of objects and get the event_id_random from each object a new list of event_id_randoms. Then we can use this list to get the full objects from the database. // // // We need to loop through the array of objects and get the event_id_random from each object a new list of event_id_randoms. Then we can use this list to get the full objects from the database.
// let tmp_li = []; // This is to prevent the array from constantly updating and triggering the liveQuery. // // let tmp_li = []; // This is to prevent the array from constantly updating and triggering the liveQuery.
// if (search_results && search_results.length) { // // if (search_results && search_results.length) {
// for (let i = 0; i < search_results.length; i++) { // // for (let i = 0; i < search_results.length; i++) {
// tmp_li.push($idaa_slct.event_obj_li[i].event_id_random); // // tmp_li.push($idaa_slct.event_obj_li[i].event_id_random);
// } // // }
// } // // }
// event_id_random_li = tmp_li; // // event_id_random_li = tmp_li;
// }) // // })
// .finally(() => { // // .finally(() => {
// // event_id_random_li = $idaa_slct.event_obj_li.map(session_obj => session_obj.event_id_random); // // // event_id_random_li = $idaa_slct.event_obj_li.map(session_obj => session_obj.event_id_random);
// // Finally done with the search. // // // Finally done with the search.
// $idaa_sess.recovery_meetings.qry__status = 'done'; // // $idaa_sess.recovery_meetings.qry__status = 'done';
// if (log_lvl > 1) { // // if (log_lvl > 1) {
// console.log(`TEST SEARCH - event_id_random_li:`, event_id_random_li); // // console.log(`TEST SEARCH - event_id_random_li:`, event_id_random_li);
// // console.log(`TEST SEARCH - search live query: ${$lq_kv__event_obj_li}`); // // // console.log(`TEST SEARCH - search live query: ${$lq_kv__event_obj_li}`);
// } // // }
// }); // // });
clearInterval(request_loop); // clearInterval(request_loop);
} // }
}, search_delay); // }, search_delay);
} // }
</script> </script>