Working on making the rendering more efficient...

This commit is contained in:
Scott Idem
2020-01-29 17:58:35 -05:00
parent 7e79f333c2
commit 5bd557e743
3 changed files with 232 additions and 117 deletions

View File

@@ -13,43 +13,64 @@ exports.create_load_idb = async function create_load_idb() {
exports.idb_to_launcher = async function idb_to_launcher() {
//tbl_example.iterate(tbl_check, tbl_check_success, tbl_check_error); //tbl_check(value, key, iteration)
//let launcher = new Object();
let launcher_new = new Object();
let tbl_event_complete = false;
let tbl_event_file_complete = false;
let tbl_event_location_complete = false;
let tbl_event_location_file_complete = false;
let tbl_event_session_complete = false;
let tbl_event_session_file_complete = false;
let tbl_event_presentation_complete = false;
let tbl_event_presentation_file_complete = false;
let tbl_event_presenter_complete = false;
let tbl_event_presenter_file_complete = false;
// Look for *events*
let tmp_event = [];
tbl_event.iterate(function(event_value, key, iteration) {
tmp_event.push(event_value);
}).then(function() {
console.log('idb_to_launcher: Iterate tbl_event complete')
tbl_event_complete = true;
});
launcher.event = tmp_event;
launcher_new.event = tmp_event;
// Look for *event files*
let tmp_event_file = []
tbl_event_file.iterate(function(file_value, key, iteration) {
//console.log('event id: '+launcher.event[0].id+' -> file_id: '+file_value.id+'for type: '+file_value.for_type+' for id: '+file_value.id);
if (file_value.for_type == 'event' && launcher.event[0].id == file_value.for_id) {
//console.log('event id: '+launcher_new.event[0].id+' -> file_id: '+file_value.id+'for type: '+file_value.for_type+' for id: '+file_value.id);
if (file_value.for_type == 'event' && launcher_new.event[0].id == file_value.for_id) {
tmp_event_file.push(file_value);
}
}).then(function() {
console.log('idb_to_launcher: Iterate tbl_event_file complete')
tbl_event_file_complete = true;
});
launcher.event_file = tmp_event_file;
launcher_new.event_file = tmp_event_file;
// Look for *locations*
let tmp_event_location = []
tbl_event_location.iterate(function(location_value, key, iteration) {
tmp_event_location.push(location_value);
}).then(function() {
console.log('idb_to_launcher: Iterate tbl_event_location complete')
tbl_event_location_complete = true;
});
launcher.location = tmp_event_location;
launcher_new.location = tmp_event_location;
// Look for *event location files*
let tmp_event_location_file = []
tbl_event_file.iterate(function(file_value, key, iteration) {
if (file_value.for_type == 'location' && launcher.location[0].id == file_value.for_id) {
if (file_value.for_type == 'location' && launcher_new.location[0].id == file_value.for_id) {
tmp_event_location_file.push(file_value);
}
}).then(function() {
console.log('idb_to_launcher: Iterate tbl_event_file complete')
tbl_event_location_file_complete = true;
});
launcher.location_file = tmp_event_location_file;
launcher_new.location_file = tmp_event_location_file;
// Look for *sessions*
@@ -66,6 +87,9 @@ exports.idb_to_launcher = async function idb_to_launcher() {
session_value.file.push(session_file_value)
//tmp_event_session_file.push(session_file_value);
}
}).then(function() {
console.log('idb_to_launcher: Iterate tbl_event_file complete')
tbl_event_session_file_complete = true;
});
@@ -82,6 +106,9 @@ exports.idb_to_launcher = async function idb_to_launcher() {
if (presentation_file_value.for_type == 'presentation' && presentation_value.id == presentation_file_value.for_id) {
presentation_value.file.push(presentation_file_value);
}
}).then(function() {
console.log('idb_to_launcher: Iterate tbl_event_file complete')
tbl_event_presentation_file_complete = true;
});
@@ -97,26 +124,23 @@ exports.idb_to_launcher = async function idb_to_launcher() {
if (presenter_file_value.for_type == 'presenter' && presenter_value.id == presenter_file_value.for_id) {
presenter_value.file.push(presenter_file_value);
}
}).then(function() {
console.log('idb_to_launcher: Iterate tbl_event_file complete')
tbl_event_presenter_file_complete = true;
});
//NOTE for some reason this is adding duplicate presenters to a session
//NOTE is this iterating twice or something???
/*
tbl_event_file.iterate(function(presenter_file_value, key, iteration) {
});
*/
presentation_value.presenter.push(presenter_value);
}
}).then(function() {
console.log('idb_to_launcher: Iterate tbl_event_presenter complete')
tbl_event_presenter_complete = true;
});
//NOTE add in presenters and then presenter's files
session_value.presentation.push(presentation_value);
}//);
}).then(function() {
console.log('idb_to_launcher: Iterate tbl_event_presentation complete')
tbl_event_presentation_complete = true;
});
//});
@@ -124,8 +148,9 @@ exports.idb_to_launcher = async function idb_to_launcher() {
}).then(function() {
console.log('idb_to_launcher: Iterate tbl_event_session complete')
tbl_event_session_complete = true;
});
launcher.session = tmp_event_session;
launcher_new.session = tmp_event_session;
/*
console.log('v2 idb to launcher object: ***');
@@ -133,7 +158,20 @@ exports.idb_to_launcher = async function idb_to_launcher() {
console.log('v2 idb to launcher object: ^^^');
*/
return true;
var creating_launcher_object_loop = setInterval(function() {
if (tbl_event_complete && tbl_event_file_complete && tbl_event_location_complete && tbl_event_location_file_complete && tbl_event_session_complete && tbl_event_session_file_complete && tbl_event_presentation_complete && tbl_event_presentation_file_complete && tbl_event_presenter_complete && tbl_event_presenter_file_complete) {
console.log('And DONE!!!');
console.log('v2 idb to launcher object: ***');
console.log(launcher_new);
console.log('v2 idb to launcher object: ^^^');
ui.render_launcher(launcher_new);
clearInterval(creating_launcher_object_loop);
return launcher_new;
} else {
console.log('Still building...');
}
}, 5);
//return launcher_new;
}
exports.check_file_cache = async function () {

View File

@@ -5,31 +5,41 @@ const fs = require('fs');
const { ipcRenderer } = require('electron');
exports.render_launcher = async function (launcher_tmp) {
exports.render_launcher = function (launcher_tmp) {
console.log('Rendering launcher_tmp...');
console.log('In module_app_ui.js v2 idb to launcher object: ***');
console.log(launcher_tmp);
console.log('In module_app_ui.js v2 idb to launcher object: ^^^');
for (var i in launcher_tmp.event) {
if (launcher_tmp.event[i].id == event_id) {
console.log('*** Event id ('+event_id+') found in launcher object.');
for (var j in launcher_tmp.location) {
if (launcher_tmp.location[j].id == event_location_id) {
console.log('*** Location id ('+event_location_id+') found in launcher object.');
document.getElementById('location_title').innerHTML = '<h1>Launcher '+launcher_tmp.location[j].name+'@'+launcher_tmp.event[i].name+'</h1>';
} else {
if (launcher_tmp.event) {
for (var i in launcher_tmp.event) {
if (launcher_tmp.event[i].id == event_id) {
console.log('*** Event id ('+event_id+') found in launcher object.');
for (var j in launcher_tmp.location) {
if (launcher_tmp.location[j].id == event_location_id) {
console.log('*** Location id ('+event_location_id+') found in launcher object.');
document.title = launcher_tmp.location[j].name+'@'+launcher_tmp.event[i].name;
//document.getElementById('launcher_title').innerHTML = '<h1>Launcher '+launcher_tmp.location[j].name+'@'+launcher_tmp.event[i].name+'</h1>';
document.getElementById('location_name').innerHTML = '<span class="fas fa-map-marker"></span> '+launcher_tmp.location[j].name+'@'+launcher_tmp.event[i].name;
} else {
console.log('Event location not it.');
}
}
} else {
console.log('Event not it.');
}
} else {
}
console.log('Data in launcher object');
console.log(launcher_tmp);
} else {
console.log('Missing data in launcher object');
return false;
}
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_id_'+launcher_tmp.event_file[i].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 += '<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>';
@@ -37,22 +47,23 @@ exports.render_launcher = async function (launcher_tmp) {
document.getElementById('location_files_menu').innerHTML = '<h2>Location Files</h2>';
document.getElementById('location_files_menu').innerHTML += '<ul class="list-group list-group-flush" role="">';
for (var i in launcher_tmp.location_file) {
document.getElementById('location_files_menu').innerHTML += '<li id="menu_event_file_id_'+launcher_tmp.location_file[i].id+'" class="list-group-item btn btn-secondary d-flex justify-content-between align-items-center open_local_file" data-hash_sha256="'+launcher_tmp.location_file[i].hash_sha256+'.file" data-filename="'+launcher_tmp.location_file[i].event_file_filename+'">'+launcher_tmp.location_file[i].event_file_filename+'</li>';
document.getElementById('location_files_menu').innerHTML += '<li id="menu_event_location_file_'+launcher_tmp.location_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.location_file[i].hash_sha256+'.file" data-filename="'+launcher_tmp.location_file[i].event_file_filename+'"><span class="fas fa-external-link-alt"></span> '+launcher_tmp.location_file[i].event_file_filename+'</li>';
}
document.getElementById('location_files_menu').innerHTML += '</ul>';
document.getElementById('sessions_menu').innerHTML = '<h2>Sessions</h2>';
document.getElementById('sessions_menu').innerHTML += '<ul class="list-group list-group-flush" role="">';
//let location_detail = '';
if (document.getElementById('location_detail').innerHTML.length) {
console.log('detail_session_id_xx already exists');
//let launcher_sessions = '';
if (document.getElementById('launcher_sessions').innerHTML.length) {
console.log('launcher_sessions already exists');
document.getElementById('launcher_sessions').innerHTML = ''; // This needs to be reviewed.
} else {
console.log('location_detail already populated');
document.getElementById('location_detail').innerHTML = ''; // This needs to be reviewed.
console.log('launcher_sessions is empty');
//document.getElementById('launcher_sessions').innerHTML = ''; // This needs to be reviewed.
}
for (var i in launcher_tmp.session) {
// List sessions in menu
document.getElementById('sessions_menu').innerHTML += '<li id="menu_session_id_'+launcher_tmp.session[i].id+'" class="list-group-item btn btn-info d-flex justify-content-between align-items-center btn_view_session" data-session_id="'+launcher_tmp.session[i].id+'">'+launcher_tmp.session[i].name+'</li>';
document.getElementById('sessions_menu').innerHTML += '<li id="menu_event_session_'+launcher_tmp.session[i].id+'" class="list-group-item btn btn-info d-flex justify-content-between align-items-center btn_view_session" data-session_id="'+launcher_tmp.session[i].id+'">'+launcher_tmp.session[i].name+'</li>';
// Create containers for each session
let session_detail = '';
@@ -84,7 +95,7 @@ exports.render_launcher = async function (launcher_tmp) {
let file = launcher_tmp.session[i].file[j];
//console.log(file.event_file_filename);
files_list += '<li class="list-group-item btn btn-primary d-flex justify-content-between align-items-center open_local_file" data-hash_sha256="'+file.hash_sha256+'.file" data-filename="'+file.event_file_filename+'">';
files_list += '<li id="event_session_file_'+file.event_file_id+'" class="list-group-item btn btn-primary d-flex justify-content-between align-items-center open_local_file" data-hash_sha256="'+file.hash_sha256+'.file" data-filename="'+file.event_file_filename+'">';
files_list += file.event_file_filename;
files_list += '<span class="badge badge-pill badge-light">'+format_bytes(file.size, 2)+'; '+dateFns.format(file.created_on, 'MMM M h:mm A')+'; '+file.internal_os+'</span>';
files_list += '</li>';
@@ -118,7 +129,7 @@ exports.render_launcher = async function (launcher_tmp) {
//var session_presentation_startdatetime = new Date(launcher_tmp.session[i].presentation[j].start_datetime);
presentations_list += '<li class="list-group-item">';
presentations_list += '<li id="event_presentation_'+presentation.id+'" class="list-group-item">';
presentations_list += '<div class="list-group-item-heading d-flex justify-content-between align-items-center">';
presentations_list += '<strong class="">'+presentation.name+'</strong>';
presentations_list += '<span class="badge badge-pill badge-info">'+dateFns.format(presentation.start_datetime, 'h:mm a')+'</span>';
@@ -133,7 +144,7 @@ exports.render_launcher = async function (launcher_tmp) {
let file = presentation.file[k];
//console.log(file.event_file_filename);
files_list += '<li class="list-group-item btn btn-primary d-flex justify-content-between align-items-center open_local_file" data-hash_sha256="'+file.hash_sha256+'.file" data-filename="'+file.event_file_filename+'">';
files_list += '<li id="event_presentation_file_'+file.event_file_id+'" class="list-group-item btn btn-primary d-flex justify-content-between align-items-center open_local_file" data-hash_sha256="'+file.hash_sha256+'.file" data-filename="'+file.event_file_filename+'"><span class="fas fa-external-link-alt"></span> ';
files_list += file.event_file_filename;
files_list += '<span class="badge badge-pill badge-light float-right">'+format_bytes(file.size, 2)+'; '+dateFns.format(file.created_on, 'MMM M h:mm A')+'; '+file.internal_os+'</span>';
files_list += '</li>';
@@ -150,7 +161,7 @@ exports.render_launcher = async function (launcher_tmp) {
let presenter = presentation.presenter[k];
//console.log(presenter.given_name);
presenters_list += '<li class="list-group-item">';
presenters_list += '<li id="event_presenter_'+presenter.id+'" class="list-group-item">';
presenters_list += '<strong class="list-group-item-heading">'+presenter.given_name+' '+presenter.family_name+'</strong>';
if (typeof presenter.file !== 'undefined') {
@@ -158,20 +169,7 @@ exports.render_launcher = async function (launcher_tmp) {
files_list += '<ul class="list-group list-group-flush list-group-item-text">';
for (var l in presenter.file) {
let file = presenter.file[l];
/*
files_list += '<li class="list-group-item list-group-item-action open_local_file" data-hash_sha256="'+launcher_tmp.session[i].presentation[j].presenter[k].file[l].hash_sha256+'.file" data-filename="'+launcher_tmp.session[i].presentation[j].presenter[k].file[l].event_file_filename+'">';
files_list += '<button class="btn btn-info open_local_file" data-hash_sha256="'+launcher_tmp.session[i].presentation[j].presenter[k].file[l].hash_sha256+'.file" data-filename="'+launcher_tmp.session[i].presentation[j].presenter[k].file[l].event_file_filename+'">'+launcher_tmp.session[i].presentation[j].presenter[k].file[l].event_file_filename+'</button>';
var event_file_size = launcher_tmp.session[i].presentation[j].presenter[k].file[l].size;
var event_file_created_on = new Date(launcher_tmp.session[i].presentation[j].presenter[k].file[l].created_on);
session_detail += '<span class="badge badge-pill badge-light float-right">'+format_bytes(event_file_size, 2)+'; '+dateFns.format(event_file_created_on, 'MMM M h:mm A')+'; '+launcher_tmp.session[i].presentation[j].presenter[k].file[l].internal_os+'</span>';
session_detail += '</li>';
*/
files_list += '<li class="list-group-item btn btn-primary d-flex justify-content-between align-items-center open_local_file" data-hash_sha256="'+file.hash_sha256+'.file" data-filename="'+file.event_file_filename+'">';
files_list += '<li id="event_presenter_file_'+file.event_file_id+'" class="list-group-item btn btn-primary d-flex justify-content-between align-items-center open_local_file" data-hash_sha256="'+file.hash_sha256+'.file" data-filename="'+file.event_file_filename+'"><span class="fas fa-external-link-alt"></span> ';
files_list += file.event_file_filename;
files_list += '<span class="badge badge-pill badge-light float-right">'+format_bytes(file.size, 2)+'; '+dateFns.format(file.created_on, 'MMM M h:mm A')+'; '+file.internal_os+'</span>';
files_list += '</li>';
@@ -206,19 +204,19 @@ exports.render_launcher = async function (launcher_tmp) {
session_detail += '</div> <!-- End session detail for '+launcher_tmp.session[i].id+' -->';
// *** Session presentations card section start
//document.getElementById('location_detail').innerHTML += session_detail;
//document.getElementById('launcher_sessions').innerHTML += session_detail;
if (typeof(document.getElementById('detail_session_id_'+launcher_tmp.session[i].id)) != 'undefined' && document.getElementById('detail_session_id_'+launcher_tmp.session[i].id) != null) {
document.getElementById('detail_session_id_'+launcher_tmp.session[i].id).innerHTML = session_detail;
} else {
document.getElementById('location_detail').innerHTML += session_detail;
document.getElementById('launcher_sessions').innerHTML += session_detail;
}
}
document.getElementById('sessions_menu').innerHTML += '</ul>';
index_location_detail('btn_view_session');
index_launcher_sessions('btn_view_session');
index_open_file_buttons('open_local_file');
@@ -232,7 +230,7 @@ exports.render_launcher = async function (launcher_tmp) {
/* Updated 2019-12-19 */
function index_location_detail(class_name) {
function index_launcher_sessions(class_name) {
var class_elements = document.getElementsByClassName(class_name);
for (var i = 0; i < class_elements.length; i++) {