From 9a325c75433b1d8e0fb9795a0896f4b3687cb75b Mon Sep 17 00:00:00 2001 From: Scott Idem Date: Wed, 12 Feb 2020 23:40:34 -0500 Subject: [PATCH] Mostly working. Need to finish up loading event files and then updating and deleting them. --- app/index.html | 94 +++------------- app/js/module_app_ui_v2.js | 219 +++++++++++++++++++++++++++++++------ config.json | 4 +- 3 files changed, 199 insertions(+), 118 deletions(-) diff --git a/app/index.html b/app/index.html index 1fb692a..750eab7 100644 --- a/app/index.html +++ b/app/index.html @@ -42,8 +42,14 @@
-
-
+
+

Event Files

+
    +
    +
    +

    Location Files

    +
      +

      Sessions

        @@ -266,9 +272,12 @@ let safe_to_render_launcher = false; // currently only set to true in module_app_idb.js let run_check_file_cache = false; + let looping_tbl_event = false; + let looping_tbl_event_location = false; let looping_tbl_event_session = false; let looping_tbl_event_presentation = false; let looping_tbl_event_presenter = false; + let looping_tbl_event_file = false; //const loading_loop_interval = app_config.loading_loop_interval; // in milliseconds @@ -432,6 +441,8 @@ safe_to_render_launcher = false; // Set to false so that the launcher render only starts after the launcher object has updated run_check_file_cache = true; // Set to true so that the local file cache will be checked against the updated event files idb_event_file_check_datetime = Date.now() + idb_event_file_check_period; + + let render_event_file_records_result = await uiv2.render_event_file_records(); // NOTE: v2 idb to ui } @@ -446,89 +457,10 @@ var idb_to_launcher_loop = setInterval(function() { - if (run_idb_to_launcher) { - console.log('FLAG: run_idb_to_launcher='+run_idb_to_launcher); - if (tbl_event_key_count != null && tbl_event_location_key_count != null && tbl_event_session_key_count != null - && tbl_event_presentation_key_count != null && tbl_event_presenter_key_count != null - && tbl_event_file_key_count != null) { - console.log('All IDB tables have records. Going to create/update the launcher object now...'); - - idb_tables_have_records = true; - run_idb_to_launcher = false; - - if (!idb_to_launcher_in_progress) { - console.log('idb_to_launcher is NOT in progress'); - let idb_to_launcher_result = idb.idb_to_launcher().then(function(response) { - console.log('idb_to_launcher is complete... I think?'); - //console.log('*** idb_to_launcher response: *** Launcher object has now been created/updated with IDB data.'); - //console.log(response); - - //clearInterval(idb_to_launcher_loop); - - //launcher = response; - //safe_to_render_launcher = true; - run_render_launcher = true; - }); - idb_to_launcher_in_progress = true; - } else { - console.log('idb_to_launcher IS in progress'); - } - //console.log('*** idb_to_launcher_result: ***'); - //console.log(idb_to_launcher_result); - - } else { - console.log('Not all IDB tables have records. Setting flag to true update IDB database.'); - - idb_tables_have_records = false; - safe_to_render_launcher = false; - run_update_idb = true; - } - - } else { - //console.log('run_idb_to_launcher is set to false'); - } }, idb_to_launcher_loop_interval); var update_render_loop = setInterval(async function() { - //if (run_render_launcher) { - // console.log('Flag to run idb_to_launcher is set to true'); - current_plus10_datetime = Date.now() + 10000; // add 10 seconds - let enough_time_to_render = false; - if ( - current_plus10_datetime < idb_event_check_datetime - && current_plus10_datetime < idb_event_location_check_datetime - && current_plus10_datetime < idb_event_session_check_datetime - && current_plus10_datetime < idb_event_presentation_check_datetime - && current_plus10_datetime < idb_event_presenter_check_datetime - && current_plus10_datetime < idb_event_file_check_datetime - ) { - console.log('SETTING FLAG: enough_time_to_render=true'); - enough_time_to_render = true; - } else { - //console.log(current_plus10_datetime); - //console.log(idb_event_check_datetime); - //console.log(idb_event_location_check_datetime); - //console.log(idb_event_session_check_datetime); - //console.log(idb_event_presentation_check_datetime); - //console.log(idb_event_presenter_check_datetime); - //console.log(idb_event_file_check_datetime); - enough_time_to_render = false; - } - - console.log('FLAG: safe_to_render_launcher='+safe_to_render_launcher); - console.log('FLAG: enough_time_to_render='+enough_time_to_render); - if (safe_to_render_launcher && enough_time_to_render) { - //////////////let render_launcher_result = ui.render_launcher(launcher); - - run_render_launcher = false; // Set to true so that the launcher will be rendered again - safe_to_render_launcher = false; - } else { - } - - //} else { - // console.log('Flag to run idb_to_launcher is set to false'); - //} }, update_render_loop_interval); diff --git a/app/js/module_app_ui_v2.js b/app/js/module_app_ui_v2.js index a443a43..5ad254f 100644 --- a/app/js/module_app_ui_v2.js +++ b/app/js/module_app_ui_v2.js @@ -8,6 +8,7 @@ exports.render_event_records = function () { if (value.id == event_id) { console.log('*** Event id ('+event_id+') found in table.'); document.getElementById('event_name').innerHTML = '@'+value.name; + document.getElementById('event_files_menu').getElementsByTagName('ul')[0].id = 'event_files_list_'+value.id; } else { console.log('Event not it.'); } @@ -19,11 +20,140 @@ exports.render_event_records = function () { } -// This function is used to render all event file records to the UI. -// NOTE: The event_file table should probably only be looped through once when the table is actually updated. -// NOTE: Not each time the other objects (event, location, session, presentation, presenter) are updated. -exports.render_event_file_records = function (event_files, event_id) { - console.log('Rendering event file records...'); +// This function is used to render all event, location, session, presentation, and presenter file records to the UI. +exports.render_event_file_records = async function () { + console.log('Rendering all event, location, session, presentation, and presenter file records...'); + console.log('****************** Files ******************'); + + if (looping_tbl_event_file) { + console.log('Already looping through the tbl_event_file table. Not starting until finished.'); + return false; + } else { + + } + + looping_tbl_event_file = true; + + console.log('Iterating through the tbl_event_file table...'); + await tbl_event_file.iterate(function(value, key, iteration) { + let tbl_file_id = value.id; + let tbl_hosted_file_id = value.id; + let tbl_event_id = value.event_id; + let tbl_location_id = value.event_location_id; + let tbl_session_id = value.event_session_id; + let tbl_presentation_id = value.event_presentation_id; + let tbl_presenter_id = value.event_presenter_id; + let tbl_for_type = value.for_type; + let tbl_for_id = value.for_id; + let tbl_hash_sha256 = value.hash_sha256; + let tbl_filename = value.filename; // This could also be event_file_filename, internal_filename, private_filename, or public_filename + let tbl_size = value.size; + let tbl_created_on = value.created_on; + let tbl_internal_os = value.internal_os; + + console.log('tbl_event_file iteration='+iteration+' | tbl_file_id='+tbl_file_id+' for tbl_event_id='+tbl_event_id+' at location tbl_location_id='+tbl_location_id+'.'); + + if (tbl_event_id == event_id && tbl_for_type == 'event') { + console.log('EVENT FILE **************************'); + document.getElementById('event_files_menu').classList.remove('d-none'); + document.getElementById('event_files_menu').classList.add('d-block'); + } + + if (tbl_location_id == event_location_id && tbl_for_type == 'location') { + console.log('LOCATION FILE **************************'); + } + + if (tbl_event_id == event_id/* && tbl_location_id == event_location_id*/) { + console.log('Match for event_id='+event_id+' and event_location_id='+event_location_id); + event_file_li_node = document.getElementById('event_file_'+tbl_file_id); + if (event_file_li_node) { + console.log('event_file ('+tbl_file_id+') node found... check and remove/update.'); + + + + } else { + console.log('event_file ('+tbl_file_id+') node NOT found... check and add.'); + + let node_id = tbl_for_type+'_files_list_'+tbl_for_id; + console.log(node_id); + let parent_ul_node = document.getElementById(node_id); + console.log(parent_ul_node); + if (parent_ul_node) { + let file_li_node = document.createElement('LI'); + file_li_node.id = 'event_file_'+tbl_file_id; + file_li_node.className = 'list-group-item btn btn-primary d-flex justify-content-between align-items-center open_local_file event_file'; + file_li_node.setAttribute('data-file_id', tbl_file_id); + + + file_li_node.setAttribute('data-event_id', tbl_event_id); + file_li_node.setAttribute('data-location_id', tbl_location_id); + file_li_node.setAttribute('data-session_id', tbl_session_id); + file_li_node.setAttribute('data-presentation_id', tbl_presentation_id); + file_li_node.setAttribute('data-presenter_id', tbl_presenter_id); + + file_li_node.setAttribute('data-for_type', tbl_for_type); + file_li_node.setAttribute('data-for_id', tbl_for_id); + + file_li_node.setAttribute('data-hash_sha256', tbl_hash_sha256+'.file'); + file_li_node.setAttribute('data-filename', tbl_filename); + + + + + let file_fa_span_node = document.createElement('SPAN'); + file_fa_span_node.className = 'fas fa-external-link-alt'; + + let file_filename_span_node = document.createElement('SPAN'); + file_filename_span_node.className = 'filename'; + + let filename_text_node = document.createTextNode(tbl_filename); + file_filename_span_node.appendChild(filename_text_node); + + file_badge_span_node = document.createElement('SPAN'); + file_badge_span_node.className = 'badge badge-pill badge-light float-right'; + + let badge_text_node = document.createTextNode(format_bytes(tbl_size, 2)+'; '+dateFns.format(tbl_created_on, 'MMM M h:mm A')+'; '+tbl_internal_os); + file_badge_span_node.appendChild(badge_text_node); + + file_li_node.appendChild(file_fa_span_node); + file_li_node.appendChild(file_filename_span_node); + file_li_node.appendChild(file_badge_span_node); + + console.log(file_li_node); + + parent_ul_node.appendChild(file_li_node); + + } + + } + + } else { + console.log('This file ('+tbl_file_id+') is not part of this event and or location'); + console.log('tbl_event_id='+tbl_event_id+' ?= event_id='+event_id); + console.log('tbl_location_id='+tbl_location_id+' ?= event_location_id='+event_location_id); + } + /* + if (tbl_for_type == 'event') { + } else { + + } + + if (tbl_for_type == 'location') { + } else { + + } + */ + }).then(function() { + console.log('idb_to_ui: Iterate tbl_event_file looking for files to add is complete'); + looping_tbl_event_file = false; + }); + + return true; + + /* + xxx.classList.remove('d-none'); + xxx.classList.add('d-block'); + */ /* tbl_event_file.iterate(function(value, key, iteration) { if (value.id == event_id) { @@ -57,6 +187,15 @@ exports.render_event_location_records = async function () { if (value.id == event_location_id) { console.log('*** Event location id ('+event_location_id+') found in table.'); document.getElementById('location_name').innerHTML = ' '+value.name; + + document.getElementById('location_files_menu').getElementsByTagName('ul')[0].id = 'location_files_list_'+value.id; + /* + let location_files_ul_node = document.createElement('UL'); + location_files_ul_node.id = 'event_presentation_files_list_'+value.id; + location_files_ul_node.className = 'list-group list-group-flush location_files location_files_list event_files_list'; + + document.getElementById('location_files_menu').appendChild(location_files_ul_node); + */ } else { console.log('Event location not it.'); } @@ -65,6 +204,7 @@ exports.render_event_location_records = async function () { tbl_event_location_complete = true; }); + return true; } @@ -153,7 +293,7 @@ exports.render_event_session_records = async function () { files_body_div_node.className = 'card-body'; let files_body_ul_node = document.createElement('UL'); - files_body_ul_node.id = 'event_session_files_list_'+value.id; + files_body_ul_node.id = 'session_files_list_'+value.id; files_body_ul_node.className = 'list-group list-group-flush session_files_list event_files_list'; files_body_div_node.appendChild(files_body_ul_node); @@ -212,7 +352,7 @@ exports.render_event_session_records = async function () { if (session_list_items.length) { for (let i=0, len=session_list_items.length; i < len; i++) { - console.log('session_id='+session_list_items[i].getAttribute('data-session_id')); + console.log('Checking session_id='+session_list_items[i].getAttribute('data-session_id')); let session_id = session_list_items[i].getAttribute('data-session_id'); let session_valid = false; @@ -254,11 +394,11 @@ exports.render_event_session_file_records = function (events) { exports.render_event_presentation_records = async function (events) { - console.log('********** ********* ****** ** * ** ****** ********* *********'); console.log('Rendering event presentation records...'); + console.log('****************** Presentations ******************'); let launcher_sessions = document.getElementById('launcher_sessions').childNodes; //_list_items - console.log(launcher_sessions); + //console.log(launcher_sessions); for (let i=0, len=launcher_sessions.length; i < len; i++) { //for (let i in launcher_sessions) { @@ -266,7 +406,7 @@ exports.render_event_presentation_records = async function (events) { let session_id = launcher_sessions[i].getAttribute('data-session_id'); let presentations_list = launcher_sessions[i].getElementsByClassName('session_presentations')[0].getElementsByTagName('ul')[0].childNodes; - console.log(presentations_list); + //console.log(presentations_list); // First: update or delete presentations if (presentations_list.length) { @@ -379,7 +519,7 @@ exports.render_event_presentation_records = async function (events) { presentation_li_text_div_node.className = 'list-group-item-text'; let presentation_files_ul_group_node = document.createElement('UL'); - presentation_files_ul_group_node.id = 'event_presentation_files_list_'+value.id; + presentation_files_ul_group_node.id = 'presentation_files_list_'+value.id; presentation_files_ul_group_node.className = 'list-group list-group-flush presentation_files presentation_files_list event_files_list'; let presentation_presenters_ul_group_node = document.createElement('UL'); @@ -405,7 +545,7 @@ exports.render_event_presentation_records = async function (events) { document.getElementById('event_presentation_'+value.id).remove(); } catch(err) { - console.log('A node with the ID of event_presentation_'+value.id+' was not found.'); + console.log('A node with the ID of event_presentation_'+value.id+' was not found. In most cases this is expected.'); console.log(err.message); } @@ -452,27 +592,30 @@ exports.render_event_presenter_records = async function (events) { // First: Loop through the presenters table looking for presenters for each presentation list await tbl_event_presenter.iterate(function(value, key, iteration) { + let tbl_session_id = value.event_session_id; let tbl_presentation_id = value.event_presentation_id; let tbl_presenter_id = value.id; - console.log('presenter tbl iteration='+iteration+' | tbl_presenter_id='+tbl_presenter_id+' for tbl_presentation_id='+tbl_presentation_id); + console.log('tbl_event_presenter iteration='+iteration+' | tbl_presenter_id='+tbl_presenter_id+' for tbl_presentation_id='+tbl_presentation_id); + // Second: Loop through the presentations presenter UL placeholder (assumes there is a ul for presenters under each presentation) if (presentations_presenters_lists.length) { for (var i = 0; i < presentations_presenters_lists.length; i++) { let ul_session_id = presentations_presenters_lists[i].getAttribute('data-session_id'); let ul_presentation_id = presentations_presenters_lists[i].getAttribute('data-presentation_id'); - console.log('i='+i+' | ul_presentation_id='+ul_presentation_id); + console.log('presentation i='+i+' | ul_presentation_id='+ul_presentation_id); // Check if this presenter is part of this presentation let add_presenter_id = true; // Set flag to true. Update if found. Add if not found. - let remove_presenter_id = true; + let remove_presenter_id = true; // Set flag to true. Update if found. Add if not found. if (tbl_presentation_id == ul_presentation_id) { console.log('This tbl_presentation_id '+tbl_presentation_id+' matches this ul_presentation_id '+ul_presentation_id+'. Trying to loop through list of presenters to see if it needs to be updated or added...'); // Get a list of list items under the UL presenters node for a presentation let presentation_presenters_list_items = presentations_presenters_lists[i].children; + // Third: Loop through the presenters (LI) in a specific list under a presentation. if (presentation_presenters_list_items.length) { for (let j=0, len=presentation_presenters_list_items.length; j < len; j++) { - console.log('li_presenter_id='+presentation_presenters_list_items[j].getAttribute('data-presenter_id')); + console.log('Checking li_presenter_id='+presentation_presenters_list_items[j].getAttribute('data-presenter_id')); let li_presentation_id = presentation_presenters_list_items[j].getAttribute('data-presentation_id'); let li_presenter_id = presentation_presenters_list_items[j].getAttribute('data-presenter_id'); @@ -484,11 +627,11 @@ exports.render_event_presenter_records = async function (events) { add_presenter_id = false; remove_presenter_id = false; } else if (tbl_presentation_id != li_presentation_id ) { - console.log('Set flag to remove presenter ID '+li_presenter_id); - remove_presenter_id = true; + console.log('Set flag to add presenter ID '+li_presenter_id+' to false. Set flag to remove presenter ID '+li_presenter_id+' to true.'); + add_presenter_id = false; + remove_presenter_id = true; // The default is already set to true. Is this needed? } else { - // Remove presenter here????? - // NOTE: This section is not finished!!! + // NOTE: This section is not finished??? } } @@ -503,16 +646,28 @@ exports.render_event_presenter_records = async function (events) { } else { - // Remove presenter here????? - // NOTE: This section is not finished!!! + //NOTE: This probably needs to be reviewed again. + //console.log('This tbl_presentation_id '+tbl_presentation_id+' does not match this ul_presentation_id '+ul_presentation_id+'. Do not add presenter ID. ***But leave remove presenter ID as true???'); add_presenter_id = false; - //remove_presenter_id = true; + remove_presenter_id = false; } // The presenter ID was not found. Need to add. if ( add_presenter_id ) { console.log('Adding this presenter ('+tbl_presenter_id+') to the list of presenters for this presentation ('+ul_presentation_id+').'); + + // Trying to remove old ID in case there is one already rendered + console.log('Trying to remove an old presenter LI node if it exists...'); + try { + document.getElementById('event_presenter_'+tbl_presenter_id).remove(); + } + catch(err) { + //console.log('A node with the ID of event_presenter_'+tbl_presenter_id+' was not found.'); + console.log('This presenter list item node was not found. In most cases this is expected.'); + console.log(err.message); + } + let presenter_li_node = document.createElement('LI'); presenter_li_node.id = 'event_presenter_'+tbl_presenter_id; presenter_li_node.className = 'list-group-item event_presenter'; @@ -530,19 +685,13 @@ exports.render_event_presenter_records = async function (events) { let presentation_presenters_ul_group_node = document.createElement('UL'); - presentation_presenters_ul_group_node.id = 'event_presentation_presenter_files_'+tbl_presenter_id; + presentation_presenters_ul_group_node.id = 'presenter_files_list_'+tbl_presenter_id; presentation_presenters_ul_group_node.className = 'list-group list-group-flush list-group-item-text presenter_files presenter_files_list event_files_list'; presentation_presenters_ul_group_node.setAttribute('data-presenter_id', tbl_presenter_id); presenter_li_node.appendChild(presentation_presenters_ul_group_node); - console.log('BEFORE appendChild:'); - console.log(document.getElementById('event_presentation_presenters_'+tbl_presentation_id)); document.getElementById('event_presentation_presenters_'+tbl_presentation_id).appendChild(presenter_li_node); - console.log('AFTER appendChild:'); - console.log(document.getElementById('event_presentation_presenters_'+tbl_presentation_id)); - //document.getElementById('event_presentation_presenters_'+tbl_presentation_id).innerHTML = 'WTF'; - //document.getElementById('event_presentation_presenters_'+tbl_presentation_id).appendChild(presentation_presenters_ul_group_node); remove_presenter_id = false; } else { @@ -556,24 +705,24 @@ exports.render_event_presenter_records = async function (events) { console.log('Removing this presenter ('+tbl_presenter_id+') from the list of presenters for this presentation ('+ul_presentation_id+').'); // Trying to remove old ID in case there is one already rendered + console.log('Trying to remove a presenter LI node...'); try { - presentations_presenters_lists[i].remove(); - //document.getElementById('event_presentation_'+tbl_presenter_id).getElementById('event_presenter_'+tbl_presenter_id).remove(); + document.getElementById('event_presenter_'+tbl_presenter_id).remove(); } catch(err) { //console.log('A node with the ID of event_presenter_'+tbl_presenter_id+' was not found.'); - console.log('This presenter list item node was not found.'); + console.log('This presenter list item node was not found. In some cases this is expected.'); console.log(err.message); } } } else { - console.log('This presenter ('+tbl_presenter_id+') is already part of the list of presenters for this presentation ('+ul_presentation_id+') and is correct.'); + //console.log('This presenter ('+tbl_presenter_id+') is already part of the list of presenters for this presentation ('+ul_presentation_id+') and is correct.'); } } } else { - console.log('No list of presenters found under any presentations'); + console.log('No UL placeholder list for presenters found under any presentations. Something might have gone wrong?'); } }).then(function() { console.log('idb_to_ui: Iterate tbl_event_presenter looking for presenters to update, add, or remove is complete'); diff --git a/config.json b/config.json index 765d6b7..0ad9a36 100644 --- a/config.json +++ b/config.json @@ -34,8 +34,8 @@ "idb_event_location_check_period": 90000, "idb_event_session_check_period": 90000, "idb_event_presentation_check_period": 90000, - "idb_event_presenter_check_period": 30000, - "idb_event_file_check_period": 60000, + "idb_event_presenter_check_period": 60000, + "idb_event_file_check_period": 30000, "host_file_cache_path": "file_cache", "host_file_cache_check_period": 30000, "display_arrangement": "mirror_and_extend",