185 lines
10 KiB
JavaScript
185 lines
10 KiB
JavaScript
//exports.render_event_presentation_records = async function (events) {
|
|
async function render_event_presentation_records(events) {
|
|
console.log('Rendering event presentation records...');
|
|
console.log('****************** Presentations ******************');
|
|
|
|
if (looping_tbl_event_presentation) {
|
|
console.log('Already looping through the tbl_event_presentation table. Not starting until finished.');
|
|
return false;
|
|
} else {
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
presentation_li_node.title = 'id='+value.id+' session_id='+value.event_session_id+' 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 = '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. In most cases this is expected.');
|
|
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;
|
|
}
|