Cleaning up the JS code.
This commit is contained in:
257
app/index.html
257
app/index.html
@@ -99,10 +99,12 @@
|
||||
<script>const app = require('./js/module_app');</script>
|
||||
<script>const api = require('./js/module_api');</script>
|
||||
<script>const idb = require('./js/module_app_idb');</script>
|
||||
<script>const ui = require('./js/module_app_ui');</script>
|
||||
<script>const uiv2 = require('./js/module_app_ui_v2');</script>
|
||||
<!--<script src="js/api.js"></script>-->
|
||||
<!--<script src="js/script.js"></script>-->
|
||||
<script src="js/app_ui_misc.js"></script>
|
||||
<script src="js/app_ui_sessions.js"></script>
|
||||
<script src="js/app_ui_presentations.js"></script>
|
||||
<script src="js/app_ui_presenters.js"></script>
|
||||
<script src="js/app_ui_files.js"></script>
|
||||
<!--<script src="js/testing.js"></script>-->
|
||||
|
||||
<script>
|
||||
@@ -244,8 +246,7 @@
|
||||
const api_token_update_loop_interval = 120000; // loop forever
|
||||
|
||||
const update_idb_loop_interval = 500; // loop forever; update when check datetime has passed
|
||||
const idb_to_launcher_loop_interval = 5000; // loop forever; only run when one or more tables are updated
|
||||
const update_render_loop_interval = 10000; // loop forever; only run when the launcher object is safe
|
||||
//const update_render_loop_interval = 10000; // loop forever; only run when the launcher object is safe
|
||||
const check_file_cache_loop_interval = 250; // loop forever; only run after the event_file table has updated
|
||||
|
||||
// Axios needs to authenticate first
|
||||
@@ -269,9 +270,8 @@
|
||||
idb_event_file_check_datetime = Date.now();
|
||||
|
||||
let run_update_idb = false;
|
||||
let run_idb_to_launcher = false;
|
||||
let idb_to_launcher_in_progress = false;
|
||||
let safe_to_render_launcher = false; // currently only set to true in module_app_idb.js
|
||||
//let run_idb_to_launcher = false;
|
||||
//let idb_to_launcher_in_progress = false;
|
||||
let run_check_file_cache = false;
|
||||
|
||||
let looping_tbl_event = false;
|
||||
@@ -281,40 +281,11 @@
|
||||
let looping_tbl_event_presenter = false;
|
||||
let looping_tbl_event_file = false;
|
||||
|
||||
|
||||
//const loading_loop_interval = app_config.loading_loop_interval; // in milliseconds
|
||||
//const loading_loop_interval = 500;
|
||||
//const main_loop_interval = app_config.main_loop_interval; // in milliseconds
|
||||
//const main_loop_interval = 1500; //10000; // 10 seconds
|
||||
|
||||
//const idb_check_period = app_config.idb_check_period; //30000; // 60 seconds
|
||||
// The datetime is when it should be checked again, not when it was last checked.
|
||||
// It may be good to split the object check period into event, location, session, presentation, presenter
|
||||
//let idb_check_datetime = Date.now(); // default to current datetime in ms
|
||||
// The datetime is when it should be checked again, not when it was last checked.
|
||||
// It may be good to split the file check period into event, location, session, presentation, presenter
|
||||
//let launcher_files_check_datetime = Date.now(); // default to current datetime in ms
|
||||
|
||||
const host_file_cache_path = app_config.host_file_cache_path; //'file_cache/';
|
||||
//const host_file_cache_check_period = app_config.host_file_cache_check_period; //30000; // 30 seconds
|
||||
|
||||
let launcher = new Object(); // This will create the something like location > sessions and location files > presenters and session files > presenter files
|
||||
|
||||
|
||||
|
||||
|
||||
let idb_to_launcher_result = false;
|
||||
//let launcher_cache_check_results = false;
|
||||
let launcher_render_results = false;
|
||||
|
||||
|
||||
|
||||
//let run_check_file_cache = false;
|
||||
let run_render_launcher = false;
|
||||
|
||||
|
||||
let idb_tables_have_records = false;
|
||||
//let safe_to_render_launcher = false;
|
||||
|
||||
// Development variables:
|
||||
//let account_id = 12;
|
||||
@@ -349,7 +320,6 @@
|
||||
clearInterval(open_tables_loop);
|
||||
|
||||
idb_tables_opened = true;
|
||||
run_idb_to_launcher = true; // Set to true so that the launcher object is rebuilt
|
||||
} else {
|
||||
console.log('IDB tables have not yet been created or opened');
|
||||
|
||||
@@ -358,106 +328,6 @@
|
||||
}, open_tables_loop_interval);
|
||||
|
||||
|
||||
var update_idb_loop = setInterval(async function() {
|
||||
//if (run_update_idb) {
|
||||
// console.log('run_update_idb is set to true');
|
||||
//console.log('FLAG: axios_headers_set='+axios_headers_set);
|
||||
//console.log('FLAG: idb_tables_opened='+idb_tables_opened);
|
||||
if (axios_headers_set && idb_tables_opened) {
|
||||
if (idb_event_check_datetime < Date.now()) {
|
||||
console.log('Time to check events');
|
||||
let v2_account_events = await api.v2_get_account_events(axios, account_id)
|
||||
.then(function (response) {
|
||||
for (var i in response) {
|
||||
tbl_event.setItem(response[i].id.toString(), response[i]);
|
||||
}
|
||||
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_check_datetime = Date.now() + idb_event_check_period;
|
||||
let render_event_records_result = uiv2.render_event_records(); // NOTE: v2 idb to ui
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log('Trying to check events. Something went wrong. Expired token?');
|
||||
console.log(error);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
if (idb_event_location_check_datetime < Date.now()) {
|
||||
console.log('Time to check event locations');
|
||||
let v2_event_locations = await api.v2_get_event_locations(axios, event_id);
|
||||
for (var i in v2_event_locations) {
|
||||
tbl_event_location.setItem(v2_event_locations[i].id.toString(), v2_event_locations[i]);
|
||||
}
|
||||
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_location_check_datetime = Date.now() + idb_event_location_check_period;
|
||||
let render_event_location_records_result = uiv2.render_event_location_records(); // NOTE: v2 idb to ui
|
||||
}
|
||||
|
||||
if (idb_event_session_check_datetime < Date.now()) {
|
||||
console.log('**** *** Time to check event sessions *** ****'); // All event sessions, not just location specific.
|
||||
let v2_event_sessions = await api.v2_get_event_sessions(axios, event_id); // Was v2_get_event_location_sessions
|
||||
//tbl_event_session.clear();
|
||||
for (var i in v2_event_sessions) {
|
||||
tbl_event_session.setItem(v2_event_sessions[i].id.toString(), v2_event_sessions[i]);
|
||||
}
|
||||
//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_session_check_datetime = Date.now() + idb_event_session_check_period;
|
||||
let render_event_session_records_result = uiv2.render_event_session_records(); // NOTE: v2 idb to ui
|
||||
}
|
||||
|
||||
if (idb_event_presentation_check_datetime < Date.now()) {
|
||||
console.log('Time to check event location presentations');
|
||||
let v2_event_presentations = await api.v2_get_event_location_presentations(axios, event_location_id);
|
||||
for (var i in v2_event_presentations) {
|
||||
tbl_event_presentation.setItem(v2_event_presentations[i].id.toString(), v2_event_presentations[i]);
|
||||
}
|
||||
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_presentation_check_datetime = Date.now() + idb_event_presentation_check_period;
|
||||
let render_event_presentation_records_result = await uiv2.render_event_presentation_records(); // NOTE: v2 idb to ui
|
||||
}
|
||||
|
||||
if (idb_event_presenter_check_datetime < Date.now()) {
|
||||
console.log('Time to check event location presenters');
|
||||
let v2_event_presenters = await api.v2_get_event_location_presenters(axios, event_location_id);
|
||||
for (var i in v2_event_presenters) {
|
||||
tbl_event_presenter.setItem(v2_event_presenters[i].id.toString(), v2_event_presenters[i]);
|
||||
}
|
||||
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()) {
|
||||
console.log('Time to check event location files');
|
||||
let v2_event_files = await api.v2_get_event_location_files(axios, event_location_id);
|
||||
for (var i in v2_event_files) {
|
||||
tbl_event_file.setItem(v2_event_files[i].event_file_id.toString(), v2_event_files[i]);
|
||||
}
|
||||
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
|
||||
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_file_records_result = await uiv2.render_event_file_records(); // NOTE: v2 idb to ui
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
console.log('Waiting for the Axios headers to be set and/or IDB tables opened...');
|
||||
}
|
||||
|
||||
//} else {
|
||||
// console.log('run_update_idb is set to false');
|
||||
//}
|
||||
}, update_idb_loop_interval);
|
||||
|
||||
|
||||
var api_token_update_loop = setInterval(function() {
|
||||
api.api_token_request_async(axios, secret_key).then( function(result) {
|
||||
console.log('Setting temporary API token to axios Authorization header: '+result);
|
||||
@@ -468,8 +338,115 @@
|
||||
}, api_token_update_loop_interval);
|
||||
|
||||
|
||||
var update_render_loop = setInterval(async function() {
|
||||
}, update_render_loop_interval);
|
||||
var update_idb_loop = setInterval(async function() {
|
||||
//console.log('FLAG: axios_headers_set='+axios_headers_set);
|
||||
//console.log('FLAG: idb_tables_opened='+idb_tables_opened);
|
||||
if (axios_headers_set && idb_tables_opened) {
|
||||
if (idb_event_check_datetime < Date.now()) {
|
||||
console.log('**** *** ** * Time to check events');
|
||||
let v2_account_events = await api.v2_get_account_events(axios, account_id)
|
||||
.then(function (response) {
|
||||
for (var i in response) {
|
||||
tbl_event.setItem(response[i].id.toString(), response[i]);
|
||||
}
|
||||
idb_event_check_datetime = Date.now() + idb_event_check_period;
|
||||
let render_event_records_result = render_event_records(); // NOTE: v2 idb to ui
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log('Trying to check events. Something went wrong. Expired token?');
|
||||
console.log(error);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
if (idb_event_location_check_datetime < Date.now()) {
|
||||
console.log('**** *** ** * Time to check event locations');
|
||||
let v2_event_locations = await api.v2_get_event_locations(axios, event_id);
|
||||
for (var i in v2_event_locations) {
|
||||
tbl_event_location.setItem(v2_event_locations[i].id.toString(), v2_event_locations[i]);
|
||||
}
|
||||
idb_event_location_check_datetime = Date.now() + idb_event_location_check_period;
|
||||
let render_event_location_records_result = render_event_location_records(); // NOTE: v2 idb to ui
|
||||
}
|
||||
|
||||
if (idb_event_session_check_datetime < Date.now()) {
|
||||
console.log('**** *** ** * Time to check event sessions'); // All event sessions, not just location specific.
|
||||
let v2_event_sessions = await api.v2_get_event_sessions(axios, event_id); // Was v2_get_event_location_sessions
|
||||
//tbl_event_session.clear();
|
||||
for (var i in v2_event_sessions) {
|
||||
tbl_event_session.setItem(v2_event_sessions[i].id.toString(), v2_event_sessions[i]);
|
||||
}
|
||||
idb_event_session_check_datetime = Date.now() + idb_event_session_check_period;
|
||||
let render_event_session_records_result = render_event_session_records(); // NOTE: v2 idb to ui
|
||||
}
|
||||
|
||||
if (idb_event_presentation_check_datetime < Date.now()) {
|
||||
console.log('**** *** ** * Time to check event location presentations');
|
||||
let v2_event_presentations = await api.v2_get_event_location_presentations(axios, event_location_id);
|
||||
for (var i in v2_event_presentations) {
|
||||
tbl_event_presentation.setItem(v2_event_presentations[i].id.toString(), v2_event_presentations[i]);
|
||||
}
|
||||
idb_event_presentation_check_datetime = Date.now() + idb_event_presentation_check_period;
|
||||
let render_event_presentation_records_result = await render_event_presentation_records(); // NOTE: v2 idb to ui
|
||||
}
|
||||
|
||||
if (idb_event_presenter_check_datetime < Date.now()) {
|
||||
console.log('**** *** ** * Time to check event location presenters');
|
||||
let v2_event_presenters = await api.v2_get_event_location_presenters(axios, event_location_id);
|
||||
for (var i in v2_event_presenters) {
|
||||
tbl_event_presenter.setItem(v2_event_presenters[i].id.toString(), v2_event_presenters[i]);
|
||||
}
|
||||
idb_event_presenter_check_datetime = Date.now() + idb_event_presenter_check_period;
|
||||
|
||||
let render_event_presenter_records_result = await render_event_presenter_records(); // NOTE: v2 idb to ui
|
||||
}
|
||||
|
||||
if (idb_event_file_check_datetime < Date.now()) {
|
||||
console.log('**** *** ** * Time to check event location files');
|
||||
|
||||
let v2_event_files = await api.v2_get_event_files(axios, event_id);
|
||||
for (var i in v2_event_files) {
|
||||
tbl_event_file.setItem(v2_event_files[i].id.toString(), v2_event_files[i]);
|
||||
}
|
||||
|
||||
let v2_event_location_files = await api.v2_get_event_location_files(axios, event_location_id);
|
||||
for (var i in v2_event_location_files) {
|
||||
tbl_event_file.setItem(v2_event_location_files[i].id.toString(), v2_event_location_files[i]);
|
||||
}
|
||||
|
||||
let v2_event_location_files_sessions = await api.v2_get_event_location_files_sessions(axios, event_location_id);
|
||||
for (var i in v2_event_location_files_sessions) {
|
||||
tbl_event_file.setItem(v2_event_location_files_sessions[i].id.toString(), v2_event_location_files_sessions[i]);
|
||||
}
|
||||
|
||||
let v2_event_location_files_presentations = await api.v2_get_event_location_files_presentations(axios, event_location_id);
|
||||
for (var i in v2_event_location_files_presentations) {
|
||||
tbl_event_file.setItem(v2_event_location_files_presentations[i].id.toString(), v2_event_location_files_presentations[i]);
|
||||
}
|
||||
|
||||
let v2_event_location_files_presenters = await api.v2_get_event_location_files_presenters(axios, event_location_id);
|
||||
for (var i in v2_event_location_files_presenters) {
|
||||
tbl_event_file.setItem(v2_event_location_files_presenters[i].id.toString(), v2_event_location_files_presenters[i]);
|
||||
}
|
||||
|
||||
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_file_records_result = await render_event_file_records(); // NOTE: v2 idb to ui
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
console.log('Waiting for the Axios headers to be set and/or IDB tables opened...');
|
||||
}
|
||||
}, update_idb_loop_interval);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*var update_render_loop = setInterval(async function() {
|
||||
}, update_render_loop_interval);*/
|
||||
|
||||
|
||||
var check_file_cache_loop = setInterval(async function() {
|
||||
|
||||
210
app/js/app_ui_files.js
Normal file
210
app/js/app_ui_files.js
Normal file
@@ -0,0 +1,210 @@
|
||||
// This function is used to render all event, location, session, presentation, and presenter file records to the UI.
|
||||
//exports.render_event_file_records = async function () {
|
||||
async function render_event_file_records() {
|
||||
console.log('Rendering all event, location, session, presentation, and presenter file records...');
|
||||
console.log('****************** Files ******************');
|
||||
|
||||
if (looping_tbl_event_file) {
|
||||
console.log('Already looping through the tbl_event_file table. Not starting until finished.');
|
||||
return false;
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
looping_tbl_event_file = true;
|
||||
|
||||
console.log('Iterating through the tbl_event_file table...');
|
||||
await tbl_event_file.iterate(function(value, key, iteration) {
|
||||
let tbl_file_id = value.id;
|
||||
let tbl_hosted_file_id = value.hosted_file_id;
|
||||
let tbl_event_id = value.event_id;
|
||||
let tbl_location_id = value.event_location_id;
|
||||
let tbl_session_id = value.event_session_id;
|
||||
let tbl_presentation_id = value.event_presentation_id;
|
||||
let tbl_presenter_id = value.event_presenter_id;
|
||||
let tbl_for_type = value.for_type;
|
||||
let tbl_for_id = value.for_id;
|
||||
let tbl_hash_sha256 = value.hosted_file_hash_sha256;
|
||||
let tbl_filename = value.filename; // This could also be event_file_filename, internal_filename, private_filename, public_filename, or hosted_file_filename
|
||||
let tbl_size = value.hosted_file_size;
|
||||
let tbl_created_on = value.created_on;
|
||||
let tbl_updated_on = value.created_on;
|
||||
let tbl_internal_os = value.internal_os;
|
||||
|
||||
console.log('tbl_event_file iteration='+iteration+' | tbl_file_id='+tbl_file_id+' for tbl_event_id='+tbl_event_id+' at location tbl_location_id='+tbl_location_id+'.');
|
||||
|
||||
if (tbl_event_id == event_id && tbl_for_type == 'event') {
|
||||
console.log('EVENT FILE **************************');
|
||||
document.getElementById('event_files_menu').classList.remove('d-none');
|
||||
document.getElementById('event_files_menu').classList.add('d-block');
|
||||
}
|
||||
|
||||
if (tbl_location_id == event_location_id && tbl_for_type == 'location') {
|
||||
console.log('LOCATION FILE **************************');
|
||||
document.getElementById('location_files_menu').classList.remove('d-none');
|
||||
document.getElementById('location_files_menu').classList.add('d-block');
|
||||
}
|
||||
|
||||
//add_file_id = false;
|
||||
remove_file_id = true;
|
||||
if (tbl_event_id == event_id/* && tbl_location_id == event_location_id*/) {
|
||||
console.log('Match for event_id='+event_id+' and event_location_id='+event_location_id);
|
||||
file_li_node = document.getElementById('event_file_'+tbl_file_id);
|
||||
if (file_li_node) {
|
||||
console.log('event_file ('+tbl_file_id+') node found... check and remove/update.');
|
||||
if (file_li_node.getAttribute('data-for_type') == tbl_for_type && file_li_node.getAttribute('data-for_id') == tbl_for_id) {
|
||||
console.log('This file is still for_type='+tbl_for_type+' and for_id='+tbl_for_id+'.');
|
||||
file_li_node.setAttribute('data-filename', tbl_filename);
|
||||
file_li_node.getElementsByClassName('filename')[0].innerHTML = tbl_filename;
|
||||
try {
|
||||
file_li_node.getElementsByClassName('file_meta')[0].innerHTML = format_bytes(tbl_size, 2)+'; '+dateFns.format(tbl_created_on, 'MMM M h:mm A')+'; '+tbl_internal_os;
|
||||
}
|
||||
catch(err) {
|
||||
console.log('file_meta span not found. This is ok for event and location specific files.');
|
||||
}
|
||||
|
||||
file_li_node.setAttribute('data-size', tbl_size);
|
||||
|
||||
file_li_node.setAttribute('data-created_on', dateFns.format(tbl_created_on, 'YYYY-MM-DD HH:mm:ss A'));
|
||||
file_li_node.setAttribute('data-updated_on', dateFns.format(tbl_updated_on, 'YYYY-MM-DD HH:mm:ss A'));
|
||||
|
||||
file_li_node.setAttribute('data-internal_os', tbl_internal_os);
|
||||
|
||||
|
||||
remove_file_id = false;
|
||||
} else {
|
||||
console.log('This file no longer matching for_type='+tbl_for_type+' and for_id='+tbl_for_id+'. Removing...');
|
||||
file_li_node.remove();
|
||||
remove_file_id = false;
|
||||
}
|
||||
} else if (!file_li_node) {
|
||||
console.log('event_file ('+tbl_file_id+') node NOT found... check and add.');
|
||||
|
||||
let node_id = tbl_for_type+'_files_list_'+tbl_for_id;
|
||||
console.log(node_id);
|
||||
let parent_ul_node = document.getElementById(node_id);
|
||||
console.log(parent_ul_node);
|
||||
if (parent_ul_node) {
|
||||
// Trying to remove old ID in case there is one already rendered
|
||||
console.log('Trying to remove an old file LI node if it exists...');
|
||||
try {
|
||||
document.getElementById('event_file_'+tbl_file_id).remove();
|
||||
}
|
||||
catch(err) {
|
||||
//console.log('A node with the ID of event_file_'+tbl_file_id+' was not found.');
|
||||
console.log('This event file list item node was not found. In most cases this is expected.');
|
||||
console.log(err.message);
|
||||
}
|
||||
|
||||
let file_li_node = document.createElement('LI');
|
||||
file_li_node.id = 'event_file_'+tbl_file_id;
|
||||
file_li_node.className = 'list-group-item btn btn-primary d-flex justify-content-between align-items-center open_local_file event_file';
|
||||
file_li_node.setAttribute('data-file_id', tbl_file_id);
|
||||
|
||||
|
||||
file_li_node.setAttribute('data-event_id', tbl_event_id);
|
||||
file_li_node.setAttribute('data-location_id', tbl_location_id);
|
||||
file_li_node.setAttribute('data-session_id', tbl_session_id);
|
||||
file_li_node.setAttribute('data-presentation_id', tbl_presentation_id);
|
||||
file_li_node.setAttribute('data-presenter_id', tbl_presenter_id);
|
||||
|
||||
file_li_node.setAttribute('data-for_type', tbl_for_type);
|
||||
file_li_node.setAttribute('data-for_id', tbl_for_id);
|
||||
|
||||
file_li_node.setAttribute('data-hash_sha256', tbl_hash_sha256+'.file');
|
||||
file_li_node.setAttribute('data-filename', tbl_filename);
|
||||
file_li_node.setAttribute('data-size', tbl_size);
|
||||
|
||||
file_li_node.setAttribute('data-created_on', dateFns.format(tbl_created_on, 'YYYY-MM-DD HH:mm:ss A'));
|
||||
file_li_node.setAttribute('data-updated_on', dateFns.format(tbl_updated_on, 'YYYY-MM-DD HH:mm:ss A'));
|
||||
|
||||
file_li_node.setAttribute('data-internal_os', tbl_internal_os);
|
||||
|
||||
file_li_node.title = 'id='+tbl_file_id+' for_type='+tbl_for_type+' for_id='+tbl_for_id+' updated_on='+dateFns.format(tbl_updated_on, 'YYYY-MM-DD HH:mm:ss A');
|
||||
|
||||
let file_fa_span_node = document.createElement('SPAN');
|
||||
file_fa_span_node.className = 'fas fa-external-link-alt';
|
||||
|
||||
let file_filename_span_node = document.createElement('SPAN');
|
||||
file_filename_span_node.className = 'filename';
|
||||
|
||||
let filename_text_node = document.createTextNode(tbl_filename);
|
||||
file_filename_span_node.appendChild(filename_text_node);
|
||||
|
||||
file_li_node.appendChild(file_fa_span_node);
|
||||
file_li_node.appendChild(file_filename_span_node);
|
||||
|
||||
// We do not want the badge to show in the left menu. Not enough space.
|
||||
if (tbl_for_type != 'event' && tbl_for_type != 'location') {
|
||||
let file_badge_span_node = document.createElement('SPAN');
|
||||
file_badge_span_node.className = 'badge badge-pill badge-light float-right file_meta';
|
||||
|
||||
let badge_text_node = document.createTextNode(format_bytes(tbl_size, 2)+'; '+dateFns.format(tbl_created_on, 'MMM M h:mm A')+'; '+tbl_internal_os);
|
||||
file_badge_span_node.appendChild(badge_text_node);
|
||||
|
||||
file_li_node.appendChild(file_badge_span_node);
|
||||
}
|
||||
|
||||
|
||||
|
||||
console.log(file_li_node);
|
||||
|
||||
parent_ul_node.appendChild(file_li_node);
|
||||
remove_file_id = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// NOTE: This is probably not needed?
|
||||
if (remove_file_id) {
|
||||
// Trying to remove old ID in case there is one already rendered
|
||||
console.log('Trying to remove an old file LI node if it exists...');
|
||||
try {
|
||||
document.getElementById('event_file_'+tbl_file_id).remove();
|
||||
}
|
||||
catch(err) {
|
||||
//console.log('A node with the ID of event_file_'+tbl_file_id+' was not found.');
|
||||
console.log('This event file list item node was not found. In most cases this is expected.');
|
||||
console.log(err.message);
|
||||
}
|
||||
}
|
||||
|
||||
console.log('XXXXX ******** STARTING SORT ******** XXXXX');
|
||||
let node_id = tbl_for_type+'_files_list_'+tbl_for_id;
|
||||
console.log(node_id);
|
||||
|
||||
var categoryItems = document.getElementById(node_id).childNodes;
|
||||
console.log(categoryItems);
|
||||
|
||||
var categoryItemsArray = Array.from(categoryItems);
|
||||
|
||||
function sorter(a, b) {
|
||||
if (a.dataset.updated_on > b.dataset.updated_on) return -1;
|
||||
if (a.dataset.updated_on < b.dataset.updated_on) return 1;
|
||||
}
|
||||
|
||||
let sorted = categoryItemsArray.sort(sorter);
|
||||
|
||||
function update_li_order(item, index) {
|
||||
document.getElementById(node_id).appendChild(item);
|
||||
}
|
||||
|
||||
sorted.forEach(update_li_order);
|
||||
console.log('******** FINISHED SORT ********');
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
console.log('This file ('+tbl_file_id+') is not part of this event and or location');
|
||||
console.log('tbl_event_id='+tbl_event_id+' ?= event_id='+event_id);
|
||||
console.log('tbl_location_id='+tbl_location_id+' ?= event_location_id='+event_location_id);
|
||||
}
|
||||
}).then(function() {
|
||||
console.log('idb_to_ui: Iterate tbl_event_file looking for files to add is complete');
|
||||
looping_tbl_event_file = false;
|
||||
});
|
||||
|
||||
index_open_file_buttons('open_local_file');
|
||||
return true;
|
||||
|
||||
}
|
||||
126
app/js/app_ui_misc.js
Normal file
126
app/js/app_ui_misc.js
Normal file
@@ -0,0 +1,126 @@
|
||||
const path = require('path');
|
||||
const { ipcRenderer } = require('electron');
|
||||
|
||||
//exports.render_event_records = function () {
|
||||
function render_event_records() {
|
||||
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;
|
||||
document.getElementById('event_files_menu').getElementsByTagName('ul')[0].id = 'event_files_list_'+value.id;
|
||||
} else {
|
||||
console.log('Event not it.');
|
||||
}
|
||||
}).then(function() {
|
||||
console.log('idb_to_ui: Iterate tbl_event_file complete')
|
||||
tbl_event_complete = true;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
//exports.render_event_location_records = async function () {
|
||||
async function render_event_location_records() {
|
||||
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;
|
||||
|
||||
document.getElementById('location_files_menu').getElementsByTagName('ul')[0].id = 'location_files_list_'+value.id;
|
||||
/*
|
||||
let location_files_ul_node = document.createElement('UL');
|
||||
location_files_ul_node.id = 'event_presentation_files_list_'+value.id;
|
||||
location_files_ul_node.className = 'list-group list-group-flush location_files location_files_list event_files_list';
|
||||
|
||||
document.getElementById('location_files_menu').appendChild(location_files_ul_node);
|
||||
*/
|
||||
} else {
|
||||
console.log('Event location not it.');
|
||||
}
|
||||
}).then(function() {
|
||||
console.log('idb_to_ui: Iterate tbl_event_file complete')
|
||||
tbl_event_location_complete = true;
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
|
||||
/* Updated 2020-02-13 */
|
||||
function index_open_file_buttons(class_name) {
|
||||
var class_elements = document.getElementsByClassName(class_name);
|
||||
|
||||
for (var i = 0; i < class_elements.length; i++) {
|
||||
// Do not use an anonymous function. If you do then it will keep adding event listeners.
|
||||
// Adding the exact same event listeners over and over doesn't hurt anything.
|
||||
// No need to use removeEventListener()
|
||||
class_elements[i].addEventListener( 'click', open_local_file );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Updated 2020-02-13 */
|
||||
function open_local_file(element) {
|
||||
console.log(element);
|
||||
let file_path = path.join(host_file_cache_path, element.getAttribute('data-hash_sha256'));
|
||||
let filename = element.getAttribute('data-filename');
|
||||
console.log(file_path);
|
||||
console.log(filename);
|
||||
|
||||
ipcRenderer.send('open_local_file', file_path, filename);
|
||||
}
|
||||
|
||||
|
||||
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];
|
||||
}
|
||||
177
app/js/app_ui_presentations.js
Normal file
177
app/js/app_ui_presentations.js
Normal file
@@ -0,0 +1,177 @@
|
||||
//exports.render_event_presentation_records = async function (events) {
|
||||
async function render_event_presentation_records(events) {
|
||||
console.log('Rendering event presentation records...');
|
||||
console.log('****************** Presentations ******************');
|
||||
|
||||
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;
|
||||
}
|
||||
210
app/js/app_ui_presenters.js
Normal file
210
app/js/app_ui_presenters.js
Normal file
@@ -0,0 +1,210 @@
|
||||
//exports.render_event_presenter_records = async function (events) {
|
||||
async function render_event_presenter_records(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_session_id = value.event_session_id;
|
||||
let tbl_presentation_id = value.event_presentation_id;
|
||||
let tbl_presenter_id = value.id;
|
||||
console.log('tbl_event_presenter iteration='+iteration+' | tbl_presenter_id='+tbl_presenter_id+' for tbl_presentation_id='+tbl_presentation_id);
|
||||
|
||||
// Second: Loop through the presentations presenter UL placeholder (assumes there is a ul for presenters under each presentation)
|
||||
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('presentation 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; // Set flag to true. Update if found. Add if not found.
|
||||
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;
|
||||
|
||||
// Third: Loop through the presenters (LI) in a specific list under a presentation.
|
||||
if (presentation_presenters_list_items.length) {
|
||||
for (let j=0, len=presentation_presenters_list_items.length; j < len; j++) {
|
||||
console.log('Checking 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).setAttribute('data-given_name', value.given_name);
|
||||
document.getElementById('event_presenter_'+tbl_presenter_id).setAttribute('data-family_name', value.family_name);
|
||||
document.getElementById('event_presenter_'+tbl_presenter_id).getElementsByClassName('presenter_name')[0].innerHTML = value.given_name+' '+value.family_name;
|
||||
// Could have used getElementsByTagName('strong') instead
|
||||
|
||||
|
||||
console.log('XXXXX ******** STARTING SORT ******** XXXXX');
|
||||
var categoryItems = document.getElementById('event_presentation_presenters_'+tbl_presentation_id).childNodes;
|
||||
console.log(categoryItems);
|
||||
|
||||
var categoryItemsArray = Array.from(categoryItems);
|
||||
|
||||
function sorter(a, b) {
|
||||
if (a.dataset.family_name < b.dataset.family_name) return -1;
|
||||
if (a.dataset.family_name > b.dataset.family_name) return 1;
|
||||
}
|
||||
|
||||
let sorted = categoryItemsArray.sort(sorter);
|
||||
|
||||
function update_li_order(item, index) {
|
||||
document.getElementById('event_presentation_presenters_'+tbl_presentation_id).appendChild(item);
|
||||
}
|
||||
|
||||
sorted.forEach(update_li_order);
|
||||
console.log('******** FINISHED SORT ********');
|
||||
|
||||
|
||||
|
||||
add_presenter_id = false;
|
||||
remove_presenter_id = false;
|
||||
} else if (tbl_presentation_id != li_presentation_id ) {
|
||||
console.log('Set flag to add presenter ID '+li_presenter_id+' to false. Set flag to remove presenter ID '+li_presenter_id+' to true.');
|
||||
add_presenter_id = false;
|
||||
remove_presenter_id = true; // The default is already set to true. Is this needed?
|
||||
} else {
|
||||
// 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 {
|
||||
//NOTE: This probably needs to be reviewed again.
|
||||
//console.log('This tbl_presentation_id '+tbl_presentation_id+' does not match this ul_presentation_id '+ul_presentation_id+'. Do not add presenter ID. ***But leave remove presenter ID as true???');
|
||||
add_presenter_id = false;
|
||||
remove_presenter_id = false;
|
||||
}
|
||||
|
||||
|
||||
// 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+').');
|
||||
|
||||
// Trying to remove old ID in case there is one already rendered
|
||||
console.log('Trying to remove an old presenter LI node if it exists...');
|
||||
try {
|
||||
document.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. In most cases this is expected.');
|
||||
console.log(err.message);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
presenter_li_node.setAttribute('data-given_name', value.given_name);
|
||||
presenter_li_node.setAttribute('data-family_name', value.family_name);
|
||||
|
||||
presenter_li_node.title = 'id='+tbl_presenter_id+' session_id='+value.event_session_id+' presentation_id='+ul_presentation_id+' 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 = 'presenter_files_list_'+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);
|
||||
|
||||
document.getElementById('event_presentation_presenters_'+tbl_presentation_id).appendChild(presenter_li_node);
|
||||
|
||||
remove_presenter_id = false;
|
||||
|
||||
console.log('XXXXX ******** STARTING SORT ******** XXXXX');
|
||||
var categoryItems = document.getElementById('event_presentation_presenters_'+tbl_presentation_id).childNodes;
|
||||
console.log(categoryItems);
|
||||
|
||||
var categoryItemsArray = Array.from(categoryItems);
|
||||
|
||||
function sorter(a, b) {
|
||||
if (a.dataset.family_name < b.dataset.family_name) return -1;
|
||||
if (a.dataset.family_name > b.dataset.family_name) return 1;
|
||||
}
|
||||
|
||||
let sorted = categoryItemsArray.sort(sorter);
|
||||
|
||||
function update_li_order(item, index) {
|
||||
document.getElementById('event_presentation_presenters_'+tbl_presentation_id).appendChild(item);
|
||||
}
|
||||
|
||||
sorted.forEach(update_li_order);
|
||||
console.log('******** FINISHED SORT ********');
|
||||
|
||||
} 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
|
||||
console.log('Trying to remove a presenter LI node...');
|
||||
try {
|
||||
document.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. In some cases this is expected.');
|
||||
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 UL placeholder list for presenters found under any presentations. Something might have gone wrong?');
|
||||
}
|
||||
}).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;
|
||||
}
|
||||
178
app/js/app_ui_sessions.js
Normal file
178
app/js/app_ui_sessions.js
Normal file
@@ -0,0 +1,178 @@
|
||||
//exports.render_event_session_records = async function () {
|
||||
async function render_event_session_records() {
|
||||
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);
|
||||
|
||||
node.title = 'id='+value.id+' 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 = '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('Checking 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');
|
||||
|
||||
}
|
||||
@@ -331,6 +331,27 @@ exports.v2_get_event_location_presenters = async function (axios, event_location
|
||||
}
|
||||
|
||||
|
||||
exports.v2_get_event_files = async function (axios, event_id) {
|
||||
console.log('Requesting event files...');
|
||||
const url = '/v2/event/'+event_id+'/event_files';
|
||||
|
||||
const data = await axios.get(url)
|
||||
.then(function (response) {
|
||||
console.log('v2 location files data: ***');
|
||||
console.log(response.data);
|
||||
console.log('v2 location files data: ^^^');
|
||||
//data = response.data;
|
||||
return response.data;
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log(error);
|
||||
return error;
|
||||
});
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
exports.v2_get_event_location_files = async function (axios, event_location_id) {
|
||||
console.log('Requesting location files...');
|
||||
const url = '/v2/event_location/'+event_location_id+'/event_files';
|
||||
@@ -350,3 +371,66 @@ exports.v2_get_event_location_files = async function (axios, event_location_id)
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
exports.v2_get_event_location_files_sessions = async function (axios, event_location_id) {
|
||||
console.log('Requesting all session files for a location...');
|
||||
const url = '/v2/event_location/'+event_location_id+'/event_files/sessions';
|
||||
|
||||
const data = await axios.get(url)
|
||||
.then(function (response) {
|
||||
console.log('v2 location files data: ***');
|
||||
console.log(response.data);
|
||||
console.log('v2 location files data: ^^^');
|
||||
//data = response.data;
|
||||
return response.data;
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log(error);
|
||||
return error;
|
||||
});
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
exports.v2_get_event_location_files_presentations = async function (axios, event_location_id) {
|
||||
console.log('Requesting all presentation files for a location...');
|
||||
const url = '/v2/event_location/'+event_location_id+'/event_files/presentations';
|
||||
|
||||
const data = await axios.get(url)
|
||||
.then(function (response) {
|
||||
console.log('v2 location files data: ***');
|
||||
console.log(response.data);
|
||||
console.log('v2 location files data: ^^^');
|
||||
//data = response.data;
|
||||
return response.data;
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log(error);
|
||||
return error;
|
||||
});
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
exports.v2_get_event_location_files_presenters = async function (axios, event_location_id) {
|
||||
console.log('Requesting all presenter files for a location...');
|
||||
const url = '/v2/event_location/'+event_location_id+'/event_files/presenters';
|
||||
|
||||
const data = await axios.get(url)
|
||||
.then(function (response) {
|
||||
console.log('v2 location files data: ***');
|
||||
console.log(response.data);
|
||||
console.log('v2 location files data: ^^^');
|
||||
//data = response.data;
|
||||
return response.data;
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log(error);
|
||||
return error;
|
||||
});
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -4,192 +4,14 @@ const fs = require('fs');
|
||||
|
||||
const { ipcRenderer } = require('electron');
|
||||
|
||||
|
||||
exports.create_load_idb = async function create_load_idb() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
exports.idb_to_launcher = async function idb_to_launcher() {
|
||||
if (idb_to_launcher_in_progress) {
|
||||
console.log('*** Exit idb_to_launcher. It is already in progress. ***');
|
||||
return false; // return false... false being that another idb_to_launcher is in progress
|
||||
} else {
|
||||
console.log('idb_to_launcher is not in progress. It appears to be safe to start... starting.');
|
||||
}
|
||||
|
||||
//tbl_example.iterate(tbl_check, tbl_check_success, tbl_check_error); //tbl_check(value, key, iteration)
|
||||
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_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_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_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_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_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_new.location_file = tmp_event_location_file;
|
||||
|
||||
|
||||
// Look for *sessions*
|
||||
let tmp_event_session = []
|
||||
tbl_event_session.iterate(function(session_value, session_key, session_iteration) {
|
||||
//console.log('session id: '+session_value.id);
|
||||
|
||||
|
||||
// Look for *session files*
|
||||
session_value.file = [];
|
||||
tbl_event_file.iterate(function(session_file_value, session_file_key, session_file_iteration) {
|
||||
if (session_file_value.for_type == 'session' && session_value.id == session_file_value.for_id) {
|
||||
//console.log('session id: '+session_value.id+' -> file id: '+session_file_value.id);
|
||||
session_value.file.push(session_file_value)
|
||||
}
|
||||
}).then(function() {
|
||||
//console.log('idb_to_launcher: Iterate tbl_event_file complete')
|
||||
tbl_event_session_file_complete = true;
|
||||
});
|
||||
|
||||
|
||||
// Look for *presentations per session*
|
||||
session_value.presentation = [];
|
||||
tbl_event_presentation.iterate(function(presentation_value, presentation_key, presentation_iteration) {
|
||||
if (session_value.id == presentation_value.event_session_id) {
|
||||
//console.log('session id: '+session_value.id+' -> presentation id: '+presentation_value.id);
|
||||
// Look for *presentation files*
|
||||
presentation_value.file = [];
|
||||
tbl_event_file.iterate(function(presentation_file_value, presentation_file_key, presentation_file_iteration) {
|
||||
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;
|
||||
});
|
||||
|
||||
|
||||
// Look for *presenters per presentation*
|
||||
presentation_value.presenter = [];
|
||||
tbl_event_presenter.iterate(function(presenter_value, presenter_key, presenter_iteration) {
|
||||
if (presentation_value.id == presenter_value.event_presentation_id) {
|
||||
//console.log('presentation id: '+presentation_value.id+' -> presenter id: '+presenter_value.id);
|
||||
// Look for *presenter files*
|
||||
presenter_value.file = [];
|
||||
tbl_event_file.iterate(function(presenter_file_value, presenter_file_key, presenter_file_iteration) {
|
||||
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;
|
||||
});
|
||||
presentation_value.presenter.push(presenter_value);
|
||||
}
|
||||
}).then(function() {
|
||||
//console.log('idb_to_launcher: Iterate tbl_event_presenter complete')
|
||||
tbl_event_presenter_complete = true;
|
||||
});
|
||||
|
||||
session_value.presentation.push(presentation_value);
|
||||
}//);
|
||||
|
||||
}).then(function() {
|
||||
//console.log('idb_to_launcher: Iterate tbl_event_presentation complete')
|
||||
tbl_event_presentation_complete = true;
|
||||
});
|
||||
//});
|
||||
|
||||
tmp_event_session.push(session_value);
|
||||
|
||||
}).then(function() {
|
||||
//console.log('idb_to_launcher: Iterate tbl_event_session complete')
|
||||
tbl_event_session_complete = true;
|
||||
});
|
||||
launcher_new.session = tmp_event_session;
|
||||
|
||||
/*
|
||||
console.log('v2 idb to launcher object: ***');
|
||||
console.log(launcher);
|
||||
console.log('v2 idb to launcher object: ^^^');
|
||||
*/
|
||||
|
||||
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('*** New launcher object built!!! ***');
|
||||
console.log('idb to launcher object: ***');
|
||||
console.log(launcher_new);
|
||||
console.log('idb to launcher object: ^^^');
|
||||
launcher = launcher_new;
|
||||
safe_to_render_launcher = true;
|
||||
idb_to_launcher_in_progress = false;
|
||||
//ui.render_launcher(launcher_new);
|
||||
clearInterval(creating_launcher_object_loop);
|
||||
return launcher_new;
|
||||
} else {
|
||||
console.log('Still building launcher object...');
|
||||
safe_to_render_launcher = false;
|
||||
idb_to_launcher_in_progress = true;
|
||||
}
|
||||
}, 5);
|
||||
//return launcher_new;
|
||||
}
|
||||
|
||||
exports.check_file_cache = async function () {
|
||||
console.log('Checking the local file cache against the remote server.');
|
||||
tbl_event_file.iterate(function(file_value, key, iteration) {
|
||||
if (file_value.event_location_id == event_location_id) {
|
||||
//if (file_value.event_location_id == event_location_id) {
|
||||
//console.log('f: ('+file_value.event_file_id+') '+file_value.event_file_filename+' ***')
|
||||
|
||||
file_id = file_value.event_file_id; // NOTE: the .id is the hosted_file.id!
|
||||
let filename = file_value.hash_sha256+'.file';
|
||||
file_id = file_value.id; // NOTE: This is the event_file.id or event_file_id.
|
||||
let filename = file_value.hosted_file_hash_sha256+'.file';
|
||||
|
||||
save_path = path.join(host_file_cache_path, filename);
|
||||
|
||||
@@ -200,20 +22,8 @@ exports.check_file_cache = async function () {
|
||||
let api_endpoint = '/event/file/'+file_id+'/download';
|
||||
ipcRenderer.send('download_file', api_base_url, api_endpoint, api_temporary_token, save_path); // Must download file using main node.js thread.
|
||||
}
|
||||
}
|
||||
//}
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
function tbl_check(value, key, iteration) {
|
||||
console.log(value);
|
||||
}
|
||||
|
||||
function tbl_check_success(result) {
|
||||
console.log(result);
|
||||
}
|
||||
function tbl_check_error(result) {
|
||||
console.log(result);
|
||||
}
|
||||
|
||||
@@ -1,816 +0,0 @@
|
||||
const path = require('path');
|
||||
const { ipcRenderer } = require('electron');
|
||||
|
||||
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;
|
||||
document.getElementById('event_files_menu').getElementsByTagName('ul')[0].id = 'event_files_list_'+value.id;
|
||||
} else {
|
||||
console.log('Event not it.');
|
||||
}
|
||||
}).then(function() {
|
||||
console.log('idb_to_ui: Iterate tbl_event_file complete')
|
||||
tbl_event_complete = true;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
|
||||
document.getElementById('location_files_menu').getElementsByTagName('ul')[0].id = 'location_files_list_'+value.id;
|
||||
/*
|
||||
let location_files_ul_node = document.createElement('UL');
|
||||
location_files_ul_node.id = 'event_presentation_files_list_'+value.id;
|
||||
location_files_ul_node.className = 'list-group list-group-flush location_files location_files_list event_files_list';
|
||||
|
||||
document.getElementById('location_files_menu').appendChild(location_files_ul_node);
|
||||
*/
|
||||
} else {
|
||||
console.log('Event location not it.');
|
||||
}
|
||||
}).then(function() {
|
||||
console.log('idb_to_ui: Iterate tbl_event_file complete')
|
||||
tbl_event_location_complete = true;
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
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 = '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('Checking 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('Rendering event presentation records...');
|
||||
console.log('****************** Presentations ******************');
|
||||
|
||||
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 = '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;
|
||||
}
|
||||
|
||||
|
||||
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_session_id = value.event_session_id;
|
||||
let tbl_presentation_id = value.event_presentation_id;
|
||||
let tbl_presenter_id = value.id;
|
||||
console.log('tbl_event_presenter iteration='+iteration+' | tbl_presenter_id='+tbl_presenter_id+' for tbl_presentation_id='+tbl_presentation_id);
|
||||
|
||||
// Second: Loop through the presentations presenter UL placeholder (assumes there is a ul for presenters under each presentation)
|
||||
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('presentation 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; // Set flag to true. Update if found. Add if not found.
|
||||
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;
|
||||
|
||||
// Third: Loop through the presenters (LI) in a specific list under a presentation.
|
||||
if (presentation_presenters_list_items.length) {
|
||||
for (let j=0, len=presentation_presenters_list_items.length; j < len; j++) {
|
||||
console.log('Checking 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 add presenter ID '+li_presenter_id+' to false. Set flag to remove presenter ID '+li_presenter_id+' to true.');
|
||||
add_presenter_id = false;
|
||||
remove_presenter_id = true; // The default is already set to true. Is this needed?
|
||||
} else {
|
||||
// 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 {
|
||||
//NOTE: This probably needs to be reviewed again.
|
||||
//console.log('This tbl_presentation_id '+tbl_presentation_id+' does not match this ul_presentation_id '+ul_presentation_id+'. Do not add presenter ID. ***But leave remove presenter ID as true???');
|
||||
add_presenter_id = false;
|
||||
remove_presenter_id = false;
|
||||
}
|
||||
|
||||
|
||||
// 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+').');
|
||||
|
||||
// Trying to remove old ID in case there is one already rendered
|
||||
console.log('Trying to remove an old presenter LI node if it exists...');
|
||||
try {
|
||||
document.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. In most cases this is expected.');
|
||||
console.log(err.message);
|
||||
}
|
||||
|
||||
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 = 'presenter_files_list_'+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);
|
||||
|
||||
document.getElementById('event_presentation_presenters_'+tbl_presentation_id).appendChild(presenter_li_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
|
||||
console.log('Trying to remove a presenter LI node...');
|
||||
try {
|
||||
document.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. In some cases this is expected.');
|
||||
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 UL placeholder list for presenters found under any presentations. Something might have gone wrong?');
|
||||
}
|
||||
}).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;
|
||||
}
|
||||
|
||||
|
||||
// This function is used to render all event, location, session, presentation, and presenter file records to the UI.
|
||||
exports.render_event_file_records = async function () {
|
||||
console.log('Rendering all event, location, session, presentation, and presenter file records...');
|
||||
console.log('****************** Files ******************');
|
||||
|
||||
if (looping_tbl_event_file) {
|
||||
console.log('Already looping through the tbl_event_file table. Not starting until finished.');
|
||||
return false;
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
looping_tbl_event_file = true;
|
||||
|
||||
console.log('Iterating through the tbl_event_file table...');
|
||||
await tbl_event_file.iterate(function(value, key, iteration) {
|
||||
let tbl_file_id = value.id;
|
||||
let tbl_hosted_file_id = value.id;
|
||||
let tbl_event_id = value.event_id;
|
||||
let tbl_location_id = value.event_location_id;
|
||||
let tbl_session_id = value.event_session_id;
|
||||
let tbl_presentation_id = value.event_presentation_id;
|
||||
let tbl_presenter_id = value.event_presenter_id;
|
||||
let tbl_for_type = value.for_type;
|
||||
let tbl_for_id = value.for_id;
|
||||
let tbl_hash_sha256 = value.hash_sha256;
|
||||
let tbl_filename = value.filename; // This could also be event_file_filename, internal_filename, private_filename, or public_filename
|
||||
let tbl_size = value.size;
|
||||
let tbl_created_on = value.created_on;
|
||||
let tbl_internal_os = value.internal_os;
|
||||
|
||||
console.log('tbl_event_file iteration='+iteration+' | tbl_file_id='+tbl_file_id+' for tbl_event_id='+tbl_event_id+' at location tbl_location_id='+tbl_location_id+'.');
|
||||
|
||||
if (tbl_event_id == event_id && tbl_for_type == 'event') {
|
||||
console.log('EVENT FILE **************************');
|
||||
document.getElementById('event_files_menu').classList.remove('d-none');
|
||||
document.getElementById('event_files_menu').classList.add('d-block');
|
||||
}
|
||||
|
||||
if (tbl_location_id == event_location_id && tbl_for_type == 'location') {
|
||||
console.log('LOCATION FILE **************************');
|
||||
document.getElementById('location_files_menu').classList.remove('d-none');
|
||||
document.getElementById('location_files_menu').classList.add('d-block');
|
||||
}
|
||||
|
||||
if (tbl_event_id == event_id/* && tbl_location_id == event_location_id*/) {
|
||||
console.log('Match for event_id='+event_id+' and event_location_id='+event_location_id);
|
||||
event_file_li_node = document.getElementById('event_file_'+tbl_file_id);
|
||||
if (event_file_li_node) {
|
||||
console.log('event_file ('+tbl_file_id+') node found... check and remove/update.');
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
console.log('event_file ('+tbl_file_id+') node NOT found... check and add.');
|
||||
|
||||
let node_id = tbl_for_type+'_files_list_'+tbl_for_id;
|
||||
console.log(node_id);
|
||||
let parent_ul_node = document.getElementById(node_id);
|
||||
console.log(parent_ul_node);
|
||||
if (parent_ul_node) {
|
||||
let file_li_node = document.createElement('LI');
|
||||
file_li_node.id = 'event_file_'+tbl_file_id;
|
||||
file_li_node.className = 'list-group-item btn btn-primary d-flex justify-content-between align-items-center open_local_file event_file';
|
||||
file_li_node.setAttribute('data-file_id', tbl_file_id);
|
||||
|
||||
|
||||
file_li_node.setAttribute('data-event_id', tbl_event_id);
|
||||
file_li_node.setAttribute('data-location_id', tbl_location_id);
|
||||
file_li_node.setAttribute('data-session_id', tbl_session_id);
|
||||
file_li_node.setAttribute('data-presentation_id', tbl_presentation_id);
|
||||
file_li_node.setAttribute('data-presenter_id', tbl_presenter_id);
|
||||
|
||||
file_li_node.setAttribute('data-for_type', tbl_for_type);
|
||||
file_li_node.setAttribute('data-for_id', tbl_for_id);
|
||||
|
||||
file_li_node.setAttribute('data-hash_sha256', tbl_hash_sha256+'.file');
|
||||
file_li_node.setAttribute('data-filename', tbl_filename);
|
||||
|
||||
|
||||
|
||||
|
||||
let file_fa_span_node = document.createElement('SPAN');
|
||||
file_fa_span_node.className = 'fas fa-external-link-alt';
|
||||
|
||||
let file_filename_span_node = document.createElement('SPAN');
|
||||
file_filename_span_node.className = 'filename';
|
||||
|
||||
let filename_text_node = document.createTextNode(tbl_filename);
|
||||
file_filename_span_node.appendChild(filename_text_node);
|
||||
|
||||
file_li_node.appendChild(file_fa_span_node);
|
||||
file_li_node.appendChild(file_filename_span_node);
|
||||
|
||||
// We do not want the badge to show in the left menu. Not enough space.
|
||||
if (tbl_for_type != 'event' && tbl_for_type != 'location') {
|
||||
let file_badge_span_node = document.createElement('SPAN');
|
||||
file_badge_span_node.className = 'badge badge-pill badge-light float-right';
|
||||
|
||||
let badge_text_node = document.createTextNode(format_bytes(tbl_size, 2)+'; '+dateFns.format(tbl_created_on, 'MMM M h:mm A')+'; '+tbl_internal_os);
|
||||
file_badge_span_node.appendChild(badge_text_node);
|
||||
|
||||
file_li_node.appendChild(file_badge_span_node);
|
||||
}
|
||||
|
||||
|
||||
|
||||
console.log(file_li_node);
|
||||
|
||||
parent_ul_node.appendChild(file_li_node);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
console.log('This file ('+tbl_file_id+') is not part of this event and or location');
|
||||
console.log('tbl_event_id='+tbl_event_id+' ?= event_id='+event_id);
|
||||
console.log('tbl_location_id='+tbl_location_id+' ?= event_location_id='+event_location_id);
|
||||
}
|
||||
/*
|
||||
if (tbl_for_type == 'event') {
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
if (tbl_for_type == 'location') {
|
||||
} else {
|
||||
|
||||
}
|
||||
*/
|
||||
}).then(function() {
|
||||
console.log('idb_to_ui: Iterate tbl_event_file looking for files to add is complete');
|
||||
looping_tbl_event_file = false;
|
||||
});
|
||||
|
||||
index_open_file_buttons('open_local_file');
|
||||
return true;
|
||||
|
||||
/*
|
||||
xxx.classList.remove('d-none');
|
||||
xxx.classList.add('d-block');
|
||||
*/
|
||||
/*
|
||||
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>';
|
||||
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
|
||||
/* Updated 2020-02-13 */
|
||||
function index_open_file_buttons(class_name) {
|
||||
var class_elements = document.getElementsByClassName(class_name);
|
||||
|
||||
for (var i = 0; i < class_elements.length; i++) {
|
||||
// Do not use an anonymous function. If you do then it will keep adding event listeners.
|
||||
// Adding the exact same event listeners over and over doesn't hurt anything.
|
||||
// No need to use removeEventListener()
|
||||
class_elements[i].addEventListener( 'click', open_local_file );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Updated 2020-02-13 */
|
||||
function open_local_file(element) {
|
||||
console.log(element);
|
||||
let file_path = path.join(host_file_cache_path, element.getAttribute('data-hash_sha256'));
|
||||
let filename = element.getAttribute('data-filename');
|
||||
console.log(file_path);
|
||||
console.log(filename);
|
||||
|
||||
ipcRenderer.send('open_local_file', file_path, filename);
|
||||
}
|
||||
|
||||
|
||||
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];
|
||||
}
|
||||
Reference in New Issue
Block a user