General clean up. Less debug. Things work better?
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
|
||||
@@ -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.');
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user