Mostly working now. Need to work on updates for files and token refresh. And probably other thigns..
This commit is contained in:
@@ -241,6 +241,8 @@
|
||||
const api_auth_loop_interval = 100; // only runs on start up
|
||||
const open_tables_loop_interval = 10; // only runs on start up
|
||||
|
||||
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
|
||||
@@ -456,8 +458,14 @@
|
||||
}, update_idb_loop_interval);
|
||||
|
||||
|
||||
var idb_to_launcher_loop = setInterval(function() {
|
||||
}, idb_to_launcher_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);
|
||||
axios.defaults.headers.common['Authorization'] = `Token ${result}`;
|
||||
api_temporary_token = result;
|
||||
return result;
|
||||
});
|
||||
}, api_token_update_loop_interval);
|
||||
|
||||
|
||||
var update_render_loop = setInterval(async function() {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
const path = require('path');
|
||||
const { ipcRenderer } = require('electron');
|
||||
|
||||
exports.render_event_records = function () {
|
||||
console.log('Rendering event records...');
|
||||
@@ -20,166 +22,6 @@ exports.render_event_records = function () {
|
||||
}
|
||||
|
||||
|
||||
// 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 **************************');
|
||||
}
|
||||
|
||||
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_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_fa_span_node);
|
||||
file_li_node.appendChild(file_filename_span_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;
|
||||
});
|
||||
|
||||
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>';
|
||||
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
exports.render_event_location_records = async function () {
|
||||
console.log('Rendering event location records...');
|
||||
|
||||
@@ -208,11 +50,6 @@ exports.render_event_location_records = async function () {
|
||||
}
|
||||
|
||||
|
||||
exports.render_event_location_file_records = function (events) {
|
||||
console.log('Rendering event location file records...');
|
||||
}
|
||||
|
||||
|
||||
exports.render_event_session_records = async function () {
|
||||
console.log('Rendering event session records...');
|
||||
|
||||
@@ -733,13 +570,178 @@ exports.render_event_presenter_records = async function (events) {
|
||||
}
|
||||
|
||||
|
||||
exports.render_event_presenter_file_records = function (events) {
|
||||
console.log('Rendering event presenter file records...');
|
||||
// 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);
|
||||
@@ -775,6 +777,32 @@ function view_session(session_id) {
|
||||
}
|
||||
|
||||
|
||||
/* 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';
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
"event_presenter_id": null,
|
||||
"event_file_id": null,
|
||||
"api_auth_loop_interval": 100,
|
||||
"api_token_update_loop_interval": 120000,
|
||||
"open_tables_loop_interval": 10,
|
||||
"update_idb_loop_interval": 10,
|
||||
"idb_to_launcher_loop_interval": 250,
|
||||
|
||||
Reference in New Issue
Block a user