The event search now mostly works.

This commit is contained in:
Scott Idem
2024-10-01 13:36:50 -04:00
parent d7284d5010
commit cca43b957a
4 changed files with 482 additions and 10 deletions

View File

@@ -74,6 +74,7 @@ export async function load_ae_obj_li__event(
for_obj_type = 'account',
for_obj_id,
qry_conference = true,
qry_str = null,
inc_file_li = false,
inc_location_li = false,
inc_presentation_li = false,
@@ -88,6 +89,7 @@ export async function load_ae_obj_li__event(
for_obj_type: string,
for_obj_id: string,
qry_conference?: boolean,
qry_str?: null|string,
inc_file_li?: boolean,
inc_location_li?: boolean,
inc_presentation_li?: boolean,
@@ -113,6 +115,15 @@ export async function load_ae_obj_li__event(
if (qry_conference) {
params_json['and_qry']['conference'] = qry_conference;
} else if (qry_conference === false) {
params_json['and_qry']['conference'] = qry_conference;
}
if (qry_str) {
params_json['ft_qry'] = {};
params_json['ft_qry']['default_qry_str'] = qry_str;
params_json['ft_qry']['location_address_json_ext'] = qry_str;
params_json['ft_qry']['contact_li_json_ext'] = qry_str;
}
// console.log('params_json:', params_json);

View File

@@ -3,6 +3,7 @@ import { writable } from 'svelte/store';
import type { Writable } from 'svelte/store';
import type { key_val } from '$lib/ae_stores';
import { offset } from '@floating-ui/dom';
// Set the version for the app data. Changing this should force a notification and ask the user to clear and reload the page.
let ver = '2024-08-21_1646';
@@ -37,15 +38,25 @@ let idaa_local_data_struct: key_val = {
'qry__offset': 0,
archives: {
enabled: 'enabled', // all, disabled, enabled
hidden: 'not_hidden', // all, hidden, not_hidden
limit: 150,
offset: 0,
},
bb: {
enabled: 'enabled', // all, disabled, enabled
hidden: 'not_hidden', // all, hidden, not_hidden
limit: 150,
offset: 0,
show_list__post_obj_li: true,
},
recovery_meetings: {
enabled: 'enabled', // all, disabled, enabled
hidden: 'not_hidden', // all, hidden, not_hidden
limit: 150,
offset: 0,
},
};
// console.log(`AE Stores - App IDAA Local Storage Data:`, idaa_local_data_struct);
@@ -67,15 +78,16 @@ let idaa_session_data_struct: key_val = {
log_lvl: 1,
archives: {
qry__status: null,
},
bb: {
qry__status: null,
},
recovery_meetings: {
qry__status: null,
qry__fulltext_str: null,
},
};

View File

@@ -19,12 +19,13 @@ import { liveQuery } from "dexie";
import { core_func } from '$lib/ae_core_functions';
import { db_events } from "$lib/db_events";
import { ae_snip, ae_loc, ae_sess, ae_api, ae_trig, slct, slct_trigger } from '$lib/ae_stores';
import { events_loc, events_sess, events_slct, events_trigger } from '$lib/ae_events_stores';
import { events_func } from '$lib/ae_events_functions';
// import { events_func } from '$lib/ae_events_functions';
import Comp__event_obj_qry from './ae_idaa_comp__event_obj_qry.svelte';
import Comp__event_obj_li from './ae_idaa_comp__event_obj_li.svelte';
import Comp__event_obj_id_view from './ae_idaa_comp__event_obj_id_view.svelte';
let event_id_random_li: Array<string>;
$: lq__event_obj_li = liveQuery(async () => {
let results = await db_events.events
@@ -42,6 +43,54 @@ $: lq__event_obj = liveQuery(async () => {
return results;
});
// Functions and Logic
$: lq_new__event_obj_li = liveQuery(async () => {
console.log('Trying... HERE!!! BEGIN');
let link_to_type: string = 'account';
let link_to_id: string = $slct.account_id;
console.log(`link_to_type: ${link_to_type}; link_to_id: ${link_to_id}`);
if (event_id_random_li?.length) {
console.log(`Trying bulkGet:`, event_id_random_li);
let results = await db_events.events
.bulkGet(event_id_random_li);
return results;
} else if (link_to_type && link_to_id) {
console.log(`Trying where: ${link_to_type}; equals: ${link_to_id}`);
let results = await db_events.events
.where(`${link_to_type}_id`)
.equals(link_to_id)
.sortBy('name')
return results;
} else {
console.log('Trying... Nothing to load');
return null;
}
console.log('Trying... HERE!!! END');
});
$: lq_bulk__event_obj_li = liveQuery(async () => {
console.log('Trying... HERE!!! BULK BEGIN');
if (event_id_random_li.length) {
console.log(`Trying bulkGet:`, event_id_random_li);
let results = await db_events.events
.bulkGet(event_id_random_li);
return results;
} else {
console.log('Trying... Nothing to load');
return null;
}
console.log('Trying... HERE!!! BULK END');
});
</script>
@@ -57,11 +106,17 @@ $: lq__event_obj = liveQuery(async () => {
"
>
<Comp__event_obj_qry
bind:event_id_random_li={event_id_random_li}
/>
<h1>Recovery Meetings {$lq__event_obj_li?.length}</h1>
{#if $lq__event_obj_li && $lq__event_obj_li?.length }
<h1>Recovery Meetings {$lq_new__event_obj_li?.length}</h1>
<!-- Search results: {$lq_bulk__event_obj_li?.length}? -->
{#if $lq_new__event_obj_li && $lq_new__event_obj_li?.length }
<Comp__event_obj_li
lq__event_obj_li={lq__event_obj_li}
lq__event_obj_li={lq_new__event_obj_li}
/>
{/if}

View File

@@ -0,0 +1,394 @@
<script lang="ts">
// *** Import Svelte core
import { onMount } from 'svelte';
import { Spinner } from 'flowbite-svelte';
// *** Import Aether core variables and functions
import type { key_val } from '$lib/ae_stores';
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 { idaa_loc, idaa_sess, idaa_slct } from '$lib/ae_idaa_stores';
import { events_func } from '$lib/ae_events_functions';
export let log_lvl = 1;
export let event_id_random_li: Array<string>;
// export let container_class_li = [];
let ae_tmp: key_val = {};
let ae_trigger: any = null;
let ae_triggers: key_val = {};
let search_submit_results: any = null;
onMount(() => {
console.log('** AE IDAA Mounted: ** Query - Recovery Meeting (Event) Obj');
});
// Updated 2024-10-01
$: if (ae_trigger == 'load__event_obj_li') {
if (log_lvl) {
console.log('*** TEST SEARCH - load__event_obj_li == load__event_obj_li ***');
}
ae_trigger = null;
if ($idaa_sess.recovery_meetings.qry_status == 'loading') {
console.log('*** $idaa_sess.recovery_meetings.qry_status == loading ***');
setTimeout(() => {
console.log("Delayed for X second.");
// ae_trigger = null;
handle_search__event({lk_search_str: $idaa_loc.recovery_meetings.qry__fulltext_str});
}, 250);
} else {
console.log('*** $idaa_sess.recovery_meetings.qry_status != loading ***');
// ae_trigger = null;
handle_search__event({lk_search_str: $idaa_loc.recovery_meetings.qry__fulltext_str});
}
}
async function handle_search__event(
{
ft_search_str = '',
lk_search_str = '',
and_lk_location_name = '',
search_delay = 0,
max_tries = 5,
params = {
'qry__enabled': $idaa_loc.recovery_meetings.qry_enabled ?? 'enabled',
'qry__hidden': $idaa_loc.recovery_meetings.qry_hidden ?? 'not_hidden',
'qry__limit': $idaa_loc.recovery_meetings.qry_limit__events ?? 35,
},
try_cache=false,
log_lvl=1,
}: {
ft_search_str?: string,
lk_search_str?: string,
and_lk_location_name?: string,
search_delay?: number, // In milliseconds
max_tries?: number,
params?: key_val,
try_cache?: boolean,
log_lvl?: number,
}
) {
console.log('handle_search__event()');
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 ***');
// 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 = lk_search_str;
// We want to delay the initial search request to give the previous search request to finish.
let random_delay = Math.floor(Math.random() * 50);
search_delay += 50+random_delay;
}
log_lvl = 2;
let count = 0;
let request_loop = setInterval(() => {
count++;
if (log_lvl) {
console.log(`*** TEST SEARCH - Search delay: ${search_delay} *** loop count=${count}`);
}
if (count >= max_tries) {
console.log('*** TEST SEARCH - Max tries reached ***');
clearInterval(request_loop);
}
if ($idaa_sess.recovery_meetings?.qry__status != null && $idaa_sess.recovery_meetings?.qry__status != 'done') {
let random_delay = Math.floor(Math.random() * 25);
search_delay += 25+random_delay;
console.log(`*** TEST SEARCH - $idaa_sess.recovery_meetings.qry__status == loading wait *** search_delay=${search_delay}`);
// $idaa_sess.status_qry__last_request_str = lk_search_str;
} else {
console.log('*** TEST SEARCH - $idaa_sess.recovery_meetings.qry__status != loading ***');
$idaa_sess.recovery_meetings.qry__status = 'loading';
search_submit_results = events_func.load_ae_obj_li__event({
api_cfg: $ae_api,
for_obj_type: 'account',
for_obj_id: $ae_loc.account_id,
qry_conference: false,
qry_str: lk_search_str,
// type_code: type_code,
// qry__fulltext_str: ft_search_str,
// ft_presenter_search_qry_str: null,
// like_search_qry_str: lk_search_str,
// like_presentation_search_qry_str: lk_search_str,
// like_presenter_search_qry_str: lk_search_str,
// external_event_id: $idaa_loc.recovery_meetings.default__external_registration_id,
// location_name: and_lk_location_name,
params: params,
try_cache: try_cache,
log_lvl: 0,
})
.then(function (search_results) {
// Processing the results from the search.
$idaa_sess.recovery_meetings.qry__status = 'processing';
$idaa_slct.event_obj_li = search_results;
console.log(search_results);
// $idaa_sess.recovery_meetings.qry__status = 'done';
if (log_lvl) {
console.log('TEST SEARCH - Search done. Pulling out the event_id_randoms.');
}
// console.log(`TEST search: ${$lq_kv__event_obj_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.
let tmp_li = []; // This is to prevent the array from constantly updating and triggering the liveQuery.
if (search_results && search_results.length) {
for (let i = 0; i < search_results.length; i++) {
tmp_li.push($idaa_slct.event_obj_li[i].event_id_random);
}
}
event_id_random_li = tmp_li;
})
.finally(() => {
// event_id_random_li = $idaa_slct.event_obj_li.map(session_obj => session_obj.event_id_random);
// Finally done with the search.
$idaa_sess.recovery_meetings.qry__status = 'done';
if (log_lvl > 1) {
console.log(`TEST SEARCH - event_id_random_li:`, event_id_random_li);
// console.log(`TEST SEARCH - search live query: ${$lq_kv__event_obj_li}`);
}
});
clearInterval(request_loop);
}
}, search_delay);
}
</script>
<section class="ae_section ae_options filters_and_search flex flex-col gap-1 variant-ghost-success my-2 p-2 border rounded-md items-center justify-center">
<!-- <div class="ae_info recovery_meetings_info note">
{@html $idaa_loc.recovery_meetings.ds.recovery_meetings_info}
</div> -->
<!-- <div class="note">Note: The state/province filter only includes states and provinces that are set for at least one meeting. Many virtual/online meetings do not have a state/province set. Some in-person meetings also do not have a state/province set. Please ask one of the meeting contacts to update this information if it is missing.</div> -->
<form
on:submit|preventDefault={() => {
ae_trigger = 'load__event_obj_li';
}}
class="search_form flex flex-col gap-1 w-full"
>
<!-- <div class="ae_group">
<input
type="search"
placeholder="Search (day of week, location, time, chair, etc.)"
name="qry__fulltext_str"
on:keyup={handle_oninput_qry__fulltext_str}
bind:value={$idaa_loc.recovery_meetings.qry__fulltext_str}
>
</div> -->
<div class="ae_group flex flex-row w-full items-center justify-center">
<button
type="button"
class="btn btn-sm variant-ghost-warning hover:variant-filled-warning transition-all mx-1"
on:click={() => {
$idaa_loc.recovery_meetings.qry__fulltext_str = '';
ae_trigger = 'load__event_obj_li';
}}
title="Clear search text"
>
<!-- <span class="fas fa-backspace"></span> -->
<!-- <span class="fas fa-broom"></span> -->
<span class="fas fa-remove-format"></span>
<!-- Clear text -->
</button>
<input
type="search"
placeholder="Search (day of week, location, chair, etc.)"
id="meeting_qry__fulltext_str"
name="qry__fulltext_str"
bind:value={$idaa_loc.recovery_meetings.qry__fulltext_str}
style="width: 50%;"
class="bs-input input text-1xl hover:text-2xl font-bold font-mono w-80 transition-all mx-1"
>
<button
type="submit"
class="btn btn-lg variant-ghost-success hover:variant-filled-success text-2xl font-bold w-48 transition-all mx-1"
>
<span class="fas fa-search m-1"></span> Search
</button>
</div>
<fieldset class="flex flex-row gap-1 w-full">
<legend>Location?</legend>
<!-- <div class="ae_row ae_flex_justify_around ae_width_md"> -->
<label>Virtual
<input
name="qry_virtual"
type="checkbox"
bind:checked={$idaa_loc.recovery_meetings.qry_virtual}
on:change={() => {ae_trigger = 'load__event_obj_li';}}
>
</label>
<label>In-person
<input
name="qry_physical"
type="checkbox"
bind:checked={$idaa_loc.recovery_meetings.qry_physical}
on:change={() => {ae_trigger = 'load__event_obj_li';}}
>
</label>
<!-- </div> -->
</fieldset>
<fieldset class="flex flex-row gap-1 w-full">
<legend>Type?</legend>
<!-- <div class="ae_row ae_flex_justify_around ae_width_100"> -->
<label>All
<input
name="qry_type"
type="radio"
value=""
bind:group={$idaa_loc.recovery_meetings.qry_type}
on:change={() => {ae_trigger = 'load__event_obj_li';}}
title="Show all meeting types"
>
</label>
<label>IDAA
<input
name="qry_type"
type="radio"
value="IDAA"
bind:group={$idaa_loc.recovery_meetings.qry_type}
on:change={() => {ae_trigger = 'load__event_obj_li';}}
title="Open to IDAA members only"
>
</label>
<label>Caduceus
<input
name="qry_type"
type="radio"
value="Caduceus"
bind:group={$idaa_loc.recovery_meetings.qry_type}
on:change={() => {ae_trigger = 'load__event_obj_li';}}
title="Open to all healthcare workers including those who do not qualify for IDAA"
>
</label>
<label>Family Recovery
<input
name="qry_type"
type="radio"
value="Family Recovery"
bind:group={$idaa_loc.recovery_meetings.qry_type}
on:change={() => {ae_trigger = 'load__event_obj_li';}}
title="Open to spouses, parents, and children of medical professionals who have substance use disorder."
>
</label>
<!-- {#if $ae_loc.administrator_access}
<label>Al-Anon (old)
<input
name="qry_type"
type="radio"
value="Al-Anon"
bind:group={$idaa_loc.recovery_meetings.qry_type}
on:change={() => {ae_trigger = 'load__event_obj_li';}}
>
</label>
<label>Other (old)
<input
name="qry_type"
type="radio"
value="Other"
bind:group={$idaa_loc.recovery_meetings.qry_type}
on:change={() => {ae_trigger = 'load__event_obj_li';}}
>
</label>
{/if} -->
<!-- </div> -->
</fieldset>
</form>
<!-- {#await idaa_event_obj_li_get_promise}
<div>Loading events...</div>
{:catch error}
<div>Error: {error.message}</div>
{/await} -->
<div class="ae_group ae_row flex flex-row gap-1 w-full items-center justify-center">
{#if $ae_loc.trusted_access && !$idaa_loc.recovery_meetings.hidden}
<button
on:click={() => {
$idaa_loc.recovery_meetings.hidden = 'all';
$idaa_loc.recovery_meetings.limit = 150;
ae_trigger = 'load__event_obj_li';
}}
class="btn_show_bb_post ae_btn btn btn-info btn-sm variant-ghost-secondary"
>
<span class="fas fa-eye m-1"></span> Show Hidden Events
</button>
{:else if $ae_loc.trusted_access && $idaa_loc.recovery_meetings.hidden == 'all'}
<button
on:click={() => {
$idaa_loc.recovery_meetings.hidden = 'not_hidden';
ae_trigger = 'load__event_obj_li';
}}
class="btn_hide_bb_post ae_btn btn btn-info btn-sm variant-ghost-secondary"
>
<span class="fas fa-eye-slash m-1"></span> Hide Hidden Events
</button>
{/if}
{#if $ae_loc.administrator_access && !$idaa_loc.recovery_meetings.enabled}
<button
on:click={() => {
$idaa_loc.recovery_meetings.hidden = 'all';
$idaa_loc.recovery_meetings.enabled = 'all';
$idaa_loc.recovery_meetings.limit = 500;
ae_trigger = 'load__event_obj_li';
}}
class="btn_show_bb_post ae_btn btn btn-warning btn-sm variant-ghost-secondary"
>
<span class="fas fa-eye m-1"></span> Show Disabled Events
</button>
{:else if $ae_loc.administrator_access && $idaa_loc.recovery_meetings.enabled == 'all'}
<button
on:click={() => {
$idaa_loc.recovery_meetings.enabled = 'enabled';
ae_trigger = 'load__event_obj_li';
}}
class="btn_hide_bb_post ae_btn btn btn-warning btn-sm variant-ghost-secondary"
>
<span class="fas fa-eye-slash m-1"></span> Hide Disabled Events
</button>
{/if}
<button
on:click={() => {
$slct.event_id = null;
$slct.event_obj = {};
const url = new URL(location);
url.searchParams.delete('event_id');
history.pushState({}, '', url);
$idaa_loc.recovery_meetings.show_main__options = false;
$idaa_loc.recovery_meetings.show_list__event_obj_li = false;
$idaa_loc.recovery_meetings.show_view__event_obj = false;
$idaa_loc.recovery_meetings.show_edit__event_obj = true;
}}
class="btn_new_recovery_meeting ae_btn btn btn-secondary btn-sm variant-filled-warning"
disabled={true}
>
<span class="fas fa-plus m-1"></span> Create new Meeting
</button>
</div>
</section> <!-- END: div filters_and_search -->