Wrapping up for the night at 4 AM. Made lots of progress with the Journals module. Should have saved more often.
This commit is contained in:
330
src/routes/journals/[journal_id]/+page.svelte
Normal file
330
src/routes/journals/[journal_id]/+page.svelte
Normal file
@@ -0,0 +1,330 @@
|
||||
<script lang="ts">
|
||||
/** @type {import('./$types').PageData} */
|
||||
let log_lvl: number = 1;
|
||||
|
||||
// *** Import Svelte specific
|
||||
import { browser } from '$app/environment';
|
||||
|
||||
// *** 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/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_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_id_edit from './ae_journals_comp__journal_entry_obj_id_edit.svelte';
|
||||
|
||||
interface Props {
|
||||
data: any;
|
||||
}
|
||||
|
||||
let { data }: Props = $props();
|
||||
|
||||
// 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];
|
||||
if (log_lvl) {
|
||||
console.log(`ae_acct = `, ae_acct);
|
||||
}
|
||||
|
||||
// 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 () => {
|
||||
if (log_lvl) {
|
||||
console.log(`lq__journal_obj: journal_id = ${$journals_slct?.journal_id}`);
|
||||
}
|
||||
let results = await db_journals.journal
|
||||
.get($journals_slct?.journal_id ?? ''); // null or undefined does not reset things like '' does
|
||||
|
||||
return results;
|
||||
}));
|
||||
|
||||
let lq__journal_entry_obj_li = $derived(liveQuery(async () => {
|
||||
if (log_lvl) {
|
||||
console.log(`$lq__journal_obj.cfg_json = `, $lq__journal_obj?.cfg_json);
|
||||
}
|
||||
if ($lq__journal_obj?.cfg_json?.entry_group_sort === 'DESC') {
|
||||
let 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');
|
||||
|
||||
return results;
|
||||
} else {
|
||||
console.log(`lq__journal_entry_obj_li - default query using journal_id: ${$journals_slct?.journal_id}`);
|
||||
let 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('updated_on');
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
}));
|
||||
|
||||
// let lq__journal_entry_obj = $derived(liveQuery(async () => {
|
||||
// if (log_lvl) {
|
||||
// console.log(`lq__journal_entry_obj: journal_entry_id = ${$journals_slct?.journal_entry_id}`);
|
||||
// }
|
||||
// if ($journals_slct.journal_entry_id) {
|
||||
// let results = await db_journals.journal_entry
|
||||
// .get($journals_slct.journal_entry_id); // null or undefined does not reset things like '' does
|
||||
|
||||
// return results;
|
||||
// }
|
||||
// // const results = await db_journals.journal_entry
|
||||
// // .get($journals_slct.journal_entry_id); // null or undefined does not reset things like '' does
|
||||
|
||||
// // return results;
|
||||
// }));
|
||||
|
||||
|
||||
$effect(() => {
|
||||
if ($journals_trig.journal_entry_li) {
|
||||
$journals_trig.journal_entry_li = false;
|
||||
|
||||
if (log_lvl) {
|
||||
console.log(`Triggered: $journals_trig.journal_entry_li`);
|
||||
}
|
||||
|
||||
if ($journals_loc.qry__enabled !== 'all' || $journals_loc.qry__hidden !== 'all') {
|
||||
console.log(`Deleting disabled or hidden journal entry.`);
|
||||
// let results = db_journals.journal_entry
|
||||
// .where('enable')
|
||||
// .notEqual(true)
|
||||
// .delete();
|
||||
let results = db_journals.journal_entry
|
||||
.clear();
|
||||
console.log(`Deleted ${results} disabled journal entry.`);
|
||||
|
||||
}
|
||||
// if ($journals_loc.qry__hidden !== 'all') {
|
||||
// console.log(`Deleting hidden journal entry.`);
|
||||
// let results = db_journals.journal_entry
|
||||
// .clear();
|
||||
// console.log(`Deleted ${results} hidden journal entry.`);
|
||||
|
||||
// }
|
||||
// let results = db_journals.journal_entry
|
||||
// .where('enable')
|
||||
// .equals('false')
|
||||
// .delete();
|
||||
// console.log(`Deleted ${results} disabled journal entry.`);
|
||||
|
||||
$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,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
if (browser) {
|
||||
console.log('Browser environment detected.');
|
||||
|
||||
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>
|
||||
</svelte:head>
|
||||
|
||||
|
||||
<section
|
||||
class="
|
||||
ae_journals__bb
|
||||
container h-full mx-auto
|
||||
flex flex-col gap-1
|
||||
py-1 px-2 pb-16
|
||||
items-center
|
||||
min-w-full
|
||||
max-w-max
|
||||
"
|
||||
>
|
||||
|
||||
<!-- <h1>Journals {$lq__journal_obj?.name} - {$lq__journal_entry_obj_li?.length}</h1> -->
|
||||
|
||||
<a href="/journals" class="novi_btn btn btn-secondary btn-sm
|
||||
variant-ghost-tertiary
|
||||
hover:variant-filled-tertiary
|
||||
transition
|
||||
">
|
||||
<!-- <span class="fas fa-arrow-left m-1"></span> Back to Journals -->
|
||||
<span class="fas fa-times m-1"></span> View Other Journals
|
||||
</a>
|
||||
|
||||
|
||||
<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_entry_obj_li={lq__journal_entry_obj_li}
|
||||
/>
|
||||
{:else}
|
||||
<p>No journal entry available to show.</p>
|
||||
{/if}
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
|
||||
<!-- Modal: Journal edit ID -->
|
||||
<Modal
|
||||
title="{$lq__journal_obj?.name} - {$lq__journal_obj?.id}"
|
||||
bind:open={$journals_sess.show__modal_edit__journal_id}
|
||||
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"
|
||||
>
|
||||
|
||||
{#snippet header()}
|
||||
|
||||
<div class="flex flex-row items-center justify-between w-full">
|
||||
<h3 class="text-lg font-semibold">
|
||||
{#if $ae_loc.trusted_access}
|
||||
<!-- <div class="ae_options"> -->
|
||||
<button
|
||||
onclick={() => {
|
||||
// const url = new URL(location);
|
||||
// url.searchParams.set('event_id', $lq__journal_obj?.event_id_random);
|
||||
// history.pushState({}, '', url);
|
||||
|
||||
$journals_sess.show__modal_view__journal_id = $journals_slct.journal_id;
|
||||
$journals_sess.show__modal_edit__journal_id = false;
|
||||
}}
|
||||
class="novi_btn btn btn-sm variant-ghost-warning hover:variant-filled-warning transition"
|
||||
title={`View meeting: ${$lq__journal_obj?.name}`}
|
||||
>
|
||||
<span class="fas fa-eye m-1"></span> View
|
||||
</button>
|
||||
<!-- </div> -->
|
||||
{/if}
|
||||
|
||||
<span class="text-sm text-gray-500">
|
||||
Edit Journal:
|
||||
</span>
|
||||
{$lq__journal_obj?.name}
|
||||
</h3>
|
||||
</div>
|
||||
|
||||
|
||||
{/snippet}
|
||||
|
||||
<!-- <Journal_obj_id_edit
|
||||
lq__journal_obj={lq__journal_obj}
|
||||
/> -->
|
||||
|
||||
|
||||
<!-- <svelte:fragment slot="footer">
|
||||
<div class="text-center w-full">
|
||||
<button
|
||||
type="button"
|
||||
on:click={() => {
|
||||
console.log('Close modal');
|
||||
$journals_sess.recovery_meetings.show__modal_edit__journal_id = false;
|
||||
}}
|
||||
class="btn btn-sm variant-soft-warning hover:variant-ghost-warning"
|
||||
>
|
||||
<span class="fas fa-times mx-1"></span>
|
||||
Close
|
||||
</button>
|
||||
</div>
|
||||
</svelte:fragment> -->
|
||||
|
||||
</Modal>
|
||||
|
||||
|
||||
<!-- Modal: Journal Content edit ID -->
|
||||
<!-- <Modal
|
||||
bind:open={$journals_sess.show__modal_edit__journal_entry_id}
|
||||
title="{$lq__journal_entry_obj?.name ?? 'New Journal Content'} - {$lq__journal_entry_obj?.id ?? 'Not Saved Yet'}"
|
||||
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"
|
||||
>
|
||||
|
||||
{#snippet header()}
|
||||
|
||||
<div class="flex flex-row items-center justify-between w-full">
|
||||
<h3 class="text-lg font-semibold">
|
||||
{#if $ae_loc.trusted_access}
|
||||
|
||||
<button
|
||||
onclick={() => {
|
||||
// const url = new URL(location);
|
||||
// url.searchParams.set('event_id', $lq__journal_entry_obj?.event_id_random);
|
||||
// history.pushState({}, '', url);
|
||||
|
||||
$journals_sess.show__modal_view__journal_entry_id = $journals_slct.journal_entry_id;
|
||||
$journals_sess.show__modal_edit__journal_entry_id = false;
|
||||
}}
|
||||
class="novi_btn btn btn-sm variant-ghost-warning hover:variant-filled-warning transition"
|
||||
title={`View meeting: ${$lq__journal_entry_obj?.name}`}
|
||||
>
|
||||
<span class="fas fa-eye m-1"></span> View
|
||||
</button>
|
||||
{/if}
|
||||
|
||||
<span class="text-sm text-gray-500">
|
||||
Edit Journal Content:
|
||||
</span>
|
||||
{$lq__journal_entry_obj?.name ?? 'New Journal Content'}
|
||||
</h3>
|
||||
</div>
|
||||
|
||||
|
||||
{/snippet}
|
||||
|
||||
|
||||
</Modal> -->
|
||||
|
||||
|
||||
<!-- Modal: Journal Content ID media player -->
|
||||
<!-- {#if $journals_slct.journal_entry_id && $journals_sess.show__modal_view__journal_entry_id}
|
||||
<Modal_media_player
|
||||
lq__journal_entry_obj={lq__journal_entry_obj}
|
||||
/>
|
||||
{/if} -->
|
||||
84
src/routes/journals/[journal_id]/+page.ts
Normal file
84
src/routes/journals/[journal_id]/+page.ts
Normal file
@@ -0,0 +1,84 @@
|
||||
/** @type {import('./$types').PageLoad} */
|
||||
import { error } from '@sveltejs/kit';
|
||||
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, {
|
||||
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 and presentations.
|
||||
data[account_id] = ae_acct;
|
||||
|
||||
return data;
|
||||
}
|
||||
Reference in New Issue
Block a user