Trying to make things work better...

This commit is contained in:
Scott Idem
2024-03-26 14:24:35 -04:00
parent 040e1e71e3
commit 4d486a580c
22 changed files with 508 additions and 410 deletions

View File

@@ -30,7 +30,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: 2
log_lvl: 1
})
.then(function (site_domain_obj_get_result) {
if (site_domain_obj_get_result) {

View File

@@ -0,0 +1,49 @@
import type { key_val } from '$lib/ae_stores';
import { api } from '$lib/api';
// import { liveQuery } from "dexie";
// import { db_core } from "$lib/db_core";
// let example_li = liveQuery(
// () => db_core.sponsorships.toArray()
// );
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 }) {
console.log(`*** handle_load_ae_obj_id__sponsorship_cfg() *** sponsorship_cfg_id=${sponsorship_cfg_id}`);
let params = {};
// ae_loc.hub.sponsorships.qry_status = 'loading';
ae_promises.load__sponsorship_cfg_obj = await api.get_ae_obj_id_crud({
api_cfg: api_cfg,
obj_type: 'sponsorship_cfg',
obj_id: sponsorship_cfg_id,
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
})
.then(function (sponsorship_cfg_obj_get_result) {
if (sponsorship_cfg_obj_get_result) {
return sponsorship_cfg_obj_get_result;
} else {
console.log('No results returned.');
return null;
}
})
.catch(function (error) {
console.log('No results returned or failed.', error);
});
return ae_promises.load__sponsorship_cfg_obj;
}
let export_obj = {
handle_load_ae_obj_id__sponsorship_cfg: handle_load_ae_obj_id__sponsorship_cfg,
};
export let spons_func = export_obj;

View File

@@ -46,7 +46,11 @@ export let ae_app_local_data_struct: key_val = {
'account_id': ae_account_id, // OSIT Demo _XY7DXtc9MY
'site_domain': null, // https://example.com, https://dev.example.com, etc.
'site_cfg_json': {},
'site_cfg_json': {
slct__event_id: null,
slct__event_badge_template_id: null,
slct__sponsorship_cfg_id: null,
},
'page_access_code_li': {'administrator': '11500', 'trusted': '19111', 'authenticated': '00000'},
'administrator_passcode': '11500',

View File

@@ -15,7 +15,7 @@ export let ds_name: null|string = null;
export let ds_type: string = 'text';
export let for_type: null|string = null;
export let for_id: null|string = null;
console.log(`ae_e_data_store ${ds_code} for_type=${for_type} for_id=${for_id}`);
console.log(`ae_e_data_store ${ds_code} for_type=${for_type} for_id=${for_id} account_id=${$ae_loc.account_id}`);
export let store: string = 'local';
export let display: string = 'block';
@@ -60,10 +60,11 @@ let ds_code_obj =
md: null,
text: null,
updated_on: null,
chk_account_id: null,
};
let ae_ds_loc: Writable<key_val> = localStorageStore(`ae_ds__${ds_code}`, ds_code_obj);
// console.log(`ae_ Data Store ${ds_code} = `, $ae_ds_loc);
console.log(`ae_e_data_store cached: ${ds_code} = `, $ae_ds_loc);
if (!$ae_ds_loc.id) {
ds_loading_status = '-- loading --';
@@ -76,7 +77,7 @@ $ae_sess.ds.update_status = null;
let trigger: null|string = null;
// This is a quick check to make sure the data store is not stale. If it is, then we need to trigger a reload.
if ($ae_ds_loc.loaded_on) {
if ($ae_ds_loc.loaded_on && $ae_ds_loc.chk_account_id == $ae_loc.account_id) {
let loaded_on = new Date($ae_ds_loc.loaded_on);
let now = new Date();
let diff = now.getTime() - loaded_on.getTime();
@@ -89,14 +90,9 @@ if ($ae_ds_loc.loaded_on) {
setTimeout(() => {
trigger = 'load__ds__code';
}, random_ms);
// trigger = 'load__ds__code';
}
// let diff_hours = diff / (1000 * 60 * 60);
// if (diff_hours > 1) {
// trigger = 'load__ds__code';
// }
} else {
console.log('No loaded_on date found. Need to trigger reload.');
console.log('No loaded_on date found and or the account_id check failed. Need to trigger reload.');
trigger = 'load__ds__code';
}
@@ -108,17 +104,19 @@ if (!$ae_ds_loc.account_id === null || $ae_loc.account_id == $ae_loc.account_id)
onMount(() => {
console.log('Element: Data Store element_data_store.svelte');
// if (ds_code && ds_type) {
// trigger = 'load__ds__code';
// $slct_trigger = 'load__ds__code';
// }
// Wait for random number of milliseconds to avoid all data stores being reloaded at the same time.
let random_ms = Math.floor(Math.random() * 500);
console.log(`Random number of milliseconds: ${random_ms}`);
setTimeout(() => {
trigger = 'load__ds__code';
}, random_ms);
});
// let ds_code_li = {}; //: key_val; // = ae_loc_tmp.ds;
// console.log(`ae_ ds_code_li = `, ds_code_li);
$: if (trigger == 'load__ds__code' && ds_code && ds_type) {
console.log(`ae_ load__ds__code: ${ds_code} ${ds_type} ${for_type} ${for_id} ${try_cache}`);
console.log(`ae_ load__ds__code: ${ds_code} ds_type=${ds_type} for_type=${for_type} for_id=${for_id} ${try_cache}`);
trigger = null;
@@ -152,7 +150,7 @@ async function load_data_store(
api_cfg: $ae_api,
data_store_code: code,
data_type: type,
log_lvl: 1
log_lvl: 0
})
.then( function (ds_results) {
@@ -168,6 +166,8 @@ async function load_data_store(
// Set the loaded_on datetime to the current time for reference later. This will be used to determine if the data store is stale.
$ae_ds_loc.loaded_on = new Date().toISOString();
// Set the chk_account_id as a backup check to make sure the data store belongs to the account for the current site. This should not be needed, but here we are...
$ae_ds_loc.chk_account_id = $ae_loc.account_id;
$ae_ds_loc.id = ds_results.data_store_id_random;
$ae_ds_loc.account_id = ds_results.account_id_random;
@@ -677,37 +677,37 @@ async function handle_update__data_store({
<!-- {#if mode == 'view'} -->
{#if !$ae_ds_loc.type && !$ae_ds_loc.html && !$ae_ds_loc.json && !$ae_ds_loc.md && !$ae_ds_loc.text}
<span class="variant-soft-warning">No data found! Is the data store correct or new?</span>
{/if}
{#if !$ae_ds_loc.type && !$ae_ds_loc.html && !$ae_ds_loc.json && !$ae_ds_loc.md && !$ae_ds_loc.text}
<span class="variant-soft-warning">No data found! Is the data store correct or new?</span>
{/if}
{#if $ae_ds_loc.type == 'html' && $ae_ds_loc.html}
{@html $ae_ds_loc.html}
{:else if $ae_ds_loc.type == 'html'}
<span class="variant-soft-warning">No HTML found! Is the data store type correct?</span>
{/if}
{#if $ae_ds_loc.type == 'html' && $ae_ds_loc.html}
{@html $ae_ds_loc.html}
{:else if $ae_ds_loc.type == 'html'}
<span class="variant-soft-warning">No HTML found! Is the data store type correct?</span>
{/if}
{#if $ae_ds_loc.type == 'text' && $ae_ds_loc.text}
{$ae_ds_loc.text}
{:else if $ae_ds_loc.type == 'text'}
<span class="variant-soft-warning">No text found! Is the data store type correct?</span>
{/if}
{#if $ae_ds_loc.type == 'text' && $ae_ds_loc.text}
{$ae_ds_loc.text}
{:else if $ae_ds_loc.type == 'text'}
<span class="variant-soft-warning">No text found! Is the data store type correct?</span>
{/if}
<button
type="button"
class="ae_btn_edit__ds btn hover:variant-glass-warning text-xs absolute top-0 right-0 opacity-30 hover:opacity-100 transition delay-700 hover:delay-200 m-1 p-1"
class:opacity-5={!$ae_loc.administrator_access}
class:hidden={!show_edit_btn || !$ae_loc.trusted_access}
on:dblclick={() => {
trigger = 'load__ds__code';
show_edit = true;
show_view = false;
}}
title="Double click to edit data store: {ds_code} with {$ae_ds_loc.account_id ? `account ID=${$ae_ds_loc.account_id}` : 'no account ID'}"
>
<span class="fas fa-edit mx-1"></span>
Edit
</button>
<button
type="button"
class="ae_btn_edit__ds btn hover:variant-glass-warning text-xs absolute top-0 right-0 opacity-30 hover:opacity-100 transition delay-700 hover:delay-200 m-1 p-1"
class:opacity-5={!$ae_loc.administrator_access}
class:hidden={!show_edit_btn || !$ae_loc.trusted_access}
on:dblclick={() => {
trigger = 'load__ds__code';
show_edit = true;
show_view = false;
}}
title="Double click to edit data store: {ds_code} with {$ae_ds_loc.account_id ? `account ID=${$ae_ds_loc.account_id}` : 'no account ID'}"
>
<span class="fas fa-edit mx-1"></span>
Edit
</button>
<!-- {/if} -->
{:else}