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

@@ -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);
// 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;
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);
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');
if ( presenter_id == li_presenter_id ) {
// Update the presenter information
add_presenter_id = false;
} else {
// Remove presenter here?????
// NOTE: This section is not finished!!!
// 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;
}
} 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';
// 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_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 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+').');
}
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);
// 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.');
}
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;
}