From 991cb1e9da3dbafa142cb8916dddbabd387948b6 Mon Sep 17 00:00:00 2001 From: Scott Idem Date: Thu, 20 Jun 2024 17:45:00 -0400 Subject: [PATCH] Working on ability to change the presentation name and session name... Making progress. Need to figure out why the file list does not reload correctly right after saving. --- src/lib/ae_events_functions.ts | 49 ++++- src/lib/db_events.ts | 6 +- src/lib/element_ae_crud.svelte | 80 ++------ .../session/[slug]/+page.svelte | 2 +- .../session/[slug]/presenter_view.svelte | 190 +++++++++++++++++- 5 files changed, 247 insertions(+), 80 deletions(-) diff --git a/src/lib/ae_events_functions.ts b/src/lib/ae_events_functions.ts index 2bc8428f..52633cbf 100644 --- a/src/lib/ae_events_functions.ts +++ b/src/lib/ae_events_functions.ts @@ -196,6 +196,7 @@ async function handle_load_ae_obj_li__event_file( handle_db_save_ae_obj_li__event_file({obj_type: 'event_file', obj_li: event_file_obj_li_get_result}); return event_file_obj_li_get_result; } else { + console.log('No results returned.'); return []; } }) @@ -269,7 +270,7 @@ async function handle_load_ae_obj_id__event_session( use_alt_table: false, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config. use_alt_base: false, // NOTE: This will use the base_name_alt value instead of the base_name value in the API config. params: params, - log_lvl: 0 + log_lvl: log_lvl }) .then(function (event_session_obj_get_result) { if (event_session_obj_get_result) { @@ -436,6 +437,51 @@ async function handle_search__event_session( } +// Updated 2024-06-20 +async function handle_load_ae_obj_id__event_presentation( + { + api_cfg, + event_presentation_id, + try_cache=false, + log_lvl=0 + } : { + api_cfg: any, + event_presentation_id: string, + try_cache?: boolean, + log_lvl?: number + } + ) { + console.log(`*** handle_load_ae_obj_id__event_presentation() *** event_presentation_id=${event_presentation_id}`); + + let params = {}; + + ae_promises.load__event_presentation_obj = await api.get_ae_obj_id_crud({ + api_cfg: api_cfg, + obj_type: 'event_presentation', + obj_id: event_presentation_id, // NOTE: This is the FQDN, not normally the ID. + use_alt_table: false, // NOTE: This will use the table_name_alt value instead of the table_name value in the API config. + use_alt_base: false, // NOTE: This will use the base_name_alt value instead of the base_name value + params: params, + log_lvl: log_lvl + }) + .then(function (event_presentation_obj_get_result) { + if (event_presentation_obj_get_result) { + // This is expecting a list + handle_db_save_ae_obj_li__event_presentation({obj_type: 'event_presentation', obj_li: [event_presentation_obj_get_result]}); + return event_presentation_obj_get_result; + } else { + console.log('No results returned.'); + return null; + } + }) + .catch(function (error) { + console.log('No results returned or failed.', error); + }); + + return ae_promises.load__event_presentation_obj; +} + + // Updated 2024-06-10 async function handle_load_ae_obj_li__event_presentation( { @@ -1900,6 +1946,7 @@ let export_obj = { handle_load_ae_obj_li__event_session: handle_load_ae_obj_li__event_session, handle_search__event_session: handle_search__event_session, + handle_load_ae_obj_id__event_presentation: handle_load_ae_obj_id__event_presentation, handle_load_ae_obj_li__event_presentation: handle_load_ae_obj_li__event_presentation, handle_load_ae_obj_id__event_presenter: handle_load_ae_obj_id__event_presenter, diff --git a/src/lib/db_events.ts b/src/lib/db_events.ts index 8e5368d2..f12f4575 100644 --- a/src/lib/db_events.ts +++ b/src/lib/db_events.ts @@ -483,7 +483,7 @@ export class MySubClassedDexie extends Dexie { event_id_random, event_session_id_random, event_presentation_id_random, event_presenter_id_random, event_location_id_random, filename, extension, lu_file_purpose_id, lu_event_file_purpose_name, file_purpose, - enable, hide, priority, sort, group, notes, created_on, updated_on`, + enable, hide, priority, sort, group, created_on, updated_on`, presentations: ` id, event_presentation_id, event_presentation_id_random, @@ -493,7 +493,7 @@ export class MySubClassedDexie extends Dexie { event_id_random, event_session_id_random, event_abstract_id_random, abstract_code, name, description, start_datetime, end_datetime, hide_event_launcher, - enable, hide, priority, sort, group, notes, created_on, updated_on`, + enable, hide, priority, sort, group, created_on, updated_on`, presenters: ` id, event_presenter_id, event_presenter_id_random, @@ -506,7 +506,7 @@ export class MySubClassedDexie extends Dexie { full_name, affiliations, email, agree, hide_event_launcher, - enable, hide, priority, sort, group, notes, created_on, updated_on`, + enable, hide, priority, sort, group, created_on, updated_on`, }); } } diff --git a/src/lib/element_ae_crud.svelte b/src/lib/element_ae_crud.svelte index 86e79cf1..5c5c592f 100644 --- a/src/lib/element_ae_crud.svelte +++ b/src/lib/element_ae_crud.svelte @@ -89,7 +89,7 @@ async function handle_obj_field_patch(new_field_value: any) { // let params = {}; - ae_promises.api_update__ae_obj = core_func.handle_update_ae_obj_id_crud({ + ae_promises.api_update__ae_obj = await core_func.handle_update_ae_obj_id_crud({ api_cfg: api_cfg, object_type: object_type, object_id: object_id, @@ -100,7 +100,7 @@ async function handle_obj_field_patch(new_field_value: any) { log_lvl: 0 }) .then(function (results) { - console.log('PATCH Promise', results); + console.log('Field PATCH Promise', results); if (results) { console.log(`Patched - Field Name: ${field_name} with new Field Value: ${new_field_value}; Original Field Value: ${original_field_value}`); @@ -110,7 +110,16 @@ async function handle_obj_field_patch(new_field_value: any) { patch_result = 'PATCH failed'; return false; } - + return true; + }) + .catch(function (error) { + console.log('Something went wrong patching the record.'); + console.log(error); + return false; + }) + .finally(function () { + console.log('Field PATCH Promise finally'); + // This dispatch() must be under "finally". dispatch( 'ae_crud_updated', { @@ -121,73 +130,8 @@ async function handle_obj_field_patch(new_field_value: any) { 'original_value': original_field_value, } ); - return true; - }) - .catch(function (error) { - console.log('Something went wrong patching the record.'); - console.log(error); - return false; - }) - .finally(function () { - console.log('PATCH Promise finally'); }); - - // if (ae_promises.api_update__ae_obj) { - // console.log(`Patched - Field Name: ${field_name} with new Field Value: ${new_field_value}; Original Field Value: ${original_field_value}`); - // patch_result = 'PATCH complete'; - // } else { - // console.log(`Not Patched - Field Name: ${field_name} with new Field Value: ${new_field_value}; Original Field Value: ${original_field_value}`); - // patch_result = 'PATCH failed'; - // return false; - // } - - // ae_promises.api_update__ae_obj = api.update_ae_obj_id_crud({ - // api_cfg: api_cfg, - // obj_type: object_type, - // obj_id: object_id, - // field_name: field_name, - // field_value: new_field_value, - // // fields: data, - // key: api_crud_super_key, - // // jwt: null, - // // params: params, - // // data: patch_data, - // log_lvl: 2 - // }) - // .then(function (results) { - // console.log('PATCH Promise', results); - - // if (results) { - // console.log(`Patched - Field Name: ${field_name} with new Field Value: ${new_field_value}; Original Field Value: ${original_field_value}`); - // patch_result = 'PATCH complete'; - // } else { - // console.log(`Not Patched - Field Name: ${field_name} with new Field Value: ${new_field_value}; Original Field Value: ${original_field_value}`); - // patch_result = 'PATCH failed'; - // return false; - // } - - // dispatch( - // 'ae_crud_updated', - // { - // 'type': object_type, - // 'id': object_id, - // 'field_name': field_name, - // 'field_value': new_field_value, - // 'original_value': original_field_value, - // } - // ); - // return true; - // }) - // .catch(function (error) { - // console.log('Something went wrong patching the record.'); - // console.log(error); - // return false; - // }) - // .finally(function () { - // console.log('PATCH Promise finally'); - // }); - return ae_promises.api_update__ae_obj; } diff --git a/src/routes/events_pres_mgmt/session/[slug]/+page.svelte b/src/routes/events_pres_mgmt/session/[slug]/+page.svelte index 98cb39a7..a205b120 100644 --- a/src/routes/events_pres_mgmt/session/[slug]/+page.svelte +++ b/src/routes/events_pres_mgmt/session/[slug]/+page.svelte @@ -447,7 +447,7 @@ function send_sign_in_poc_email( {$lq__event_session_obj.poc_person_full_name ? $lq__event_session_obj.poc_person_full_name : '-- not set --'} - {#if $ae_loc.trusted_access } + {#if $ae_loc.trusted_access} ; let ae_placeholder_li: key_val = {}; +let ae_promises: key_val = {}; // Promise; +let ae_tmp: key_val = {}; +ae_tmp.show__file_li = true; +let ae_triggers: key_val = {}; let lq__event_session_obj = liveQuery( () => db_events.sessions.get($events_slct.event_session_id) @@ -39,7 +42,7 @@ let lq__event_presenter_obj = liveQuery( ); let lq__event_file_obj_li = liveQuery( - () => db_events.files.where('event_presenter_id_random').equals($events_slct.event_presenter_id).toArray() + async () => await db_events.files.where('event_presenter_id_random').equals($events_slct.event_presenter_id).toArray() ); // $events_slct.event_presenter_obj = $lq__event_presenter_obj; @@ -57,7 +60,9 @@ let lq__event_file_obj_li = liveQuery( onMount(() => { console.log('Events Session [slug]: presenter_view.svelte'); console.log(`$events_slct.event_presenter_id:`, $events_slct.event_presenter_id); - console.log(`$lq__event_presenter_obj:`, $lq__event_presenter_obj); + // console.log(`$lq__event_presenter_obj:`, $lq__event_presenter_obj); + + $slct_trigger = 'load__event_file_obj_li'; }); @@ -324,6 +329,68 @@ async function handle_delete__event_file({event_file_id}) {

Title: "{$events_slct.presentation_obj.name}"

+ + { + console.log(`ae_crud_updated:`, e.detail); + + events_func.handle_load_ae_obj_id__event_presentation({api_cfg: $ae_api, event_presentation_id: $events_slct.presentation_obj.event_presentation_id_random, log_lvl: 1}) + .then(function (load_results) { + // We need to force reload the Indexed DB - Dexie.js? + // Sometimes the changes are not seen. The file disappears when the Save button is pressed. + + // Maybe reload page? + // window.location.reload(); + }) + .finally(function () { + // ae_tmp.show__file_li = false; + // Careful with the trigger_patch. It will keep firing if not reset. + ae_triggers.update_event_presentation_name = false; + }); + }} + > + + + + + + + + + + +

Presenter:

-

Files: {$events_slct.presenter_obj.file_count ? `${$events_slct.presenter_obj.file_count}x` : '-- none --'}

+

+ Files: {$events_slct.presenter_obj.file_count ? `${$events_slct.presenter_obj.file_count}x` : '-- none --'} +

+
WARNING: The file upload and management is a work in progress. You can upload and delete files, but not yet rename them. @@ -422,7 +505,7 @@ WARNING: The file upload and management is a work in progress. You can upload an -{#if $lq__event_file_obj_li} +{#if ae_tmp.show__file_li && $lq__event_file_obj_li && $lq__event_file_obj_li.length > 0}
    @@ -472,10 +555,103 @@ WARNING: The file upload and management is a work in progress. You can upload an + + {#if ae_tmp[event_file_obj.event_file_id_random] && ae_tmp[event_file_obj.event_file_id_random]?.show__edit_file_purpose === true} + { + console.log(`ae_crud_updated:`, e.detail); + + events_func.handle_load_ae_obj_id__event_file({api_cfg: $ae_api, event_file_id: event_file_obj.event_file_id_random, log_lvl: 1}) + .then(function (load_results) { + // We need to force reload the Indexed DB - Dexie.js? + // Sometimes the changes are not seen. The file disappears when the Save button is pressed. + + // Maybe reload page? + // window.location.reload(); + }) + .finally(function () { + // ae_tmp[event_file_obj.event_file_id_random].file_purpose = null; + ae_tmp[event_file_obj.event_file_id_random].show__edit_file_purpose = false; + // Careful with the trigger_patch. It will keep firing if not reset. + ae_triggers.update_event_file_purpose = false; + }); + }} + > + + + + + + {:else} + + {/if} + +