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; }); } // 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('*** 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; }); document.getElementById('event_files_menu').innerHTML = '

Event Files

'; document.getElementById('event_files_menu').innerHTML += ''; */ } exports.render_event_location_records = function () { console.log('Rendering event location records...'); 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 = ' '+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 = 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'; 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); 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); //console.log(session_list_items.length); for (var i in session_list_items) { console.log(session_list_items[i].getAttribute('data-session_id')); //console.log(session_list_items[i]); 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); //session_list_items[i].remove(); 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 = function (events) { console.log('Rendering event presentation records...'); } exports.render_event_presention_file_records = function (events) { console.log('Rendering event presentation file records...'); } exports.render_event_presenter_records = function (events) { console.log('Rendering event presenter records...'); } 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]; }