Now with the ability to clone template entries

This commit is contained in:
Scott Idem
2025-04-02 12:56:08 -04:00
parent 0e72d27dbd
commit b4f2be0f13
9 changed files with 184 additions and 189 deletions

View File

@@ -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>