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_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,
|
||||
|
||||
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_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: [
|
||||
{ code: 'diary', name: 'Diary' },
|
||||
{ code: 'log', name: 'Log' },
|
||||
@@ -72,6 +75,24 @@ const journals_local_data_struct: key_val = {
|
||||
]
|
||||
},
|
||||
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:
|
||||
'Summarize the following journal entry content in a concise manner, focusing on key points and insights.',
|
||||
llm__max_tokens: 512,
|
||||
@@ -81,9 +102,7 @@ const journals_local_data_struct: key_val = {
|
||||
llm__frequency_penalty: 0.0,
|
||||
llm__presence_penalty: 0.0,
|
||||
|
||||
auto_save: false,
|
||||
edit: false,
|
||||
edit_kv: {}
|
||||
auto_save: false
|
||||
}
|
||||
};
|
||||
// console.log(`AE Stores - App Journals Local Storage Data:`, journals_local_data_struct);
|
||||
|
||||
@@ -26,10 +26,11 @@
|
||||
}
|
||||
let { data, children }: Props = $props();
|
||||
|
||||
$journals_loc.qry__enabled = 'enabled';
|
||||
$journals_loc.qry__hidden = 'not_hidden';
|
||||
$journals_loc.qry__limit = 15;
|
||||
$journals_loc.qry__offset = 0;
|
||||
// Initialize/Reset Entry Query defaults on layout load
|
||||
// $journals_loc.entry.qry__enabled = 'enabled';
|
||||
// $journals_loc.entry.qry__hidden = 'not_hidden';
|
||||
// $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.
|
||||
$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>
|
||||
|
||||
<!-- Svelte layout for a Journal ID page and children -->
|
||||
@@ -221,7 +123,8 @@
|
||||
hover:preset-filled-tertiary-300-700
|
||||
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 /> -->
|
||||
<!-- <Library /> -->
|
||||
@@ -348,8 +251,7 @@
|
||||
hover:variant-filled-warning
|
||||
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 />
|
||||
<span class="hidden md:inline">
|
||||
Edit Journal
|
||||
@@ -371,8 +273,8 @@
|
||||
let data_kv = {
|
||||
category_code: null
|
||||
};
|
||||
if ($journals_loc.qry__category_code) {
|
||||
data_kv.category_code = $journals_loc.qry__category_code;
|
||||
if ($journals_loc.entry.qry__category_code) {
|
||||
data_kv.category_code = $journals_loc.entry.qry__category_code;
|
||||
}
|
||||
if (log_lvl) {
|
||||
console.log('Creating new journal entry with data_kv:', data_kv);
|
||||
@@ -425,7 +327,7 @@
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<!-- <div class="overflow-auto"> -->
|
||||
<div class="overflow-auto">
|
||||
{@render children?.()}
|
||||
<!-- </div> -->
|
||||
</section>
|
||||
</div>
|
||||
</section>
|
||||
@@ -11,6 +11,7 @@
|
||||
// *** Import Svelte specific
|
||||
import { browser } from '$app/environment';
|
||||
// import { goto } from '$app/navigation';
|
||||
import { untrack } from 'svelte';
|
||||
|
||||
// *** Import other supporting libraries
|
||||
// import {
|
||||
@@ -111,7 +112,7 @@
|
||||
|
||||
$journals_slct.journal_id = ae_acct.slct.journal_id;
|
||||
|
||||
$journals_sess.entry_li = [];
|
||||
$journals_sess.entry_li = null;
|
||||
$journals_slct.journal_entry_id = null;
|
||||
|
||||
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(
|
||||
liveQuery(async () => {
|
||||
let results;
|
||||
|
||||
if ($journals_sess.entry_li_trigger && !$journals_sess?.entry_li) {
|
||||
$journals_sess.entry_li = null;
|
||||
$journals_sess.entry_li_trigger = false;
|
||||
}
|
||||
// If we have a specific list in the session (e.g. from a search), use it.
|
||||
if ($journals_sess?.entry_li !== null && $journals_sess?.entry_li !== undefined) {
|
||||
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) {
|
||||
let journal_entry_id_random_li = []; // This is to prevent the array from constantly updating and triggering the liveQuery.
|
||||
results = [];
|
||||
} 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_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 = []; // 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];
|
||||
// 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 {
|
||||
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')
|
||||
.equals($journals_slct?.journal_id ?? '') // null or undefined does not reset things like '' does
|
||||
.reverse()
|
||||
.sortBy('tmp_sort_1');
|
||||
// .sortBy('updated_on');
|
||||
.equals($journals_slct?.journal_id ?? ''); // null or undefined does not reset things like '' does
|
||||
|
||||
// Apply Category Filter
|
||||
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
|
||||
@@ -214,20 +256,20 @@
|
||||
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
|
||||
`LQ - $journals_loc.entry.qry__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.`);
|
||||
} 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
|
||||
$journals_loc.entry.qry__category_code &&
|
||||
$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 {
|
||||
console.log(
|
||||
`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`);
|
||||
}
|
||||
|
||||
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) {
|
||||
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}`);
|
||||
console.log(`$journals_loc.entry.qry__enabled = ${$journals_loc.entry.qry__enabled}`);
|
||||
console.log(`$journals_loc.entry.qry__hidden = ${$journals_loc.entry.qry__hidden}`);
|
||||
}
|
||||
let results = db_journals.journal_entry.clear();
|
||||
if (log_lvl) {
|
||||
@@ -287,10 +329,10 @@
|
||||
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,
|
||||
enabled: $journals_loc.entry.qry__enabled,
|
||||
hidden: $journals_loc.entry.qry__hidden,
|
||||
limit: $journals_loc.entry.qry__limit,
|
||||
order_by_li: $journals_loc.entry.qry__order_by_li,
|
||||
try_cache: true,
|
||||
log_lvl: log_lvl
|
||||
}
|
||||
@@ -336,18 +378,18 @@
|
||||
"
|
||||
> -->
|
||||
|
||||
<Journal_view
|
||||
{lq__journal_obj}
|
||||
{lq__journal_entry_obj_li}
|
||||
onShowExport={() => show_export_modal = true}
|
||||
onShowImport={() => show_import_modal = true}
|
||||
<Journal_view
|
||||
{lq__journal_obj}
|
||||
{lq__journal_entry_obj_li}
|
||||
onShowExport={() => show_export_modal = true}
|
||||
onShowImport={() => show_import_modal = true}
|
||||
/>
|
||||
|
||||
{#if $lq__journal_entry_obj_li && $lq__journal_entry_obj_li?.length}
|
||||
<Journal_entry_obj_li {lq__journal_obj} {lq__journal_entry_obj_li} />
|
||||
{:else}
|
||||
<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>
|
||||
{/if}
|
||||
|
||||
@@ -379,4 +421,4 @@
|
||||
<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>
|
||||
</section>
|
||||
{/if}
|
||||
{/if}
|
||||
@@ -349,19 +349,17 @@
|
||||
type="button"
|
||||
onclick={() => {
|
||||
if (
|
||||
$journals_loc.filter__category_code ==
|
||||
$journals_loc.entry.qry__category_code ==
|
||||
journals_journal_entry_obj.category_code
|
||||
) {
|
||||
$journals_loc.filter__category_code = null;
|
||||
$journals_loc.entry.qry__category_code = null;
|
||||
} else {
|
||||
$journals_loc.filter__category_code =
|
||||
journals_journal_entry_obj.category_code;
|
||||
$journals_loc.qry__category_code =
|
||||
$journals_loc.entry.qry__category_code =
|
||||
journals_journal_entry_obj.category_code;
|
||||
}
|
||||
$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}
|
||||
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}`}
|
||||
@@ -559,6 +557,6 @@
|
||||
/>
|
||||
{/if}
|
||||
{:else}
|
||||
<p>No journal entry available to show.</p>
|
||||
<p>No Æ Journal Entry available to show.</p>
|
||||
{/if}
|
||||
</section>
|
||||
@@ -77,7 +77,7 @@
|
||||
|
||||
if (log_lvl) {
|
||||
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({
|
||||
api_cfg: $ae_api,
|
||||
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_alert: null,
|
||||
// qry_priority: null,
|
||||
// qry_type: and_type,
|
||||
|
||||
enabled: 'enabled', // $journals_loc.qry__enabled,
|
||||
hidden: 'not_hidden', // $journals_loc.qry__hidden,
|
||||
// order_by_li: $journals_loc.qry__order_by_li,
|
||||
// limit: $journals_loc.qry__limit,
|
||||
enabled: $journals_loc.entry.qry__enabled ?? 'enabled',
|
||||
hidden: $journals_loc.entry.qry__hidden ?? 'not_hidden',
|
||||
// order_by_li: $journals_loc.entry.qry__order_by_li,
|
||||
// limit: $journals_loc.entry.qry__limit,
|
||||
// try_cache: try_cache,
|
||||
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 = {
|
||||
...$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;
|
||||
$journals_sess = { ...$journals_sess }; // ensure session is updated
|
||||
} else {
|
||||
console.log('Clear the search results: no entries found for that query.');
|
||||
// $journals_sess.entry_li = [''];
|
||||
$journals_sess.entry_li = null;
|
||||
// $journals_trig.journal_entry_li = true;
|
||||
// alert('No journal entries found for that search query.');
|
||||
// $journals_sess = $journals_sess;
|
||||
// Explicitly set to empty array to indicate "0 results found" (vs null which is "default view")
|
||||
$journals_sess.entry_li = [];
|
||||
}
|
||||
|
||||
if (log_lvl) {
|
||||
@@ -131,10 +126,10 @@
|
||||
disabled={false}
|
||||
type="text"
|
||||
placeholder="Search Journal Entries"
|
||||
bind:value={$journals_loc.qry__search_text}
|
||||
bind:value={$journals_loc.entry.qry__search_text}
|
||||
onkeyup={(event) => {
|
||||
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;
|
||||
}
|
||||
}}
|
||||
@@ -151,11 +146,11 @@
|
||||
<!-- Clear search text button -->
|
||||
<button
|
||||
type="button"
|
||||
class:hidden={!$journals_loc.qry__search_text}
|
||||
class:hidden={!$journals_loc.entry.qry__search_text}
|
||||
onclick={() => {
|
||||
console.log(`TESTING - 1 - Cleared search query: ${$journals_loc.qry__search_text}`);
|
||||
$journals_loc.qry__search_text = '';
|
||||
console.log(`TESTING - 2 - Cleared search query: ${$journals_loc.qry__search_text}`);
|
||||
console.log(`TESTING - 1 - Cleared search query: ${$journals_loc.entry.qry__search_text}`);
|
||||
$journals_loc.entry.qry__search_text = '';
|
||||
console.log(`TESTING - 2 - Cleared search query: ${$journals_loc.entry.qry__search_text}`);
|
||||
$journals_trig.journal_entry_qry = true;
|
||||
}}
|
||||
class="
|
||||
@@ -209,13 +204,13 @@
|
||||
hover:preset-filled-tertiary-100-900
|
||||
transition-all
|
||||
"
|
||||
bind:value={$journals_loc.qry__category_code}
|
||||
bind:value={$journals_loc.entry.qry__category_code}
|
||||
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.
|
||||
$journals_loc.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_loc.entry.qry__category_code = (event.target as HTMLInputElement).value;
|
||||
$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"
|
||||
>
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
// Derived / Local target
|
||||
// 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
|
||||
let target_journal_id = $derived($journals_slct.journal_id || selected_journal_id);
|
||||
@@ -80,7 +80,7 @@
|
||||
function handle_journal_change(e: Event) {
|
||||
const val = (e.target as HTMLSelectElement).value;
|
||||
selected_journal_id = val;
|
||||
$journals_loc.qry__journal_id = val; // Persist choice
|
||||
$journals_loc.entry.qry__journal_id = val; // Persist choice
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -124,8 +124,8 @@
|
||||
let data_kv = {
|
||||
category_code: null
|
||||
};
|
||||
if ($journals_loc.qry__category_code) {
|
||||
data_kv.category_code = $journals_loc.qry__category_code;
|
||||
if ($journals_loc.entry.qry__category_code) {
|
||||
data_kv.category_code = $journals_loc.entry.qry__category_code;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
// Internal State
|
||||
let tab: 'form' | 'local_json' | 'session_json' = $state('form');
|
||||
let tmp_config: any = $state({
|
||||
journal: {},
|
||||
entry: {}
|
||||
});
|
||||
|
||||
@@ -160,6 +161,58 @@
|
||||
</div>
|
||||
</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 -->
|
||||
<section class="space-y-4">
|
||||
<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