Less debug. Code clean up. And it uses the Svelte fetch function!! I think it just works...
This commit is contained in:
@@ -94,9 +94,15 @@ export let get_object = async function get_object(
|
||||
console.log('Fetch options:', fetchOptions);
|
||||
}
|
||||
|
||||
let fetch_method: any = fetch;
|
||||
if (api_cfg.fetch) {
|
||||
console.log('Using custom fetch function from api_cfg!!!');
|
||||
fetch_method = api_cfg.fetch;
|
||||
}
|
||||
|
||||
for (let attempt = 1; attempt <= retry_count; attempt++) {
|
||||
try {
|
||||
const response = await fetch(url.toString(), fetchOptions)
|
||||
const response = await fetch_method(url.toString(), fetchOptions)
|
||||
.catch(function (error) {
|
||||
console.log('API GET Object *fetch* request was aborted or failed in an unexpected way.', error);
|
||||
});
|
||||
|
||||
@@ -185,6 +185,8 @@ export async function load({ fetch, params, parent, route, url }) { // params, r
|
||||
ae_acct.account_id = json_data.account_id_random;
|
||||
|
||||
ae_api_init['account_id'] = json_data.account_id_random;
|
||||
ae_api_init['fetch'] = fetch;
|
||||
// ae_api_init['fetch'] = null;
|
||||
ae_api_init['headers']['x-account-id'] = json_data.account_id_random;
|
||||
ae_api_init['headers']['x-no-account-id'] = null;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
console.log(`ae_journals +layout.ts start`);
|
||||
|
||||
// Imports
|
||||
import { browser } from '$app/environment';
|
||||
// import { browser } from '$app/environment';
|
||||
// import { journals_func } from '$lib/ae_journals/ae_journals_functions';
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import { browser } from '$app/environment';
|
||||
import { journals_func } from '$lib/ae_journals/ae_journals_functions';
|
||||
|
||||
export async function load({ parent }) {
|
||||
export async function load({ fetch, parent }) {
|
||||
let log_lvl: number = 0;
|
||||
|
||||
let parent_data = await parent();
|
||||
|
||||
@@ -57,7 +57,9 @@ let lq__journal_obj = $derived(liveQuery(async () => {
|
||||
.get($journals_slct?.journal_id ?? ''); // null or undefined does not reset things like '' does
|
||||
|
||||
$journals_slct.journal_obj = results;
|
||||
console.log(`lq__journal_obj: results = `, results);
|
||||
if (log_lvl) {
|
||||
console.log(`lq__journal_obj: results = `, results);
|
||||
}
|
||||
|
||||
return results;
|
||||
}));
|
||||
@@ -95,7 +97,9 @@ async function handle_update_journal() {
|
||||
data_kv: data_kv,
|
||||
log_lvl: log_lvl
|
||||
}).then((results) => {
|
||||
console.log('Journal updated:', results);
|
||||
if (log_lvl) {
|
||||
console.log('Journal updated:', results);
|
||||
}
|
||||
// $journals_slct.journal_id = results?.journal_id_random;
|
||||
}).catch((error) => {
|
||||
console.error('Error updating journal:', error);
|
||||
@@ -245,7 +249,9 @@ async function handle_update_journal() {
|
||||
data_kv: data_kv,
|
||||
log_lvl: log_lvl
|
||||
}).then((results) => {
|
||||
console.log('New journal entry created:', results);
|
||||
if (log_lvl) {
|
||||
console.log('New journal entry created:', results);
|
||||
}
|
||||
$journals_slct.journal_entry_id = results?.journal_entry_id_random;
|
||||
// $journals_loc.entry.edit = true;
|
||||
$journals_loc.entry.edit_kv[$journals_slct.journal_entry_id] = 'current';
|
||||
@@ -299,7 +305,7 @@ async function handle_update_journal() {
|
||||
title="Select a category for the new journal entry"
|
||||
>
|
||||
<option value="">Select Category</option>
|
||||
{#each $lq__journal_obj?.cfg_json.category_li as category}
|
||||
{#each $lq__journal_obj?.cfg_json?.category_li as category}
|
||||
<option value={category.code}>{category.name}</option>
|
||||
{/each}
|
||||
</select>
|
||||
|
||||
@@ -58,7 +58,9 @@ let lq__journal_obj = $derived(liveQuery(async () => {
|
||||
}
|
||||
let results = await db_journals.journal
|
||||
.get($journals_slct?.journal_id ?? ''); // null or undefined does not reset things like '' does
|
||||
console.log(`lq__journal_obj: results = `, results);
|
||||
if (log_lvl) {
|
||||
console.log(`lq__journal_obj: results = `, results);
|
||||
}
|
||||
|
||||
return results;
|
||||
}));
|
||||
@@ -81,7 +83,10 @@ let lq__journal_entry_obj_li = $derived(liveQuery(async () => {
|
||||
|
||||
return results;
|
||||
} else if ($journals_loc.filter__category_code && $journals_loc.filter__category_code.length > 0) {
|
||||
console.log(`lq__journal_entry_obj_li - filtering by category_code: ${$journals_loc.filter__category_code}`);
|
||||
if (log_lvl) {
|
||||
// console.log(`$lq__journal_obj.cfg_json = `, $lq__journal_obj?.cfg_json);
|
||||
console.log(`$journals_loc.filter__category_code = `, $journals_loc.filter__category_code);
|
||||
}
|
||||
let results = await db_journals.journal_entry
|
||||
.where('journal_id')
|
||||
.equals($journals_slct?.journal_id ?? '') // null or undefined does not reset things like '' does
|
||||
@@ -91,7 +96,10 @@ let lq__journal_entry_obj_li = $derived(liveQuery(async () => {
|
||||
|
||||
return results;
|
||||
} else {
|
||||
console.log(`lq__journal_entry_obj_li - default query using journal_id: ${$journals_slct?.journal_id}`);
|
||||
if (log_lvl) {
|
||||
// console.log(`$lq__journal_obj.cfg_json = `, $lq__journal_obj?.cfg_json);
|
||||
console.log(`$journals_slct?.journal_id - default query using journal_id: ${$journals_slct?.journal_id}`);
|
||||
}
|
||||
let results = await db_journals.journal_entry
|
||||
.where('journal_id')
|
||||
.equals($journals_slct?.journal_id ?? '') // null or undefined does not reset things like '' does
|
||||
@@ -114,12 +122,15 @@ if ($journals_trig.journal_entry_li) {
|
||||
}
|
||||
|
||||
if ($journals_loc.qry__enabled !== 'all' || $journals_loc.qry__hidden !== 'all') {
|
||||
console.log(`Not set to all for enabled or hidden. Clearing all journal entries to be safe.`);
|
||||
|
||||
let results = db_journals.journal_entry
|
||||
.clear();
|
||||
console.log(`Deleted ${results} disabled journal entry.`);
|
||||
|
||||
if (log_lvl) {
|
||||
console.log(`Not set to all for enabled or hidden. Clearing all journal entries to be safe.`);
|
||||
console.log(`$journals_loc.qry__enabled = ${$journals_loc.qry__enabled}`);
|
||||
console.log(`$journals_loc.qry__hidden = ${$journals_loc.qry__hidden}`);
|
||||
}
|
||||
let results = db_journals.journal_entry.clear();
|
||||
if (log_lvl) {
|
||||
console.log(`Cleared all journal entries in the database.`, results);
|
||||
}
|
||||
}
|
||||
|
||||
$journals_prom.load__journal_entry_obj_li = journals_func.load_ae_obj_li__journal_entry({
|
||||
@@ -137,7 +148,7 @@ if ($journals_trig.journal_entry_li) {
|
||||
});
|
||||
|
||||
if (browser) {
|
||||
console.log('Browser environment detected.');
|
||||
// console.log('Browser environment detected.');
|
||||
|
||||
let message = {'journal_id': $journals_slct?.journal_id ?? null};
|
||||
window.parent.postMessage(message, "*");
|
||||
|
||||
@@ -3,20 +3,20 @@
|
||||
let log_lvl: number = 0;
|
||||
|
||||
// *** Import Svelte specific
|
||||
import { browser } from '$app/environment';
|
||||
// import { browser } from '$app/environment';
|
||||
|
||||
// *** Import other supporting libraries
|
||||
import { Modal } from 'flowbite-svelte';
|
||||
// import { Modal } from 'flowbite-svelte';
|
||||
import { liveQuery } from "dexie";
|
||||
|
||||
// *** Import Aether specific variables and functions
|
||||
// import type { key_val } from '$lib/ae_stores';
|
||||
import { ae_util } from '$lib/ae_utils/ae_utils';
|
||||
// import { ae_util } from '$lib/ae_utils/ae_utils';
|
||||
// import { core_func } from '$lib/ae_core/ae_core_functions';
|
||||
import { db_journals } from "$lib/ae_journals/db_journals";
|
||||
import { ae_snip, ae_loc, ae_sess, ae_api, ae_trig, slct, slct_trigger } from '$lib/ae_stores';
|
||||
import { journals_loc, journals_sess, journals_slct, journals_prom, journals_trig } from '$lib/ae_journals/ae_journals_stores';
|
||||
import { journals_func } from '$lib/ae_journals/ae_journals_functions';
|
||||
// import { journals_func } from '$lib/ae_journals/ae_journals_functions';
|
||||
|
||||
// import Journal_entry_obj_id_edit from './ae_journals_comp__journal_entry_obj_id_edit.svelte';
|
||||
import Journal_entry_view from './../../../ae_comp__journal_entry_obj_id_view.svelte';
|
||||
@@ -69,7 +69,7 @@ let lq__journal_entry_obj = $derived(liveQuery(async () => {
|
||||
}
|
||||
let results = await db_journals.journal_entry
|
||||
.get($journals_slct.journal_entry_id ?? ''); // null or undefined does not reset things like '' does
|
||||
console.log(`lq__journal_entry_obj: results = `, results);
|
||||
// console.log(`lq__journal_entry_obj: results = `, results);
|
||||
|
||||
return results;
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user