diff --git a/app/index.html b/app/index.html index debf38b..32eec8d 100644 --- a/app/index.html +++ b/app/index.html @@ -4,7 +4,7 @@ - One Sky IT: macOS App + One Sky IT @@ -34,27 +34,21 @@
+
-
- -
- -
-
- -
-
- -
+
+
+
+
+
-
- -
+
@@ -132,11 +126,6 @@ if (window.indexedDB) { console.log('IndexedDB is supported'); - - - - - } else { console.log('IndexedDB is NOT supported'); close(); @@ -180,6 +169,7 @@ storeName: 'event_location', }); tbl_event_location.length().then(function(key_count) { + console.log('tbl_event_location count: '+key_count); tbl_event_location_key_count = key_count; }).catch(function(err) { console.log(err); @@ -189,6 +179,7 @@ storeName: 'event_session', }); tbl_event_session.length().then(function(key_count) { + console.log('tbl_event_session count: '+key_count); tbl_event_session_key_count = key_count; }).catch(function(err) { console.log(err); @@ -198,6 +189,7 @@ storeName: 'event_presentation', }); tbl_event_presentation.length().then(function(key_count) { + console.log('tbl_event_presentation_key_count count: '+key_count); tbl_event_presentation_key_count = key_count; }).catch(function(err) { console.log(err); @@ -207,6 +199,7 @@ storeName: 'event_presenter', }); tbl_event_presenter.length().then(function(key_count) { + console.log('tbl_event_presenter count: '+key_count); tbl_event_presenter_key_count = key_count; }).catch(function(err) { console.log(err); @@ -252,9 +245,9 @@ */ - + //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; //2000; // 2 seconds + //const main_loop_interval = app_config.main_loop_interval; // in milliseconds const main_loop_interval = 1500; //10000; // 10 seconds idb_event_check_period = app_config.idb_event_check_period; @@ -282,10 +275,7 @@ 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 v2_launcher = new Object(); - launcher.account_id = account_id; - launcher.event_id = event_id; - launcher.event_location_id = event_location_id; + let idb_to_launcher_result = false; //let launcher_cache_check_results = false; @@ -347,33 +337,124 @@ */ + var load_cached_data_loop = setInterval(function() { + if (tbl_event && tbl_event_location && tbl_event_session + && tbl_event_presentation && tbl_event_presenter + && tbl_event_file) { + idb_tables_opened = true; + console.log('IDB tables have been opened'); + + + if (tbl_event_key_count != null && tbl_event_location_key_count != null && tbl_event_session_key_count != null + && tbl_event_presentation_key_count != null && tbl_event_presenter_key_count != null + && tbl_event_file_key_count != null) { + idb_tables_have_records = true; + console.log('All IDB tables have been checked for records.'); + + console.log('Running idb_to_launcher with cached data.'); + + idb.idb_to_launcher().then(function(response) { + console.log('Launcher object has now been created with cached data.'); + console.log(response); + clearInterval(load_cached_data_loop); + + launcher = response; + //let launcher_tmp = launcher; + + //render_launcher_result = ui.render_launcher(response); + console.log('The launcher has now been rendered with cached data. ***'); + }); + + /* + idb_to_launcer_result.then(function (response) { + console.log('Launcher object has now been created with cached data.'); + console.log(response); + clearInterval(load_cached_data_loop); + + launcher = response; + //let launcher_tmp = launcher; + + render_launcher_result = ui.render_launcher(response); + console.log('The launcher has now been rendered with cached data. ***'); + + + //render_launcher_result.then(function (response) { + // console.log('The launcher has now been rendered with cached data. ***'); + // clearInterval(load_cached_data_loop); + //}); + + }); + */ + + /* + let launcher_new = idb.idb_to_launcher(); + launcher_new_result.then + render_launcher_result = ui.render_launcher(launcher_new); + if (render_launcher_result) { + clearInterval(load_cached_data_loop); + } else { + console.log('Launcher object not really ready yet...'); + } + //render_launcher_result.then(function (response) { + // console.log('The launcher has now been rendered with cached data. ***'); + + //}); + */ + + } else { + //console.log('One or more tables did not have any records. Moving on...'); + console.log('Still waiting for the table record counts.'); + } + + } else { + idb_tables_opened = false; + console.log('Waiting for IDB tables to be opened'); + } + }, 1000); + + /* + function load_cached_data () { + idb_tables_opened = true; + console.log('IDB tables have been opened'); + + if (tbl_event_key_count && tbl_event_location_key_count && tbl_event_session_key_count + && tbl_event_presentation_key_count && tbl_event_presenter_key_count + && tbl_event_file_key_count) { + idb_tables_have_records = true; + console.log('All IDB tables have records.'); + + console.log('Running idb_to_launcher with cached data.'); + idb_to_launcher_result = idb.idb_to_launcher(launcher); + + idb_to_launcher_result.then(function (response) { + console.log('Launcher object has now been created with cached data.'); + console.log(launcher); + + let launcher_tmp = launcher; + + render_launcher_result = ui.render_launcher(launcher_tmp); + render_launcher_result.then(function (response) { + console.log('The launcher has now been rendered with cached data. ***'); + }); + }); + } + } + + var load_cached_data_results = load_cached_data(); + */ + + // NOTE This loop needs to end at some point... - setInterval(function() { + var load_auth_loop = setInterval(function() { if (typeof axios.defaults.headers.common['Authorization'] !== 'undefined' && axios.defaults.headers.common['Authorization'] != null) { axios_headers_set = true; console.log('Axios headers have been set.'); + clearInterval(load_auth_loop); } else { axios_headers_set = false; console.log('Waiting for Axios headers to be set.'); } - if (tbl_event && tbl_event_location && tbl_event_session - && tbl_event_presentation && tbl_event_presenter - && tbl_event_file) { - idb_tables_opened = true; - console.log('IDB tables have been opened'); - } else { - idb_tables_opened = false; - console.log('Waiting for IDB tables to be opened'); - } - if (tbl_event_key_count && tbl_event_location_key_count && tbl_event_session_key_count - && tbl_event_presentation_key_count && tbl_event_presenter_key_count - && tbl_event_file_key_count) { - idb_tables_have_records = true; - console.log('All IDB tables have records.'); - } else { - console.log('No IDB records for one of the tables.'); - } }, loading_loop_interval); @@ -383,7 +464,7 @@ if (idb_event_check_datetime < Date.now()) { console.log('Time to check events'); - let v2_account_events = await api.v2_get_account_events(axios, launcher.account_id); + let v2_account_events = await api.v2_get_account_events(axios, account_id); for (var i in v2_account_events) { tbl_event.setItem(v2_account_events[i].id.toString(), v2_account_events[i]); } @@ -393,7 +474,7 @@ 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, launcher.event_id); + 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]); } @@ -403,7 +484,7 @@ if (idb_event_session_check_datetime < Date.now()) { console.log('Time to check event location sessions'); - let v2_event_sessions = await api.v2_get_event_location_sessions(axios, launcher.event_location_id); + let v2_event_sessions = await api.v2_get_event_location_sessions(axios, event_location_id); for (var i in v2_event_sessions) { tbl_event_session.setItem(v2_event_sessions[i].id.toString(), v2_event_sessions[i]); } @@ -413,7 +494,7 @@ 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, launcher.event_location_id); + 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]); } @@ -423,7 +504,7 @@ 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, launcher.event_location_id); + 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]); } @@ -433,7 +514,7 @@ 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, launcher.event_location_id); + 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]); } @@ -524,9 +605,7 @@ */ } else { - console.log('Waiting '+main_loop_interval+'ms to see if Authorization header is set.'); - console.log('Waiting '+main_loop_interval+'ms to see if tbl_event_session_key_count is set.'+tbl_event_session_key_count); - + console.log('Waiting '+main_loop_interval+'ms to see if Authorization header is set, tables are opened, and record counts have been done.'); } }, main_loop_interval); diff --git a/app/js/module_app_idb.js b/app/js/module_app_idb.js index 686cf45..bac8290 100644 --- a/app/js/module_app_idb.js +++ b/app/js/module_app_idb.js @@ -13,43 +13,64 @@ exports.create_load_idb = async function create_load_idb() { exports.idb_to_launcher = async function idb_to_launcher() { //tbl_example.iterate(tbl_check, tbl_check_success, tbl_check_error); //tbl_check(value, key, iteration) - //let launcher = new Object(); + let launcher_new = new Object(); + + let tbl_event_complete = false; + let tbl_event_file_complete = false; + let tbl_event_location_complete = false; + let tbl_event_location_file_complete = false; + let tbl_event_session_complete = false; + let tbl_event_session_file_complete = false; + let tbl_event_presentation_complete = false; + let tbl_event_presentation_file_complete = false; + let tbl_event_presenter_complete = false; + let tbl_event_presenter_file_complete = false; // Look for *events* let tmp_event = []; tbl_event.iterate(function(event_value, key, iteration) { tmp_event.push(event_value); + }).then(function() { + console.log('idb_to_launcher: Iterate tbl_event complete') + tbl_event_complete = true; }); - launcher.event = tmp_event; + launcher_new.event = tmp_event; // Look for *event files* let tmp_event_file = [] tbl_event_file.iterate(function(file_value, key, iteration) { - //console.log('event id: '+launcher.event[0].id+' -> file_id: '+file_value.id+'for type: '+file_value.for_type+' for id: '+file_value.id); - if (file_value.for_type == 'event' && launcher.event[0].id == file_value.for_id) { + //console.log('event id: '+launcher_new.event[0].id+' -> file_id: '+file_value.id+'for type: '+file_value.for_type+' for id: '+file_value.id); + if (file_value.for_type == 'event' && launcher_new.event[0].id == file_value.for_id) { tmp_event_file.push(file_value); } }).then(function() { console.log('idb_to_launcher: Iterate tbl_event_file complete') + tbl_event_file_complete = true; }); - launcher.event_file = tmp_event_file; + launcher_new.event_file = tmp_event_file; // Look for *locations* let tmp_event_location = [] tbl_event_location.iterate(function(location_value, key, iteration) { tmp_event_location.push(location_value); + }).then(function() { + console.log('idb_to_launcher: Iterate tbl_event_location complete') + tbl_event_location_complete = true; }); - launcher.location = tmp_event_location; + launcher_new.location = tmp_event_location; // Look for *event location files* let tmp_event_location_file = [] tbl_event_file.iterate(function(file_value, key, iteration) { - if (file_value.for_type == 'location' && launcher.location[0].id == file_value.for_id) { + if (file_value.for_type == 'location' && launcher_new.location[0].id == file_value.for_id) { tmp_event_location_file.push(file_value); } + }).then(function() { + console.log('idb_to_launcher: Iterate tbl_event_file complete') + tbl_event_location_file_complete = true; }); - launcher.location_file = tmp_event_location_file; + launcher_new.location_file = tmp_event_location_file; // Look for *sessions* @@ -66,6 +87,9 @@ exports.idb_to_launcher = async function idb_to_launcher() { session_value.file.push(session_file_value) //tmp_event_session_file.push(session_file_value); } + }).then(function() { + console.log('idb_to_launcher: Iterate tbl_event_file complete') + tbl_event_session_file_complete = true; }); @@ -82,6 +106,9 @@ exports.idb_to_launcher = async function idb_to_launcher() { if (presentation_file_value.for_type == 'presentation' && presentation_value.id == presentation_file_value.for_id) { presentation_value.file.push(presentation_file_value); } + }).then(function() { + console.log('idb_to_launcher: Iterate tbl_event_file complete') + tbl_event_presentation_file_complete = true; }); @@ -97,26 +124,23 @@ exports.idb_to_launcher = async function idb_to_launcher() { if (presenter_file_value.for_type == 'presenter' && presenter_value.id == presenter_file_value.for_id) { presenter_value.file.push(presenter_file_value); } + }).then(function() { + console.log('idb_to_launcher: Iterate tbl_event_file complete') + tbl_event_presenter_file_complete = true; }); - - - //NOTE for some reason this is adding duplicate presenters to a session - //NOTE is this iterating twice or something??? - /* - tbl_event_file.iterate(function(presenter_file_value, key, iteration) { - - }); - */ presentation_value.presenter.push(presenter_value); } + }).then(function() { + console.log('idb_to_launcher: Iterate tbl_event_presenter complete') + tbl_event_presenter_complete = true; }); - //NOTE add in presenters and then presenter's files - - session_value.presentation.push(presentation_value); }//); + }).then(function() { + console.log('idb_to_launcher: Iterate tbl_event_presentation complete') + tbl_event_presentation_complete = true; }); //}); @@ -124,8 +148,9 @@ exports.idb_to_launcher = async function idb_to_launcher() { }).then(function() { console.log('idb_to_launcher: Iterate tbl_event_session complete') + tbl_event_session_complete = true; }); - launcher.session = tmp_event_session; + launcher_new.session = tmp_event_session; /* console.log('v2 idb to launcher object: ***'); @@ -133,7 +158,20 @@ exports.idb_to_launcher = async function idb_to_launcher() { console.log('v2 idb to launcher object: ^^^'); */ - return true; + var creating_launcher_object_loop = setInterval(function() { + if (tbl_event_complete && tbl_event_file_complete && tbl_event_location_complete && tbl_event_location_file_complete && tbl_event_session_complete && tbl_event_session_file_complete && tbl_event_presentation_complete && tbl_event_presentation_file_complete && tbl_event_presenter_complete && tbl_event_presenter_file_complete) { + console.log('And DONE!!!'); + console.log('v2 idb to launcher object: ***'); + console.log(launcher_new); + console.log('v2 idb to launcher object: ^^^'); + ui.render_launcher(launcher_new); + clearInterval(creating_launcher_object_loop); + return launcher_new; + } else { + console.log('Still building...'); + } + }, 5); + //return launcher_new; } exports.check_file_cache = async function () { diff --git a/app/js/module_app_ui.js b/app/js/module_app_ui.js index bb0bac0..0fb83ec 100644 --- a/app/js/module_app_ui.js +++ b/app/js/module_app_ui.js @@ -5,31 +5,41 @@ const fs = require('fs'); const { ipcRenderer } = require('electron'); -exports.render_launcher = async function (launcher_tmp) { +exports.render_launcher = function (launcher_tmp) { console.log('Rendering launcher_tmp...'); console.log('In module_app_ui.js v2 idb to launcher object: ***'); console.log(launcher_tmp); console.log('In module_app_ui.js v2 idb to launcher object: ^^^'); - for (var i in launcher_tmp.event) { - if (launcher_tmp.event[i].id == event_id) { - console.log('*** Event id ('+event_id+') found in launcher object.'); - for (var j in launcher_tmp.location) { - if (launcher_tmp.location[j].id == event_location_id) { - console.log('*** Location id ('+event_location_id+') found in launcher object.'); - document.getElementById('location_title').innerHTML = '

Launcher '+launcher_tmp.location[j].name+'@'+launcher_tmp.event[i].name+'

'; - } else { + if (launcher_tmp.event) { + for (var i in launcher_tmp.event) { + if (launcher_tmp.event[i].id == event_id) { + console.log('*** Event id ('+event_id+') found in launcher object.'); + for (var j in launcher_tmp.location) { + if (launcher_tmp.location[j].id == event_location_id) { + console.log('*** Location id ('+event_location_id+') found in launcher object.'); + document.title = launcher_tmp.location[j].name+'@'+launcher_tmp.event[i].name; + //document.getElementById('launcher_title').innerHTML = '

Launcher '+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.'); } - } else { } + console.log('Data in launcher object'); + console.log(launcher_tmp); + } else { + console.log('Missing data in launcher object'); + return false; } - document.getElementById('event_files_menu').innerHTML = '

Event Files

'; document.getElementById('event_files_menu').innerHTML += ''; @@ -37,22 +47,23 @@ exports.render_launcher = async function (launcher_tmp) { document.getElementById('location_files_menu').innerHTML = '

Location Files

'; document.getElementById('location_files_menu').innerHTML += ''; document.getElementById('sessions_menu').innerHTML = '

Sessions

'; document.getElementById('sessions_menu').innerHTML += '
'; // *** Session presentations card section start - //document.getElementById('location_detail').innerHTML += session_detail; + //document.getElementById('launcher_sessions').innerHTML += session_detail; if (typeof(document.getElementById('detail_session_id_'+launcher_tmp.session[i].id)) != 'undefined' && document.getElementById('detail_session_id_'+launcher_tmp.session[i].id) != null) { document.getElementById('detail_session_id_'+launcher_tmp.session[i].id).innerHTML = session_detail; } else { - document.getElementById('location_detail').innerHTML += session_detail; + document.getElementById('launcher_sessions').innerHTML += session_detail; } } document.getElementById('sessions_menu').innerHTML += ''; - index_location_detail('btn_view_session'); + index_launcher_sessions('btn_view_session'); index_open_file_buttons('open_local_file'); @@ -232,7 +230,7 @@ exports.render_launcher = async function (launcher_tmp) { /* Updated 2019-12-19 */ -function index_location_detail(class_name) { +function index_launcher_sessions(class_name) { var class_elements = document.getElementsByClassName(class_name); for (var i = 0; i < class_elements.length; i++) {