feat(journals): implement background auto-save for status and security fields

- Refactored handle_update_journal and handle_update_entry to support non-closing background persistence.
- Implemented strict payload whitelisting for journal and journal_entry updates to resolve HTTP 400 schema errors.
- Added onchange triggers to enable, hide, priority, and sort fields for real-time background syncing.
- Standardized 'Status & Security' tab labeling across configuration components.
This commit is contained in:
Scott Idem
2026-01-14 19:08:37 -05:00
parent dbb45e10ae
commit 98cd35078d
2 changed files with 65 additions and 24 deletions

View File

@@ -92,7 +92,7 @@
}
});
async function handle_update_journal() {
async function handle_update_journal(close_modal: boolean = true) {
if (!tmp__journal_obj.name || !tmp__journal_obj.type_code) {
alert('Please provide both name and type for the journal.');
return;
@@ -127,8 +127,7 @@
default_private: tmp__journal_obj.default_private,
default_public: tmp__journal_obj.default_public,
default_personal: tmp__journal_obj.default_personal,
default_professional: tmp__journal_obj.default_professional,
code: tmp__journal_obj.code
default_professional: tmp__journal_obj.default_professional
};
await journals_func.update_ae_obj__journal({
@@ -137,10 +136,11 @@
data_kv: data_kv,
log_lvl: log_lvl
});
show = false;
if (close_modal) show = false;
} catch (error) {
console.error('Error updating journal:', error);
alert('Failed to update journal.');
if (close_modal) alert('Failed to update journal.');
}
}
@@ -277,21 +277,21 @@
</h2>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<label class="flex items-center space-x-3 cursor-pointer p-3 rounded-lg bg-surface-500/5 border border-surface-500/10 transition-colors hover:bg-surface-500/10">
<input type="checkbox" bind:checked={tmp__journal_obj.enable} class="checkbox checkbox-primary" />
<input type="checkbox" bind:checked={tmp__journal_obj.enable} onchange={() => handle_update_journal(false)} class="checkbox checkbox-primary" />
<div class="flex flex-col">
<span class="font-bold">Enabled</span>
<span class="text-xs opacity-60">Allow access to this journal</span>
</div>
</label>
<label class="flex items-center space-x-3 cursor-pointer p-3 rounded-lg bg-surface-500/5 border border-surface-500/10 transition-colors hover:bg-surface-500/10">
<input type="checkbox" bind:checked={tmp__journal_obj.hide} class="checkbox checkbox-primary" />
<input type="checkbox" bind:checked={tmp__journal_obj.hide} onchange={() => handle_update_journal(false)} class="checkbox checkbox-primary" />
<div class="flex flex-col">
<span class="font-bold">Hidden</span>
<span class="text-xs opacity-60">Hide from standard lists</span>
</div>
</label>
<label class="flex items-center space-x-3 cursor-pointer p-3 rounded-lg bg-surface-500/5 border border-surface-500/10 transition-colors hover:bg-surface-500/10">
<input type="checkbox" bind:checked={tmp__journal_obj.priority} class="checkbox checkbox-primary" />
<input type="checkbox" bind:checked={tmp__journal_obj.priority} onchange={() => handle_update_journal(false)} class="checkbox checkbox-primary" />
<div class="flex flex-col">
<span class="font-bold">Priority Journal</span>
<span class="text-xs opacity-60">Star or pin to top</span>
@@ -303,9 +303,9 @@
<span class="text-xs opacity-60">Manual list position</span>
</div>
<div class="flex items-center gap-2">
<button class="btn-icon btn-icon-sm variant-soft-surface" onclick={() => { tmp__journal_obj.sort = (tmp__journal_obj.sort ?? 0) - 1; }}><Minus size="1em"/></button>
<button class="btn-icon btn-icon-sm variant-soft-surface" onclick={() => { tmp__journal_obj.sort = (tmp__journal_obj.sort ?? 0) - 1; handle_update_journal(false); }}><Minus size="1em"/></button>
<span class="font-mono font-bold w-8 text-center text-lg">{tmp__journal_obj.sort ?? 0}</span>
<button class="btn-icon btn-icon-sm variant-soft-surface" onclick={() => { tmp__journal_obj.sort = (tmp__journal_obj.sort ?? 0) + 1; }}><Plus size="1em"/></button>
<button class="btn-icon btn-icon-sm variant-soft-surface" onclick={() => { tmp__journal_obj.sort = (tmp__journal_obj.sort ?? 0) + 1; handle_update_journal(false); }}><Plus size="1em"/></button>
</div>
</div>
</div>
@@ -509,7 +509,7 @@
<button class="btn variant-ghost-surface font-bold min-w-[100px]" onclick={() => (show = false)}>
<X size="1.2em" class="mr-2" /> Cancel
</button>
<button class="btn variant-filled-primary font-bold shadow-lg min-w-[120px]" onclick={handle_update_journal}>
<button class="btn variant-filled-primary font-bold shadow-lg min-w-[120px]" onclick={() => handle_update_journal(true)}>
<Check size="1.2em" class="mr-2" /> Save Changes
</button>
</div>