Lots of work on the Journals
This commit is contained in:
@@ -4,6 +4,7 @@ let log_lvl: number = 0;
|
||||
|
||||
// *** Import Svelte specific
|
||||
import { browser } from '$app/environment';
|
||||
import { goto } from '$app/navigation';
|
||||
|
||||
// *** Import other supporting libraries
|
||||
import { Modal } from 'flowbite-svelte';
|
||||
@@ -59,12 +60,11 @@ let lq__journal_obj = $derived(liveQuery(async () => {
|
||||
return results;
|
||||
}));
|
||||
|
||||
let force_refresh = false; // Set to true to force a refresh of the data
|
||||
|
||||
let lq__journal_entry_obj_li = $derived(liveQuery(async () => {
|
||||
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);
|
||||
console.log(`force_refresh = `, force_refresh);
|
||||
}
|
||||
if ($lq__journal_obj?.cfg_json?.entry_group_sort === 'DESC') {
|
||||
let results = await db_journals.journal_entry
|
||||
@@ -77,24 +77,14 @@ let lq__journal_entry_obj_li = $derived(liveQuery(async () => {
|
||||
// .sortBy('title');
|
||||
|
||||
return results;
|
||||
// } else if (force_refresh) {
|
||||
// force_refresh = false;
|
||||
// console.log(`lq__journal_entry_obj_li - force refresh`);
|
||||
// let results = await db_journals.journal_entry
|
||||
// .where('journal_id')
|
||||
// .equals($journals_slct?.journal_id ?? '') // null or undefined does not reset things like '' does
|
||||
// // .reverse()
|
||||
// .sortBy('updated_on');
|
||||
|
||||
// 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}`);
|
||||
let results = await db_journals.journal_entry
|
||||
.where('journal_id')
|
||||
.equals($journals_slct?.journal_id ?? '') // null or undefined does not reset things like '' does
|
||||
.and(entry => entry.category_code === $journals_loc.filter__category_code)
|
||||
// .reverse()
|
||||
.sortBy('updated_on');
|
||||
.reverse()
|
||||
.sortBy('tmp_sort_1');
|
||||
|
||||
return results;
|
||||
} else {
|
||||
@@ -102,33 +92,18 @@ let lq__journal_entry_obj_li = $derived(liveQuery(async () => {
|
||||
let results = await db_journals.journal_entry
|
||||
.where('journal_id')
|
||||
.equals($journals_slct?.journal_id ?? '') // null or undefined does not reset things like '' does
|
||||
// .reverse()
|
||||
.sortBy('updated_on');
|
||||
.reverse()
|
||||
.sortBy('tmp_sort_1');
|
||||
// .sortBy('updated_on');
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
}));
|
||||
|
||||
// let lq__journal_entry_obj = $derived(liveQuery(async () => {
|
||||
// if (log_lvl) {
|
||||
// console.log(`lq__journal_entry_obj: journal_entry_id = ${$journals_slct?.journal_entry_id}`);
|
||||
// }
|
||||
// if ($journals_slct.journal_entry_id) {
|
||||
// let results = await db_journals.journal_entry
|
||||
// .get($journals_slct.journal_entry_id); // null or undefined does not reset things like '' does
|
||||
|
||||
// return results;
|
||||
// }
|
||||
// // const results = await db_journals.journal_entry
|
||||
// // .get($journals_slct.journal_entry_id); // null or undefined does not reset things like '' does
|
||||
|
||||
// // return results;
|
||||
// }));
|
||||
|
||||
|
||||
$effect(() => {
|
||||
if ($journals_trig.journal_entry_li) {
|
||||
if ($journals_trig.journal_entry_li) {
|
||||
$journals_trig.journal_entry_li = false;
|
||||
|
||||
if (log_lvl) {
|
||||
@@ -136,30 +111,14 @@ $effect(() => {
|
||||
}
|
||||
|
||||
if ($journals_loc.qry__enabled !== 'all' || $journals_loc.qry__hidden !== 'all') {
|
||||
console.log(`Deleting disabled or hidden journal entry.`);
|
||||
// let results = db_journals.journal_entry
|
||||
// .where('enable')
|
||||
// .notEqual(true)
|
||||
// .delete();
|
||||
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 ($journals_loc.qry__hidden !== 'all') {
|
||||
// console.log(`Deleting hidden journal entry.`);
|
||||
// let results = db_journals.journal_entry
|
||||
// .clear();
|
||||
// console.log(`Deleted ${results} hidden journal entry.`);
|
||||
|
||||
// }
|
||||
// let results = db_journals.journal_entry
|
||||
// .where('enable')
|
||||
// .equals('false')
|
||||
// .delete();
|
||||
// console.log(`Deleted ${results} disabled journal entry.`);
|
||||
|
||||
$journals_prom.load__journal_entry_obj_li = journals_func.load_ae_obj_li__journal_entry({
|
||||
api_cfg: $ae_api,
|
||||
for_obj_type: 'journal',
|
||||
@@ -174,38 +133,6 @@ $effect(() => {
|
||||
}
|
||||
});
|
||||
|
||||
// $effect(() => {
|
||||
// if ($journals_loc.filter__category_code) {
|
||||
// console.log(`Filtering journal entry by category_code: ${$journals_loc.filter__category_code}`);
|
||||
|
||||
// $journals_prom.load__journal_entry_obj_li = journals_func.load_ae_obj_li__journal_entry({
|
||||
// api_cfg: $ae_api,
|
||||
// for_obj_type: 'journal',
|
||||
// for_obj_id: $journals_slct.journal_id,
|
||||
// enabled: $journals_loc.qry__enabled,
|
||||
// hidden: $journals_loc.qry__hidden,
|
||||
// limit: $journals_loc.qry__limit,
|
||||
// order_by_li: $journals_loc.qry__order_by_li,
|
||||
// try_cache: true,
|
||||
// log_lvl: log_lvl,
|
||||
// });
|
||||
// } else {
|
||||
// console.log(`No category_code filter applied.`);
|
||||
// // force_refresh = true;
|
||||
// $journals_prom.load__journal_entry_obj_li = journals_func.load_ae_obj_li__journal_entry({
|
||||
// api_cfg: $ae_api,
|
||||
// for_obj_type: 'journal',
|
||||
// for_obj_id: $journals_slct.journal_id,
|
||||
// enabled: $journals_loc.qry__enabled,
|
||||
// hidden: $journals_loc.qry__hidden,
|
||||
// limit: $journals_loc.qry__limit,
|
||||
// order_by_li: $journals_loc.qry__order_by_li,
|
||||
// try_cache: true,
|
||||
// log_lvl: log_lvl,
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
|
||||
if (browser) {
|
||||
console.log('Browser environment detected.');
|
||||
|
||||
@@ -213,13 +140,6 @@ if (browser) {
|
||||
window.parent.postMessage(message, "*");
|
||||
}
|
||||
|
||||
let journal_entry_category_li = [
|
||||
{ code: 'test', name: 'Test' },
|
||||
{ code: 'personal', name: 'Personal' },
|
||||
{ code: 'work', name: 'Work' },
|
||||
{ code: 'other', name: 'Other' },
|
||||
];
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
@@ -247,8 +167,6 @@ let journal_entry_category_li = [
|
||||
<!-- <h1>Journals {$lq__journal_obj?.name} - {$lq__journal_entry_obj_li?.length}</h1> -->
|
||||
|
||||
<div class="flex flex-row items-center justify-between w-full">
|
||||
{$journals_loc.filter__category_code}
|
||||
|
||||
<a href="/journals" class="novi_btn btn btn-secondary btn-sm
|
||||
variant-ghost-tertiary
|
||||
hover:variant-filled-tertiary
|
||||
@@ -260,59 +178,74 @@ let journal_entry_category_li = [
|
||||
</a>
|
||||
|
||||
<!-- Add default journal entry -->
|
||||
<button
|
||||
class="novi_btn btn btn-secondary btn-sm
|
||||
variant-ghost-success
|
||||
hover:variant-filled-success
|
||||
transition"
|
||||
onclick={() => {
|
||||
// $journals_sess.show__modal_new__journal_entry_obj = true;
|
||||
<span class="flex flex-row items-center gap-2">
|
||||
<span class="text-sm text-gray-500 hidden md:inline">
|
||||
New Entry:
|
||||
</span>
|
||||
<button
|
||||
class="btn btn-sm
|
||||
variant-ghost-success
|
||||
hover:variant-filled-success
|
||||
transition"
|
||||
onclick={() => {
|
||||
// $journals_sess.show__modal_new__journal_entry_obj = true;
|
||||
|
||||
let data_kv = {
|
||||
// journal_id_random: $lq__journal_obj?.journal_id,
|
||||
category_code: 'test',
|
||||
};
|
||||
if ($journals_loc.qry__category_code) {
|
||||
data_kv.category_code = $journals_loc.qry__category_code;
|
||||
}
|
||||
if (log_lvl) {
|
||||
console.log('Creating new journal entry with data_kv:', data_kv);
|
||||
}
|
||||
journals_func.create_ae_obj__journal_entry({
|
||||
api_cfg: $ae_api,
|
||||
journal_id: $lq__journal_obj?.journal_id,
|
||||
data_kv: data_kv,
|
||||
log_lvl: log_lvl
|
||||
}).then((results) => {
|
||||
console.log('New journal entry created:', results);
|
||||
$journals_slct.journal_entry_id = results?.journal_entry_id_random;
|
||||
// alert('Journal entry created successfully!');
|
||||
}).catch((error) => {
|
||||
console.error('Error updating journal entry:', error);
|
||||
alert('Failed to update journal entry.');
|
||||
});
|
||||
}}
|
||||
>
|
||||
<span class="fas fa-plus m-1"></span> New Journal Entry
|
||||
</button>
|
||||
let data_kv = {
|
||||
// journal_id_random: $lq__journal_obj?.journal_id,
|
||||
category_code: 'test',
|
||||
};
|
||||
if ($journals_loc.qry__category_code) {
|
||||
data_kv.category_code = $journals_loc.qry__category_code;
|
||||
}
|
||||
if (log_lvl) {
|
||||
console.log('Creating new journal entry with data_kv:', data_kv);
|
||||
}
|
||||
journals_func.create_ae_obj__journal_entry({
|
||||
api_cfg: $ae_api,
|
||||
journal_id: $lq__journal_obj?.journal_id,
|
||||
data_kv: data_kv,
|
||||
log_lvl: log_lvl
|
||||
}).then((results) => {
|
||||
console.log('New journal entry created:', results);
|
||||
$journals_slct.journal_entry_id = results?.journal_entry_id_random;
|
||||
// alert(`Journal entry created successfully! ${$journals_slct.journal_entry_id}`);
|
||||
}).catch((error) => {
|
||||
console.error('Error updating journal entry:', error);
|
||||
alert('Failed to update journal entry.');
|
||||
}).finally(() => {
|
||||
goto(`/journals/${$lq__journal_obj?.journal_id}/entry/${$journals_slct.journal_entry_id}`);
|
||||
});
|
||||
}}
|
||||
>
|
||||
<span class="fas fa-plus m-1"></span> New Journal Entry
|
||||
</button>
|
||||
|
||||
<!-- Give list of categories to base the new entry on -->
|
||||
<select
|
||||
class="novi_btn btn btn-secondary btn-sm
|
||||
variant-ghost-primary
|
||||
hover:variant-filled-primary
|
||||
transition"
|
||||
bind:value={$journals_loc.qry__category_code}
|
||||
onchange={(event) => {
|
||||
$journals_loc.qry__category_code = event.target.value;
|
||||
console.log('Selected category:', $journals_loc.qry__category_code);
|
||||
}}
|
||||
>
|
||||
<option value="">Select Category</option>
|
||||
{#each journal_entry_category_li as category}
|
||||
<option value={category.code}>{category.name}</option>
|
||||
{/each}
|
||||
</select>
|
||||
<!-- Give list of categories to base the new entry on -->
|
||||
<span class="flex flex-row items-center gap-2">
|
||||
<span class="text-sm text-gray-500 hidden sm:inline">
|
||||
Category:
|
||||
</span>
|
||||
<select
|
||||
class="novi_btn btn btn-secondary btn-sm
|
||||
variant-soft-primary
|
||||
hover:variant-filled-primary
|
||||
transition
|
||||
text-xs
|
||||
"
|
||||
bind:value={$journals_loc.qry__category_code}
|
||||
onchange={(event) => {
|
||||
$journals_loc.qry__category_code = event.target.value;
|
||||
console.log('Selected category:', $journals_loc.qry__category_code);
|
||||
}}
|
||||
title="Select a category for the new journal entry"
|
||||
>
|
||||
<option value="">Select Category</option>
|
||||
{#each $lq__journal_obj?.cfg_json.category_li as category}
|
||||
<option value={category.code}>{category.name}</option>
|
||||
{/each}
|
||||
</select>
|
||||
</span>
|
||||
</span>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
@@ -40,11 +40,20 @@ if (log_lvl) {
|
||||
console.log(`ae_acct = `, ae_acct);
|
||||
}
|
||||
|
||||
$journals_slct.journal_id = ae_acct.slct.journal_id;
|
||||
let lq__journal_obj = $derived(liveQuery(async () => {
|
||||
let results = await db_journals.journal
|
||||
.where('id')
|
||||
.equals($journals_slct.journal_id)
|
||||
.first();
|
||||
|
||||
return results;
|
||||
}));
|
||||
|
||||
// For some reason data.params.journal_entry_id (or whatever param) is not being passed to this page when loaded by a link from another page. This seems to be a bug with Svelte or SvelteKit. Hopefully fixed in a future version 5? 2024-11-06
|
||||
$journals_slct.journal_entry_id = ae_acct.slct.journal_entry_id;
|
||||
// $journals_slct.journal_entry_obj = ae_acct.slct.journal_entry_obj;
|
||||
|
||||
|
||||
let lq__journal_entry_obj = $derived(liveQuery(async () => {
|
||||
if (log_lvl) {
|
||||
console.log(`lq__journal_entry_obj: journal_entry_id = ${$journals_slct?.journal_entry_id}`);
|
||||
@@ -192,6 +201,7 @@ if (browser) {
|
||||
|
||||
{#if $lq__journal_entry_obj}
|
||||
<Journal_entry_view
|
||||
lq__journal_obj={lq__journal_obj}
|
||||
lq__journal_entry_obj={lq__journal_entry_obj}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
@@ -14,6 +14,9 @@ export async function load({ params, parent }) { // route
|
||||
let account_id = data.account_id;
|
||||
let ae_acct = data[account_id];
|
||||
|
||||
let journal_id = params.journal_id;
|
||||
ae_acct.slct.journal_id = journal_id;
|
||||
|
||||
let journal_entry_id = params.journal_entry_id;
|
||||
if (!journal_entry_id) {
|
||||
console.log(`ae_journals journals [journal_entry_id] +page.ts: The journal_entry_id was not found in the params!!!`);
|
||||
|
||||
Reference in New Issue
Block a user