Working ability to create new Journals
This commit is contained in:
@@ -202,7 +202,7 @@ export async function load_ae_obj_li__journal(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Updated 2025-03-15
|
// Updated 2025-03-24
|
||||||
export async function create_ae_obj__journal(
|
export async function create_ae_obj__journal(
|
||||||
{
|
{
|
||||||
api_cfg,
|
api_cfg,
|
||||||
@@ -224,6 +224,11 @@ export async function create_ae_obj__journal(
|
|||||||
console.log(`*** create_ae_obj__journal() *** account_id=${account_id}`);
|
console.log(`*** create_ae_obj__journal() *** account_id=${account_id}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!account_id) {
|
||||||
|
console.log(`ERROR: Journals - Journal - account_id required to create`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
ae_promises.create__journal = await api.create_ae_obj_crud({
|
ae_promises.create__journal = await api.create_ae_obj_crud({
|
||||||
api_cfg: api_cfg,
|
api_cfg: api_cfg,
|
||||||
obj_type: 'journal',
|
obj_type: 'journal',
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ let journals_session_data_struct: key_val = {
|
|||||||
// trigger__journal_li: null,
|
// trigger__journal_li: null,
|
||||||
|
|
||||||
show__modal_edit__journal_id: false,
|
show__modal_edit__journal_id: false,
|
||||||
|
show__modal_new__journal_obj: false,
|
||||||
show__modal_view__journal_id: null,
|
show__modal_view__journal_id: null,
|
||||||
show_list__journal_entry_li_group: true,
|
show_list__journal_entry_li_group: true,
|
||||||
show__modal_view__journal_entry_id: null,
|
show__modal_view__journal_entry_id: null,
|
||||||
@@ -65,6 +66,9 @@ let journals_session_data_struct: key_val = {
|
|||||||
journal: {
|
journal: {
|
||||||
edit: false,
|
edit: false,
|
||||||
edit_kv: {},
|
edit_kv: {},
|
||||||
|
|
||||||
|
new_journal_name: '',
|
||||||
|
new_journal_type_code: '',
|
||||||
},
|
},
|
||||||
entry: {
|
entry: {
|
||||||
edit: false,
|
edit: false,
|
||||||
|
|||||||
@@ -1,14 +1,18 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
let log_lvl: number = 0;
|
||||||
// console.log(`ae_journals +page data:`, data);
|
// console.log(`ae_journals +page data:`, data);
|
||||||
// console.log(`ae_journals Data Params:`, data.url.searchParams.get('journal_id'));
|
// console.log(`ae_journals Data Params:`, data.url.searchParams.get('journal_id'));
|
||||||
|
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
|
import { goto } from '$app/navigation';
|
||||||
|
import { FolderPlus } from '@lucide/svelte';
|
||||||
|
|
||||||
// import { api } from '$lib/api';
|
// import { api } from '$lib/api';
|
||||||
import { liveQuery } from "dexie";
|
import { liveQuery } from "dexie";
|
||||||
import { db_journals } from "$lib/ae_journals/db_journals";
|
import { db_journals } from "$lib/ae_journals/db_journals";
|
||||||
|
import { journals_func } from '$lib/ae_journals/ae_journals_functions';
|
||||||
import { ae_loc, ae_sess, ae_api, slct, slct_trigger } from '$lib/ae_stores';
|
import { ae_loc, ae_sess, ae_api, slct, slct_trigger } from '$lib/ae_stores';
|
||||||
// import { journals_loc, journals_slct, journals_trig } from '$lib/ae_journals/ae_journals_stores';
|
import { journals_loc, journals_slct, journals_trig } from '$lib/ae_journals/ae_journals_stores';
|
||||||
import { ae_util } from '$lib/ae_utils/ae_utils';
|
import { ae_util } from '$lib/ae_utils/ae_utils';
|
||||||
interface Props {
|
interface Props {
|
||||||
data: any;
|
data: any;
|
||||||
@@ -18,6 +22,7 @@ let { data }: Props = $props();
|
|||||||
|
|
||||||
|
|
||||||
import Journal_obj_li from './ae_comp__journal_obj_li.svelte';
|
import Journal_obj_li from './ae_comp__journal_obj_li.svelte';
|
||||||
|
import { journals_sess } from '$lib/ae_journals/ae_journals_stores';
|
||||||
|
|
||||||
// import Element_data_store from '$lib/element_data_store_v2.svelte';
|
// import Element_data_store from '$lib/element_data_store_v2.svelte';
|
||||||
|
|
||||||
@@ -68,11 +73,53 @@ onMount(() => {
|
|||||||
// console.log(href_url);
|
// console.log(href_url);
|
||||||
|
|
||||||
$ae_loc.href_url = href_url;
|
$ae_loc.href_url = href_url;
|
||||||
// console.log(`$ae_loc.href_url = `, $ae_loc.href_url);
|
|
||||||
console.log(`lq__journal_obj = `, $lq__journal_obj);
|
console.log(`lq__journal_obj = `, $lq__journal_obj);
|
||||||
// $journals_slct.journal_obj = db_journals.journals.get($journals_slct.journal_id);
|
|
||||||
// console.log(`$journals_slct.journal_obj = `, $journals_slct.journal_obj?.name);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
async function create_journal() {
|
||||||
|
if ($journals_sess.journal.new_journal_name && $journals_sess.journal.new_journal_type_code) {
|
||||||
|
$journals_slct.journal_id = null;
|
||||||
|
try {
|
||||||
|
let data_kv = {
|
||||||
|
// account: $slct.account_id,
|
||||||
|
name: $journals_sess.journal.new_journal_name,
|
||||||
|
type_code: $journals_sess.journal.new_journal_type_code,
|
||||||
|
cfg_json: {
|
||||||
|
"category_li":
|
||||||
|
[
|
||||||
|
{ "code": "", "name": "Default" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
journals_func.create_ae_obj__journal({
|
||||||
|
api_cfg: $ae_api,
|
||||||
|
account_id: $slct.account_id,
|
||||||
|
data_kv: data_kv,
|
||||||
|
log_lvl: log_lvl
|
||||||
|
}).then((results) => {
|
||||||
|
console.log('New journal created:', results);
|
||||||
|
$journals_slct.journal_id = results?.journal_id_random;
|
||||||
|
}).catch((error) => {
|
||||||
|
console.error('Error creating journal:', error);
|
||||||
|
alert('Failed to create journal.');
|
||||||
|
}).finally(() => {
|
||||||
|
if ($journals_slct.journal_id) {
|
||||||
|
$journals_sess.show__modal_new__journal_obj = false;
|
||||||
|
goto(`/journals/${$journals_slct.journal_id}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// console.log('New journal created:', result);
|
||||||
|
// $journals_sess.show__modal_new__journal_obj = false;
|
||||||
|
// goto(`/journals/${result.journal_id_random}`);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error creating journal:', error);
|
||||||
|
alert('Failed to create journal.');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
alert('Please provide both name and type for the journal.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
@@ -80,6 +127,27 @@ onMount(() => {
|
|||||||
|
|
||||||
<h1 class="h1 text-center">Journals for {$ae_loc.account_name ?? 'Æ loading...'}</h1>
|
<h1 class="h1 text-center">Journals for {$ae_loc.account_name ?? 'Æ loading...'}</h1>
|
||||||
|
|
||||||
|
<div class="flex flex-row items-center justify-center w-full border-gray-200 border-y-2 py-2">
|
||||||
|
<!-- Add new journal button -->
|
||||||
|
<button
|
||||||
|
class="
|
||||||
|
btn btn-sm
|
||||||
|
variant-ghost-primary
|
||||||
|
hover:variant-filled-primary
|
||||||
|
transition
|
||||||
|
"
|
||||||
|
onclick={
|
||||||
|
() => {
|
||||||
|
$journals_sess.show__modal_new__journal_obj = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<FolderPlus class="mx-1" />
|
||||||
|
New Journal
|
||||||
|
</button>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- <Element_data_store
|
<!-- <Element_data_store
|
||||||
ds_code="journals___overview"
|
ds_code="journals___overview"
|
||||||
ds_type="html"
|
ds_type="html"
|
||||||
@@ -141,5 +209,25 @@ onMount(() => {
|
|||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- Modal for creating new journal -->
|
||||||
|
{#if $journals_sess.show__modal_new__journal_obj}
|
||||||
|
<div class="modal">
|
||||||
|
<div class="modal-box">
|
||||||
|
<h3 class="font-bold text-lg">Create New Journal</h3>
|
||||||
|
<div class="py-4">
|
||||||
|
<input type="text" placeholder="Journal Name" bind:value={$journals_sess.journal.new_journal_name} class="input input-bordered w-full mb-2" />
|
||||||
|
<input type="text" placeholder="Journal Type" bind:value={$journals_sess.journal.new_journal_type_code} class="input input-bordered w-full mb-2" />
|
||||||
|
</div>
|
||||||
|
<div class="modal-action">
|
||||||
|
<button class="btn btn-primary" onclick={create_journal}>Create</button>
|
||||||
|
<button class="btn" onclick={$journals_sess.show__modal_new__journal_obj ?? false}>
|
||||||
|
Cancel
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
|
||||||
<style lang="postcss">
|
<style lang="postcss">
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -83,9 +83,9 @@ let lq__journal_obj = $derived(liveQuery(async () => {
|
|||||||
|
|
||||||
<!-- Add default journal entry -->
|
<!-- Add default journal entry -->
|
||||||
<span class="flex flex-row items-center gap-1">
|
<span class="flex flex-row items-center gap-1">
|
||||||
<span class="text-sm text-gray-500 hidden md:inline">
|
<!-- <span class="text-sm text-gray-500 hidden md:inline">
|
||||||
New entry:
|
New entry:
|
||||||
</span>
|
</span> -->
|
||||||
<button
|
<button
|
||||||
class="
|
class="
|
||||||
btn btn-sm
|
btn btn-sm
|
||||||
|
|||||||
@@ -208,7 +208,7 @@ if (browser) {
|
|||||||
}
|
}
|
||||||
journals_func.create_ae_obj__journal_entry({
|
journals_func.create_ae_obj__journal_entry({
|
||||||
api_cfg: $ae_api,
|
api_cfg: $ae_api,
|
||||||
journal_id: $lq__journal_obj?.journal_id,
|
journal_id: $lq__journal_obj?.journal_id ?? '',
|
||||||
data_kv: data_kv,
|
data_kv: data_kv,
|
||||||
log_lvl: log_lvl
|
log_lvl: log_lvl
|
||||||
}).then((results) => {
|
}).then((results) => {
|
||||||
@@ -216,8 +216,8 @@ if (browser) {
|
|||||||
$journals_slct.journal_entry_id = results?.journal_entry_id_random;
|
$journals_slct.journal_entry_id = results?.journal_entry_id_random;
|
||||||
// alert(`Journal entry created successfully! ${$journals_slct.journal_entry_id}`);
|
// alert(`Journal entry created successfully! ${$journals_slct.journal_entry_id}`);
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
console.error('Error updating journal entry:', error);
|
console.error('Error creating journal entry:', error);
|
||||||
alert('Failed to update journal entry.');
|
alert('Failed to create journal entry.');
|
||||||
}).finally(() => {
|
}).finally(() => {
|
||||||
goto(`/journals/${$lq__journal_obj?.journal_id}/entry/${$journals_slct.journal_entry_id}`);
|
goto(`/journals/${$lq__journal_obj?.journal_id}/entry/${$journals_slct.journal_entry_id}`);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user