Fixed bug of an ID being set wrong. Still need to finish presenters and everything related to files.

This commit is contained in:
Scott Idem
2020-02-12 14:15:23 -05:00
parent 85b268c0b8
commit 2d87ccfa73
3 changed files with 774 additions and 73 deletions

View File

@@ -266,7 +266,9 @@
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_session = false;
let looping_tbl_event_presentation = false;
let looping_tbl_event_presenter = false;
//const loading_loop_interval = app_config.loading_loop_interval; // in milliseconds
@@ -416,6 +418,8 @@
run_idb_to_launcher = true; // Set to true so that the launcher object is rebuilt
safe_to_render_launcher = false; // Set to false so that the launcher render only starts after the launcher object has updated
idb_event_presenter_check_datetime = Date.now() + idb_event_presenter_check_period;
let render_event_presenter_records_result = await uiv2.render_event_presenter_records(); // NOTE: v2 idb to ui
}
if (idb_event_file_check_datetime < Date.now()) {
@@ -428,8 +432,6 @@
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_presenter_records_result = await uiv2.render_event_presenter_records(); // NOTE: v2 idb to ui
}

View File

@@ -0,0 +1,639 @@
exports.render_event_records = function () {
console.log('Rendering event records...');
//console.log(tbl_event);
//console.log(event_id);
tbl_event.iterate(function(value, key, iteration) {
if (value.id == event_id) {
console.log('*** Event id ('+event_id+') found in table.');
document.getElementById('event_name').innerHTML = '@'+value.name;
} else {
console.log('Event not it.');
}
}).then(function() {
console.log('idb_to_ui: Iterate tbl_event_file complete')
tbl_event_complete = true;
});
}
// 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...');
/*
tbl_event_file.iterate(function(value, key, iteration) {
if (value.id == event_id) {
console.log('This event file ('+value.id+') is part of the this event ('+event_id+').');
document.getElementById('event_name').innerHTML = '@'+value.name;
} else {
console.log('This event file ('+value.id+') is NOT part of the this event ('+event_id+').');
}
}).then(function() {
console.log('idb_to_ui: Iterate tbl_event_file complete')
tbl_event_complete = true;
});
document.getElementById('event_files_menu').innerHTML = '<h2>Event Files</h2>';
document.getElementById('event_files_menu').innerHTML += '<ul class="list-group list-group-flush">';
for (var i in launcher_tmp.event_file) {
document.getElementById('event_files_menu').innerHTML += '<li id="menu_event_file_'+launcher_tmp.event_file[i].event_file_id+'" class="list-group-item btn btn-secondary d-flex justify-content-between align-items-center open_local_file" data-hash_sha256="'+launcher_tmp.event_file[i].hash_sha256+'.file" data-filename="'+launcher_tmp.event_file[i].event_file_filename+'">'+launcher_tmp.event_file[i].event_file_filename+'</li>';
}
document.getElementById('event_files_menu').innerHTML += '</ul>';
*/
}
exports.render_event_location_records = async function () {
console.log('Rendering event location records...');
await tbl_event_location.iterate(function(value, key, iteration) {
if (value.id == event_location_id) {
console.log('*** Event location id ('+event_location_id+') found in table.');
document.getElementById('location_name').innerHTML = '<span class="fas fa-map-marker"></span> '+value.name;
} else {
console.log('Event location not it.');
}
}).then(function() {
console.log('idb_to_ui: Iterate tbl_event_file complete')
tbl_event_location_complete = true;
});
}
exports.render_event_location_file_records = function (events) {
console.log('Rendering event location file records...');
}
exports.render_event_session_records = async function () {
console.log('Rendering event session records...');
// First: update or add sessions
tbl_event_session.iterate(function(value, key, iteration) {
if (value.event_id == event_id && value.event_location_id == event_location_id) {
console.log('*** Event session id ('+value.id+') is part of this event location.');
// *** ** * Checking if the session is already in the launcher menu * ** ***
if (document.getElementById('menu_event_session_'+value.id)) {
// Update the session menu list item
document.getElementById('menu_event_session_'+value.id).innerHTML = value.name;
} else {
// Unhide the sessions menu
if (document.getElementById('sessions_menu').classList.contains('d-none') ) {
document.getElementById('sessions_menu').classList.remove('d-none');
document.getElementById('sessions_menu').classList.add('d-block');
}
// Add the new session to the session menu
let node = document.createElement('LI');
node.id = 'menu_event_session_'+value.id;
node.className = 'list-group-item btn btn-info d-flex justify-content-between align-items-center btn_view_session';
node.setAttribute('data-session_id', value.id);
let text_node = document.createTextNode(value.name);
node.appendChild(text_node);
document.getElementById('sessions_menu').getElementsByTagName('ul')[0].appendChild(node);
}
let session_startdatetime = new Date(value.start_datetime);
// *** ** * Checking if the session is already in the launcher sessions detail * ** ***
if (document.getElementById('detail_session_'+value.id)) {
// Update the launcher sessions list
// NOTE: Updating this text is very awkward?
document.getElementById('detail_session_'+value.id).getElementsByTagName('h2')[0].firstChild.data = value.name;
console.log(document.getElementById('detail_session_'+value.id).getElementsByTagName('h2')[0]);
document.getElementById('detail_session_'+value.id).getElementsByTagName('h2')[0].getElementsByTagName('span')[0].innerHTML = dateFns.format(session_startdatetime, 'ddd h:mm A');
} else {
// Add the new session to the launcher sessions list
let div_node = document.createElement('DIV');
div_node.id = 'detail_session_'+value.id;
div_node.className = 'container d-none session_detail event_session';
div_node.setAttribute('data-session_id', value.id);
let h2_node = document.createElement('H2');
h2_node.className = 'session_title d-flex justify-content-between align-items-center';
// NOTE: Instead of a text node should this just be wrapped in a set of tags?
// Updating this is kind of awkward... see above
let h2_text_node = document.createTextNode(value.name);
h2_node.appendChild(h2_text_node);
let h2_span_node = document.createElement('SPAN');
h2_span_node.className = 'badge badge-pill badge-info';
let h2_span_text_node = document.createTextNode(dateFns.format(session_startdatetime, 'ddd h:mm A'));
h2_span_node.appendChild(h2_span_text_node);
h2_node.appendChild(h2_span_node);
div_node.appendChild(h2_node);
// Add placeholder cards for session files and session presentations
// Files
let files_div_node = document.createElement('DIV');
files_div_node.id = 'event_session_files_'+value.id;
files_div_node.className = 'card session_files';
let files_header_div_node = document.createElement('DIV');
files_header_div_node.className = 'card-header';
let files_header_text_node = document.createTextNode('Session Files:');
files_header_div_node.appendChild(files_header_text_node);
let files_body_div_node = document.createElement('DIV');
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.className = 'list-group list-group-flush session_files_list event_files_list';
files_body_div_node.appendChild(files_body_ul_node);
files_div_node.appendChild(files_header_div_node);
files_div_node.appendChild(files_body_div_node);
div_node.appendChild(files_div_node);
// Presentations
let presentations_div_node = document.createElement('DIV');
presentations_div_node.id = 'session_presentations_'+value.id;
presentations_div_node.className = 'card session_presentations';
let presentations_header_div_node = document.createElement('DIV');
presentations_header_div_node.className = 'card-header';
let presentations_header_text_node = document.createTextNode('Presentations:');
presentations_header_div_node.appendChild(presentations_header_text_node);
let presentations_body_div_node = document.createElement('DIV');
presentations_body_div_node.className = 'card-body';
let presentations_body_ul_node = document.createElement('UL');
presentations_body_ul_node.id = 'session_presentations_list_'+value.id;
presentations_body_ul_node.className = 'list-group list-group-flush session_presentations_list';
presentations_body_ul_node.setAttribute('data-session_id', value.id);
presentations_body_div_node.appendChild(presentations_body_ul_node);
presentations_div_node.appendChild(presentations_header_div_node);
presentations_div_node.appendChild(presentations_body_div_node);
div_node.appendChild(presentations_div_node);
document.getElementById('launcher_sessions').appendChild(div_node);
}
} else {
//console.log('Event session not it.');
}
}).then(function() {
console.log('idb_to_ui: Iterate tbl_event_session complete');
tbl_event_session_complete = true;
}).then(function() {
// Second: remove sessions from the launcher sessions menu and sessions list
// This is basing the removal of sessions only on the menu list of sessions.
// In theory this should be safe as long as nothing gets out sync...
console.log('Looking for removed sessions...');
let session_list_items = document.getElementById('sessions_menu').getElementsByTagName('ul')[0].childNodes;
//console.log(session_list_items);
let session_list = document.getElementById('sessions_menu').getElementsByTagName('ul')[0].children;
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'));
let session_id = session_list_items[i].getAttribute('data-session_id');
let session_valid = false;
tbl_event_session.iterate(function(value, key, iteration) {
//console.log(value.event_id+' ?= '+event_id+' : '+value.event_location_id+' ?= '+event_location_id+' : '+value.id+' ?= '+session_id);
if (value.event_id == event_id && value.event_location_id == event_location_id && value.id == session_id) {
// The session is still part of the event and the location
session_valid = true;
} else {
// The session is no longer part of the event and or the location
//console.log('Need to remove session id '+session_id);
}
}).then(function() {
console.log('idb_to_ui: Iterate tbl_event_session looking for sessions to remove is complete')
if (session_valid) {
//console.log('Keep session id '+session_id);
} else {
console.log('Remove session id '+session_id);
document.getElementById('menu_event_session_'+session_id).remove(); // Remove the node from the launcher sessions menu list
document.getElementById('detail_session_'+session_id).remove(); // Remove the node from the launcher sessions list
}
});
}
}
});
// Third: re-index view session buttons
// NOTE: Should this go in a .then() section?
// NOTE: It might make even more sense to only have this done individually per add. Should also do a remove to keep things clean.
//index_launcher_sessions('btn_view_session');
index_launcher_sessions('btn_view_session');
}
exports.render_event_session_file_records = function (events) {
console.log('Rendering event session file records...');
}
exports.render_event_presentation_records = async function (events) {
console.log('********** ********* ****** ** * ** ****** ********* *********');
console.log('Rendering event presentation records...');
let launcher_sessions = document.getElementById('launcher_sessions').childNodes; //_list_items
console.log(launcher_sessions);
for (let i=0, len=launcher_sessions.length; i < len; i++) {
//for (let i in launcher_sessions) {
console.log('Current launcher session_id='+launcher_sessions[i].getAttribute('data-session_id'));
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);
// First: update or delete presentations
if (presentations_list.length) {
console.log('Presentations listed under this session (id='+session_id+'). (launcher sessions loop i = '+i+')');
console.log(launcher_sessions[i].getElementsByClassName('session_presentations')[0].getElementsByTagName('ul'));
for (let j=0, len=presentations_list.length; j < len; j++) {
console.log('Current launcher presentation_id='+presentations_list[j].getAttribute('data-presentation_id'));
let presentation_id = presentations_list[j].getAttribute('data-presentation_id');
await tbl_event_presentation.iterate(function(value, key, iteration) {
//console.log('*** 1: session_id='+session_id+' | presentation.event_session_id='+value.event_session_id+' | presentation_id='+presentation_id+' | presentation.id='+value.id+' (launcher sessions loop i='+i+')');
looping_tbl_event_presentation = true;
if (session_id == value.event_session_id && presentation_id == value.id) {
// Found presentation in that session. Updating...
console.log('Presentation ('+presentation_id+') was found in the session ('+session_id+'). Updating...');
document.getElementById('event_presentation_'+value.id).getElementsByTagName('div')[0].getElementsByTagName('strong')[0].innerHTML = value.name;
let presentation_startdatetime = new Date(value.start_datetime);
document.getElementById('event_presentation_'+value.id).getElementsByTagName('div')[0].getElementsByTagName('span')[0].innerHTML = dateFns.format(presentation_startdatetime, 'h:mm A');
} else if (session_id != value.event_session_id && presentation_id == value.id) {
// Found presentation in a session that it should not be in. Removing...
console.log('Presentation exists but should not be part of this session. Removing...');
console.log('*** Presentation id ('+value.id+') is NOT part of this session ('+session_id+'). (launcher sessions loop i='+i+')');
document.getElementById('event_presentation_'+presentation_id).remove(); // Remove the node from the launcher presentations list
} else {
//console.log('Not doing anything');
}
}).then(function() {
console.log('idb_to_ui: Iterate tbl_event_presentation looking for presentations to update or remove is complete');
looping_tbl_event_presentation = false;
});
}
} else { // Close for if presentations_list.length
} // Close for if presentations_list.length
// Now that the updates and removals have been done we need to add presentations.
await tbl_event_presentation.iterate(function(value, key, iteration) {
//console.log('*** 2: session_id='+session_id+' | presentation.event_session_id='+value.event_session_id+' | presentation.id='+value.id+' (launcher sessions loop i='+i+')');
looping_tbl_event_presentation = true;
let add_presentation = true;
if (session_id == value.event_session_id) {
// This presentation should be part of the session. Adding if not there...
presentations_list = launcher_sessions[i].getElementsByClassName('session_presentations')[0].getElementsByTagName('ul')[0].childNodes;
console.log(presentations_list);
if (presentations_list.length) {
// One more presentations are already in this session.
// Need to check if this one needs to be added.
for (let j=0, len=presentations_list.length; j < len; j++) {
let presentation_id = presentations_list[j].getAttribute('data-presentation_id');
if (presentation_id == value.id) {
// Nothing here so it for sure needs to be added.
add_presentation = false;
} else {
// Don't reset the add_presentation back to true
}
}
} else {
// Nothing here, so it for sure needs to be added.
//add_presentation = true;
}
} else {
add_presentation = false;
}
if (add_presentation) {
// Presentation not found. Adding...
console.log('Presentation was not found in the session but should be. Adding...');
console.log('Presentation id ('+value.id+') is part of this session ('+session_id+'). (launcher sessions loop i='+i+')');
// Add the new presentation to the launcher presentation list
let presentation_li_node = document.createElement('LI');
presentation_li_node.id = 'event_presentation_'+value.id;
presentation_li_node.className = 'list-group-item event_presentation';
presentation_li_node.setAttribute('data-session_id', value.event_session_id);
presentation_li_node.setAttribute('data-presentation_id', value.id);
let presentation_li_heading_div_node = document.createElement('DIV');
presentation_li_heading_div_node.className = 'list-group-item-heading d-flex justify-content-between align-items-center';
let presentation_name_strong_node = document.createElement('STRONG');
let presentation_name_text_node= document.createTextNode(value.name);
presentation_name_strong_node.appendChild(presentation_name_text_node);
let presentation_heading_span_node = document.createElement('SPAN');
presentation_heading_span_node.className = 'badge badge-pill badge-info';
let presentation_startdatetime = new Date(value.start_datetime);
let presentation_heading_span_text_node = document.createTextNode(dateFns.format(presentation_startdatetime, 'h:mm A'));
presentation_heading_span_node.appendChild(presentation_heading_span_text_node);
presentation_li_heading_div_node.appendChild(presentation_name_strong_node);
presentation_li_heading_div_node.appendChild(presentation_heading_span_node);
let presentation_li_text_div_node = document.createElement('DIV');
//presentation_li_text_div_node.id = 'event_presentation_files_'+value.id;
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.className = 'list-group list-group-flush presentation_files presentation_files_list event_files_list';
let presentation_presenters_ul_group_node = document.createElement('UL');
presentation_presenters_ul_group_node.id = 'event_presentation_presenters_'+value.id;
presentation_presenters_ul_group_node.className = 'list-group list-group-flush presentation_presenters presentation_presenters_list';
presentation_presenters_ul_group_node.setAttribute('data-session_id', value.event_session_id);
presentation_presenters_ul_group_node.setAttribute('data-presentation_id', value.id);
presentation_li_text_div_node.appendChild(presentation_files_ul_group_node);
presentation_li_text_div_node.appendChild(presentation_presenters_ul_group_node);
presentation_li_node.appendChild(presentation_li_heading_div_node);
presentation_li_node.appendChild(presentation_li_text_div_node);
//console.log(launcher_sessions[i].getElementsByClassName('session_presentations'));
let launcher_session_details = document.getElementById('detail_session_'+session_id);
//console.log(launcher_session_details.getElementsByClassName('session_presentations'));
// Trying to remove old ID in case there is one already rendered
try {
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(err.message);
}
let session = document.getElementById('detail_session_'+session_id).getElementsByClassName('session_presentations')[0].getElementsByTagName('ul')[0].appendChild(presentation_li_node);
presentation_id_found = true;
} else {
// Presentation not part of this session. Moving on...
//console.log('Presentation was not found in the session and should not be. Moving on...');
//console.log('*** Presentation id ('+value.id+') is not part of this session ('+session_id+'). (launcher sessions loop i='+i+')');
}
}).then(function() {
console.log('idb_to_ui: Iterate tbl_event_presentation looking for presentations to add is complete');
looping_tbl_event_presentation = false;
});
}
return true;
}
exports.render_event_presention_file_records = function (events) {
console.log('Rendering event presentation file records...');
}
exports.render_event_presenter_records = async function (events) {
console.log('Rendering event presenter records...');
console.log('****************** Presenters ******************');
if (looping_tbl_event_presenter) {
console.log('Already looping through the tbl_event_presenter table. Not starting until finished.');
return false;
} else {
}
looping_tbl_event_presenter = true;
let presentations_presenters_lists = document.getElementsByClassName('presentation_presenters'); // from the UL nodes for presenters
console.log(presentations_presenters_lists);
// First: Loop through the presenters table looking for presenters for each presentation list
await tbl_event_presenter.iterate(function(value, key, iteration) {
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);
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);
// 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;
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;
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'));
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');
if ( tbl_presentation_id == li_presentation_id && tbl_presenter_id == li_presenter_id ) {
console.log('Updating presenter ID '+li_presenter_id);
// Update the presenter information
document.getElementById('event_presenter_'+tbl_presenter_id).getElementsByClassName('presenter_name')[0].innerHTML = value.given_name+' '+value.family_name;
// Could have used getElementsByTagName('strong') instead
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;
} else {
// Remove presenter here?????
// NOTE: This section is not finished!!!
}
}
} else {
// No need to remove anything if the list is empty.
console.log('Ignoring this presentation\'s list ('+ul_presentation_id+') of presenters because it is empty. Adding this presenter ('+tbl_presenter_id+') to the list...');
add_presenter_id = true; // Technically this line is not needed since the value was initialized to true.
remove_presenter_id = false;
}
} else {
// Remove presenter here?????
// NOTE: This section is not finished!!!
add_presenter_id = false;
//remove_presenter_id = true;
}
// 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+').');
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';
presenter_li_node.setAttribute('data-session_id', value.event_session_id);
presenter_li_node.setAttribute('data-presentation_id', ul_presentation_id);
presenter_li_node.setAttribute('data-presenter_id', tbl_presenter_id);
let presenter_name_strong_node = document.createElement('STRONG');
presenter_name_strong_node.className = 'list-group-item-heading presenter_name';
let presenter_name_text_node= document.createTextNode(value.given_name+' '+value.family_name);
presenter_name_strong_node.appendChild(presenter_name_text_node);
presenter_li_node.appendChild(presenter_name_strong_node);
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.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 {
//console.log('Not going to add this presenter ('+tbl_presenter_id+') to the list of presenters for this presentation ('+ul_presentation_id+').');
}
// The presenter ID was found, but not part of this presentation. Need to remove.
if ( remove_presenter_id ) {
if ( ul_presentation_id != tbl_presentation_id ) {
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
try {
presentations_presenters_lists[i].remove();
//document.getElementById('event_presentation_'+tbl_presenter_id).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(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.');
}
}
} else {
console.log('No list of presenters found under any presentations');
}
}).then(function() {
console.log('idb_to_ui: Iterate tbl_event_presenter looking for presenters to update, add, or remove is complete');
looping_tbl_event_presenter = false;
});
return true;
}
exports.render_event_presenter_file_records = function (events) {
console.log('Rendering event presenter file records...');
}
/* Updated 2020-01-31 */
function index_launcher_sessions(class_name) {
console.log('Indexing launcher sessions with class name: '+class_name);
var class_elements = document.getElementsByClassName(class_name);
for (var i = 0; i < class_elements.length; i++) {
class_elements[i].addEventListener( 'click', function() {view_session( this.getAttribute('data-session_id')) } );
}
console.log(class_elements);
return true;
}
/* Updated 2020-01-31 */
function view_session(session_id) {
var class_elements = document.getElementsByClassName('session_detail'); // This class name should be the class names for each div container
console.log('View session ID: '+session_id);
for (var i = 0; i < class_elements.length; i++) {
//console.log('*** checking: '+class_elements[i].getAttribute('data-session_id'));
if (class_elements[i].getAttribute('data-session_id') == session_id) {
//console.log('show');
class_elements[i].classList.remove('d-none');
class_elements[i].classList.add('d-block');
} else {
//console.log('hide');
class_elements[i].classList.remove('d-block');
class_elements[i].classList.add('d-none');
}
}
return true;
}
function format_bytes(bytes, decimals = 2) {
if (bytes === 0) return '0 Bytes';
const k = 1024;
const dm = decimals < 0 ? 0 : decimals;
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
}

View File

@@ -24,7 +24,7 @@ exports.render_event_records = function () {
// 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...');
/*
tbl_event_file.iterate(function(value, key, iteration) {
if (value.id == event_id) {
console.log('This event file ('+value.id+') is part of the this event ('+event_id+').');
@@ -45,7 +45,7 @@ exports.render_event_file_records = function (event_files, event_id) {
}
document.getElementById('event_files_menu').innerHTML += '</ul>';
*/
}
@@ -194,7 +194,7 @@ exports.render_event_session_records = async function () {
}
} else {
console.log('Event session not it.');
//console.log('Event session not it.');
}
}).then(function() {
console.log('idb_to_ui: Iterate tbl_event_session complete');
@@ -278,11 +278,11 @@ exports.render_event_presentation_records = async function (events) {
let presentation_id = presentations_list[j].getAttribute('data-presentation_id');
await tbl_event_presentation.iterate(function(value, key, iteration) {
console.log('*** 1: session_id='+session_id+' | presentation.event_session_id='+value.event_session_id+' | presentation_id='+presentation_id+' | presentation.id='+value.id+' (launcher sessions loop i='+i+')');
//console.log('*** 1: session_id='+session_id+' | presentation.event_session_id='+value.event_session_id+' | presentation_id='+presentation_id+' | presentation.id='+value.id+' (launcher sessions loop i='+i+')');
looping_tbl_event_presentation = true;
if (session_id == value.event_session_id && presentation_id == value.id) {
// Found presentation in that session. Updating...
console.log('Presentation was found in the session. Updating...');
console.log('Presentation ('+presentation_id+') was found in the session ('+session_id+'). Updating...');
document.getElementById('event_presentation_'+value.id).getElementsByTagName('div')[0].getElementsByTagName('strong')[0].innerHTML = value.name;
let presentation_startdatetime = new Date(value.start_datetime);
document.getElementById('event_presentation_'+value.id).getElementsByTagName('div')[0].getElementsByTagName('span')[0].innerHTML = dateFns.format(presentation_startdatetime, 'h:mm A');
@@ -311,7 +311,7 @@ exports.render_event_presentation_records = async function (events) {
// Now that the updates and removals have been done we need to add presentations.
await tbl_event_presentation.iterate(function(value, key, iteration) {
console.log('*** 2: session_id='+session_id+' | presentation.event_session_id='+value.event_session_id+' | presentation.id='+value.id+' (launcher sessions loop i='+i+')');
//console.log('*** 2: session_id='+session_id+' | presentation.event_session_id='+value.event_session_id+' | presentation.id='+value.id+' (launcher sessions loop i='+i+')');
looping_tbl_event_presentation = true;
let add_presentation = true;
@@ -352,6 +352,7 @@ exports.render_event_presentation_records = async function (events) {
let presentation_li_node = document.createElement('LI');
presentation_li_node.id = 'event_presentation_'+value.id;
presentation_li_node.className = 'list-group-item event_presentation';
presentation_li_node.setAttribute('data-session_id', value.event_session_id);
presentation_li_node.setAttribute('data-presentation_id', value.id);
let presentation_li_heading_div_node = document.createElement('DIV');
@@ -373,7 +374,7 @@ exports.render_event_presentation_records = async function (events) {
presentation_li_heading_div_node.appendChild(presentation_heading_span_node);
let presentation_li_text_div_node = documerender_event_file_recordsnt.createElement('DIV');
let presentation_li_text_div_node = document.createElement('DIV');
//presentation_li_text_div_node.id = 'event_presentation_files_'+value.id;
presentation_li_text_div_node.className = 'list-group-item-text';
@@ -384,6 +385,7 @@ exports.render_event_presentation_records = async function (events) {
let presentation_presenters_ul_group_node = document.createElement('UL');
presentation_presenters_ul_group_node.id = 'event_presentation_presenters_'+value.id;
presentation_presenters_ul_group_node.className = 'list-group list-group-flush presentation_presenters presentation_presenters_list';
presentation_presenters_ul_group_node.setAttribute('data-session_id', value.event_session_id);
presentation_presenters_ul_group_node.setAttribute('data-presentation_id', value.id);
presentation_li_text_div_node.appendChild(presentation_files_ul_group_node);
@@ -436,91 +438,149 @@ exports.render_event_presenter_records = async function (events) {
console.log('Rendering event presenter records...');
console.log('****************** Presenters ******************');
let session_presentations_lists = document.getElementsByClassName('presentation_presenters'); // from the UL nodes for presenters
console.log(session_presentations_lists);
if (looping_tbl_event_presenter) {
console.log('Already looping through the tbl_event_presenter table. Not starting until finished.');
return false;
} else {
}
looping_tbl_event_presenter = true;
let presentations_presenters_lists = document.getElementsByClassName('presentation_presenters'); // from the UL nodes for presenters
console.log(presentations_presenters_lists);
// First: Loop through the presenters table looking for presenters for each presentation list
await tbl_event_presenter.iterate(function(value, key, iteration) {
let presenter_id = value.id;
console.log('presenter_id='+presenter_id);
for (var i = 0; i < session_presentations_lists.length; i++) {
let presentation_id = session_presentations_lists[i].getAttribute('data-presentation_id');
console.log('presentation_id='+presentation_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);
// 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.
if (presentation_id == value.event_presentation_id) {
// Get a list of list items under the UL presenters node for a presentation
let presentation_presenters_list_items = session_presentations_lists[i].children;
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);
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'));
let li_presenter_id = presentation_presenters_list_items[j].getAttribute('data-presenter_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;
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;
if ( presenter_id == li_presenter_id ) {
// Update the presenter information
add_presenter_id = false;
} else {
// Remove presenter here?????
// NOTE: This section is not finished!!!
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'));
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');
if ( tbl_presentation_id == li_presentation_id && tbl_presenter_id == li_presenter_id ) {
console.log('Updating presenter ID '+li_presenter_id);
// Update the presenter information
document.getElementById('event_presenter_'+tbl_presenter_id).getElementsByClassName('presenter_name')[0].innerHTML = value.given_name+' '+value.family_name;
// Could have used getElementsByTagName('strong') instead
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;
} else {
// Remove presenter here?????
// NOTE: This section is not finished!!!
}
}
} else {
// No need to remove anything if the list is empty.
console.log('Ignoring this presentation\'s list ('+ul_presentation_id+') of presenters because it is empty. Adding this presenter ('+tbl_presenter_id+') to the list...');
add_presenter_id = true; // Technically this line is not needed since the value was initialized to true.
remove_presenter_id = false;
}
} else {
// Remove presenter here?????
// NOTE: This section is not finished!!!
add_presenter_id = false;
//remove_presenter_id = true;
}
// 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+').');
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';
presenter_li_node.setAttribute('data-session_id', value.event_session_id);
presenter_li_node.setAttribute('data-presentation_id', ul_presentation_id);
presenter_li_node.setAttribute('data-presenter_id', tbl_presenter_id);
let presenter_name_strong_node = document.createElement('STRONG');
presenter_name_strong_node.className = 'list-group-item-heading presenter_name';
let presenter_name_text_node= document.createTextNode(value.given_name+' '+value.family_name);
presenter_name_strong_node.appendChild(presenter_name_text_node);
presenter_li_node.appendChild(presenter_name_strong_node);
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.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 {
//console.log('Not going to add this presenter ('+tbl_presenter_id+') to the list of presenters for this presentation ('+ul_presentation_id+').');
}
// The presenter ID was found, but not part of this presentation. Need to remove.
if ( remove_presenter_id ) {
if ( ul_presentation_id != tbl_presentation_id ) {
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
try {
presentations_presenters_lists[i].remove();
//document.getElementById('event_presentation_'+tbl_presenter_id).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(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.');
}
} else {
// Remove presenter here?????
// NOTE: This section is not finished!!!
add_presenter_id = false;
}
// The presenter ID was not found. Need to add.
if ( add_presenter_id ) {
console.log('Adding this presenter ('+presenter_id+') to the list of presenters for this presentation ('+presentation_id+')');
let presenter_li_node = document.createElement('LI');
presenter_li_node.id = 'event_presenter_'+presenter_id;
presenter_li_node.className = 'list-group-item event_presenter';
presenter_li_node.setAttribute('data-presenter_id', presenter_id);
let presenter_name_strong_node = document.createElement('STRONG');
presenter_name_strong_node.className = 'list-group-item-heading presenter_name';
let presenter_name_text_node= document.createTextNode(value.given_name+' '+value.family_name);
presenter_name_strong_node.appendChild(presenter_name_text_node);
presenter_li_node.appendChild(presenter_name_strong_node);
let presentation_presenters_ul_group_node = document.createElement('UL');
presentation_presenters_ul_group_node.id = 'event_presentation_presenter_files_'+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', presenter_id);
presenter_li_node.appendChild(presentation_presenters_ul_group_node);
console.log(document.getElementById('event_presentation_presenters_'+presentation_id));
document.getElementById('event_presentation_presenters_'+presentation_id).appendChild(presenter_li_node);
//document.getElementById('event_presentation_presenters_'+presentation_id).appendChild(presentation_presenters_ul_group_node);
} else {
console.log('This presenter ('+presenter_id+') is already part of the list of presenters for this presentation ('+presentation_id+')');
}
} else {
console.log('No list of presenters found under any presentations');
}
}).then(function() {
console.log('idb_to_ui: Iterate tbl_event_presenter looking for presenters to??????? update or remove is complete');
looping_tbl_event_presentation = false;
console.log('idb_to_ui: Iterate tbl_event_presenter looking for presenters to update, add, or remove is complete');
looping_tbl_event_presenter = false;
});
return true;
}