feat: Migrate ESLint to flat config and resolve initial linting errors

Migrated the ESLint configuration to the new flat config format ()
and addressed several initial linting errors.

Key changes include:
- Updated ESLint configuration to treat  as warnings instead of errors.
- Fixed  errors in  by declaring  and .
- Corrected  error in  by using  instead of an out-of-scope .
- Resolved  error in  by replacing the undefined  directive with the  component.
- Addressed  errors in  by replacing  with  and  with .
- Fixed  errors in  by importing necessary modules (, , ) and adding missing props (, , , , ).
This commit is contained in:
Scott Idem
2025-11-17 18:46:54 -05:00
parent b99e85f1db
commit 7e1eaba3bc
374 changed files with 95654 additions and 93952 deletions

View File

@@ -1,93 +1,85 @@
<script lang="ts">
/** @type {import('./$types').LayoutProps} */
let log_lvl = $state(0);
/** @type {import('./$types').LayoutProps} */
let log_lvl = $state(0);
// *** Import Svelte specific
// import { browser } from '$app/environment';
import { goto } from '$app/navigation';
// *** Import Svelte specific
// import { browser } from '$app/environment';
import { goto } from '$app/navigation';
// *** Import other supporting libraries
import {
House,
RefreshCw,
Satellite
} from '@lucide/svelte';
// *** Import other supporting libraries
import { House, RefreshCw, Satellite } from '@lucide/svelte';
// *** Import Aether specific variables and functions
import { ae_loc, ae_sess, ae_api, slct } from '$lib/stores/ae_stores';
import { journals_loc, journals_slct, journals_trig } from '$lib/ae_journals/ae_journals_stores';
import Element_data_store from '$lib/elements/element_data_store_v2.svelte';
import Help_tech from '$lib/app_components/e_app_help_tech.svelte';
// *** Import Aether specific variables and functions
import { ae_loc, ae_sess, ae_api, slct } from '$lib/stores/ae_stores';
import { journals_loc, journals_slct, journals_trig } from '$lib/ae_journals/ae_journals_stores';
import Element_data_store from '$lib/elements/element_data_store_v2.svelte';
import Help_tech from '$lib/app_components/e_app_help_tech.svelte';
// *** Setup Svelte properties
interface Props {
data: any;
children: any;
}
let { data, children }: Props = $props();
// *** Setup Svelte properties
interface Props {
data: any;
children: any;
}
let { data, children }: Props = $props();
$journals_loc.qry__enabled = 'enabled';
$journals_loc.qry__hidden = 'not_hidden';
$journals_loc.qry__limit = 15;
$journals_loc.qry__offset = 0;
$journals_loc.qry__enabled = 'enabled';
$journals_loc.qry__hidden = 'not_hidden';
$journals_loc.qry__limit = 15;
$journals_loc.qry__offset = 0;
// Quickly save the data passed from the parent(s) to the Svelte stores, localStorage, and other.
$slct.account_id = data.account_id;
$effect(() => {
if (log_lvl) {
console.log(`$slct.account_id = `, $slct.account_id);
}
});
let ae_acct = data[$slct.account_id];
// Quickly save the data passed from the parent(s) to the Svelte stores, localStorage, and other.
$slct.account_id = data.account_id;
$effect(() => {
if (log_lvl) {
console.log(`$slct.account_id = `, $slct.account_id);
}
});
let ae_acct = data[$slct.account_id];
$journals_slct.journal_id = ae_acct.slct.journal_id;
$journals_slct.journal_obj_li = ae_acct.slct.journal_obj_li;
$journals_slct.journal_id = ae_acct.slct.journal_id;
$journals_slct.journal_obj_li = ae_acct.slct.journal_obj_li;
let nav_y_height = $state(0);
let nav_y_height = $state(0);
let box: any;
let xLeft = $state(0);
let xScroll = $state(0);
let xWidth = $state(0);
let yTop = $state(0);
let yScroll = $state(0);
let yHeight = $state(0);
let box: any;
let xLeft = $state(0);
let xScroll = $state(0);
let xWidth = $state(0);
let yTop = $state(0);
let yScroll = $state(0);
let yHeight = $state(0);
function handle_scroll() {
// console.log(`handle_scroll() called`);
if (box) {
xLeft = box.scrollLeft;
xScroll = box.scrollWidth;
xWidth = box.clientWidth;
yTop = box.scrollTop;
yHeight = box.clientHeight;
yScroll = box.scrollHeight;
// console.log(`handle_scroll() called: ${yTop}`);
}
}
function scroll_container() {
return document.getElementById('ae_main_content') || document.documentElement || document.body;
}
function handle_scroll() {
// console.log(`handle_scroll() called`);
if (box) {
xLeft = box.scrollLeft;
xScroll = box.scrollWidth;
xWidth = box.clientWidth;
yTop = box.scrollTop;
yHeight = box.clientHeight;
yScroll = box.scrollHeight;
// console.log(`handle_scroll() called: ${yTop}`);
}
}
function scroll_container() {
return document.getElementById('ae_main_content') || document.documentElement || document.body;
}
</script>
<svelte:head>
<title>Journals - {$journals_loc.title ?? 'Æ loading...'}</title>
</svelte:head>
{#if $ae_loc.user_id && $ae_loc.person_id && $ae_loc.trusted_access}
<!-- These are needed: h-full overflow-auto -->
<div
id="ae_main_content"
bind:clientHeight={$ae_loc.iframe_height}
bind:this={box}
onscroll={handle_scroll}
class:iframe={$ae_loc?.iframe}
class="
<!-- These are needed: h-full overflow-auto -->
<div
id="ae_main_content"
bind:clientHeight={$ae_loc.iframe_height}
bind:this={box}
onscroll={handle_scroll}
class:iframe={$ae_loc?.iframe}
class="
ae_journals
h-full max-h-full max-w-7xl
overflow-auto
@@ -97,14 +89,13 @@ function scroll_container() {
bg-gray-50 dark:bg-gray-900
text-gray-800 dark:text-gray-200
"
>
<!-- class:hidden={yTop > 200} -->
<nav
bind:clientHeight={nav_y_height}
class:hidden={yTop > 600}
class:opacity-0={yTop > 250}
class="
>
<!-- class:hidden={yTop > 200} -->
<nav
bind:clientHeight={nav_y_height}
class:hidden={yTop > 600}
class:opacity-0={yTop > 250}
class="
submenu
z-20
hover:opacity-100
@@ -123,139 +114,137 @@ function scroll_container() {
transition-all duration-1000
"
>
<span class="justify-self-start">
>
<span class="justify-self-start">
<!-- Be sure to explain what &AElig; (Aether) means in the title text or similar! -->
<Satellite size="1.5em" class="mx-1 inline-block text-gray-500" />
<abbr title="Aether - Journals Module"> Æ Journals </abbr>
</span>
<a
href="/"
class="btn btn-sm preset-tonal-surface border border-surface-500 hover:preset-filled-success-500"
>
<House />
<span class="hidden md:inline"> Home </span>
</a>
<!-- <a href="/about" class="btn btn-sm">About</a> -->
<!-- <a href="/settings" class="btn btn-sm">Settings</a> -->
<button
onclick={() => {
if ($ae_loc.edit_mode) {
// Confirm before clearing
if (
!confirm(
'Are you sure you want to clear IndexedDB databases, localStorage, and sessionStorage? This will also reload the page.'
)
) {
return;
}
<!-- Be sure to explain what &AElig; (Aether) means in the title text or similar! -->
<Satellite
size="1.5em"
class="mx-1 inline-block text-gray-500"
/>
<abbr title="Aether - Journals Module">
Æ
Journals
</abbr>
</span>
<a
href="/"
class="btn btn-sm preset-tonal-surface border border-surface-500 hover:preset-filled-success-500"
>
<House />
<span class="hidden md:inline">
Home
</span>
</a>
<!-- <a href="/about" class="btn btn-sm">About</a> -->
<!-- <a href="/settings" class="btn btn-sm">Settings</a> -->
<button
console.log(
'Clearing IndexedDB, localStorage, sessionStorage, and reloading the page...'
);
onclick={() => {
if ($ae_loc.edit_mode) {
// Confirm before clearing
if (!confirm("Are you sure you want to clear IndexedDB databases, localStorage, and sessionStorage? This will also reload the page.")) {
return;
}
// Clear Indexed DB
indexedDB.deleteDatabase('ae_archives_db'); // Archives module
indexedDB.deleteDatabase('ae_core_db');
indexedDB.deleteDatabase('ae_events_db'); // Events module
indexedDB.deleteDatabase('ae_journals_db'); // Journals module
indexedDB.deleteDatabase('ae_posts_db'); // Posts module
indexedDB.deleteDatabase('ae_sponsorships_db'); // Sponsorships module
console.log("Clearing IndexedDB, localStorage, sessionStorage, and reloading the page...");
// Clear localStorage and sessionStorage
// Clearing the localStorage will force it to be re-created.
localStorage.clear();
sessionStorage.clear();
// Clear Indexed DB
indexedDB.deleteDatabase('ae_archives_db'); // Archives module
indexedDB.deleteDatabase('ae_core_db');
indexedDB.deleteDatabase('ae_events_db'); // Events module
indexedDB.deleteDatabase('ae_journals_db'); // Journals module
indexedDB.deleteDatabase('ae_posts_db'); // Posts module
indexedDB.deleteDatabase('ae_sponsorships_db'); // Sponsorships module
goto('/', { invalidateAll: true });
// Clear localStorage and sessionStorage
// Clearing the localStorage will force it to be re-created.
localStorage.clear();
sessionStorage.clear();
// window.location.reload(true);
} else {
// Confirm before clearing
if (
!confirm(
'Are you sure you want to clear IndexedDB databases and some caches? This will also reload the page.'
)
) {
return;
}
goto('/', {invalidateAll: true});
console.log(
'Clearing IndexedDB, localStorage, sessionStorage, and reloading the page...'
);
// window.location.reload(true);
} else {
// Confirm before clearing
if (!confirm("Are you sure you want to clear IndexedDB databases and some caches? This will also reload the page.")) {
return;
}
// Clear Indexed DB
indexedDB.deleteDatabase('ae_archives_db'); // Archives module
indexedDB.deleteDatabase('ae_core_db');
indexedDB.deleteDatabase('ae_events_db'); // Events module
indexedDB.deleteDatabase('ae_journals_db'); // Journals module
indexedDB.deleteDatabase('ae_posts_db'); // Posts module
indexedDB.deleteDatabase('ae_sponsorships_db'); // Sponsorships module
console.log("Clearing IndexedDB, localStorage, sessionStorage, and reloading the page...");
window.location.reload();
}
// Clear Indexed DB
indexedDB.deleteDatabase('ae_archives_db'); // Archives module
indexedDB.deleteDatabase('ae_core_db');
indexedDB.deleteDatabase('ae_events_db'); // Events module
indexedDB.deleteDatabase('ae_journals_db'); // Journals module
indexedDB.deleteDatabase('ae_posts_db'); // Posts module
indexedDB.deleteDatabase('ae_sponsorships_db'); // Sponsorships module
// This does not seem to work fast enough or something?
// goto('/', {invalidateAll: true});
window.location.reload();
}
// The page does usually seem to reload correctly?
// window.location.reload(true); // true only works with Firefox
// alert('Local and Session Storage cleared and Indexed DBs deleted. You will probably want to refresh the page.');
}}
class="btn btn-sm preset-tonal-surface border border-surface-500 hover:preset-filled-warning-500"
title="Clear App Data & Settings: Clear IndexedDB and reload. If in edit mode localStorage and sessionStorage will also be cleared."
>
<!-- <span class="fas fa-eraser mx-1"></span> -->
<!-- <span class="fas fa-sync mx-1"></span> -->
<RefreshCw />
<span class="hidden md:inline">Clear & Reload</span>
</button>
// This does not seem to work fast enough or something?
// goto('/', {invalidateAll: true});
<Help_tech
e_class=""
e_class_form_hidden=""
e_class_form_showing="min-w-full"
btn_class=""
show_btn_class="btn-info"
additional_kv={{
test: true
}}
></Help_tech>
</nav>
// The page does usually seem to reload correctly?
// window.location.reload(true); // true only works with Firefox
// alert('Local and Session Storage cleared and Indexed DBs deleted. You will probably want to refresh the page.');
}}
class="btn btn-sm preset-tonal-surface border border-surface-500 hover:preset-filled-warning-500"
title="Clear App Data & Settings: Clear IndexedDB and reload. If in edit mode localStorage and sessionStorage will also be cleared."
>
<!-- <span class="fas fa-eraser mx-1"></span> -->
<!-- <span class="fas fa-sync mx-1"></span> -->
<RefreshCw />
<span class="hidden md:inline">Clear & Reload</span>
</button>
<Help_tech
e_class=""
e_class_form_hidden=""
e_class_form_showing="min-w-full"
btn_class=""
show_btn_class="btn-info"
additional_kv={{
'test': true,
}}
>
</Help_tech>
</nav>
<!-- Add overflow-auto to section element to have the main nav sort of sticky at top -->
<section
class:iframe={$ae_loc?.iframe}
class:pt-12={nav_y_height <= 50}
class:pt-20={nav_y_height > 50 && nav_y_height <= 100}
class:pt-32={nav_y_height > 100 && nav_y_height <= 150}
class:pt-40={nav_y_height > 150 && nav_y_height <= 200}
class="
<!-- Add overflow-auto to section element to have the main nav sort of sticky at top -->
<section
class:iframe={$ae_loc?.iframe}
class:pt-12={nav_y_height <= 50}
class:pt-20={nav_y_height > 50 && nav_y_height <= 100}
class:pt-32={nav_y_height > 100 && nav_y_height <= 150}
class:pt-40={nav_y_height > 150 && nav_y_height <= 200}
class="
main_content
grow
px-1 md:px-2
pb-48
"
>
{@render children?.()}
</section>
>
{@render children?.()}
</section>
<div
class:hidden={yTop < 500}
class="
<div
class:hidden={yTop < 500}
class="
z-20
hover:opacity-100
fixed bottom-48 right-1
flex flex-col gap-1 items-end justify-end
"
>
<!-- Scroll to top button -->
<button
type="button"
class="
>
<!-- Scroll to top button -->
<button
type="button"
class="
ae_btn_success_outlined
@@ -264,42 +253,45 @@ function scroll_container() {
transition-all duration-500
"
class:hidden={yTop < 500}
class:opacity-80={yTop > 750}
class:opacity-0={yTop < 750}
class:ae_btn_warning_filled={yTop > 1500}
onclick={() => {
log_lvl = 1;
$effect(() => {
if (log_lvl) {
console.log(`Scroll to top button clicked. scroll_y: ${scroll_y} scrollTop: ${scroll_container().scrollTop}`, scroll_container());
// document.getElementById('ae_idaa')?.scrollTo(0, 0);
// document.documentElement?.scrollTo(0, 0);
// document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
// document.body.scrollTop = 0; // For Safari
}
});
class:hidden={yTop < 500}
class:opacity-80={yTop > 750}
class:opacity-0={yTop < 750}
class:ae_btn_warning_filled={yTop > 1500}
onclick={() => {
log_lvl = 1;
$effect(() => {
if (log_lvl) {
console.log(
`Scroll to top button clicked. yScroll: ${yScroll} scrollTop: ${scroll_container().scrollTop}`,
scroll_container()
);
// document.getElementById('ae_idaa')?.scrollTo(0, 0);
// document.documentElement?.scrollTo(0, 0);
// document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
// document.body.scrollTop = 0; // For Safari
}
});
console.log('Not Safari, using smooth scroll to top');
document.getElementById('ae_main_content')?.scrollTo({
top: 0,
behavior: 'smooth'
});
console.log('Not Safari, using smooth scroll to top');
document.getElementById('ae_main_content')?.scrollTo({
top: 0,
behavior: 'smooth'
});
window.parent.postMessage({'scroll_to': 0}, "*"); // This should be
}}
title="Scroll to top"
>
<span class="fas fa-arrow-up"></span>
Scroll to Top
</button>
window.parent.postMessage({ scroll_to: 0 }, '*'); // This should be
}}
title="Scroll to top"
>
<span class="fas fa-arrow-up"></span>
Scroll to Top
</button>
<!-- Scroll to the right button -->
<!-- Temporarily hidden until I figure out a better way to do this -->
<button
class:hidden={1==1}
type="button"
class="
<!-- Scroll to the right button -->
<!-- Temporarily hidden until I figure out a better way to do this -->
<button
class:hidden={1 == 1}
type="button"
class="
ae_btn_success_outlined
btn btn-sm btn-secondary
@@ -307,28 +299,27 @@ function scroll_container() {
transition-all duration-500
"
class:ae_btn_warning_filled={xLeft + xWidth < xScroll - 750}
onclick={() => {
document.getElementById('ae_main_content')?.scrollTo({
left: 0,
behavior: 'smooth'
});
class:ae_btn_warning_filled={xLeft + xWidth < xScroll - 750}
onclick={() => {
document.getElementById('ae_main_content')?.scrollTo({
left: 0,
behavior: 'smooth'
});
window.parent.postMessage({'scroll_to': scroll_x}, "*");
}}
title="Scroll to right"
>
<span class="fas fa-arrow-right"></span>
<!-- Scroll to Right
xLeft={xLeft} xScroll={xScroll} xWidth={xWidth} scroll_x={scroll_x} scrollLeft={scroll_container().scrollLeft}
window.parent.postMessage({ scroll_to: xScroll }, '*');
}}
title="Scroll to right"
>
<span class="fas fa-arrow-right"></span>
<!-- Scroll to Right
xLeft={xLeft} xScroll={xScroll} xWidth={xWidth} xScroll={xScroll} scrollLeft={scroll_container().scrollLeft}
total={xLeft + xWidth} -->
</button>
</button>
<!-- Scroll to bottom button -->
<button
type="button"
class="
<!-- Scroll to bottom button -->
<button
type="button"
class="
ae_btn_success_outlined
btn btn-sm btn-secondary
@@ -336,45 +327,46 @@ function scroll_container() {
transition-all duration-500
"
class:hidden={yTop < 500}
class:opacity-80={yTop > 750}
class:opacity-0={yTop < 750}
class:ae_btn_warning_filled={yTop > 1500}
onclick={() => {
log_lvl = 1;
$effect(() => {
if (log_lvl) {
console.log(`Scroll to bottom button clicked. scroll_y: ${scroll_y} scrollTop: ${scroll_container().scrollTop}`, scroll_container());
// document.getElementById('ae_idaa')?.scrollTo(0, 0);
// document.documentElement?.scrollTo(0, 0);
// document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
// document.body.scrollTop = 0; // For Safari
}
});
class:hidden={yTop < 500}
class:opacity-80={yTop > 750}
class:opacity-0={yTop < 750}
class:ae_btn_warning_filled={yTop > 1500}
onclick={() => {
log_lvl = 1;
$effect(() => {
if (log_lvl) {
console.log(
`Scroll to bottom button clicked. yScroll: ${yScroll} scrollTop: ${scroll_container().scrollTop}`,
scroll_container()
);
// document.getElementById('ae_idaa')?.scrollTo(0, 0);
// document.documentElement?.scrollTo(0, 0);
// document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
// document.body.scrollTop = 0; // For Safari
}
});
console.log('Not Safari, using smooth scroll to bottom');
document.getElementById('ae_main_content')?.scrollTo({
top: yScroll,
behavior: 'smooth'
});
console.log('Not Safari, using smooth scroll to bottom');
document.getElementById('ae_main_content')?.scrollTo({
top: yScroll,
behavior: 'smooth'
});
window.parent.postMessage({'scroll_to': scroll_y}, "*"); // This should be
}}
title="Scroll to bottom"
>
<span class="fas fa-arrow-down"></span>
Scroll to Bottom
<!-- yTop={yTop} yScroll={yScroll} yHeight={yHeight} scroll_y={scroll_y} scrollTop={scroll_container().scrollTop} total={scroll_container().scrollTop + yHeight} -->
</button>
window.parent.postMessage({ scroll_to: yScroll }, '*'); // This should be
}}
title="Scroll to bottom"
>
<span class="fas fa-arrow-down"></span>
Scroll to Bottom
<!-- yTop={yTop} yScroll={yScroll} yHeight={yHeight} yScroll={yScroll} scrollTop={scroll_container().scrollTop} total={scroll_container().scrollTop + yHeight} -->
</button>
</div>
</div>
<footer
class:hidden={yTop > 300}
class:opacity-80={yTop < 250}
class:opacity-0={yTop > 250}
class="
<footer
class:hidden={yTop > 300}
class:opacity-80={yTop < 250}
class:opacity-0={yTop > 250}
class="
footer
z-20
hover:opacity-100
@@ -395,24 +387,19 @@ function scroll_container() {
transition-all duration-1000
"
class:ae_debug={$ae_loc?.debug}
>
<Element_data_store
ds_code="hub__site__appshell_footer"
ds_type="html"
class_li="grow flex flex-row justify-between"
/>
</footer>
</div>
class:ae_debug={$ae_loc?.debug}
>
<Element_data_store
ds_code="hub__site__appshell_footer"
ds_type="html"
class_li="grow flex flex-row justify-between"
/>
</footer>
</div>
{:else}
<section class="main_content grow px-1 md:px-2 pb-28 flex flex-col gap-1 items-center">
<p class="text-center">
You are not logged in as a user. You must be signed in to access the journals module.
</p>
</section>
<section class="main_content grow px-1 md:px-2 pb-28 flex flex-col gap-1 items-center">
<p class="text-center">
You are not logged in as a user. You must be signed in to access the journals module.
</p>
</section>
{/if}

View File

@@ -5,35 +5,34 @@ console.log(`ae_journals +layout.ts start`);
// import { browser } from '$app/environment';
// import { journals_func } from '$lib/ae_journals/ae_journals_functions';
export async function load({ params, parent }) {
let log_lvl: number = 0;
const log_lvl: number = 0;
let parent_data = await parent();
// console.log(`ae_journals +layout.ts parent_data:`, parent_data);
const parent_data = await parent();
// console.log(`ae_journals +layout.ts parent_data:`, parent_data);
let account_id = parent_data.account_id;
if (!account_id) {
console.log(`journals +layout.ts: The account_id was not found in the parent_data!!!`);
return false;
}
const account_id = parent_data.account_id;
if (!account_id) {
console.log(`journals +layout.ts: The account_id was not found in the parent_data!!!`);
return false;
}
let ae_acct = parent_data[account_id];
if (log_lvl) {
console.log(`ae_acct = `, ae_acct);
}
const ae_acct = parent_data[account_id];
if (log_lvl) {
console.log(`ae_acct = `, ae_acct);
}
// let submenu = {
// main: {name: 'Main', href: '/journals', access: false},
// // manage: {name: 'Manage', href: '/journals/manage', access: 'administrator', disable: true, hide: true},
// locations: {name: 'Locations', href: `/journals/${note_id}/locations`, access: false, disable: false, hide: false},
// };
// parent_data.submenu = submenu
// let submenu = {
// main: {name: 'Main', href: '/journals', access: false},
// // manage: {name: 'Manage', href: '/journals/manage', access: 'administrator', disable: true, hide: true},
// locations: {name: 'Locations', href: `/journals/${note_id}/locations`, access: false, disable: false, hide: false},
// };
// parent_data.submenu = submenu
// WARNING: Precaution against shared parent_data between sites and sessions.
parent_data[account_id] = ae_acct;
// WARNING: Precaution against shared parent_data between sites and sessions.
parent_data[account_id] = ae_acct;
return parent_data;
return parent_data;
}
// export const prerender = false;

View File

@@ -1,160 +1,156 @@
<script lang="ts">
let log_lvl: number = 0;
// console.log(`ae_journals +page data:`, data);
// console.log(`ae_journals Data Params:`, data.url.searchParams.get('journal_id'));
let log_lvl: number = 0;
// console.log(`ae_journals +page data:`, data);
// console.log(`ae_journals Data Params:`, data.url.searchParams.get('journal_id'));
// *** Import Svelte specific
import { onMount } from 'svelte';
import { goto } from '$app/navigation';
// *** Import Svelte specific
import { onMount } from 'svelte';
import { goto } from '$app/navigation';
// *** Import other supporting libraries
import {
BookPlus,
FolderPlus, Library,
SquareLibrary,
Wrench
} from '@lucide/svelte';
import { liveQuery } from "dexie";
import { Modal } from 'flowbite-svelte';
// *** Import other supporting libraries
import { BookPlus, FolderPlus, Library, SquareLibrary, Wrench } from '@lucide/svelte';
import { liveQuery } from 'dexie';
import { Modal } from 'flowbite-svelte';
// *** Import Aether specific variables and functions
// import { api } from '$lib/api';
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/stores/ae_stores';
import { journals_loc, journals_sess, journals_slct, journals_trig } from '$lib/ae_journals/ae_journals_stores';
import { ae_util } from '$lib/ae_utils/ae_utils';
interface Props {
data: any;
}
// *** Import Aether specific variables and functions
// import { api } from '$lib/api';
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/stores/ae_stores';
import {
journals_loc,
journals_sess,
journals_slct,
journals_trig
} from '$lib/ae_journals/ae_journals_stores';
import { ae_util } from '$lib/ae_utils/ae_utils';
interface Props {
data: any;
}
let { data }: Props = $props();
let { data }: Props = $props();
import Modal_journals_cfg from './modal_journals_config.svelte';
import Journal_obj_li from './ae_comp__journal_obj_li.svelte';
import Modal_journals_cfg from './modal_journals_config.svelte';
import Journal_obj_li from './ae_comp__journal_obj_li.svelte';
// import Element_data_store from '$lib/element_data_store_v2.svelte';
// import Element_data_store from '$lib/element_data_store_v2.svelte';
let ae_acct = data[$slct.account_id];
// $journals_slct.journal_obj = ae_acct.slct.journal_obj;
// $journals_slct.journal_obj_li = ae_acct.slct.journal_obj_li;
let lq__journal_obj_li = $derived(
liveQuery(async () => {
let results = await db_journals.journal
.where('person_id')
.equals($ae_loc.person_id)
// .sortBy('group')
// .sortBy('priority')
// .sortBy('sort')
.reverse()
.sortBy('tmp_sort_3');
let ae_acct = data[$slct.account_id];
// $journals_slct.journal_obj = ae_acct.slct.journal_obj;
// $journals_slct.journal_obj_li = ae_acct.slct.journal_obj_li;
// .orderBy('tmp_sort_3')
// .reverse()
// .toArray()
// .sortBy('start_datetime')
// () => db_journals.journals
// .where('conference')
// // .aboveOrEqual(0)
// .equals('true')
// // .above(0)
// .sortBy('name') // Use sortBy() instead of orderBy(). toArray() is also not needed???
// // .sortBy('[priority+name]')
// // .orderBy('name')
// // .offset(10).limit(5)
// // .toArray()
let lq__journal_obj_li = $derived(liveQuery(async () => {
let results = await db_journals.journal
.where('person_id')
.equals($ae_loc.person_id)
// .sortBy('group')
// .sortBy('priority')
// .sortBy('sort')
.reverse()
.sortBy('tmp_sort_3')
return results;
})
);
// console.log(`lq__journal_obj_li:`, $lq__journal_obj_li);
// .orderBy('tmp_sort_3')
// .reverse()
// .toArray()
let lq__journal_obj = $derived(
liveQuery(async () => {
let results = await db_journals.journal.where('id').equals(ae_acct.slct.journal_id).toArray();
// .first()
// .get($journals_slct.journal_id)
return results;
})
);
// .sortBy('start_datetime')
// () => db_journals.journals
// .where('conference')
// // .aboveOrEqual(0)
// .equals('true')
// // .above(0)
// .sortBy('name') // Use sortBy() instead of orderBy(). toArray() is also not needed???
// // .sortBy('[priority+name]')
// // .orderBy('name')
// // .offset(10).limit(5)
// // .toArray()
onMount(() => {
console.log('Journals: +page.svelte');
return results;
}));
// console.log(`lq__journal_obj_li:`, $lq__journal_obj_li);
console.log('ae_ slct:', $slct);
let lq__journal_obj = $derived(liveQuery(async () => {
let results = await db_journals.journal
.where('id')
.equals(ae_acct.slct.journal_id)
.toArray()
// .first()
// .get($journals_slct.journal_id)
let href_url = window.location.href;
// console.log(href_url);
return results;
}));
$ae_loc.href_url = href_url;
console.log(`lq__journal_obj = `, $lq__journal_obj);
});
onMount(() => {
console.log('Journals: +page.svelte');
console.log('ae_ slct:', $slct);
let href_url = window.location.href;
// console.log(href_url);
$ae_loc.href_url = href_url;
console.log(`lq__journal_obj = `, $lq__journal_obj);
});
async function create_journal() {
// Confirm before creating a new journal
if (confirm('Are you sure you want to create a new journal?')) {
console.log('Creating new journal...');
} else {
console.log('Journal creation cancelled.');
return;
}
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,
person_id_random: $ae_loc.person_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.');
}
}
async function create_journal() {
// Confirm before creating a new journal
if (confirm('Are you sure you want to create a new journal?')) {
console.log('Creating new journal...');
} else {
console.log('Journal creation cancelled.');
return;
}
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,
person_id_random: $ae_loc.person_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>
<!-- Svelte Page for a AE Journals Module main page -->
<section
class="
class="
ae_journals
mx-auto
flex flex-col gap-1
@@ -165,70 +161,59 @@ async function create_journal() {
max-w-max
space-y-2
"
>
>
<h1 class="h1 text-4xl text-center text-gray-800 dark:text-gray-200">
<!-- <Library size="1em" class="mx-1 inline-block" /> -->
<SquareLibrary size="1em" class="mx-1 inline-block text-neutral-800/60" />
Journals for {$ae_loc.account_name ?? 'Æ loading...'}
{$ae_loc.person.given_name ? `- ${$ae_loc.person.given_name}` : ''}
</h1>
<h1 class="h1 text-4xl text-center text-gray-800 dark:text-gray-200">
<!-- <Library size="1em" class="mx-1 inline-block" /> -->
<SquareLibrary size="1em" class="mx-1 inline-block text-neutral-800/60"/>
Journals for {$ae_loc.account_name ?? 'Æ loading...'}
{$ae_loc.person.given_name ? `- ${$ae_loc.person.given_name}` : ''}
</h1>
<div
class="flex flex-row flex-wrap gap-1 items-center justify-center w-full border-gray-200 border-y-2 py-2"
class:hidden={!$ae_loc.edit_mode}
>
<!-- Add new journal button -->
<button
type="button"
class="
<div
class="flex flex-row flex-wrap gap-1 items-center justify-center w-full border-gray-200 border-y-2 py-2"
class:hidden={!$ae_loc.edit_mode}
>
<!-- Add new journal button -->
<button
type="button"
class="
btn btn-sm
preset-tonal-secondary border border-secondary-500
hover:preset-filled-secondary-500
transition
"
onclick={
() => {
$journals_sess.show__modal_new__journal_obj = true;
}
}
title="Create a new journal"
>
<!-- <FolderPlus class="mx-1" /> -->
<BookPlus class="mx-1" />
<span class="hidden md:inline">
New Journal
</span>
</button>
onclick={() => {
$journals_sess.show__modal_new__journal_obj = true;
}}
title="Create a new journal"
>
<!-- <FolderPlus class="mx-1" /> -->
<BookPlus class="mx-1" />
<span class="hidden md:inline"> New Journal </span>
</button>
<!-- Show Journals Config button -->
<button
type="button"
class="
<!-- Show Journals Config button -->
<button
type="button"
class="
btn btn-sm
preset-tonal-secondary border border-secondary-500
hover:preset-filled-secondary-500
transition
"
onclick={
() => {
$journals_sess.show__modal__journals_config = true;
// Redirect to the journals config page
// goto('/journals/config');
}
}
title="Configure Journals"
>
<Wrench class="mx-1" />
<span class="hidden md:inline">
Journals Config
</span>
</button>
onclick={() => {
$journals_sess.show__modal__journals_config = true;
// Redirect to the journals config page
// goto('/journals/config');
}}
title="Configure Journals"
>
<Wrench class="mx-1" />
<span class="hidden md:inline"> Journals Config </span>
</button>
</div>
</div>
<!-- <Element_data_store
<!-- <Element_data_store
ds_code="journals___overview"
ds_type="html"
for_type="journal"
@@ -237,7 +222,7 @@ async function create_journal() {
class_li="p-2"
/> -->
<!-- <Element_data_store
<!-- <Element_data_store
ds_code="journals___example"
ds_type="html"
for_type="journal"
@@ -250,92 +235,83 @@ async function create_journal() {
show_edit={false}
/> -->
{#await ae_acct.slct.journal_obj_li}
<div class="flex flex-col items-center justify-center p-8">
<span class="fas fa-spinner fa-spin text-4xl text-primary-500 mb-4"></span>
<span class="text-lg text-gray-600 dark:text-gray-400">Loading journals...</span>
</div>
{:then}
<!-- <span class="flex flex-row items-center justify-center">
{#await ae_acct.slct.journal_obj_li}
<div class="flex flex-col items-center justify-center p-8">
<span class="fas fa-spinner fa-spin text-4xl text-primary-500 mb-4"></span>
<span class="text-lg text-gray-600 dark:text-gray-400">Loading journals...</span>
</div>
{:then}
<!-- <span class="flex flex-row items-center justify-center">
<span class="fas fa-check text-green-500 mx-1"></span>
<span>Loaded</span>
</span> -->
{#if $lq__journal_obj_li && $lq__journal_obj_li?.length}
<Journal_obj_li
lq__journal_obj_li={lq__journal_obj_li}
/>
{:else}
<div class="flex flex-col items-center justify-center p-4 text-center">
<p class="text-lg text-gray-600 dark:text-gray-400 mb-4">No journals found.</p>
<p class="text-md text-gray-500 dark:text-gray-300">Click the "New Journal" button above to create your first journal.</p>
</div>
{/if}
{:catch error}
<div class="text-red-800">
<span class="fas fa-exclamation-triangle text-xl"></span>
<span>Error: {error.message}</span>
</div>
{/await}
{#if $lq__journal_obj_li && $lq__journal_obj_li?.length}
<Journal_obj_li {lq__journal_obj_li} />
{:else}
<div class="flex flex-col items-center justify-center p-4 text-center">
<p class="text-lg text-gray-600 dark:text-gray-400 mb-4">No journals found.</p>
<p class="text-md text-gray-500 dark:text-gray-300">
Click the "New Journal" button above to create your first journal.
</p>
</div>
{/if}
{:catch error}
<div class="text-red-800">
<span class="fas fa-exclamation-triangle text-xl"></span>
<span>Error: {error.message}</span>
</div>
{/await}
</section>
<!-- Modal for creating new journal -->
{#if $journals_sess.show__modal_new__journal_obj}
<Modal
title="Create New Journal"
bind:open={$journals_sess.show__modal_new__journal_obj}
autoclose={false}
placement="top-center"
size="xl"
class="top-center bg-white dark:bg-gray-800 text-gray-800 dark:text-gray-200 rounded-lg border-gray-200 dark:border-gray-700 divide-gray-200 dark:divide-gray-700 shadow-md relative flex flex-col mx-auto w-full divide-y"
>
<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 preset-tonal-primary"
onclick={create_journal}>Create</button>
<button
type="button"
onclick={() => {
// Close the modal
$journals_sess.show__modal_new__journal_obj = false;
}}
class="btn preset-tonal-secondary"
>
Cancel
</button>
</div>
</div>
</div>
</Modal>
<Modal
title="Create New Journal"
bind:open={$journals_sess.show__modal_new__journal_obj}
autoclose={false}
placement="top-center"
size="xl"
class="top-center bg-white dark:bg-gray-800 text-gray-800 dark:text-gray-200 rounded-lg border-gray-200 dark:border-gray-700 divide-gray-200 dark:divide-gray-700 shadow-md relative flex flex-col mx-auto w-full divide-y"
>
<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 preset-tonal-primary" onclick={create_journal}>Create</button>
<button
type="button"
onclick={() => {
// Close the modal
$journals_sess.show__modal_new__journal_obj = false;
}}
class="btn preset-tonal-secondary"
>
Cancel
</button>
</div>
</div>
</div>
</Modal>
{/if}
{#if $journals_sess.show__modal__journals_config}
<Modal_journals_cfg
show={$journals_sess.show__modal__journals_config}
/>
<Modal_journals_cfg show={$journals_sess.show__modal__journals_config} />
{/if}
<style lang="postcss">
</style>

View File

@@ -5,61 +5,60 @@ import { browser } from '$app/environment';
import { journals_func } from '$lib/ae_journals/ae_journals_functions';
export async function load({ fetch, parent }) {
let log_lvl: number = 0;
const log_lvl: number = 0;
let parent_data = await parent();
const parent_data = await parent();
let account_id = parent_data.account_id;
const account_id = parent_data.account_id;
let ae_acct = parent_data[account_id];
const ae_acct = parent_data[account_id];
let journal_id = ae_acct.slct.journal_id; // From root +layout.ts
if (!journal_id) {
if (log_lvl) {
console.log(`INFO: journals +layout.ts: The journal_id was not found in the parent_data.`);
}
// return false;
}
const journal_id = ae_acct.slct.journal_id; // From root +layout.ts
if (!journal_id) {
if (log_lvl) {
console.log(`INFO: journals +layout.ts: The journal_id was not found in the parent_data.`);
}
// return false;
}
if (browser) {
if (journal_id) {
// let ae_params = {};
if (browser) {
if (journal_id) {
// let ae_params = {};
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
});
ae_acct.slct.journal_obj_li = load_journal_obj_li;
}
const 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
});
ae_acct.slct.journal_obj_li = load_journal_obj_li;
}
// console.log(`ae_acct = `, ae_acct);
// WARNING: This does not currently work because the person_id has not been set yet.
let person_id = ae_acct.loc.person_id;
// console.log(`person_id = `, person_id);
// console.log(`ae_acct = `, ae_acct);
// WARNING: This does not currently work because the person_id has not been set yet.
const person_id = ae_acct.loc.person_id;
// console.log(`person_id = `, person_id);
let load_journal_obj_li = await journals_func.load_ae_obj_li__journal({
api_cfg: ae_acct.api,
for_obj_type: 'account',
for_obj_id: account_id,
qry_person_id: person_id,
inc_entry_li: true,
hidden: 'all', // 'not_hidden'
enabled: 'enabled',
// order_by_li: {'priority': 'DESC', 'sort': 'DESC', 'name': 'ASC', 'updated_on': 'DESC', 'created_on': 'DESC'},
limit: 25,
// params: ae_params,
try_cache: true,
log_lvl: log_lvl
});
ae_acct.slct.journal_obj_li = load_journal_obj_li;
const load_journal_obj_li = await journals_func.load_ae_obj_li__journal({
api_cfg: ae_acct.api,
for_obj_type: 'account',
for_obj_id: account_id,
qry_person_id: person_id,
inc_entry_li: true,
hidden: 'all', // 'not_hidden'
enabled: 'enabled',
// order_by_li: {'priority': 'DESC', 'sort': 'DESC', 'name': 'ASC', 'updated_on': 'DESC', 'created_on': 'DESC'},
limit: 25,
// params: ae_params,
try_cache: true,
log_lvl: log_lvl
});
ae_acct.slct.journal_obj_li = load_journal_obj_li;
}
}
parent_data[account_id] = ae_acct;
parent_data[account_id] = ae_acct;
return parent_data;
return parent_data;
}

View File

@@ -1,149 +1,169 @@
<script lang="ts">
/** @type {import('./$types').LayoutProps} */
let log_lvl: number = $state(0);
/** @type {import('./$types').LayoutProps} */
let log_lvl: number = $state(0);
let { data, children } = $props();
let { data, children } = $props();
// *** Import Svelte specific
import { goto } from '$app/navigation';
// *** Import Svelte specific
import { goto } from '$app/navigation';
// *** Import other supporting libraries
import {
FilePlus,
Notebook,
SquareLibrary,
X
} from '@lucide/svelte';
// *** Import other supporting libraries
import { FilePlus, Notebook, SquareLibrary, X } from '@lucide/svelte';
import { liveQuery } from "dexie";
import { liveQuery } from 'dexie';
import { db_journals } from "$lib/ae_journals/db_journals";
import { ae_loc, ae_api, slct } from '$lib/stores/ae_stores';
import { journals_loc, journals_sess, journals_slct } from '$lib/ae_journals/ae_journals_stores';
import { journals_func } from '$lib/ae_journals/ae_journals_functions';
import { db_journals } from '$lib/ae_journals/db_journals';
import { ae_loc, ae_api, slct } from '$lib/stores/ae_stores';
import { journals_loc, journals_sess, journals_slct } from '$lib/ae_journals/ae_journals_stores';
import { journals_func } from '$lib/ae_journals/ae_journals_functions';
import Journal_entry_obj_qry from './../ae_comp__journal_entry_obj_qry.svelte';
import Journal_entry_obj_qry from './../ae_comp__journal_entry_obj_qry.svelte';
let ae_acct = data[$slct.account_id];
$effect(() => {
if (log_lvl) {
console.log(`ae_acct = `, ae_acct);
}
});
let ae_acct = data[$slct.account_id];
$effect(() => {
if (log_lvl) {
console.log(`ae_acct = `, ae_acct);
}
});
let show_menu__all_journals: boolean = $state(false);
let show_menu__all_journals: boolean = $state(false);
let lq__journal_obj = $derived(liveQuery(async () => {
let results = await db_journals.journal
.get($journals_slct?.journal_id ?? ''); // null or undefined does not reset things like '' does
let lq__journal_obj = $derived(
liveQuery(async () => {
let results = await db_journals.journal.get($journals_slct?.journal_id ?? ''); // null or undefined does not reset things like '' does
// Check if results are different than the current session version stored under $journals_slct
if ($journals_slct.journal_obj && results) {
if (JSON.stringify($journals_slct.journal_obj) !== JSON.stringify(results)) {
$journals_slct.journal_obj = { ...results };
}
}
// Check if results are different than the current session version stored under $journals_slct
if ($journals_slct.journal_obj && results) {
if (JSON.stringify($journals_slct.journal_obj) !== JSON.stringify(results)) {
$journals_slct.journal_obj = { ...results };
}
}
return results;
}));
return results;
})
);
$effect(() => {
if (log_lvl) {
console.log(`lq__journal_obj: journal_id = ${$journals_slct?.journal_id}`);
console.log(`lq__journal_obj: results = `, lq__journal_obj);
if ($journals_slct.journal_obj && lq__journal_obj) {
if (JSON.stringify($journals_slct.journal_obj) !== JSON.stringify(lq__journal_obj)) {
console.log(`Session slct stored version has changed for ID = ${$journals_slct.journal_id}`, $journals_slct.journal_obj);
} else {
console.log(`Session slct stored version has not changed for ID = ${$journals_slct.journal_id}`);
}
}
}
});
$effect(() => {
if (log_lvl) {
console.log(`lq__journal_obj: journal_id = ${$journals_slct?.journal_id}`);
console.log(`lq__journal_obj: results = `, lq__journal_obj);
if ($journals_slct.journal_obj && lq__journal_obj) {
if (JSON.stringify($journals_slct.journal_obj) !== JSON.stringify(lq__journal_obj)) {
console.log(
`Session slct stored version has changed for ID = ${$journals_slct.journal_id}`,
$journals_slct.journal_obj
);
} else {
console.log(
`Session slct stored version has not changed for ID = ${$journals_slct.journal_id}`
);
}
}
}
});
let lq__journal_entry_obj_li = $derived(liveQuery(async () => {
let results;
let lq__journal_entry_obj_li = $derived(
liveQuery(async () => {
let results;
if ($journals_sess?.entry_li && $journals_sess?.entry_li?.length) {
// $journals_sess.entry_li_trigger = false;
let journal_entry_id_random_li = []; // This is to prevent the array from constantly updating and triggering the liveQuery.
if ($journals_sess?.entry_li && $journals_sess?.entry_li?.length) {
// $journals_sess.entry_li_trigger = false;
let journal_entry_id_random_li = []; // This is to prevent the array from constantly updating and triggering the liveQuery.
for (let i = 0; i < $journals_sess?.entry_li.length; i++) {
let journal_entry_obj = $journals_sess?.entry_li[i];
let journal_entry_id_random = journal_entry_obj.journal_entry_id_random;
journal_entry_id_random_li.push(journal_entry_id_random);
}
// let journal_entry_id_random_li = tmp_li;
for (let i = 0; i < $journals_sess?.entry_li.length; i++) {
let journal_entry_obj = $journals_sess?.entry_li[i];
let journal_entry_id_random = journal_entry_obj.journal_entry_id_random;
journal_entry_id_random_li.push(journal_entry_id_random);
}
// let journal_entry_id_random_li = tmp_li;
results = await db_journals.journal_entry
.bulkGet(journal_entry_id_random_li);
results = await db_journals.journal_entry.bulkGet(journal_entry_id_random_li);
} else if ($lq__journal_obj?.cfg_json?.entry_group_sort === 'DESC') {
results = await db_journals.journal_entry
// .orderBy('updated_on')
.where('journal_id')
.equals($journals_slct?.journal_id ?? '') // null or undefined does not reset things like '' does
.reverse()
// .sortBy('tmp_sort_2');
.sortBy('updated_on');
// .sortBy('title');
} else if (
$journals_loc.filter__category_code &&
$journals_loc.filter__category_code.length > 0
) {
results = await db_journals.journal_entry
.where('journal_id')
.equals($journals_slct?.journal_id ?? '') // null or undefined does not reset things like '' does
.and((entry) => entry.category_code === $journals_loc.filter__category_code)
.reverse()
.sortBy('tmp_sort_1');
} else {
results = await db_journals.journal_entry
.where('journal_id')
.equals($journals_slct?.journal_id ?? '') // null or undefined does not reset things like '' does
.reverse()
.sortBy('tmp_sort_1');
// .sortBy('updated_on');
}
} else if ($lq__journal_obj?.cfg_json?.entry_group_sort === 'DESC') {
results = await db_journals.journal_entry
// .orderBy('updated_on')
.where('journal_id')
.equals($journals_slct?.journal_id ?? '') // null or undefined does not reset things like '' does
.reverse()
// .sortBy('tmp_sort_2');
.sortBy('updated_on');
// .sortBy('title');
// Check if results are different than the current session version stored under $journals_slct
if (
$journals_slct.journal_entry_obj_li &&
JSON.stringify($journals_slct.journal_entry_obj_li) !== JSON.stringify(results)
) {
$journals_slct.journal_entry_obj_li = [...results];
}
} else if ($journals_loc.filter__category_code && $journals_loc.filter__category_code.length > 0) {
results = await db_journals.journal_entry
.where('journal_id')
.equals($journals_slct?.journal_id ?? '') // null or undefined does not reset things like '' does
.and(entry => entry.category_code === $journals_loc.filter__category_code)
.reverse()
.sortBy('tmp_sort_1');
} else {
results = await db_journals.journal_entry
.where('journal_id')
.equals($journals_slct?.journal_id ?? '') // null or undefined does not reset things like '' does
.reverse()
.sortBy('tmp_sort_1');
// .sortBy('updated_on');
}
// Check if results are different than the current session version stored under $journals_slct
if ($journals_slct.journal_entry_obj_li && JSON.stringify($journals_slct.journal_entry_obj_li) !== JSON.stringify(results)) {
$journals_slct.journal_entry_obj_li = [...results];
}
return results;
}));
$effect(() => {
if (log_lvl) {
console.log(`LQ - $lq__journal_obj.cfg_json = `, $lq__journal_obj?.cfg_json);
console.log(`LQ - $journals_loc.filter__category_code = `, $journals_loc.filter__category_code);
if ($journals_sess?.entry_li && $journals_sess?.entry_li?.length) {
console.log(`LQ - Using $journals_sess.entry_li to get journal entries.`);
} else if ($lq__journal_obj?.cfg_json?.entry_group_sort === 'DESC') {
console.log(`LQ - Using DESC sort for Journal Entry list journal_id: ${$journals_slct?.journal_id}`);
} else if ($journals_loc.filter__category_code && $journals_loc.filter__category_code.length > 0) {
console.log(`LQ - Using category filter: ${$journals_loc.filter__category_code}`);
} else {
console.log(`LQ - Using default sort for Journal Entry list journal_id: ${$journals_slct?.journal_id}`);
}
if ($journals_slct.journal_entry_obj_li && JSON.stringify($journals_slct.journal_entry_obj_li) !== JSON.stringify(lq__journal_entry_obj_li)) {
console.log(`Session slct li stored version has changed for ID = ${$journals_slct.journal_id}`, $journals_slct.journal_entry_obj_li);
} else {
if (log_lvl > 1) {
console.log(`Session slct li stored version has not changed for ID = ${$journals_slct.journal_id}`);
}
}
}
});
return results;
})
);
$effect(() => {
if (log_lvl) {
console.log(`LQ - $lq__journal_obj.cfg_json = `, $lq__journal_obj?.cfg_json);
console.log(
`LQ - $journals_loc.filter__category_code = `,
$journals_loc.filter__category_code
);
if ($journals_sess?.entry_li && $journals_sess?.entry_li?.length) {
console.log(`LQ - Using $journals_sess.entry_li to get journal entries.`);
} else if ($lq__journal_obj?.cfg_json?.entry_group_sort === 'DESC') {
console.log(
`LQ - Using DESC sort for Journal Entry list journal_id: ${$journals_slct?.journal_id}`
);
} else if (
$journals_loc.filter__category_code &&
$journals_loc.filter__category_code.length > 0
) {
console.log(`LQ - Using category filter: ${$journals_loc.filter__category_code}`);
} else {
console.log(
`LQ - Using default sort for Journal Entry list journal_id: ${$journals_slct?.journal_id}`
);
}
if (
$journals_slct.journal_entry_obj_li &&
JSON.stringify($journals_slct.journal_entry_obj_li) !==
JSON.stringify(lq__journal_entry_obj_li)
) {
console.log(
`Session slct li stored version has changed for ID = ${$journals_slct.journal_id}`,
$journals_slct.journal_entry_obj_li
);
} else {
if (log_lvl > 1) {
console.log(
`Session slct li stored version has not changed for ID = ${$journals_slct.journal_id}`
);
}
}
}
});
</script>
<!-- Svelte layout for a Journal ID page and children -->
<section
class="
class="
ae_journals__journal
mx-auto
flex flex-col grow gap-1
@@ -154,12 +174,9 @@ $effect(() => {
max-w-max
space-y-2
"
>
<div
class="
>
<div
class="
flex flex-row flex-wrap
gap-1
items-center justify-between
@@ -171,29 +188,25 @@ $effect(() => {
relative transition-all
"
>
<!-- If middle click then open the all journals page in a new tab. Otherwise show/hide the menu. -->
<button
type="button"
onmousedown={
(event) => {
if (event.button === 1) {
// Middle click - open in new tab
// window.open('/journals', '_blank');
window.open('/journals');
// } else {
// // Left click - toggle menu
// event.preventDefault(); // Prevent default middle-click behavior
// show_menu__all_journals = !show_menu__all_journals;
}
}
}
onclick={() => {
show_menu__all_journals = !show_menu__all_journals;
}}
class="
>
<!-- If middle click then open the all journals page in a new tab. Otherwise show/hide the menu. -->
<button
type="button"
onmousedown={(event) => {
if (event.button === 1) {
// Middle click - open in new tab
// window.open('/journals', '_blank');
window.open('/journals');
// } else {
// // Left click - toggle menu
// event.preventDefault(); // Prevent default middle-click behavior
// show_menu__all_journals = !show_menu__all_journals;
}
}}
onclick={() => {
show_menu__all_journals = !show_menu__all_journals;
}}
class="
btn btn-sm
preset-tonal-tertiary
preset-outlined-tertiary-600-400
@@ -201,25 +214,23 @@ $effect(() => {
hover:preset-filled-tertiary-300-700
transition-all
"
title={`View all journals menu: "${$ae_loc?.user?.name}"\nMiddle-click to open in new tab`}
>
<!-- <BookHeart /> -->
<!-- <Library /> -->
{#if show_menu__all_journals}
<X class="text-orange-500"/>
{:else}
<SquareLibrary class="text-gray-500"/>
{/if}
<span class="hidden md:inline">
Journals
<!-- for {$ae_loc?.user?.name} -->
</span>
title={`View all journals menu: "${$ae_loc?.user?.name}"\nMiddle-click to open in new tab`}
>
<!-- <BookHeart /> -->
<!-- <Library /> -->
{#if show_menu__all_journals}
<X class="text-orange-500" />
{:else}
<SquareLibrary class="text-gray-500" />
{/if}
<span class="hidden md:inline">
Journals
<!-- for {$ae_loc?.user?.name} -->
</span>
</button>
</button>
<div
class="
<div
class="
absolute top-12 left-0
p-4 z-50 w-80
space-y-0.5
@@ -229,10 +240,11 @@ $effect(() => {
min-w-72
max-w-fit
"
class:hidden={!show_menu__all_journals}
>
<a href="/journals"
class="
class:hidden={!show_menu__all_journals}
>
<a
href="/journals"
class="
btn btn-sm
preset-tonal-tertiary
preset-outlined-tertiary-600-400
@@ -240,54 +252,52 @@ $effect(() => {
hover:preset-filled-tertiary-300-700
transition-all
"
title="View all journals for this account: {$ae_loc.account_name}"
>
<!-- <BookHeart /> -->
<!-- <Library /> -->
<SquareLibrary class="text-blue-500"/>
<span class="">
All Journals
</span>
title="View all journals for this account: {$ae_loc.account_name}"
>
<!-- <BookHeart /> -->
<!-- <Library /> -->
<SquareLibrary class="text-blue-500" />
<span class=""> All Journals </span>
</a>
</a>
<!-- $journals_slct?.journal_id && -->
<!-- List of recent entries here... -->
<!-- $journals_loc.entry_view_history_li -->
{#if $journals_loc.entry_view_history_kv && Object.keys($journals_loc.entry_view_history_kv).length > 0}
<select
bind:value={$journals_slct.journal_entry_id}
onchange={() => {
if ($journals_slct.journal_entry_id) {
goto(`/journals/${$journals_slct?.journal_id}/entry/${$journals_slct.journal_entry_id}`);
}
}}
class="
<!-- $journals_slct?.journal_id && -->
<!-- List of recent entries here... -->
<!-- $journals_loc.entry_view_history_li -->
{#if $journals_loc.entry_view_history_kv && Object.keys($journals_loc.entry_view_history_kv).length > 0}
<select
bind:value={$journals_slct.journal_entry_id}
onchange={() => {
if ($journals_slct.journal_entry_id) {
goto(
`/journals/${$journals_slct?.journal_id}/entry/${$journals_slct.journal_entry_id}`
);
}
}}
class="
form-select
w-full
text-sm
border border-neutral-400-600
p-1
"
>
<option value="" disabled selected>
{Object.keys($journals_loc.entry_view_history_kv).length}&times; Recent Entries...
</option>
<!-- loop through each key value -->
{#each Object.entries($journals_loc.entry_view_history_kv).reverse() as [journal_entry_id, journal_entry_obj]}
<option value={journal_entry_obj.id}>
{(journal_entry_obj?.name || journal_entry_obj?.id) ?? 'NONE'}
</option>
{/each}
</select>
{/if}
>
<option value="" disabled selected>
{Object.keys($journals_loc.entry_view_history_kv).length}&times; Recent Entries...
</option>
<!-- loop through each key value -->
{#each Object.entries($journals_loc.entry_view_history_kv).reverse() as [journal_entry_id, journal_entry_obj]}
<option value={journal_entry_obj.id}>
{(journal_entry_obj?.name || journal_entry_obj?.id) ?? 'NONE'}
</option>
{/each}
</select>
{/if}
</div>
</div>
{#if $journals_slct?.journal_entry_id}
<a
href="/journals/{$journals_slct?.journal_id}"
class="
{#if $journals_slct?.journal_entry_id}
<a
href="/journals/{$journals_slct?.journal_id}"
class="
btn btn-sm
preset-tonal-tertiary
preset-outlined-tertiary-600-400
@@ -295,21 +305,21 @@ $effect(() => {
hover:preset-filled-tertiary-300-700
transition-all
"
title="View all journal entries for this journal: {$lq__journal_obj?.name}"
>
<Notebook />
<!-- <Bookmark /> -->
<!-- <BookHeart class="m-1" /> -->
<!-- <BookImage class="m-1" /> -->
<!-- <BookOpenText class="m-1" /> -->
<span class="hidden lg:inline">Back:</span>
<span class="font-bold">
{$lq__journal_obj?.name || 'Journal'}
</span>
</a>
{:else}
<!-- Edit Journal button. Creates a modal to edit the journal. -->
<!-- <button
title="View all journal entries for this journal: {$lq__journal_obj?.name}"
>
<Notebook />
<!-- <Bookmark /> -->
<!-- <BookHeart class="m-1" /> -->
<!-- <BookImage class="m-1" /> -->
<!-- <BookOpenText class="m-1" /> -->
<span class="hidden lg:inline">Back:</span>
<span class="font-bold">
{$lq__journal_obj?.name || 'Journal'}
</span>
</a>
{:else}
<!-- Edit Journal button. Creates a modal to edit the journal. -->
<!-- <button
type="button"
onclick={() => {
tmp_journal_obj = {
@@ -337,60 +347,63 @@ $effect(() => {
Edit Journal
</span>
</button> -->
<Journal_entry_obj_qry
log_lvl={log_lvl}
lq__journal_obj={lq__journal_obj}
/>
{/if}
<Journal_entry_obj_qry {log_lvl} {lq__journal_obj} />
{/if}
<!-- Add default journal entry -->
<span class="flex flex-row flex-wrap items-center justify-center gap-2">
<!-- <span class="text-sm text-gray-500 hidden md:inline">
<!-- Add default journal entry -->
<span class="flex flex-row flex-wrap items-center justify-center gap-2">
<!-- <span class="text-sm text-gray-500 hidden md:inline">
New entry:
</span> -->
<button
type="button"
onclick={() => {
// $journals_sess.show__modal_new__journal_entry_obj = true;
<button
type="button"
onclick={() => {
// $journals_sess.show__modal_new__journal_entry_obj = true;
let data_kv = {
category_code: null,
};
if ($journals_loc.qry__category_code) {
data_kv.category_code = $journals_loc.qry__category_code;
}
$effect(() => {
if (log_lvl) {
console.log('Creating new journal entry with data_kv:', data_kv);
}
});
journals_func.create_ae_obj__journal_entry({
api_cfg: $ae_api,
journal_id: $lq__journal_obj.journal_id,
data_kv: data_kv,
log_lvl: log_lvl
}).then((results) => {
$effect(() => {
if (log_lvl) {
console.log('New journal entry created:', results);
}
});
$journals_slct.journal_entry_id = results?.journal_entry_id_random;
// $journals_loc.entry.edit = true;
$journals_loc.entry.edit_kv[$journals_slct.journal_entry_id] = 'current';
// alert(`Journal entry created successfully! ${$journals_slct.journal_entry_id}`);
}).catch((error) => {
console.error('Error updating journal entry:', error);
alert('Failed to update journal entry.');
}).finally(() => {
if ($journals_slct.journal_entry_id) {
goto(`/journals/${$lq__journal_obj?.journal_id}/entry/${$journals_slct.journal_entry_id}`);
} else {
alert('Failed to create new journal entry.');
}
});
}}
class="
let data_kv = {
category_code: null
};
if ($journals_loc.qry__category_code) {
data_kv.category_code = $journals_loc.qry__category_code;
}
$effect(() => {
if (log_lvl) {
console.log('Creating new journal entry with data_kv:', data_kv);
}
});
journals_func
.create_ae_obj__journal_entry({
api_cfg: $ae_api,
journal_id: $lq__journal_obj.journal_id,
data_kv: data_kv,
log_lvl: log_lvl
})
.then((results) => {
$effect(() => {
if (log_lvl) {
console.log('New journal entry created:', results);
}
});
$journals_slct.journal_entry_id = results?.journal_entry_id_random;
// $journals_loc.entry.edit = true;
$journals_loc.entry.edit_kv[$journals_slct.journal_entry_id] = 'current';
// alert(`Journal entry created successfully! ${$journals_slct.journal_entry_id}`);
})
.catch((error) => {
console.error('Error updating journal entry:', error);
alert('Failed to update journal entry.');
})
.finally(() => {
if ($journals_slct.journal_entry_id) {
goto(
`/journals/${$lq__journal_obj?.journal_id}/entry/${$journals_slct.journal_entry_id}`
);
} else {
alert('Failed to create new journal entry.');
}
});
}}
class="
btn btn-sm
preset-tonal-tertiary
preset-outlined-tertiary-600-400
@@ -398,31 +411,20 @@ $effect(() => {
hover:preset-filled-tertiary-300-700
transition-all
"
title="Create a new journal entry for this journal: {$lq__journal_obj?.name}"
>
<FilePlus />
<!-- <span class="fas fa-plus m-1"></span> -->
<span class="hidden sm:inline">
New Entry
</span>
</button>
</span>
</div>
<!-- <div class="overflow-auto"> -->
{@render children?.()}
<!-- </div> -->
title="Create a new journal entry for this journal: {$lq__journal_obj?.name}"
>
<FilePlus />
<!-- <span class="fas fa-plus m-1"></span> -->
<span class="hidden sm:inline"> New Entry </span>
</button>
</span>
</div>
<!-- <div class="overflow-auto"> -->
{@render children?.()}
<!-- </div> -->
</section>
<!-- {#if $journals_sess.show__modal_edit__journal_obj}
<Journal_obj_id_edit
log_lvl={log_lvl}
@@ -430,4 +432,3 @@ $effect(() => {
show={$journals_sess.show__modal_edit__journal_obj}
/>
{/if} -->

View File

@@ -8,78 +8,80 @@ import { journals_func } from '$lib/ae_journals/ae_journals_functions';
// import { load_ae_obj_id } from '$lib/ae_core/core__crud_generic';
export async function load({ params, parent }) {
let log_lvl: number = 0;
const log_lvl: number = 0;
let data = await parent();
data.log_lvl = log_lvl;
const data = await parent();
data.log_lvl = log_lvl;
let account_id = data.account_id;
let ae_acct = data[account_id];
const account_id = data.account_id;
const ae_acct = data[account_id];
let journal_id = params.journal_id;
if (!journal_id) {
console.log(`ae_journals journals [journal_id] +page.ts: The journal_id was not found in the params!!!`);
error(404, {
message: 'Journals - Journal ID not found'
});
}
ae_acct.slct.journal_id = journal_id;
if (log_lvl) {
console.log(`ae_journals journals [journal_id] +page.ts: journal_id = `, journal_id);
}
const journal_id = params.journal_id;
if (!journal_id) {
console.log(
`ae_journals journals [journal_id] +page.ts: The journal_id was not found in the params!!!`
);
error(404, {
message: 'Journals - Journal ID not found'
});
}
ae_acct.slct.journal_id = journal_id;
if (log_lvl) {
console.log(`ae_journals journals [journal_id] +page.ts: journal_id = `, journal_id);
}
if (browser) {
if (log_lvl) {
console.log(`ae_journals journals [journal_id] +page.ts: journal_id = `, journal_id);
}
// Load journal object
// let load_journal_obj = load_ae_obj_id({
// api_cfg: ae_acct.api,
// obj_type: 'journal',
// obj_id: journal_id,
// db_instance: db_journals,
// db_field_li: journal_field_li,
// inc_obj_type_li: ['journal_entry'],
// log_lvl: 2
// });
if (browser) {
if (log_lvl) {
console.log(`ae_journals journals [journal_id] +page.ts: journal_id = `, journal_id);
}
// Load journal object
// let load_journal_obj = load_ae_obj_id({
// api_cfg: ae_acct.api,
// obj_type: 'journal',
// obj_id: journal_id,
// db_instance: db_journals,
// db_field_li: journal_field_li,
// inc_obj_type_li: ['journal_entry'],
// log_lvl: 2
// });
let load_journal_obj = await journals_func.load_ae_obj_id__journal({
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
});
// .then((results) => {
// if (!results) {
// error(404, {
// message: 'Journals - Journal not found'
// });
// } else {
// // ae_acct.slct.journal_obj = results;
// }
// })
// .catch((err) => {
// console.error(`Error loading journal object:`, err);
// error(500, {
// message: 'Journals - Error loading journal object'
// });
// });
const load_journal_obj = await journals_func.load_ae_obj_id__journal({
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
});
// .then((results) => {
// if (!results) {
// error(404, {
// message: 'Journals - Journal not found'
// });
// } else {
// // ae_acct.slct.journal_obj = results;
// }
// })
// .catch((err) => {
// console.error(`Error loading journal object:`, err);
// error(500, {
// message: 'Journals - Error loading journal object'
// });
// });
if (!load_journal_obj) {
error(404, {
message: 'Journals - Journal Entry not found'
});
} else {
ae_acct.slct.load_journal_obj = load_journal_obj;
}
}
if (!load_journal_obj) {
error(404, {
message: 'Journals - Journal Entry not found'
});
} else {
ae_acct.slct.load_journal_obj = load_journal_obj;
}
}
// WARNING: Precaution against shared data between sites.
data[account_id] = ae_acct;
// WARNING: Precaution against shared data between sites.
data[account_id] = ae_acct;
return data;
return data;
}

View File

@@ -1,272 +1,315 @@
<script lang="ts">
/** @type {import('./$types').PageData} */
let log_lvl: number = $state(1);
/** @type {import('./$types').PageData} */
let log_lvl: number = $state(1);
interface Props {
data: any;
}
interface Props {
data: any;
}
let { data }: Props = $props();
let { data }: Props = $props();
// *** Import Svelte specific
import { browser } from '$app/environment';
// import { goto } from '$app/navigation';
// *** Import Svelte specific
import { browser } from '$app/environment';
// import { goto } from '$app/navigation';
// *** Import other supporting libraries
// import {
// ArrowDown01, ArrowDown10, ArrowDownUp,
// BetweenVerticalEnd, BetweenVerticalStart,
// BookHeart, BookImage, Bookmark, BookOpenText, BriefcaseBusiness,
// Check, Copy,
// Expand, Eye, EyeOff,
// Flag, FlagOff, FilePlus, Fingerprint,
// Globe,
// Library,
// MessageSquareWarning, Minus,
// Notebook,
// Pencil, Plus,
// RemoveFormatting,
// SquareLibrary,
// Shapes, Share2, ShieldCheck, ShieldMinus, Siren, Skull,
// Tags, Target, ToggleLeft, ToggleRight, Trash2, TypeOutline,
// X
// } from '@lucide/svelte';
// import * as icons from '@lucide/svelte';
// import { Modal } from 'flowbite-svelte';
import { liveQuery } from 'dexie';
// *** Import other supporting libraries
// import {
// ArrowDown01, ArrowDown10, ArrowDownUp,
// BetweenVerticalEnd, BetweenVerticalStart,
// BookHeart, BookImage, Bookmark, BookOpenText, BriefcaseBusiness,
// Check, Copy,
// Expand, Eye, EyeOff,
// Flag, FlagOff, FilePlus, Fingerprint,
// Globe,
// Library,
// MessageSquareWarning, Minus,
// Notebook,
// Pencil, Plus,
// RemoveFormatting,
// SquareLibrary,
// Shapes, Share2, ShieldCheck, ShieldMinus, Siren, Skull,
// Tags, Target, ToggleLeft, ToggleRight, Trash2, TypeOutline,
// X
// } from '@lucide/svelte';
// import * as icons from '@lucide/svelte';
// import { Modal } from 'flowbite-svelte';
import { liveQuery } from "dexie";
// *** Import Aether specific variables and functions
// import type { key_val } from '$lib/ae_stores';
import { ae_util } from '$lib/ae_utils/ae_utils';
// import { core_func } from '$lib/ae_core/ae_core_functions';
import {
ae_snip,
ae_loc,
ae_sess,
ae_api,
ae_trig,
slct,
slct_trigger
} from '$lib/stores/ae_stores';
import { db_journals } from '$lib/ae_journals/db_journals';
import {
journals_loc,
journals_sess,
journals_slct,
journals_prom,
journals_trig
} from '$lib/ae_journals/ae_journals_stores';
import { journals_func } from '$lib/ae_journals/ae_journals_functions';
// *** Import Aether specific variables and functions
// import type { key_val } from '$lib/ae_stores';
import { ae_util } from '$lib/ae_utils/ae_utils';
// import { core_func } from '$lib/ae_core/ae_core_functions';
import { ae_snip, ae_loc, ae_sess, ae_api, ae_trig, slct, slct_trigger } from '$lib/stores/ae_stores';
import { db_journals } from "$lib/ae_journals/db_journals";
import { journals_loc, journals_sess, journals_slct, journals_prom, journals_trig } from '$lib/ae_journals/ae_journals_stores';
import { journals_func } from '$lib/ae_journals/ae_journals_functions';
// import Journal_obj_id_edit from './ae_journals_comp__journal_obj_id_edit.svelte';
import Journal_view from './../ae_comp__journal_obj_id_view.svelte';
// import Journal_page_menu from './session_page_menu.svelte';
// import Element_data_store from '$lib/element_data_store_v2.svelte';
// import Journal_obj_id_edit from './ae_journals_comp__journal_obj_id_edit.svelte';
import Journal_view from './../ae_comp__journal_obj_id_view.svelte';
// import Journal_page_menu from './session_page_menu.svelte';
// import Element_data_store from '$lib/element_data_store_v2.svelte';
import Journal_entry_obj_li from './../ae_comp__journal_entry_obj_li.svelte';
// import Journal_entry_obj_qry from './../ae_comp__journal_entry_obj_qry.svelte';
import Journal_obj_id_edit from '../ae_comp__journal_obj_id_edit.svelte';
import Journal_entry_obj_li from './../ae_comp__journal_entry_obj_li.svelte';
// import Journal_entry_obj_qry from './../ae_comp__journal_entry_obj_qry.svelte';
import Journal_obj_id_edit from '../ae_comp__journal_obj_id_edit.svelte';
// let ae_promises: key_val = {};
// let ae_tmp: key_val = {};
// let ae_triggers: key_val = {};
// Variables
// *** Quickly pull out data from parent(s)
let ae_acct = data[$slct.account_id];
$effect(() => {
if (log_lvl > 1) {
console.log(`ae_acct = `, ae_acct);
}
});
// let ae_promises: key_val = {};
// let ae_tmp: key_val = {};
// let ae_triggers: key_val = {};
$inspect(log_lvl, `log_lvl = ${log_lvl}`);
$inspect($journals_slct.journal_id, `$journals_slct.journal_id = ${$journals_slct.journal_id}`);
$inspect(
$journals_slct.journal_entry_id,
`$journals_slct.journal_entry_id = ${$journals_slct.journal_entry_id}`
);
// Variables
// *** Quickly pull out data from parent(s)
let ae_acct = data[$slct.account_id];
$effect(() => {
if (log_lvl > 1) {
console.log(`ae_acct = `, ae_acct);
// $inspect($journals_slct.journal_entry_id).with((type, val) => {
// if (type === 'update') {
// // debugger; // or `console.trace`, or whatever you want
// console.log('$journals_slct.journal_entry_id updated:', val);
// }
// });
}
});
// For some reason data.params.journal_id (or whatever param) is not being passed to this page when loaded by a link from another page. This seems to be a bug with Svelte or SvelteKit. Hopefully fixed in a future version 5? 2024-11-06
// $journals_slct.journal_id = ae_acct.slct.journal_id;
// $journals_slct.journal_obj = ae_acct.slct.journal_obj;
$inspect(log_lvl, `log_lvl = ${log_lvl}`);
$inspect($journals_slct.journal_id, `$journals_slct.journal_id = ${$journals_slct.journal_id}`);
$inspect($journals_slct.journal_entry_id, `$journals_slct.journal_entry_id = ${$journals_slct.journal_entry_id}`);
$journals_slct.journal_id = ae_acct.slct.journal_id;
// $inspect($journals_slct.journal_entry_id).with((type, val) => {
// if (type === 'update') {
// // debugger; // or `console.trace`, or whatever you want
// console.log('$journals_slct.journal_entry_id updated:', val);
// }
// });
$journals_sess.entry_li = [];
$journals_slct.journal_entry_id = null;
// For some reason data.params.journal_id (or whatever param) is not being passed to this page when loaded by a link from another page. This seems to be a bug with Svelte or SvelteKit. Hopefully fixed in a future version 5? 2024-11-06
// $journals_slct.journal_id = ae_acct.slct.journal_id;
// $journals_slct.journal_obj = ae_acct.slct.journal_obj;
let lq__journal_obj = $derived(
liveQuery(async () => {
let results = await db_journals.journal.get($journals_slct?.journal_id ?? ''); // null or undefined does not reset things like '' does
$journals_slct.journal_id = ae_acct.slct.journal_id;
// Check if results are different than the current session version stored under $journals_slct
if ($journals_slct.journal_obj && results) {
if (JSON.stringify($journals_slct.journal_obj) !== JSON.stringify(results)) {
$journals_slct.journal_obj = { ...results };
}
}
$journals_sess.entry_li = [];
$journals_slct.journal_entry_id = null;
return results;
})
);
let lq__journal_obj = $derived(liveQuery(async () => {
let results = await db_journals.journal
.get($journals_slct?.journal_id ?? ''); // null or undefined does not reset things like '' does
$effect(() => {
if (log_lvl) {
console.log(`lq__journal_obj: journal_id = ${$journals_slct?.journal_id}`);
console.log(`lq__journal_obj: results = `, lq__journal_obj);
if ($journals_slct.journal_obj && lq__journal_obj) {
if (JSON.stringify($journals_slct.journal_obj) !== JSON.stringify(lq__journal_obj)) {
console.log(
`Session slct stored version has changed for ID = ${$journals_slct.journal_id}`,
$journals_slct.journal_obj
);
} else {
console.log(
`Session slct stored version has not changed for ID = ${$journals_slct.journal_id}`
);
}
}
}
});
// Check if results are different than the current session version stored under $journals_slct
if ($journals_slct.journal_obj && results) {
if (JSON.stringify($journals_slct.journal_obj) !== JSON.stringify(results)) {
$journals_slct.journal_obj = { ...results};
}
}
let lq__journal_entry_obj_li = $derived(
liveQuery(async () => {
let results;
return results;
}));
if ($journals_sess.entry_li_trigger && !$journals_sess?.entry_li) {
$journals_sess.entry_li = null;
$journals_sess.entry_li_trigger = false;
}
$effect(() => {
if (log_lvl) {
console.log(`lq__journal_obj: journal_id = ${$journals_slct?.journal_id}`);
console.log(`lq__journal_obj: results = `, lq__journal_obj);
if ($journals_slct.journal_obj && lq__journal_obj) {
if (JSON.stringify($journals_slct.journal_obj) !== JSON.stringify(lq__journal_obj)) {
console.log(`Session slct stored version has changed for ID = ${$journals_slct.journal_id}`, $journals_slct.journal_obj);
} else {
console.log(`Session slct stored version has not changed for ID = ${$journals_slct.journal_id}`);
}
}
}
});
if ($journals_sess?.entry_li && $journals_sess?.entry_li?.length) {
let journal_entry_id_random_li = []; // This is to prevent the array from constantly updating and triggering the liveQuery.
let lq__journal_entry_obj_li = $derived(liveQuery(async () => {
let results;
for (let i = 0; i < $journals_sess?.entry_li.length; i++) {
let journal_entry_obj = $journals_sess?.entry_li[i];
let journal_entry_id_random = journal_entry_obj.journal_entry_id_random;
journal_entry_id_random_li.push(journal_entry_id_random);
}
// let journal_entry_id_random_li = tmp_li;
if ($journals_sess.entry_li_trigger && !$journals_sess?.entry_li) {
$journals_sess.entry_li = null;
$journals_sess.entry_li_trigger = false;
}
results = await db_journals.journal_entry.bulkGet(journal_entry_id_random_li);
} else if ($lq__journal_obj?.cfg_json?.entry_group_sort === 'DESC') {
results = await db_journals.journal_entry
// .orderBy('updated_on')
.where('journal_id')
.equals($journals_slct?.journal_id ?? '') // null or undefined does not reset things like '' does
.reverse()
// .sortBy('tmp_sort_2');
.sortBy('updated_on');
// .sortBy('title');
} else if (
$journals_loc.filter__category_code &&
$journals_loc.filter__category_code.length > 0
) {
results = await db_journals.journal_entry
.where('journal_id')
.equals($journals_slct?.journal_id ?? '') // null or undefined does not reset things like '' does
.and((entry) => entry.category_code === $journals_loc.filter__category_code)
.reverse()
.sortBy('tmp_sort_1');
} else {
results = await db_journals.journal_entry
.where('journal_id')
.equals($journals_slct?.journal_id ?? '') // null or undefined does not reset things like '' does
.reverse()
.sortBy('tmp_sort_1');
// .sortBy('updated_on');
}
if ($journals_sess?.entry_li && $journals_sess?.entry_li?.length) {
let journal_entry_id_random_li = []; // This is to prevent the array from constantly updating and triggering the liveQuery.
// Check if results are different than the current session version stored under $journals_slct
if (
$journals_slct.journal_entry_obj_li &&
JSON.stringify($journals_slct.journal_entry_obj_li) !== JSON.stringify(results)
) {
$journals_slct.journal_entry_obj_li = [...results];
}
for (let i = 0; i < $journals_sess?.entry_li.length; i++) {
let journal_entry_obj = $journals_sess?.entry_li[i];
let journal_entry_id_random = journal_entry_obj.journal_entry_id_random;
journal_entry_id_random_li.push(journal_entry_id_random);
}
// let journal_entry_id_random_li = tmp_li;
return results;
})
);
results = await db_journals.journal_entry
.bulkGet(journal_entry_id_random_li);
$effect(() => {
if (log_lvl) {
console.log(`LQ - $lq__journal_obj.cfg_json = `, $lq__journal_obj?.cfg_json);
console.log(
`LQ - $journals_loc.filter__category_code = `,
$journals_loc.filter__category_code
);
if ($journals_sess?.entry_li && $journals_sess?.entry_li?.length) {
console.log(`LQ - Using $journals_sess.entry_li to get journal entries.`);
} else if ($lq__journal_obj?.cfg_json?.entry_group_sort === 'DESC') {
console.log(
`LQ - Using DESC sort for Journal Entry list journal_id: ${$journals_slct?.journal_id}`
);
} else if (
$journals_loc.filter__category_code &&
$journals_loc.filter__category_code.length > 0
) {
console.log(`LQ - Using category filter: ${$journals_loc.filter__category_code}`);
} else {
console.log(
`LQ - Using default sort for Journal Entry list journal_id: ${$journals_slct?.journal_id}`
);
}
if (
$journals_slct.journal_entry_obj_li &&
JSON.stringify($journals_slct.journal_entry_obj_li) !==
JSON.stringify(lq__journal_entry_obj_li)
) {
console.log(
`Session slct li stored version has changed for ID = ${$journals_slct.journal_id}`,
$journals_slct.journal_entry_obj_li
);
} else {
if (log_lvl > 1) {
console.log(
`Session slct li stored version has not changed for ID = ${$journals_slct.journal_id}`
);
}
}
}
});
} else if ($lq__journal_obj?.cfg_json?.entry_group_sort === 'DESC') {
results = await db_journals.journal_entry
// .orderBy('updated_on')
.where('journal_id')
.equals($journals_slct?.journal_id ?? '') // null or undefined does not reset things like '' does
.reverse()
// .sortBy('tmp_sort_2');
.sortBy('updated_on');
// .sortBy('title');
// Trigger doing a basic load of journal entries
// NOTE: Categories are (currently) filtered at the CSS style level.
$effect(() => {
if ($journals_trig.journal_entry_li) {
$journals_trig.journal_entry_li = false;
} else if ($journals_loc.filter__category_code && $journals_loc.filter__category_code.length > 0) {
results = await db_journals.journal_entry
.where('journal_id')
.equals($journals_slct?.journal_id ?? '') // null or undefined does not reset things like '' does
.and(entry => entry.category_code === $journals_loc.filter__category_code)
.reverse()
.sortBy('tmp_sort_1');
// if ($journals_trig?.journal_entry_li.length > 0) {
// $journals_sess.entry_li = $journals_trig.journal_entry_li;
// console.log('TEST TEST TEST');
// return ;
// }
} else {
results = await db_journals.journal_entry
.where('journal_id')
.equals($journals_slct?.journal_id ?? '') // null or undefined does not reset things like '' does
.reverse()
.sortBy('tmp_sort_1');
// .sortBy('updated_on');
if (log_lvl) {
console.log(`Triggered: $journals_trig.journal_entry_li`);
}
}
if ($journals_loc.qry__enabled !== 'all' || $journals_loc.qry__hidden !== 'all') {
if (log_lvl) {
console.log(
`Not set to all for enabled or hidden. Clearing all journal entries to be safe.`
);
console.log(`$journals_loc.qry__enabled = ${$journals_loc.qry__enabled}`);
console.log(`$journals_loc.qry__hidden = ${$journals_loc.qry__hidden}`);
}
let results = db_journals.journal_entry.clear();
if (log_lvl) {
console.log(`Cleared all journal entries in the database.`, results);
}
}
// Check if results are different than the current session version stored under $journals_slct
if ($journals_slct.journal_entry_obj_li && JSON.stringify($journals_slct.journal_entry_obj_li) !== JSON.stringify(results)) {
$journals_slct.journal_entry_obj_li = [...results];
}
$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_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
});
return results;
}));
$effect(() => {
if (log_lvl) {
console.log(`LQ - $lq__journal_obj.cfg_json = `, $lq__journal_obj?.cfg_json);
console.log(`LQ - $journals_loc.filter__category_code = `, $journals_loc.filter__category_code);
if ($journals_sess?.entry_li && $journals_sess?.entry_li?.length) {
console.log(`LQ - Using $journals_sess.entry_li to get journal entries.`);
} else if ($lq__journal_obj?.cfg_json?.entry_group_sort === 'DESC') {
console.log(`LQ - Using DESC sort for Journal Entry list journal_id: ${$journals_slct?.journal_id}`);
} else if ($journals_loc.filter__category_code && $journals_loc.filter__category_code.length > 0) {
console.log(`LQ - Using category filter: ${$journals_loc.filter__category_code}`);
} else {
console.log(`LQ - Using default sort for Journal Entry list journal_id: ${$journals_slct?.journal_id}`);
}
if ($journals_slct.journal_entry_obj_li && JSON.stringify($journals_slct.journal_entry_obj_li) !== JSON.stringify(lq__journal_entry_obj_li)) {
console.log(`Session slct li stored version has changed for ID = ${$journals_slct.journal_id}`, $journals_slct.journal_entry_obj_li);
} else {
if (log_lvl > 1) {
console.log(`Session slct li stored version has not changed for ID = ${$journals_slct.journal_id}`);
}
}
}
});
// Trigger doing a basic load of journal entries
// NOTE: Categories are (currently) filtered at the CSS style level.
$effect(() => {
if ($journals_trig.journal_entry_li) {
$journals_trig.journal_entry_li = false;
// if ($journals_trig?.journal_entry_li.length > 0) {
// $journals_sess.entry_li = $journals_trig.journal_entry_li;
// console.log('TEST TEST TEST');
// return ;
// }
if (log_lvl) {
console.log(`Triggered: $journals_trig.journal_entry_li`);
}
if ($journals_loc.qry__enabled !== 'all' || $journals_loc.qry__hidden !== 'all') {
if (log_lvl) {
console.log(`Not set to all for enabled or hidden. Clearing all journal entries to be safe.`);
console.log(`$journals_loc.qry__enabled = ${$journals_loc.qry__enabled}`);
console.log(`$journals_loc.qry__hidden = ${$journals_loc.qry__hidden}`);
}
let results = db_journals.journal_entry.clear();
if (log_lvl) {
console.log(`Cleared all journal entries in the database.`, results);
}
}
$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_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,
});
// Should we reset the entry list???
// $journals_sess.entry_li = null;
}
});
if (browser) {
let message = {'journal_id': $journals_slct?.journal_id ?? null};
window.parent.postMessage(message, "*");
}
// Should we reset the entry list???
// $journals_sess.entry_li = null;
}
});
if (browser) {
let message = { journal_id: $journals_slct?.journal_id ?? null };
window.parent.postMessage(message, '*');
}
</script>
<svelte:head>
<title>
Æ Journals:
{$lq__journal_obj?.name ? ae_util.shorten_string({ string: $lq__journal_obj?.name, max_length: 20, begin_length: 10, end_length: 4 }) : ''}
- {$ae_loc?.title}
</title>
Æ Journals:
{$lq__journal_obj?.name
? ae_util.shorten_string({
string: $lq__journal_obj?.name,
max_length: 20,
begin_length: 10,
end_length: 4
})
: ''}
- {$ae_loc?.title}
</title>
</svelte:head>
{#if $ae_loc.person_id == $lq__journal_obj?.person_id}
<!-- Svelte Page for a Journal ID page -->
<!-- <section
<!-- Svelte Page for a Journal ID page -->
<!-- <section
class="
ae_journals__journal
container h-full mx-auto
@@ -278,44 +321,27 @@ if (browser) {
"
> -->
<Journal_view {lq__journal_obj} {lq__journal_entry_obj_li} />
{#if $lq__journal_entry_obj_li && $lq__journal_entry_obj_li?.length}
<Journal_entry_obj_li {lq__journal_obj} {lq__journal_entry_obj_li} />
{:else}
<section class="main_content grow px-1 md:px-2 pb-28 flex flex-col gap-1 items-center">
<p>No journal entry available to show.</p>
</section>
{/if}
<!-- </section> -->
<Journal_view
lq__journal_obj={lq__journal_obj}
lq__journal_entry_obj_li={lq__journal_entry_obj_li}
/>
{#if $lq__journal_entry_obj_li && $lq__journal_entry_obj_li?.length }
<Journal_entry_obj_li
lq__journal_obj={lq__journal_obj}
lq__journal_entry_obj_li={lq__journal_entry_obj_li}
/>
<!-- Modal: Journal edit ID -->
<!-- tmp__journal_obj={$journals_slct.journal_obj} -->
<Journal_obj_id_edit
{log_lvl}
{lq__journal_obj}
show={$journals_sess.show__modal_edit__journal_obj}
/>
{:else}
<section class="main_content grow px-1 md:px-2 pb-28 flex flex-col gap-1 items-center">
<p>No journal entry available to show.</p>
</section>
<section class="main_content grow px-1 md:px-2 pb-28 flex flex-col gap-1 items-center">
<p class="text-center">You must be logged in as the owner to view this Journal.</p>
</section>
{/if}
<!-- </section> -->
<!-- Modal: Journal edit ID -->
<!-- tmp__journal_obj={$journals_slct.journal_obj} -->
<Journal_obj_id_edit
log_lvl={log_lvl}
lq__journal_obj={lq__journal_obj}
show={$journals_sess.show__modal_edit__journal_obj}
/>
{:else}
<section class="main_content grow px-1 md:px-2 pb-28 flex flex-col gap-1 items-center">
<p class="text-center">
You must be logged in as the owner to view this Journal.
</p>
</section>
{/if}

View File

@@ -5,80 +5,70 @@ console.log(`ae_p_journals [journal_id] +page.ts start`);
import { browser } from '$app/environment';
import { journals_func } from '$lib/ae_journals/ae_journals_functions';
export async function load({ params, parent }) { // route
// let log_lvl: number = 1;
// let data = await parent();
// data.log_lvl = log_lvl;
// let account_id = data.account_id;
// let ae_acct = data[account_id];
// let journal_id = params.journal_id;
// if (!journal_id) {
// console.log(`ae_journals journals [journal_id] +page.ts: The journal_id was not found in the params!!!`);
// error(404, {
export async function load({ params, parent }) {
// route
// let log_lvl: number = 1;
// let data = await parent();
// data.log_lvl = log_lvl;
// let account_id = data.account_id;
// let ae_acct = data[account_id];
// let journal_id = params.journal_id;
// if (!journal_id) {
// console.log(`ae_journals journals [journal_id] +page.ts: The journal_id was not found in the params!!!`);
// error(404, {
// message: 'Journals - Journal ID not found'
// });
// }
// ae_acct.slct.journal_id = journal_id;
// console.log(`ae_journals journals [journal_id] +page.ts: journal_id = `, ae_acct.slct.journal_id);
// if (browser) {
// if (log_lvl) {
// console.log(`ae_journals journals [journal_id] +page.ts: journal_id = `, journal_id);
// }
// // Load event journal object
// let load_journal_obj = journals_func.load_ae_obj_id__journal({
// api_cfg: ae_acct.api,
// journal_id: journal_id,
// inc_entry_li: true,
// try_cache: true,
// log_lvl: log_lvl
// });
// ae_acct.slct.journal_obj = load_journal_obj;
// Load journal entries for the journal
// let load_journal_entry_obj_li = journals_func.load_ae_obj_li__journal_entry({
// api_cfg: ae_acct.api,
// for_obj_type: 'journal',
// for_obj_id: journal_id,
// params: {qry__enabled: 'all', qry__limit: 99},
// try_cache: true
// })
// .then((journal_entry_obj_li) => {
// if (log_lvl) {
// console.log(`journal_entry_obj_li = `, journal_entry_obj_li);
// }
// for (let index = 0; index < journal_entry_obj_li.length; index++) {
// let journal_entry_obj = journal_entry_obj_li[index];
// let journal_entry_id = journal_entry_obj.journal_entry_id_random;
// let load_journal_entry_obj_li = journals_func.load_ae_obj_li__journal_entry({
// api_cfg: ae_acct.api,
// for_obj_type: 'journal_entry',
// for_obj_id: journal_entry_id,
// params: {qry__enabled: 'all', qry__limit: 15},
// try_cache: true
// });
// if (log_lvl) {
// console.log(`load_journal_entry_obj_li = `, load_journal_entry_obj_li);
// }
// journal_entry_obj_li[index].journal_entry_li = load_journal_entry_obj_li;
// }
// return journal_entry_obj_li;
// });
// if (log_lvl) {
// console.log(`load_journal_entry_obj_li = `, load_journal_entry_obj_li);
// }
// ae_acct.slct.journal_entry_obj_li = load_journal_entry_obj_li;
// }
// WARNING: Precaution against shared data between sites.
// data[account_id] = ae_acct;
// return data;
// }
// ae_acct.slct.journal_id = journal_id;
// console.log(`ae_journals journals [journal_id] +page.ts: journal_id = `, ae_acct.slct.journal_id);
// if (browser) {
// if (log_lvl) {
// console.log(`ae_journals journals [journal_id] +page.ts: journal_id = `, journal_id);
// }
// // Load event journal object
// let load_journal_obj = journals_func.load_ae_obj_id__journal({
// api_cfg: ae_acct.api,
// journal_id: journal_id,
// inc_entry_li: true,
// try_cache: true,
// log_lvl: log_lvl
// });
// ae_acct.slct.journal_obj = load_journal_obj;
// Load journal entries for the journal
// let load_journal_entry_obj_li = journals_func.load_ae_obj_li__journal_entry({
// api_cfg: ae_acct.api,
// for_obj_type: 'journal',
// for_obj_id: journal_id,
// params: {qry__enabled: 'all', qry__limit: 99},
// try_cache: true
// })
// .then((journal_entry_obj_li) => {
// if (log_lvl) {
// console.log(`journal_entry_obj_li = `, journal_entry_obj_li);
// }
// for (let index = 0; index < journal_entry_obj_li.length; index++) {
// let journal_entry_obj = journal_entry_obj_li[index];
// let journal_entry_id = journal_entry_obj.journal_entry_id_random;
// let load_journal_entry_obj_li = journals_func.load_ae_obj_li__journal_entry({
// api_cfg: ae_acct.api,
// for_obj_type: 'journal_entry',
// for_obj_id: journal_entry_id,
// params: {qry__enabled: 'all', qry__limit: 15},
// try_cache: true
// });
// if (log_lvl) {
// console.log(`load_journal_entry_obj_li = `, load_journal_entry_obj_li);
// }
// journal_entry_obj_li[index].journal_entry_li = load_journal_entry_obj_li;
// }
// return journal_entry_obj_li;
// });
// if (log_lvl) {
// console.log(`load_journal_entry_obj_li = `, load_journal_entry_obj_li);
// }
// ae_acct.slct.journal_entry_obj_li = load_journal_entry_obj_li;
// }
// WARNING: Precaution against shared data between sites.
// data[account_id] = ae_acct;
// return data;
}

View File

@@ -1,242 +1,285 @@
<script lang="ts">
/** @type {import('./$types').PageData} */
let log_lvl: number = $state(1);
/** @type {import('./$types').PageData} */
let log_lvl: number = $state(1);
// *** Import Svelte specific
import { browser } from '$app/environment';
// *** Import Svelte specific
import { browser } from '$app/environment';
// *** Import other supporting libraries
// import { Modal } from 'flowbite-svelte';
import { liveQuery } from "dexie";
// *** Import other supporting libraries
// import { Modal } from 'flowbite-svelte';
import { liveQuery } from 'dexie';
// *** Import Aether specific variables and functions
// import type { key_val } from '$lib/ae_stores';
import { ae_util } from '$lib/ae_utils/ae_utils';
// import { core_func } from '$lib/ae_core/ae_core_functions';
import { db_journals } from "$lib/ae_journals/db_journals";
import { ae_snip, ae_loc, ae_sess, ae_api, ae_trig, slct, slct_trigger } from '$lib/stores/ae_stores';
import { journals_loc, journals_sess, journals_slct, journals_prom, journals_trig } from '$lib/ae_journals/ae_journals_stores';
// import { journals_func } from '$lib/ae_journals/ae_journals_functions';
// *** Import Aether specific variables and functions
// import type { key_val } from '$lib/ae_stores';
import { ae_util } from '$lib/ae_utils/ae_utils';
// import { core_func } from '$lib/ae_core/ae_core_functions';
import { db_journals } from '$lib/ae_journals/db_journals';
import {
ae_snip,
ae_loc,
ae_sess,
ae_api,
ae_trig,
slct,
slct_trigger
} from '$lib/stores/ae_stores';
import {
journals_loc,
journals_sess,
journals_slct,
journals_prom,
journals_trig
} from '$lib/ae_journals/ae_journals_stores';
// import { journals_func } from '$lib/ae_journals/ae_journals_functions';
// import Journal_entry_obj_id_edit from './ae_journals_comp__journal_entry_obj_id_edit.svelte';
import Journal_entry_view from './../../../ae_comp__journal_entry_obj_id_view.svelte';
// import Journal_page_menu from './session_page_menu.svelte';
// import Element_data_store from '$lib/element_data_store_v2.svelte';
// import Journal_entry_obj_id_edit from './ae_journals_comp__journal_entry_obj_id_edit.svelte';
import Journal_entry_view from './../../../ae_comp__journal_entry_obj_id_view.svelte';
// import Journal_page_menu from './session_page_menu.svelte';
// import Element_data_store from '$lib/element_data_store_v2.svelte';
interface Props {
data: any;
}
interface Props {
data: any;
}
let { data }: Props = $props();
let { data }: Props = $props();
// let ae_promises: key_val = {};
// let ae_tmp: key_val = {};
// let ae_triggers: key_val = {};
// let ae_promises: key_val = {};
// let ae_tmp: key_val = {};
// let ae_triggers: key_val = {};
// Variables
// *** Quickly pull out data from parent(s)
let ae_acct = data[$slct.account_id];
$effect(() => {
if (log_lvl) {
console.log(`ae_acct = `, ae_acct);
}
});
// Variables
// *** Quickly pull out data from parent(s)
let ae_acct = data[$slct.account_id];
$effect(() => {
if (log_lvl) {
console.log(`ae_acct = `, ae_acct);
}
});
$journals_slct.journal_id = ae_acct.slct.journal_id;
let lq__journal_obj = $derived(liveQuery(async () => {
let results = await db_journals.journal
.get($journals_slct?.journal_id ?? ''); // null or undefined does not reset things like '' does
$journals_slct.journal_id = ae_acct.slct.journal_id;
let lq__journal_obj = $derived(
liveQuery(async () => {
let results = await db_journals.journal.get($journals_slct?.journal_id ?? ''); // null or undefined does not reset things like '' does
// Check if results are different than the current session version stored under $journals_slct
if ($journals_slct.journal_obj && results) {
if (JSON.stringify($journals_slct.journal_obj) !== JSON.stringify(results)) {
$journals_slct.journal_obj = { ...results };
}
}
// Check if results are different than the current session version stored under $journals_slct
if ($journals_slct.journal_obj && results) {
if (JSON.stringify($journals_slct.journal_obj) !== JSON.stringify(results)) {
$journals_slct.journal_obj = { ...results };
}
}
return results;
}));
return results;
})
);
$effect(() => {
if (log_lvl) {
console.log(`lq__journal_obj: journal_id = ${$journals_slct?.journal_id}`);
console.log(`lq__journal_obj: results = `, lq__journal_obj);
if ($journals_slct.journal_obj && lq__journal_obj) {
if (JSON.stringify($journals_slct.journal_obj) !== JSON.stringify(lq__journal_obj)) {
console.log(`Session slct stored version has changed for ID = ${$journals_slct.journal_id}`, $journals_slct.journal_obj);
} else {
console.log(`Session slct stored version has not changed for ID = ${$journals_slct.journal_id}`);
}
}
}
});
$effect(() => {
if (log_lvl) {
console.log(`lq__journal_obj: journal_id = ${$journals_slct?.journal_id}`);
console.log(`lq__journal_obj: results = `, lq__journal_obj);
if ($journals_slct.journal_obj && lq__journal_obj) {
if (JSON.stringify($journals_slct.journal_obj) !== JSON.stringify(lq__journal_obj)) {
console.log(
`Session slct stored version has changed for ID = ${$journals_slct.journal_id}`,
$journals_slct.journal_obj
);
} else {
console.log(
`Session slct stored version has not changed for ID = ${$journals_slct.journal_id}`
);
}
}
}
});
let lq__journal_obj_li = $derived(liveQuery(async () => {
let results = await db_journals.journal
.where('person_id')
.equals($ae_loc.person_id)
.reverse()
.sortBy('tmp_sort_2');
let lq__journal_obj_li = $derived(
liveQuery(async () => {
let results = await db_journals.journal
.where('person_id')
.equals($ae_loc.person_id)
.reverse()
.sortBy('tmp_sort_2');
// Check if results are different than the current session version stored under $journals_slct
if ($journals_slct.journal_obj_li && JSON.stringify($journals_slct.journal_obj_li) !== JSON.stringify(results)) {
$journals_slct.journal_obj_li = [...results];
}
// Check if results are different than the current session version stored under $journals_slct
if (
$journals_slct.journal_obj_li &&
JSON.stringify($journals_slct.journal_obj_li) !== JSON.stringify(results)
) {
$journals_slct.journal_obj_li = [...results];
}
return results;
}));
return results;
})
);
$effect(() => {
if (log_lvl) {
console.log(`lq__journal_obj_li: person_id = ${$ae_loc.person_id}`);
console.log(`lq__journal_obj_li: results = `, lq__journal_obj_li);
if ($journals_slct.journal_obj_li && JSON.stringify($journals_slct.journal_obj_li) !== JSON.stringify(lq__journal_obj_li)) {
console.log(`Session slct li stored version has changed for ID = ${$ae_loc.person_id}`, $journals_slct.journal_obj_li);
} else {
if (log_lvl > 1) {
console.log(`Session slct li stored version has not changed for ID = ${$ae_loc.person_id}`);
}
}
}
});
$effect(() => {
if (log_lvl) {
console.log(`lq__journal_obj_li: person_id = ${$ae_loc.person_id}`);
console.log(`lq__journal_obj_li: results = `, lq__journal_obj_li);
if (
$journals_slct.journal_obj_li &&
JSON.stringify($journals_slct.journal_obj_li) !== JSON.stringify(lq__journal_obj_li)
) {
console.log(
`Session slct li stored version has changed for ID = ${$ae_loc.person_id}`,
$journals_slct.journal_obj_li
);
} else {
if (log_lvl > 1) {
console.log(
`Session slct li stored version has not changed for ID = ${$ae_loc.person_id}`
);
}
}
}
});
// For some reason data.params.journal_entry_id (or whatever param) is not being passed to this page when loaded by a link from another page. This seems to be a bug with Svelte or SvelteKit. Hopefully fixed in a future version 5? 2024-11-06
$journals_slct.journal_entry_id = ae_acct.slct.journal_entry_id;
// $journals_slct.journal_entry_obj = ae_acct.slct.journal_entry_obj;
// For some reason data.params.journal_entry_id (or whatever param) is not being passed to this page when loaded by a link from another page. This seems to be a bug with Svelte or SvelteKit. Hopefully fixed in a future version 5? 2024-11-06
$journals_slct.journal_entry_id = ae_acct.slct.journal_entry_id;
// $journals_slct.journal_entry_obj = ae_acct.slct.journal_entry_obj;
let lq__journal_entry_obj = $derived(liveQuery(async () => {
let results = await db_journals.journal_entry
.get($journals_slct.journal_entry_id ?? ''); // null or undefined does not reset things like '' does
let lq__journal_entry_obj = $derived(
liveQuery(async () => {
let results = await db_journals.journal_entry.get($journals_slct.journal_entry_id ?? ''); // null or undefined does not reset things like '' does
// Check if results are different than the current session version stored under $journals_slct
if ($journals_slct.journal_entry_obj && results) {
if (JSON.stringify($journals_slct.journal_entry_obj) !== JSON.stringify(results)) {
$journals_slct.journal_entry_obj = { ...results};
}
}
// Check if results are different than the current session version stored under $journals_slct
if ($journals_slct.journal_entry_obj && results) {
if (JSON.stringify($journals_slct.journal_entry_obj) !== JSON.stringify(results)) {
$journals_slct.journal_entry_obj = { ...results };
}
}
return results;
}));
return results;
})
);
$effect(() => {
if (log_lvl) {
console.log(`lq__journal_entry_obj: journal_entry_id = ${$journals_slct?.journal_entry_id}`);
console.log(`lq__journal_entry_obj: results = `, lq__journal_entry_obj);
if ($journals_slct.journal_entry_obj && lq__journal_entry_obj) {
if (JSON.stringify($journals_slct.journal_entry_obj) !== JSON.stringify(lq__journal_entry_obj)) {
console.log(`Session slct stored version has changed for ID = ${$journals_slct.journal_entry_id}`, $journals_slct.journal_entry_obj);
} else {
console.log(`Session slct stored version has not changed for ID = ${$journals_slct.journal_entry_id}`);
}
}
}
});
$effect(() => {
if (log_lvl) {
console.log(`lq__journal_entry_obj: journal_entry_id = ${$journals_slct?.journal_entry_id}`);
console.log(`lq__journal_entry_obj: results = `, lq__journal_entry_obj);
if ($journals_slct.journal_entry_obj && lq__journal_entry_obj) {
if (
JSON.stringify($journals_slct.journal_entry_obj) !== JSON.stringify(lq__journal_entry_obj)
) {
console.log(
`Session slct stored version has changed for ID = ${$journals_slct.journal_entry_id}`,
$journals_slct.journal_entry_obj
);
} else {
console.log(
`Session slct stored version has not changed for ID = ${$journals_slct.journal_entry_id}`
);
}
}
}
});
// $effect(() => {
// if (browser && $lq__journal_entry_obj?.journal_entry_id) {
// $effect(() => {
// if (browser && $lq__journal_entry_obj?.journal_entry_id) {
// // $journals_loc.entry_view_history_li = [...new Set($journals_loc.entry_view_history_li)]
// // $journals_loc.entry_view_history_li = [...new Set($journals_loc.entry_view_history_li)]
// let tmp_history_li = [
// ...new Set($journals_loc?.entry_view_history_li ?? [])
// ];
// let tmp_history_li = [
// ...new Set($journals_loc?.entry_view_history_li ?? [])
// ];
// // Limit to last 15 entries
// if (tmp_history_li.length > 15) {
// tmp_history_li = tmp_history_li.slice(tmp_history_li.length - 15);
// }
// // Limit to last 15 entries
// if (tmp_history_li.length > 15) {
// tmp_history_li = tmp_history_li.slice(tmp_history_li.length - 15);
// }
// // let chk_history_li = tmp_history_li?.filter(item => item.id === $lq__journal_entry_obj?.journal_entry_id);
// // let chk_history_li = tmp_history_li?.filter(item => item.id === $lq__journal_entry_obj?.journal_entry_id);
// // if (chk_history_li?.length) {
// // // Already in history, do not add again
// // console.log(`Entry ID = ${$lq__journal_entry_obj?.journal_entry_id} already in history, not adding again.`, tmp_history_li);
// // if (chk_history_li?.length) {
// // // Already in history, do not add again
// // console.log(`Entry ID = ${$lq__journal_entry_obj?.journal_entry_id} already in history, not adding again.`, tmp_history_li);
// // // if (tmp_history_li !== $journals_loc.entry_view_history_li) {
// // if (JSON.stringify(tmp_history_li) !== JSON.stringify($journals_loc.entry_view_history_li)) {
// // $journals_loc.entry_view_history_li = tmp_history_li;
// // // if (tmp_history_li !== $journals_loc.entry_view_history_li) {
// // if (JSON.stringify(tmp_history_li) !== JSON.stringify($journals_loc.entry_view_history_li)) {
// // $journals_loc.entry_view_history_li = tmp_history_li;
// // console.log(`$journals_loc.entry_view_history_li = `, $journals_loc.entry_view_history_li);
// // }
// // console.log(`$journals_loc.entry_view_history_li = `, $journals_loc.entry_view_history_li);
// // }
// // return;
// // }
// // return;
// // }
// tmp_history_li.push({
// id: $lq__journal_entry_obj?.journal_entry_id ?? 'NONE',
// name: $lq__journal_entry_obj?.name ?? ae_util.iso_datetime_formatter($lq__journal_entry_obj?.created_on, 'datetime_iso_12_no_seconds'),
// url: `/journals/${$lq__journal_entry_obj?.journal_id ?? 'NONE'}/entry/${$lq__journal_entry_obj?.journal_entry_id ?? 'NONE'}`,
// });
// tmp_history_li.push({
// id: $lq__journal_entry_obj?.journal_entry_id ?? 'NONE',
// name: $lq__journal_entry_obj?.name ?? ae_util.iso_datetime_formatter($lq__journal_entry_obj?.created_on, 'datetime_iso_12_no_seconds'),
// url: `/journals/${$lq__journal_entry_obj?.journal_id ?? 'NONE'}/entry/${$lq__journal_entry_obj?.journal_entry_id ?? 'NONE'}`,
// });
// // Remove duplicates and keep most recent
// tmp_history_li = [...new Set(tmp_history_li.map(item => JSON.stringify(item)))].map(item => JSON.parse(item));
// // Remove duplicates and keep most recent
// tmp_history_li = [...new Set(tmp_history_li.map(item => JSON.stringify(item)))].map(item => JSON.parse(item));
// // Limit to last 15 entries
// if (tmp_history_li.length > 15) {
// tmp_history_li = tmp_history_li.slice(tmp_history_li.length - 15);
// }
// // Limit to last 15 entries
// if (tmp_history_li.length > 15) {
// tmp_history_li = tmp_history_li.slice(tmp_history_li.length - 15);
// }
// if (JSON.stringify(tmp_history_li) !== JSON.stringify($journals_loc?.entry_view_history_li)) {
// $journals_loc.entry_view_history_li = tmp_history_li;
// if (JSON.stringify(tmp_history_li) !== JSON.stringify($journals_loc?.entry_view_history_li)) {
// $journals_loc.entry_view_history_li = tmp_history_li;
// console.log(`$journals_loc.entry_view_history_li = `, $journals_loc?.entry_view_history_li);
// }
// console.log(`$journals_loc.entry_view_history_li = `, $journals_loc?.entry_view_history_li);
// }
// console.log(`$journals_loc.entry_view_history_li = `, $journals_loc?.entry_view_history_li);
// }
// });
// console.log(`$journals_loc.entry_view_history_li = `, $journals_loc?.entry_view_history_li);
// }
// });
$effect(() => {
if (browser && $lq__journal_entry_obj?.journal_entry_id) {
// log_lvl = 2;
// Start with the current KV or convert the LI to a KV if needed
let history_kv = { ...($journals_loc?.entry_view_history_kv ?? {}) };
// Add or update the current entry
const entry_id = $lq__journal_entry_obj?.journal_entry_id ?? 'NONE';
history_kv[entry_id] = {
id: entry_id,
name:
$lq__journal_entry_obj?.name ??
ae_util.iso_datetime_formatter(
$lq__journal_entry_obj?.created_on,
'datetime_iso_12_no_seconds'
),
url: `/journals/${$lq__journal_entry_obj?.journal_id ?? 'NONE'}/entry/${entry_id}`
};
$effect(() => {
if (browser && $lq__journal_entry_obj?.journal_entry_id) {
// log_lvl = 2;
// Start with the current KV or convert the LI to a KV if needed
let history_kv = { ...( $journals_loc?.entry_view_history_kv ?? {} ) };
console.log(`history_kv (before limiting) = `, history_kv);
// Add or update the current entry
const entry_id = $lq__journal_entry_obj?.journal_entry_id ?? 'NONE';
history_kv[entry_id] = {
id: entry_id,
name: $lq__journal_entry_obj?.name ?? ae_util.iso_datetime_formatter($lq__journal_entry_obj?.created_on, 'datetime_iso_12_no_seconds'),
url: `/journals/${$lq__journal_entry_obj?.journal_id ?? 'NONE'}/entry/${entry_id}`,
};
// // Convert KV to array, sort by most recent (last updated), and limit to 15
// let history_li = Object.values(history_kv);
console.log(`history_kv (before limiting) = `, history_kv);
// console.log(`history_li (before limiting) = `, history_li);
// // Convert KV to array, sort by most recent (last updated), and limit to 15
// let history_li = Object.values(history_kv);
// // If you want to keep the most recent 15, you can use the order of insertion.
// // To do this, remove the oldest if over 15.
// if (history_li.length > 15) {
// // Remove the oldest entries (by insertion order)
// // Get the keys in insertion order
// const keys = Object.keys(history_kv);
// const keys_to_remove = keys.slice(0, history_li.length - 15);
// for (const key of keys_to_remove) {
// delete history_kv[key];
// }
// }
// console.log(`history_li (before limiting) = `, history_li);
// Only update if changed
if (JSON.stringify(history_kv) !== JSON.stringify($journals_loc?.entry_view_history_kv)) {
$journals_loc.entry_view_history_kv = history_kv;
console.log(`$journals_loc.entry_view_history_kv = `, $journals_loc.entry_view_history_kv);
} else {
if (log_lvl > 1) {
console.log(`$journals_loc.entry_view_history_kv has not changed.`);
}
}
// // If you want to keep the most recent 15, you can use the order of insertion.
// // To do this, remove the oldest if over 15.
// if (history_li.length > 15) {
// // Remove the oldest entries (by insertion order)
// // Get the keys in insertion order
// const keys = Object.keys(history_kv);
// const keys_to_remove = keys.slice(0, history_li.length - 15);
// for (const key of keys_to_remove) {
// delete history_kv[key];
// }
// }
// Only update if changed
if (JSON.stringify(history_kv) !== JSON.stringify($journals_loc?.entry_view_history_kv)) {
$journals_loc.entry_view_history_kv = history_kv;
console.log(`$journals_loc.entry_view_history_kv = `, $journals_loc.entry_view_history_kv);
} else {
if (log_lvl > 1) {
console.log(`$journals_loc.entry_view_history_kv has not changed.`);
}
}
// log_lvl = 1;
}
});
// log_lvl = 1;
}
});
</script>
<!-- <svelte:head>
<title>
&AElig; Journals:
@@ -245,10 +288,9 @@ $effect(() => {
</title>
</svelte:head> -->
{#if $ae_loc.person_id == $lq__journal_obj?.person_id || $lq__journal_entry_obj?.public}
<section
class="
<section
class="
ae_journals__journal_entry
mx-auto
flex flex-col grow gap-1
@@ -259,24 +301,13 @@ $effect(() => {
max-w-max
space-y-2
"
>
<!-- {#if $lq__journal_entry_obj} -->
<Journal_entry_view
lq__journal_obj={lq__journal_obj}
lq__journal_obj_li={lq__journal_obj_li}
lq__journal_entry_obj={lq__journal_entry_obj}
/>
<!-- {/if} -->
</section>
>
<!-- {#if $lq__journal_entry_obj} -->
<Journal_entry_view {lq__journal_obj} {lq__journal_obj_li} {lq__journal_entry_obj} />
<!-- {/if} -->
</section>
{:else}
<section class="main_content grow px-1 md:px-2 pb-28 flex flex-col gap-1 items-center">
<p class="text-center">
You must be logged in as the owner to view this Journal Entry.
</p>
</section>
{/if}
<section class="main_content grow px-1 md:px-2 pb-28 flex flex-col gap-1 items-center">
<p class="text-center">You must be logged in as the owner to view this Journal Entry.</p>
</section>
{/if}

View File

@@ -4,65 +4,74 @@ console.log(`ae_p_journals [journal_entry_id] +page.ts start`);
import { browser } from '$app/environment';
import { journals_func } from '$lib/ae_journals/ae_journals_functions';
import { db_journals, journal_entry_field_li } from "$lib/ae_journals/db_journals";
import { db_journals, journal_entry_field_li } from '$lib/ae_journals/db_journals';
import { load_ae_obj_id } from '$lib/ae_core/core__crud_generic';
export async function load({ params, parent }) { // route
let log_lvl: number = 0;
export async function load({ params, parent }) {
// route
const log_lvl: number = 0;
let data = await parent();
data.log_lvl = log_lvl;
const data = await parent();
data.log_lvl = log_lvl;
let account_id = data.account_id;
let ae_acct = data[account_id];
const account_id = data.account_id;
const ae_acct = data[account_id];
let journal_id = params.journal_id;
ae_acct.slct.journal_id = journal_id;
const journal_id = params.journal_id;
ae_acct.slct.journal_id = journal_id;
let journal_entry_id = params.journal_entry_id;
if (!journal_entry_id) {
console.log(`ae_journals journals [journal_entry_id] +page.ts: The journal_entry_id was not found in the params!!!`);
error(404, {
const journal_entry_id = params.journal_entry_id;
if (!journal_entry_id) {
console.log(
`ae_journals journals [journal_entry_id] +page.ts: The journal_entry_id was not found in the params!!!`
);
error(404, {
message: 'Journals - Journal Entry ID not found'
});
}
ae_acct.slct.journal_entry_id = journal_entry_id;
if (log_lvl) {
console.log(`ae_journals journals [journal_entry_id] +page.ts: journal_entry_id = `, journal_entry_id);
}
}
ae_acct.slct.journal_entry_id = journal_entry_id;
if (log_lvl) {
console.log(
`ae_journals journals [journal_entry_id] +page.ts: journal_entry_id = `,
journal_entry_id
);
}
if (browser) {
if (log_lvl) {
console.log(`ae_journals journals [journal_entry_id] +page.ts: journal_entry_id = `, journal_entry_id);
}
// Load event journal entry object
// let load_journal_entry_obj = journals_func.load_ae_obj_id__journal_entry({
// api_cfg: ae_acct.api,
// journal_entry_id: journal_entry_id,
// try_cache: true,
// log_lvl: log_lvl
// });
if (browser) {
if (log_lvl) {
console.log(
`ae_journals journals [journal_entry_id] +page.ts: journal_entry_id = `,
journal_entry_id
);
}
// Load event journal entry object
// let load_journal_entry_obj = journals_func.load_ae_obj_id__journal_entry({
// api_cfg: ae_acct.api,
// journal_entry_id: journal_entry_id,
// try_cache: true,
// log_lvl: log_lvl
// });
let load_journal_entry_obj = load_ae_obj_id({
api_cfg: ae_acct.api,
obj_type: 'journal_entry',
obj_id: journal_entry_id,
db_instance: db_journals,
db_field_li: journal_entry_field_li,
log_lvl: 2
});
const load_journal_entry_obj = load_ae_obj_id({
api_cfg: ae_acct.api,
obj_type: 'journal_entry',
obj_id: journal_entry_id,
db_instance: db_journals,
db_field_li: journal_entry_field_li,
log_lvl: 2
});
if (!load_journal_entry_obj) {
error(404, {
message: 'Journals - Journal Entry not found'
});
} else {
ae_acct.slct.load_journal_entry_obj = load_journal_entry_obj;
}
}
if (!load_journal_entry_obj) {
error(404, {
message: 'Journals - Journal Entry not found'
});
} else {
ae_acct.slct.load_journal_entry_obj = load_journal_entry_obj;
}
}
// WARNING: Precaution against shared data between sites.
data[account_id] = ae_acct;
// WARNING: Precaution against shared data between sites.
data[account_id] = ae_acct;
return data;
return data;
}

View File

@@ -1,331 +1,334 @@
<script lang="ts">
// *** Import Aether specific variables and functions
import type { key_val } from '$lib/stores/ae_stores';
import { ae_util } from '$lib/ae_utils/ae_utils';
import { core_func } from '$lib/ae_core/ae_core_functions';
import {
ae_snip,
ae_loc,
ae_sess,
ae_api,
ae_trig,
slct,
slct_trigger
} from '$lib/stores/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 Aether specific variables and functions
import type { key_val } from '$lib/stores/ae_stores';
import { ae_util } from '$lib/ae_utils/ae_utils';
import { core_func } from '$lib/ae_core/ae_core_functions';
import { ae_snip, ae_loc, ae_sess, ae_api, ae_trig, slct, slct_trigger } from '$lib/stores/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 Comp_hosted_files_upload from '$lib/ae_core/ae_comp__hosted_files_upload.svelte';
import Element_manage_hosted_file_li_wrap from '$lib/elements/element_manage_hosted_file_li_all.svelte';
import Comp_hosted_files_upload from '$lib/ae_core/ae_comp__hosted_files_upload.svelte';
import Element_manage_hosted_file_li_wrap from '$lib/elements/element_manage_hosted_file_li_all.svelte';
interface Props {
log_lvl?: number;
link_to_type: string;
link_to_id: string;
lq__journal_entry_obj: any;
}
let { log_lvl = 0, link_to_type, link_to_id, lq__journal_entry_obj }: Props = $props();
interface Props {
log_lvl?: number;
link_to_type: string;
link_to_id: string;
lq__journal_entry_obj: any;
}
let ae_promises: key_val = $state({});
let hosted_file_kv: key_val = $state($lq__journal_entry_obj?.data_json?.hosted_file_kv ?? {}); // WARNING: This does no seem to set soon enough. Added an effect to set it as a backup.
// let hosted_file_li: [string, any][] = $state([]);
let slct_hosted_file_obj_li: any[] = $state(
$lq__journal_entry_obj?.data_json?.slct_hosted_file_obj_li ?? []
);
let slct_hosted_file_id_li: string[] = $state([]);
let upload_complete: boolean = $state(false);
let {
log_lvl = 0,
link_to_type,
link_to_id,
lq__journal_entry_obj,
}: Props = $props();
let slct_hosted_file_kv: key_val = $state({});
let slct_hosted_file_id: string | null = $state(null);
let slct_hosted_file_obj: any = $state(null);
let ae_promises: key_val = $state({});
let hosted_file_kv: key_val = $state($lq__journal_entry_obj?.data_json?.hosted_file_kv ?? {}); // WARNING: This does no seem to set soon enough. Added an effect to set it as a backup.
// let hosted_file_li: [string, any][] = $state([]);
let slct_hosted_file_obj_li: any[] = $state($lq__journal_entry_obj?.data_json?.slct_hosted_file_obj_li ?? []);
let slct_hosted_file_id_li: string[] = $state([]);
let upload_complete: boolean = $state(false);
let rem_hosted_file_id: string | null = $state(null);
let slct_hosted_file_kv: key_val = $state({});
let slct_hosted_file_id: string|null = $state(null);
let slct_hosted_file_obj: any = $state(null);
async function update_journal_entry() {
// hosted_file_kv = lq__journal_entry_obj.data_json.hosted_file_kv;
// slct_hosted_file_obj_li = [... $lq__journal_entry_obj?.data_json?.slct_hosted_file_obj_li];
// hosted_file_kv = {
// ...$lq__journal_entry_obj?.data_json?.hosted_file_kv,
// };
let rem_hosted_file_id: string|null = $state(null);
let data_kv: key_val = { data_json: $lq__journal_entry_obj?.data_json ?? {} };
async function update_journal_entry() {
// hosted_file_kv = lq__journal_entry_obj.data_json.hosted_file_kv;
// slct_hosted_file_obj_li = [... $lq__journal_entry_obj?.data_json?.slct_hosted_file_obj_li];
// hosted_file_kv = {
// ...$lq__journal_entry_obj?.data_json?.hosted_file_kv,
// };
data_kv.data_json = {
hosted_file_kv: hosted_file_kv
// ...$lq__journal_entry_obj?.data_json,
// hosted_file_kv: {
// ...slct_hosted_file_kv,
// },
// slct_hosted_file_obj_li: slct_hosted_file_obj_li
};
console.log('data_kv', data_kv);
let data_kv: key_val = {'data_json' : $lq__journal_entry_obj?.data_json ?? {}};
try {
const response = 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: 1
});
console.log('Journal entry updated successfully:', response);
} catch (error) {
console.error('Error updating journal entry:', error);
alert('Failed to update journal entry.');
}
}
data_kv.data_json = {
hosted_file_kv: hosted_file_kv,
// ...$lq__journal_entry_obj?.data_json,
// hosted_file_kv: {
// ...slct_hosted_file_kv,
// },
// slct_hosted_file_obj_li: slct_hosted_file_obj_li
};
console.log('data_kv', data_kv);
$effect(() => {
// if ($lq__journal_entry_obj && Object.keys(slct_hosted_file_kv ?? {}).length && slct_hosted_file_kv != hosted_file_kv) {
// hosted_file_kv = {
// hosted_file_kv,
// ...slct_hosted_file_kv
// };
// console.log('hosted_file_kv', hosted_file_kv);
// slct_hosted_file_kv = {};
// update_journal_entry();
// }
try {
const response = 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: 1,
});
console.log('Journal entry updated successfully:', response);
} catch (error) {
console.error('Error updating journal entry:', error);
alert('Failed to update journal entry.');
}
if (
!Object.keys(hosted_file_kv ?? {}).length &&
$lq__journal_entry_obj?.data_json?.hosted_file_kv
) {
hosted_file_kv = $lq__journal_entry_obj?.data_json?.hosted_file_kv;
}
}
// This is for the Select file option
if ($lq__journal_entry_obj && slct_hosted_file_id && slct_hosted_file_obj) {
if (log_lvl) {
console.log(`slct_hosted_file_id=${slct_hosted_file_id}`, slct_hosted_file_obj);
}
hosted_file_kv = {
...hosted_file_kv,
[slct_hosted_file_id]: slct_hosted_file_obj
};
slct_hosted_file_id = null;
slct_hosted_file_obj = null;
update_journal_entry();
$effect(() => {
// if ($lq__journal_entry_obj && Object.keys(slct_hosted_file_kv ?? {}).length && slct_hosted_file_kv != hosted_file_kv) {
// hosted_file_kv = {
// hosted_file_kv,
// ...slct_hosted_file_kv
// };
// console.log('hosted_file_kv', hosted_file_kv);
// slct_hosted_file_kv = {};
// update_journal_entry();
// }
// slct_hosted_file_obj = $lq__journal_entry_obj?.data_json?.slct_hosted_file_obj_li?.find((obj: any) => obj.hosted_file_id == slct_hosted_file_id);
// console.log('slct_hosted_file_obj', slct_hosted_file_obj);
}
if (!Object.keys(hosted_file_kv ?? {}).length && $lq__journal_entry_obj?.data_json?.hosted_file_kv) {
hosted_file_kv = $lq__journal_entry_obj?.data_json?.hosted_file_kv;
}
// This is for the Upload file option
if (
$lq__journal_entry_obj &&
slct_hosted_file_id_li &&
slct_hosted_file_id_li.length &&
upload_complete
) {
if (log_lvl) {
console.log(`slct_hosted_file_id=${slct_hosted_file_id}`, slct_hosted_file_obj);
}
// This is for the Select file option
if ($lq__journal_entry_obj && slct_hosted_file_id && slct_hosted_file_obj) {
if (log_lvl) {
console.log(`slct_hosted_file_id=${slct_hosted_file_id}`, slct_hosted_file_obj);
}
hosted_file_kv = {
...hosted_file_kv,
[slct_hosted_file_id]: slct_hosted_file_obj
};
slct_hosted_file_id = null;
slct_hosted_file_obj = null;
hosted_file_kv = {
...hosted_file_kv,
// ...keymap
// ...slct_hosted_file_kv
...Object.fromEntries(slct_hosted_file_id_li.map((id) => [id, slct_hosted_file_kv[id]]))
};
slct_hosted_file_id = null;
slct_hosted_file_obj = null;
slct_hosted_file_id_li = [];
update_journal_entry();
upload_complete = false;
// slct_hosted_file_obj = $lq__journal_entry_obj?.data_json?.slct_hosted_file_obj_li?.find((obj: any) => obj.hosted_file_id == slct_hosted_file_id);
// console.log('slct_hosted_file_obj', slct_hosted_file_obj);
}
update_journal_entry();
// This is for the Upload file option
if ($lq__journal_entry_obj && slct_hosted_file_id_li && slct_hosted_file_id_li.length && upload_complete) {
if (log_lvl) {
console.log(`slct_hosted_file_id=${slct_hosted_file_id}`, slct_hosted_file_obj);
}
// slct_hosted_file_obj = $lq__journal_entry_obj?.data_json?.slct_hosted_file_obj_li?.find((obj: any) => obj.hosted_file_id == slct_hosted_file_id);
// console.log('slct_hosted_file_obj', slct_hosted_file_obj);
}
hosted_file_kv = {
...hosted_file_kv,
// ...keymap
// ...slct_hosted_file_kv
...Object.fromEntries(slct_hosted_file_id_li.map(id => [id, slct_hosted_file_kv[id]]))
};
slct_hosted_file_id = null;
slct_hosted_file_obj = null;
slct_hosted_file_id_li = [];
upload_complete = false;
update_journal_entry();
// slct_hosted_file_obj = $lq__journal_entry_obj?.data_json?.slct_hosted_file_obj_li?.find((obj: any) => obj.hosted_file_id == slct_hosted_file_id);
// console.log('slct_hosted_file_obj', slct_hosted_file_obj);
}
if ($lq__journal_entry_obj && rem_hosted_file_id) {
if (log_lvl) {
console.log(`rem_hosted_file_id=${rem_hosted_file_id}`);
}
delete hosted_file_kv[rem_hosted_file_id];
rem_hosted_file_id = null;
update_journal_entry(); // Should we use await here?
}
});
if ($lq__journal_entry_obj && rem_hosted_file_id) {
if (log_lvl) {
console.log(`rem_hosted_file_id=${rem_hosted_file_id}`);
}
delete hosted_file_kv[rem_hosted_file_id];
rem_hosted_file_id = null;
update_journal_entry(); // Should we use await here?
}
});
</script>
<section
class:hidden={!$ae_loc.edit_mode}
class="
class:hidden={!$ae_loc.edit_mode}
class="
ae_section journal_entry__hosted_file
border border-gray-200 rounded
p-2 space-y-2
w-full
"
>
<button
type="button"
class="btn btn-sm preset-tonal-warning border border-warning-500 hover:preset-filled-warning-500 float-right"
title="Toggle between Upload and Select from Hosted Files"
onclick={() => {
if ($ae_sess.files.add_to_use_files_method == 'upload') {
$ae_sess.files.add_to_use_files_method = 'select';
} else {
$ae_sess.files.add_to_use_files_method = 'upload';
}
}}
>
<span class="fas fa-exchange-alt m-1"></span>
Upload/Select
</button>
>
<button
type="button"
class="btn btn-sm preset-tonal-warning border border-warning-500 hover:preset-filled-warning-500 float-right"
title="Toggle between Upload and Select from Hosted Files"
onclick={() => {
if ($ae_sess.files.add_to_use_files_method == 'upload') {
$ae_sess.files.add_to_use_files_method = 'select';
} else {
$ae_sess.files.add_to_use_files_method = 'upload';
}
}}
>
<span class="fas fa-exchange-alt m-1"></span>
Upload/Select
</button>
<h3 class="h3 text-lg">{$ae_sess.files.add_to_use_files_method == 'select' ? 'Select' : 'Upload'} and Manage Hosted Files</h3>
<!-- {Object.keys($lq__journal_entry_obj?.data_json?.hosted_file_kv ?? {}).length} selected -->
<!-- {Object.keys(hosted_file_kv ?? {}).length} selected -->
<!-- {Object.keys(slct_hosted_file_kv ?? {}).length} to add -->
<h3 class="h3 text-lg">
{$ae_sess.files.add_to_use_files_method == 'select' ? 'Select' : 'Upload'} and Manage Hosted Files
</h3>
<!-- {Object.keys($lq__journal_entry_obj?.data_json?.hosted_file_kv ?? {}).length} selected -->
<!-- {Object.keys(hosted_file_kv ?? {}).length} selected -->
<!-- {Object.keys(slct_hosted_file_kv ?? {}).length} to add -->
<div
class:hidden={$ae_sess.files.add_to_use_files_method != 'upload'}
class="upload"
>
<Comp_hosted_files_upload
class_li="
<div class:hidden={$ae_sess.files.add_to_use_files_method != 'upload'} class="upload">
<Comp_hosted_files_upload
class_li="
border border-gray-300 rounded-md p-2
bg-gray-100 dark:bg-gray-800
"
link_to_type={link_to_type}
link_to_id={link_to_id}
bind:hosted_file_id_li={slct_hosted_file_id_li}
bind:hosted_file_obj_li={slct_hosted_file_obj_li}
bind:hosted_file_obj_kv={slct_hosted_file_kv}
bind:upload_complete={upload_complete}
log_lvl={log_lvl}
>
{#snippet label()}
<span >
<div>
<span class="fas fa-upload"></span>
<strong class="bg-green-100 dark:bg-green-900 p-1">Upload Journal Entry files</strong>
</div>
<span class="text-sm text-gray-600 dark:text-gray-400 italic">
<strong>Aether hosted files only</strong>
</span>
</span>
{/snippet}
</Comp_hosted_files_upload>
</div>
{link_to_type}
{link_to_id}
bind:hosted_file_id_li={slct_hosted_file_id_li}
bind:hosted_file_obj_li={slct_hosted_file_obj_li}
bind:hosted_file_obj_kv={slct_hosted_file_kv}
bind:upload_complete
{log_lvl}
>
{#snippet label()}
<span>
<div>
<span class="fas fa-upload"></span>
<strong class="bg-green-100 dark:bg-green-900 p-1">Upload Journal Entry files</strong>
</div>
<span class="text-sm text-gray-600 dark:text-gray-400 italic">
<strong>Aether hosted files only</strong>
</span>
</span>
{/snippet}
</Comp_hosted_files_upload>
</div>
<div
class:hidden={$ae_sess.files.add_to_use_files_method != 'select'}
class=""
>
<!-- link_to_type={'journal_entry'} -->
<!-- link_to_id={$lq__journal_entry_obj?.journal_entry_id} -->
<Element_manage_hosted_file_li_wrap
link_to_type={'account'}
link_to_id={$ae_loc?.account_id}
allow_basic={true}
allow_moderator={true}
class_li={''}
bind:slct_hosted_file_kv={slct_hosted_file_kv}
bind:slct_hosted_file_id={slct_hosted_file_id}
bind:slct_hosted_file_obj={slct_hosted_file_obj}
/>
</div>
<div class:hidden={$ae_sess.files.add_to_use_files_method != 'select'} class="">
<!-- link_to_type={'journal_entry'} -->
<!-- link_to_id={$lq__journal_entry_obj?.journal_entry_id} -->
<Element_manage_hosted_file_li_wrap
link_to_type={'account'}
link_to_id={$ae_loc?.account_id}
allow_basic={true}
allow_moderator={true}
class_li={''}
bind:slct_hosted_file_kv
bind:slct_hosted_file_id
bind:slct_hosted_file_obj
/>
</div>
{#if !Object.keys(hosted_file_kv ?? {}).length}
No file(s) uploaded yet.
{:else}
<!-- {Object.keys(hosted_file_kv ?? {}).length} -->
<!-- <pre>
{#if !Object.keys(hosted_file_kv ?? {}).length}
No file(s) uploaded yet.
{:else}
<!-- {Object.keys(hosted_file_kv ?? {}).length} -->
<!-- <pre>
{JSON.stringify(hosted_file_kv)}
</pre> -->
{#each Object.entries(hosted_file_kv) as [hosted_file_id, hosted_file_obj]}
<div
class="flex flex-row flex-wrap gap-1 items-center justify-center w-full"
>
{#each Object.entries(hosted_file_kv) as [hosted_file_id, hosted_file_obj]}
<div class="flex flex-row flex-wrap gap-1 items-center justify-center w-full">
<label for="filename" class="grow">
<span class="text-sm text-gray-600 dark:text-gray-400 italic">
<span class="fas fa-file-alt"></span>
<strong class="bg-green-100 p-1">Filename</strong>
</span>
<input
type="text"
id="filename"
name="filename"
value={hosted_file_obj?.filename ? hosted_file_obj?.filename : 'unknown'}
class="input w-full"
/>
</label>
<label for="filename" class="grow">
<span class="text-sm text-gray-600 dark:text-gray-400 italic">
<span class="fas fa-file-alt"></span>
<strong class="bg-green-100 p-1">Filename</strong>
</span>
<input type="text" id="filename" name="filename" value={(hosted_file_obj?.filename ? hosted_file_obj?.filename : 'unknown')} class="input w-full">
</label>
<label for="extension max-w-20">
<span class="text-sm text-gray-600 dark:text-gray-400 italic">
<span class="fas fa-file-code"></span>
<strong class="bg-green-100 p-1">File Extension</strong>
{#if !$ae_loc.administrator_access}
<span class="fas fa-lock" title="Field is locked"></span>
{:else}
<span class="fas fa-unlock" title="Field is unlocked"></span>
{/if}
</span>
<input
type="text"
id="extension"
name="extension"
value={hosted_file_obj?.extension ? hosted_file_obj?.extension : 'ext'}
readonly={!$ae_loc.administrator_access}
class="input w-full max-w-20"
/>
</label>
<label for="extension max-w-20">
<span class="text-sm text-gray-600 dark:text-gray-400 italic">
<span class="fas fa-file-code"></span>
<strong class="bg-green-100 p-1">File Extension</strong>
{#if !$ae_loc.administrator_access}
<span class="fas fa-lock" title="Field is locked"></span>
{:else}
<span class="fas fa-unlock" title="Field is unlocked"></span>
{/if}
</span>
<input
type="text"
id="extension"
name="extension"
value={(hosted_file_obj?.extension ? hosted_file_obj?.extension : 'ext')}
readonly={!$ae_loc.administrator_access}
class="input w-full max-w-20"
>
</label>
<button
disabled={!$ae_loc.administrator_access}
type="button"
onclick={async () => {
if (confirm('Are you sure you want to remove the file?')) {
// First - Attempt to delete the hosted file
ae_promises.journal_entry_obj__hosted_file = await core_func
.delete_ae_obj_id__hosted_file({
api_cfg: $ae_api,
hosted_file_id: hosted_file_id,
link_to_type: link_to_type,
link_to_id: link_to_id,
rm_orphan: true,
fake_delete: true,
log_lvl: log_lvl
})
.then(function (delete_result) {
// Second - If deleted, then update the journal_entry_obj
console.log(`File removed. Now update the journal_entry_obj`);
<button
disabled={!$ae_loc.administrator_access}
type="button"
onclick={async () => {
if (confirm('Are you sure you want to remove the file?')) {
// First - Attempt to delete the hosted file
ae_promises.journal_entry_obj__hosted_file = await core_func.delete_ae_obj_id__hosted_file({
api_cfg: $ae_api,
hosted_file_id: hosted_file_id,
link_to_type: link_to_type,
link_to_id: link_to_id,
rm_orphan: true,
fake_delete: true,
log_lvl: log_lvl
})
.then(function (delete_result) {
// Second - If deleted, then update the journal_entry_obj
console.log(`File removed. Now update the journal_entry_obj`);
rem_hosted_file_id = hosted_file_id; // Should we use await here?
// update_journal_entry();
})
.catch(function (error: any) {
console.log('Something went wrong.');
console.log(error);
return false;
})
.finally(() => {
// We need to do all of this since the DB object has changed and the SLCT object does automatically update (yet...??? Svelte 5?).
slct_hosted_file_obj.hosted_file_id = null;
slct_hosted_file_obj.file_path = null;
slct_hosted_file_obj.filename = null;
slct_hosted_file_obj.file_extension = null;
});
}
}}
class="btn btn-sm preset-tonal-error"
>
{#await ae_promises.journal_entry_obj__hosted_file}
<span class="fas fa-spinner fa-spin m-1"></span>
{:then}
<span class="fas fa-trash-alt m-1"></span>
Remove File
{/await}
<!-- <span class="fas fa-trash-alt m-1"></span>
rem_hosted_file_id = hosted_file_id; // Should we use await here?
// update_journal_entry();
})
.catch(function (error: any) {
console.log('Something went wrong.');
console.log(error);
return false;
})
.finally(() => {
// We need to do all of this since the DB object has changed and the SLCT object does automatically update (yet...??? Svelte 5?).
slct_hosted_file_obj.hosted_file_id = null;
slct_hosted_file_obj.file_path = null;
slct_hosted_file_obj.filename = null;
slct_hosted_file_obj.file_extension = null;
});
}
}}
class="btn btn-sm preset-tonal-error"
>
{#await ae_promises.journal_entry_obj__hosted_file}
<span class="fas fa-spinner fa-spin m-1"></span>
{:then}
<span class="fas fa-trash-alt m-1"></span>
Remove File
{/await}
<!-- <span class="fas fa-trash-alt m-1"></span>
Remove File -->
</button>
</button>
</div>
{/each}
</div>
{/each}
<!-- <label for="file_path">File Path
<!-- <label for="file_path">File Path
{#if !$ae_loc.administrator_access}
<span class="fas fa-lock" title="Field is locked"></span>
{:else}
@@ -340,7 +343,5 @@ $effect(() => {
class="input w-full"
>
</label> -->
{/if}
{/if}
</section>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,202 +1,223 @@
<script lang="ts">
interface Props {
log_lvl?: number;
lq__journal_obj: any;
}
interface Props {
log_lvl?: number;
lq__journal_obj: any;
}
let {
log_lvl = $bindable(0),
lq__journal_obj,
}: Props = $props();
let { log_lvl = $bindable(0), lq__journal_obj }: Props = $props();
import {
ArrowDown01,
ArrowDown10,
ArrowDownUp,
BetweenVerticalEnd,
BetweenVerticalStart,
BookHeart,
BookImage,
Bookmark,
BookOpenText,
BriefcaseBusiness,
Check,
Copy,
Expand,
Eye,
EyeOff,
Flag,
FlagOff,
FilePlus,
Fingerprint,
Globe,
Library,
MessageSquareWarning,
Minus,
Notebook,
Pencil,
Plus,
RemoveFormatting,
SquareLibrary,
Shapes,
Share2,
ShieldCheck,
ShieldMinus,
Siren,
Skull,
Tags,
Target,
ToggleLeft,
ToggleRight,
Trash2,
TypeOutline,
X
} from '@lucide/svelte';
import {
ArrowDown01, ArrowDown10, ArrowDownUp,
BetweenVerticalEnd, BetweenVerticalStart,
BookHeart, BookImage, Bookmark, BookOpenText, BriefcaseBusiness,
Check, Copy,
Expand, Eye, EyeOff,
Flag, FlagOff, FilePlus, Fingerprint,
Globe,
Library,
MessageSquareWarning, Minus,
Notebook,
Pencil, Plus,
RemoveFormatting,
SquareLibrary,
Shapes, Share2, ShieldCheck, ShieldMinus, Siren, Skull,
Tags, Target, ToggleLeft, ToggleRight, Trash2, TypeOutline,
X
} from '@lucide/svelte';
import {
ae_snip,
ae_loc,
ae_sess,
ae_api,
ae_trig,
slct,
slct_trigger
} from '$lib/stores/ae_stores';
import {
journals_loc,
journals_sess,
journals_slct,
journals_prom,
journals_trig
} from '$lib/ae_journals/ae_journals_stores';
import { journals_func } from '$lib/ae_journals/ae_journals_functions';
import { ae_snip, ae_loc, ae_sess, ae_api, ae_trig, slct, slct_trigger } from '$lib/stores/ae_stores';
import { journals_loc, journals_sess, journals_slct, journals_prom, journals_trig } from '$lib/ae_journals/ae_journals_stores';
import { journals_func } from '$lib/ae_journals/ae_journals_functions';
// Trigger doing a search query for journal entries
$effect(async () => {
if ($journals_trig.journal_entry_qry) {
$journals_trig.journal_entry_qry = false;
if (log_lvl) {
console.log(
`Triggered: $journals_trig.journal_entry_qry: ${$journals_loc.qry__search_text}`
);
}
// Trigger doing a search query for journal entries
$effect(async () => {
if ($journals_trig.journal_entry_qry) {
$journals_trig.journal_entry_qry = false;
// $journals_prom.load__journal_entry_obj_qry = journals_func.qry__journal_entry({
$journals_prom.load__journal_entry_obj_li = await journals_func.qry__journal_entry({
api_cfg: $ae_api,
journal_id: $lq__journal_obj?.journal_id ?? '',
qry_str: $journals_loc.qry__search_text,
if (log_lvl) {
console.log(`Triggered: $journals_trig.journal_entry_qry: ${$journals_loc.qry__search_text}`);
}
// qry_created_on: null,
// qry_alert: null,
// qry_priority: null,
// qry_type: and_type,
// $journals_prom.load__journal_entry_obj_qry = journals_func.qry__journal_entry({
$journals_prom.load__journal_entry_obj_li = await journals_func.qry__journal_entry({
api_cfg: $ae_api,
journal_id: $lq__journal_obj?.journal_id ?? '',
qry_str: $journals_loc.qry__search_text,
// enabled: $journals_loc.recovery_meetings.qry__enabled,
// hidden: $journals_loc.recovery_meetings.qry__hidden,
// order_by_li: $journals_loc.recovery_meetings.qry__order_by_li,
// limit: $journals_loc.recovery_meetings.qry__limit,
// try_cache: try_cache,
log_lvl: log_lvl
});
if ($journals_prom.load__journal_entry_obj_li.length) {
$journals_sess.entry_li = $journals_prom.load__journal_entry_obj_li;
// qry_created_on: null,
// qry_alert: null,
// qry_priority: null,
// qry_type: and_type,
$journals_sess = {
...$journals_sess
}; // ensure session is updated
// enabled: $journals_loc.recovery_meetings.qry__enabled,
// hidden: $journals_loc.recovery_meetings.qry__hidden,
// order_by_li: $journals_loc.recovery_meetings.qry__order_by_li,
// limit: $journals_loc.recovery_meetings.qry__limit,
// try_cache: try_cache,
log_lvl: log_lvl,
});
if ($journals_prom.load__journal_entry_obj_li.length) {
$journals_sess.entry_li = $journals_prom.load__journal_entry_obj_li;
$journals_sess = {
...$journals_sess }; // ensure session is updated
// $journals_trig.journal_entry_li = true; // trigger the entry list to refresh
// $journals_trig.journal_entry_li = $journals_prom.load__journal_entry_obj_li;
} else {
console.log('Clear the search results: no entries found for that query.');
// $journals_sess.entry_li = [''];
$journals_sess.entry_li = null;
// $journals_trig.journal_entry_li = true;
// alert('No journal entries found for that search query.');
// $journals_sess = $journals_sess;
}
if (log_lvl) {
console.log(`$journals_sess.entry_li = `, $journals_sess.entry_li);
}
}
});
// $journals_trig.journal_entry_li = true; // trigger the entry list to refresh
// $journals_trig.journal_entry_li = $journals_prom.load__journal_entry_obj_li;
} else {
console.log('Clear the search results: no entries found for that query.');
// $journals_sess.entry_li = [''];
$journals_sess.entry_li = null;
// $journals_trig.journal_entry_li = true;
// alert('No journal entries found for that search query.');
// $journals_sess = $journals_sess;
}
if (log_lvl) {
console.log(`$journals_sess.entry_li = `, $journals_sess.entry_li);
}
}
});
</script>
<!-- Search input form -->
<span class="flex flex-row flex-wrap items-center justify-center gap-1">
<span class="text-sm text-gray-500 hidden lg:inline">
Search:
</span>
<input
disabled={false}
type="text"
placeholder="Search Journal Entries"
bind:value={$journals_loc.qry__search_text}
onkeyup={(event) => {
if (event.key === 'Enter') {
// $journals_loc.qry__search_text = event.target.value;
$journals_trig.journal_entry_qry = true;
}
}}
title={`Search for Entries in "${$lq__journal_obj?.name}. Press Enter to search.`}
autocomplete="off"
class="
<span class="text-sm text-gray-500 hidden lg:inline"> Search: </span>
<input
disabled={false}
type="text"
placeholder="Search Journal Entries"
bind:value={$journals_loc.qry__search_text}
onkeyup={(event) => {
if (event.key === 'Enter') {
// $journals_loc.qry__search_text = event.target.value;
$journals_trig.journal_entry_qry = true;
}
}}
title={`Search for Entries in "${$lq__journal_obj?.name}. Press Enter to search.`}
autocomplete="off"
class="
input input-sm input-bordered
w-44 md:w-52
text-sm
"
class:bg-red-200={$journals_sess.entry_li == null}
class:dark:bg-red-800={$journals_sess.entry_li == null}
/>
<!-- Clear search text button -->
<button
type="button"
class:hidden={!$journals_loc.qry__search_text}
onclick={() => {
console.log(`TESTING - 1 - Cleared search query: ${$journals_loc.qry__search_text}`);
$journals_loc.qry__search_text = '';
console.log(`TESTING - 2 - Cleared search query: ${$journals_loc.qry__search_text}`);
$journals_trig.journal_entry_qry = true;
}}
class="
class:bg-red-200={$journals_sess.entry_li == null}
class:dark:bg-red-800={$journals_sess.entry_li == null}
/>
<!-- Clear search text button -->
<button
type="button"
class:hidden={!$journals_loc.qry__search_text}
onclick={() => {
console.log(`TESTING - 1 - Cleared search query: ${$journals_loc.qry__search_text}`);
$journals_loc.qry__search_text = '';
console.log(`TESTING - 2 - Cleared search query: ${$journals_loc.qry__search_text}`);
$journals_trig.journal_entry_qry = true;
}}
class="
btn btn-sm
preset-tonal-tertiary
preset-outlined-tertiary-100-900
hover:preset-filled-tertiary-100-900
transition-all
"
title="Clear search query text"
>
<RemoveFormatting size="1.25em" class="text-neutral-800/60 dark:text-neutral-50/60" />
<span class="hidden md:inline">
Clear
</span>
{#await $journals_prom.load__journal_entry_obj_li}
<span class="text-sm text-gray-500 italic">
Loading...
</span>
{:then load_result}
{#if load_result === null}
<span class="text-xs text-gray-600/80 dark:text-gray-400/80 italic font-semibold">
No entries found - null
</span>
{:else if load_result?.length === 0}
<span class="text-xs text-gray-600/80 dark:text-gray-400/80 italic font-semibold">
No entries found
</span>
{:else if $journals_sess.entry_li?.length === 0}
<span class="text-xs text-gray-600/80 dark:text-gray-400/80 italic">
Enter to search
</span>
{:else}
<span class="text-xs text-gray-600/80 dark:text-gray-400/80 italic">
{load_result?.length ?? 0} found
</span>
{/if}
{:catch error}
<span class="text-xs text-red-600/80 dark:text-red-400/80 italic">
Error loading entries.
</span>
{/await}
</button>
title="Clear search query text"
>
<RemoveFormatting size="1.25em" class="text-neutral-800/60 dark:text-neutral-50/60" />
<span class="hidden md:inline"> Clear </span>
{#await $journals_prom.load__journal_entry_obj_li}
<span class="text-sm text-gray-500 italic"> Loading... </span>
{:then load_result}
{#if load_result === null}
<span class="text-xs text-gray-600/80 dark:text-gray-400/80 italic font-semibold">
No entries found - null
</span>
{:else if load_result?.length === 0}
<span class="text-xs text-gray-600/80 dark:text-gray-400/80 italic font-semibold">
No entries found
</span>
{:else if $journals_sess.entry_li?.length === 0}
<span class="text-xs text-gray-600/80 dark:text-gray-400/80 italic"> Enter to search </span>
{:else}
<span class="text-xs text-gray-600/80 dark:text-gray-400/80 italic">
{load_result?.length ?? 0} found
</span>
{/if}
{:catch error}
<span class="text-xs text-red-600/80 dark:text-red-400/80 italic">
Error loading entries.
</span>
{/await}
</button>
</span>
<!-- Give list of categories to base the new entry on -->
<span class="flex flex-row items-center gap-2">
<span class="text-sm text-gray-500 hidden md:inline">
Category:
</span>
<select
class="
<span class="text-sm text-gray-500 hidden md:inline"> Category: </span>
<select
class="
btn btn-sm
preset-tonal-tertiary
preset-outlined-tertiary-100-900
hover:preset-filled-tertiary-100-900
transition-all
"
bind:value={$journals_loc.qry__category_code}
onchange={(event) => {
// WARNING: This will cause pages to reset if the journal entry list is being filtered by category. This is a bug that should be fixed.
$journals_loc.qry__category_code = event.target.value;
$journals_loc.filter__category_code = event.target.value;
$journals_trig.journal_entry_li = true;
console.log('Selected category:', $journals_loc.qry__category_code);
}}
title="Select a category for the new journal entry"
>
<option value="">Select Category</option>
{#each $lq__journal_obj?.cfg_json?.category_li as category}
<option value={category.code}>{category.name}</option>
{/each}
</select>
</span>
bind:value={$journals_loc.qry__category_code}
onchange={(event) => {
// WARNING: This will cause pages to reset if the journal entry list is being filtered by category. This is a bug that should be fixed.
$journals_loc.qry__category_code = event.target.value;
$journals_loc.filter__category_code = event.target.value;
$journals_trig.journal_entry_li = true;
console.log('Selected category:', $journals_loc.qry__category_code);
}}
title="Select a category for the new journal entry"
>
<option value="">Select Category</option>
{#each $lq__journal_obj?.cfg_json?.category_li as category}
<option value={category.code}>{category.name}</option>
{/each}
</select>
</span>

File diff suppressed because it is too large Load Diff

View File

@@ -1,143 +1,159 @@
<script lang="ts">
// *** Import Svelte specific
import { goto } from '$app/navigation';
// *** Import Svelte specific
import { goto } from '$app/navigation';
// *** Import other supporting libraries
import {
BookPlus, BookOpenText,
FilePlus, Menu, Pencil
} from '@lucide/svelte';
// *** Import other supporting libraries
import { BookPlus, BookOpenText, FilePlus, Menu, Pencil } from '@lucide/svelte';
// *** Import Aether specific variables and functions
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/stores/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 Aether specific variables and functions
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/stores/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';
interface Props {
log_lvl?: number;
lq__journal_obj: any;
lq__journal_entry_obj_li: any;
}
interface Props {
log_lvl?: number;
lq__journal_obj: any;
lq__journal_entry_obj_li: any;
}
let { log_lvl = 0,
lq__journal_obj,
lq__journal_entry_obj_li
}: Props = $props();
let { log_lvl = 0, lq__journal_obj, lq__journal_entry_obj_li }: Props = $props();
// let ae_promises: key_val = {};
// let ae_tmp: key_val = {};
// let ae_trigger: any = null;
// let ae_triggers: key_val = {};
// let ae_promises: key_val = {};
// let ae_tmp: key_val = {};
// let ae_trigger: any = null;
// let ae_triggers: key_val = {};
let show_menu: boolean = $state(false);
let typed_journal_passcode: string = $state('');
let passcode_timer: any = $state(null);
let show_menu: boolean = $state(false);
let typed_journal_passcode: string = $state('');
let passcode_timer: any = $state(null);
$effect(() => {
if (typed_journal_passcode?.length > 4) {
if (!$journals_sess?.journal_kv) {
$journals_sess.journal_kv = {};
}
if (!$journals_sess.journal_kv[$lq__journal_obj?.id]) {
$journals_sess.journal_kv[$lq__journal_obj?.id] = {};
}
$effect(() => {
if (typed_journal_passcode?.length > 4) {
if (!$journals_sess?.journal_kv) {
$journals_sess.journal_kv = {};
}
if (!$journals_sess.journal_kv[$lq__journal_obj?.id]) {
$journals_sess.journal_kv[$lq__journal_obj?.id] = {};
}
verify_journal_passcode();
}
verify_journal_passcode();
}
// We need to set a timeout to force the user to re-enter their private passcode
if ($lq__journal_obj?.id && $journals_sess?.journal_kv[$lq__journal_obj?.id] && $journals_sess?.journal_kv[$lq__journal_obj?.id]?.journal_passcode_verified) {
if (passcode_timer) {
if (log_lvl) {
console.log('Passcode timer already set');
}
return;
}
console.log('Setting passcode timer');
passcode_timer = setTimeout(() => {
if (log_lvl) {
console.log('Passcode timer expired');
}
typed_journal_passcode = '';
if (!$journals_sess?.journal_kv[$lq__journal_obj?.id]) {
$journals_sess.journal_kv[$lq__journal_obj?.id] = {};
}
$journals_sess.journal_kv[$lq__journal_obj?.id].journal_passcode_verified = false;
}, 1000 * 60 * 1); // 1 minutes
// }, 1000 * $lq__journal_obj?.passcode_timeout); // 5 minutes
}
});
// We need to set a timeout to force the user to re-enter their private passcode
if (
$lq__journal_obj?.id &&
$journals_sess?.journal_kv[$lq__journal_obj?.id] &&
$journals_sess?.journal_kv[$lq__journal_obj?.id]?.journal_passcode_verified
) {
if (passcode_timer) {
if (log_lvl) {
console.log('Passcode timer already set');
}
return;
}
console.log('Setting passcode timer');
passcode_timer = setTimeout(
() => {
if (log_lvl) {
console.log('Passcode timer expired');
}
typed_journal_passcode = '';
if (!$journals_sess?.journal_kv[$lq__journal_obj?.id]) {
$journals_sess.journal_kv[$lq__journal_obj?.id] = {};
}
$journals_sess.journal_kv[$lq__journal_obj?.id].journal_passcode_verified = false;
},
1000 * 60 * 1
); // 1 minutes
// }, 1000 * $lq__journal_obj?.passcode_timeout); // 5 minutes
}
});
function verify_journal_passcode() {
if (log_lvl) {
console.log(`verify_journal_passcode: typed_journal_passcode = ${typed_journal_passcode} journal private passcode = ${$lq__journal_obj?.private_passcode}`);
}
function verify_journal_passcode() {
if (log_lvl) {
console.log(
`verify_journal_passcode: typed_journal_passcode = ${typed_journal_passcode} journal private passcode = ${$lq__journal_obj?.private_passcode}`
);
}
if (typed_journal_passcode === $lq__journal_obj?.private_passcode) {
console.log('Matched journal private passcode');
if (!$journals_sess?.journal_kv[$lq__journal_obj?.id]) {
$journals_sess.journal_kv[$lq__journal_obj?.id] = {};
}
$journals_sess.journal_kv[$lq__journal_obj?.id] = {
typed_journal_passcode: typed_journal_passcode,
journal_passcode_verified: true
};
if (typed_journal_passcode === $lq__journal_obj?.private_passcode) {
console.log('Matched journal private passcode');
if (!$journals_sess?.journal_kv[$lq__journal_obj?.id]) {
$journals_sess.journal_kv[$lq__journal_obj?.id] = {};
}
$journals_sess.journal_kv[$lq__journal_obj?.id] = {
typed_journal_passcode: typed_journal_passcode,
journal_passcode_verified: true
};
typed_journal_passcode = '';
} else {
}
}
typed_journal_passcode = '';
} else {
}
}
</script>
<section class="
<section
class="
rounded-lg p-2 m-2 w-full
flex flex-col flex-wrap items-center justify-center
bg-{$lq__journal_obj?.cfg_json.color_scheme}-100
text-gray-900 dark:text-gray-900
"
bind:clientHeight={$ae_loc.iframe_height_modal_body}>
bind:clientHeight={$ae_loc.iframe_height_modal_body}
>
<header
class="ae_header journal__header flex flex-row flex-wrap gap-2 items-center justify-between w-full"
>
<h2 class="journal__name h3 text-center">
<BookOpenText class="inline-block text-neutral-800/60" />
{@html $lq__journal_obj?.name ?? 'Loading...'}
{#if $ae_loc.trusted_access && $ae_loc.edit_mode}
({$lq__journal_entry_obj_li?.length ?? '0'}×)
{/if}
{#await $journals_prom.load__journal_entry_obj_li}
<span class="fas fa-spinner fa-spin"></span>
{:then}
<!-- done -->
{/await}
</h2>
<header class="ae_header journal__header flex flex-row flex-wrap gap-2 items-center justify-between w-full">
<h2 class="journal__name h3 text-center ">
<BookOpenText class="inline-block text-neutral-800/60" />
{@html $lq__journal_obj?.name ?? 'Loading...'}
{#if $ae_loc.trusted_access && $ae_loc.edit_mode}
({$lq__journal_entry_obj_li?.length ?? '0'}×)
{/if}
{#await $journals_prom.load__journal_entry_obj_li}
<span class="fas fa-spinner fa-spin"></span>
{:then}
<!-- done -->
{/await}
</h2>
<div class="grow flex flex-row flex-wrap gap-2 items-center justify-end">
<section class="relative transition-all">
<!-- Menu Button -->
<button
type="button"
onclick={() => (show_menu = !show_menu)}
class="
<div class="grow flex flex-row flex-wrap gap-2 items-center justify-end">
<section class="relative transition-all">
<!-- Menu Button -->
<button
type="button"
onclick={() => (show_menu = !show_menu)}
class="
btn
variant-outline-secondary hover:preset-filled-secondary-400-600
py-1 px-2 w-24
transition-all
"
title="Toggle menu"
>
<Menu size="1.5em" class="inline-block" />
<span class="hidden md:inline">Menu</span>
</button>
title="Toggle menu"
>
<Menu size="1.5em" class="inline-block" />
<span class="hidden md:inline">Menu</span>
</button>
<!-- Menu -->
<!-- {#if show_menu} -->
<div
class="
<!-- Menu -->
<!-- {#if show_menu} -->
<div
class="
absolute top-12 right-0
p-4 z-50 w-80
space-y-0.5
@@ -147,145 +163,141 @@ function verify_journal_passcode() {
min-w-72
max-w-fit
"
class:hidden={!show_menu}
>
<div
class="
class:hidden={!show_menu}
>
<div
class="
flex flex-row flex-wrap items-center justify-evenly gap-2 w-full
"
>
>
<span class="text-sm text-gray-500">
<span class="fas fa-info-circle text-blue-500"></span>
Journal ID: {$lq__journal_obj?.id}
</span>
<button
type="button"
onclick={() => {
// $journals_sess.show__modal_new__journal_entry_obj = true
// log_lvl = 3;
<span class="text-sm text-gray-500">
<span class="fas fa-info-circle text-blue-500"></span>
Journal ID: {$lq__journal_obj?.id}
</span>
<button
type="button"
onclick={() => {
// $journals_sess.show__modal_new__journal_entry_obj = true
// log_lvl = 3;
let data_kv = {
category_code: null,
};
if ($journals_loc.qry__category_code) {
data_kv.category_code = $journals_loc.qry__category_code;
}
if (log_lvl) {
console.log('Creating new journal entry with data_kv:', data_kv);
}
journals_func.create_ae_obj__journal_entry({
api_cfg: $ae_api,
journal_id: $lq__journal_obj?.journal_id,
data_kv: data_kv,
log_lvl: log_lvl
}).then((results) => {
if (log_lvl) {
console.log('New journal entry created:', results);
}
$journals_slct.journal_entry_id = results?.journal_entry_id_random;
// $journals_loc.entry.edit = true;
$journals_loc.entry.edit_kv[$journals_slct.journal_entry_id] = 'current';
// alert(`Journal entry created successfully! ${$journals_slct.journal_entry_id}`);
}).catch((error) => {
console.error('Error updating journal entry:', error);
alert('Failed to update journal entry.');
}).finally(() => {
if ($journals_slct.journal_entry_id) {
goto(`/journals/${$lq__journal_obj?.journal_id}/entry/${$journals_slct.journal_entry_id}`);
} else {
alert('Failed to create new journal entry.');
}
});
}}
class="
let data_kv = {
category_code: null
};
if ($journals_loc.qry__category_code) {
data_kv.category_code = $journals_loc.qry__category_code;
}
if (log_lvl) {
console.log('Creating new journal entry with data_kv:', data_kv);
}
journals_func
.create_ae_obj__journal_entry({
api_cfg: $ae_api,
journal_id: $lq__journal_obj?.journal_id,
data_kv: data_kv,
log_lvl: log_lvl
})
.then((results) => {
if (log_lvl) {
console.log('New journal entry created:', results);
}
$journals_slct.journal_entry_id = results?.journal_entry_id_random;
// $journals_loc.entry.edit = true;
$journals_loc.entry.edit_kv[$journals_slct.journal_entry_id] = 'current';
// alert(`Journal entry created successfully! ${$journals_slct.journal_entry_id}`);
})
.catch((error) => {
console.error('Error updating journal entry:', error);
alert('Failed to update journal entry.');
})
.finally(() => {
if ($journals_slct.journal_entry_id) {
goto(
`/journals/${$lq__journal_obj?.journal_id}/entry/${$journals_slct.journal_entry_id}`
);
} else {
alert('Failed to create new journal entry.');
}
});
}}
class="
btn btn-sm
preset-tonal-secondary border border-secondary-500
hover:preset-filled-secondary-500
transition
"
title="Create a new journal entry for this journal: {$lq__journal_obj?.name}"
>
<FilePlus />
<!-- <span class="fas fa-plus m-1"></span> -->
<span class="hidden sm:inline">
New Journal Entry
</span>
</button>
title="Create a new journal entry for this journal: {$lq__journal_obj?.name}"
>
<FilePlus />
<!-- <span class="fas fa-plus m-1"></span> -->
<span class="hidden sm:inline"> New Journal Entry </span>
</button>
<button
type="button"
onclick={() => {
$journals_slct.tmp_journal_obj = {
name: $lq__journal_obj?.name,
description: $lq__journal_obj?.description,
type_code: $lq__journal_obj?.type_code,
passcode: $lq__journal_obj?.passcode,
passcode_timeout: $lq__journal_obj?.passcode_timeout,
auth_key: $lq__journal_obj?.auth_key,
cfg_json: $lq__journal_obj?.cfg_json
};
$journals_sess.show__modal_edit__journal_obj = true;
}}
class:hidden={!$ae_loc.edit_mode}
class="
<button
type="button"
onclick={() => {
$journals_slct.tmp_journal_obj = {
name: $lq__journal_obj?.name,
description: $lq__journal_obj?.description,
type_code: $lq__journal_obj?.type_code,
passcode: $lq__journal_obj?.passcode,
passcode_timeout: $lq__journal_obj?.passcode_timeout,
auth_key: $lq__journal_obj?.auth_key,
cfg_json: $lq__journal_obj?.cfg_json
};
$journals_sess.show__modal_edit__journal_obj = true;
}}
class:hidden={!$ae_loc.edit_mode}
class="
btn btn-sm
preset-tonal-warning border border-warning-500
hover:preset-filled-warning-500
transition
"
title="Edit Journal meta and configuration (name, type, passcode, categories, etc.: {$lq__journal_obj?.name})"
>
<Pencil />
<span class="hidden md:inline">
Edit Journal
</span>
</button>
title="Edit Journal meta and configuration (name, type, passcode, categories, etc.: {$lq__journal_obj?.name})"
>
<Pencil />
<span class="hidden md:inline"> Edit Journal </span>
</button>
</div>
</div>
<!-- Set Journal private_passcode (string) -->
<!-- The Journal private_passcode will be used along with the Journal passcode to encrypt the journal entries. -->
<input
type="text"
bind:value={typed_journal_passcode}
placeholder="Journal passcode"
onchange={() => {
// console.log('HERE');
// verify_journal_passcode();
}}
class="input input-sm input-bordered w-full mb-2"
title="Enter private passcode of this journal"
/>
<!-- Set Journal private_passcode (string) -->
<!-- The Journal private_passcode will be used along with the Journal passcode to encrypt the journal entries. -->
<input
type="text"
bind:value={typed_journal_passcode}
placeholder="Journal passcode"
onchange={() => {
// console.log('HERE');
// verify_journal_passcode();
}}
class="input input-sm input-bordered w-full mb-2"
title="Enter private passcode of this journal"
/>
{#if $journals_sess?.journal_kv[$lq__journal_obj?.id]?.journal_passcode_verified}
<div class="text-sm text-gray-500">
<span class="fas fa-check-circle text-green-500"></span>
Journal passcode verified
</div>
{:else}
<div class="text-sm text-gray-500">
<span class="fas fa-exclamation-circle text-red-500"></span>
Journal passcode not verified {$lq__journal_obj?.private_passcode ?? '??'}
</div>
{/if}
</div>
<!-- {/if} -->
</section>
</div>
</header>
{#if $journals_sess?.journal_kv[$lq__journal_obj?.id]?.journal_passcode_verified}
<div class="text-sm text-gray-500">
<span class="fas fa-check-circle text-green-500"></span>
Journal passcode verified
</div>
{:else}
<div class="text-sm text-gray-500">
<span class="fas fa-exclamation-circle text-red-500"></span>
Journal passcode not verified {$lq__journal_obj?.private_passcode ?? '??'}
</div>
{/if}
</div>
<!-- {/if} -->
</section>
</div>
</header>
<!-- Show Journal description -->
<!-- class:bg-green-100={$lq__journal_obj?.cfg_json.color_scheme ?? 'green'} -->
<!-- prose-h1:text-gray-100 dark:prose-h1:text-gray-900 -->
<!-- <div> -->
{#if $lq__journal_obj?.description && $ae_loc.edit_mode}
<div
class="
<!-- Show Journal description -->
<!-- class:bg-green-100={$lq__journal_obj?.cfg_json.color_scheme ?? 'green'} -->
<!-- prose-h1:text-gray-100 dark:prose-h1:text-gray-900 -->
<!-- <div> -->
{#if $lq__journal_obj?.description && $ae_loc.edit_mode}
<div
class="
prose
space-y-1
p-2
@@ -304,13 +316,9 @@ function verify_journal_passcode() {
prose-li:m-0 prose-li:p-0 prose-li:line-height-none
"
>
{@html $lq__journal_obj.description_md_html}
</div>
{/if}
<!-- </div> -->
</section>
>
{@html $lq__journal_obj.description_md_html}
</div>
{/if}
<!-- </div> -->
</section>

View File

@@ -1,84 +1,86 @@
<script lang="ts">
// let log_lvl: number = 0;
// let log_lvl: number = 0;
// *** Import Svelte specific
// import { goto } from '$app/navigation';
// *** Import Svelte specific
// import { goto } from '$app/navigation';
// *** Import other supporting libraries
// import { Spinner } from 'flowbite-svelte';
import {
BookOpenText, BookType
} from '@lucide/svelte';
// *** Import other supporting libraries
// import { Spinner } from 'flowbite-svelte';
import { BookOpenText, BookType } from '@lucide/svelte';
// *** Import Aether specific variables and functions
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/stores/ae_stores';
import { journals_loc, journals_sess, journals_slct } from '$lib/ae_journals/ae_journals_stores';
// *** Import Aether specific variables and functions
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/stores/ae_stores';
import { journals_loc, journals_sess, journals_slct } from '$lib/ae_journals/ae_journals_stores';
// *** Setup Svelte properties
interface Props {
lq__journal_obj_li: any;
}
// *** Setup Svelte properties
interface Props {
lq__journal_obj_li: any;
}
let { lq__journal_obj_li }: Props = $props();
let { lq__journal_obj_li }: Props = $props();
</script>
<section class="journal_list flex flex-col gap-2 items-center justify-center w-full">
{#if $lq__journal_obj_li && $lq__journal_obj_li.length}
{#each $lq__journal_obj_li as journals_journal_obj, index}
<div
class="
{#if $lq__journal_obj_li && $lq__journal_obj_li.length}
{#each $lq__journal_obj_li as journals_journal_obj, index}
<div
class="
container journal journal_obj
border rounded p-2 mb-2 space-y-2
w-full max-w-(--breakpoint-md)
flex flex-col items-center justify-center
bg-{journals_journal_obj?.cfg_json.color_scheme}-100
"
class:hidden={(journals_journal_obj?.hide || !journals_journal_obj?.enable) && !$ae_loc.trusted_access}
class:dim={journals_journal_obj.hide}
class:bg-warning-100={!journals_journal_obj?.enable}
class:text-warning-900={!journals_journal_obj?.enable}
>
<header
class="
class:hidden={(journals_journal_obj?.hide || !journals_journal_obj?.enable) &&
!$ae_loc.trusted_access}
class:dim={journals_journal_obj.hide}
class:bg-warning-100={!journals_journal_obj?.enable}
class:text-warning-900={!journals_journal_obj?.enable}
>
<header
class="
ae_header
flex flex-row gap-2 items-center justify-between
w-full
text-neutral-800/60
"
>
<h3 class="journal__name h3">
>
<h3 class="journal__name h3">
<BookType class="m-1 inline-block" />
<span class="journal__name">{@html journals_journal_obj.name}</span>
</h3>
<BookType class="m-1 inline-block" />
<span class="journal__name">{@html journals_journal_obj.name}</span>
</h3>
<!-- Show a label if the type code is set -->
{#if journals_journal_obj.type_code}
<span
class="
<!-- Show a label if the type code is set -->
{#if journals_journal_obj.type_code}
<span
class="
preset-tonal-warning
text-xs font-semibold
mr-2 px-2.5 py-0.5
rounded
"
>
<!-- <span class="ae_label">Type:</span> -->
<span class="ae_value">{journals_journal_obj.type_code}</span>
</span>
{/if}
</header>
>
<!-- <span class="ae_label">Type:</span> -->
<span class="ae_value">{journals_journal_obj.type_code}</span>
</span>
{/if}
</header>
<!-- {journals_journal_obj?.tmp_sort_3} -->
<!-- {journals_journal_obj?.tmp_sort_3} -->
{#if journals_journal_obj.description && $ae_loc.edit_mode}
<div
class="
{#if journals_journal_obj.description && $ae_loc.edit_mode}
<div
class="
prose
space-y-1
journal__description
@@ -96,55 +98,63 @@ let { lq__journal_obj_li }: Props = $props();
prose-h1:m-0 prose-h2:m-0 prose-h3:m-0 prose-h4:m-0 prose-h5:m-0 prose-h6:m-0
prose-li:m-0 prose-li:p-0 prose-li:line-height-none
"
>
{@html journals_journal_obj.description_md_html}
</div>
{/if}
>
{@html journals_journal_obj.description_md_html}
</div>
{/if}
<div class="ae_options flex flex-row gap-2 items-center justify-center">
<div class="ae_options flex flex-row gap-2 items-center justify-center">
<a
href="/journals/{journals_journal_obj?.journal_id}"
class="btn btn-secondary btn-md preset-tonal-primary border border-primary-500 hover:preset-filled-primary-500 hover:underline transition"
title={`View: ${journals_journal_obj?.name}`}
>
<!-- <span class="fas fa-envelope-open m-1"></span> -->
<BookOpenText class="m-1" />
Open
<a href="/journals/{journals_journal_obj?.journal_id}" class="btn btn-secondary btn-md preset-tonal-primary border border-primary-500 hover:preset-filled-primary-500 hover:underline transition" title={`View: ${journals_journal_obj?.name}`}>
<!-- <span class="fas fa-envelope-open m-1"></span> -->
<BookOpenText class="m-1" />
Open
{#if journals_journal_obj?.journal_entry_count}
<span class="ae_badge ae_info journal__journal_entry_count">
{@html journals_journal_obj?.journal_entry_count == 1
? `${journals_journal_obj?.journal_entry_count}&times; entry`
: `${journals_journal_obj?.journal_entry_count}&times; entries`}
</span>
{/if}
</a>
</div>
{#if journals_journal_obj?.journal_entry_count}
<span class="ae_badge ae_info journal__journal_entry_count">
{@html (journals_journal_obj?.journal_entry_count == 1 ? `${journals_journal_obj?.journal_entry_count}&times; entry` : `${journals_journal_obj?.journal_entry_count}&times; entries` )}
</span>
{/if}
</a>
</div>
<section
class="ae_section ae_footer ae_meta journal__meta mt-2 flex flex-col sm:flex-row gap-1 items-center justify-center text-sm text-gray-500"
class:hidden={!$ae_loc.administrator_access || !$ae_loc.edit_mode}
>
<div class="ae_group">
{#if !journals_journal_obj.updated_on}
<span
class="journal__created_on"
>
<span class="ae_label">Created on:</span>
<span class="ae_value">{ae_util.iso_datetime_formatter(journals_journal_obj.created_on, 'datetime_12_long')}</span>
</span>
{:else}
<span
class="journal__updated_on"
>
<span class="ae_label">Updated on:</span>
<span class="ae_value">{ae_util.iso_datetime_formatter(journals_journal_obj.updated_on, 'datetime_12_long')}</span>
</span>
{/if}
</div>
</section>
</div>
{/each}
{:else}
No journals found at this time
{/if}
<section
class="ae_section ae_footer ae_meta journal__meta mt-2 flex flex-col sm:flex-row gap-1 items-center justify-center text-sm text-gray-500"
class:hidden={!$ae_loc.administrator_access || !$ae_loc.edit_mode}
>
<div class="ae_group">
{#if !journals_journal_obj.updated_on}
<span class="journal__created_on">
<span class="ae_label">Created on:</span>
<span class="ae_value"
>{ae_util.iso_datetime_formatter(
journals_journal_obj.created_on,
'datetime_12_long'
)}</span
>
</span>
{:else}
<span class="journal__updated_on">
<span class="ae_label">Updated on:</span>
<span class="ae_value"
>{ae_util.iso_datetime_formatter(
journals_journal_obj.updated_on,
'datetime_12_long'
)}</span
>
</span>
{/if}
</div>
</section>
</div>
{/each}
{:else}
No journals found at this time
{/if}
</section>
<!-- {/if} -->

View File

@@ -1,322 +1,365 @@
<script lang="ts">
// *** Import Svelte specific
// *** Import Svelte specific
import {
ArrowDown01, ArrowDown10, ArrowDownUp,
BookHeart, BriefcaseBusiness,
CalendarClock, CalendarOff, Clock, CodeXml, Copy,
Eye, EyeOff,
Flag, FlagOff, FileX, Fingerprint,
Globe, Group,
History,
LockKeyhole, LockKeyholeOpen,
MessageSquareWarning, Minus,
NotebookPen, NotebookText, NotepadTextDashed,
Pencil, PenLine, Plus,
RemoveFormatting,
Search,
Shapes, Share2, ShieldCheck, ShieldMinus, Siren, Skull,
SquareLibrary,
Tags, Trash2, TypeOutline,
X
} from '@lucide/svelte';
import {
ArrowDown01,
ArrowDown10,
ArrowDownUp,
BookHeart,
BriefcaseBusiness,
CalendarClock,
CalendarOff,
Clock,
CodeXml,
Copy,
Eye,
EyeOff,
Flag,
FlagOff,
FileX,
Fingerprint,
Globe,
Group,
History,
LockKeyhole,
LockKeyholeOpen,
MessageSquareWarning,
Minus,
NotebookPen,
NotebookText,
NotepadTextDashed,
Pencil,
PenLine,
Plus,
RemoveFormatting,
Search,
Shapes,
Share2,
ShieldCheck,
ShieldMinus,
Siren,
Skull,
SquareLibrary,
Tags,
Trash2,
TypeOutline,
X
} from '@lucide/svelte';
// *** Import Aether specific variables and functions
import type { key_val } from '$lib/stores/ae_stores';
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/stores/ae_stores';
// *** Import Aether specific variables and functions
import type { key_val } from '$lib/stores/ae_stores';
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/stores/ae_stores';
import { journals_func } from '$lib/ae_journals/ae_journals_functions';
import { journals_slct } from '$lib/ae_journals/ae_journals_stores';
import { goto } from '$app/navigation';
interface Props {
log_lvl?: number;
obj_priority: any;
obj_sort: any;
obj_group: any;
obj_archive_on: any;
obj_hide: any;
obj_enable: any;
obj_delete: any;
}
let {
log_lvl = 0,
obj_priority,
obj_sort,
obj_group,
obj_archive_on,
obj_hide,
obj_enable,
obj_delete
}: Props = $props();
let ae_promises: key_val = $state({});
interface Props {
log_lvl?: number;
obj_priority: any;
obj_sort: any;
obj_group: any;
obj_archive_on: any;
obj_hide: any;
obj_enable: any;
obj_delete: any;
tmp_entry_obj: any;
update_journal_entry: any;
$lq__journal_entry_obj: any;
change_journal_id: any;
$lq__journal_obj_li: any;
}
let {
log_lvl = 0,
obj_priority,
obj_sort,
obj_group,
obj_archive_on,
obj_hide,
obj_enable,
obj_delete,
tmp_entry_obj,
update_journal_entry,
$lq__journal_entry_obj,
change_journal_id,
$lq__journal_obj_li
}: Props = $props();
let ae_promises: key_val = $state({});
</script>
<section class="ae_meta flex flex-row flex-wrap gap-1 items-center justify-between w-full">
<!-- {$lq__journal_entry_obj?.priority}
<!-- {$lq__journal_entry_obj?.priority}
{$lq__journal_entry_obj?.sort}
{$lq__journal_entry_obj?.group}
{obj_hide}
{obj_enable} -->
<!-- Set/unset priority (boolean) -->
<button
type="button"
onclick={() => {
obj_priority = !obj_priority;
// update_journal_entry();
}}
class="btn-icon btn-icon-sm md:btn-icon-base preset-tonal-tertiary transition hover:preset-filled-tertiary-500"
title="Toggle priority of this journal entry"
>
{#if obj_priority}
<Flag strokeWidth="2.5" color="green" class="inline-block" />
{:else}
<FlagOff strokeWidth="1" color="gray" class="inline-block" />
{/if}
<span class="hidden lg:inline">
Priority
</span>
</button>
<!-- Set/unset priority (boolean) -->
<button
type="button"
onclick={() => {
obj_priority = !obj_priority;
// update_journal_entry();
}}
class="btn-icon btn-icon-sm md:btn-icon-base preset-tonal-tertiary transition hover:preset-filled-tertiary-500"
title="Toggle priority of this journal entry"
>
{#if obj_priority}
<Flag strokeWidth="2.5" color="green" class="inline-block" />
{:else}
<FlagOff strokeWidth="1" color="gray" class="inline-block" />
{/if}
<span class="hidden lg:inline"> Priority </span>
</button>
<!-- Set sort order (number) -->
<span
class:hidden={!$ae_loc.edit_mode}
class="flex flex-row flex-wrap items-center justify-center border border-gray-300 rounded-lg">
<button
type="button"
onclick={() => {
obj_sort = obj_sort ? obj_sort + 1 : 1;
// update_journal_entry();
}}
class="btn-icon-sm preset-tonal-tertiary transition hover:preset-filled-tertiary-500"
title="Increment sort order of this journal entry"
>
<Plus strokeWidth="2.5" color="blue" />
</button>
<span class="mx-1">
{#if obj_sort}
{obj_sort}
{:else}
<!-- <ArrowDown01 /> -->
<ArrowDown10 />
{/if}
</span>
<button
type="button"
onclick={() => {
obj_sort = obj_sort ? obj_sort - 1 : 0;
// update_journal_entry();
}}
class="btn-icon-sm preset-tonal-tertiary transition hover:preset-filled-tertiary-500"
title="Decrement sort order of this journal entry"
>
<Minus strokeWidth="2.5" color="blue" />
</button>
</span>
<!-- Set sort order (number) -->
<span
class:hidden={!$ae_loc.edit_mode}
class="flex flex-row flex-wrap items-center justify-center border border-gray-300 rounded-lg"
>
<button
type="button"
onclick={() => {
obj_sort = obj_sort ? obj_sort + 1 : 1;
// update_journal_entry();
}}
class="btn-icon-sm preset-tonal-tertiary transition hover:preset-filled-tertiary-500"
title="Increment sort order of this journal entry"
>
<Plus strokeWidth="2.5" color="blue" />
</button>
<span class="mx-1">
{#if obj_sort}
{obj_sort}
{:else}
<!-- <ArrowDown01 /> -->
<ArrowDown10 />
{/if}
</span>
<button
type="button"
onclick={() => {
obj_sort = obj_sort ? obj_sort - 1 : 0;
// update_journal_entry();
}}
class="btn-icon-sm preset-tonal-tertiary transition hover:preset-filled-tertiary-500"
title="Decrement sort order of this journal entry"
>
<Minus strokeWidth="2.5" color="blue" />
</button>
</span>
<!-- Set group (string) -->
<input
type="text"
bind:value={obj_group}
placeholder="Group"
onchange={() => {
// update_journal_entry();
}}
class:hidden={!$ae_loc.edit_mode}
class="input input-sm input-bordered w-24"
title="Set group (for sorting) of this journal entry"
/>
<!-- Set group (string) -->
<input
type="text"
bind:value={obj_group}
placeholder="Group"
onchange={() => {
// update_journal_entry();
}}
class:hidden={!$ae_loc.edit_mode}
class="input input-sm input-bordered w-24"
title="Set group (for sorting) of this journal entry"
/>
<!-- Set archive datetime (string) -->
<span
class="flex flex-row flex-wrap items-center justify-center border border-gray-200 rounded-lg"
>
<input
type="datetime-local"
bind:value={obj_archive_on}
placeholder="Archive On"
onchange={() => {
// update_journal_entry();
}}
class:hidden={!$ae_loc.edit_mode}
class="input input-sm input-bordered w-auto border-none"
title="Set archive on datetime for archiving this journal entry"
/>
<!-- Set archive datetime (string) -->
<span class="flex flex-row flex-wrap items-center justify-center border border-gray-200 rounded-lg">
{#if obj_archive_on}
<!-- Button to clear the datetime -->
<button
type="button"
onclick={() => {
obj_archive_on = null;
// update_journal_entry();
}}
class:hidden={!$ae_loc.edit_mode}
class="btn btn-icon btn-icon-sm preset-tonal-warning hover:preset-filled-warning-500 transition *:hover:inline"
title="Clear the archive on datetime for this journal entry"
>
<X strokeWidth="2.5" color="red" />
<!-- <span class="hidden">Clear Archive</span> -->
</button>
{:else}
<!-- Button to set the datetime to now -->
<button
type="button"
onclick={() => {
// tmp_entry_obj.archive_on = new Date().toISOString();
// console.log('Archive on datetime set to now:', tmp_entry_obj.archive_on);
obj_archive_on = new Date().toISOString();
console.log('Archive on datetime set to now:', tmp_entry_obj.archive_on);
// update_journal_entry();
}}
class:hidden={!$ae_loc.edit_mode}
class="btn btn-icon btn-icon-sm preset-tonal-warning hover:preset-filled-warning-500 transition *:hover:inline"
title="Set the archive on datetime for this journal entry"
>
<Clock strokeWidth="2.5" color="blue" />
<!-- <span class="hidden">Set Archive</span> -->
</button>
{/if}
</span>
<input
type="datetime-local"
bind:value={obj_archive_on}
placeholder="Archive On"
onchange={() => {
// update_journal_entry();
}}
class:hidden={!$ae_loc.edit_mode}
class="input input-sm input-bordered w-auto border-none"
title="Set archive on datetime for archiving this journal entry"
/>
<!-- Set/unset hide (boolean) -->
<button
type="button"
onclick={() => {
obj_hide = !obj_hide;
update_journal_entry();
}}
class="btn btn-sm md:btn-md preset-tonal-warning hover:preset-filled-warning-500 transition"
title="Toggle visibility of this journal entry"
>
{#if obj_hide}
<EyeOff strokeWidth="1" color="red" class="inline-block" />
<span class="hidden md:inline">Hidden</span>
{:else}
<Eye strokeWidth="2.5" color="green" class="inline-block" />
<span class="hidden md:inline">Visible</span>
{/if}
</button>
{#if obj_archive_on}
<!-- Button to clear the datetime -->
<button
type="button"
onclick={() => {
obj_archive_on = null;
// update_journal_entry();
}}
class:hidden={!$ae_loc.edit_mode}
class="btn btn-icon btn-icon-sm preset-tonal-warning hover:preset-filled-warning-500 transition *:hover:inline"
title="Clear the archive on datetime for this journal entry"
>
<X strokeWidth="2.5" color="red" />
<!-- <span class="hidden">Clear Archive</span> -->
</button>
{:else}
<!-- Button to set the datetime to now -->
<button
type="button"
onclick={() => {
// tmp_entry_obj.archive_on = new Date().toISOString();
// console.log('Archive on datetime set to now:', tmp_entry_obj.archive_on);
obj_archive_on = new Date().toISOString();
console.log('Archive on datetime set to now:', tmp_entry_obj.archive_on);
// update_journal_entry();
}}
class:hidden={!$ae_loc.edit_mode}
class="btn btn-icon btn-icon-sm preset-tonal-warning hover:preset-filled-warning-500 transition *:hover:inline"
title="Set the archive on datetime for this journal entry"
>
<Clock strokeWidth="2.5" color="blue" />
<!-- <span class="hidden">Set Archive</span> -->
</button>
{/if}
</span>
<!-- Set/unset enable (boolean) -->
<button
type="button"
onclick={() => {
obj_enable = !obj_enable;
// update_journal_entry();
}}
class:hidden={!$ae_loc.administrator_access || !$ae_loc.edit_mode}
class="btn btn-sm md:btn-md preset-tonal-error hover:preset-filled-error-500 transition"
title="Toggle enable status of this journal entry"
>
{#if obj_enable}
<ShieldCheck strokeWidth="2.5" color="green" class="inline-block" />
<span class="hidden md:inline">Enabled</span>
{:else}
<ShieldMinus strokeWidth="1" color="red" class="inline-block" />
<span class="hidden md:inline">Disabled</span>
{/if}
</button>
<!-- Set/unset hide (boolean) -->
<button
type="button"
onclick={() => {
obj_hide = !obj_hide;
update_journal_entry();
}}
class="btn btn-sm md:btn-md preset-tonal-warning hover:preset-filled-warning-500 transition"
title="Toggle visibility of this journal entry"
>
{#if obj_hide}
<EyeOff strokeWidth="1" color="red" class="inline-block" />
<span class="hidden md:inline">Hidden</span>
{:else}
<Eye strokeWidth="2.5" color="green" class="inline-block" />
<span class="hidden md:inline">Visible</span>
{/if}
</button>
<!-- Delete journal entry -->
<button
type="button"
onclick={() => {
if (confirm(`Are you sure you want to delete this journal entry?`)) {
let delete_method = 'disable';
if ($ae_loc.administrator_access && $ae_loc.edit_mode) {
delete_method = 'delete';
}
journals_func
.delete_ae_obj_id__journal_entry({
api_cfg: $ae_api,
journal_entry_id: $lq__journal_entry_obj?.journal_entry_id,
method: delete_method, // 'delete', 'disable', 'hide'
log_lvl: log_lvl
})
.then(() => {
// Optionally, you can provide feedback to the user
alert('Journal entry deleted successfully!');
})
.catch((error: any) => {
console.error('Error deleting journal entry:', error);
alert('Failed to delete journal entry.');
})
.finally(() => {
$journals_slct.journal_id = null;
$journals_slct.journal_obj = null;
goto(`/journals/${$lq__journal_entry_obj?.journal_id}`);
});
}
}}
class:hidden={!$ae_loc.edit_mode}
class="btn btn-sm md:btn-md preset-tonal-error hover:preset-filled-error-500 transition"
title="Delete this journal entry"
>
{#if $ae_loc.administrator_access && $ae_loc.edit_mode}
<FileX strokeWidth="2.5" color="red" class="inline-block" />
<span class="hidden md:inline">Delete</span>
{:else}
<Trash2 strokeWidth="2.5" color="orange" class="inline-block" />
<span class="hidden md:inline">Remove</span>
{/if}
</button>
<!-- Set/unset enable (boolean) -->
<button
type="button"
onclick={() => {
obj_enable = !obj_enable;
// update_journal_entry();
}}
class:hidden={!$ae_loc.administrator_access || !$ae_loc.edit_mode}
class="btn btn-sm md:btn-md preset-tonal-error hover:preset-filled-error-500 transition"
title="Toggle enable status of this journal entry"
>
{#if obj_enable}
<ShieldCheck strokeWidth="2.5" color="green" class="inline-block" />
<span class="hidden md:inline">Enabled</span>
{:else}
<ShieldMinus strokeWidth="1" color="red" class="inline-block" />
<span class="hidden md:inline">Disabled</span>
{/if}
</button>
<span class="flex flex-row items-center justify-center text-sm text-gray-500">
{#if !$ae_loc.edit_mode}
<span class="">
{ae_util.iso_datetime_formatter(
$lq__journal_entry_obj?.created_on,
'datetime_iso_12_no_seconds'
)}
{$lq__journal_entry_obj?.updated_on
? ` | Last updated: ${ae_util.iso_datetime_formatter($lq__journal_entry_obj?.updated_on, 'datetime_iso_12_no_seconds')}`
: ''}
</span>
{:else}
<span class="">
{ae_util.iso_datetime_formatter($lq__journal_entry_obj?.created_on, 'datetime_iso_tz')}
{$lq__journal_entry_obj?.updated_on
? ` | Last updated: ${ae_util.iso_datetime_formatter($lq__journal_entry_obj?.updated_on, 'datetime_iso_tz')}`
: ''}
</span>
{/if}
</span>
<!-- Delete journal entry -->
<button
type="button"
onclick={() => {
if (confirm(`Are you sure you want to delete this journal entry?`)) {
let delete_method = 'disable';
if ($ae_loc.administrator_access && $ae_loc.edit_mode) {
delete_method = 'delete';
}
journals_func.delete_ae_obj_id__journal_entry({
api_cfg: $ae_api,
journal_entry_id: $lq__journal_entry_obj?.journal_entry_id,
method: delete_method, // 'delete', 'disable', 'hide'
log_lvl: log_lvl
}).then(() => {
// Optionally, you can provide feedback to the user
alert('Journal entry deleted successfully!');
}).catch((error: any) => {
console.error('Error deleting journal entry:', error);
alert('Failed to delete journal entry.');
}).finally(() => {
$journals_slct.journal_id = null;
$journals_slct.journal_obj = null;
goto(`/journals/${$lq__journal_entry_obj?.journal_id}`);
});
}
}}
class:hidden={!$ae_loc.edit_mode}
class="btn btn-sm md:btn-md preset-tonal-error hover:preset-filled-error-500 transition"
title="Delete this journal entry"
>
{#if ($ae_loc.administrator_access && $ae_loc.edit_mode)}
<FileX strokeWidth="2.5" color="red" class="inline-block" />
<span class="hidden md:inline">Delete</span>
{:else}
<Trash2 strokeWidth="2.5" color="orange" class="inline-block" />
<span class="hidden md:inline">Remove</span>
{/if}
</button>
<span class="flex flex-row items-center justify-center text-sm text-gray-500">
{#if !$ae_loc.edit_mode}
<span class="">
{ae_util.iso_datetime_formatter($lq__journal_entry_obj?.created_on, 'datetime_iso_12_no_seconds')}
{$lq__journal_entry_obj?.updated_on ?
` | Last updated: ${ae_util.iso_datetime_formatter($lq__journal_entry_obj?.updated_on, 'datetime_iso_12_no_seconds')}` : ''}
</span>
{:else}
<span class="">
{ae_util.iso_datetime_formatter($lq__journal_entry_obj?.created_on, 'datetime_iso_tz')}
{$lq__journal_entry_obj?.updated_on ?
` | Last updated: ${ae_util.iso_datetime_formatter($lq__journal_entry_obj?.updated_on, 'datetime_iso_tz')}` : ''}
</span>
{/if}
</span>
<!-- Select option list of Journals to choose from. This is used to assign the Journal Entry to a different Journal ID. -->
{#if $ae_loc.edit_mode && $lq__journal_obj_li?.length}
<div class="flex flex-row flex-wrap gap-2 items-center justify-start border border-gray-200 rounded-lg">
<SquareLibrary size="1em" class="mx-1"/>
<span class="text-sm text-gray-500 hidden sm:inline">
Journal:
</span>
<select
class="novi_btn btn btn-secondary btn-sm
<!-- Select option list of Journals to choose from. This is used to assign the Journal Entry to a different Journal ID. -->
{#if $ae_loc.edit_mode && $lq__journal_obj_li?.length}
<div
class="flex flex-row flex-wrap gap-2 items-center justify-start border border-gray-200 rounded-lg"
>
<SquareLibrary size="1em" class="mx-1" />
<span class="text-sm text-gray-500 hidden sm:inline"> Journal: </span>
<select
class="novi_btn btn btn-secondary btn-sm
preset-tonal-primary
hover:preset-filled-primary-500
transition
text-xs
border-none
"
bind:value={tmp_entry_obj.journal_id}
onchange={(event) => {
tmp_entry_obj.journal_id = event.target.value;
console.log('Selected journal:', tmp_entry_obj.journal_id);
if (confirm(`Are you sure you want to change the journal for this entry?`)) {
change_journal_id();
}
}}
title="Select a different journal for this entry"
>
<option value="">Select Journal</option>
{#each $lq__journal_obj_li as journal}
<option value={journal.journal_id}
title={`Journal: ${journal.name}`}
>
{journal.name}
</option>
{/each}
</select>
</div>
{/if}
bind:value={tmp_entry_obj.journal_id}
onchange={(event) => {
tmp_entry_obj.journal_id = event.target.value;
console.log('Selected journal:', tmp_entry_obj.journal_id);
if (confirm(`Are you sure you want to change the journal for this entry?`)) {
change_journal_id();
}
}}
title="Select a different journal for this entry"
>
<option value="">Select Journal</option>
{#each $lq__journal_obj_li as journal}
<option value={journal.journal_id} title={`Journal: ${journal.name}`}>
{journal.name}
</option>
{/each}
</select>
</div>
{/if}
</section>

View File

@@ -1,65 +0,0 @@
<script lang="ts">
/** @type {import('./$types').LayoutData} */
let { children } = $props();
import { ae_loc, ae_sess, ae_api, slct } from '$lib/stores/ae_stores';
// import { notes_loc, notes_slct, notes_trigger } from '$lib/ae_journals/ae_journals_stores';
</script>
<svelte:head>
<title>Notes - {$notes_loc.title ?? 'Æ loading...'}</title>
</svelte:head>
<div class="ae_notes">
<nav class="submenu flex flex-row justify-center gap-1">
<a href="/" class="btn btn-sm preset-tonal-success border border-success-500 hover:preset-filled-success-500">Home</a>
<!-- <a href="/about" class="btn btn-sm">About</a> -->
<!-- <a href="/settings" class="btn btn-sm">Settings</a> -->
<button
onclick={() => {
// Clear the local and session storage. Clearing the localStorage will force it to be re-created.
localStorage.clear();
sessionStorage.clear();
// Clear Indexed DB as well
indexedDB.deleteDatabase('ae_core_db');
indexedDB.deleteDatabase('ae_notes_db');
// This does not seem to work fast enough or something?
goto('/', {invalidateAll: true});
// The page does usually seem to reload correctly?
window.location.reload(); // true only works with Firefox
// alert('Local and Session Storage cleared and Indexed DBs deleted. You will probably want to refresh the page.');
}}
class="btn btn-sm preset-tonal-success border border-success-500 hover:preset-filled-success-500"
title="Clear App Data & Settings - Reload: Clear the browser storage for this site"
>
<!-- <span class="fas fa-eraser mx-1"></span> -->
<span class="fas fa-sync mx-1"></span>
Clear & Reload
</button>
</nav>
<section class="status flex flex-col justify-center items-center gap-1">
{#if $ae_loc.administrator_access}
<h3 class="h4">Administrator Access - Technical Support</h3>
<p>You are accessing the notes module with "administrator" level permissions.</p>
{:else if $ae_loc.trusted_access}
<h3 class="h4">Trusted Access - Staff</h3>
<p>You are accessing the notes module with "trusted" level permissions.</p>
{:else if !$ae_loc.trusted_access}
<h3 class="h4">Restricted Access</h3>
<p>You are accessing to the notes module is limited</p>
{/if}
</section>
<section class="main_content outline">
{@render children?.()}
</section>
</div>

View File

@@ -1,34 +0,0 @@
/** @type {import('./$types').LayoutLoad} */
// import { error } from '@sveltejs/kit';
import { browser } from '$app/environment';
// import { api } from '$lib/api';
// import { ae_loc, ae_sess, ae_api, slct, slct_trigger } from '$lib/ae_stores';
// import { core_func } from '$lib/ae_core/ae_core_functions';
// import type { key_val } from '$lib/ae_stores';
export async function load({ fetch, params, parent, route, url }) {
let log_lvl: number = 0;
let parent_data = await parent();
let account_id = parent_data.account_id;
let ae_acct = parent_data[account_id];
if (log_lvl) {
console.log(`ae_acct = `, ae_acct);
}
// let ae_params = {};
if (browser) {
}
parent_data[account_id] = ae_acct;
return parent_data;
}

View File

@@ -1,49 +1,87 @@
<script lang="ts">
interface Props {
log_lvl?: number;
show?: boolean;
tab?: string;
}
interface Props {
log_lvl?: number;
show?: boolean;
tab?: string;
}
let {
log_lvl = $bindable(0),
show = $bindable(true),
tab = $bindable('form'), // form, local_json, session_json
}: Props = $props();
let {
log_lvl = $bindable(0),
show = $bindable(true),
tab = $bindable('form') // form, local_json, session_json
}: Props = $props();
import {
ArrowDown01, ArrowDown10, ArrowDownUp,
BetweenVerticalEnd, BetweenVerticalStart,
BookHeart, BookImage, Bookmark, BookOpenText, BriefcaseBusiness,
Check, Copy,
Expand, Eye, EyeOff,
Flag, FlagOff, FilePlus, Fingerprint,
Globe,
Library,
MessageSquareWarning, Minus,
Notebook,
Pencil, Plus,
RefreshCcw, RemoveFormatting,
SquareLibrary,
Shapes, Share2, ShieldCheck, ShieldMinus, Siren, Skull,
Tags, Target, ToggleLeft, ToggleRight, Trash2, TypeOutline,
X
} from '@lucide/svelte';
import { Modal } from 'flowbite-svelte';
import { ae_snip, ae_loc, ae_sess, ae_api, ae_trig, slct, slct_trigger } from '$lib/stores/ae_stores';
import { journals_loc, journals_sess, journals_slct, journals_prom, journals_trig } from '$lib/ae_journals/ae_journals_stores';
import E_app_codemirror_v5 from '$lib/app_components/e_app_codemirror_v5.svelte';
import {
ArrowDown01,
ArrowDown10,
ArrowDownUp,
BetweenVerticalEnd,
BetweenVerticalStart,
BookHeart,
BookImage,
Bookmark,
BookOpenText,
BriefcaseBusiness,
Check,
Copy,
Expand,
Eye,
EyeOff,
Flag,
FlagOff,
FilePlus,
Fingerprint,
Globe,
Library,
MessageSquareWarning,
Minus,
Notebook,
Pencil,
Plus,
RefreshCcw,
RemoveFormatting,
SquareLibrary,
Shapes,
Share2,
ShieldCheck,
ShieldMinus,
Siren,
Skull,
Tags,
Target,
ToggleLeft,
ToggleRight,
Trash2,
TypeOutline,
X
} from '@lucide/svelte';
import { Modal } from 'flowbite-svelte';
import {
ae_snip,
ae_loc,
ae_sess,
ae_api,
ae_trig,
slct,
slct_trigger
} from '$lib/stores/ae_stores';
import {
journals_loc,
journals_sess,
journals_slct,
journals_prom,
journals_trig
} from '$lib/ae_journals/ae_journals_stores';
import E_app_codemirror_v5 from '$lib/app_components/e_app_codemirror_v5.svelte';
</script>
<Modal
bind:open={show}
autoclose={false}
placement="top-center"
size="xl"
class="
bind:open={show}
autoclose={false}
placement="top-center"
size="xl"
class="
top-center
relative
flex flex-col
@@ -53,348 +91,320 @@ import E_app_codemirror_v5 from '$lib/app_components/e_app_codemirror_v5.svelte'
border border-orange-300 dark:border-orange-700 rounded-lg
shadow-xl
"
headerClass="
headerClass="
flex flex-row gap-2 items-center justify-between
w-full
bg-orange-100 dark:bg-orange-900
"
footerClass="
footerClass="
flex flex-row gap-2 items-center justify-center
w-full
bg-orange-100 dark:bg-orange-900
"
>
>
{#snippet header()}
<h3>
<span class="text-base font-semibold">
<span class="text-primary-500">
<BookOpenText class="inline-block mr-1" />
</span>
&AElig; Journals Settings:
</span>
{$journals_loc?.name ?? '-- not set --'}
</h3>
{/snippet}
{#snippet header()}
<h3>
<span class="text-base font-semibold">
<span class="text-primary-500">
<BookOpenText class="inline-block mr-1" />
</span>
&AElig; Journals Settings:
</span>
{$journals_loc?.name ?? '-- not set --'}
</h3>
{/snippet}
<div class="modal h-full md:pb-24">
<div class="modal-box space-y-2">
<!-- Menu to toggle between viewing JSON and the form view -->
<div
class="flex flex-row gap-1 items-center justify-center"
>
<button
type="button"
class:preset-outlined-surface-200-800={tab === 'form'}
class="
<div class="modal h-full md:pb-24">
<div class="modal-box space-y-2">
<!-- Menu to toggle between viewing JSON and the form view -->
<div class="flex flex-row gap-1 items-center justify-center">
<button
type="button"
class:preset-outlined-surface-200-800={tab === 'form'}
class="
btn btn-sm
preset-outlined-surface-50-950
transition-all
"
onclick={() =>
tab = 'form'
}
>
<span class="fas fa-cog mr-1"></span>
Config
</button>
<button
type="button"
class:preset-outlined-surface-200-800={tab === 'local_json'}
class="
onclick={() => (tab = 'form')}
>
<span class="fas fa-cog mr-1"></span>
Config
</button>
<button
type="button"
class:preset-outlined-surface-200-800={tab === 'local_json'}
class="
btn btn-sm
preset-outlined-surface-50-950
transition-all
"
onclick={() =>
tab = 'local_json'
}
>
<span class="fas fa-code mr-1"></span>
Local JSON
</button>
<button
type="button"
class:preset-outlined-surface-200-800={tab === 'session_json'}
class="
onclick={() => (tab = 'local_json')}
>
<span class="fas fa-code mr-1"></span>
Local JSON
</button>
<button
type="button"
class:preset-outlined-surface-200-800={tab === 'session_json'}
class="
btn btn-sm
preset-outlined-surface-50-950
transition-all
"
onclick={() =>
tab = 'session_json'
} >
<span class="fas fa-code mr-1"></span>
Session JSON
</button>
onclick={() => (tab = 'session_json')}
>
<span class="fas fa-code mr-1"></span>
Session JSON
</button>
</div>
</div>
<!-- Section for the configuration form -->
<div class:hidden={tab !== 'form'} class="flex flex-col gap-1 items-start justify-start">
<!-- <h2 class="font-semibold"></h2> -->
<!-- Section for the configuration form -->
<div
class:hidden={tab !== 'form'}
class="flex flex-col gap-1 items-start justify-start"
>
<div class="w-full space-y-2 p-2 border-t border-surface-100-900">
<h2 class="font-semibold">$journals_loc:</h2>
<h3 class="font-semibold">Date and Time:</h3>
<!-- <h2 class="font-semibold"></h2> -->
<!-- datetime_format - default 'datetime_12_long'; select options -->
<label class="flex items-center justify-start gap-1">
DateTime Format:
<select
bind:value={$journals_loc.datetime_format}
class="select select-sm select-bordered w-full max-w-xs p-1"
>
<option value="datetime_12_short">MMM D, YY hh:mm A</option>
<option value="datetime_12_long">MMMM D, YYYY hh:mm A</option>
<option value="datetime_short">MMM D, YY HH:mm</option>
<option value="datetime_long">MMMM D, YYYY HH:mm</option>
<option value="datetime_us">US (MM/DD/YYYY hh:mm:ss A)</option>
<option value="datetime_iso">ISO (YYYY-MM-DD HH:mm:ss)</option>
</select>
</label>
<div class="w-full space-y-2 p-2 border-t border-surface-100-900">
<h2 class="font-semibold">$journals_loc:</h2>
<h3 class="font-semibold">Date and Time:</h3>
<!-- time_format - default 'time_12_short'; select options -->
<label class="flex items-center justify-start gap-1">
Time Format:
<select
bind:value={$journals_loc.time_format}
class="select select-sm select-bordered w-full max-w-xs p-1"
>
<option value="time_12_short">12-hour short (e.g., 3:30 PM)</option>
<option value="time_12_long">12-hour long (e.g., 3:30:45 PM)</option>
<option value="time_short">24-hour short (e.g., 15:30)</option>
<option value="time_long">24-hour long (e.g., 15:30:45)</option>
</select>
</label>
<!-- datetime_format - default 'datetime_12_long'; select options -->
<label class="flex items-center justify-start gap-1">
DateTime Format:
<select
bind:value={$journals_loc.datetime_format}
class="select select-sm select-bordered w-full max-w-xs p-1"
>
<option value="datetime_12_short">MMM D, YY hh:mm A</option>
<option value="datetime_12_long">MMMM D, YYYY hh:mm A</option>
<option value="datetime_short">MMM D, YY HH:mm</option>
<option value="datetime_long">MMMM D, YYYY HH:mm</option>
<option value="datetime_us">US (MM/DD/YYYY hh:mm:ss A)</option>
<option value="datetime_iso">ISO (YYYY-MM-DD HH:mm:ss)</option>
</select>
</label>
<!-- time_hours 12 or 24; toggle -->
<div class="flex flex-row gap-2 items-center justify-start">
<label class="flex flex-row gap-1 items-center justify-start">
12
<input
type="checkbox"
checked={$journals_loc.time_hours == 12}
value={12}
onchange={() => {
$journals_loc.time_hours = 12;
}}
class="checkbox checkbox-sm"
/>
</label>
<label class="flex flex-row gap-1 items-center justify-start">
24
<input
type="checkbox"
checked={$journals_loc.time_hours == 24}
value={24}
onchange={() => {
$journals_loc.time_hours = 24;
}}
class="checkbox checkbox-sm"
/>
</label>
<span class="text-sm">
Time Format: <span class="font-semibold">{$journals_loc.time_hours}-hour</span>
</span>
</div>
<!-- time_format - default 'time_12_short'; select options -->
<label class="flex items-center justify-start gap-1">
Time Format:
<select
bind:value={$journals_loc.time_format}
class="select select-sm select-bordered w-full max-w-xs p-1"
>
<option value="time_12_short">12-hour short (e.g., 3:30 PM)</option>
<option value="time_12_long">12-hour long (e.g., 3:30:45 PM)</option>
<option value="time_short">24-hour short (e.g., 15:30)</option>
<option value="time_long">24-hour long (e.g., 15:30:45)</option>
</select>
</label>
<h3 class="font-semibold">LLM AI:</h3>
<!-- time_hours 12 or 24; toggle -->
<div class="flex flex-row gap-2 items-center justify-start">
<label class="flex flex-row gap-1 items-center justify-start">
12
<input
type="checkbox"
checked={$journals_loc.time_hours == 12}
value={12}
onchange={() => {
$journals_loc.time_hours = 12;
}}
class="checkbox checkbox-sm"
/>
<button
type="button"
class="btn btn-sm preset-outlined-primary-400-600"
onclick={() => {
$journals_loc.llm__api_base_url =
$ae_loc.site_cfg_json?.llm__api_base_url ?? 'https://ai.dgrzone.com/api';
$journals_loc.llm__api_model =
$ae_loc.site_cfg_json?.llm__api_model ?? 'dgrzone-deepseek-8b-quick';
$journals_loc.llm__api_token = $ae_loc.site_cfg_json?.llm__api_token ?? '';
$journals_loc.llm__api_dangerous_browser =
$ae_loc.site_cfg_json?.llm__api_dangerous_browser ?? false;
$journals_loc.entry.llm__system_prompt =
$ae_loc.site_cfg_json?.llm__system_prompt ?? '';
}}
>
<Copy class="inline-block mr-1" />
LLM from Site Cfg
</button>
</label>
<label class="flex flex-row gap-1 items-center justify-start">
24
<input
type="checkbox"
checked={$journals_loc.time_hours == 24}
value={24}
onchange={() => {
$journals_loc.time_hours = 24;
}}
class="checkbox checkbox-sm"
/>
<!-- llm__api_base_url - default 'https://ai.dgrzone.com/api'; input url -->
<label class="flex items-center justify-start gap-1">
LLM API Base URL:
<input
type="text"
bind:value={$journals_loc.llm__api_base_url}
placeholder="LLM API Base URL"
class="input input-sm input-bordered w-full max-w-xs"
/>
</label>
</label>
<span class="text-sm">
Time Format: <span class="font-semibold">{$journals_loc.time_hours}-hour</span>
</span>
</div>
<!-- llm__api_model - default 'dgrzone-deepseek-8b-quick'; input text -->
<label class="flex items-center justify-start gap-1">
LLM API Model:
<input
type="text"
bind:value={$journals_loc.llm__api_model}
placeholder="LLM API Model"
class="input input-sm input-bordered w-full max-w-xs"
/>
</label>
<h3 class="font-semibold">LLM AI:</h3>
<!-- llm__api_token; input text -->
<label class="flex items-center justify-start gap-1">
LLM API Token:
<input
type="text"
bind:value={$journals_loc.llm__api_token}
placeholder="LLM API Token"
class="input input-sm input-bordered w-full max-w-4xl"
/>
</label>
<button
type="button"
class="btn btn-sm preset-outlined-primary-400-600"
onclick={() => {
$journals_loc.llm__api_base_url = $ae_loc.site_cfg_json?.llm__api_base_url ?? 'https://ai.dgrzone.com/api';
$journals_loc.llm__api_model = $ae_loc.site_cfg_json?.llm__api_model ?? 'dgrzone-deepseek-8b-quick';
$journals_loc.llm__api_token = $ae_loc.site_cfg_json?.llm__api_token ?? '';
$journals_loc.llm__api_dangerous_browser = $ae_loc.site_cfg_json?.llm__api_dangerous_browser ?? false;
$journals_loc.entry.llm__system_prompt = $ae_loc.site_cfg_json?.llm__system_prompt ?? '';
<!-- llm__api_dangerous_browser - default false; checkbox -->
<label class="flex flex-row gap-1 items-center justify-start">
<input
type="checkbox"
bind:checked={$journals_loc.llm__api_dangerous_browser}
class="checkbox checkbox-sm"
/>
<span class="text-sm"> LLM API Dangerous Browser </span>
</label>
</div>
<div class="w-full space-y-2 p-2 border-t border-surface-100-900">
<h2 class="font-semibold">$journals_loc?.entry:</h2>
}}
>
<Copy class="inline-block mr-1" />
LLM from Site Cfg
</button>
<!-- entry > ai__system_prompt - textarea -->
<!-- <div class="h-16"> -->
<!-- llm__api_base_url - default 'https://ai.dgrzone.com/api'; input url -->
<label class="flex items-center justify-start gap-1">
LLM API Base URL:
<input
type="text"
bind:value={$journals_loc.llm__api_base_url}
placeholder="LLM API Base URL"
class="input input-sm input-bordered w-full max-w-xs"
/>
</label>
<!-- </div> -->
<!-- llm__api_model - default 'dgrzone-deepseek-8b-quick'; input text -->
<label class="flex items-center justify-start gap-1">
LLM API Model:
<input
type="text"
bind:value={$journals_loc.llm__api_model}
placeholder="LLM API Model"
class="input input-sm input-bordered w-full max-w-xs"
/>
</label>
<!-- entry > llm__max_tokens - number -->
<label class="flex items-center justify-start gap-1">
LLM Max Tokens:
<input
type="number"
bind:value={$journals_loc.entry.llm__max_tokens}
placeholder="LLM Max Tokens"
class="input input-sm input-bordered w-full max-w-xs"
/>
</label>
<!-- llm__api_token; input text -->
<label class="flex items-center justify-start gap-1">
LLM API Token:
<input
type="text"
bind:value={$journals_loc.llm__api_token}
placeholder="LLM API Token"
class="input input-sm input-bordered w-full max-w-4xl"
/>
</label>
<!-- entry > llm__temperature - number -->
<label class="flex items-center justify-start gap-1">
LLM Temperature:
<input
type="number"
step="0.01"
min="0"
max="1"
bind:value={$journals_loc.entry.llm__temperature}
placeholder="LLM Temperature"
class="input input-sm input-bordered w-full max-w-xs"
/>
</label>
<!-- llm__api_dangerous_browser - default false; checkbox -->
<label class="flex flex-row gap-1 items-center justify-start">
<input
type="checkbox"
bind:checked={$journals_loc.llm__api_dangerous_browser}
class="checkbox checkbox-sm"
/>
<span class="text-sm">
LLM API Dangerous Browser
</span>
</label>
</div>
<div class="w-full space-y-2 p-2 border-t border-surface-100-900">
<h2 class="font-semibold">$journals_loc?.entry:</h2>
<!-- entry > ai__system_prompt - textarea -->
<!-- <div class="h-16"> -->
<!-- </div> -->
<!-- entry > llm__max_tokens - number -->
<label class="flex items-center justify-start gap-1">
LLM Max Tokens:
<input
type="number"
bind:value={$journals_loc.entry.llm__max_tokens}
placeholder="LLM Max Tokens"
class="input input-sm input-bordered w-full max-w-xs"
/>
</label>
<!-- entry > llm__temperature - number -->
<label class="flex items-center justify-start gap-1">
LLM Temperature:
<input
type="number"
step="0.01"
min="0"
max="1"
bind:value={$journals_loc.entry.llm__temperature}
placeholder="LLM Temperature"
class="input input-sm input-bordered w-full max-w-xs"
/>
</label>
<label class="flex flex-col items-start justify-start gap-1 h-24">
LLM System Prompt for Journal Entry summarization:
<E_app_codemirror_v5
editable={true}
readonly={false}
content={$journals_loc?.entry?.llm__system_prompt}
bind:new_content={$journals_loc.entry.llm__system_prompt}
show_line_numbers={false}
placeholder="LLM System Prompt"
class="
<label class="flex flex-col items-start justify-start gap-1 h-24">
LLM System Prompt for Journal Entry summarization:
<E_app_codemirror_v5
editable={true}
readonly={false}
content={$journals_loc?.entry?.llm__system_prompt}
bind:new_content={$journals_loc.entry.llm__system_prompt}
show_line_numbers={false}
placeholder="LLM System Prompt"
class="
p-1
preset-outlined-success-400-600
shadow-lg rounded-lg
"
on:change={(e) => {
$journals_loc.entry.llm__system_prompt = e.detail;
}}
/>
</label>
on:change={(e) => {
$journals_loc.entry.llm__system_prompt = e.detail;
}}
/>
</label>
<button
type="button"
class="btn btn-sm preset-outlined-primary-400-600"
onclick={() => {
let default_system_prompt = 'Summarize the following journal entry content in a concise manner, focusing on key points and insights.';
$journals_loc.entry.llm__system_prompt = default_system_prompt;
}}
>
<RefreshCcw class="inline-block mr-1" />
Reset to Journal Entry System Prompt
</button>
<button
type="button"
class="btn btn-sm preset-outlined-primary-400-600"
onclick={() => {
let default_system_prompt =
'Summarize the following journal entry content in a concise manner, focusing on key points and insights.';
$journals_loc.entry.llm__system_prompt = default_system_prompt;
}}
>
<RefreshCcw class="inline-block mr-1" />
Reset to Journal Entry System Prompt
</button>
</div>
</div>
</div>
</div>
<!-- Section for viewing (and direct editing???) the raw localStorage JSON configuration -->
<div
class:hidden={tab !== 'local_json'}
class=""
>
<E_app_codemirror_v5
editable={false}
readonly={true}
content={JSON.stringify($journals_loc, null, 2)}
show_line_numbers={false}
placeholder=""
class="
<!-- Section for viewing (and direct editing???) the raw localStorage JSON configuration -->
<div class:hidden={tab !== 'local_json'} class="">
<E_app_codemirror_v5
editable={false}
readonly={true}
content={JSON.stringify($journals_loc, null, 2)}
show_line_numbers={false}
placeholder=""
class="
p-1
preset-outlined-surface-100-900
rounded-lg
"
/>
<!-- <pre class="text-wrap">
/>
<!-- <pre class="text-wrap">
{JSON.stringify($journals_loc, null, 2)}
</pre> -->
</div>
</div>
<!-- Section for viewing (and direct editing???) the raw sessionStorage JSON configuration -->
<div
class:hidden={tab !== 'session_json'}
class=""
>
<E_app_codemirror_v5
editable={false}
readonly={true}
content={JSON.stringify($journals_sess, null, 2)}
show_line_numbers={false}
placeholder=""
class="
<!-- Section for viewing (and direct editing???) the raw sessionStorage JSON configuration -->
<div class:hidden={tab !== 'session_json'} class="">
<E_app_codemirror_v5
editable={false}
readonly={true}
content={JSON.stringify($journals_sess, null, 2)}
show_line_numbers={false}
placeholder=""
class="
p-1
preset-outlined-surface-100-900
rounded-lg
"
/>
<!-- <pre class="text-wrap">
/>
<!-- <pre class="text-wrap">
{JSON.stringify($journals_sess, null, 2)}
</pre> -->
</div>
</div>
</div>
</div>
</div>
</div>
{#snippet footer()}
<button
class="btn btn-sm btn-outline btn-primary"
onclick={() => show = false}
>
<X class="inline-block mr-1" />
Close
</button>
{/snippet}
</Modal>
{#snippet footer()}
<button class="btn btn-sm btn-outline btn-primary" onclick={() => (show = false)}>
<X class="inline-block mr-1" />
Close
</button>
{/snippet}
</Modal>