diff --git a/app/css/aether_system.css b/app/css/aether_system.css index c14bc2a..22864e0 100644 --- a/app/css/aether_system.css +++ b/app/css/aether_system.css @@ -15,7 +15,7 @@ body { /* Display */ /* Center and scale the image nicely */ background-color: steelblue; - background-image: url('/static/images/site_background.webp'); /* "/static/images/site_background.webp" */ + background-image: url('../static/images/site_background.svg'); background-position: center; background-repeat: no-repeat; background-attachment: fixed; diff --git a/app/css/base_style_event_launcher.css b/app/css/base_style_event_launcher.css index 3ae1b93..db5e4c6 100644 --- a/app/css/base_style_event_launcher.css +++ b/app/css/base_style_event_launcher.css @@ -1,7 +1,7 @@ body { background-color: steelblue; /* https://app.haikei.app/ */ - background-image: url('/static/images/site_background.svg'); + background-image: url('../static/images/site_background.svg'); background-position: center; background-repeat: no-repeat; background-attachment: fixed; diff --git a/app/index 2022-03-01.html.bak b/app/index 2022-03-01.html.bak index c8974b8..1f773db 100644 --- a/app/index 2022-03-01.html.bak +++ b/app/index 2022-03-01.html.bak @@ -109,7 +109,7 @@ let api_update_datetime = Date.now(); let waiting_on_api_token = false; - const secret_key = app_config.api_secret_key; + const api_secret_key = app_config.api_secret_key; let api_temporary_token = null; let api_base_url = null; // 'http://api.localhost:5001' 'https://api.oneskyit.com' @@ -135,8 +135,8 @@ //console.log('****************** LOOP: API Token Loop ******************'); if (app_online && api_update_datetime < Date.now()) { - //let api_temporary_token_result = api_token_request_async(axios, secret_key) - api_temporary_token = await api_token_request_async(axios, secret_key) + //let api_temporary_token_result = api_token_request_async(axios, api_secret_key) + api_temporary_token = await api_token_request_async(axios, api_secret_key) .then(function (result) { if (result) { console.log('Setting temporary API token to axios Authorization header: '+result); diff --git a/app/index.html b/app/index.html index a1a8310..216981d 100644 --- a/app/index.html +++ b/app/index.html @@ -56,7 +56,8 @@ - + + @@ -83,6 +84,7 @@ + @@ -103,13 +105,16 @@ const app_env = 'development_local'; // 'development_local', 'development_remote const api_env = 'development_local'; // 'development_local', 'development_remote' const app_mode = 'onsite'; // null, 'default', 'onsite' -let account_id = app_config.account_id; +let client_account_id = app_config.account_id; +console.log(client_account_id); let event_id = app_config.event_id; let event_location_id = app_config.event_location_id; const page_for = { 'event': event_id, 'event_location': event_location_id }; // Simple key value like object console.log(page_for); +const host_file_cache_path = app_config.host_file_cache_path; // 'file_cache/' + /* ***** **** *** ** * ### * ** *** **** ***** */ @@ -121,7 +126,9 @@ console.log(page_for); // let api_update_datetime = Date.now(); // let waiting_on_api_token = false; -const secret_key = app_config.api_secret_key; +const access_control_allow_origin = app_config.access_control_allow_origin; +const api_secret_key = app_config.api_secret_key; +console.log(api_secret_key); let api_temporary_token = null; let api_base_url = null; diff --git a/app/js/app_ui_files.js b/app/js/app_ui_files.js index 2d81c37..8185566 100644 --- a/app/js/app_ui_files.js +++ b/app/js/app_ui_files.js @@ -1,228 +1,228 @@ // 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('****************** Files ******************'); - console.log('Rendering all event, location, session, presentation, and presenter file records...'); - - 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...'); - let tbl_event_file_result = 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); - - let new_filename = shorten_filename(tbl_filename); - file_li_node.getElementsByClassName('filename')[0].innerHTML = new_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; - if (tbl_for_type != 'event' && tbl_for_type != 'location') { - 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.className = 'list-group-item btn btn-primary justify-content-between align-items-center open_local_file event_file'; - } else { - file_li_node.className = 'list-group-item btn btn-sm btn-secondary d-flex justify-content-between align-items-center open_local_file event_file'; - //file_li_node.className = 'list-group-item btn btn-sm btn-secondary 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 = 'Click to open "'+tbl_filename+'" | 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 new_filename = shorten_filename(tbl_filename); - let filename_text_node = document.createTextNode(new_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); - try { - 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); - } catch(err) { - console.log(err); - } - console.log('******** FINISHED SORT ********'); - - - + console.log('****************** Files ******************'); + console.log('Rendering all event, location, session, presentation, and presenter file records...'); + + if (looping_tbl_event_file) { + console.log('Already looping through the tbl_event_file table. Not starting until finished.'); + return false; } 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; + + looping_tbl_event_file = true; + + console.log('Iterating through the tbl_event_file table...'); + let tbl_event_file_result = 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); + + let new_filename = shorten_filename(tbl_filename); + file_li_node.getElementsByClassName('filename')[0].innerHTML = new_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; + if (tbl_for_type != 'event' && tbl_for_type != 'location') { + 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.className = 'list-group-item btn btn-primary justify-content-between align-items-center open_local_file event_file'; + } else { + file_li_node.className = 'list-group-item btn btn-sm btn-secondary d-flex justify-content-between align-items-center open_local_file event_file'; + //file_li_node.className = 'list-group-item btn btn-sm btn-secondary 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 = 'Click to open "'+tbl_filename+'" | 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 new_filename = shorten_filename(tbl_filename); + let filename_text_node = document.createTextNode(new_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); + try { + 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); + } catch(err) { + console.log(err); + } + 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; + return true; + }) + .catch(function (error) { + console.log('Something went wrong in function render_event_file_records.'); + console.log(error); + return false; + }); + + + index_open_file_buttons('open_local_file'); return true; - }) - .catch(function (error) { - console.log('Something went wrong in function render_event_file_records.'); - console.log(error); - return false; - }); - - - index_open_file_buttons('open_local_file'); - return true; - + } diff --git a/app/js/app_ui_misc.js b/app/js/app_ui_misc.js index 811fff1..e78b99b 100644 --- a/app/js/app_ui_misc.js +++ b/app/js/app_ui_misc.js @@ -3,178 +3,178 @@ const { ipcRenderer } = require('electron'); //exports.render_event_records = function () { async function render_event_records() { - console.log('****************** Events ******************'); - console.log('Rendering event records...'); - //console.log(tbl_event); - //console.log(event_id); - - if (looping_tbl_event) { - console.log('Already looping through the tbl_event table. Not starting until finished.'); - return false; - } else { - - } - - looping_tbl_event = true; - - 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; + console.log('****************** Events ******************'); + console.log('Rendering event records...'); + //console.log(tbl_event); + //console.log(event_id); + + if (looping_tbl_event) { + console.log('Already looping through the tbl_event table. Not starting until finished.'); + return false; } else { - console.log('Event not it.'); + } - }).then(function() { - console.log('idb_to_ui: Iterate tbl_event_file complete') - //tbl_event_complete = true; - looping_tbl_event = false; - }); - + + looping_tbl_event = true; + + 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; + looping_tbl_event = false; + }); + } //exports.render_event_location_records = async function () { async function render_event_location_records() { - console.log('****************** Locations ******************'); - console.log('Rendering event location records...'); - - if (looping_tbl_event_location) { - console.log('Already looping through the tbl_event_location table. Not starting until finished.'); - return false; - } else { - - } - - looping_tbl_event_location = true; - - 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 = ' '+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); - */ + console.log('****************** Locations ******************'); + console.log('Rendering event location records...'); + + if (looping_tbl_event_location) { + console.log('Already looping through the tbl_event_location table. Not starting until finished.'); + return false; } else { - console.log('Event location not it.'); + } - }).then(function() { - console.log('idb_to_ui: Iterate tbl_event_file complete') - //tbl_event_location_complete = true; - looping_tbl_event_location = false; - }); - - return true; + + looping_tbl_event_location = true; + + 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 = ' '+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; + looping_tbl_event_location = false; + }); + + 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; + 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'); + 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; + + return true; } /* Updated 2020-02-13 */ function index_open_file_buttons(class_name) { - console.log('****************** Indexing ******************'); - console.log('Indexing open file buttons...'); - var class_elements = document.getElementsByClassName(class_name); - //console.log(class_elements); - - 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 ); - - /* - let hash = class_elements[i].getAttribute('data-hash_sha256'); - let file_path = path.join(host_file_cache_path, hash); - let filename = class_elements[i].getAttribute('data-filename'); - class_elements[i].addEventListener( 'click', function() { ipcRenderer.send('open_local_file', file_path, filename) } ); - */ - } - - return true; + console.log('****************** Indexing ******************'); + console.log('Indexing open file buttons...'); + var class_elements = document.getElementsByClassName(class_name); + //console.log(class_elements); + + 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 ); + + /* + let hash = class_elements[i].getAttribute('data-hash_sha256'); + let file_path = path.join(host_file_cache_path, hash); + let filename = class_elements[i].getAttribute('data-filename'); + class_elements[i].addEventListener( 'click', function() { ipcRenderer.send('open_local_file', file_path, filename) } ); + */ + } + + return true; } /* Updated 2020-02-13 */ function open_local_file() { - //console.log(this); - let hash = this.getAttribute('data-hash_sha256'); - let file_path = path.join(host_file_cache_path, hash); - let filename = this.getAttribute('data-filename'); - console.log(file_path); - console.log(filename); - - ipcRenderer.send('open_local_file', file_path, filename); + //console.log(this); + let hash = this.getAttribute('data-hash_sha256'); + let file_path = path.join(host_file_cache_path, hash); + let filename = this.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'; + 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 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)); + const i = Math.floor(Math.log(bytes) / Math.log(k)); - return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]; + return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]; } function shorten_filename(filename) { - let length = filename.length; - let char_over = filename.length-45; - let new_filename = null; - let wildcards = char_over; - if (char_over > 0) { - let part1 = filename.slice(0, 20); - if (char_over > 5) { - wildcards = 5; + let length = filename.length; + let char_over = filename.length-45; + let new_filename = null; + let wildcards = char_over; + if (char_over > 0) { + let part1 = filename.slice(0, 20); + if (char_over > 5) { + wildcards = 5; + } else { + } + let part2 = '.'.repeat(wildcards); + let part3 = filename.slice(-20); + + new_filename = part1+part2+part3; } else { + new_filename = filename; } - let part2 = '.'.repeat(wildcards); - let part3 = filename.slice(-20); - - new_filename = part1+part2+part3; - } else { - new_filename = filename; - } - return new_filename; + return new_filename; } diff --git a/app/js/app_v3.js b/app/js/app_v3.js new file mode 100644 index 0000000..e8e9aa6 --- /dev/null +++ b/app/js/app_v3.js @@ -0,0 +1,20 @@ +const path = require('path'); +const { ipcRenderer } = require('electron'); + +/* Updated 2022-03-07 */ +// function open_local_file({hash, host_file_cache_path, filename}) { +function open_local_file({host_file_cache_path, hash, filename}) { + + console.log('*** open_local_file() ***'); + + // hash = this.getAttribute('data-hash_sha256'); + // let file_path = path.join(host_file_cache_path, hash); + // filename = this.getAttribute('data-filename'); + console.log(host_file_cache_path); + console.log(hash); + // console.log(file_path); + console.log(filename); + + // ipcRenderer.send('open_local_file', file_path, filename); + ipcRenderer.send('open_local_file', host_file_cache_path, hash, filename); +} \ No newline at end of file diff --git a/app/js/hold testing.js b/app/js/hold testing.js index 503e060..342b8af 100644 --- a/app/js/hold testing.js +++ b/app/js/hold testing.js @@ -15,7 +15,7 @@ if(fs.existsSync(filename)) { }) } -//shell.openItem('test.txt'); +//shell.openPath('test.txt'); /* const path = './'; diff --git a/app/js/module_app.js b/app/js/module_app.js index b25ee1e..96e0e2b 100644 --- a/app/js/module_app.js +++ b/app/js/module_app.js @@ -69,6 +69,28 @@ exports.load_config = function () { } +exports.check_file_cache_v3 = async function (host_file_cache_path, event_file_id, hash) { + console.log('**** *** ** * FUNCTION: check_file_cache_v3 * ** *** ****'); + console.log('Checking the local file cache against the remote server.'); + + event_file_id; // NOTE: This is the event_file.id_random or event_file.event_file_id_random + let hash_filename = hash+'.file'; + + let save_path = path.join(host_file_cache_path, hash_filename); + console.log(save_path); + + if (fs.existsSync(save_path)) { + console.log('Local file already exists: '+save_path); + } else { + console.log('File not found locally. Downloading file: '+save_path); + let endpoint = `/event/file/${event_file_id}/download`; + ipcRenderer.send('download_file', api_base_url, endpoint, save_path); // Must download file using main node.js thread. + } + + return true; +} + + exports.check_file_cache = async function () { console.log('**** *** ** * FUNCTION: check_file_cache * ** *** ****'); console.log('Checking the local file cache against the remote server.'); diff --git a/app/js/module_app_ui.js b/app/js/module_app_ui.js index d7dc8b4..f6cb155 100644 --- a/app/js/module_app_ui.js +++ b/app/js/module_app_ui.js @@ -6,260 +6,260 @@ const { ipcRenderer } = require('electron'); exports.render_launcher = function (launcher_tmp) { - console.log('Rendering based on launcher_tmp...'); - - console.log('In module_app_ui.js v2 idb to launcher object: ***'); - console.log(launcher_tmp); - console.log('In module_app_ui.js v2 idb to launcher object: ^^^'); - /* - if (launcher_tmp.event) { - for (var i in launcher_tmp.event) { - if (launcher_tmp.event[i].id == event_id) { - console.log('*** Event id ('+event_id+') found in launcher object.'); - for (var j in launcher_tmp.location) { - if (launcher_tmp.location[j].id == event_location_id) { - console.log('*** Location id ('+event_location_id+') found in launcher object.'); - document.title = launcher_tmp.location[j].name+'@'+launcher_tmp.event[i].name; - document.getElementById('location_name').innerHTML = ' '+launcher_tmp.location[j].name+'@'+launcher_tmp.event[i].name; - } else { - console.log('Event location not it.'); - } - } - } else { - console.log('Event not it.'); - } - } - console.log('Data in launcher object'); + console.log('Rendering based on launcher_tmp...'); + + console.log('In module_app_ui.js v2 idb to launcher object: ***'); console.log(launcher_tmp); - } else { - console.log('Missing data in launcher object'); - return false; - } - */ - document.getElementById('event_files_menu').innerHTML = '