More general clean up. Making event queries easier to use and understand.

This commit is contained in:
Scott Idem
2024-10-01 16:59:08 -04:00
parent 47e9f9f5a1
commit fad58bf26f
5 changed files with 175 additions and 50 deletions

View File

@@ -7,7 +7,7 @@ let ae_promises: key_val = {};
// Updated 2024-09-25
export async function handle_load_ae_obj_id__event(
export async function load_ae_obj_id__event(
{
api_cfg,
event_id,
@@ -30,7 +30,7 @@ export async function handle_load_ae_obj_id__event(
log_lvl?: number
}
) {
console.log(`*** handle_load_ae_obj_id__event() *** event_id=${event_id}`);
console.log(`*** load_ae_obj_id__event() *** event_id=${event_id}`);
let params = {};
@@ -48,7 +48,7 @@ export async function handle_load_ae_obj_id__event(
if (event_obj_get_result) {
if (try_cache) {
// This is expecting a list
handle_db_save_ae_obj_li__event({
db_save_ae_obj_li__event({
obj_type: 'event',
obj_li: [event_obj_get_result]
});
@@ -88,7 +88,7 @@ export async function load_ae_obj_li__event(
api_cfg: any,
for_obj_type: string,
for_obj_id: string,
qry_conference?: boolean,
qry_conference?: null|boolean,
qry_str?: null|string,
inc_file_li?: boolean,
inc_location_li?: boolean,
@@ -164,7 +164,7 @@ export async function load_ae_obj_li__event(
.then(function (event_obj_li_get_result) {
if (event_obj_li_get_result) {
if (try_cache) {
handle_db_save_ae_obj_li__event({obj_type: 'event', obj_li: event_obj_li_get_result});
db_save_ae_obj_li__event({obj_type: 'event', obj_li: event_obj_li_get_result});
}
return event_obj_li_get_result;
} else {
@@ -182,6 +182,116 @@ export async function load_ae_obj_li__event(
}
// The qry_ae_obj_li__event() is essentially a wrapper for the load_ae_obj_li__event() function. This should process the query strings and related before calling the load_ae_obj_li__event() function.
// Updated 2024-10-01
export async function qry_ae_obj_li__event(
{
api_cfg,
for_obj_type = 'account',
for_obj_id,
qry_conference = true,
qry_virtual = null,
qry_physical = null,
qry_type = null,
qry_str = null,
inc_file_li = false,
inc_location_li = false,
inc_presentation_li = false,
inc_presenter_li = false,
inc_session_li = false,
order_by_li = {'start_datetime': 'DESC', 'name': 'ASC', 'updated_on': 'DESC', 'created_on': 'DESC'},
params = {},
try_cache = true,
log_lvl = 0
}: {
api_cfg: any,
for_obj_type: string,
for_obj_id: string,
qry_conference?: null|boolean,
qry_virtual?: null|boolean,
qry_physical?: null|boolean,
qry_type?: null|string,
qry_str?: null|string,
inc_file_li?: boolean,
inc_location_li?: boolean,
inc_presentation_li?: boolean,
inc_presenter_li?: boolean,
inc_session_li?: boolean,
order_by_li?: key_val,
params?: key_val,
try_cache?: boolean,
log_lvl?: number
}
) {
console.log(`*** qry_ae_obj_li__event() *** for_obj_id=${for_obj_id}`);
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
let params_json: key_val = {};
params_json['and_qry'] = {};
if (qry_conference) {
params_json['and_qry']['conference'] = qry_conference;
} else if (qry_conference === false) {
console.log('qry_conference is false!');
params_json['and_qry']['conference'] = qry_conference;
}
if (qry_virtual) {
params_json['and_qry']['virtual'] = qry_virtual;
} else if (qry_virtual === false) {
console.log('qry_virtual is false!');
params_json['and_qry']['virtual'] = qry_virtual;
}
if (qry_physical) {
params_json['and_qry']['physical'] = qry_physical;
} else if (qry_physical === false) {
console.log('qry_physical is false!');
params_json['and_qry']['physical'] = qry_physical;
}
if (qry_type) {
params_json['and_qry']['type'] = qry_type;
}
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;
}
if (log_lvl) {
console.log('params_json:', params_json);
}
ae_promises.qry__event_obj_li = await load_ae_obj_li__event({
api_cfg: api_cfg,
for_obj_type: for_obj_type,
for_obj_id: for_obj_id,
qry_conference: qry_conference,
qry_str: qry_str,
inc_file_li: inc_file_li,
inc_location_li: inc_location_li,
inc_presentation_li: inc_presentation_li,
inc_presenter_li: inc_presenter_li,
inc_session_li: inc_session_li,
order_by_li: order_by_li,
params: params,
try_cache: try_cache,
log_lvl: log_lvl
});
return ae_promises.qry__event_obj_li;
}
// Updated 2024-09-25
export async function create_ae_obj__event(
{
@@ -214,7 +324,7 @@ export async function create_ae_obj__event(
})
.then(function (event_obj_create_result) {
if (event_obj_create_result) {
handle_db_save_ae_obj_li__event(
db_save_ae_obj_li__event(
{
obj_type: 'event',
obj_li: [event_obj_create_result]
@@ -272,7 +382,7 @@ export async function update_ae_obj__event(
.then(function (event_obj_update_result) {
if (event_obj_update_result) {
if (try_cache) {
handle_db_save_ae_obj_li__event({
db_save_ae_obj_li__event({
obj_type: 'event', obj_li: [event_obj_update_result]
});
}
@@ -295,7 +405,7 @@ export async function update_ae_obj__event(
// This function will loop through the event_obj_li and save each one to the DB.
export function handle_db_save_ae_obj_li__event(
export function db_save_ae_obj_li__event(
{
obj_type,
obj_li,
@@ -307,7 +417,7 @@ export function handle_db_save_ae_obj_li__event(
}
) {
if (log_lvl) {
console.log(`*** handle_db_save_ae_obj_li__event() ***`);
console.log(`*** db_save_ae_obj_li__event() ***`);
}
if (obj_li && obj_li.length) {

View File

@@ -1,13 +1,7 @@
// This file is used to export all the functions that are used for Aether Events related functions.
import {
handle_load_ae_obj_id__event,
load_ae_obj_li__event,
create_ae_obj__event,
update_ae_obj__event,
handle_db_save_ae_obj_li__event,
sync_config__event_pres_mgmt,
} from "$lib/ae_events__event";
// Import all the functions from this library:
import * as events from "$lib/ae_events__event";
import {
handle_load_ae_obj_id__event_file,
@@ -77,12 +71,12 @@ import {
let export_obj = {
handle_load_ae_obj_id__event: handle_load_ae_obj_id__event,
load_ae_obj_li__event: load_ae_obj_li__event,
create_ae_obj__event: create_ae_obj__event,
update_ae_obj__event: update_ae_obj__event,
handle_db_save_ae_obj_li__event: handle_db_save_ae_obj_li__event,
sync_config__event_pres_mgmt: sync_config__event_pres_mgmt,
handle_load_ae_obj_id__event: events.load_ae_obj_id__event,
load_ae_obj_li__event: events.load_ae_obj_li__event,
create_ae_obj__event: events.create_ae_obj__event,
update_ae_obj__event: events.update_ae_obj__event,
handle_db_save_ae_obj_li__event: events.db_save_ae_obj_li__event,
sync_config__event_pres_mgmt: events.sync_config__event_pres_mgmt,
handle_load_ae_obj_id__event_file: handle_load_ae_obj_id__event_file,
handle_load_ae_obj_li__event_file: handle_load_ae_obj_li__event_file,

View File

@@ -53,10 +53,15 @@ let idaa_local_data_struct: key_val = {
},
recovery_meetings: {
enabled: 'enabled', // all, disabled, enabled
hidden: 'not_hidden', // all, hidden, not_hidden
limit: 150,
offset: 0,
qry__enabled: 'enabled', // all, disabled, enabled
qry__hidden: 'not_hidden', // all, hidden, not_hidden
qry__limit: 150,
qry__offset: 0,
qry__fulltext_str: null,
qry__physical: null,
qry__type: null,
qry__virtual: null,
},
};
// console.log(`AE Stores - App IDAA Local Storage Data:`, idaa_local_data_struct);
@@ -87,7 +92,7 @@ let idaa_session_data_struct: key_val = {
recovery_meetings: {
qry__status: null,
qry__fulltext_str: null,
// qry__fulltext_str: null,
},
};

View File

@@ -5,7 +5,7 @@ import { onMount } from 'svelte';
import type { key_val } from '$lib/ae_stores';
// import { api, Element_obj_tbl_row } from 'aether_npm_lib';
import Element_obj_tbl_row from '$lib/element_obj_tbl_row.svelte';
import { post_object } from '$lib/api_post_object';
import { post_object } from '$lib/ae_api/api_post_object';
// *** Import Aether core components
// import Element_obj_tbl_row from './element_obj_tbl_row.svelte';

View File

@@ -1,7 +1,7 @@
<script lang="ts">
// *** Import Svelte core
import { onMount } from 'svelte';
import { Spinner } from 'flowbite-svelte';
// import { Spinner } from 'flowbite-svelte';
// *** Import Aether core variables and functions
import type { key_val } from '$lib/ae_stores';
@@ -57,9 +57,9 @@ async function handle_search__event(
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 ?? 35,
'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 ?? 35,
},
try_cache=false,
log_lvl=1,
@@ -223,41 +223,57 @@ async function handle_search__event(
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
<!-- <span class="fas fa-search m-1"></span> -->
{#if $idaa_sess.recovery_meetings.qry__status == 'loading'}
<span class="fas fa-spinner fa-spin m-1"></span>
{:else}
<span class="fas fa-search m-1"></span>
<!-- {#if $idaa_sess.recovery_meetings.qry__status == 'done'}
<span class="fas fa-check m-1"></span>
{/if} -->
{/if}
Search
</button>
</div>
<fieldset class="flex flex-row gap-1 w-full">
<legend>Location?</legend>
<fieldset class="flex flex-row gap-1 w-full items-center justify-center">
<div class="legend inline-block">
Location?</div>
<!-- <div class="ae_row ae_flex_justify_around ae_width_md"> -->
<label>Virtual
<label class="inline-block flex flex-row gap-1 items-center justify-center">
Virtual
<input
name="qry_virtual"
type="checkbox"
bind:checked={$idaa_loc.recovery_meetings.qry_virtual}
bind:checked={$idaa_loc.recovery_meetings.qry__virtual}
on:change={() => {ae_trigger = 'load__event_obj_li';}}
class="checkbox"
>
</label>
<label>In-person
<label class="inline-block flex flex-row gap-1 items-center justify-center">
In-person
<input
name="qry_physical"
type="checkbox"
bind:checked={$idaa_loc.recovery_meetings.qry_physical}
bind:checked={$idaa_loc.recovery_meetings.qry__physical}
on:change={() => {ae_trigger = 'load__event_obj_li';}}
class="checkbox"
>
</label>
<!-- </div> -->
</fieldset>
<fieldset class="flex flex-row gap-1 w-full">
<legend>Type?</legend>
<fieldset class="flex flex-row gap-1 w-full items-center justify-center">
<div class="legend inline-block">
Type?
</div>
<!-- <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}
bind:group={$idaa_loc.recovery_meetings.qry__type}
on:change={() => {ae_trigger = 'load__event_obj_li';}}
title="Show all meeting types"
>
@@ -267,7 +283,7 @@ async function handle_search__event(
name="qry_type"
type="radio"
value="IDAA"
bind:group={$idaa_loc.recovery_meetings.qry_type}
bind:group={$idaa_loc.recovery_meetings.qry__type}
on:change={() => {ae_trigger = 'load__event_obj_li';}}
title="Open to IDAA members only"
>
@@ -277,7 +293,7 @@ async function handle_search__event(
name="qry_type"
type="radio"
value="Caduceus"
bind:group={$idaa_loc.recovery_meetings.qry_type}
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"
>
@@ -287,7 +303,7 @@ async function handle_search__event(
name="qry_type"
type="radio"
value="Family Recovery"
bind:group={$idaa_loc.recovery_meetings.qry_type}
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."
>
@@ -298,7 +314,7 @@ async function handle_search__event(
name="qry_type"
type="radio"
value="Al-Anon"
bind:group={$idaa_loc.recovery_meetings.qry_type}
bind:group={$idaa_loc.recovery_meetings.qry__type}
on:change={() => {ae_trigger = 'load__event_obj_li';}}
>
</label>
@@ -307,7 +323,7 @@ async function handle_search__event(
name="qry_type"
type="radio"
value="Other"
bind:group={$idaa_loc.recovery_meetings.qry_type}
bind:group={$idaa_loc.recovery_meetings.qry__type}
on:change={() => {ae_trigger = 'load__event_obj_li';}}
>
</label>
@@ -336,7 +352,7 @@ async function handle_search__event(
</label>
<select
id="qry_limit__events"
bind:value={$idaa_loc.recovery_meetings.qry_limit}
bind:value={$idaa_loc.recovery_meetings.qry__limit}
on:change={() => {
// search__event_presenter({
// api_cfg: $ae_api,
@@ -348,7 +364,7 @@ async function handle_search__event(
// params: {
// 'qry__enabled': 'enabled',
// 'qry__hidden': 'not_hidden',
// 'qry__limit': $idaa_loc.recovery_meetings.qry_limit__events,},
// 'qry__limit': $idaa_loc.recovery_meetings.qry__limit__events,},
// try_cache: false,
// log_lvl: log_lvl,
// });