diff --git a/src/lib/ae_core/core__hosted_files.ts b/src/lib/ae_core/core__hosted_files.ts index 97e6e6b8..3bf81249 100644 --- a/src/lib/ae_core/core__hosted_files.ts +++ b/src/lib/ae_core/core__hosted_files.ts @@ -86,7 +86,7 @@ export async function load_ae_obj_li__hosted_file( } // Check if for_obj_type is in the list of valid Aether object types: - let valid_for_obj_types = ['account', 'archive', 'archive_content', 'event', 'event_session', 'event_presentation', 'event_presenter', 'event_location', 'post', 'post_comment']; + let valid_for_obj_types = ['account', 'archive', 'archive_content', 'event', 'event_session', 'event_presentation', 'event_presenter', 'event_location', 'journal', 'journal_entry', 'post', 'post_comment']; if (!valid_for_obj_types.includes(for_obj_type)) { console.log(`Invalid for_obj_type: ${for_obj_type}`); return []; diff --git a/src/lib/ae_core/core__idb_dexie.ts b/src/lib/ae_core/core__idb_dexie.ts index cbaaff55..ff1797ab 100644 --- a/src/lib/ae_core/core__idb_dexie.ts +++ b/src/lib/ae_core/core__idb_dexie.ts @@ -18,7 +18,7 @@ export async function db_save_ae_obj_li__ae_obj({ properties_to_save: string[]; log_lvl?: number; }) { - log_lvl = 1; + // log_lvl = 1; if (log_lvl) { console.log(`*** db_save_ae_obj_li__ae_obj() *** table_name=${table_name}`, obj_li); } @@ -72,7 +72,7 @@ export async function db_save_ae_obj_li__ae_obj({ } catch (error) { // This is fairly common and normal if the object is new if (log_lvl) { - console.error(`Bulk update failed. Falling back to bulkPut.`, error); + console.log(`Bulk update failed. Falling back to bulkPut. This is normal.`, error); } } @@ -85,7 +85,7 @@ export async function db_save_ae_obj_li__ae_obj({ return putKeys; } catch (error) { // This should not happen if the object is new - console.error(`Bulk put failed.`, error); + console.error(`Bulk put failed. Something likely went wrong!`, error); return []; } } \ No newline at end of file diff --git a/src/routes/journals/ae_comp__journal_entry_obj_id_view.svelte b/src/routes/journals/ae_comp__journal_entry_obj_id_view.svelte index 342df7e5..4198149f 100644 --- a/src/routes/journals/ae_comp__journal_entry_obj_id_view.svelte +++ b/src/routes/journals/ae_comp__journal_entry_obj_id_view.svelte @@ -35,11 +35,12 @@ import E_app_codemirror_v5 from '$lib/e_app_codemirror_v5.svelte'; // *** 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/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'; - -console.log(`ae_comp__journal_entry_obj_id_view.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/element_manage_hosted_file_li_all.svelte'; interface Props { log_lvl?: number; @@ -55,11 +56,17 @@ let { lq__journal_entry_obj, }: Props = $props(); +if (log_lvl) { + console.log(`ae_comp__journal_entry_obj_id_view.svelte`, lq__journal_obj, lq__journal_obj_li, lq__journal_entry_obj); +} + let ae_promises: key_val = $state({}); // let ae_tmp: key_val = {}; // let ae_trigger: any = null; // let ae_triggers: key_val = {}; + + let show_menu: boolean = $state(false); @@ -297,6 +304,12 @@ async function update_journal_entry() { // log_lvl = 1; + // append slct_hosted_file_kv to data_json.hosted_file_kv + if (!tmp_entry_obj.data_json.hosted_file_kv) { + tmp_entry_obj.data_json.hosted_file_kv = {}; + } + tmp_entry_obj.data_json.hosted_file_kv = $journals_loc.entry.hosted_file_kv; + let data_kv: key_val = { alert: tmp_entry_obj?.alert, personal: tmp_entry_obj?.personal, @@ -317,6 +330,8 @@ async function update_journal_entry() { history: tmp_entry_obj?.history, history_encrypted: null, // This should only be generated below. + data_json: tmp_entry_obj?.data_json, + sort: tmp_entry_obj?.sort, group: tmp_entry_obj?.group, archive_on: tmp_entry_obj?.archive_on, @@ -846,6 +861,46 @@ function handle_marked(text_string: string) { }); return marked_string; } + + +let slct_hosted_file_kv: key_val = $state({}); +let slct_hosted_file_id: any = $state(null); +let slct_hosted_file_obj: any = $state(null); +$effect(() => { + if (slct_hosted_file_id && slct_hosted_file_obj) { + console.log(`*** handle_hosted_file_selected() *** ${slct_hosted_file_id}`); + // We need to update the journal_entry_obj with the new file (for now just the first one). + + update_journal_entry(); + + + + // ae_promises.journal_entry_obj = archives_func.update_ae_obj__journal_entry({ + // api_cfg: $ae_api, + // journal_entry_id: tmp_entry_obj.journal_entry_id, + // data_kv: { + // hosted_file_id_random: slct_hosted_file_id, + // // file_path: hosted_file_obj_li[0].file_path, + // filename: slct_hosted_file_obj.filename, + // file_extension: slct_hosted_file_obj.extension, + // journal_entry_type: 'hosted_file', + // }, + // log_lvl: log_lvl + // }) + // .then(function (journal_entry_obj_update_result) { + // // tmp_entry_obj.journal_entry_obj = $lq__journal_entry_obj; + // tmp_entry_obj.journal_entry_obj = journal_entry_obj_update_result; + // }) + // .catch(function (error) { + // console.log('Something went wrong.'); + // console.log(error); + // return false; + // }); + + slct_hosted_file_id = null; + slct_hosted_file_obj = null; + } +}); @@ -2210,6 +2265,208 @@ tabindex={$ae_loc.edit_mode ? 0 : -1} --> {/if} + +
+ + + {#if $lq__journal_entry_obj?.journal_entry_id} +
+ +

Upload/Manage Hosted File

+ + {#if !tmp_entry_obj?.data_json?.hosted_file_kv} + No file(s) uploaded yet. + + {#if $ae_loc.trusted_access} + + +
+ + {#snippet label()} + +
+ + Upload Journal Entry files +
+ + Aether hosted files only + +
+ {/snippet} +
+
+ +
+ + + + +
+ {/if} + + {:else} + + + + + + + + + + {/if} + +
+ {:else} +
+ + Save the form first before uploading a file. +
+ {/if} + {:else if ($journals_loc.entry.edit_kv[$lq__journal_entry_obj?.journal_entry_id] == 'history')}