Cleaned up Journal Entry update functions

This commit is contained in:
Scott Idem
2025-04-09 16:18:56 -04:00
parent 3587258ec7
commit 2515ba5577
3 changed files with 87 additions and 393 deletions

View File

@@ -268,7 +268,8 @@ export async function create_ae_obj__journal(
db_save_ae_obj_li__journal(
{
obj_type: 'journal',
obj_li: [journal_obj_create_result]
obj_li: [journal_obj_create_result],
log_lvl: log_lvl
});
}
return journal_obj_create_result;
@@ -375,7 +376,8 @@ export async function update_ae_obj__journal(
if (journal_obj_update_result) {
if (try_cache) {
db_save_ae_obj_li__journal({
obj_type: 'journal', obj_li: [journal_obj_update_result]
obj_type: 'journal', obj_li: [journal_obj_update_result],
log_lvl: log_lvl
});
}
return journal_obj_update_result;

View File

@@ -189,7 +189,8 @@ export async function create_ae_obj__journal_entry(
await db_save_ae_obj_li__journal_entry(
{
obj_type: 'journal_entry',
obj_li: [journal_entry_obj_create_result]
obj_li: [journal_entry_obj_create_result],
log_lvl: log_lvl
});
}
return journal_entry_obj_create_result;
@@ -294,7 +295,8 @@ export async function update_ae_obj__journal_entry(
if (journal_entry_obj_update_result) {
if (try_cache) {
await db_save_ae_obj_li__journal_entry({
obj_type: 'journal_entry', obj_li: [journal_entry_obj_update_result]
obj_type: 'journal_entry', obj_li: [journal_entry_obj_update_result],
log_lvl: log_lvl
});
}
return journal_entry_obj_update_result;

View File

@@ -25,6 +25,7 @@ import { ae_util } from '$lib/ae_utils/ae_utils';
import { ae_snip, ae_loc, ae_sess, ae_api, ae_trig, slct, slct_trigger } from '$lib/ae_stores';
import { journals_loc, journals_sess, journals_slct, journals_trig, journals_prom } from '$lib/ae_journals/ae_journals_stores';
import { journals_func } from '$lib/ae_journals/ae_journals_functions';
import { updated } from '$app/state';
console.log(`ae_comp__journal_entry_obj_id_view.svelte`);
@@ -101,6 +102,8 @@ $effect(() => {
console.log('TEST: IDB has changed and not flagged as updated_obj!!!');
updated_idb = true;
// orig_entry_obj = { ...$lq__journal_entry_obj };
}
// } else if (
// // !updated_obj
// // &&
@@ -110,9 +113,10 @@ $effect(() => {
// ) {
// console.log('TEST: IDB has changed!!!');
// orig_entry_obj = { ...$lq__journal_entry_obj };
} else {
console.log('TEST: Catch all: LQ Journal Entry object available', orig_entry_obj, tmp_entry_obj, $lq__journal_entry_obj);
}
// } else {
// console.log('TEST: Catch all: LQ Journal Entry object available', orig_entry_obj, tmp_entry_obj, $lq__journal_entry_obj);
// }
});
$effect(() => {
@@ -129,7 +133,49 @@ $effect(() => {
// const test_html = marked.parse('# Marked in Node.js\n\nRendered by **marked**.');
// Reminder: Styling is being done with Tailwind CSS, not Bootstrap.
async function update_journal_entry() {
if (!$ae_loc.trusted_access) {
alert('You do not have permission to update this journal entry.');
return;
}
let data_kv = {
alert: tmp_entry_obj?.alert,
personal: tmp_entry_obj?.personal,
private: tmp_entry_obj?.private,
professional: tmp_entry_obj?.professional,
public: tmp_entry_obj?.public,
template: tmp_entry_obj?.template,
hide: tmp_entry_obj?.hide,
priority: tmp_entry_obj?.priority,
enable: tmp_entry_obj?.enable,
// alert_msg: $lq__journal_entry_obj?.alert_msg ? false : true
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,
};
// Call API to save the content
try {
await 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: 0,
});
updated_obj = true;
updated_idb = false;
console.log('Journal entry updated successfully!');
} catch (error) {
console.error('Error updating journal entry:', error);
alert('Failed to update journal entry.');
}
}
</script>
@@ -146,32 +192,10 @@ $effect(() => {
// Ask if they would like to save changes before toggling edit mode off.
if ($journals_loc.entry.edit_kv[$lq__journal_entry_obj?.journal_entry_id]) {
if (tmp_entry_obj_changed && confirm('Would you like to save changes to this journal entry before exiting edit mode?')) {
// Call API to save the content
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,
};
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!');
orig_entry_obj = null;
}).catch((error) => {
console.error('Error updating journal entry:', error);
alert('Failed to update journal entry.');
});
update_journal_entry();
}
}
// Toggle edit mode
if ($journals_loc.entry.edit_kv[$lq__journal_entry_obj?.journal_entry_id]) {
$journals_loc.entry.edit_kv[$lq__journal_entry_obj?.journal_entry_id] = false;
@@ -404,28 +428,7 @@ $effect(() => {
tmp_entry_obj.category_code = event.target.value;
console.log('Selected category:', tmp_entry_obj.category_code);
// Call API to save the content
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,
};
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!');
orig_entry_obj = null;
}).catch((error) => {
console.error('Error updating journal entry:', error);
alert('Failed to update journal entry.');
});
update_journal_entry();
}}
title="Select a category for the new journal entry"
>
@@ -475,31 +478,8 @@ $effect(() => {
<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,
alert: $lq__journal_entry_obj?.alert ? 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!');
orig_entry_obj = null;
}).catch((error) => {
console.error('Error updating journal entry:', error);
alert('Failed to update journal entry.');
});
}
tmp_entry_obj.alert = !$lq__journal_entry_obj?.alert;
update_journal_entry();
}}
class="btn-icon-sm"
title="Toggle alert status of this journal entry"
@@ -515,30 +495,8 @@ $effect(() => {
<button
type="button"
onclick={() => {
if ($ae_loc.trusted_access) {
let data_kv = {
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,
alert_msg: $lq__journal_entry_obj?.alert_msg ? 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!');
orig_entry_obj = null;
}).catch((error) => {
console.error('Error updating journal entry:', error);
alert('Failed to update journal entry.');
});
}
// tmp_entry_obj.alert_msg = !$lq__journal_entry_obj?.alert_msg;
update_journal_entry();
}}
class:hidden={!$lq__journal_entry_obj?.alert}
class="btn-icon-sm"
@@ -555,31 +513,8 @@ $effect(() => {
<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,
private: $lq__journal_entry_obj?.private ? 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!');
orig_entry_obj = null;
}).catch((error) => {
console.error('Error updating journal entry:', error);
alert('Failed to update journal entry.');
});
}
tmp_entry_obj.private = !$lq__journal_entry_obj?.private;
update_journal_entry();
}}
class="btn-icon-sm"
title="Toggle private visibility of this journal entry"
@@ -594,31 +529,8 @@ $effect(() => {
<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,
public: $lq__journal_entry_obj?.public ? 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!');
orig_entry_obj = null;
}).catch((error) => {
console.error('Error updating journal entry:', error);
alert('Failed to update journal entry.');
});
}
tmp_entry_obj.public = !$lq__journal_entry_obj?.public;
update_journal_entry();
}}
class="btn-icon-sm"
title="Toggle public visibility of this journal entry"
@@ -633,31 +545,8 @@ $effect(() => {
<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,
personal: $lq__journal_entry_obj?.personal ? 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!');
orig_entry_obj = null;
}).catch((error) => {
console.error('Error updating journal entry:', error);
alert('Failed to update journal entry.');
});
}
tmp_entry_obj.personal = !$lq__journal_entry_obj?.personal;
update_journal_entry();
}}
class="btn-icon-sm"
title="Toggle personal visibility of this journal entry"
@@ -672,31 +561,8 @@ $effect(() => {
<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,
professional: $lq__journal_entry_obj?.professional ? 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!');
orig_entry_obj = null;
}).catch((error) => {
console.error('Error updating journal entry:', error);
alert('Failed to update journal entry.');
});
}
tmp_entry_obj.professional = !$lq__journal_entry_obj?.professional;
update_journal_entry();
}}
class="btn-icon-sm"
title="Toggle professional visibility of this journal entry"
@@ -704,7 +570,7 @@ $effect(() => {
{#if $lq__journal_entry_obj?.professional}
<BriefcaseBusiness strokeWidth="2.5" color="green" />
{:else}
<BriefcaseBusiness strokeWidth="1" />
<BriefcaseBusiness strokeWidth="1" color="gray" />
{/if}
</button>
@@ -712,31 +578,8 @@ $effect(() => {
<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!');
orig_entry_obj = null;
}).catch((error) => {
console.error('Error updating journal entry:', error);
alert('Failed to update journal entry.');
});
}
tmp_entry_obj.template = !$lq__journal_entry_obj?.template;
update_journal_entry();
}}
class="btn-icon-sm"
title="Toggle template visibility of this journal entry"
@@ -866,34 +709,7 @@ $effect(() => {
<button
type="button"
onclick={() => {
// Save the updated journal entry content
if ($ae_loc.trusted_access) {
// Call API to save the content
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,
};
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: 1
}).then(() => {
// Optionally, you can provide feedback to the user
// alert('Journal entry updated successfully!');
// orig_entry_obj = {};
// tmp_entry_obj = {};
updated_obj = true;
updated_idb = false;
}).catch((error) => {
console.error('Error updating journal entry:', error);
alert('Failed to update journal entry.');
});
}
update_journal_entry();
}}
disabled={!tmp_entry_obj_changed}
class:variant-filled-error={tmp_entry_obj_changed}
@@ -936,30 +752,8 @@ $effect(() => {
<button
type="button"
onclick={() => {
if ($ae_loc.trusted_access) {
let data_kv = {
alert: $lq__journal_entry_obj?.alert,
alert_msg: $lq__journal_entry_obj?.alert_msg,
category_code: tmp_entry_obj?.category_code,
content: tmp_entry_obj?.content,
name: tmp_entry_obj?.name,
priority: $lq__journal_entry_obj?.priority ? false : true,
tags: tmp_entry_obj?.tags,
};
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!');
orig_entry_obj = null;
}).catch((error) => {
console.error('Error updating journal entry:', error);
alert('Failed to update journal entry.');
});
}
tmp_entry_obj.priority = !$lq__journal_entry_obj?.priority;
update_journal_entry();
}}
class="btn-icon-sm variant-soft-tertiary transition"
title="Toggle priority of this journal entry"
@@ -979,29 +773,8 @@ $effect(() => {
<button
type="button"
onclick={() => {
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,
sort: $lq__journal_entry_obj?.sort ? $lq__journal_entry_obj?.sort + 1 : 1
};
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!');
orig_entry_obj = null;
}).catch((error) => {
console.error('Error updating journal entry:', error);
alert('Failed to update journal entry.');
});
tmp_entry_obj.sort = $lq__journal_entry_obj?.sort ? $lq__journal_entry_obj?.sort + 1 : 1;
update_journal_entry();
}}
class="btn-icon-sm variant-soft-tertiary transition"
title="Increment sort order of this journal entry"
@@ -1019,29 +792,8 @@ $effect(() => {
<button
type="button"
onclick={() => {
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,
sort: $lq__journal_entry_obj?.sort ? $lq__journal_entry_obj?.sort - 1 : 0,
};
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!');
orig_entry_obj = null;
}).catch((error) => {
console.error('Error updating journal entry:', error);
alert('Failed to update journal entry.');
});
tmp_entry_obj.sort = $lq__journal_entry_obj?.sort ? $lq__journal_entry_obj?.sort - 1 : 0;
update_journal_entry();
}}
class="btn-icon-sm variant-soft-tertiary transition"
title="Decrement sort order of this journal entry"
@@ -1057,27 +809,7 @@ $effect(() => {
bind:value={tmp_entry_obj.group}
placeholder="Group"
onchange={() => {
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,
};
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!');
orig_entry_obj = null;
}).catch((error) => {
console.error('Error updating journal entry:', error);
alert('Failed to update journal entry.');
});
update_journal_entry();
}}
class="input input-sm input-bordered w-24"
title="Set group (for sorting) of this journal entry"
@@ -1088,29 +820,8 @@ $effect(() => {
<button
type="button"
onclick={() => {
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,
hide: $lq__journal_entry_obj?.hide ? 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!');
orig_entry_obj = null;
}).catch((error) => {
console.error('Error updating journal entry:', error);
alert('Failed to update journal entry.');
});
tmp_entry_obj.hide = !$lq__journal_entry_obj?.hide;
update_journal_entry();
}}
class="btn btn-sm md:btn-md variant-soft-warning hover:variant-filled-warning transition"
title="Toggle visibility of this journal entry"
@@ -1128,29 +839,8 @@ $effect(() => {
<button
type="button"
onclick={() => {
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,
enable: $lq__journal_entry_obj?.enable ? 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!');
orig_entry_obj = null;
}).catch((error) => {
console.error('Error updating journal entry:', error);
alert('Failed to update journal entry.');
});
tmp_entry_obj.enable = !$lq__journal_entry_obj?.enable;
update_journal_entry();
}}
class:hidden={!$ae_loc.administrator_access || !$ae_loc.edit_mode}
class="btn btn-sm md:btn-md variant-soft-error hover:variant-filled-error transition"