Now with the ability to clone template entries
This commit is contained in:
@@ -23,48 +23,6 @@ export async function load({ params, parent }) {
|
||||
console.log(`ae_acct = `, ae_acct);
|
||||
}
|
||||
|
||||
// let note_id = ae_acct.slct.note_id; // From root +layout.ts
|
||||
// if (!note_id) {
|
||||
// console.log(`ERROR: journals +layout.ts: The note_id was not found in the parent_data!!!`);
|
||||
// // return false;
|
||||
// }
|
||||
|
||||
// let ae_params = {};
|
||||
|
||||
// if (browser) {
|
||||
// if (note_id) {
|
||||
// let load_note_obj_li = journals_func.load_ae_obj_li__note({
|
||||
// api_cfg: ae_acct.api,
|
||||
// for_obj_type: 'account',
|
||||
// for_obj_id: account_id,
|
||||
// enabled: 'enabled',
|
||||
// hidden: 'not_hidden',
|
||||
// limit: 20,
|
||||
// // order_by_li: {},
|
||||
// params: ae_params,
|
||||
// try_cache: true,
|
||||
// log_lvl: log_lvl
|
||||
// });
|
||||
// ae_acct.slct.note_obj_li = load_note_obj_li;
|
||||
// }
|
||||
// }
|
||||
|
||||
// let load_note_obj = journals_func.load_ae_obj_id__note({
|
||||
// api_cfg: ae_acct.api,
|
||||
// note_id: note_id,
|
||||
// try_cache: false
|
||||
// });
|
||||
|
||||
// ae_acct.slct.note_obj = load_note_obj;
|
||||
|
||||
// if (browser) {
|
||||
// console.log(`Browser: ${browser}`);
|
||||
// journals_func.db_save_ae_obj_li__note({
|
||||
// obj_type: 'note',
|
||||
// obj_li: [load_note_obj_li],
|
||||
// });
|
||||
// }
|
||||
|
||||
// let submenu = {
|
||||
// main: {name: 'Main', href: '/journals', access: false},
|
||||
// // manage: {name: 'Manage', href: '/journals/manage', access: 'administrator', disable: true, hide: true},
|
||||
|
||||
@@ -28,6 +28,7 @@ export async function load({ parent }) {
|
||||
let load_journal_obj_li = journals_func.load_ae_obj_id__journal({
|
||||
api_cfg: ae_acct.api,
|
||||
journal_id: journal_id,
|
||||
hidden: 'all', // 'not_hidden' to load only visible entries
|
||||
// params: ae_params,
|
||||
try_cache: true,
|
||||
log_lvl: log_lvl
|
||||
@@ -40,7 +41,7 @@ export async function load({ parent }) {
|
||||
for_obj_type: 'account',
|
||||
for_obj_id: account_id,
|
||||
inc_entry_li: true,
|
||||
hidden: 'not_hidden',
|
||||
hidden: 'all', // 'not_hidden'
|
||||
enabled: 'enabled',
|
||||
// order_by_li: {'priority': 'DESC', 'sort': 'DESC', 'name': 'ASC', 'updated_on': 'DESC', 'created_on': 'DESC'},
|
||||
limit: 25,
|
||||
|
||||
@@ -32,6 +32,9 @@ export async function load({ params, parent }) {
|
||||
api_cfg: ae_acct.api,
|
||||
journal_id: journal_id,
|
||||
inc_entry_li: true,
|
||||
enabled: 'enabled',
|
||||
hidden: 'all', // 'not_hidden' to load only visible entries
|
||||
limit: 99,
|
||||
try_cache: true,
|
||||
log_lvl: log_lvl
|
||||
});
|
||||
|
||||
@@ -65,104 +65,6 @@ let lq__journal_entry_obj = $derived(liveQuery(async () => {
|
||||
return results;
|
||||
}));
|
||||
|
||||
// let lq__journal_entry_obj_li = $derived(liveQuery(async () => {
|
||||
// if (log_lvl) {
|
||||
// console.log(`$lq__journal_entry_obj.cfg_json = `, $lq__journal_entry_obj?.cfg_json);
|
||||
// }
|
||||
// if ($lq__journal_entry_obj?.cfg_json?.entry_group_sort === 'DESC') {
|
||||
// let results = await db_journals.journal_entry
|
||||
// // .orderBy('updated_on')
|
||||
// .where('journal_entry_id')
|
||||
// .equals($journals_slct?.journal_entry_id ?? '') // null or undefined does not reset things like '' does
|
||||
// .reverse()
|
||||
// // .sortBy('tmp_sort_2');
|
||||
// .sortBy('updated_on');
|
||||
// // .sortBy('title');
|
||||
|
||||
// return results;
|
||||
// } else {
|
||||
// console.log(`lq__journal_entry_obj_li - default query using journal_entry_id: ${$journals_slct?.journal_entry_id}`);
|
||||
// let results = await db_journals.journal_entry
|
||||
// .where('journal_entry_id')
|
||||
// .equals($journals_slct?.journal_entry_id ?? '') // null or undefined does not reset things like '' does
|
||||
// // .reverse()
|
||||
// .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) {
|
||||
// $journals_trig.journal_entry_li = false;
|
||||
|
||||
// if (log_lvl) {
|
||||
// console.log(`Triggered: $journals_trig.journal_entry_li`);
|
||||
// }
|
||||
|
||||
// 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();
|
||||
// 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',
|
||||
// for_obj_id: $journals_slct.journal_entry_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.');
|
||||
|
||||
// let message = {'journal_entry_id': $journals_slct?.journal_entry_id ?? null};
|
||||
// window.parent.postMessage(message, "*");
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
Flag, FlagOff, FileX, Fingerprint,
|
||||
Globe, Group,
|
||||
MessageSquareWarning, Minus,
|
||||
NotebookPen, NotebookText,
|
||||
NotebookPen, NotebookText, NotepadTextDashed,
|
||||
Pencil, Plus,
|
||||
RemoveFormatting,
|
||||
Search,
|
||||
@@ -563,6 +563,45 @@ $effect(() => {
|
||||
{/if}
|
||||
</button>
|
||||
|
||||
<!-- Toggle if entry should be used as a template entry (cloneable). Only visible in edit_mode. -->
|
||||
<button
|
||||
type="button"
|
||||
onclick={() => {
|
||||
if ($ae_loc.trusted_access) {
|
||||
let data_kv = {
|
||||
alert_msg: tmp_entry_obj?.alert_msg,
|
||||
category_code: tmp_entry_obj?.category_code,
|
||||
content: tmp_entry_obj?.content,
|
||||
group: tmp_entry_obj?.group,
|
||||
name: tmp_entry_obj?.name,
|
||||
tags: tmp_entry_obj?.tags,
|
||||
|
||||
template: $lq__journal_entry_obj?.template ? false : true
|
||||
};
|
||||
journals_func.update_ae_obj__journal_entry({
|
||||
api_cfg: $ae_api,
|
||||
journal_entry_id: $lq__journal_entry_obj?.journal_entry_id,
|
||||
data_kv: data_kv,
|
||||
log_lvl: log_lvl
|
||||
}).then(() => {
|
||||
// Optionally, you can provide feedback to the user
|
||||
// alert('Journal entry updated successfully!');
|
||||
}).catch((error) => {
|
||||
console.error('Error updating journal entry:', error);
|
||||
alert('Failed to update journal entry.');
|
||||
});
|
||||
}
|
||||
}}
|
||||
class="btn-icon-sm"
|
||||
title="Toggle template visibility of this journal entry"
|
||||
>
|
||||
{#if $lq__journal_entry_obj?.template}
|
||||
<NotepadTextDashed strokeWidth="2.5" color="green" />
|
||||
{:else}
|
||||
<NotepadTextDashed strokeWidth="1" color="gray" />
|
||||
{/if}
|
||||
</button>
|
||||
|
||||
<!-- <button
|
||||
type="button"
|
||||
onclick={() => {
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
CalendarClock, CodeXml, Copy,
|
||||
Eye, EyeOff,
|
||||
Flag, FlagOff,
|
||||
NotebookPen, NotebookText,
|
||||
NotebookPen, NotebookText, NotepadTextDashed,
|
||||
RemoveFormatting,
|
||||
Shapes, Siren,
|
||||
Tags
|
||||
@@ -68,11 +68,14 @@ let tmp_entry_obj: key_val = $state({});
|
||||
{#if (journals_journal_entry_obj.priority)}
|
||||
<Flag class="mx-1 inline-block text-yellow-500"/>
|
||||
{/if}
|
||||
{#if (journals_journal_entry_obj.name)}
|
||||
<NotebookText class="mx-1 inline-block"/>
|
||||
{#if journals_journal_entry_obj.template}
|
||||
<NotepadTextDashed class="mx-1 inline-block" />
|
||||
{@html journals_journal_entry_obj.name ?? '-- no name --'}
|
||||
{:else if (journals_journal_entry_obj.name)}
|
||||
<NotebookText class="mx-1 inline-block" />
|
||||
{@html journals_journal_entry_obj.name}
|
||||
{:else}
|
||||
<CalendarClock class="mx-1 inline-block"/>
|
||||
<CalendarClock class="mx-1 inline-block" />
|
||||
{ae_util.iso_datetime_formatter(journals_journal_entry_obj.created_on, 'datetime_iso_12_no_seconds')}
|
||||
{/if}
|
||||
</span>
|
||||
@@ -91,6 +94,7 @@ let tmp_entry_obj: key_val = $state({});
|
||||
alert('Failed to copy content.');
|
||||
});
|
||||
}}
|
||||
class:hidden={journals_journal_entry_obj.template}
|
||||
class="btn btn-sm p-1 variant-soft-secondary hover:variant-filled-secondary *:hover:inline lg:text-xs"
|
||||
title="Copy the markdown content"
|
||||
>
|
||||
@@ -117,6 +121,7 @@ let tmp_entry_obj: key_val = $state({});
|
||||
alert('Failed to copy HTML content.');
|
||||
});
|
||||
}}
|
||||
class:hidden={journals_journal_entry_obj.template}
|
||||
class="btn btn-sm p-1 variant-soft-secondary hover:variant-filled-secondary *:hover:inline lg:text-xs"
|
||||
title="Copy the rendered HTML content"
|
||||
>
|
||||
@@ -127,6 +132,58 @@ let tmp_entry_obj: key_val = $state({});
|
||||
Copy Rendered HTML
|
||||
</span>
|
||||
</button>
|
||||
|
||||
<!-- Clone entry -->
|
||||
<button
|
||||
type="button"
|
||||
onclick={() => {
|
||||
// Clone the journal entry
|
||||
// let data_kv = {
|
||||
// ...journals_journal_entry_obj,
|
||||
// };
|
||||
// // Remove specific fields that should not be cloned
|
||||
// delete data_kv.journal_entry_id;
|
||||
// delete data_kv.id; // Ensure we do not copy the ID
|
||||
// delete data_kv.template;
|
||||
// delete data_kv.notes;
|
||||
// delete data_kv.created_on;
|
||||
// delete data_kv.updated_on;
|
||||
|
||||
// We only want to clone certain fields from the original journal entry object to avoid conflicts.
|
||||
let data_kv = {
|
||||
// journal_id_random: journals_journal_entry_obj.journal_id,
|
||||
code: journals_journal_entry_obj.code,
|
||||
category_code: journals_journal_entry_obj.category_code,
|
||||
name: journals_journal_entry_obj.name,
|
||||
short_name: journals_journal_entry_obj.short_name,
|
||||
content: journals_journal_entry_obj.content,
|
||||
description: journals_journal_entry_obj.description,
|
||||
tags: journals_journal_entry_obj.tags,
|
||||
|
||||
};
|
||||
|
||||
journals_func.create_ae_obj__journal_entry({
|
||||
api_cfg: $ae_api,
|
||||
journal_id: journals_journal_entry_obj.journal_id,
|
||||
data_kv: data_kv,
|
||||
log_lvl: log_lvl,
|
||||
}).then((result) => {
|
||||
alert('Journal entry cloned successfully!');
|
||||
goto(`/journals/${result.journal_id_random}/entry/${result.journal_entry_id_random}`);
|
||||
}).catch((error) => {
|
||||
console.error('Error cloning journal entry:', error);
|
||||
alert('Failed to clone journal entry.');
|
||||
});
|
||||
}}
|
||||
class:hidden={!journals_journal_entry_obj.template}
|
||||
class="btn btn-sm p-1 variant-soft-secondary hover:variant-filled-secondary *:hover:inline lg:text-xs"
|
||||
title="Clone this journal entry"
|
||||
>
|
||||
<!-- class="btn btn-sm variant-soft-surface hover:variant-filled-warning transition py-1 px-2" -->
|
||||
<!-- <Copy strokeWidth="1" /> -->
|
||||
<Copy size="2em" />
|
||||
<span class="hidden md:inline">Clone</span>
|
||||
</button>
|
||||
</span>
|
||||
|
||||
<div class="flex flex-row flex-wrap gap-2 items-center justify-end">
|
||||
@@ -273,7 +330,6 @@ let tmp_entry_obj: key_val = $state({});
|
||||
|
||||
<section
|
||||
class="ae_meta mt-2 flex flex-col sm:flex-row gap-2 items-center justify-center text-xs text-gray-500"
|
||||
class:hidden={!$ae_loc.trusted_access || !$ae_loc.edit_mode}
|
||||
>
|
||||
<!-- <span
|
||||
class="journal_entry__journal_entry_type"
|
||||
@@ -281,7 +337,10 @@ let tmp_entry_obj: key_val = $state({});
|
||||
>
|
||||
Type: {journals_journal_entry_obj.journal_entry_type}
|
||||
</span> -->
|
||||
<span class="flex flex-row gap-1 items-center justify-center">
|
||||
<span
|
||||
class:hidden={!$ae_loc.trusted_access || !$ae_loc.edit_mode}
|
||||
class="flex flex-row gap-1 items-center justify-center"
|
||||
>
|
||||
<span
|
||||
class="journal_entry__created_on"
|
||||
>
|
||||
@@ -298,39 +357,41 @@ let tmp_entry_obj: key_val = $state({});
|
||||
</span>
|
||||
|
||||
<!-- Set/unset hide (boolean) -->
|
||||
<button
|
||||
type="button"
|
||||
onclick={() => {
|
||||
let data_kv = {
|
||||
hide: journals_journal_entry_obj?.hide ? false : true
|
||||
};
|
||||
journals_func.update_ae_obj__journal_entry({
|
||||
api_cfg: $ae_api,
|
||||
journal_entry_id: journals_journal_entry_obj.journal_entry_id,
|
||||
data_kv: data_kv,
|
||||
log_lvl: log_lvl,
|
||||
}).then(() => {
|
||||
// Optionally, you can provide feedback to the user
|
||||
// alert('Journal entry updated successfully!');
|
||||
}).catch((error) => {
|
||||
console.error('Error updating journal entry:', error);
|
||||
alert('Failed to update journal entry.');
|
||||
});
|
||||
}}
|
||||
class:hidden={!$ae_loc.edit_mode}
|
||||
class="btn btn-sm variant-soft-surface hover:variant-filled-warning transition py-1 px-2"
|
||||
title={`Set entry as ${journals_journal_entry_obj.hide ? 'visible' : 'hidden'}`}
|
||||
>
|
||||
{#if journals_journal_entry_obj.hide}
|
||||
<EyeOff strokeWidth="1" color="hsla( 0, 100%, 50%, .5)"
|
||||
class="inline-block" />
|
||||
<span class="hidden md:inline">Hidden</span>
|
||||
{:else}
|
||||
<Eye strokeWidth="2.5" color="hsla( 120, 100%, 25%, .5)"
|
||||
class="inline-block" />
|
||||
<span class="hidden lg:inline">Visible</span>
|
||||
{/if}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onclick={() => {
|
||||
let data_kv = {
|
||||
hide: journals_journal_entry_obj?.hide ? false : true
|
||||
};
|
||||
journals_func.update_ae_obj__journal_entry({
|
||||
api_cfg: $ae_api,
|
||||
journal_entry_id: journals_journal_entry_obj.journal_entry_id,
|
||||
data_kv: data_kv,
|
||||
log_lvl: log_lvl,
|
||||
}).then(() => {
|
||||
// Optionally, you can provide feedback to the user
|
||||
// alert('Journal entry updated successfully!');
|
||||
}).catch((error) => {
|
||||
console.error('Error updating journal entry:', error);
|
||||
alert('Failed to update journal entry.');
|
||||
});
|
||||
}}
|
||||
class:hidden={!$ae_loc.edit_mode}
|
||||
class="btn btn-sm variant-soft-surface hover:variant-filled-warning transition py-1 px-2"
|
||||
title={`Set entry as ${journals_journal_entry_obj.hide ? 'visible' : 'hidden'}`}
|
||||
>
|
||||
{#if journals_journal_entry_obj.hide}
|
||||
<EyeOff strokeWidth="1" color="hsla( 0, 100%, 50%, .5)"
|
||||
class="inline-block" />
|
||||
<span class="hidden md:inline">Hidden</span>
|
||||
{:else}
|
||||
<Eye strokeWidth="2.5" color="hsla( 120, 100%, 25%, .5)"
|
||||
class="inline-block" />
|
||||
<span class="hidden lg:inline">Visible</span>
|
||||
{/if}
|
||||
</button>
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user