From d8edd658b03b127073057eca0133679df1c7f68b Mon Sep 17 00:00:00 2001 From: Scott Idem Date: Tue, 20 Aug 2024 21:00:03 -0400 Subject: [PATCH] Adding a new notes module I guess. Because why not. --- src/lib/ae_notes_functions.ts | 14 +++ src/lib/ae_notes_stores.ts | 70 ++++++++++++ src/lib/db_events.ts | 3 +- src/lib/db_notes.ts | 147 +++++++++++++++++++++++++ src/routes/notes/+layout.svelte | 163 ++++++++++++++++++++++++++++ src/routes/notes/+layout.ts | 74 +++++++++++++ src/routes/notes/+page.svelte | 186 ++++++++++++++++++++++++++++++++ src/routes/notes/+page.ts | 38 +++++++ 8 files changed, 693 insertions(+), 2 deletions(-) create mode 100644 src/lib/ae_notes_functions.ts create mode 100644 src/lib/ae_notes_stores.ts create mode 100644 src/lib/db_notes.ts create mode 100644 src/routes/notes/+layout.svelte create mode 100644 src/routes/notes/+layout.ts create mode 100644 src/routes/notes/+page.svelte create mode 100644 src/routes/notes/+page.ts diff --git a/src/lib/ae_notes_functions.ts b/src/lib/ae_notes_functions.ts new file mode 100644 index 00000000..a6c16e7c --- /dev/null +++ b/src/lib/ae_notes_functions.ts @@ -0,0 +1,14 @@ +// This file is used to export all the functions that are used for Aether Events related functions. + +// import { +// handle_load_ae_obj_id__note, +// handle_load_ae_obj_li__note, +// handle_db_save_ae_obj_li__note, +// } from "$lib/ae_notes__note"; + + + +let export_obj = { + // handle_load_ae_obj_id__note: handle_load_ae_obj_id__note, +}; +export let notes_func = export_obj; diff --git a/src/lib/ae_notes_stores.ts b/src/lib/ae_notes_stores.ts new file mode 100644 index 00000000..2cfc41a8 --- /dev/null +++ b/src/lib/ae_notes_stores.ts @@ -0,0 +1,70 @@ +import { localStorageStore } from '@skeletonlabs/skeleton'; +import { writable } from 'svelte/store'; +import type { Writable } from 'svelte/store'; + +import type { key_val } from '$lib/ae_stores'; + + +/* *** BEGIN *** Initialize notes_local_data_struct */ +// This is for longer term or sticky app data. This should be stored to *local* storage. +// Updated 2024-08-20 +let notes_local_data_struct: key_val = { + ver: '2024-08-20_19', + // Shared + name: 'Aether - Notes (SvelteKit 2.x Svelte 4.x)', + title: `OSIT's Æ Notes`, // Æ + + mode__edit: false, + mode__debug: false, + +}; +// console.log(`AE Stores - App Notes Local Storage Data:`, notes_local_data_struct); + +// This works and uses *local* storage: +export let notes_loc: Writable = localStorageStore('ae_notes_loc', notes_local_data_struct); +// console.log(`AE Stores - App Local Storage Data:`, get(ae_loc)); + + + +/* *** BEGIN *** Initialize notes_session_data_struct */ +// Temporary app data. This is lost if the page is refreshed or using different tabs/windows. This should be stored to *session* storage. +// Updated 2024-08-20 +let notes_session_data_struct: key_val = { + ver: '2024-08-20_19', + log_lvl: 1, + + // Shared Triggers + trigger: null, + trigger__note_id: null, + // trigger__note_li: null, +}; +// console.log(`AE Stores - App Notes Session Storage Data:`, notes_session_data_struct); +export let notes_sess = writable(notes_session_data_struct); + + + +/* *** BEGIN *** Initialize notes_slct and notes_trigger */ +/* The slct and slct_trigger variable should not be stored in local storage. Only use session storage because browser tabs can be open to different notes, badges, exhibits, etc. */ + +// Intended for temporary session storage. +// Updated 2024-08-20 +let notes_slct_obj_template: key_val = { + // Top level + 'note_id': null, + 'note_obj': {}, + 'note_obj_li': [], + + 'lq__note_obj': {}, // Testing passing a LiveQuery object around... +}; +// console.log(`AE Stores - Selected Notes Objects:`, notes_slct_obj_template); + +// This works, and uses *session* (not local) storage: +export let notes_slct = writable(notes_slct_obj_template); + + + +/* *** BEGIN *** Initialize notes_trigger */ +// Intended for temporary session storage. +// Updated 2024-08-20 +export let notes_trigger: any = writable(null); +// console.log(`AE Notes Stores - Notes Trigger:`, notes_trigger); \ No newline at end of file diff --git a/src/lib/db_events.ts b/src/lib/db_events.ts index 92641283..82f0c828 100644 --- a/src/lib/db_events.ts +++ b/src/lib/db_events.ts @@ -1,7 +1,6 @@ import Dexie, { type Table } from 'dexie'; -import type { list } from 'postcss'; + import type { key_val } from './ae_stores'; -import type { o } from 'vitest/dist/reporters-B7ebVMkT.js'; // li = list // kv = key value list diff --git a/src/lib/db_notes.ts b/src/lib/db_notes.ts new file mode 100644 index 00000000..18d838fd --- /dev/null +++ b/src/lib/db_notes.ts @@ -0,0 +1,147 @@ +import Dexie, { type Table } from 'dexie'; + +import type { key_val } from './ae_stores'; + +// li = list +// kv = key value list +// json = JSON string +// ux = user experience (mode) +// LLM = Large Language Model (AI) + +// Updated 2024-08-20 +export interface Note { + id: string; // actually "id_random" + note_id: string; + + // Essentially this is a change log of notes + snapshot_id: string; // This is the original note ID. If deleted, then delete all children notes. + previous_id?: null|string; // This is the old or parent note ID + next_id?: null|string; // This is the new or child note ID + + external_id?: null|string; + import_id?: null|string; + code?: null|string; + + for_type?: null|string; + for_id?: null|string; + + type_code?: null|string; + + account_id?: null|string; // Owner account of the note + person_id?: null|string; // Owner person of the note + event_id: null|string; // Assign to an event??? + location_id?: null|string; // Assign to a location??? + + name: string; // or the title + summary?: null|string; // LLM (AI) generated summary...??? + outline?: null|string; // LLM (AI) generated outline...??? + + note?: null|string; + note_html?: null|string; + note_json?: null|string; + + start_datetime?: null|Date; + end_datetime?: null|Date; + timezone?: null|string; + + hide_event_launcher?: null|boolean; + + alert?: null|boolean; // LLM (AI) generated summary...??? + alert_msg?: null|string; // LLM (AI) generated summary...??? + + data_json?: null|string; // We always need to store something extra... + + ux_mode?: null|string; // 'mobile' or 'desktop' + + // This only allows for basic access to the content. + passcode_read?: null|string; // For LLM (AI) generated summary...??? + passcode_read_expire?: null|Date; + passcode_write?: null|string; + passcode_write_expire?: null|Date + + enable: null|boolean; + hide: null|boolean; + priority: null|boolean + sort: null|number; + group: null|string; + notes: null|string; + created_on: Date; + updated_on: null|Date; + + // Additional fields for convenience (database views) + file_count?: null|number; // Only files directly under a note + note_file_id_li_json?: null|string; + + // One person + person__given_name?: null|string; + person__family_name?: null|string; + person__full_name?: null|string; + person__primary_email?: null|string; + person__passcode?: null|string; + + // JSON formatted key value pairs for multiple people: {id: name, email, etc.} + person__kv_json?: null|string; + + note_name?: null|string; + + note_location_code?: null|string; + note_location_name?: null|string; + + // A key value list of the presentations + note_presentation_kv?: null|key_val; + note_presentation_li?: null|list; + // A key value list of the files + note_file_kv?: null|key_val; + note_file_li?: null|list; + + // Future standard fields!!! + obj_id?: null|string; + obj_ext_uid?: null|string; // Probably not needed for notes + obj_ext_id?: null|string; // Probably not needed for notes + obj_import_id?: null|string; // Probably not needed for notes + obj_code?: null|string; + obj_account_id?: null|string; + obj_passcode?: null|string; + obj_type?: null|string; // Should always be 'note' in this case + obj_type_ver_id?: null|string; // The ID from the table for the object type + obj_name?: null|string; + obj_summary?: null|string; // LLM (AI) generated summary...??? + obj_outline?: null|string; // LLM (AI) generated outline...??? + obj_description?: null|string; // Probably not needed for notes + obj_enable?: null|boolean; + obj_enable_on?: null|Date; + obj_archive_on?: null|Date; + obj_hide?: null|boolean; + obj_priority?: null|number; + obj_sort?: null|number; + obj_group?: null|string; + obj_cfg_json?: null|string; + obj_notes?: null|string; // Not the same as the "note" in the object type named "Note". + obj_created_on?: Date; + obj_updated_on?: null|Date; +} + + +// Updated 2024-06-10 +export class MySubClassedDexie extends Dexie { + // We just tell the typing system this is the case + notes!: Table; + + constructor() { + super('ae_notes_db'); + this.version(1).stores({ + notes: ` + id, note_id, note_id_random, + code, + account_id, account_id_random, + conference, type, + name, + start_datetime, end_datetime, + timezone, + cfg_json, + enable, hide, priority, sort, group, notes, created_on, updated_on`, + }); + } +} + +export const db_notes = new MySubClassedDexie(); \ No newline at end of file diff --git a/src/routes/notes/+layout.svelte b/src/routes/notes/+layout.svelte new file mode 100644 index 00000000..8f6cf1ca --- /dev/null +++ b/src/routes/notes/+layout.svelte @@ -0,0 +1,163 @@ + + + + + Notes - {$notes_loc.title ?? 'Æ loading...'} + + + +{#if $ae_loc.administrator_access && 1==2} + +{/if} + + + +{#if $ae_loc.ver != '2024-08-16_1821' || $ae_loc.ver_idb != '2024-08-16_1826'} + +
+ + +

New Version Available

+

+ There is a new version of the web app (this website). Please use the button to clear some cached data and settings. The page will then reload. +

+ +{#if $ae_loc.ver != '2024-08-07_1504'} +

+ You will need to sign in again after clearing the cache. +

+{/if} + + +
+ +{:else} + + + +{/if} + + + + diff --git a/src/routes/notes/+layout.ts b/src/routes/notes/+layout.ts new file mode 100644 index 00000000..d4837ad2 --- /dev/null +++ b/src/routes/notes/+layout.ts @@ -0,0 +1,74 @@ +/** @type {import('./$types').LayoutLoad} */ +console.log(`ae_notes +layout.ts start`); + +// Imports +import { browser } from '$app/environment'; +import { events_func } from '$lib/ae_events_functions'; + + +export async function load({ parent }) { + let log_lvl = 0; + + let data = await parent(); + // console.log(`ae_events_pres_mgmt +layout.ts data:`, data); + + let account_id = data.account_id; + if (!account_id) { + console.log(`events_pres_mgmt +layout.ts: The account_id was not found in the data!!!`); + return false; + } + + let ae_acct = data[account_id]; + if (log_lvl) { + console.log(`ae_acct = `, ae_acct); + } + + let event_id = ae_acct.slct.event_id; // From root +layout.ts + if (!event_id) { + console.log(`ERROR: events_pres_mgmt +layout.ts: The event_id was not found in the data!!!`); + return false; + } + + if (browser) { + // Should we limit these to event.conference = true? + let load_event_obj_li = events_func.handle_load_ae_obj_li__event({ + api_cfg: ae_acct.api, + account_id: account_id, + params: {enabled: 'enabled', qry__limit: 25}, + try_cache: true, + log_lvl: log_lvl + }); + ae_acct.slct.event_obj_li = load_event_obj_li; + } + + // let load_event_obj = events_func.handle_load_ae_obj_id__event({ + // api_cfg: ae_acct.api, + // event_id: event_id, + // try_cache: false + // }); + + // ae_acct.slct.event_obj = load_event_obj; + + // if (browser) { + // console.log(`Browser: ${browser}`); + // events_func.handle_db_save_ae_obj_li__event({ + // obj_type: 'event', + // obj_li: [load_event_obj_li], + // }); + // } + + let submenu = { + main: {name: 'Main', href: '/events_pres_mgmt', access: false}, + // manage: {name: 'Manage', href: '/events_pres_mgmt/manage', access: 'administrator', disable: true, hide: true}, + locations: {name: 'Locations', href: '/events_pres_mgmt/locations', access: false, disable: false, hide: false}, + }; + data.submenu = submenu + + // WARNING: Precaution against shared data between sites and sessions. + data[account_id] = ae_acct; + + return data; +} + +// export const prerender = false; +// export const prerender = true; diff --git a/src/routes/notes/+page.svelte b/src/routes/notes/+page.svelte new file mode 100644 index 00000000..d26e0880 --- /dev/null +++ b/src/routes/notes/+page.svelte @@ -0,0 +1,186 @@ + + + +
+ +

Notes for {$ae_loc.account_name ?? 'Æ loading...'}

+ + + + +{#if $ae_loc.administrator_access} +

Administrator Access - Technical Support

+

You are accessing the notes system with "administrator" level permissions.

+{:else if $ae_loc.trusted_access} +

Trusted Access - Staff

+

You are accessing the notes system with "trusted" level permissions.

+{:else if !$ae_loc.trusted_access} +

Restricted Access

+

You are accessing to the notes system is limited

+{/if} + + + + + + +{#await ae_acct.slct.note_obj_li} +
+ + Loading... +
+{:then} +
+ + Loaded +
+ + +{#if ae_acct.slct.note_obj_li && $lq__note_obj_li} + +{/if} + + +{:catch error} +
+ + Error: {error.message} +
+{/await} + +
+ + + diff --git a/src/routes/notes/+page.ts b/src/routes/notes/+page.ts new file mode 100644 index 00000000..5ec2dc6b --- /dev/null +++ b/src/routes/notes/+page.ts @@ -0,0 +1,38 @@ +/** @type {import('./$types').PageLoad} */ + +import { error } from '@sveltejs/kit'; +import { notes_func } from '$lib/ae_notes_functions'; + +export async function load({ parent }) { + let log_lvl = 0; + + let data = await parent(); + + // let account_id = data.account_id; + // if (!account_id) { + // console.log(`ae_notes +page.ts: The account_id was not found in the data!!!`); + // error(500, { + // message: 'Not found' + // }); + // } + + // let ae_acct = data[account_id]; + + // Should we limit these to note.conference = true? + // let load_note_obj_li = await notes_func.handle_load_ae_obj_li__note({ + // api_cfg: ae_acct.api, + // account_id: account_id, + // params: {enabled: 'enabled', qry__limit: 25}, + // try_cache: false, + // log_lvl: 1 + // }); + // ae_acct.slct.note_obj_li = load_note_obj_li; + + // data[account_id] = ae_acct; + + return data; + + // return { + // ae_notes_page_ts: true, + // }; +}