diff --git a/src/lib/ae_archives/ae_archives__archive_content.ts b/src/lib/ae_archives/ae_archives__archive_content.ts index 1c776664..bab5f974 100644 --- a/src/lib/ae_archives/ae_archives__archive_content.ts +++ b/src/lib/ae_archives/ae_archives__archive_content.ts @@ -6,6 +6,9 @@ import { db_archives } from "$lib/db_archives"; let ae_promises: key_val = {}; +// TESTING NOTE: I changed these to all use async and await. Not sure if this helps or hurts things. Mainly this is related to the Dexie DB changes. 2024-11-08 + + // Updated 2024-09-25 export async function load_ae_obj_id__archive_content( { @@ -135,12 +138,14 @@ export async function create_ae_obj__archive_content( archive_id, data_kv, params={}, + try_cache = true, log_lvl=0 }: { api_cfg: any, archive_id: string, data_kv: key_val, params?: key_val, + try_cache?: boolean, log_lvl?: number } ) { @@ -160,11 +165,13 @@ export async function create_ae_obj__archive_content( }) .then(async function (archive_content_obj_create_result) { if (archive_content_obj_create_result) { - await db_save_ae_obj_li__archive_content( - { - obj_type: 'archive_content', - obj_li: [archive_content_obj_create_result] - }); + if (try_cache) { + await db_save_ae_obj_li__archive_content( + { + obj_type: 'archive_content', + obj_li: [archive_content_obj_create_result] + }); + } return archive_content_obj_create_result; } else { return null; @@ -183,6 +190,59 @@ export async function create_ae_obj__archive_content( } +// Updated 2024-11-08 +export async function delete_ae_obj_id__archive_content( + { + api_cfg, + archive_content_id, + method = 'delete', // 'delete', 'disable', 'hide' + params = {}, + try_cache = true, + log_lvl = 0 + }: { + api_cfg: any, + archive_content_id: string, + method?: string, + params?: key_val, + try_cache?: boolean, + log_lvl?: number + } + ) { + if (log_lvl) { + console.log(`*** delete_ae_obj_id__archive_content() *** archive_content_id=${archive_content_id}`); + } + + ae_promises.delete__archive_content_obj = await api.delete_ae_obj_id_crud({ + api_cfg: api_cfg, + obj_type: 'archive_content', + obj_id: archive_content_id, + key: api_cfg.api_crud_super_key, + params: params, + method: method, + log_lvl: log_lvl + }) + .then(function (archive_content_obj_delete_result) { + // if (archive_content_obj_delete_result) { + // return archive_content_obj_delete_result; + // } else { + // return null; + // } + }) + .catch(function (error) { + console.log('No results returned or failed.', error); + }) + .finally(function () { + db_archives.content.delete(archive_content_id); // Delete from the DB no matter what. + }); + + if (log_lvl) { + console.log('ae_promises.delete__archive_content_obj:', ae_promises.delete__archive_content_obj); + } + + return ae_promises.delete__archive_content_obj; +} + + // Updated 2024-09-25 export async function update_ae_obj__archive_content( { diff --git a/src/lib/ae_archives/ae_archives_functions.ts b/src/lib/ae_archives/ae_archives_functions.ts index e3f2a559..761f0e9c 100644 --- a/src/lib/ae_archives/ae_archives_functions.ts +++ b/src/lib/ae_archives/ae_archives_functions.ts @@ -14,6 +14,7 @@ import { load_ae_obj_id__archive_content, load_ae_obj_li__archive_content, create_ae_obj__archive_content, + delete_ae_obj_id__archive_content, update_ae_obj__archive_content, // qry__archive_content, db_save_ae_obj_li__archive_content, @@ -30,6 +31,7 @@ let export_obj = { load_ae_obj_id__archive_content: load_ae_obj_id__archive_content, load_ae_obj_li__archive_content: load_ae_obj_li__archive_content, create_ae_obj__archive_content: create_ae_obj__archive_content, + delete_ae_obj_id__archive_content: delete_ae_obj_id__archive_content, update_ae_obj__archive_content: update_ae_obj__archive_content, db_save_ae_obj_li__archive_content: db_save_ae_obj_li__archive_content, }; diff --git a/src/lib/ae_events/ae_events__event_presenter.ts b/src/lib/ae_events/ae_events__event_presenter.ts index 09d71d06..847e7607 100644 --- a/src/lib/ae_events/ae_events__event_presenter.ts +++ b/src/lib/ae_events/ae_events__event_presenter.ts @@ -215,7 +215,7 @@ export async function delete_ae_obj_id__event_presenter( ae_promises.delete__event_presenter_obj = await api.delete_ae_obj_id_crud({ api_cfg: api_cfg, obj_type: 'event_presenter', - obj_id: event_presenter_id, // NOTE: This is the FQDN, not normally the ID. + obj_id: event_presenter_id, key: api_cfg.api_crud_super_key, params: params, method: method, diff --git a/src/routes/idaa/(idaa)/archives/[archive_id]/ae_idaa_comp__archive_content_obj_id_edit.svelte b/src/routes/idaa/(idaa)/archives/[archive_id]/ae_idaa_comp__archive_content_obj_id_edit.svelte index acedbce4..6f7c0cdb 100644 --- a/src/routes/idaa/(idaa)/archives/[archive_id]/ae_idaa_comp__archive_content_obj_id_edit.svelte +++ b/src/routes/idaa/(idaa)/archives/[archive_id]/ae_idaa_comp__archive_content_obj_id_edit.svelte @@ -26,7 +26,7 @@ let upload__hosted_file_obj_promise: any; let prom_api__archive_content_obj: any; let prom_api__archive_content_obj__hosted_file: any; -let disable_submit_btn = true; +let disable_submit_btn = false; if ($idaa_slct.archive_content_id) { console.log(`Archive Content ID selected: ${$idaa_slct.archive_content_id}`); @@ -127,12 +127,11 @@ async function handle_submit_form(event) { let archive_content_do: key_val = {}; if (!$idaa_slct.archive_content_id) { - archive_content_do['account_id_random'] = $ae_loc.account_id; archive_content_do['archive_id_random'] = $idaa_slct.archive_id; - // archive_content_do['enable'] = true; } archive_content_do['name'] = archive_content_di.name; + // Check if the description_new_html exists and is a string if (typeof $idaa_slct.archive_content_obj.description_new_html === 'string') { console.log('New description is a string'); @@ -148,11 +147,11 @@ async function handle_submit_form(event) { archive_content_do['archive_content_type'] = null; } - archive_content_do['enable_for_public'] = !!!archive_content_di.enable_for_public; + // archive_content_do['enable_for_public'] = !!!archive_content_di.enable_for_public; - archive_content_do['file_path'] = archive_content_di.file_path; - archive_content_do['filename'] = archive_content_di.filename.trim(); - archive_content_do['file_extension'] = archive_content_di.file_extension.trim(); + // archive_content_do['file_path'] = archive_content_di.file_path; + archive_content_do['filename'] = archive_content_di?.filename?.trim() ?? null; + archive_content_do['file_extension'] = archive_content_di?.file_extension?.trim() ?? null; let date_time_str = null; let date_part = archive_content_di.original_datetime_date.trim(); @@ -184,11 +183,8 @@ async function handle_submit_form(event) { archive_content_do['group'] = null; } - // Check if the enable exists and is a string - console.log(`archive_content_di.enable = ${archive_content_di.enable}`); - // if (typeof archive_content_di.enable !== 'undefined') { - archive_content_do['enable'] = !!archive_content_di.enable; - // } + // console.log(`archive_content_di.enable = ${archive_content_di.enable}`); + archive_content_do['enable'] = !!archive_content_di.enable; // Check if the notes_new_html exists and is a string if (typeof $idaa_slct.archive_content_obj.notes_new_html === 'string') { @@ -202,12 +198,11 @@ async function handle_submit_form(event) { console.log(archive_content_do); if (!$idaa_slct.archive_content_id) { - create_archive_content_obj_promise = api.create_ae_obj_crud({ + prom_api__archive_content_obj = archives_func.create_ae_obj__archive_content({ api_cfg: $ae_api, - obj_type: 'archive_content', - fields: archive_content_do, - key: $ae_api.api_crud_super_key, - log_lvl: 1 + archive_id: $idaa_slct.archive_id, + data_kv: archive_content_do, + log_lvl: 2 }) .then(async function (archive_content_obj_create_result) { if (!archive_content_obj_create_result) { @@ -216,78 +211,17 @@ async function handle_submit_form(event) { } $idaa_slct.archive_content_id = archive_content_obj_create_result.obj_id_random; + $idaa_slct.archive_content_obj = archive_content_obj_create_result; - // Get ready to upload the file now that we have a new archive_content_id. - const form_data = new FormData(); - - form_data.append('account_id', $ae_loc.account_id); - form_data.append('link_to_type', 'archive_content'); - form_data.append('link_to_id', $idaa_slct.archive_content_id); - - for (let i = 0; i < event.target.file_list.files.length; i++) { - form_data.append(`file_list`, event.target.archive_content_file_upload_list.files[i]); - } - - let params = null; - - let endpoint = '/hosted_file/upload_files'; - - console.log(form_data); - - params = null; - - // Uncomment and the post_promise is not seen by the "await" below - // post_promise = await api.post_object({api_cfg: $cfg.api, endpoint: endpoint, params: params, data:form_data}); - // Uncomment so that the post_promise is not seen by the "await" below - upload__hosted_file_obj_promise = await api.post_object({api_cfg: $ae_api, endpoint: endpoint, params: params, form_data: form_data}); - console.log(upload__hosted_file_obj_promise); - let hosted_file_id = upload__hosted_file_obj_promise[0].hosted_file_id_random; - - archive_content_do = {}; - archive_content_do['hosted_file_id_random'] = hosted_file_id; - archive_content_do['file_path'] = `/hosted_file/download/${hosted_file_id}?filename=${archive_content_di.filename.trim()}`; - archive_content_do['archive_content_type'] = 'hosted_file'; - - update_archive_content_obj_promise = await api.update_ae_obj_id_crud({ - api_cfg: $ae_api, - obj_type: 'archive_content', - obj_id: $idaa_slct.archive_content_id, - fields: archive_content_do, - key: $ae_api.api_crud_super_key, - log_lvl: 1 - }) - .then(function (archive_content_obj_update_result) { - if (!archive_content_obj_update_result) { - console.log('The result was null or false.'); - return false; - } - return archive_content_obj_update_result; - }) - .catch(function (error) { - console.log('Something went wrong.'); - console.log(error); - return false; - }); - - // update_archive_content_obj_promise = await update_archive_content_obj({archive_content_id: $idaa_slct.archive_content_id, data: archive_content_do}) - // console.log(update_archive_content_obj_promise); return update_archive_content_obj_promise }) - .then(function (archive_content_obj_create_result) { - - // dispatch( - // 'created__archive_content_obj', - // { - // archive_content_id: $idaa_slct.archive_content_id, - // } - // ); - - return archive_content_obj_create_result; - }) .catch(function (error) { console.log('Something went wrong.'); console.log(error); return false; + }) + .finally(() => { + disable_submit_btn = false; }); return create_archive_content_obj_promise; @@ -313,46 +247,16 @@ async function handle_submit_form(event) { return false; }) .finally(() => { - // We need to do this since the comment has changed and the idaa_slct object does automatically update (yet...???). - $idaa_slct.archive_content_obj = $lq__archive_content_obj; - disable_submit_btn = false; - // $idaa_sess.archives.show__modal_edit__archive_content_id = false; + // We need to do all of this since the DB object has changed and the SLCT object does automatically update (yet...??? Svelte 5?). + // $idaa_slct.archive_content_obj = await $lq__archive_content_obj; + + $idaa_slct.archive_content_id = null; + $idaa_slct.archive_content_obj = {}; + $idaa_sess.archives.show__modal_edit__archive_content_id = false; }); return prom_api__archive_content_obj; } - - // update_archive_content_obj_promise = api.update_ae_obj_id_crud({ - // api_cfg: $ae_api, - // obj_type: 'archive_content', - // obj_id: $idaa_slct.archive_content_id, - // fields: archive_content_do, - // key: $ae_api.api_crud_super_key, - // log_lvl: 1 - // }) - // .then(function (archive_content_obj_update_result) { - // if (!archive_content_obj_update_result) { - // console.log('The result was null or false.'); - // return false; - // } - - // // dispatch( - // // 'updated__archive_content_obj', - // // { - // // archive_content_id: $idaa_slct.archive_content_id, - // // } - // // ); - - // return archive_content_obj_update_result; - // }) - // .catch(function (error) { - // console.log('Something went wrong.'); - // console.log(error); - // return false; - // }); - - // return update_archive_content_obj_promise; - // } } $: if ($idaa_slct.archive_content_obj.upload_complete && $idaa_slct.archive_content_obj.hosted_file_id_li?.length && $idaa_slct.archive_content_obj.hosted_file_obj_li?.length) { @@ -441,7 +345,7 @@ async function handle_hosted_files_uploaded(hosted_file_id_li: string[], hosted_