Fix: Stabilize Journal Entries query logic and UI search behavior
- Consolidated LiveQuery logic into [journal_id]/+page.svelte and removed redundancy from layout. - Added automatic load trigger on journal_id change to ensure data freshness. - Hardened Enabled/Hidden filters to correctly include NULL/undefined values in default views. - Refined search behavior to distinguish between "default view" (null) and "no results found" ([]). - Updated modal_journals_config.svelte with standardized module-level settings. - Robust ID handling in bulk retrieval to handle varying property names (id, random_id).
This commit is contained in:
@@ -21,14 +21,6 @@ const journals_local_data_struct: key_val = {
|
|||||||
time_format: 'time_12_short',
|
time_format: 'time_12_short',
|
||||||
time_hours: 12, // 12 or 24
|
time_hours: 12, // 12 or 24
|
||||||
|
|
||||||
qry__enabled: 'enabled', // all, disabled, enabled
|
|
||||||
qry__hidden: 'not_hidden', // all, hidden, not_hidden
|
|
||||||
qry__limit: 20,
|
|
||||||
qry__order_by_li: {
|
|
||||||
// 'created_on': 'desc',
|
|
||||||
// 'updated_on': 'desc',
|
|
||||||
},
|
|
||||||
qry__offset: 0,
|
|
||||||
qry__journal_id: null,
|
qry__journal_id: null,
|
||||||
|
|
||||||
journal_view_history_li: [], // Appended each time the journal is loaded.
|
journal_view_history_li: [], // Appended each time the journal is loaded.
|
||||||
@@ -58,6 +50,17 @@ const journals_local_data_struct: key_val = {
|
|||||||
edit: false,
|
edit: false,
|
||||||
edit_kv: {},
|
edit_kv: {},
|
||||||
|
|
||||||
|
// Query / Search Settings
|
||||||
|
qry__search_text: '',
|
||||||
|
qry__enabled: 'enabled', // all, disabled, enabled
|
||||||
|
qry__hidden: 'not_hidden', // all, hidden, not_hidden
|
||||||
|
qry__limit: 25,
|
||||||
|
qry__offset: 0,
|
||||||
|
qry__order_by_li: {
|
||||||
|
// 'created_on': 'desc',
|
||||||
|
// 'updated_on': 'desc',
|
||||||
|
},
|
||||||
|
|
||||||
type_code_li: [
|
type_code_li: [
|
||||||
{ code: 'diary', name: 'Diary' },
|
{ code: 'diary', name: 'Diary' },
|
||||||
{ code: 'log', name: 'Log' },
|
{ code: 'log', name: 'Log' },
|
||||||
@@ -72,6 +75,24 @@ const journals_local_data_struct: key_val = {
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
entry: {
|
entry: {
|
||||||
|
edit: false,
|
||||||
|
edit_kv: {},
|
||||||
|
|
||||||
|
// Query / Search Settings
|
||||||
|
qry__search_text: '',
|
||||||
|
qry__category_code: '', // For filtering
|
||||||
|
qry__enabled: 'enabled', // all, disabled, enabled
|
||||||
|
qry__hidden: 'not_hidden', // all, hidden, not_hidden
|
||||||
|
qry__limit: 50,
|
||||||
|
qry__offset: 0,
|
||||||
|
qry__order_by_li: {
|
||||||
|
// 'created_on': 'desc',
|
||||||
|
// 'updated_on': 'desc',
|
||||||
|
},
|
||||||
|
|
||||||
|
// This is effectively "last used journal for creating entries"
|
||||||
|
qry__journal_id: null,
|
||||||
|
|
||||||
llm__system_prompt:
|
llm__system_prompt:
|
||||||
'Summarize the following journal entry content in a concise manner, focusing on key points and insights.',
|
'Summarize the following journal entry content in a concise manner, focusing on key points and insights.',
|
||||||
llm__max_tokens: 512,
|
llm__max_tokens: 512,
|
||||||
@@ -81,9 +102,7 @@ const journals_local_data_struct: key_val = {
|
|||||||
llm__frequency_penalty: 0.0,
|
llm__frequency_penalty: 0.0,
|
||||||
llm__presence_penalty: 0.0,
|
llm__presence_penalty: 0.0,
|
||||||
|
|
||||||
auto_save: false,
|
auto_save: false
|
||||||
edit: false,
|
|
||||||
edit_kv: {}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// console.log(`AE Stores - App Journals Local Storage Data:`, journals_local_data_struct);
|
// console.log(`AE Stores - App Journals Local Storage Data:`, journals_local_data_struct);
|
||||||
|
|||||||
@@ -26,10 +26,11 @@
|
|||||||
}
|
}
|
||||||
let { data, children }: Props = $props();
|
let { data, children }: Props = $props();
|
||||||
|
|
||||||
$journals_loc.qry__enabled = 'enabled';
|
// Initialize/Reset Entry Query defaults on layout load
|
||||||
$journals_loc.qry__hidden = 'not_hidden';
|
// $journals_loc.entry.qry__enabled = 'enabled';
|
||||||
$journals_loc.qry__limit = 15;
|
// $journals_loc.entry.qry__hidden = 'not_hidden';
|
||||||
$journals_loc.qry__offset = 0;
|
// $journals_loc.entry.qry__limit = 15;
|
||||||
|
// $journals_loc.entry.qry__offset = 0;
|
||||||
|
|
||||||
// Quickly save the data passed from the parent(s) to the Svelte stores, localStorage, and other.
|
// Quickly save the data passed from the parent(s) to the Svelte stores, localStorage, and other.
|
||||||
$slct.account_id = data.account_id;
|
$slct.account_id = data.account_id;
|
||||||
|
|||||||
@@ -68,104 +68,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let lq__journal_entry_obj_li = $derived(
|
|
||||||
liveQuery(async () => {
|
|
||||||
let results;
|
|
||||||
|
|
||||||
if ($journals_sess?.entry_li && $journals_sess?.entry_li?.length) {
|
|
||||||
// $journals_sess.entry_li_trigger = false;
|
|
||||||
let journal_entry_id_random_li = []; // This is to prevent the array from constantly updating and triggering the liveQuery.
|
|
||||||
|
|
||||||
for (let i = 0; i < $journals_sess?.entry_li.length; i++) {
|
|
||||||
let journal_entry_obj = $journals_sess?.entry_li[i];
|
|
||||||
let journal_entry_id_random = journal_entry_obj.journal_entry_id_random;
|
|
||||||
journal_entry_id_random_li.push(journal_entry_id_random);
|
|
||||||
}
|
|
||||||
// let journal_entry_id_random_li = tmp_li;
|
|
||||||
|
|
||||||
results = await db_journals.journal_entry.bulkGet(journal_entry_id_random_li);
|
|
||||||
} else if ($lq__journal_obj?.cfg_json?.entry_group_sort === 'DESC') {
|
|
||||||
results = await db_journals.journal_entry
|
|
||||||
// .orderBy('updated_on')
|
|
||||||
.where('journal_id')
|
|
||||||
.equals($journals_slct?.journal_id ?? '') // null or undefined does not reset things like '' does
|
|
||||||
.reverse()
|
|
||||||
// .sortBy('tmp_sort_2');
|
|
||||||
.sortBy('updated_on');
|
|
||||||
// .sortBy('title');
|
|
||||||
} else if (
|
|
||||||
$journals_loc.filter__category_code &&
|
|
||||||
$journals_loc.filter__category_code.length > 0
|
|
||||||
) {
|
|
||||||
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('tmp_sort_1');
|
|
||||||
} else {
|
|
||||||
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('tmp_sort_1');
|
|
||||||
// .sortBy('updated_on');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if results are different than the current session version stored under $journals_slct
|
|
||||||
if (
|
|
||||||
$journals_slct.journal_entry_obj_li &&
|
|
||||||
JSON.stringify($journals_slct.journal_entry_obj_li) !== JSON.stringify(results)
|
|
||||||
) {
|
|
||||||
$journals_slct.journal_entry_obj_li = [...results];
|
|
||||||
}
|
|
||||||
|
|
||||||
return results;
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
$effect(() => {
|
|
||||||
if (log_lvl) {
|
|
||||||
console.log(`LQ - $lq__journal_obj.cfg_json = `, $lq__journal_obj?.cfg_json);
|
|
||||||
console.log(
|
|
||||||
`LQ - $journals_loc.filter__category_code = `,
|
|
||||||
$journals_loc.filter__category_code
|
|
||||||
);
|
|
||||||
if ($journals_sess?.entry_li && $journals_sess?.entry_li?.length) {
|
|
||||||
console.log(`LQ - Using $journals_sess.entry_li to get journal entries.`);
|
|
||||||
} else if ($lq__journal_obj?.cfg_json?.entry_group_sort === 'DESC') {
|
|
||||||
console.log(
|
|
||||||
`LQ - Using DESC sort for Journal Entry list journal_id: ${$journals_slct?.journal_id}`
|
|
||||||
);
|
|
||||||
} else if (
|
|
||||||
$journals_loc.filter__category_code &&
|
|
||||||
$journals_loc.filter__category_code.length > 0
|
|
||||||
) {
|
|
||||||
console.log(`LQ - Using category filter: ${$journals_loc.filter__category_code}`);
|
|
||||||
} else {
|
|
||||||
console.log(
|
|
||||||
`LQ - Using default sort for Journal Entry list journal_id: ${$journals_slct?.journal_id}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
$journals_slct.journal_entry_obj_li &&
|
|
||||||
JSON.stringify($journals_slct.journal_entry_obj_li) !==
|
|
||||||
JSON.stringify(lq__journal_entry_obj_li)
|
|
||||||
) {
|
|
||||||
console.log(
|
|
||||||
`Session slct li stored version has changed for ID = ${$journals_slct.journal_id}`,
|
|
||||||
$journals_slct.journal_entry_obj_li
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
if (log_lvl > 1) {
|
|
||||||
console.log(
|
|
||||||
`Session slct li stored version has not changed for ID = ${$journals_slct.journal_id}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- Svelte layout for a Journal ID page and children -->
|
<!-- Svelte layout for a Journal ID page and children -->
|
||||||
@@ -221,7 +123,8 @@
|
|||||||
hover:preset-filled-tertiary-300-700
|
hover:preset-filled-tertiary-300-700
|
||||||
transition-all
|
transition-all
|
||||||
"
|
"
|
||||||
title={`View all journals menu: "${$ae_loc?.user?.name}"\nMiddle-click to open in new tab`}
|
title={`View all journals menu: "${$ae_loc?.user?.name}"
|
||||||
|
Middle-click to open in new tab`}
|
||||||
>
|
>
|
||||||
<!-- <BookHeart /> -->
|
<!-- <BookHeart /> -->
|
||||||
<!-- <Library /> -->
|
<!-- <Library /> -->
|
||||||
@@ -348,8 +251,7 @@
|
|||||||
hover:variant-filled-warning
|
hover:variant-filled-warning
|
||||||
transition
|
transition
|
||||||
"
|
"
|
||||||
title="Edit Journal meta and configuration (name, type, passcode, categories, etc.: {$lq__journal_obj?.name})"
|
title="Edit Journal meta and configuration (name, type, passcode, categories, etc.: {$lq__journal_obj?.name})">
|
||||||
>
|
|
||||||
<Pencil />
|
<Pencil />
|
||||||
<span class="hidden md:inline">
|
<span class="hidden md:inline">
|
||||||
Edit Journal
|
Edit Journal
|
||||||
@@ -371,8 +273,8 @@
|
|||||||
let data_kv = {
|
let data_kv = {
|
||||||
category_code: null
|
category_code: null
|
||||||
};
|
};
|
||||||
if ($journals_loc.qry__category_code) {
|
if ($journals_loc.entry.qry__category_code) {
|
||||||
data_kv.category_code = $journals_loc.qry__category_code;
|
data_kv.category_code = $journals_loc.entry.qry__category_code;
|
||||||
}
|
}
|
||||||
if (log_lvl) {
|
if (log_lvl) {
|
||||||
console.log('Creating new journal entry with data_kv:', data_kv);
|
console.log('Creating new journal entry with data_kv:', data_kv);
|
||||||
@@ -425,7 +327,7 @@
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- <div class="overflow-auto"> -->
|
<div class="overflow-auto">
|
||||||
{@render children?.()}
|
{@render children?.()}
|
||||||
<!-- </div> -->
|
</div>
|
||||||
</section>
|
</section>
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
// *** Import Svelte specific
|
// *** Import Svelte specific
|
||||||
import { browser } from '$app/environment';
|
import { browser } from '$app/environment';
|
||||||
// import { goto } from '$app/navigation';
|
// import { goto } from '$app/navigation';
|
||||||
|
import { untrack } from 'svelte';
|
||||||
|
|
||||||
// *** Import other supporting libraries
|
// *** Import other supporting libraries
|
||||||
// import {
|
// import {
|
||||||
@@ -111,7 +112,7 @@
|
|||||||
|
|
||||||
$journals_slct.journal_id = ae_acct.slct.journal_id;
|
$journals_slct.journal_id = ae_acct.slct.journal_id;
|
||||||
|
|
||||||
$journals_sess.entry_li = [];
|
$journals_sess.entry_li = null;
|
||||||
$journals_slct.journal_entry_id = null;
|
$journals_slct.journal_entry_id = null;
|
||||||
|
|
||||||
let lq__journal_obj = $derived(
|
let lq__journal_obj = $derived(
|
||||||
@@ -150,52 +151,93 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Trigger load of entries when the journal_id changes
|
||||||
|
$effect(() => {
|
||||||
|
if ($journals_slct.journal_id) {
|
||||||
|
untrack(() => {
|
||||||
|
if (log_lvl) console.log(`Triggering load for journal_id: ${$journals_slct.journal_id}`);
|
||||||
|
$journals_trig.journal_entry_li = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
let lq__journal_entry_obj_li = $derived(
|
let lq__journal_entry_obj_li = $derived(
|
||||||
liveQuery(async () => {
|
liveQuery(async () => {
|
||||||
let results;
|
let results;
|
||||||
|
|
||||||
if ($journals_sess.entry_li_trigger && !$journals_sess?.entry_li) {
|
// If we have a specific list in the session (e.g. from a search), use it.
|
||||||
$journals_sess.entry_li = null;
|
if ($journals_sess?.entry_li !== null && $journals_sess?.entry_li !== undefined) {
|
||||||
$journals_sess.entry_li_trigger = false;
|
if ($journals_sess.entry_li.length === 0) {
|
||||||
}
|
if (log_lvl) {
|
||||||
|
console.log(`LQ - Using empty $journals_sess.entry_li to get journal entries.`);
|
||||||
|
}
|
||||||
|
|
||||||
if ($journals_sess?.entry_li && $journals_sess?.entry_li?.length) {
|
results = [];
|
||||||
let journal_entry_id_random_li = []; // This is to prevent the array from constantly updating and triggering the liveQuery.
|
} else {
|
||||||
|
if (log_lvl) {
|
||||||
|
console.log(`LQ - Using $journals_sess.entry_li to get journal entries.`);
|
||||||
|
}
|
||||||
|
|
||||||
for (let i = 0; i < $journals_sess?.entry_li.length; i++) {
|
let journal_entry_id_random_li = []; // This is to prevent the array from constantly updating and triggering the liveQuery.
|
||||||
let journal_entry_obj = $journals_sess?.entry_li[i];
|
|
||||||
let journal_entry_id_random = journal_entry_obj.journal_entry_id_random;
|
for (let i = 0; i < $journals_sess?.entry_li.length; i++) {
|
||||||
journal_entry_id_random_li.push(journal_entry_id_random);
|
let journal_entry_obj = $journals_sess?.entry_li[i];
|
||||||
|
// Robust ID extraction: try id, then journal_entry_id_random, then journal_entry_id
|
||||||
|
let target_id = journal_entry_obj.id || journal_entry_obj.journal_entry_id_random || journal_entry_obj.journal_entry_id;
|
||||||
|
|
||||||
|
if (target_id) {
|
||||||
|
journal_entry_id_random_li.push(target_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
results = await db_journals.journal_entry.bulkGet(journal_entry_id_random_li);
|
||||||
|
// Filter out any undefined results (e.g. if ID not found in local DB yet)
|
||||||
|
results = results.filter(item => item !== undefined);
|
||||||
}
|
}
|
||||||
// let journal_entry_id_random_li = tmp_li;
|
|
||||||
|
|
||||||
results = await db_journals.journal_entry.bulkGet(journal_entry_id_random_li);
|
|
||||||
} else if ($lq__journal_obj?.cfg_json?.entry_group_sort === 'DESC') {
|
|
||||||
results = await db_journals.journal_entry
|
|
||||||
// .orderBy('updated_on')
|
|
||||||
.where('journal_id')
|
|
||||||
.equals($journals_slct?.journal_id ?? '') // null or undefined does not reset things like '' does
|
|
||||||
.reverse()
|
|
||||||
// .sortBy('tmp_sort_2');
|
|
||||||
.sortBy('updated_on');
|
|
||||||
// .sortBy('title');
|
|
||||||
} else if (
|
|
||||||
$journals_loc.filter__category_code &&
|
|
||||||
$journals_loc.filter__category_code.length > 0
|
|
||||||
) {
|
|
||||||
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('tmp_sort_1');
|
|
||||||
} else {
|
} else {
|
||||||
results = await db_journals.journal_entry
|
if (log_lvl) {
|
||||||
|
console.log(`LQ - No $journals_sess.entry_li set. Querying local DB for journal entries for journal_id: ${$journals_slct?.journal_id}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise, query the local database based on the current journal context and filters.
|
||||||
|
let collection = db_journals.journal_entry
|
||||||
.where('journal_id')
|
.where('journal_id')
|
||||||
.equals($journals_slct?.journal_id ?? '') // null or undefined does not reset things like '' does
|
.equals($journals_slct?.journal_id ?? ''); // null or undefined does not reset things like '' does
|
||||||
.reverse()
|
|
||||||
.sortBy('tmp_sort_1');
|
// Apply Category Filter
|
||||||
// .sortBy('updated_on');
|
if (
|
||||||
|
$journals_loc.entry.qry__category_code &&
|
||||||
|
$journals_loc.entry.qry__category_code.length > 0
|
||||||
|
) {
|
||||||
|
collection = collection.and(
|
||||||
|
(entry) => entry.category_code === $journals_loc.entry.qry__category_code
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply Enabled Filter
|
||||||
|
if ($journals_loc.entry.qry__enabled === 'enabled') {
|
||||||
|
collection = collection.and((entry) => entry.enable === true || entry.enable === null || entry.enable === undefined);
|
||||||
|
} else if ($journals_loc.entry.qry__enabled === 'not_enabled') {
|
||||||
|
collection = collection.and((entry) => entry.enable === false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply Hidden Filter
|
||||||
|
if ($journals_loc.entry.qry__hidden === 'hidden') {
|
||||||
|
collection = collection.and((entry) => entry.hide === true);
|
||||||
|
} else if ($journals_loc.entry.qry__hidden === 'not_hidden') {
|
||||||
|
collection = collection.and((entry) => entry.hide === false || entry.hide === null || entry.hide === undefined);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply Sorting
|
||||||
|
if ($lq__journal_obj?.cfg_json?.entry_group_sort === 'DESC') {
|
||||||
|
results = await collection.reverse().sortBy('updated_on');
|
||||||
|
} else {
|
||||||
|
results = await collection.reverse().sortBy('tmp_sort_1');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply Limit (after sorting)
|
||||||
|
if ($journals_loc.entry.qry__limit && $journals_loc.entry.qry__limit > 0) {
|
||||||
|
results = results.slice(0, $journals_loc.entry.qry__limit);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if results are different than the current session version stored under $journals_slct
|
// Check if results are different than the current session version stored under $journals_slct
|
||||||
@@ -214,20 +256,20 @@
|
|||||||
if (log_lvl) {
|
if (log_lvl) {
|
||||||
console.log(`LQ - $lq__journal_obj.cfg_json = `, $lq__journal_obj?.cfg_json);
|
console.log(`LQ - $lq__journal_obj.cfg_json = `, $lq__journal_obj?.cfg_json);
|
||||||
console.log(
|
console.log(
|
||||||
`LQ - $journals_loc.filter__category_code = `,
|
`LQ - $journals_loc.entry.qry__category_code = `,
|
||||||
$journals_loc.filter__category_code
|
$journals_loc.entry.qry__category_code
|
||||||
);
|
);
|
||||||
if ($journals_sess?.entry_li && $journals_sess?.entry_li?.length) {
|
if ($journals_sess?.entry_li !== null) {
|
||||||
console.log(`LQ - Using $journals_sess.entry_li to get journal entries.`);
|
console.log(`LQ - Using $journals_sess.entry_li to get journal entries.`);
|
||||||
} else if ($lq__journal_obj?.cfg_json?.entry_group_sort === 'DESC') {
|
} else if ($lq__journal_obj?.cfg_json?.entry_group_sort === 'DESC') {
|
||||||
console.log(
|
console.log(
|
||||||
`LQ - Using DESC sort for Journal Entry list journal_id: ${$journals_slct?.journal_id}`
|
`LQ - Using DESC sort for Journal Entry list journal_id: ${$journals_slct?.journal_id}`
|
||||||
);
|
);
|
||||||
} else if (
|
} else if (
|
||||||
$journals_loc.filter__category_code &&
|
$journals_loc.entry.qry__category_code &&
|
||||||
$journals_loc.filter__category_code.length > 0
|
$journals_loc.entry.qry__category_code.length > 0
|
||||||
) {
|
) {
|
||||||
console.log(`LQ - Using category filter: ${$journals_loc.filter__category_code}`);
|
console.log(`LQ - Using category filter: ${$journals_loc.entry.qry__category_code}`);
|
||||||
} else {
|
} else {
|
||||||
console.log(
|
console.log(
|
||||||
`LQ - Using default sort for Journal Entry list journal_id: ${$journals_slct?.journal_id}`
|
`LQ - Using default sort for Journal Entry list journal_id: ${$journals_slct?.journal_id}`
|
||||||
@@ -268,13 +310,13 @@
|
|||||||
console.log(`Triggered: $journals_trig.journal_entry_li`);
|
console.log(`Triggered: $journals_trig.journal_entry_li`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($journals_loc.qry__enabled !== 'all' || $journals_loc.qry__hidden !== 'all') {
|
if ($journals_loc.entry.qry__enabled !== 'all' || $journals_loc.entry.qry__hidden !== 'all') {
|
||||||
if (log_lvl) {
|
if (log_lvl) {
|
||||||
console.log(
|
console.log(
|
||||||
`Not set to all for enabled or hidden. Clearing all journal entries to be safe.`
|
`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.entry.qry__enabled = ${$journals_loc.entry.qry__enabled}`);
|
||||||
console.log(`$journals_loc.qry__hidden = ${$journals_loc.qry__hidden}`);
|
console.log(`$journals_loc.entry.qry__hidden = ${$journals_loc.entry.qry__hidden}`);
|
||||||
}
|
}
|
||||||
let results = db_journals.journal_entry.clear();
|
let results = db_journals.journal_entry.clear();
|
||||||
if (log_lvl) {
|
if (log_lvl) {
|
||||||
@@ -287,10 +329,10 @@
|
|||||||
api_cfg: $ae_api,
|
api_cfg: $ae_api,
|
||||||
for_obj_type: 'journal',
|
for_obj_type: 'journal',
|
||||||
for_obj_id: $journals_slct.journal_id,
|
for_obj_id: $journals_slct.journal_id,
|
||||||
enabled: $journals_loc.qry__enabled,
|
enabled: $journals_loc.entry.qry__enabled,
|
||||||
hidden: $journals_loc.qry__hidden,
|
hidden: $journals_loc.entry.qry__hidden,
|
||||||
limit: $journals_loc.qry__limit,
|
limit: $journals_loc.entry.qry__limit,
|
||||||
order_by_li: $journals_loc.qry__order_by_li,
|
order_by_li: $journals_loc.entry.qry__order_by_li,
|
||||||
try_cache: true,
|
try_cache: true,
|
||||||
log_lvl: log_lvl
|
log_lvl: log_lvl
|
||||||
}
|
}
|
||||||
@@ -336,18 +378,18 @@
|
|||||||
"
|
"
|
||||||
> -->
|
> -->
|
||||||
|
|
||||||
<Journal_view
|
<Journal_view
|
||||||
{lq__journal_obj}
|
{lq__journal_obj}
|
||||||
{lq__journal_entry_obj_li}
|
{lq__journal_entry_obj_li}
|
||||||
onShowExport={() => show_export_modal = true}
|
onShowExport={() => show_export_modal = true}
|
||||||
onShowImport={() => show_import_modal = true}
|
onShowImport={() => show_import_modal = true}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{#if $lq__journal_entry_obj_li && $lq__journal_entry_obj_li?.length}
|
{#if $lq__journal_entry_obj_li && $lq__journal_entry_obj_li?.length}
|
||||||
<Journal_entry_obj_li {lq__journal_obj} {lq__journal_entry_obj_li} />
|
<Journal_entry_obj_li {lq__journal_obj} {lq__journal_entry_obj_li} />
|
||||||
{:else}
|
{:else}
|
||||||
<section class="main_content grow px-1 md:px-2 pb-28 flex flex-col gap-1 items-center">
|
<section class="main_content grow px-1 md:px-2 pb-28 flex flex-col gap-1 items-center">
|
||||||
<p>No journal entry available to show.</p>
|
<p>No Journal Entry available to show. Please check the query filters or create a new Entry.</p>
|
||||||
</section>
|
</section>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
@@ -379,4 +421,4 @@
|
|||||||
<section class="main_content grow px-1 md:px-2 pb-28 flex flex-col gap-1 items-center">
|
<section class="main_content grow px-1 md:px-2 pb-28 flex flex-col gap-1 items-center">
|
||||||
<p class="text-center">You must be logged in as the owner to view this Journal.</p>
|
<p class="text-center">You must be logged in as the owner to view this Journal.</p>
|
||||||
</section>
|
</section>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -349,19 +349,17 @@
|
|||||||
type="button"
|
type="button"
|
||||||
onclick={() => {
|
onclick={() => {
|
||||||
if (
|
if (
|
||||||
$journals_loc.filter__category_code ==
|
$journals_loc.entry.qry__category_code ==
|
||||||
journals_journal_entry_obj.category_code
|
journals_journal_entry_obj.category_code
|
||||||
) {
|
) {
|
||||||
$journals_loc.filter__category_code = null;
|
$journals_loc.entry.qry__category_code = null;
|
||||||
} else {
|
} else {
|
||||||
$journals_loc.filter__category_code =
|
$journals_loc.entry.qry__category_code =
|
||||||
journals_journal_entry_obj.category_code;
|
|
||||||
$journals_loc.qry__category_code =
|
|
||||||
journals_journal_entry_obj.category_code;
|
journals_journal_entry_obj.category_code;
|
||||||
}
|
}
|
||||||
$journals_trig.journal_entry_li = true;
|
$journals_trig.journal_entry_li = true;
|
||||||
}}
|
}}
|
||||||
class:bg-green-100={$journals_loc.filter__category_code ==
|
class:bg-green-100={$journals_loc.entry.qry__category_code ==
|
||||||
journals_journal_entry_obj.category_code}
|
journals_journal_entry_obj.category_code}
|
||||||
class="btn btn-sm variant-outline-secondary hover:preset-filled-secondary-500 transition py-1 px-2"
|
class="btn btn-sm variant-outline-secondary hover:preset-filled-secondary-500 transition py-1 px-2"
|
||||||
title={`Filter by category: ${journals_journal_entry_obj.category_code}`}
|
title={`Filter by category: ${journals_journal_entry_obj.category_code}`}
|
||||||
@@ -559,6 +557,6 @@
|
|||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
{:else}
|
{:else}
|
||||||
<p>No journal entry available to show.</p>
|
<p>No Æ Journal Entry available to show.</p>
|
||||||
{/if}
|
{/if}
|
||||||
</section>
|
</section>
|
||||||
@@ -77,7 +77,7 @@
|
|||||||
|
|
||||||
if (log_lvl) {
|
if (log_lvl) {
|
||||||
console.log(
|
console.log(
|
||||||
`Triggered: $journals_trig.journal_entry_qry: ${$journals_loc.qry__search_text}`
|
`Triggered: $journals_trig.journal_entry_qry: ${$journals_loc.entry.qry__search_text}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,36 +85,31 @@
|
|||||||
$journals_prom.load__journal_entry_obj_li = await journals_func.qry__journal_entry({
|
$journals_prom.load__journal_entry_obj_li = await journals_func.qry__journal_entry({
|
||||||
api_cfg: $ae_api,
|
api_cfg: $ae_api,
|
||||||
journal_id: $lq__journal_obj?.journal_id ?? '',
|
journal_id: $lq__journal_obj?.journal_id ?? '',
|
||||||
qry_str: $journals_loc.qry__search_text,
|
qry_str: $journals_loc.entry.qry__search_text,
|
||||||
|
|
||||||
// qry_created_on: null,
|
// qry_created_on: null,
|
||||||
// qry_alert: null,
|
// qry_alert: null,
|
||||||
// qry_priority: null,
|
// qry_priority: null,
|
||||||
// qry_type: and_type,
|
// qry_type: and_type,
|
||||||
|
|
||||||
enabled: 'enabled', // $journals_loc.qry__enabled,
|
enabled: $journals_loc.entry.qry__enabled ?? 'enabled',
|
||||||
hidden: 'not_hidden', // $journals_loc.qry__hidden,
|
hidden: $journals_loc.entry.qry__hidden ?? 'not_hidden',
|
||||||
// order_by_li: $journals_loc.qry__order_by_li,
|
// order_by_li: $journals_loc.entry.qry__order_by_li,
|
||||||
// limit: $journals_loc.qry__limit,
|
// limit: $journals_loc.entry.qry__limit,
|
||||||
// try_cache: try_cache,
|
// try_cache: try_cache,
|
||||||
log_lvl: log_lvl
|
log_lvl: log_lvl
|
||||||
});
|
});
|
||||||
if ($journals_prom.load__journal_entry_obj_li.length) {
|
|
||||||
|
if (!$journals_loc.entry.qry__search_text) {
|
||||||
|
// If search text was cleared or empty, reset to default view (null)
|
||||||
|
$journals_sess.entry_li = null;
|
||||||
|
} else if ($journals_prom.load__journal_entry_obj_li && $journals_prom.load__journal_entry_obj_li.length > 0) {
|
||||||
$journals_sess.entry_li = $journals_prom.load__journal_entry_obj_li;
|
$journals_sess.entry_li = $journals_prom.load__journal_entry_obj_li;
|
||||||
|
$journals_sess = { ...$journals_sess }; // ensure session is updated
|
||||||
$journals_sess = {
|
|
||||||
...$journals_sess
|
|
||||||
}; // ensure session is updated
|
|
||||||
|
|
||||||
// $journals_trig.journal_entry_li = true; // trigger the entry list to refresh
|
|
||||||
// $journals_trig.journal_entry_li = $journals_prom.load__journal_entry_obj_li;
|
|
||||||
} else {
|
} else {
|
||||||
console.log('Clear the search results: no entries found for that query.');
|
console.log('Clear the search results: no entries found for that query.');
|
||||||
// $journals_sess.entry_li = [''];
|
// Explicitly set to empty array to indicate "0 results found" (vs null which is "default view")
|
||||||
$journals_sess.entry_li = null;
|
$journals_sess.entry_li = [];
|
||||||
// $journals_trig.journal_entry_li = true;
|
|
||||||
// alert('No journal entries found for that search query.');
|
|
||||||
// $journals_sess = $journals_sess;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (log_lvl) {
|
if (log_lvl) {
|
||||||
@@ -131,10 +126,10 @@
|
|||||||
disabled={false}
|
disabled={false}
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="Search Journal Entries"
|
placeholder="Search Journal Entries"
|
||||||
bind:value={$journals_loc.qry__search_text}
|
bind:value={$journals_loc.entry.qry__search_text}
|
||||||
onkeyup={(event) => {
|
onkeyup={(event) => {
|
||||||
if (event.key === 'Enter') {
|
if (event.key === 'Enter') {
|
||||||
// $journals_loc.qry__search_text = (event.target as HTMLInputElement).value;
|
// $journals_loc.entry.qry__search_text = (event.target as HTMLInputElement).value;
|
||||||
$journals_trig.journal_entry_qry = true;
|
$journals_trig.journal_entry_qry = true;
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
@@ -151,11 +146,11 @@
|
|||||||
<!-- Clear search text button -->
|
<!-- Clear search text button -->
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
class:hidden={!$journals_loc.qry__search_text}
|
class:hidden={!$journals_loc.entry.qry__search_text}
|
||||||
onclick={() => {
|
onclick={() => {
|
||||||
console.log(`TESTING - 1 - Cleared search query: ${$journals_loc.qry__search_text}`);
|
console.log(`TESTING - 1 - Cleared search query: ${$journals_loc.entry.qry__search_text}`);
|
||||||
$journals_loc.qry__search_text = '';
|
$journals_loc.entry.qry__search_text = '';
|
||||||
console.log(`TESTING - 2 - Cleared search query: ${$journals_loc.qry__search_text}`);
|
console.log(`TESTING - 2 - Cleared search query: ${$journals_loc.entry.qry__search_text}`);
|
||||||
$journals_trig.journal_entry_qry = true;
|
$journals_trig.journal_entry_qry = true;
|
||||||
}}
|
}}
|
||||||
class="
|
class="
|
||||||
@@ -209,13 +204,13 @@
|
|||||||
hover:preset-filled-tertiary-100-900
|
hover:preset-filled-tertiary-100-900
|
||||||
transition-all
|
transition-all
|
||||||
"
|
"
|
||||||
bind:value={$journals_loc.qry__category_code}
|
bind:value={$journals_loc.entry.qry__category_code}
|
||||||
onchange={(event) => {
|
onchange={(event) => {
|
||||||
// WARNING: This will cause pages to reset if the journal entry list is being filtered by category. This is a bug that should be fixed.
|
// WARNING: This will cause pages to reset if the journal entry list is being filtered by category. This is a bug that should be fixed.
|
||||||
$journals_loc.qry__category_code = (event.target as HTMLInputElement).value;
|
$journals_loc.entry.qry__category_code = (event.target as HTMLInputElement).value;
|
||||||
$journals_loc.filter__category_code = (event.target as HTMLInputElement).value;
|
// $journals_loc.entry.qry__category_code = (event.target as HTMLInputElement).value;
|
||||||
$journals_trig.journal_entry_li = true;
|
$journals_trig.journal_entry_li = true;
|
||||||
console.log('Selected category:', $journals_loc.qry__category_code);
|
console.log('Selected category:', $journals_loc.entry.qry__category_code);
|
||||||
}}
|
}}
|
||||||
title="Select a category for the new journal entry"
|
title="Select a category for the new journal entry"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
// Derived / Local target
|
// Derived / Local target
|
||||||
// We prefer the persisted 'qry__journal_id' if we are on the main landing page
|
// We prefer the persisted 'qry__journal_id' if we are on the main landing page
|
||||||
let selected_journal_id = $state($journals_loc.qry__journal_id);
|
let selected_journal_id = $state($journals_loc.entry.qry__journal_id);
|
||||||
|
|
||||||
// If a journal is explicitly selected via slct (e.g. we are in a journal view), use that
|
// If a journal is explicitly selected via slct (e.g. we are in a journal view), use that
|
||||||
let target_journal_id = $derived($journals_slct.journal_id || selected_journal_id);
|
let target_journal_id = $derived($journals_slct.journal_id || selected_journal_id);
|
||||||
@@ -80,7 +80,7 @@
|
|||||||
function handle_journal_change(e: Event) {
|
function handle_journal_change(e: Event) {
|
||||||
const val = (e.target as HTMLSelectElement).value;
|
const val = (e.target as HTMLSelectElement).value;
|
||||||
selected_journal_id = val;
|
selected_journal_id = val;
|
||||||
$journals_loc.qry__journal_id = val; // Persist choice
|
$journals_loc.entry.qry__journal_id = val; // Persist choice
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -124,8 +124,8 @@
|
|||||||
let data_kv = {
|
let data_kv = {
|
||||||
category_code: null
|
category_code: null
|
||||||
};
|
};
|
||||||
if ($journals_loc.qry__category_code) {
|
if ($journals_loc.entry.qry__category_code) {
|
||||||
data_kv.category_code = $journals_loc.qry__category_code;
|
data_kv.category_code = $journals_loc.entry.qry__category_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -45,6 +45,7 @@
|
|||||||
// Internal State
|
// Internal State
|
||||||
let tab: 'form' | 'local_json' | 'session_json' = $state('form');
|
let tab: 'form' | 'local_json' | 'session_json' = $state('form');
|
||||||
let tmp_config: any = $state({
|
let tmp_config: any = $state({
|
||||||
|
journal: {},
|
||||||
entry: {}
|
entry: {}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -160,6 +161,58 @@
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<!-- Journal Query Filters Section -->
|
||||||
|
<section class="space-y-4">
|
||||||
|
<h2 class="text-xl font-bold flex items-center gap-2 border-b border-surface-500/30 pb-2">
|
||||||
|
<Database size="1.2em" class="text-primary-500" />
|
||||||
|
Journal Query Filters
|
||||||
|
</h2>
|
||||||
|
<div class="grid grid-cols-1 md:grid-cols-2 gap-6 p-2">
|
||||||
|
<label class="label">
|
||||||
|
<span class="text-sm font-bold opacity-70">Enabled Status</span>
|
||||||
|
<select bind:value={tmp_config.journal.qry__enabled} class="select select-sm variant-form-material">
|
||||||
|
<option value="enabled">Enabled Only</option>
|
||||||
|
<option value="not_enabled">Disabled Only</option>
|
||||||
|
<option value="all">All (Enabled & Disabled & NULL)</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
<label class="label">
|
||||||
|
<span class="text-sm font-bold opacity-70">Hidden Status</span>
|
||||||
|
<select bind:value={tmp_config.journal.qry__hidden} class="select select-sm variant-form-material">
|
||||||
|
<option value="not_hidden">Visible Only</option>
|
||||||
|
<option value="hidden">Hidden Only</option>
|
||||||
|
<option value="all">All (Visible & Hidden & NULL)</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- Entry Query Filters Section -->
|
||||||
|
<section class="space-y-4">
|
||||||
|
<h2 class="text-xl font-bold flex items-center gap-2 border-b border-surface-500/30 pb-2">
|
||||||
|
<Database size="1.2em" class="text-primary-500" />
|
||||||
|
Entry Query Filters
|
||||||
|
</h2>
|
||||||
|
<div class="grid grid-cols-1 md:grid-cols-2 gap-6 p-2">
|
||||||
|
<label class="label">
|
||||||
|
<span class="text-sm font-bold opacity-70">Enabled Status</span>
|
||||||
|
<select bind:value={tmp_config.entry.qry__enabled} class="select select-sm variant-form-material">
|
||||||
|
<option value="enabled">Enabled Only</option>
|
||||||
|
<option value="not_enabled">Disabled Only</option>
|
||||||
|
<option value="all">All (Enabled & Disabled & NULL)</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
<label class="label">
|
||||||
|
<span class="text-sm font-bold opacity-70">Hidden Status</span>
|
||||||
|
<select bind:value={tmp_config.entry.qry__hidden} class="select select-sm variant-form-material">
|
||||||
|
<option value="not_hidden">Visible Only</option>
|
||||||
|
<option value="hidden">Hidden Only</option>
|
||||||
|
<option value="all">All (Visible & Hidden & NULL)</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
<!-- Security Section -->
|
<!-- Security Section -->
|
||||||
<section class="space-y-4">
|
<section class="space-y-4">
|
||||||
<h2 class="text-xl font-bold flex items-center gap-2 border-b border-surface-500/30 pb-2">
|
<h2 class="text-xl font-bold flex items-center gap-2 border-b border-surface-500/30 pb-2">
|
||||||
|
|||||||
Reference in New Issue
Block a user