General clean up. Less debug. Things work better?

This commit is contained in:
Scott Idem
2024-03-29 12:15:50 -04:00
parent c0e1d666f4
commit 0e26765312
10 changed files with 181 additions and 95 deletions

View File

@@ -11,8 +11,21 @@ import { api } from '$lib/api';
let ae_promises: key_val = {}; // Promise<any>;
// Updated 2024-03-20
async function handle_load_ae_obj_id__site_domain({ api_cfg, fqdn, try_cache=false }) {
// Updated 2024-03-29
async function handle_load_ae_obj_id__site_domain(
{
api_cfg,
fqdn,
try_cache=false,
log_lvl=0
} : {
api_cfg: any,
fqdn: string,
try_cache: boolean,
log_lvl: number
}
) {
console.log(`*** handle_load_ae_obj_id__site_domain() *** fqdn=${fqdn}`);
let no_account_id = false;
@@ -33,7 +46,7 @@ async function handle_load_ae_obj_id__site_domain({ api_cfg, fqdn, try_cache=fal
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: true, // NOTE: This will use the base_name_alt value instead of the base_name value in the API config.
params: params,
log_lvl: 0
log_lvl: log_lvl
})
.then(function (site_domain_obj_get_result) {
if (site_domain_obj_get_result) {
@@ -56,7 +69,8 @@ async function handle_load_ae_obj_id__site_domain({ api_cfg, fqdn, try_cache=fal
return ae_promises.load__site_domain_obj;
}
// handle_load_ae_obj_code__data_store
// Updated 2024-03-29
async function handle_load_ae_obj_code__data_store(
{
api_cfg,
@@ -65,7 +79,8 @@ async function handle_load_ae_obj_code__data_store(
for_type=null,
for_id=null,
try_cache=true,
save_idb=false
save_idb=false,
log_lvl=0
}: {
api_cfg: any,
code: string,
@@ -73,19 +88,21 @@ async function handle_load_ae_obj_code__data_store(
for_type: string|null,
for_id: string|null,
try_cache: boolean,
save_idb: boolean
save_idb: boolean,
log_lvl: number
}
) {
console.log(`*** handle_get_data_store_obj_w_code() *** code=${code}`);
) {
if (log_lvl) {
console.log(`*** handle_get_data_store_obj_w_code() *** code=${code}`);
}
if (!code) {
console.log('No code provided.');
console.log(`*ae_func* No code provided!`);
return false;
}
if (!api_cfg.account_id) {
console.log('No account_id provided.');
console.log(`*ae_func* No account_id found in API config!`);
return false;
}
@@ -93,15 +110,17 @@ async function handle_load_ae_obj_code__data_store(
api_cfg: api_cfg,
data_store_code: code,
data_type: data_type,
log_lvl: 0
log_lvl: log_lvl
})
.then(function (get_ds_result) {
let return_this = null;
if (get_ds_result) {
console.log(`Got a result for code ${code}`);
if (log_lvl) {
console.log(`*ae_func* Got a result for code ${code}`);
}
if (!get_ds_result.data_store_id_random) {
console.log('Something went wrong? No data store ID found.');
console.log('*ae_func* Something went wrong? No data store ID found.');
return false;
}
@@ -174,28 +193,53 @@ async function handle_load_ae_obj_code__data_store(
if (save_idb) {
if (browser) {
// console.log(`ae_ds__ key: ${code}, value:`, get_ds_result);
localStorage.setItem(`ae_ds__${code}`, JSON.stringify(get_ds_result));
let key_prefix = 'ae_ds__';
if (log_lvl) {
console.log(`*ae_func* localStorage key: ${code}, value:`, get_ds_result);
}
localStorage.setItem(`${key_prefix}${code}`, JSON.stringify(get_ds_result));
} else {
console.log('No browser!!!');
if (log_lvl) {
console.log('*ae_func* No browser! Can not use localStorage to save data store object.');
}
}
}
} else {
console.log('No results returned.');
console.log('*ae_func* No results returned.');
return_this = null;
}
return return_this;
})
.catch(function (error) {
console.log('No results returned or failed.', error);
console.log('*ae_func* No results returned or failed.', error);
});
return ae_promises.load__data_store_obj;
}
async function handle_update_ae_obj_id_crud({api_cfg, object_type, object_id, field_name, new_field_value, params={}, try_cache=false}) {
// Updated 2024-03-27
async function handle_update_ae_obj_id_crud(
{
api_cfg,
object_type,
object_id,
field_name,
new_field_value,
params={},
try_cache=false,
log_lvl=0
}: {
api_cfg: any,
object_type: string,
object_id: string,
field_name: string,
new_field_value: any,
params: key_val,
try_cache: boolean,
log_lvl: number
}) {
let patch_result: any = null;
@@ -210,7 +254,7 @@ async function handle_update_ae_obj_id_crud({api_cfg, object_type, object_id, fi
// jwt: null,
// params: params,
// data: patch_data,
log_lvl: 2
log_lvl: log_lvl
})
.then(function (results) {
console.log('PATCH Promise', results);
@@ -223,17 +267,6 @@ async function handle_update_ae_obj_id_crud({api_cfg, object_type, object_id, fi
patch_result = 'PATCH failed';
return false;
}
// dispatch(
// 'ae_crud_updated',
// {
// 'type': object_type,
// 'id': object_id,
// 'field_name': field_name,
// 'field_value': new_field_value,
// 'original_value': original_field_value,
// }
// );
return true;
})
.catch(function (error) {

View File

@@ -85,7 +85,7 @@ let events_local_data_struct: key_val = {
// other
}
console.log(`AE Stores - App Events Local Storage Data:`, events_local_data_struct);
// console.log(`AE Stores - App Events Local Storage Data:`, events_local_data_struct);
// This works, but does not uses local storage:
// export let ae_loc = writable(events_local_data_struct);
@@ -181,7 +181,7 @@ let events_session_data_struct: key_val = {
// other
};
console.log(`AE Stores - App Events Session Storage Data:`, events_session_data_struct);
// console.log(`AE Stores - App Events Session Storage Data:`, events_session_data_struct);
export let events_sess = writable(events_session_data_struct);

View File

@@ -1,5 +1,6 @@
import type { key_val } from '$lib/ae_stores';
import { api } from '$lib/api';
import type { log } from 'console';
// import { liveQuery } from "dexie";
// import { db_core } from "$lib/db_core";
@@ -10,10 +11,28 @@ import { api } from '$lib/api';
let ae_promises: key_val = {}; // Promise<any>;
// Updated 2024-03-20
async function handle_load_ae_obj_id__sponsorship_cfg({ api_cfg, sponsorship_cfg_id, try_cache=false }) {
// Updated 2024-03-29
async function handle_load_ae_obj_id__sponsorship_cfg(
{
api_cfg,
sponsorship_cfg_id,
try_cache=false,
log_lvl=0
} : {
api_cfg: any,
sponsorship_cfg_id: string,
try_cache: boolean,
log_lvl: number
}
) {
console.log(`*** handle_load_ae_obj_id__sponsorship_cfg() *** sponsorship_cfg_id=${sponsorship_cfg_id}`);
if (!api_cfg.account_id) {
console.log(`*ae_func* No account_id found in API config!'`);
return false;
}
let params = {};
// ae_loc.hub.sponsorships.qry_status = 'loading';
@@ -24,10 +43,13 @@ async function handle_load_ae_obj_id__sponsorship_cfg({ api_cfg, sponsorship_cfg
use_alt_table: false, // 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: 2
log_lvl: log_lvl
})
.then(function (sponsorship_cfg_obj_get_result) {
if (sponsorship_cfg_obj_get_result) {
if (log_lvl) {
console.log(`*ae_func* Got a result for sponsorship_cfg_id ${sponsorship_cfg_id}`);
}
return sponsorship_cfg_obj_get_result;
} else {
console.log('No results returned.');

View File

@@ -59,13 +59,37 @@ export let temp_get_object_percent_completed = 0;
export let get_object_percent_completed = temp_get_object_percent_completed;
// Updated 2022-10-28
export let get_object = async function get_object({api_cfg, endpoint='', headers={}, params={}, data={}, timeout=60000, return_meta=false, return_blob=false, filename=null, auto_download=false, as_list=false, log_lvl=0}) {
export let get_object = async function get_object(
{
api_cfg,
endpoint='',
headers={},
params={},
data={},
timeout=60000,
return_meta=false,
return_blob=false,
filename=null,
auto_download=false,
as_list=false,
log_lvl=0
// } : {
// api_cfg: any,
// endpoint: string,
// headers?: any,
// params?: any,
// data?: any,
// timeout?: number,
// return_meta?: boolean,
// return_blob?: boolean,
// filename?: string,
// auto_download?: boolean,
// as_list?: boolean,
// log_lvl?: number
}
) {
if (log_lvl) {
console.log('*** get_object() ***');
}
if (log_lvl) {
console.log(`Endpoint: ${endpoint}`);
console.log(`*** get_object() *** Endpoint: ${endpoint}`);
console.log('Params:', params);
if (log_lvl > 1) {
console.log('Data:', data);
@@ -164,6 +188,9 @@ export let get_object = async function get_object({api_cfg, endpoint='', headers
)
.then(function (response) {
if (log_lvl) {
console.log(`GET Response: status=${response.status} statusText=${response.statusText} baseURL=${response.config.baseURL} url=${response.config.url} method=${response.config.method} headers=${response.config.headers} params=${response.config.params}`);
}
if (log_lvl > 1) {
console.log('GET Response:', response);
}
if (!Array.isArray(response.data['data']) && as_list) {
@@ -285,12 +312,15 @@ export let get_object = async function get_object({api_cfg, endpoint='', headers
)
.then(function (response) {
if (log_lvl) {
console.log(response);
console.log(`GET (blob) Response: status=${response.status} statusText=${response.statusText} baseURL=${response.config.baseURL} url=${response.config.url} method=${response.config.method} headers=${response.config.headers} params=${response.config.params}`);
}
if (log_lvl > 1) {
console.log('GET (blob) Response:', response);
}
const { data, headers } = response
console.log(headers);
const { data, headers } = response;
// Careful if this download filename needs to be changed to a different file extension. The browser/client may not know how to handle it.
if (filename) {
} else if (headers['content-disposition']) {
filename = headers['content-disposition'].replace(/\w+;filename=(.*)/, '$1');
@@ -299,11 +329,13 @@ export let get_object = async function get_object({api_cfg, endpoint='', headers
}
if (auto_download) {
if (log_lvl) {
console.log(`Auto Download: ${filename}`);
}
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
// link.setAttribute('download', 'event_exhibit_tracking_export.xlsx'); //or any other extension
link.setAttribute('download', filename); //or any other extension
link.setAttribute('download', filename);
document.body.appendChild(link);
link.click();
return true;
@@ -322,7 +354,7 @@ export let get_object = async function get_object({api_cfg, endpoint='', headers
return response_data_promise;
} else {
// This generally should not happen. It likely means the query was bad or an API issue.
console.log('Returning unknown. This should not happen in most cases.');
console.log('Returning (blob) unknown. This should not happen in most cases.');
Promise.reject(new Error('fail')).then(resolved, rejected);
}
}

View File

@@ -66,9 +66,9 @@ import Element_data_store from '$lib/element_data_store.svelte';
// Quickly save the data passed from the parent(s) to the Svelte stores, localStorage, and other. This should catch anything that is a child of this layout.svelte file.
$slct.account_id = data.account_id;
console.log(`$slct.account_id = `, $slct.account_id);
console.log(`*ae_root +layout.svelte* $slct.account_id = `, $slct.account_id);
let ae_acct = data[$slct.account_id];
console.log(`ae_acct = `, ae_acct);
// console.log(`*ae_root +layout.svelte* ae_acct = `, ae_acct);
// let ae_acct = data.ae_acct;
// $ae_api = ae_acct.api;
// $ae_loc = ae_acct.loc;
@@ -77,13 +77,13 @@ $ae_api = {
...$ae_api,
...ae_acct.api,
}
console.log(`$ae_api = `, $ae_api);
// console.log(`$ae_api = `, $ae_api);
$ae_loc = {
...$ae_loc,
...ae_acct.loc,
}
console.log(`$ae_loc = `, $ae_loc);
// console.log(`$ae_loc = `, $ae_loc);
$slct = {
...$slct,
@@ -105,8 +105,10 @@ if ($ae_loc.site_cfg_json.slct__event_id) {
if ($ae_loc.site_cfg_json.slct__sponsorship_cfg_id) {
$slct.sponsorship_cfg_id = $ae_loc.site_cfg_json.slct__sponsorship_cfg_id;
$ae_loc.mod.sponsorships.cfg_id = $ae_loc.site_cfg_json.slct__sponsorship_cfg_id;
} else if ($ae_loc.default__sponsorship_cfg_id) {
$slct.sponsorship_cfg_id = $ae_loc.default__sponsorship_cfg_id;
$ae_loc.mod.sponsorships.cfg_id = $ae_loc.default__sponsorship_cfg_id;
} else {
console.log(`No Sponsorship Config ID set.`);
}
@@ -190,19 +192,9 @@ onMount(() => {
if (data.url.searchParams.get('sponsorship_cfg_id')) {
$slct.sponsorship_cfg_id = data.url.searchParams.get('sponsorship_cfg_id');
$ae_loc.mod.sponsorships.cfg_id = data.url.searchParams.get('sponsorship_cfg_id');
}
});
// $slct_trigger = 'set_access_code_li';
// $: if ($slct_trigger == 'set_access_code_li' && !$ae_loc.ds['hub__page__access_code_li_json']) {
// console.log(`$ae_loc.ds['hub__page__access_code_li_json'] = `, $ae_loc.ds['hub__page__access_code_li_json']);
// $slct_trigger = null; // Reset the trigger to prevent loops
// $ae_loc.page_access_code_li = $ae_loc.ds['hub__page__access_code_li_json'];
// $ae_loc = $ae_loc; // Trigger Svelte just in case
// // console.log($ae_loc);
// }
</script>

View File

@@ -132,7 +132,7 @@ export async function load({ fetch, params, parent, route, url }) { // params, r
// ae_loc.site_domain = data.url.origin;
// console.log(`ae_loc = `, ae_loc);
account_id = await core_func.handle_load_ae_obj_id__site_domain({api_cfg: ae_api_init, fqdn: url.host, try_cache: false})
account_id = await core_func.handle_load_ae_obj_id__site_domain({api_cfg: ae_api_init, fqdn: url.host, try_cache: false, log_lvl: 1})
.then(function (site_domain_results) {
if (site_domain_results) {
@@ -162,18 +162,11 @@ export async function load({ fetch, params, parent, route, url }) { // params, r
return null;
});
// .then(async function (results) {
// return true;
// })
// .finally(function () {
// return true;
// });
if (!account_id) {
console.log(`root layout.ts: The account_id was not found in API response!!!`);
return false;
}
// console.log(ae_loc_init);
// if (browser) {
@@ -189,12 +182,6 @@ export async function load({ fetch, params, parent, route, url }) { // params, r
.then(function (ds_results) {
if (ds_results) {
console.log(`ae_ ds_results = `, ds_results);
// if (browser) {
// console.log(`ae_ds__ key: ${ds_code}, value:`, ds_results);
// localStorage.setItem(`ae_ds__${ds_code}`, JSON.stringify(ds_results));
// } else {
// console.log('No browser!!!');
// }
return ds_results;
}

View File

@@ -386,6 +386,13 @@ export let get_event_exhibit_tracking_export = async function get_event_exhibit_
{/if} <!-- $events_loc?.leads.auth_exhibit_kv[$events_slct.exhibit_id].key -->
<hr class="border w-full">
<h2 class="h3">
<!-- <span class="fas fa-cogs"></span> -->
Additional Settings
</h2>
<div>
<button
class="btn btn-sm variant-ghost-warning"
@@ -413,15 +420,21 @@ export let get_event_exhibit_tracking_export = async function get_event_exhibit_
<span class="fas fa-eraser mx-1"></span>
Clear Storage
</button>
<button
class="btn btn-sm variant-ghost-warning"
title="Clear browser iDB storage"
on:click={() => {
db_events.delete().then(() => {
console.log('Database cleared.');
});
}}
>
<span class="fas fa-database mx-1"></span>
Clear iDB
</button>
</div>
<hr class="border w-full">
<h2 class="h3">
<!-- <span class="fas fa-cogs"></span> -->
Additional Settings
</h2>
{#if $events_loc?.leads.auth_exhibit_kv[$events_slct.exhibit_id]}
Auto hide on sign in:

View File

@@ -30,7 +30,7 @@ export async function load({ parent }) {
return false;
}
let load_event_obj = events_func.handle_load_ae_obj_id__event({api_cfg: ae_acct.api, event_id: event_id, try_cache: false});
let load_event_obj = events_func.handle_load_ae_obj_id__event({api_cfg: ae_acct.api, event_id: event_id, try_cache: false});
ae_acct.slct.event_obj = load_event_obj;

View File

@@ -30,7 +30,7 @@ export async function load({ parent }) {
return false;
}
let load_sponsorship_cfg_obj = spons_func.handle_load_ae_obj_id__sponsorship_cfg({api_cfg: ae_acct.api, sponsorship_cfg_id: sponsorship_cfg_id, try_cache: false});
let load_sponsorship_cfg_obj = spons_func.handle_load_ae_obj_id__sponsorship_cfg({api_cfg: ae_acct.api, sponsorship_cfg_id: sponsorship_cfg_id, try_cache: false});
ae_acct.slct.sponsorship_cfg_id = sponsorship_cfg_id;
ae_acct.slct.sponsorship_cfg_obj = await load_sponsorship_cfg_obj;
@@ -51,7 +51,8 @@ export async function load({ parent }) {
ds_code = 'hub__page__sponsorships__create_info_header';
ds_type = 'text';
ds_code_li[ds_code] = core_func.handle_load_ae_obj_code__data_store({api_cfg: ae_acct.api, code: ds_code, data_type: ds_type, save_idb: true})
// ds_code_li[ds_code] =
ae_acct['ds'][ds_code] = core_func.handle_load_ae_obj_code__data_store({api_cfg: ae_acct.api, code: ds_code, data_type: ds_type, save_idb: true})
.then(function (ds_results) {
if (ds_results) {
// console.log(`ae_ ds_results = `, ds_results);
@@ -110,7 +111,8 @@ export async function load({ parent }) {
ds_code = 'hub__page__sponsorships__create_info';
ds_type = 'text';
ds_code_li[ds_code] = core_func.handle_load_ae_obj_code__data_store({api_cfg: ae_acct.api, code: ds_code, data_type: ds_type, save_idb: true})
// ds_code_li[ds_code] =
ae_acct['ds'][ds_code] = core_func.handle_load_ae_obj_code__data_store({api_cfg: ae_acct.api, code: ds_code, data_type: ds_type, save_idb: true})
.then(function (ds_results) {
if (ds_results) {
// console.log(`ae_ ds_results = `, ds_results);
@@ -187,15 +189,20 @@ export async function load({ parent }) {
// // console.log(`ae_loc_tmp = `, ae_loc_tmp);
// data['ae_loc'] = ae_loc_tmp;
data['ae_ds'] = ds_code_li;
// data['ae_ds'] = ds_code_li;
ae_acct['ds'] = {
...ae_acct['ds'],
...ds_code_li
};
// ae_acct['ds'] = {
// ...ae_acct['ds'],
// ...ds_code_li
// };
// ae_acct['ds'] = ds_code_li;
data['ae_ds'] = {
...data['ae_ds'],
...ae_acct['ds']
}
// WARNING: Precaution against shared data between sites and sessions.
data[account_id] = ae_acct;

View File

@@ -1,5 +1,5 @@
<script lang="ts">
export let data;
export let data: any;
// console.log(`ae_ Svelte Sponsorships +page data:`, data);