Trying to make things work better...
This commit is contained in:
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user