Lots of general clean up and fixes.
This commit is contained in:
107
src/lib/ae_core_functions.ts
Normal file
107
src/lib/ae_core_functions.ts
Normal file
@@ -0,0 +1,107 @@
|
||||
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.badges.toArray()
|
||||
// );
|
||||
|
||||
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 }) {
|
||||
console.log(`*** handle_load_ae_obj_id__site_domain() *** fqdn=${fqdn}`);
|
||||
|
||||
let no_account_id = false;
|
||||
if (!api_cfg.account_id) {
|
||||
no_account_id = true;
|
||||
}
|
||||
|
||||
let params = {};
|
||||
|
||||
// ae_loc.hub.site_domain_id_qry_status = 'loading';
|
||||
ae_promises.load__site_domain_obj = api.get_ae_obj_id_crud({
|
||||
api_cfg: api_cfg,
|
||||
no_account_id: no_account_id,
|
||||
obj_type: 'site_domain',
|
||||
obj_id: fqdn, // NOTE: This is the FQDN, not normally the ID.
|
||||
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
|
||||
})
|
||||
.then(function (site_domain_obj_get_result) {
|
||||
if (site_domain_obj_get_result) {
|
||||
// slct.site_domain_obj = site_domain_obj_get_result;
|
||||
// console.log(`site_domain object:`, get(slct).site_domain_obj);
|
||||
|
||||
// ae_loc.account_id = $slct.site_domain_obj.account_id_random;
|
||||
// ae_loc.site_id = $slct.site_domain_obj.site_id_random;
|
||||
// ae_loc.site_domain_id = $slct.site_domain_obj.site_domain_id_random;
|
||||
return site_domain_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__site_domain_obj;
|
||||
}
|
||||
|
||||
// handle_load_ae_obj_code__data_store
|
||||
async function handle_load_ae_obj_code__data_store({ api_cfg, code=null, data_type='text' }) {
|
||||
console.log(`*** handle_get_data_store_obj_w_code() *** code=${code}`);
|
||||
|
||||
if (!code) {
|
||||
console.log('No code provided.');
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!api_cfg.account_id) {
|
||||
console.log('No account_id provided.');
|
||||
return false;
|
||||
}
|
||||
|
||||
ae_promises.load__data_store_obj = api.get_data_store_obj_w_code({
|
||||
api_cfg: api_cfg,
|
||||
data_store_code: code,
|
||||
data_type: data_type,
|
||||
log_lvl: 0
|
||||
})
|
||||
.then(function (get_data_store_result) {
|
||||
let return_this = null;
|
||||
if (get_data_store_result) {
|
||||
|
||||
if (data_type == 'text') {
|
||||
// console.log(get_data_store_result.text);
|
||||
return_this = get_data_store_result.text;
|
||||
} else if (data_type == 'json') {
|
||||
// console.log(get_data_store_result.json);
|
||||
return_this = get_data_store_result.json;
|
||||
}
|
||||
|
||||
} else {
|
||||
console.log('No results returned.');
|
||||
return_this = null;
|
||||
}
|
||||
return return_this;
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log('No results returned or failed.', error);
|
||||
});
|
||||
|
||||
return ae_promises.load__data_store_obj;
|
||||
}
|
||||
|
||||
|
||||
|
||||
let export_obj = {
|
||||
handle_load_ae_obj_id__site_domain: handle_load_ae_obj_id__site_domain,
|
||||
handle_load_ae_obj_code__data_store: handle_load_ae_obj_code__data_store,
|
||||
};
|
||||
export let core_func = export_obj;
|
||||
@@ -47,6 +47,7 @@ let events_local_data_struct: key_val = {
|
||||
show_content__scan_requirements: true,
|
||||
|
||||
auto_view: true,
|
||||
auto_hide_on_sign_in: true,
|
||||
|
||||
show_hidden: false, // These are hidden (archived) leads so the list is not as long.
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { localStorageStore } from '@skeletonlabs/skeleton';
|
||||
import { get, readable, writable } from 'svelte/store';
|
||||
import type { get, Writable } from 'svelte/store';
|
||||
import { writable } from 'svelte/store';
|
||||
import type { Writable } from 'svelte/store';
|
||||
|
||||
|
||||
import { PUBLIC_TESTING, PUBLIC_AE_API_PROTOCOL, PUBLIC_AE_API_SERVER, PUBLIC_AE_API_BAK_SERVER, PUBLIC_AE_API_PORT, PUBLIC_AE_API_PATH, PUBLIC_AE_API_SECRET_KEY, PUBLIC_AE_API_CRUD_SUPER_KEY, PUBLIC_AE_NO_ACCOUNT_ID, PUBLIC_AE_NO_ACCOUNT_ID_TOKEN, PUBLIC_AE_ACCOUNT_ID, PUBLIC_AE_EVENT_ID, PUBLIC_AE_SPONSORSHIP_CFG_ID } from '$env/static/public';
|
||||
// console.log(`AE Stores - PUBLIC_TESTING:`, PUBLIC_TESTING);
|
||||
console.log(`AE Stores - PUBLIC_TESTING:`, PUBLIC_TESTING);
|
||||
|
||||
const api_base_url = `${PUBLIC_AE_API_PROTOCOL}://${PUBLIC_AE_API_SERVER}:${PUBLIC_AE_API_PORT}${PUBLIC_AE_API_PATH}`;
|
||||
const api_base_url_bak = `${PUBLIC_AE_API_PROTOCOL}://${PUBLIC_AE_API_BAK_SERVER}:${PUBLIC_AE_API_PORT}${PUBLIC_AE_API_PATH}`;
|
||||
@@ -21,7 +21,7 @@ const ae_sponsorship_cfg_id = PUBLIC_AE_SPONSORSHIP_CFG_ID;
|
||||
|
||||
// import { getStores, navigating, page, updated } from '$app/stores';
|
||||
// import { assets, base, resolveRoute } from '$app/paths';
|
||||
// console.log(page.path); // Everything after the domian name
|
||||
// console.log(page.path); // Everything after the domain name
|
||||
|
||||
// console.log(import.meta.env.MODE);
|
||||
// console.log(import.meta.env.BASE_URL);
|
||||
|
||||
@@ -59,7 +59,7 @@ 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=600000, 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}) {
|
||||
if (log_lvl) {
|
||||
console.log('*** get_object() ***');
|
||||
}
|
||||
@@ -226,6 +226,10 @@ export let get_object = async function get_object({api_cfg, endpoint='', headers
|
||||
}
|
||||
return null; // Returning null since there were no results
|
||||
}
|
||||
if (error.code === 'ECONNABORTED') {
|
||||
// Timeout Error (You can implement retry here where suitable)
|
||||
console.log('Timeout Error: ', error.message);
|
||||
}
|
||||
if (log_lvl) {
|
||||
console.log('The response was an error. Returning false.');
|
||||
}
|
||||
@@ -1320,16 +1324,16 @@ export let get_data_store_obj_w_code = async function get_data_store_obj_w_code(
|
||||
// let get_item_result = window.localStorage.getItem(code);
|
||||
|
||||
const endpoint = `/data_store/code/${data_store_code}`;
|
||||
let data_store_obj_get_promise = await api.get_object({api_cfg: api_cfg, endpoint: endpoint, headers: headers, params: params, log_lvl: log_lvl});
|
||||
let data_store_obj_get_promise = await api.get_object({api_cfg: api_cfg, endpoint: endpoint, headers: headers, params: params, timeout: 3000, log_lvl: log_lvl});
|
||||
|
||||
if (data_store_obj_get_promise === false) {
|
||||
console.log('Data Store - RUN AGAIN WITH BACKUP');
|
||||
let original_api_base_url = api_cfg['base_url'];
|
||||
|
||||
let temp_api = api_cfg;
|
||||
temp_api['base_url'] = temp_api['base_url_backup']
|
||||
temp_api['base_url'] = temp_api['base_url_bak']
|
||||
|
||||
data_store_obj_get_promise = await api.get_object({api_cfg: temp_api, endpoint: endpoint, headers: headers, params: params, log_lvl: log_lvl});
|
||||
data_store_obj_get_promise = await api.get_object({api_cfg: temp_api, endpoint: endpoint, headers: headers, params: params, timeout: 6000, log_lvl: log_lvl});
|
||||
temp_api['base_url'] = original_api_base_url;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,11 +8,13 @@ import { ae_loc, ae_sess, ae_api, slct, slct_trigger, ae_trig } from '$lib/ae_st
|
||||
import { ae_util } from '$lib/ae_utils';
|
||||
import type { key_val } from '$lib/ae_stores';
|
||||
|
||||
export let expire_minutes: number = 10;
|
||||
|
||||
export let ds_code: string;
|
||||
export let ds_name: null|string = null;
|
||||
export let ds_type: string = 'text';
|
||||
export let for_type: null|string;
|
||||
export let for_id: null|string;
|
||||
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}`);
|
||||
|
||||
export let store: string = 'local';
|
||||
@@ -71,7 +73,37 @@ $ae_sess.ds.submit_status = null;
|
||||
$ae_sess.ds.create_status = null;
|
||||
$ae_sess.ds.update_status = null;
|
||||
|
||||
let trigger: null|string = 'load__ds__code';
|
||||
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) {
|
||||
let loaded_on = new Date($ae_ds_loc.loaded_on);
|
||||
let now = new Date();
|
||||
let diff = now.getTime() - loaded_on.getTime();
|
||||
let diff_minutes = diff / (1000 * 60);
|
||||
if (diff_minutes > expire_minutes) {
|
||||
console.log(`Data Store ${ds_code} stale. Last loaded on: ${loaded_on.toISOString()}`);
|
||||
// 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);
|
||||
// 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.');
|
||||
trigger = 'load__ds__code';
|
||||
}
|
||||
|
||||
// This is a secondary check... The account_id should either be null or match the current account_id.
|
||||
if (!$ae_ds_loc.account_id === null || $ae_loc.account_id == $ae_loc.account_id) {
|
||||
trigger = 'load__ds__code';
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
console.log('Element: Data Store element_data_store.svelte');
|
||||
@@ -123,6 +155,11 @@ async function load_data_store({
|
||||
return false;
|
||||
}
|
||||
|
||||
ds_loaded = true;
|
||||
|
||||
// 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();
|
||||
|
||||
$ae_ds_loc.id = ds_results.data_store_id_random;
|
||||
$ae_ds_loc.account_id = ds_results.account_id_random;
|
||||
$ae_ds_loc.code = ds_results.code; // This will overwrite whatever was passed in.
|
||||
@@ -149,8 +186,6 @@ async function load_data_store({
|
||||
val_text = ds_results.text;
|
||||
return ds_results.text;
|
||||
}
|
||||
|
||||
ds_loaded = true;
|
||||
} else {
|
||||
ds_loaded = false;
|
||||
ds_loading_status = '-- not found --';
|
||||
@@ -654,11 +689,12 @@ async function handle_update__data_store({
|
||||
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:click={() => {
|
||||
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
|
||||
@@ -681,7 +717,7 @@ async function handle_update__data_store({
|
||||
</pre> -->
|
||||
|
||||
{#await ds_get_results}
|
||||
<div class="modal-loading text-xs">
|
||||
<div class="modal-loading text-xs absolute bottom-0 left-0 opacity-30 hover:opacity-100 transition delay-700 hover:delay-200">
|
||||
<span class="fas fa-spinner fa-spin"></span>
|
||||
<span class="loading-text">
|
||||
Loading...
|
||||
|
||||
Reference in New Issue
Block a user