General clean up, updates, and prep for new version of launcher using Svelte.

This commit is contained in:
Scott Idem
2022-03-01 17:59:48 -05:00
parent 382e98baf1
commit cbb0dc6a82
47 changed files with 7269 additions and 8732 deletions

View File

@@ -1,441 +1,441 @@
async function api_token_request_async(axios, secret_key) {
console.log('****************** API Token Request ******************');
console.log('Requesting API temporary token...');
if (waiting_on_api_token) {
console.log('Already waiting on an API token request. Not starting another until finished.');
return false;
} else {
waiting_on_api_token = true;
const url = '/api_token_request';
let data = { secret_key: secret_key };
const result = await axios.post(url, data)
.then(function (response) {
//console.log(response);
const api_temporary_token = response.data.temporary_token;
//console.log('API Temporary Token: '+temporary_token);
return api_temporary_token;
})
.catch(function (error) {
console.error(error);
console.log('****************** API Token Request ******************');
console.log('Requesting API temporary token...');
if (waiting_on_api_token) {
console.log('Already waiting on an API token request. Not starting another until finished.');
return false;
});
waiting_on_api_token = false;
return result;
}
return false;
} else {
waiting_on_api_token = true;
const url = '/api_token_request';
let data = { secret_key: secret_key };
const result = await axios.post(url, data)
.then(function (response) {
//console.log(response);
const api_temporary_token = response.data.temporary_token;
//console.log('API Temporary Token: '+temporary_token);
return api_temporary_token;
})
.catch(function (error) {
console.error(error);
return false;
});
waiting_on_api_token = false;
return result;
}
return false;
}
async function get_event_details(axios, event_id) {
console.log('Requesting event details...');
const url = '/event/'+event_id;
const data = await axios.get(url)
.then(function (response) {
//console.log(response.data);
//data = response.data;
return response.data;
})
.catch(function (error) {
console.log(error);
return error;
});
return data;
console.log('Requesting event details...');
const url = '/event/'+event_id;
const data = await axios.get(url)
.then(function (response) {
//console.log(response.data);
//data = response.data;
return response.data;
})
.catch(function (error) {
console.log(error);
return error;
});
return data;
}
async function get_event_location_details(axios, event_id, event_location_id) {
console.log('Requesting event location details...');
const url = '/event/'+event_id+'/location/'+event_location_id;
const data = await axios.get(url)
.then(function (response) {
//console.log(response.data);
//data = response.data;
return response.data;
})
.catch(function (error) {
console.log(error);
return error;
});
return data;
console.log('Requesting event location details...');
const url = '/event/'+event_id+'/location/'+event_location_id;
const data = await axios.get(url)
.then(function (response) {
//console.log(response.data);
//data = response.data;
return response.data;
})
.catch(function (error) {
console.log(error);
return error;
});
return data;
}
async function get_event_location_sessions(axios, event_id, event_location_id) {
console.log('Requesting location sessions...');
const url = '/event/'+event_id+'/location/'+event_location_id+'/session';
const data = await axios.get(url)
.then(function (response) {
//console.log(response.data);
//data = response.data;
return response.data;
})
.catch(function (error) {
console.log(error);
return error;
});
return data;
console.log('Requesting location sessions...');
const url = '/event/'+event_id+'/location/'+event_location_id+'/session';
const data = await axios.get(url)
.then(function (response) {
//console.log(response.data);
//data = response.data;
return response.data;
})
.catch(function (error) {
console.log(error);
return error;
});
return data;
}
async function get_session_presentations(axios, event_id, event_session_id) {
console.log('Requesting session presentations...');
const url = '/event/'+event_id+'/session/'+event_session_id+'/presentation';
const data = await axios.get(url)
.then(function (response) {
//console.log(response.data);
//data = response.data;
return response.data;
})
.catch(function (error) {
console.log(error);
return error;
});
return data;
console.log('Requesting session presentations...');
const url = '/event/'+event_id+'/session/'+event_session_id+'/presentation';
const data = await axios.get(url)
.then(function (response) {
//console.log(response.data);
//data = response.data;
return response.data;
})
.catch(function (error) {
console.log(error);
return error;
});
return data;
}
async function get_presentation_presenters(axios, event_id, event_session_id, event_presentation_id) {
console.log('Requesting presentation presenters...');
const url = '/event/'+event_id+'/session/'+event_session_id+'/presentation/'+event_presentation_id+'/presenter';
const data = await axios.get(url)
.then(function (response) {
//console.log(response.data);
//data = response.data;
return response.data;
})
.catch(function (error) {
console.log(error);
return error;
});
return data;
console.log('Requesting presentation presenters...');
const url = '/event/'+event_id+'/session/'+event_session_id+'/presentation/'+event_presentation_id+'/presenter';
const data = await axios.get(url)
.then(function (response) {
//console.log(response.data);
//data = response.data;
return response.data;
})
.catch(function (error) {
console.log(error);
return error;
});
return data;
}
async function get_files_for_type_for_id(axios, for_type, for_id) {
console.log('Requesting files for '+for_type+' '+for_id);
const url = '/event/file/'+for_type+'/'+for_id;
const data = await axios.get(url)
.then(function (response) {
//console.log(response.data);
//data = response.data;
return response.data;
})
.catch(function (error) {
console.log(error);
return error;
});
return data;
console.log('Requesting files for '+for_type+' '+for_id);
const url = '/event/file/'+for_type+'/'+for_id;
const data = await axios.get(url)
.then(function (response) {
//console.log(response.data);
//data = response.data;
return response.data;
})
.catch(function (error) {
console.log(error);
return error;
});
return data;
}
/*
async function download_file_id(axios, file_id, filename) {
ipcRenderer.send('download_file', api_base_url, api_endpoint, api_temporary_token, save_path); // in render thread
console.log('1: download file id '+file_id);
const url = '/event/file/'+file_id+'/download';
//const data = await axios.get(url, responseType: 'stream')
const data = await axios({
method: "get",
url: url,
responseType: "stream"
})
.then(function (response) {
console.log('2: downloaded file id '+file_id);
console.log(response);
//console.log(response.data);
let filename = 'default.txt';
if (typeof filename_override === 'undefined' || filename_override == null) {
let headerLine = response.data.headers['content-disposition'];
console.log(headerLine);
console.log(headerLine.indexOf('="'));
console.log(headerLine.indexOf('='));
if (headerLine.indexOf('="') != -1) {
let startFileNameIndex = headerLine.indexOf('="') + 2;
let endFileNameIndex = headerLine.lastIndexOf('"');
filename = headerLine.substring(startFileNameIndex, endFileNameIndex);
} else if (headerLine.indexOf('=') != -1) {
let startFileNameIndex = headerLine.indexOf('=') + 1;
let endFileNameIndex = headerLine.length;
filename = headerLine.substring(startFileNameIndex, endFileNameIndex);
} else {
filename = 'filename_not_found_in_header.txt';
}
} else {
filename = filename_override;
}
let directory = 'file_cache/';
directory_and_filename = path.join(directory, filename);
//console.log(directory_and_filename);
if (fs.existsSync(directory_and_filename)) {
console.log('3a: file already exists: '+directory_and_filename);
} else {
console.log('3b: saving file: '+directory_and_filename);
response.data.pipe(fs.createWriteStream(directory_and_filename));
}
//data = response.data;
console.log('4: saved file id '+file_id);
return true;
//return response.data;
ipcRenderer.send('download_file', api_base_url, api_endpoint, api_temporary_token, save_path); // in render thread
console.log('1: download file id '+file_id);
const url = '/event/file/'+file_id+'/download';
//const data = await axios.get(url, responseType: 'stream')
const data = await axios({
method: "get",
url: url,
responseType: "stream"
})
.catch(function (error) {
console.log(error);
return error;
});
//return data;
.then(function (response) {
console.log('2: downloaded file id '+file_id);
console.log(response);
//console.log(response.data);
let filename = 'default.txt';
if (typeof filename_override === 'undefined' || filename_override == null) {
let headerLine = response.data.headers['content-disposition'];
console.log(headerLine);
console.log(headerLine.indexOf('="'));
console.log(headerLine.indexOf('='));
if (headerLine.indexOf('="') != -1) {
let startFileNameIndex = headerLine.indexOf('="') + 2;
let endFileNameIndex = headerLine.lastIndexOf('"');
filename = headerLine.substring(startFileNameIndex, endFileNameIndex);
} else if (headerLine.indexOf('=') != -1) {
let startFileNameIndex = headerLine.indexOf('=') + 1;
let endFileNameIndex = headerLine.length;
filename = headerLine.substring(startFileNameIndex, endFileNameIndex);
} else {
filename = 'filename_not_found_in_header.txt';
}
} else {
filename = filename_override;
}
let directory = 'file_cache/';
directory_and_filename = path.join(directory, filename);
//console.log(directory_and_filename);
if (fs.existsSync(directory_and_filename)) {
console.log('3a: file already exists: '+directory_and_filename);
} else {
console.log('3b: saving file: '+directory_and_filename);
response.data.pipe(fs.createWriteStream(directory_and_filename));
}
//data = response.data;
console.log('4: saved file id '+file_id);
return true;
//return response.data;
})
.catch(function (error) {
console.log(error);
return error;
});
//return data;
}
*/
/* v2 Section */
async function v2_get_account_events(axios, account_id) {
console.log('Requesting account events...');
const url = '/v2/account/'+account_id+'/events';
const data = await axios.get(url)
.then(function (response) {
console.log('v2 account events data: ***');
console.log(response.data);
console.log('v2 account events data: ^^^');
return response.data;
})
.catch(function (error) {
console.log(error);
return error;
});
return data;
console.log('Requesting account events...');
const url = '/v2/account/'+account_id+'/events';
const data = await axios.get(url)
.then(function (response) {
console.log('v2 account events data: ***');
console.log(response.data);
console.log('v2 account events data: ^^^');
return response.data;
})
.catch(function (error) {
console.log(error);
return error;
});
return data;
}
async function v2_get_event_locations(axios, event_id) {
console.log('Requesting event locations...');
const url = '/v2/event/'+event_id+'/event_locations';
const data = await axios.get(url)
.then(function (response) {
console.log('v2 event locations data: ***');
console.log(response.data);
console.log('v2 event locations data: ^^^');
return response.data;
})
.catch(function (error) {
console.log(error);
return error;
});
return data;
console.log('Requesting event locations...');
const url = '/v2/event/'+event_id+'/event_locations';
const data = await axios.get(url)
.then(function (response) {
console.log('v2 event locations data: ***');
console.log(response.data);
console.log('v2 event locations data: ^^^');
return response.data;
})
.catch(function (error) {
console.log(error);
return error;
});
return data;
}
async function v2_get_event_sessions(axios, event_id) {
console.log('Requesting event sessions...');
const url = '/v2/event/'+event_id+'/event_sessions';
const data = await axios.get(url)
.then(function (response) {
console.log('v2 location sessions data: ***');
console.log(response.data);
console.log('v2 location sessions data: ^^^');
return response.data;
})
.catch(function (error) {
console.log(error);
return error;
});
return data;
console.log('Requesting event sessions...');
const url = '/v2/event/'+event_id+'/event_sessions';
const data = await axios.get(url)
.then(function (response) {
console.log('v2 location sessions data: ***');
console.log(response.data);
console.log('v2 location sessions data: ^^^');
return response.data;
})
.catch(function (error) {
console.log(error);
return error;
});
return data;
}
async function v2_get_event_location_sessions(axios, event_location_id) {
console.log('Requesting location sessions...');
const url = '/v2/event_location/'+event_location_id+'/event_sessions';
const data = await axios.get(url)
.then(function (response) {
console.log('v2 location sessions data: ***');
console.log(response.data);
console.log('v2 location sessions data: ^^^');
return response.data;
})
.catch(function (error) {
console.log(error);
return error;
});
return data;
console.log('Requesting location sessions...');
const url = '/v2/event_location/'+event_location_id+'/event_sessions';
const data = await axios.get(url)
.then(function (response) {
console.log('v2 location sessions data: ***');
console.log(response.data);
console.log('v2 location sessions data: ^^^');
return response.data;
})
.catch(function (error) {
console.log(error);
return error;
});
return data;
}
async function v2_get_event_location_presentations(axios, event_location_id) {
console.log('Requesting location presentations...');
const url = '/v2/event_location/'+event_location_id+'/event_presentations';
const data = await axios.get(url)
.then(function (response) {
console.log('v2 location presentations data: ***');
console.log(response.data);
console.log('v2 location presentations data: ^^^');
return response.data;
})
.catch(function (error) {
console.log(error);
return error;
});
return data;
console.log('Requesting location presentations...');
const url = '/v2/event_location/'+event_location_id+'/event_presentations';
const data = await axios.get(url)
.then(function (response) {
console.log('v2 location presentations data: ***');
console.log(response.data);
console.log('v2 location presentations data: ^^^');
return response.data;
})
.catch(function (error) {
console.log(error);
return error;
});
return data;
}
async function v2_get_event_location_presenters(axios, event_location_id) {
console.log('Requesting location presenters...');
const url = '/v2/event_location/'+event_location_id+'/event_presenters';
const data = await axios.get(url)
.then(function (response) {
console.log('v2 location presenters data: ***');
console.log(response.data);
console.log('v2 location presenters data: ^^^');
return response.data;
})
.catch(function (error) {
console.log(error);
return error;
});
return data;
console.log('Requesting location presenters...');
const url = '/v2/event_location/'+event_location_id+'/event_presenters';
const data = await axios.get(url)
.then(function (response) {
console.log('v2 location presenters data: ***');
console.log(response.data);
console.log('v2 location presenters data: ^^^');
return response.data;
})
.catch(function (error) {
console.log(error);
return error;
});
return data;
}
async function v2_get_event_files(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;
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;
}
async function v2_get_event_location_files(axios, event_location_id) {
console.log('Requesting location files...');
const url = '/v2/event_location/'+event_location_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;
console.log('Requesting location files...');
const url = '/v2/event_location/'+event_location_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;
}
async function v2_get_event_location_files_sessions(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;
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;
}
async function v2_get_event_location_files_presentations(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;
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;
}
async function v2_get_event_location_files_presenters(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;
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;
}

View File

@@ -1,413 +0,0 @@
const os = require('os');
const path = require('path');
const fs = require('fs');
const { ipcRenderer } = require('electron');
exports.launcher_cache_check = async function (launcher, api_base_url, api_temporary_token, host_file_cache_path) {
if (typeof launcher.event === 'undefined') {
launcher.event = await api.get_event_details(axios, launcher.event_id);
console.log(launcher.event.id);
idbKeyval.set(launcher.event.id, launcher.event, tbl_event);
/*
.then(function (data) {
console.log(data.id);
idbKeyval.set(data.id, data, tbl_event);
//for (var i in response) {
//var event_record = data[i];
//idbKeyval.set(response[i].id, response[i], tbl_event);
//}
});
*/
}
if (typeof launcher.location === 'undefined') {
launcher.location = await api.get_event_location_details(axios, launcher.event_id, launcher.event_location_id);
}
if (typeof launcher.event_files === 'undefined') {
console.log('Check for global event files.');
let for_id = launcher.event_id;
launcher.event_files = await api.get_files_for_type_for_id(axios, 'event', for_id);
for (var i in launcher.event_files) {
console.log('f: ('+launcher.event_files[i].event_file_id+') '+launcher.event_files[i].event_file_filename+' ***')
file_id = launcher.event_files[i].event_file_id; // NOTE: the .id is the hosted_file.id!
let filename = launcher.event_files[i].hash_sha256+'.file';
save_path = path.join(host_file_cache_path, filename);
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 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.
}
}
} else {
console.log('No check for global event files');
}
if (typeof launcher.location_files === 'undefined') {
console.log('Check for location specific files.');
let for_id = launcher.event_location_id;
launcher.location_files = await api.get_files_for_type_for_id(axios, 'location', for_id);
for (var i in launcher.location_files) {
console.log('f: ('+launcher.location_files[i].event_file_id+') '+launcher.location_files[i].event_file_filename+' ***')
file_id = launcher.location_files[i].event_file_id; // NOTE: the .id is the hosted_file.id!
let filename = launcher.location_files[i].hash_sha256+'.file';
save_path = path.join(host_file_cache_path, filename);
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 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.
}
}
} else {
console.log('No check for location specific files.');
}
if (typeof launcher.sessions === 'undefined') {
console.log('Check for location sessions.');
launcher.sessions = await api.get_event_location_sessions(axios, launcher.event_id, launcher.event_location_id);
for (var i in launcher.sessions) {
console.log('*** '+launcher.sessions[i].name+' ***')
// Check for session files start
if (typeof launcher.sessions[i].files === 'undefined') {
console.log('Check for session files.');
let for_id = launcher.sessions[i].id;
launcher.sessions[i].files = await api.get_files_for_type_for_id(axios, 'session', for_id);
if (launcher.sessions[i].files) {
console.log('Session files found.');
for (var j in launcher.sessions[i].files) {
console.log('f: ('+launcher.sessions[i].files[j].event_file_id+') '+launcher.sessions[i].files[j].event_file_filename+' ***');
file_id = launcher.sessions[i].files[j].event_file_id; // NOTE: the .id is the hosted_file.id!
let filename = launcher.sessions[i].files[j].hash_sha256+'.file';
save_path = path.join(host_file_cache_path, filename);
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 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.
}
}
} else {
console.log('No session files found.');
}
} else {
console.log('No check for session files.');
}
// Check for session files end
// Get session presentations and associated files
launcher.sessions[i].presentations = await api.get_session_presentations(axios, launcher.event_id, launcher.sessions[i].id);
for (var j in launcher.sessions[i].presentations) {
console.log('* '+launcher.sessions[i].presentations[j].name);
// Check for presentation files start
if (typeof launcher.sessions[i].presentations[j].files === 'undefined') {
console.log('Check for presentation files.');
let for_id = launcher.sessions[i].presentations[j].id;
launcher.sessions[i].presentations[j].files = await api.get_files_for_type_for_id(axios, 'presentation', for_id);
if (launcher.sessions[i].presentations[j].files) {
console.log('Presentation files found.');
for (var k in launcher.sessions[i].presentations[j].files) {
console.log('f: ('+launcher.sessions[i].presentations[j].files[k].event_file_id+') '+launcher.sessions[i].presentations[j].files[k].event_file_filename+' ***');
file_id = launcher.sessions[i].presentations[j].files[k].event_file_id; // NOTE: the .id is the hosted_file.id!
let filename = launcher.sessions[i].presentations[j].files[k].hash_sha256+'.file';
save_path = path.join(host_file_cache_path, filename);
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 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.
}
}
} else {
console.log('No presentation files found.');
}
} else {
console.log('No check for presentation files.');
}
// Check for presentation files end
// Get session presentations presenters and associated files
//let event_presentation_id = launcher.sessions[i].presentations[j].id;
launcher.sessions[i].presentations[j].presenters = await api.get_presentation_presenters(axios, launcher.event_id, launcher.sessions[i].id, launcher.sessions[i].presentations[j].id);
for (var k in launcher.sessions[i].presentations[j].presenters) {
console.log('-- '+launcher.sessions[i].presentations[j].presenters[k].given_name+' '+launcher.sessions[i].presentations[j].presenters[k].family_name)
// Check for presenter files start
if (typeof launcher.sessions[i].presentations[j].presenters[k].files === 'undefined') {
console.log('Check for presenter files.');
let for_id = launcher.sessions[i].presentations[j].presenters[k].id;
launcher.sessions[i].presentations[j].presenters[k].files = await api.get_files_for_type_for_id(axios, 'presenter', for_id);
if (launcher.sessions[i].presentations[j].presenters[k].files) {
console.log('Presenter files found.');
for (var l in launcher.sessions[i].presentations[j].presenters[k].files) {
console.log('f: ('+launcher.sessions[i].presentations[j].presenters[k].files[l].event_file_id+') '+launcher.sessions[i].presentations[j].presenters[k].files[l].event_file_filename+' ***')
file_id = launcher.sessions[i].presentations[j].presenters[k].files[l].event_file_id; // NOTE: the .id is the hosted_file.id!
let filename = launcher.sessions[i].presentations[j].presenters[k].files[l].hash_sha256+'.file';
save_path = path.join(host_file_cache_path, filename);
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 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.
}
}
} else {
console.log('No presenter files found.');
}
} else {
console.log('No check for presenter files.');
}
// Check for presenter files end
}
}
}
} else {
console.log('No check for location sessions.');
}
console.log('Location cache check finished.');
return true;
}
exports.launcher_render = async function (launcher) {
console.log('Rendering launcher...');
document.getElementById('location_title').innerHTML = '<h1>Launcher '+launcher.location.name+'@'+launcher.event.name+'</h1>';
document.getElementById('event_files_menu').innerHTML = '<h2>Event Files</h2>';
document.getElementById('event_files_menu').innerHTML += '<ul class="">';
for (var i in launcher.event_files) {
document.getElementById('event_files_menu').innerHTML += '<li id="menu_event_file_id_'+launcher.event_files[i].id+'" class="btn btn-info btn_no_case open_local_file" data-hash_sha256="'+launcher.event_files[i].hash_sha256+'.file" data-filename="'+launcher.event_files[i].event_file_filename+'">'+launcher.event_files[i].event_file_filename+'</li>';
}
document.getElementById('event_files_menu').innerHTML += '</ul>';
document.getElementById('location_files_menu').innerHTML = '<h2>Location Files</h2>';
document.getElementById('location_files_menu').innerHTML += '<ul class="" role="">';
for (var i in launcher.location_files) {
document.getElementById('location_files_menu').innerHTML += '<li id="menu_event_file_id_'+launcher.location_files[i].id+'" class="btn btn-info open_local_file" data-hash_sha256="'+launcher.location_files[i].hash_sha256+'.file" data-filename="'+launcher.location_files[i].event_file_filename+'">'+launcher.location_files[i].event_file_filename+'</li>';
}
document.getElementById('location_files_menu').innerHTML += '</ul>';
document.getElementById('sessions_menu').innerHTML = '<h2>Sessions</h2>';
document.getElementById('sessions_menu').innerHTML += '<ul class="" role="">';
//let location_detail = '';
if (document.getElementById('location_detail').innerHTML.length) {
console.log('detail_session_id_xx already exists');
} else {
console.log('location_detail already populated');
document.getElementById('location_detail').innerHTML = ''; // This needs to be reviewed.
}
for (var i in launcher.sessions) {
// List sessions in menu
document.getElementById('sessions_menu').innerHTML += '<li id="menu_session_id_'+launcher.sessions[i].id+'" class="btn btn-info btn_view_session" data-session_id="'+launcher.sessions[i].id+'">'+launcher.sessions[i].name+'</li>';
// Create containers for each session
let session_detail = '';
if (typeof(document.getElementById('detail_session_id_'+launcher.sessions[i].id)) != 'undefined' && document.getElementById('detail_session_id_'+launcher.sessions[i].id) != null) {
//console.log('detail_session_id_xx already exists');
} else {
//console.log('Adding detail_session_id_xx');
session_detail += '<div id="detail_session_id_'+launcher.sessions[i].id+'" class="container d-none session_detail" data-session_id="'+launcher.sessions[i].id+'">';
}
var session_startdatetime = new Date(launcher.sessions[i].start_datetime);
session_detail += '<h2 class="session_title">'+launcher.sessions[i].name+'<span class="badge badge-pill badge-info float-right">'+dateFns.format(session_startdatetime, 'ddd h:mm A')+'</span>'+'</h2>';
//session_detail += '<div class="">'; // for card-group
session_detail += '<div class="card">';
session_detail += '<div class="card-header">Session Files:</div>';
session_detail += '<div class="card-body">';
session_detail += '<ul>';
for (var j in launcher.sessions[i].files) {
//console.log(launcher.sessions[i].files[j].event_file_filename);
session_detail += '<li class="btn btn-info open_local_file" data-hash_sha256="'+launcher.sessions[i].files[j].hash_sha256+'.file" data-filename="'+launcher.sessions[i].files[j].event_file_filename+'">'+launcher.sessions[i].files[j].event_file_filename+'</li>';
}
session_detail += '</ul>';
session_detail += '</div>'; // for card-body
session_detail += '</div> <!-- for session files card -->'; // for session files card
//session_detail += '<div class="session_presentations">';
for (var j in launcher.sessions[i].presentations) {
//session_detail += '<li>'+launcher.sessions[i].presentations[j].name;
var session_presentation_startdatetime = new Date(launcher.sessions[i].presentations[j].start_datetime);
session_detail += '<div class="card">';
session_detail += '<div class="card-header">'+launcher.sessions[i].presentations[j].name+'<span class="badge badge-pill badge-info float-right">'+dateFns.format(session_startdatetime, 'h:mm a')+'</span>'+':</div>';
session_detail += '<div class="card-body">';
session_detail += '<ul class="list-group">';
for (var k in launcher.sessions[i].presentations[j].files) {
//console.log(launcher.sessions[i].presentations[j].files[k].event_file_filename);
session_detail += '<li class="list-group-item btn btn-info open_local_file" data-hash_sha256="'+launcher.sessions[i].presentations[j].files[k].hash_sha256+'.file" data-filename="'+launcher.sessions[i].presentations[j].files[k].event_file_filename+'">'+launcher.sessions[i].presentations[j].files[k].event_file_filename+'</li>';
}
session_detail += '</ul>';
session_detail += '<ul>';
for (var k in launcher.sessions[i].presentations[j].presenters) {
//console.log(launcher.sessions[i].presentations[j].presenters[k].given_name);
session_detail += '<li>'+launcher.sessions[i].presentations[j].presenters[k].given_name+' '+launcher.sessions[i].presentations[j].presenters[k].family_name;
session_detail += '<ul class="list-group">';
for (var l in launcher.sessions[i].presentations[j].presenters[k].files) {
//console.log(launcher.sessions[i].presentations[j].presenters[k].files[l].event_file_filename);
//session_detail += '<li class="list-group-item" data-hash_sha256="'+launcher.sessions[i].presentations[j].presenters[k].files[l].hash_sha256+'.file" data-filename="'+launcher.sessions[i].presentations[j].presenters[k].files[l].event_file_filename+'">'+launcher.sessions[i].presentations[j].presenters[k].files[l].event_file_filename;
session_detail += '<li class="list-group-item" data-hash_sha256="'+launcher.sessions[i].presentations[j].presenters[k].files[l].hash_sha256+'.file" data-filename="'+launcher.sessions[i].presentations[j].presenters[k].files[l].event_file_filename+'">';
session_detail += '<button class="btn btn-info open_local_file" data-hash_sha256="'+launcher.sessions[i].presentations[j].presenters[k].files[l].hash_sha256+'.file" data-filename="'+launcher.sessions[i].presentations[j].presenters[k].files[l].event_file_filename+'">'+launcher.sessions[i].presentations[j].presenters[k].files[l].event_file_filename+'</button>';
var event_file_size = launcher.sessions[i].presentations[j].presenters[k].files[l].size;
var event_file_created_on = new Date(launcher.sessions[i].presentations[j].presenters[k].files[l].created_on);
session_detail += '<span class="badge badge-pill badge-light float-right">'+format_bytes(event_file_size, 2)+'; '+dateFns.format(event_file_created_on, 'MMM M h:mm A')+'; '+launcher.sessions[i].presentations[j].presenters[k].files[l].internal_os+'</span>';
session_detail += '</li>';
}
session_detail += '</ul>';
session_detail +='</li>';
}
session_detail += '</ul>';
session_detail += '</ul>';
session_detail += '</div>'; // for card-body
session_detail += '</div> <!-- for card -->'; // for card
}
//session_detail += '</div> <!-- for session_presentations -->'; // for session_presentations
//session_detail += '</div>'; // for card-group
session_detail += '</div> <!-- End session detail for '+launcher.sessions[i].id+' -->';
//document.getElementById('location_detail').innerHTML += session_detail;
if (typeof(document.getElementById('detail_session_id_'+launcher.sessions[i].id)) != 'undefined' && document.getElementById('detail_session_id_'+launcher.sessions[i].id) != null) {
document.getElementById('detail_session_id_'+launcher.sessions[i].id).innerHTML = session_detail;
} else {
document.getElementById('location_detail').innerHTML += session_detail;
}
}
document.getElementById('sessions_menu').innerHTML += '</ul>';
index_location_detail('btn_view_session');
index_open_file_buttons('open_local_file');
//const btn_session_{{ event_presentation.id }}_name = document.querySelector('button#presentation_{{ event_presentation.id }}_name');
//btn_presentation_{{ event_presentation.id }}_name.onclick = display_hide_poster_for_type_id.bind(this, true, 'presentation', {{ event_presentation.id }});
console.log('Rendering launcher finished.');
return true;
}
/* Updated 2019-12-19 */
function index_location_detail(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')) } );
}
return true;
}
/* Updated 2019-12-19 */
function view_session(session_id) {
var class_elements = document.getElementsByClassName('session_detail');
console.log('*** 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 2019-12-20 */
function index_open_file_buttons(class_name) {
var class_elements = document.getElementsByClassName(class_name);
for (var i = 0; i < class_elements.length; i++) {
//class_elements[i].addEventListener( 'click', function() {open_local_file( this.getAttribute('data-filename')) } );
//let directory = 'file_cache/';
//directory_and_filename = path.join(directory, class_elements[i].getAttribute('data-filename'));
let file_path = path.join(host_file_cache_path, class_elements[i].getAttribute('data-hash_sha256'));
let filename = class_elements[i].getAttribute('data-filename');
class_elements[i].addEventListener( 'click', function() { ipcRenderer.send('open_local_file', file_path, filename) } );
//ipcRenderer.send('open_local_file', this.getAttribute('data-filename')); // in render thread
}
return true;
}
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];
}

View File

@@ -1,57 +1,57 @@
async function load_idb_tables() {
console.log('****************** Load IDB Tables ******************');
console.log('Loading IDB tables...');
localforage.config({
driver: localforage.INDEXEDDB,
version: 1,
name: idb_name
});
tbl_event = await localforage.createInstance({
name: idb_name,
storeName: 'event',
});
console.log('tbl_event count: '+ await tbl_event.length());
tbl_event_key_count = await tbl_event.length();
tbl_event_location = await localforage.createInstance({
name: idb_name,
storeName: 'event_location',
});
console.log('tbl_event_location count: '+ await tbl_event_location.length());
tbl_event_location_key_count = await tbl_event_location.length();
tbl_event_session = await localforage.createInstance({
name: idb_name,
storeName: 'event_session',
});
console.log('tbl_event_session count: '+ await tbl_event_session.length());
tbl_event_session_key_count = await tbl_event_session.length();
tbl_event_presentation = await localforage.createInstance({
name: idb_name,
storeName: 'event_presentation',
});
console.log('tbl_event_presentation count: '+ await tbl_event_presentation.length());
tbl_event_presentation_key_count = await tbl_event_presentation.length();
tbl_event_presenter = await localforage.createInstance({
name: idb_name,
storeName: 'event_presenter',
});
console.log('tbl_event_presenter count: '+ await tbl_event_presenter.length());
tbl_event_presenter_key_count = await tbl_event_presenter.length();
tbl_event_file = await localforage.createInstance({
name: idb_name,
storeName: 'event_file',
});
console.log('tbl_event_file count: '+ await tbl_event_file.length());
tbl_event_file_key_count = await tbl_event_file.length();
console.log('IDB tables have now been opened.');
return true;
console.log('****************** Load IDB Tables ******************');
console.log('Loading IDB tables...');
localforage.config({
driver: localforage.INDEXEDDB,
version: 1,
name: idb_name
});
tbl_event = await localforage.createInstance({
name: idb_name,
storeName: 'event',
});
console.log('tbl_event count: '+ await tbl_event.length());
tbl_event_key_count = await tbl_event.length();
tbl_event_location = await localforage.createInstance({
name: idb_name,
storeName: 'event_location',
});
console.log('tbl_event_location count: '+ await tbl_event_location.length());
tbl_event_location_key_count = await tbl_event_location.length();
tbl_event_session = await localforage.createInstance({
name: idb_name,
storeName: 'event_session',
});
console.log('tbl_event_session count: '+ await tbl_event_session.length());
tbl_event_session_key_count = await tbl_event_session.length();
tbl_event_presentation = await localforage.createInstance({
name: idb_name,
storeName: 'event_presentation',
});
console.log('tbl_event_presentation count: '+ await tbl_event_presentation.length());
tbl_event_presentation_key_count = await tbl_event_presentation.length();
tbl_event_presenter = await localforage.createInstance({
name: idb_name,
storeName: 'event_presenter',
});
console.log('tbl_event_presenter count: '+ await tbl_event_presenter.length());
tbl_event_presenter_key_count = await tbl_event_presenter.length();
tbl_event_file = await localforage.createInstance({
name: idb_name,
storeName: 'event_file',
});
console.log('tbl_event_file count: '+ await tbl_event_file.length());
tbl_event_file_key_count = await tbl_event_file.length();
console.log('IDB tables have now been opened.');
return true;
}

View File

@@ -1,142 +0,0 @@
const os = require('os');
const path = require('path');
const fs = require('fs');
let request_waiting = false;
setInterval(async function() {
if (typeof axios.defaults.headers.common['Authorization'] !== 'undefined' && axios.defaults.headers.common['Authorization'] != null) {
if (typeof launcher.sessions === 'undefined') {
console.log('Check for location files.');
let for_id = launcher.event_location_id;
launcher.files = await api.get_files_for_type_for_id(axios, 'location', for_id);
for (var i in launcher.files) {
console.log('f: ('+launcher.files[i].event_file_id+') '+launcher.files[i].event_file_filename+' ***')
file_id = launcher.files[i].event_file_id; // NOTE: the .id is the hosted_file.id!
filename = launcher.files[i].hash_sha256+'.file';
save_path = path.join(file_cache_path, filename);
//console.log(directory_and_filename);
if (fs.existsSync(save_path)) {
console.log('Local file already exists: '+save_path);
} else {
console.log('File not found locally. Downloading file: '+save_path);
ipcRenderer.send('download_file', api_base_url, api_endpoint, api_temporary_token, save_path); // Must download file using main node.js thread.
//response.data.pipe(fs.createWriteStream(directory_and_filename));
}
//let results = await api.download_file_id(axios, file_id, hash_sha256);
}
} else {
console.log('No check for location files.');
}
if (typeof launcher.sessions === 'undefined') {
console.log('Check for location sessions.');
launcher.sessions = await api.get_event_location_sessions(axios, launcher.event_id, launcher.event_location_id);
for (var i in launcher.sessions) {
console.log('*** '+launcher.sessions[i].name+' ***')
// Check for session files start
if (typeof launcher.sessions[i].files === 'undefined') {
console.log('Check for session files.');
let for_id = launcher.sessions[i].id;
launcher.sessions[i].files = await api.get_files_for_type_for_id(axios, 'session', for_id);
if (launcher.sessions[i].files) {
console.log('Session files found.');
for (var j in launcher.sessions[i].files) {
console.log('f: ('+launcher.sessions[i].files[j].event_file_id+') '+launcher.sessions[i].files[j].event_file_filename+' ***');
file_id = launcher.sessions[i].files[j].event_file_id; // NOTE: the .id is the hosted_file.id!
hash_sha256 = launcher.sessions[i].files[j].hash_sha256+'.file';
let results = await api.download_file_id(axios, file_id, hash_sha256);
}
} else {
console.log('No session files found.');
}
} else {
console.log('No check for session files.');
}
// Check for session files end
// Get session presentations and associated files
launcher.sessions[i].presentations = await api.get_session_presentations(axios, launcher.event_id, launcher.sessions[i].id);
for (var j in launcher.sessions[i].presentations) {
console.log('* '+launcher.sessions[i].presentations[j].name);
// Check for presentation files start
if (typeof launcher.sessions[i].presentations[j].files === 'undefined') {
console.log('Check for presentation files.');
let for_id = launcher.sessions[i].presentations[j].id;
launcher.sessions[i].presentations[j].files = await api.get_files_for_type_for_id(axios, 'presentation', for_id);
if (launcher.sessions[i].presentations[j].files) {
console.log('Presentation files found.');
for (var k in launcher.sessions[i].presentations[j].files) {
console.log('f: ('+launcher.sessions[i].presentations[j].files[k].event_file_id+') '+launcher.sessions[i].presentations[j].files[k].event_file_filename+' ***');
file_id = launcher.sessions[i].presentations[j].files[k].event_file_id; // NOTE: the .id is the hosted_file.id!
hash_sha256 = launcher.sessions[i].presentations[j].files[k].hash_sha256+'.file';
let results = await api.download_file_id(axios, file_id, hash_sha256);
}
} else {
console.log('No presentation files found.');
}
} else {
console.log('No check for presentation files.');
}
// Check for presentation files end
// Get session presentations presenters and associated files
//let event_presentation_id = launcher.sessions[i].presentations[j].id;
launcher.sessions[i].presentations[j].presenters = await api.get_presentation_presenters(axios, launcher.event_id, launcher.sessions[i].id, launcher.sessions[i].presentations[j].id);
for (var k in launcher.sessions[i].presentations[j].presenters) {
console.log('-- '+launcher.sessions[i].presentations[j].presenters[k].given_name+' '+launcher.sessions[i].presentations[j].presenters[k].family_name)
// Check for presenter files start
if (typeof launcher.sessions[i].presentations[j].presenters[k].files === 'undefined') {
console.log('Check for presenter files.');
let for_id = launcher.sessions[i].presentations[j].presenters[k].id;
launcher.sessions[i].presentations[j].presenters[k].files = await api.get_files_for_type_for_id(axios, 'presenter', for_id);
if (launcher.sessions[i].presentations[j].presenters[k].files) {
console.log('Presenter files found.');
for (var l in launcher.sessions[i].presentations[j].presenters[k].files) {
console.log('f: ('+launcher.sessions[i].presentations[j].presenters[k].files[l].event_file_id+') '+launcher.sessions[i].presentations[j].presenters[k].files[l].event_file_filename+' ***')
file_id = launcher.sessions[i].presentations[j].presenters[k].files[l].event_file_id; // NOTE: the .id is the hosted_file.id!
hash_sha256 = launcher.sessions[i].presentations[j].presenters[k].files[l].hash_sha256+'.file';
let results = await api.download_file_id(axios, file_id, hash_sha256);
}
} else {
console.log('No presenter files found.');
}
} else {
console.log('No check for presenter files.');
}
// Check for presenter files end
}
}
}
} else {
console.log('No check for location sessions.');
}
/*
if (launcher.sessions) {
console.log('Check for session files.');
let for_id = launcher.event_location_id;
launcher.files = await api.get_files_for_type_for_id(axios, 'location', for_id);
for (var i in launcher.sessions) {
console.log('f: ('+launcher.sessions[i].event_file_id+') '+launcher.files[i].event_file_filename+' ***')
file_id = launcher.files[i].event_file_id; // NOTE: the .id is the hosted_file.id!
let results = await api.download_file_id(axios, file_id);
}
} else {
console.log('No check for location files.');
}
*/
} else {
console.log('Waiting a few more seconds to see if Authorization header is set.');
}
}, 5000);

View File

@@ -1,422 +0,0 @@
const os = require('os');
const path = require('path');
const fs = require('fs');
const { ipcRenderer } = require('electron');
exports.api_token_request_async = async function (axios, secret_key) {
console.log('Requesting API temporary token...');
const url = '/api_token_request';
let data = { secret_key: secret_key };
const response = await axios.post(url, data)
.then(function (response) {
//console.log(response);
const api_temporary_token = response.data.temporary_token;
//console.log('API Temporary Token: '+temporary_token);
return api_temporary_token;
})
.catch(function (error) {
console.error(error);
return error;
});
return response;
}
exports.get_event_location_sessions = async function (axios, event_id, event_location_id) {
console.log('Requesting location sessions...');
const url = '/event/'+event_id+'/location/'+event_location_id+'/session';
const data = await axios.get(url)
.then(function (response) {
//console.log(response.data);
//data = response.data;
return response.data;
})
.catch(function (error) {
console.log(error);
return error;
});
return data;
}
exports.get_session_presentations = async function (axios, event_id, event_session_id) {
console.log('Requesting session presentations...');
const url = '/event/'+event_id+'/session/'+event_session_id+'/presentation';
const data = await axios.get(url)
.then(function (response) {
//console.log(response.data);
//data = response.data;
return response.data;
})
.catch(function (error) {
console.log(error);
return error;
});
return data;
}
exports.get_presentation_presenters = async function (axios, event_id, event_session_id, event_presentation_id) {
console.log('Requesting presentation presenters...');
const url = '/event/'+event_id+'/session/'+event_session_id+'/presentation/'+event_presentation_id+'/presenter';
const data = await axios.get(url)
.then(function (response) {
//console.log(response.data);
//data = response.data;
return response.data;
})
.catch(function (error) {
console.log(error);
return error;
});
return data;
}
exports.get_files_for_type_for_id = async function (axios, for_type, for_id) {
console.log('Requesting files for '+for_type+' '+for_id);
const url = '/event/file/'+for_type+'/'+for_id;
const data = await axios.get(url)
.then(function (response) {
//console.log(response.data);
//data = response.data;
return response.data;
})
.catch(function (error) {
console.log(error);
return error;
});
return data;
}
exports.download_file_id = async function (axios, file_id, filename) {
ipcRenderer.send('download_file', api_base_url, api_endpoint, api_temporary_token, save_path); // in render thread
console.log('1: download file id '+file_id);
const url = '/event/file/'+file_id+'/download';
//const data = await axios.get(url, responseType: 'stream')
const data = await axios({
method: "get",
url: url,
responseType: "stream"
})
.then(function (response) {
console.log('2: downloaded file id '+file_id);
console.log(response);
//console.log(response.data);
let filename = 'default.txt';
if (typeof filename_override === 'undefined' || filename_override == null) {
let headerLine = response.data.headers['content-disposition'];
console.log(headerLine);
console.log(headerLine.indexOf('="'));
console.log(headerLine.indexOf('='));
if (headerLine.indexOf('="') != -1) {
let startFileNameIndex = headerLine.indexOf('="') + 2;
let endFileNameIndex = headerLine.lastIndexOf('"');
filename = headerLine.substring(startFileNameIndex, endFileNameIndex);
} else if (headerLine.indexOf('=') != -1) {
let startFileNameIndex = headerLine.indexOf('=') + 1;
let endFileNameIndex = headerLine.length;
filename = headerLine.substring(startFileNameIndex, endFileNameIndex);
} else {
filename = 'filename_not_found_in_header.txt';
}
} else {
filename = filename_override;
}
let directory = 'file_cache/';
directory_and_filename = path.join(directory, filename);
//console.log(directory_and_filename);
if (fs.existsSync(directory_and_filename)) {
console.log('3a: file already exists: '+directory_and_filename);
} else {
console.log('3b: saving file: '+directory_and_filename);
response.data.pipe(fs.createWriteStream(directory_and_filename));
}
//data = response.data;
console.log('4: saved file id '+file_id);
return true;
//return response.data;
})
.catch(function (error) {
console.log(error);
return error;
});
//return data;
}
exports.launcher_cache_check = async function (launcher, api_base_url, api_temporary_token, file_cache_path) {
if (typeof launcher.event_files === 'undefined') {
console.log('Check for global event files.');
let for_id = launcher.event_id;
launcher.event_files = await api.get_files_for_type_for_id(axios, 'event', for_id);
for (var i in launcher.event_files) {
console.log('f: ('+launcher.event_files[i].event_file_id+') '+launcher.event_files[i].event_file_filename+' ***')
file_id = launcher.event_files[i].event_file_id; // NOTE: the .id is the hosted_file.id!
let filename = launcher.event_files[i].hash_sha256+'.file';
save_path = path.join(file_cache_path, filename);
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 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.
}
}
} else {
console.log('No check for global event files');
}
if (typeof launcher.location_files === 'undefined') {
console.log('Check for location specific files.');
let for_id = launcher.event_location_id;
launcher.location_files = await api.get_files_for_type_for_id(axios, 'location', for_id);
for (var i in launcher.location_files) {
console.log('f: ('+launcher.location_files[i].event_file_id+') '+launcher.location_files[i].event_file_filename+' ***')
file_id = launcher.location_files[i].event_file_id; // NOTE: the .id is the hosted_file.id!
let filename = launcher.location_files[i].hash_sha256+'.file';
save_path = path.join(file_cache_path, filename);
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 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.
}
}
} else {
console.log('No check for location specific files.');
}
if (typeof launcher.sessions === 'undefined') {
console.log('Check for location sessions.');
launcher.sessions = await api.get_event_location_sessions(axios, launcher.event_id, launcher.event_location_id);
for (var i in launcher.sessions) {
console.log('*** '+launcher.sessions[i].name+' ***')
// Check for session files start
if (typeof launcher.sessions[i].files === 'undefined') {
console.log('Check for session files.');
let for_id = launcher.sessions[i].id;
launcher.sessions[i].files = await api.get_files_for_type_for_id(axios, 'session', for_id);
if (launcher.sessions[i].files) {
console.log('Session files found.');
for (var j in launcher.sessions[i].files) {
console.log('f: ('+launcher.sessions[i].files[j].event_file_id+') '+launcher.sessions[i].files[j].event_file_filename+' ***');
file_id = launcher.sessions[i].files[j].event_file_id; // NOTE: the .id is the hosted_file.id!
let filename = launcher.sessions[i].files[j].hash_sha256+'.file';
save_path = path.join(file_cache_path, filename);
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 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.
}
}
} else {
console.log('No session files found.');
}
} else {
console.log('No check for session files.');
}
// Check for session files end
// Get session presentations and associated files
launcher.sessions[i].presentations = await api.get_session_presentations(axios, launcher.event_id, launcher.sessions[i].id);
for (var j in launcher.sessions[i].presentations) {
console.log('* '+launcher.sessions[i].presentations[j].name);
// Check for presentation files start
if (typeof launcher.sessions[i].presentations[j].files === 'undefined') {
console.log('Check for presentation files.');
let for_id = launcher.sessions[i].presentations[j].id;
launcher.sessions[i].presentations[j].files = await api.get_files_for_type_for_id(axios, 'presentation', for_id);
if (launcher.sessions[i].presentations[j].files) {
console.log('Presentation files found.');
for (var k in launcher.sessions[i].presentations[j].files) {
console.log('f: ('+launcher.sessions[i].presentations[j].files[k].event_file_id+') '+launcher.sessions[i].presentations[j].files[k].event_file_filename+' ***');
file_id = launcher.sessions[i].presentations[j].files[k].event_file_id; // NOTE: the .id is the hosted_file.id!
let filename = launcher.sessions[i].presentations[j].files[k].hash_sha256+'.file';
save_path = path.join(file_cache_path, filename);
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 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.
}
}
} else {
console.log('No presentation files found.');
}
} else {
console.log('No check for presentation files.');
}
// Check for presentation files end
// Get session presentations presenters and associated files
//let event_presentation_id = launcher.sessions[i].presentations[j].id;
launcher.sessions[i].presentations[j].presenters = await api.get_presentation_presenters(axios, launcher.event_id, launcher.sessions[i].id, launcher.sessions[i].presentations[j].id);
for (var k in launcher.sessions[i].presentations[j].presenters) {
console.log('-- '+launcher.sessions[i].presentations[j].presenters[k].given_name+' '+launcher.sessions[i].presentations[j].presenters[k].family_name)
// Check for presenter files start
if (typeof launcher.sessions[i].presentations[j].presenters[k].files === 'undefined') {
console.log('Check for presenter files.');
let for_id = launcher.sessions[i].presentations[j].presenters[k].id;
launcher.sessions[i].presentations[j].presenters[k].files = await api.get_files_for_type_for_id(axios, 'presenter', for_id);
if (launcher.sessions[i].presentations[j].presenters[k].files) {
console.log('Presenter files found.');
for (var l in launcher.sessions[i].presentations[j].presenters[k].files) {
console.log('f: ('+launcher.sessions[i].presentations[j].presenters[k].files[l].event_file_id+') '+launcher.sessions[i].presentations[j].presenters[k].files[l].event_file_filename+' ***')
file_id = launcher.sessions[i].presentations[j].presenters[k].files[l].event_file_id; // NOTE: the .id is the hosted_file.id!
let filename = launcher.sessions[i].presentations[j].presenters[k].files[l].hash_sha256+'.file';
save_path = path.join(file_cache_path, filename);
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 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.
}
}
} else {
console.log('No presenter files found.');
}
} else {
console.log('No check for presenter files.');
}
// Check for presenter files end
}
}
}
} else {
console.log('No check for location sessions.');
}
console.log('Location cache check finished.');
return true;
}
exports.launcher_render = async function (launcher) {
console.log('Rendering launcher...');
document.getElementById('location_title').innerHTML = '<h1>Launcher '+launcher.event_location_id+'@'+launcher.event_id+'</h1>';
document.getElementById('event_files_menu').innerHTML = '<h2>Event Files</h2>';
document.getElementById('event_files_menu').innerHTML += '<ul class="">';
for (var i in launcher.event_files) {
document.getElementById('event_files_menu').innerHTML += '<li id="menu_event_file_id_'+launcher.event_files[i].id+'" class="btn btn-info">'+launcher.event_files[i].event_file_filename+'</li>';
}
document.getElementById('event_files_menu').innerHTML += '</ul>';
document.getElementById('location_files_menu').innerHTML = '<h2>Location Files</h2>';
document.getElementById('location_files_menu').innerHTML += '<ul class="" role="">';
for (var i in launcher.location_files) {
document.getElementById('location_files_menu').innerHTML += '<li id="menu_event_file_id_'+launcher.location_files[i].id+'" class="btn btn-info">'+launcher.location_files[i].event_file_filename+'</li>';
}
document.getElementById('location_files_menu').innerHTML += '</ul>';
document.getElementById('sessions_menu').innerHTML = '<h2>Sessions</h2>';
document.getElementById('sessions_menu').innerHTML += '<ul class="" role="">';
//let sessions_detail = '';
document.getElementById('sessions_detail').innerHTML = ''; // This needs to be reviewed.
for (var i in launcher.sessions) {
// List sessions in menu
document.getElementById('sessions_menu').innerHTML += '<li id="menu_session_id_'+launcher.sessions[i].id+'" class="btn btn-info btn_view_session" data-session_id="'+launcher.sessions[i].id+'">'+launcher.sessions[i].name+'</li>';
// Create containers for each session
let session_detail = '';
session_detail += '<div id="detail_session_id_'+launcher.sessions[i].id+'" class="container d-none session_detail" data-session_id="'+launcher.sessions[i].id+'">';
session_detail += '<h2 class="session_title">'+launcher.sessions[i].name+'</h2>';
session_detail += '<div class="session_presentations"><ul>';
for (var j in launcher.sessions[i].presentations) {
session_detail += '<li>'+launcher.sessions[i].presentations[j].name+'</li>';
}
session_detail += '</ul></div>';
session_detail += '</div> <!-- End session detail for '+launcher.sessions[i].id+' -->';
document.getElementById('sessions_detail').innerHTML += session_detail;
//document.getElementById('sessions_menu').innerHTML += '</ul>';
}
document.getElementById('sessions_menu').innerHTML += '</ul>';
index_sessions_detail('btn_view_session');
//const btn_session_{{ event_presentation.id }}_name = document.querySelector('button#presentation_{{ event_presentation.id }}_name');
//btn_presentation_{{ event_presentation.id }}_name.onclick = display_hide_poster_for_type_id.bind(this, true, 'presentation', {{ event_presentation.id }});
return true;
}
/* Updated 2019-12-19 */
function index_sessions_detail(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')) } );
}
return true;
}
/* Updated 2019-12-19 */
function view_session(session_id) {
var class_elements = document.getElementsByClassName('session_detail');
console.log('*** 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;
}

View File

@@ -1,614 +0,0 @@
const os = require('os');
const path = require('path');
const fs = require('fs');
const { ipcRenderer } = require('electron');
exports.api_token_request_async = async function (axios, secret_key) {
console.log('Requesting API temporary token...');
const url = '/api_token_request';
let data = { secret_key: secret_key };
const response = await axios.post(url, data)
.then(function (response) {
//console.log(response);
const api_temporary_token = response.data.temporary_token;
//console.log('API Temporary Token: '+temporary_token);
return api_temporary_token;
})
.catch(function (error) {
console.error(error);
return error;
});
return response;
}
exports.get_event_details = async function (axios, event_id) {
console.log('Requesting event details...');
const url = '/event/'+event_id;
const data = await axios.get(url)
.then(function (response) {
//console.log(response.data);
//data = response.data;
return response.data;
})
.catch(function (error) {
console.log(error);
return error;
});
return data;
}
exports.get_event_location_details = async function (axios, event_id, event_location_id) {
console.log('Requesting event location details...');
const url = '/event/'+event_id+'/location/'+event_location_id;
const data = await axios.get(url)
.then(function (response) {
//console.log(response.data);
//data = response.data;
return response.data;
})
.catch(function (error) {
console.log(error);
return error;
});
return data;
}
exports.get_event_location_sessions = async function (axios, event_id, event_location_id) {
console.log('Requesting location sessions...');
const url = '/event/'+event_id+'/location/'+event_location_id+'/session';
const data = await axios.get(url)
.then(function (response) {
//console.log(response.data);
//data = response.data;
return response.data;
})
.catch(function (error) {
console.log(error);
return error;
});
return data;
}
exports.get_session_presentations = async function (axios, event_id, event_session_id) {
console.log('Requesting session presentations...');
const url = '/event/'+event_id+'/session/'+event_session_id+'/presentation';
const data = await axios.get(url)
.then(function (response) {
//console.log(response.data);
//data = response.data;
return response.data;
})
.catch(function (error) {
console.log(error);
return error;
});
return data;
}
exports.get_presentation_presenters = async function (axios, event_id, event_session_id, event_presentation_id) {
console.log('Requesting presentation presenters...');
const url = '/event/'+event_id+'/session/'+event_session_id+'/presentation/'+event_presentation_id+'/presenter';
const data = await axios.get(url)
.then(function (response) {
//console.log(response.data);
//data = response.data;
return response.data;
})
.catch(function (error) {
console.log(error);
return error;
});
return data;
}
exports.get_files_for_type_for_id = async function (axios, for_type, for_id) {
console.log('Requesting files for '+for_type+' '+for_id);
const url = '/event/file/'+for_type+'/'+for_id;
const data = await axios.get(url)
.then(function (response) {
//console.log(response.data);
//data = response.data;
return response.data;
})
.catch(function (error) {
console.log(error);
return error;
});
return data;
}
exports.download_file_id = async function (axios, file_id, filename) {
ipcRenderer.send('download_file', api_base_url, api_endpoint, api_temporary_token, save_path); // in render thread
console.log('1: download file id '+file_id);
const url = '/event/file/'+file_id+'/download';
//const data = await axios.get(url, responseType: 'stream')
const data = await axios({
method: "get",
url: url,
responseType: "stream"
})
.then(function (response) {
console.log('2: downloaded file id '+file_id);
console.log(response);
//console.log(response.data);
let filename = 'default.txt';
if (typeof filename_override === 'undefined' || filename_override == null) {
let headerLine = response.data.headers['content-disposition'];
console.log(headerLine);
console.log(headerLine.indexOf('="'));
console.log(headerLine.indexOf('='));
if (headerLine.indexOf('="') != -1) {
let startFileNameIndex = headerLine.indexOf('="') + 2;
let endFileNameIndex = headerLine.lastIndexOf('"');
filename = headerLine.substring(startFileNameIndex, endFileNameIndex);
} else if (headerLine.indexOf('=') != -1) {
let startFileNameIndex = headerLine.indexOf('=') + 1;
let endFileNameIndex = headerLine.length;
filename = headerLine.substring(startFileNameIndex, endFileNameIndex);
} else {
filename = 'filename_not_found_in_header.txt';
}
} else {
filename = filename_override;
}
let directory = 'file_cache/';
directory_and_filename = path.join(directory, filename);
//console.log(directory_and_filename);
if (fs.existsSync(directory_and_filename)) {
console.log('3a: file already exists: '+directory_and_filename);
} else {
console.log('3b: saving file: '+directory_and_filename);
response.data.pipe(fs.createWriteStream(directory_and_filename));
}
//data = response.data;
console.log('4: saved file id '+file_id);
return true;
//return response.data;
})
.catch(function (error) {
console.log(error);
return error;
});
//return data;
}
exports.launcher_cache_check = async function (launcher, api_base_url, api_temporary_token, file_cache_path) {
if (typeof launcher.event === 'undefined') {
launcher.event = await api.get_event_details(axios, launcher.event_id);
console.log(launcher.event.id);
idbKeyval.set(launcher.event.id, launcher.event, db_event);
/*
.then(function (data) {
console.log(data.id);
idbKeyval.set(data.id, data, db_event);
//for (var i in response) {
//var event_record = data[i];
//idbKeyval.set(response[i].id, response[i], db_event);
//}
});
*/
}
if (typeof launcher.location === 'undefined') {
launcher.location = await api.get_event_location_details(axios, launcher.event_id, launcher.event_location_id);
}
if (typeof launcher.event_files === 'undefined') {
console.log('Check for global event files.');
let for_id = launcher.event_id;
launcher.event_files = await api.get_files_for_type_for_id(axios, 'event', for_id);
for (var i in launcher.event_files) {
console.log('f: ('+launcher.event_files[i].event_file_id+') '+launcher.event_files[i].event_file_filename+' ***')
file_id = launcher.event_files[i].event_file_id; // NOTE: the .id is the hosted_file.id!
let filename = launcher.event_files[i].hash_sha256+'.file';
save_path = path.join(file_cache_path, filename);
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 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.
}
}
} else {
console.log('No check for global event files');
}
if (typeof launcher.location_files === 'undefined') {
console.log('Check for location specific files.');
let for_id = launcher.event_location_id;
launcher.location_files = await api.get_files_for_type_for_id(axios, 'location', for_id);
for (var i in launcher.location_files) {
console.log('f: ('+launcher.location_files[i].event_file_id+') '+launcher.location_files[i].event_file_filename+' ***')
file_id = launcher.location_files[i].event_file_id; // NOTE: the .id is the hosted_file.id!
let filename = launcher.location_files[i].hash_sha256+'.file';
save_path = path.join(file_cache_path, filename);
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 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.
}
}
} else {
console.log('No check for location specific files.');
}
if (typeof launcher.sessions === 'undefined') {
console.log('Check for location sessions.');
launcher.sessions = await api.get_event_location_sessions(axios, launcher.event_id, launcher.event_location_id);
for (var i in launcher.sessions) {
console.log('*** '+launcher.sessions[i].name+' ***')
// Check for session files start
if (typeof launcher.sessions[i].files === 'undefined') {
console.log('Check for session files.');
let for_id = launcher.sessions[i].id;
launcher.sessions[i].files = await api.get_files_for_type_for_id(axios, 'session', for_id);
if (launcher.sessions[i].files) {
console.log('Session files found.');
for (var j in launcher.sessions[i].files) {
console.log('f: ('+launcher.sessions[i].files[j].event_file_id+') '+launcher.sessions[i].files[j].event_file_filename+' ***');
file_id = launcher.sessions[i].files[j].event_file_id; // NOTE: the .id is the hosted_file.id!
let filename = launcher.sessions[i].files[j].hash_sha256+'.file';
save_path = path.join(file_cache_path, filename);
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 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.
}
}
} else {
console.log('No session files found.');
}
} else {
console.log('No check for session files.');
}
// Check for session files end
// Get session presentations and associated files
launcher.sessions[i].presentations = await api.get_session_presentations(axios, launcher.event_id, launcher.sessions[i].id);
for (var j in launcher.sessions[i].presentations) {
console.log('* '+launcher.sessions[i].presentations[j].name);
// Check for presentation files start
if (typeof launcher.sessions[i].presentations[j].files === 'undefined') {
console.log('Check for presentation files.');
let for_id = launcher.sessions[i].presentations[j].id;
launcher.sessions[i].presentations[j].files = await api.get_files_for_type_for_id(axios, 'presentation', for_id);
if (launcher.sessions[i].presentations[j].files) {
console.log('Presentation files found.');
for (var k in launcher.sessions[i].presentations[j].files) {
console.log('f: ('+launcher.sessions[i].presentations[j].files[k].event_file_id+') '+launcher.sessions[i].presentations[j].files[k].event_file_filename+' ***');
file_id = launcher.sessions[i].presentations[j].files[k].event_file_id; // NOTE: the .id is the hosted_file.id!
let filename = launcher.sessions[i].presentations[j].files[k].hash_sha256+'.file';
save_path = path.join(file_cache_path, filename);
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 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.
}
}
} else {
console.log('No presentation files found.');
}
} else {
console.log('No check for presentation files.');
}
// Check for presentation files end
// Get session presentations presenters and associated files
//let event_presentation_id = launcher.sessions[i].presentations[j].id;
launcher.sessions[i].presentations[j].presenters = await api.get_presentation_presenters(axios, launcher.event_id, launcher.sessions[i].id, launcher.sessions[i].presentations[j].id);
for (var k in launcher.sessions[i].presentations[j].presenters) {
console.log('-- '+launcher.sessions[i].presentations[j].presenters[k].given_name+' '+launcher.sessions[i].presentations[j].presenters[k].family_name)
// Check for presenter files start
if (typeof launcher.sessions[i].presentations[j].presenters[k].files === 'undefined') {
console.log('Check for presenter files.');
let for_id = launcher.sessions[i].presentations[j].presenters[k].id;
launcher.sessions[i].presentations[j].presenters[k].files = await api.get_files_for_type_for_id(axios, 'presenter', for_id);
if (launcher.sessions[i].presentations[j].presenters[k].files) {
console.log('Presenter files found.');
for (var l in launcher.sessions[i].presentations[j].presenters[k].files) {
console.log('f: ('+launcher.sessions[i].presentations[j].presenters[k].files[l].event_file_id+') '+launcher.sessions[i].presentations[j].presenters[k].files[l].event_file_filename+' ***')
file_id = launcher.sessions[i].presentations[j].presenters[k].files[l].event_file_id; // NOTE: the .id is the hosted_file.id!
let filename = launcher.sessions[i].presentations[j].presenters[k].files[l].hash_sha256+'.file';
save_path = path.join(file_cache_path, filename);
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 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.
}
}
} else {
console.log('No presenter files found.');
}
} else {
console.log('No check for presenter files.');
}
// Check for presenter files end
}
}
}
} else {
console.log('No check for location sessions.');
}
console.log('Location cache check finished.');
return true;
}
exports.launcher_render = async function (launcher) {
console.log('Rendering launcher...');
document.getElementById('location_title').innerHTML = '<h1>Launcher '+launcher.location.name+'@'+launcher.event.name+'</h1>';
document.getElementById('event_files_menu').innerHTML = '<h2>Event Files</h2>';
document.getElementById('event_files_menu').innerHTML += '<ul class="">';
for (var i in launcher.event_files) {
document.getElementById('event_files_menu').innerHTML += '<li id="menu_event_file_id_'+launcher.event_files[i].id+'" class="btn btn-info btn_no_case open_local_file" data-hash_sha256="'+launcher.event_files[i].hash_sha256+'.file" data-filename="'+launcher.event_files[i].event_file_filename+'">'+launcher.event_files[i].event_file_filename+'</li>';
}
document.getElementById('event_files_menu').innerHTML += '</ul>';
document.getElementById('location_files_menu').innerHTML = '<h2>Location Files</h2>';
document.getElementById('location_files_menu').innerHTML += '<ul class="" role="">';
for (var i in launcher.location_files) {
document.getElementById('location_files_menu').innerHTML += '<li id="menu_event_file_id_'+launcher.location_files[i].id+'" class="btn btn-info open_local_file" data-hash_sha256="'+launcher.location_files[i].hash_sha256+'.file" data-filename="'+launcher.location_files[i].event_file_filename+'">'+launcher.location_files[i].event_file_filename+'</li>';
}
document.getElementById('location_files_menu').innerHTML += '</ul>';
document.getElementById('sessions_menu').innerHTML = '<h2>Sessions</h2>';
document.getElementById('sessions_menu').innerHTML += '<ul class="" role="">';
//let location_detail = '';
if (document.getElementById('location_detail').innerHTML.length) {
console.log('detail_session_id_xx already exists');
} else {
console.log('location_detail already populated');
document.getElementById('location_detail').innerHTML = ''; // This needs to be reviewed.
}
for (var i in launcher.sessions) {
// List sessions in menu
document.getElementById('sessions_menu').innerHTML += '<li id="menu_session_id_'+launcher.sessions[i].id+'" class="btn btn-info btn_view_session" data-session_id="'+launcher.sessions[i].id+'">'+launcher.sessions[i].name+'</li>';
// Create containers for each session
let session_detail = '';
if (typeof(document.getElementById('detail_session_id_'+launcher.sessions[i].id)) != 'undefined' && document.getElementById('detail_session_id_'+launcher.sessions[i].id) != null) {
//console.log('detail_session_id_xx already exists');
} else {
//console.log('Adding detail_session_id_xx');
session_detail += '<div id="detail_session_id_'+launcher.sessions[i].id+'" class="container d-none session_detail" data-session_id="'+launcher.sessions[i].id+'">';
}
var session_startdatetime = new Date(launcher.sessions[i].start_datetime);
session_detail += '<h2 class="session_title">'+launcher.sessions[i].name+'<span class="badge badge-pill badge-info float-right">'+dateFns.format(session_startdatetime, 'ddd h:mm A')+'</span>'+'</h2>';
//session_detail += '<div class="">'; // for card-group
session_detail += '<div class="card">';
session_detail += '<div class="card-header">Session Files:</div>';
session_detail += '<div class="card-body">';
session_detail += '<ul>';
for (var j in launcher.sessions[i].files) {
//console.log(launcher.sessions[i].files[j].event_file_filename);
session_detail += '<li class="btn btn-info open_local_file" data-hash_sha256="'+launcher.sessions[i].files[j].hash_sha256+'.file" data-filename="'+launcher.sessions[i].files[j].event_file_filename+'">'+launcher.sessions[i].files[j].event_file_filename+'</li>';
}
session_detail += '</ul>';
session_detail += '</div>'; // for card-body
session_detail += '</div> <!-- for session files card -->'; // for session files card
//session_detail += '<div class="session_presentations">';
for (var j in launcher.sessions[i].presentations) {
//session_detail += '<li>'+launcher.sessions[i].presentations[j].name;
var session_presentation_startdatetime = new Date(launcher.sessions[i].presentations[j].start_datetime);
session_detail += '<div class="card">';
session_detail += '<div class="card-header">'+launcher.sessions[i].presentations[j].name+'<span class="badge badge-pill badge-info float-right">'+dateFns.format(session_startdatetime, 'h:mm a')+'</span>'+':</div>';
session_detail += '<div class="card-body">';
session_detail += '<ul class="list-group">';
for (var k in launcher.sessions[i].presentations[j].files) {
//console.log(launcher.sessions[i].presentations[j].files[k].event_file_filename);
session_detail += '<li class="list-group-item btn btn-info open_local_file" data-hash_sha256="'+launcher.sessions[i].presentations[j].files[k].hash_sha256+'.file" data-filename="'+launcher.sessions[i].presentations[j].files[k].event_file_filename+'">'+launcher.sessions[i].presentations[j].files[k].event_file_filename+'</li>';
}
session_detail += '</ul>';
session_detail += '<ul>';
for (var k in launcher.sessions[i].presentations[j].presenters) {
//console.log(launcher.sessions[i].presentations[j].presenters[k].given_name);
session_detail += '<li>'+launcher.sessions[i].presentations[j].presenters[k].given_name+' '+launcher.sessions[i].presentations[j].presenters[k].family_name;
session_detail += '<ul class="list-group">';
for (var l in launcher.sessions[i].presentations[j].presenters[k].files) {
//console.log(launcher.sessions[i].presentations[j].presenters[k].files[l].event_file_filename);
//session_detail += '<li class="list-group-item" data-hash_sha256="'+launcher.sessions[i].presentations[j].presenters[k].files[l].hash_sha256+'.file" data-filename="'+launcher.sessions[i].presentations[j].presenters[k].files[l].event_file_filename+'">'+launcher.sessions[i].presentations[j].presenters[k].files[l].event_file_filename;
session_detail += '<li class="list-group-item" data-hash_sha256="'+launcher.sessions[i].presentations[j].presenters[k].files[l].hash_sha256+'.file" data-filename="'+launcher.sessions[i].presentations[j].presenters[k].files[l].event_file_filename+'">';
session_detail += '<button class="btn btn-info open_local_file" data-hash_sha256="'+launcher.sessions[i].presentations[j].presenters[k].files[l].hash_sha256+'.file" data-filename="'+launcher.sessions[i].presentations[j].presenters[k].files[l].event_file_filename+'">'+launcher.sessions[i].presentations[j].presenters[k].files[l].event_file_filename+'</button>';
var event_file_size = launcher.sessions[i].presentations[j].presenters[k].files[l].size;
var event_file_created_on = new Date(launcher.sessions[i].presentations[j].presenters[k].files[l].created_on);
session_detail += '<span class="badge badge-pill badge-light float-right">'+format_bytes(event_file_size, 2)+'; '+dateFns.format(event_file_created_on, 'MMM M h:mm A')+'; '+launcher.sessions[i].presentations[j].presenters[k].files[l].internal_os+'</span>';
session_detail += '</li>';
}
session_detail += '</ul>';
session_detail +='</li>';
}
session_detail += '</ul>';
session_detail += '</ul>';
session_detail += '</div>'; // for card-body
session_detail += '</div> <!-- for card -->'; // for card
}
//session_detail += '</div> <!-- for session_presentations -->'; // for session_presentations
//session_detail += '</div>'; // for card-group
session_detail += '</div> <!-- End session detail for '+launcher.sessions[i].id+' -->';
//document.getElementById('location_detail').innerHTML += session_detail;
if (typeof(document.getElementById('detail_session_id_'+launcher.sessions[i].id)) != 'undefined' && document.getElementById('detail_session_id_'+launcher.sessions[i].id) != null) {
document.getElementById('detail_session_id_'+launcher.sessions[i].id).innerHTML = session_detail;
} else {
document.getElementById('location_detail').innerHTML += session_detail;
}
}
document.getElementById('sessions_menu').innerHTML += '</ul>';
index_location_detail('btn_view_session');
index_open_file_buttons('open_local_file');
//const btn_session_{{ event_presentation.id }}_name = document.querySelector('button#presentation_{{ event_presentation.id }}_name');
//btn_presentation_{{ event_presentation.id }}_name.onclick = display_hide_poster_for_type_id.bind(this, true, 'presentation', {{ event_presentation.id }});
console.log('Rendering launcher finished.');
return true;
}
/* Updated 2019-12-19 */
function index_location_detail(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')) } );
}
return true;
}
/* Updated 2019-12-19 */
function view_session(session_id) {
var class_elements = document.getElementsByClassName('session_detail');
console.log('*** 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 2019-12-20 */
function index_open_file_buttons(class_name) {
var class_elements = document.getElementsByClassName(class_name);
for (var i = 0; i < class_elements.length; i++) {
//class_elements[i].addEventListener( 'click', function() {open_local_file( this.getAttribute('data-filename')) } );
//let directory = 'file_cache/';
//directory_and_filename = path.join(directory, class_elements[i].getAttribute('data-filename'));
let file_path = path.join(file_cache_path, class_elements[i].getAttribute('data-hash_sha256'));
let filename = class_elements[i].getAttribute('data-filename');
class_elements[i].addEventListener( 'click', function() { ipcRenderer.send('open_local_file', file_path, filename) } );
//ipcRenderer.send('open_local_file', this.getAttribute('data-filename')); // in render thread
}
return true;
}
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];
}

View File

@@ -1,300 +0,0 @@
const os = require('os');
const path = require('path');
const fs = require('fs');
const { ipcRenderer } = require('electron');
exports.api_token_request_async = async function (axios, secret_key) {
console.log('Requesting API temporary token...');
const url = '/api_token_request';
let data = { secret_key: secret_key };
const response = await axios.post(url, data)
.then(function (response) {
//console.log(response);
const api_temporary_token = response.data.temporary_token;
//console.log('API Temporary Token: '+temporary_token);
return api_temporary_token;
})
.catch(function (error) {
console.error(error);
return error;
});
return response;
}
exports.get_event_location_sessions = async function (axios, event_id, event_location_id) {
console.log('Requesting location sessions...');
const url = '/event/'+event_id+'/location/'+event_location_id+'/session';
const data = await axios.get(url)
.then(function (response) {
//console.log(response.data);
//data = response.data;
return response.data;
})
.catch(function (error) {
console.log(error);
return error;
});
return data;
}
exports.get_session_presentations = async function (axios, event_id, event_session_id) {
console.log('Requesting session presentations...');
const url = '/event/'+event_id+'/session/'+event_session_id+'/presentation';
const data = await axios.get(url)
.then(function (response) {
//console.log(response.data);
//data = response.data;
return response.data;
})
.catch(function (error) {
console.log(error);
return error;
});
return data;
}
exports.get_presentation_presenters = async function (axios, event_id, event_session_id, event_presentation_id) {
console.log('Requesting presentation presenters...');
const url = '/event/'+event_id+'/session/'+event_session_id+'/presentation/'+event_presentation_id+'/presenter';
const data = await axios.get(url)
.then(function (response) {
//console.log(response.data);
//data = response.data;
return response.data;
})
.catch(function (error) {
console.log(error);
return error;
});
return data;
}
exports.get_files_for_type_for_id = async function (axios, for_type, for_id) {
console.log('Requesting files...');
const url = '/event/file/'+for_type+'/'+for_id;
const data = await axios.get(url)
.then(function (response) {
//console.log(response.data);
//data = response.data;
return response.data;
})
.catch(function (error) {
console.log(error);
return error;
});
return data;
}
exports.download_file_id = async function (axios, file_id, filename) {
ipcRenderer.send('download_file', api_base_url, api_endpoint, api_temporary_token, save_path); // in render thread
console.log('1: download file id '+file_id);
const url = '/event/file/'+file_id+'/download';
//const data = await axios.get(url, responseType: 'stream')
const data = await axios({
method: "get",
url: url,
responseType: "stream"
})
.then(function (response) {
console.log('2: downloaded file id '+file_id);
console.log(response);
//console.log(response.data);
let filename = 'default.txt';
if (typeof filename_override === 'undefined' || filename_override == null) {
let headerLine = response.data.headers['content-disposition'];
console.log(headerLine);
console.log(headerLine.indexOf('="'));
console.log(headerLine.indexOf('='));
if (headerLine.indexOf('="') != -1) {
let startFileNameIndex = headerLine.indexOf('="') + 2;
let endFileNameIndex = headerLine.lastIndexOf('"');
filename = headerLine.substring(startFileNameIndex, endFileNameIndex);
} else if (headerLine.indexOf('=') != -1) {
let startFileNameIndex = headerLine.indexOf('=') + 1;
let endFileNameIndex = headerLine.length;
filename = headerLine.substring(startFileNameIndex, endFileNameIndex);
} else {
filename = 'filename_not_found_in_header.txt';
}
} else {
filename = filename_override;
}
let directory = 'file_cache/';
directory_and_filename = path.join(directory, filename);
//console.log(directory_and_filename);
if (fs.existsSync(directory_and_filename)) {
console.log('3a: file already exists: '+directory_and_filename);
} else {
console.log('3b: saving file: '+directory_and_filename);
response.data.pipe(fs.createWriteStream(directory_and_filename));
}
//data = response.data;
console.log('4: saved file id '+file_id);
return true;
//return response.data;
})
.catch(function (error) {
console.log(error);
return error;
});
//return data;
}
exports.launcher_cache = async function (launcher, api_base_url, api_endpoint, api_temporary_token, file_cache_path) {
if (typeof launcher.sessions === 'undefined') {
console.log('Check for location files.');
let for_id = launcher.event_location_id;
launcher.files = await api.get_files_for_type_for_id(axios, 'location', for_id);
for (var i in launcher.files) {
console.log('f: ('+launcher.files[i].event_file_id+') '+launcher.files[i].event_file_filename+' ***')
file_id = launcher.files[i].event_file_id; // NOTE: the .id is the hosted_file.id!
let filename = launcher.files[i].hash_sha256+'.file';
save_path = path.join(file_cache_path, filename);
//console.log(directory_and_filename);
if (fs.existsSync(save_path)) {
console.log('Local file already exists: '+save_path);
} else {
console.log('File not found locally. Downloading file: '+save_path);
const 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.
//response.data.pipe(fs.createWriteStream(directory_and_filename));
}
//let results = await api.download_file_id(axios, file_id, hash_sha256);
}
} else {
console.log('No check for location files.');
}
if (typeof launcher.sessions === 'undefined') {
console.log('Check for location sessions.');
launcher.sessions = await api.get_event_location_sessions(axios, launcher.event_id, launcher.event_location_id);
for (var i in launcher.sessions) {
console.log('*** '+launcher.sessions[i].name+' ***')
// Check for session files start
if (typeof launcher.sessions[i].files === 'undefined') {
console.log('Check for session files.');
let for_id = launcher.sessions[i].id;
launcher.sessions[i].files = await api.get_files_for_type_for_id(axios, 'session', for_id);
if (launcher.sessions[i].files) {
console.log('Session files found.');
for (var j in launcher.sessions[i].files) {
console.log('f: ('+launcher.sessions[i].files[j].event_file_id+') '+launcher.sessions[i].files[j].event_file_filename+' ***');
file_id = launcher.sessions[i].files[j].event_file_id; // NOTE: the .id is the hosted_file.id!
hash_sha256 = launcher.sessions[i].files[j].hash_sha256+'.file';
let results = await api.download_file_id(axios, file_id, hash_sha256);
}
} else {
console.log('No session files found.');
}
} else {
console.log('No check for session files.');
}
// Check for session files end
// Get session presentations and associated files
launcher.sessions[i].presentations = await api.get_session_presentations(axios, launcher.event_id, launcher.sessions[i].id);
for (var j in launcher.sessions[i].presentations) {
console.log('* '+launcher.sessions[i].presentations[j].name);
// Check for presentation files start
if (typeof launcher.sessions[i].presentations[j].files === 'undefined') {
console.log('Check for presentation files.');
let for_id = launcher.sessions[i].presentations[j].id;
launcher.sessions[i].presentations[j].files = await api.get_files_for_type_for_id(axios, 'presentation', for_id);
if (launcher.sessions[i].presentations[j].files) {
console.log('Presentation files found.');
for (var k in launcher.sessions[i].presentations[j].files) {
console.log('f: ('+launcher.sessions[i].presentations[j].files[k].event_file_id+') '+launcher.sessions[i].presentations[j].files[k].event_file_filename+' ***');
file_id = launcher.sessions[i].presentations[j].files[k].event_file_id; // NOTE: the .id is the hosted_file.id!
hash_sha256 = launcher.sessions[i].presentations[j].files[k].hash_sha256+'.file';
let results = await api.download_file_id(axios, file_id, hash_sha256);
}
} else {
console.log('No presentation files found.');
}
} else {
console.log('No check for presentation files.');
}
// Check for presentation files end
// Get session presentations presenters and associated files
//let event_presentation_id = launcher.sessions[i].presentations[j].id;
launcher.sessions[i].presentations[j].presenters = await api.get_presentation_presenters(axios, launcher.event_id, launcher.sessions[i].id, launcher.sessions[i].presentations[j].id);
for (var k in launcher.sessions[i].presentations[j].presenters) {
console.log('-- '+launcher.sessions[i].presentations[j].presenters[k].given_name+' '+launcher.sessions[i].presentations[j].presenters[k].family_name)
// Check for presenter files start
if (typeof launcher.sessions[i].presentations[j].presenters[k].files === 'undefined') {
console.log('Check for presenter files.');
let for_id = launcher.sessions[i].presentations[j].presenters[k].id;
launcher.sessions[i].presentations[j].presenters[k].files = await api.get_files_for_type_for_id(axios, 'presenter', for_id);
if (launcher.sessions[i].presentations[j].presenters[k].files) {
console.log('Presenter files found.');
for (var l in launcher.sessions[i].presentations[j].presenters[k].files) {
console.log('f: ('+launcher.sessions[i].presentations[j].presenters[k].files[l].event_file_id+') '+launcher.sessions[i].presentations[j].presenters[k].files[l].event_file_filename+' ***')
file_id = launcher.sessions[i].presentations[j].presenters[k].files[l].event_file_id; // NOTE: the .id is the hosted_file.id!
hash_sha256 = launcher.sessions[i].presentations[j].presenters[k].files[l].hash_sha256+'.file';
let results = await api.download_file_id(axios, file_id, hash_sha256);
}
} else {
console.log('No presenter files found.');
}
} else {
console.log('No check for presenter files.');
}
// Check for presenter files end
}
}
}
} else {
console.log('No check for location sessions.');
}
/*
if (launcher.sessions) {
console.log('Check for session files.');
let for_id = launcher.event_location_id;
launcher.files = await api.get_files_for_type_for_id(axios, 'location', for_id);
for (var i in launcher.sessions) {
console.log('f: ('+launcher.sessions[i].event_file_id+') '+launcher.files[i].event_file_filename+' ***')
file_id = launcher.files[i].event_file_id; // NOTE: the .id is the hosted_file.id!
let results = await api.download_file_id(axios, file_id);
}
} else {
console.log('No check for location files.');
}
*/
}

View File

@@ -5,133 +5,133 @@ const fs = require('fs');
const { ipcRenderer } = require('electron');
exports.load_config = function () {
console.log('CWD: '+process.cwd());
console.log('CWD: '+process.cwd());
let home_directory = require('os').homedir();
console.log('Home: '+home_directory);
let tmp_directory = require('os').tmpdir();
console.log('Temporary: '+tmp_directory);
let config = null;
let config_directory = null;
let default_config_path = path.join(process.cwd(),'config.json.default');
let config_path = null;
if (os.platform == 'darwin') {
config_directory = path.join(home_directory, 'Library/Application Support/OSIT');
console.log('macOS config directory: '+config_directory);
} else if (os.platform == 'linux') {
config_directory = path.join(home_directory, '.config/OSIT');
console.log('Linux config directory: '+config_directory);
}
if (fs.existsSync(config_directory)) {
console.log('Config: '+config_directory);
config_path = path.join(config_directory, 'config.json');
} else {
fs.mkdirSync(config_directory);
console.log('Config directory created: '+config_directory);
//default_config_path = path.join(process.cwd(),'config.json.default');
config_path = path.join(config_directory, 'config.json');
fs.copyFileSync(default_config_path, config_path);
console.log('Default config file copied: '+config_directory);
}
if (fs.existsSync(config_path)) {
console.log('Config path: '+config_path);
console.log('Config file (config.json) found under '+config_directory+'.');
config = JSON.parse(fs.readFileSync(config_path));
console.log('Config file read.');
} else if (!fs.existsSync(config_path)) {
fs.copyFileSync(default_config_path, config_path);
console.log('Default config file copied: '+config_directory);
config = JSON.parse(fs.readFileSync(config_path));
console.log('Config file read.');
} else if (fs.existsSync('config.json')) {
//fs.copyFileSync(default_config_path, config_path);
//console.log('Default config file copied: '+config_directory);
config = JSON.parse(fs.readFileSync('config.json'));
console.log('Config file (config.json) not found under '+config_directory+'. Using config in CWD.');
console.log('Config file read.');
//console.log('Config file (config.json) not found under '+config_directory+'. Using config in CWD.');
//config = JSON.parse(fs.readFileSync('config.json'));
} else {
//close();
}
//console.log(config);
return config;
let home_directory = require('os').homedir();
console.log('Home: '+home_directory);
let tmp_directory = require('os').tmpdir();
console.log('Temporary: '+tmp_directory);
let config = null;
let config_directory = null;
let default_config_path = path.join(process.cwd(),'config.json.default');
let config_path = null;
if (os.platform == 'darwin') {
config_directory = path.join(home_directory, 'Library/Application Support/OSIT');
console.log('macOS config directory: '+config_directory);
} else if (os.platform == 'linux') {
config_directory = path.join(home_directory, '.config/OSIT');
console.log('Linux config directory: '+config_directory);
}
if (fs.existsSync(config_directory)) {
console.log('Config: '+config_directory);
config_path = path.join(config_directory, 'config.json');
} else {
fs.mkdirSync(config_directory);
console.log('Config directory created: '+config_directory);
//default_config_path = path.join(process.cwd(),'config.json.default');
config_path = path.join(config_directory, 'config.json');
fs.copyFileSync(default_config_path, config_path);
console.log('Default config file copied: '+config_directory);
}
if (fs.existsSync(config_path)) {
console.log('Config path: '+config_path);
console.log('Config file (config.json) found under '+config_directory+'.');
config = JSON.parse(fs.readFileSync(config_path));
console.log('Config file read.');
} else if (!fs.existsSync(config_path)) {
fs.copyFileSync(default_config_path, config_path);
console.log('Default config file copied: '+config_directory);
config = JSON.parse(fs.readFileSync(config_path));
console.log('Config file read.');
} else if (fs.existsSync('config.json')) {
//fs.copyFileSync(default_config_path, config_path);
//console.log('Default config file copied: '+config_directory);
config = JSON.parse(fs.readFileSync('config.json'));
console.log('Config file (config.json) not found under '+config_directory+'. Using config in CWD.');
console.log('Config file read.');
//console.log('Config file (config.json) not found under '+config_directory+'. Using config in CWD.');
//config = JSON.parse(fs.readFileSync('config.json'));
} else {
//close();
}
//console.log(config);
return config;
}
exports.check_file_cache = async function () {
console.log('**** *** ** * FUNCTION: check_file_cache * ** *** ****');
console.log('Checking the local file cache against the remote server.');
if (api_base_url && api_temporary_token) {
tbl_event_file.iterate(function(file_value, key, iteration) {
//if (file_value.event_location_id == event_location_id) {
//console.log('f: ('+file_value.event_file_id+') '+file_value.event_file_filename+' ***')
let 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';
let save_path = path.join(host_file_cache_path, 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 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.
}
});
} else {
console.log('The api_base_url or api_temporary_token has not been set.');
console.log(api_base_url);
console.log(api_temporary_token);
return false;
}
return true;
console.log('**** *** ** * FUNCTION: check_file_cache * ** *** ****');
console.log('Checking the local file cache against the remote server.');
if (api_base_url && api_temporary_token) {
tbl_event_file.iterate(function(file_value, key, iteration) {
//if (file_value.event_location_id == event_location_id) {
//console.log('f: ('+file_value.event_file_id+') '+file_value.event_file_filename+' ***')
let 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';
let save_path = path.join(host_file_cache_path, 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 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.
}
});
} else {
console.log('The api_base_url or api_temporary_token has not been set.');
console.log(api_base_url);
console.log(api_temporary_token);
return false;
}
return true;
}
exports.currently_online = function() {
//alert('You are currently online');
console.log('Currently online');
app_online = true;
//document.getElementById('app_network_status').classList.remove('alert-info');
//document.getElementById('app_network_status').classList.remove('warning');
//document.getElementById('app_network_status').classList.remove('alert-warning');
//document.getElementById('app_network_status').classList.add('success');
//document.getElementById('app_network_status').classList.add('alert-success');
document.getElementById('app_network_status').classList.remove('app_warning');
//document.getElementById('app_network_status').classList.add('d-none');
document.getElementById('app_network_status').innerHTML = '<span class="fas fa-check"></span> <span class="fas fa-globe"></span> Currently Online';
//document.getElementById('app_network_status').innerHTML('Currently Online');
//alert('You are currently online');
console.log('Currently online');
app_online = true;
//document.getElementById('app_network_status').classList.remove('alert-info');
//document.getElementById('app_network_status').classList.remove('warning');
//document.getElementById('app_network_status').classList.remove('alert-warning');
//document.getElementById('app_network_status').classList.add('success');
//document.getElementById('app_network_status').classList.add('alert-success');
document.getElementById('app_network_status').classList.remove('app_warning');
//document.getElementById('app_network_status').classList.add('d-none');
document.getElementById('app_network_status').innerHTML = '<span class="fas fa-check"></span> <span class="fas fa-globe"></span> Currently Online';
//document.getElementById('app_network_status').innerHTML('Currently Online');
}
exports.currently_offline = function() {
//alert('You are currently offline');
console.log('Currently offline');
app_online = false;
//document.getElementById('app_network_status').classList.remove('alert-info');
//document.getElementById('app_network_status').classList.remove('success');
//document.getElementById('app_network_status').classList.remove('alert-success');
//document.getElementById('app_network_status').classList.add('warning');
//document.getElementById('app_network_status').classList.add('alert-warning');
document.getElementById('app_network_status').classList.add('app_warning');
//document.getElementById('app_network_status').classList.remove('d-none');
document.getElementById('app_network_status').innerHTML = '<span class="fas fa-exclamation"></span> <span class="fas fa-globe"></span> Currently Offline';
//document.getElementById('app_network_status').innerHTML('Currently Offline');
//alert('You are currently offline');
console.log('Currently offline');
app_online = false;
//document.getElementById('app_network_status').classList.remove('alert-info');
//document.getElementById('app_network_status').classList.remove('success');
//document.getElementById('app_network_status').classList.remove('alert-success');
//document.getElementById('app_network_status').classList.add('warning');
//document.getElementById('app_network_status').classList.add('alert-warning');
document.getElementById('app_network_status').classList.add('app_warning');
//document.getElementById('app_network_status').classList.remove('d-none');
document.getElementById('app_network_status').innerHTML = '<span class="fas fa-exclamation"></span> <span class="fas fa-globe"></span> Currently Offline';
//document.getElementById('app_network_status').innerHTML('Currently Offline');
}
//window.addEventListener('online', currently_online);

View File

@@ -1,271 +0,0 @@
const os = require('os');
const path = require('path');
const fs = require('fs');
const { ipcRenderer } = require('electron');
exports.launcher_cache_check = async function (launcher, api_base_url, api_temporary_token, host_file_cache_path) {
if (typeof launcher.event === 'undefined') {
launcher.event = await api.get_event_details(axios, launcher.event_id);
tbl_event.setItem(launcher.event.id.toString(), launcher.event);
/*
.then(function (data) {
console.log(data.id);
idbKeyval.set(data.id, data, tbl_event);
//for (var i in response) {
//var event_record = data[i];
//idbKeyval.set(response[i].id, response[i], tbl_event);
//}
});
*/
}
if (typeof launcher.location === 'undefined') {
launcher.location = await api.get_event_location_details(axios, launcher.event_id, launcher.event_location_id);
tbl_event_location.setItem(launcher.location.id.toString(), launcher.location);
}
if (typeof launcher.event_files === 'undefined') {
console.log('Check for global event files.');
let for_id = launcher.event_id;
launcher.event_files = await api.get_files_for_type_for_id(axios, 'event', for_id);
for (var i in launcher.event_files) {
console.log('f: ('+launcher.event_files[i].event_file_id+') '+launcher.event_files[i].event_file_filename+' ***')
tbl_event_file.setItem(launcher.event_files[i].event_file_id.toString(), launcher.event_files[i]);
file_id = launcher.event_files[i].event_file_id; // NOTE: the .id is the hosted_file.id!
let filename = launcher.event_files[i].hash_sha256+'.file';
save_path = path.join(host_file_cache_path, filename);
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 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.
}
}
} else {
console.log('No check for global event files');
}
if (typeof launcher.location_files === 'undefined') {
console.log('Check for location specific files.');
let for_id = launcher.event_location_id;
launcher.location_files = await api.get_files_for_type_for_id(axios, 'location', for_id);
for (var i in launcher.location_files) {
console.log('f: ('+launcher.location_files[i].event_file_id+') '+launcher.location_files[i].event_file_filename+' ***')
tbl_event_file.setItem(launcher.location_files[i].event_file_id.toString(), launcher.location_files[i]);
file_id = launcher.location_files[i].event_file_id; // NOTE: the .id is the hosted_file.id!
let filename = launcher.location_files[i].hash_sha256+'.file';
save_path = path.join(host_file_cache_path, filename);
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 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.
}
}
} else {
console.log('No check for location specific files.');
}
if (typeof launcher.sessions === 'undefined') {
console.log('Check for location sessions.');
launcher.sessions = await api.get_event_location_sessions(axios, launcher.event_id, launcher.event_location_id);
for (var i in launcher.sessions) {
console.log('*** '+launcher.sessions[i].name+' ***')
tbl_event_session.setItem(launcher.sessions[i].id.toString(), launcher.sessions[i]);
// Check for session files start
if (typeof launcher.sessions[i].files === 'undefined') {
console.log('Check for session files.');
let for_id = launcher.sessions[i].id;
launcher.sessions[i].files = await api.get_files_for_type_for_id(axios, 'session', for_id);
if (launcher.sessions[i].files) {
console.log('Session files found.');
for (var j in launcher.sessions[i].files) {
console.log('f: ('+launcher.sessions[i].files[j].event_file_id+') '+launcher.sessions[i].files[j].event_file_filename+' ***');
tbl_event_file.setItem(launcher.sessions[i].files[j].event_file_id.toString(), launcher.sessions[i].files[j]);
file_id = launcher.sessions[i].files[j].event_file_id; // NOTE: the .id is the hosted_file.id!
let filename = launcher.sessions[i].files[j].hash_sha256+'.file';
save_path = path.join(host_file_cache_path, filename);
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 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.
}
}
} else {
console.log('No session files found.');
}
} else {
console.log('No check for session files.');
}
// Check for session files end
// Get session presentations and associated files
launcher.sessions[i].presentations = await api.get_session_presentations(axios, launcher.event_id, launcher.sessions[i].id);
for (var j in launcher.sessions[i].presentations) {
console.log('* '+launcher.sessions[i].presentations[j].name);
tbl_event_presentation.setItem(launcher.sessions[i].presentations[j].id.toString(), launcher.sessions[i].presentations[j]);
// Check for presentation files start
if (typeof launcher.sessions[i].presentations[j].files === 'undefined') {
console.log('Check for presentation files.');
let for_id = launcher.sessions[i].presentations[j].id;
launcher.sessions[i].presentations[j].files = await api.get_files_for_type_for_id(axios, 'presentation', for_id);
if (launcher.sessions[i].presentations[j].files) {
console.log('Presentation files found.');
for (var k in launcher.sessions[i].presentations[j].files) {
console.log('f: ('+launcher.sessions[i].presentations[j].files[k].event_file_id+') '+launcher.sessions[i].presentations[j].files[k].event_file_filename+' ***');
tbl_event_file.setItem(launcher.sessions[i].presentations[j].files[k].event_file_id.toString(), launcher.sessions[i].presentations[j].files[k]);
file_id = launcher.sessions[i].presentations[j].files[k].event_file_id; // NOTE: the .id is the hosted_file.id!
let filename = launcher.sessions[i].presentations[j].files[k].hash_sha256+'.file';
save_path = path.join(host_file_cache_path, filename);
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 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.
}
}
} else {
console.log('No presentation files found.');
}
} else {
console.log('No check for presentation files.');
}
// Check for presentation files end
// Get session presentations presenters and associated files
//let event_presentation_id = launcher.sessions[i].presentations[j].id;
launcher.sessions[i].presentations[j].presenters = await api.get_presentation_presenters(axios, launcher.event_id, launcher.sessions[i].id, launcher.sessions[i].presentations[j].id);
for (var k in launcher.sessions[i].presentations[j].presenters) {
console.log('-- '+launcher.sessions[i].presentations[j].presenters[k].given_name+' '+launcher.sessions[i].presentations[j].presenters[k].family_name)
tbl_event_presenter.setItem(launcher.sessions[i].presentations[j].presenters[k].id.toString(), launcher.sessions[i].presentations[j].presenters[k]);
// Check for presenter files start
if (typeof launcher.sessions[i].presentations[j].presenters[k].files === 'undefined') {
console.log('Check for presenter files.');
let for_id = launcher.sessions[i].presentations[j].presenters[k].id;
launcher.sessions[i].presentations[j].presenters[k].files = await api.get_files_for_type_for_id(axios, 'presenter', for_id);
if (launcher.sessions[i].presentations[j].presenters[k].files) {
console.log('Presenter files found.');
for (var l in launcher.sessions[i].presentations[j].presenters[k].files) {
console.log('f: ('+launcher.sessions[i].presentations[j].presenters[k].files[l].event_file_id+') '+launcher.sessions[i].presentations[j].presenters[k].files[l].event_file_filename+' ***');
tbl_event_file.setItem(launcher.sessions[i].presentations[j].presenters[k].files[l].event_file_id.toString(), launcher.sessions[i].presentations[j].presenters[k].files[l]);
file_id = launcher.sessions[i].presentations[j].presenters[k].files[l].event_file_id; // NOTE: the .id is the hosted_file.id!
let filename = launcher.sessions[i].presentations[j].presenters[k].files[l].hash_sha256+'.file';
save_path = path.join(host_file_cache_path, filename);
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 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.
}
}
} else {
console.log('No presenter files found.');
}
} else {
console.log('No check for presenter files.');
}
// Check for presenter files end
}
}
}
} else {
console.log('No check for location sessions.');
}
console.log('Location cache check finished.');
return true;
}
/* Updated 2019-12-19 */
function index_location_detail(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')) } );
}
return true;
}
/* Updated 2019-12-19 */
function view_session(session_id) {
var class_elements = document.getElementsByClassName('session_detail');
console.log('*** 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 2019-12-20 */
function index_open_file_buttons(class_name) {
var class_elements = document.getElementsByClassName(class_name);
for (var i = 0; i < class_elements.length; i++) {
//class_elements[i].addEventListener( 'click', function() {open_local_file( this.getAttribute('data-filename')) } );
//let directory = 'file_cache/';
//directory_and_filename = path.join(directory, class_elements[i].getAttribute('data-filename'));
let file_path = path.join(host_file_cache_path, class_elements[i].getAttribute('data-hash_sha256'));
let filename = class_elements[i].getAttribute('data-filename');
class_elements[i].addEventListener( 'click', function() { ipcRenderer.send('open_local_file', file_path, filename) } );
//ipcRenderer.send('open_local_file', this.getAttribute('data-filename')); // in render thread
}
return true;
}

View File

@@ -1,368 +0,0 @@
const os = require('os');
const path = require('path');
const fs = require('fs');
const { ipcRenderer } = require('electron');
exports.launcher_cache_check = async function (launcher, api_base_url, api_temporary_token, host_file_cache_path) {
if (typeof launcher.event === 'undefined') {
launcher.event = await api.get_event_details(axios, launcher.event_id);
tbl_event.setItem(launcher.event.id.toString(), launcher.event);
/*
.then(function (data) {
console.log(data.id);
idbKeyval.set(data.id, data, tbl_event);
//for (var i in response) {
//var event_record = data[i];
//idbKeyval.set(response[i].id, response[i], tbl_event);
//}
});
*/
}
if (typeof launcher.location === 'undefined') {
launcher.location = await api.get_event_location_details(axios, launcher.event_id, launcher.event_location_id);
tbl_event_location.setItem(launcher.location.id.toString(), launcher.location);
}
if (typeof launcher.event_files === 'undefined') {
console.log('Check for global event files.');
let for_id = launcher.event_id;
launcher.event_files = await api.get_files_for_type_for_id(axios, 'event', for_id);
for (var i in launcher.event_files) {
console.log('f: ('+launcher.event_files[i].event_file_id+') '+launcher.event_files[i].event_file_filename+' ***')
tbl_event_file.setItem(launcher.event_files[i].event_file_id.toString(), launcher.event_files[i]);
file_id = launcher.event_files[i].event_file_id; // NOTE: the .id is the hosted_file.id!
let filename = launcher.event_files[i].hash_sha256+'.file';
save_path = path.join(host_file_cache_path, filename);
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 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.
}
}
} else {
console.log('No check for global event files');
}
if (typeof launcher.location_files === 'undefined') {
console.log('Check for location specific files.');
let for_id = launcher.event_location_id;
launcher.location_files = await api.get_files_for_type_for_id(axios, 'location', for_id);
for (var i in launcher.location_files) {
console.log('f: ('+launcher.location_files[i].event_file_id+') '+launcher.location_files[i].event_file_filename+' ***')
tbl_event_file.setItem(launcher.location_files[i].event_file_id.toString(), launcher.location_files[i]);
file_id = launcher.location_files[i].event_file_id; // NOTE: the .id is the hosted_file.id!
let filename = launcher.location_files[i].hash_sha256+'.file';
save_path = path.join(host_file_cache_path, filename);
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 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.
}
}
} else {
console.log('No check for location specific files.');
}
if (typeof launcher.sessions === 'undefined') {
console.log('Check for location sessions.');
launcher.sessions = await api.get_event_location_sessions(axios, launcher.event_id, launcher.event_location_id);
for (var i in launcher.sessions) {
console.log('*** '+launcher.sessions[i].name+' ***')
tbl_event_session.setItem(launcher.sessions[i].id.toString(), launcher.sessions[i]);
// Check for session files start
if (typeof launcher.sessions[i].files === 'undefined') {
console.log('Check for session files.');
let for_id = launcher.sessions[i].id;
launcher.sessions[i].files = await api.get_files_for_type_for_id(axios, 'session', for_id);
if (launcher.sessions[i].files) {
console.log('Session files found.');
for (var j in launcher.sessions[i].files) {
console.log('f: ('+launcher.sessions[i].files[j].event_file_id+') '+launcher.sessions[i].files[j].event_file_filename+' ***');
tbl_event_file.setItem(launcher.sessions[i].files[j].event_file_id.toString(), launcher.sessions[i].files[j]);
file_id = launcher.sessions[i].files[j].event_file_id; // NOTE: the .id is the hosted_file.id!
let filename = launcher.sessions[i].files[j].hash_sha256+'.file';
save_path = path.join(host_file_cache_path, filename);
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 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.
}
}
} else {
console.log('No session files found.');
}
} else {
console.log('No check for session files.');
}
// Check for session files end
// Get session presentations and associated files
launcher.sessions[i].presentations = await api.get_session_presentations(axios, launcher.event_id, launcher.sessions[i].id);
for (var j in launcher.sessions[i].presentations) {
console.log('* '+launcher.sessions[i].presentations[j].name);
tbl_event_presentation.setItem(launcher.sessions[i].presentations[j].id.toString(), launcher.sessions[i].presentations[j]);
// Check for presentation files start
if (typeof launcher.sessions[i].presentations[j].files === 'undefined') {
console.log('Check for presentation files.');
let for_id = launcher.sessions[i].presentations[j].id;
launcher.sessions[i].presentations[j].files = await api.get_files_for_type_for_id(axios, 'presentation', for_id);
if (launcher.sessions[i].presentations[j].files) {
console.log('Presentation files found.');
for (var k in launcher.sessions[i].presentations[j].files) {
console.log('f: ('+launcher.sessions[i].presentations[j].files[k].event_file_id+') '+launcher.sessions[i].presentations[j].files[k].event_file_filename+' ***');
tbl_event_file.setItem(launcher.sessions[i].presentations[j].files[k].event_file_id.toString(), launcher.sessions[i].presentations[j].files[k]);
file_id = launcher.sessions[i].presentations[j].files[k].event_file_id; // NOTE: the .id is the hosted_file.id!
let filename = launcher.sessions[i].presentations[j].files[k].hash_sha256+'.file';
save_path = path.join(host_file_cache_path, filename);
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 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.
}
}
} else {
console.log('No presentation files found.');
}
} else {
console.log('No check for presentation files.');
}
// Check for presentation files end
// Get session presentations presenters and associated files
//let event_presentation_id = launcher.sessions[i].presentations[j].id;
launcher.sessions[i].presentations[j].presenters = await api.get_presentation_presenters(axios, launcher.event_id, launcher.sessions[i].id, launcher.sessions[i].presentations[j].id);
for (var k in launcher.sessions[i].presentations[j].presenters) {
console.log('-- '+launcher.sessions[i].presentations[j].presenters[k].given_name+' '+launcher.sessions[i].presentations[j].presenters[k].family_name)
tbl_event_presenter.setItem(launcher.sessions[i].presentations[j].presenters[k].id.toString(), launcher.sessions[i].presentations[j].presenters[k]);
// Check for presenter files start
if (typeof launcher.sessions[i].presentations[j].presenters[k].files === 'undefined') {
console.log('Check for presenter files.');
let for_id = launcher.sessions[i].presentations[j].presenters[k].id;
launcher.sessions[i].presentations[j].presenters[k].files = await api.get_files_for_type_for_id(axios, 'presenter', for_id);
if (launcher.sessions[i].presentations[j].presenters[k].files) {
console.log('Presenter files found.');
for (var l in launcher.sessions[i].presentations[j].presenters[k].files) {
console.log('f: ('+launcher.sessions[i].presentations[j].presenters[k].files[l].event_file_id+') '+launcher.sessions[i].presentations[j].presenters[k].files[l].event_file_filename+' ***');
tbl_event_file.setItem(launcher.sessions[i].presentations[j].presenters[k].files[l].event_file_id.toString(), launcher.sessions[i].presentations[j].presenters[k].files[l]);
file_id = launcher.sessions[i].presentations[j].presenters[k].files[l].event_file_id; // NOTE: the .id is the hosted_file.id!
let filename = launcher.sessions[i].presentations[j].presenters[k].files[l].hash_sha256+'.file';
save_path = path.join(host_file_cache_path, filename);
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 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.
}
}
} else {
console.log('No presenter files found.');
}
} else {
console.log('No check for presenter files.');
}
// Check for presenter files end
}
}
}
} else {
console.log('No check for location sessions.');
}
console.log('Location cache check finished.');
return true;
}
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();
// Look for *events*
let tmp_event = [];
tbl_event.iterate(function(event_value, key, iteration) {
tmp_event.push(event_value);
});
launcher.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) {
tmp_event_file.push(file_value);
}
}).then(function() {
console.log('idb_to_launcher: Iterate tbl_event_file complete')
});
launcher.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);
});
launcher.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) {
tmp_event_location_file.push(file_value);
}
});
launcher.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)
//tmp_event_session_file.push(session_file_value);
}
});
// 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);
}
});
// 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);
}
});
//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);
}
});
//NOTE add in presenters and then presenter's files
session_value.presentation.push(presentation_value);
}//);
});
//});
tmp_event_session.push(session_value);
}).then(function() {
console.log('idb_to_launcher: Iterate tbl_event_session complete')
});
launcher.session = tmp_event_session;
/*
console.log('v2 idb to launcher object: ***');
console.log(launcher);
console.log('v2 idb to launcher object: ^^^');
*/
return true;
}
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) {
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';
save_path = path.join(host_file_cache_path, filename);
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 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.
}
}
});
}
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);
}

View File

@@ -1,234 +0,0 @@
const os = require('os');
const path = require('path');
const fs = require('fs');
const { ipcRenderer } = require('electron');
exports.launcher_render = async function (launcher) {
console.log('Rendering launcher...');
document.getElementById('location_title').innerHTML = '<h1>Launcher '+launcher.location.name+'@'+launcher.event.name+'</h1>';
document.getElementById('event_files_menu').innerHTML = '<h2>Event Files</h2>';
document.getElementById('event_files_menu').innerHTML += '<ul class="">';
for (var i in launcher.event_files) {
document.getElementById('event_files_menu').innerHTML += '<li id="menu_event_file_id_'+launcher.event_files[i].id+'" class="btn btn-info btn_no_case open_local_file" data-hash_sha256="'+launcher.event_files[i].hash_sha256+'.file" data-filename="'+launcher.event_files[i].event_file_filename+'">'+launcher.event_files[i].event_file_filename+'</li>';
}
document.getElementById('event_files_menu').innerHTML += '</ul>';
document.getElementById('location_files_menu').innerHTML = '<h2>Location Files</h2>';
document.getElementById('location_files_menu').innerHTML += '<ul class="" role="">';
for (var i in launcher.location_files) {
document.getElementById('location_files_menu').innerHTML += '<li id="menu_event_file_id_'+launcher.location_files[i].id+'" class="btn btn-info open_local_file" data-hash_sha256="'+launcher.location_files[i].hash_sha256+'.file" data-filename="'+launcher.location_files[i].event_file_filename+'">'+launcher.location_files[i].event_file_filename+'</li>';
}
document.getElementById('location_files_menu').innerHTML += '</ul>';
document.getElementById('sessions_menu').innerHTML = '<h2>Sessions</h2>';
document.getElementById('sessions_menu').innerHTML += '<ul class="" role="">';
//let location_detail = '';
if (document.getElementById('location_detail').innerHTML.length) {
console.log('detail_session_id_xx already exists');
} else {
console.log('location_detail already populated');
document.getElementById('location_detail').innerHTML = ''; // This needs to be reviewed.
}
for (var i in launcher.sessions) {
// List sessions in menu
document.getElementById('sessions_menu').innerHTML += '<li id="menu_session_id_'+launcher.sessions[i].id+'" class="btn btn-info btn_view_session" data-session_id="'+launcher.sessions[i].id+'">'+launcher.sessions[i].name+'</li>';
// Create containers for each session
let session_detail = '';
if (typeof(document.getElementById('detail_session_id_'+launcher.sessions[i].id)) != 'undefined' && document.getElementById('detail_session_id_'+launcher.sessions[i].id) != null) {
//console.log('detail_session_id_xx already exists');
} else {
//console.log('Adding detail_session_id_xx');
session_detail += '<div id="detail_session_id_'+launcher.sessions[i].id+'" class="container d-none session_detail" data-session_id="'+launcher.sessions[i].id+'">';
}
var session_startdatetime = new Date(launcher.sessions[i].start_datetime);
session_detail += '<h2 class="session_title">'+launcher.sessions[i].name+'<span class="badge badge-pill badge-info float-right">'+dateFns.format(session_startdatetime, 'ddd h:mm A')+'</span>'+'</h2>';
//session_detail += '<div class="">'; // for card-group
session_detail += '<div class="card">';
session_detail += '<div class="card-header">Session Files:</div>';
session_detail += '<div class="card-body">';
session_detail += '<ul>';
for (var j in launcher.sessions[i].files) {
//console.log(launcher.sessions[i].files[j].event_file_filename);
session_detail += '<li class="btn btn-info open_local_file" data-hash_sha256="'+launcher.sessions[i].files[j].hash_sha256+'.file" data-filename="'+launcher.sessions[i].files[j].event_file_filename+'">'+launcher.sessions[i].files[j].event_file_filename+'</li>';
}
session_detail += '</ul>';
session_detail += '</div>'; // for card-body
session_detail += '</div> <!-- for session files card -->'; // for session files card
//session_detail += '<div class="session_presentations">';
for (var j in launcher.sessions[i].presentations) {
//session_detail += '<li>'+launcher.sessions[i].presentations[j].name;
var session_presentation_startdatetime = new Date(launcher.sessions[i].presentations[j].start_datetime);
session_detail += '<div class="card">';
session_detail += '<div class="card-header">'+launcher.sessions[i].presentations[j].name+'<span class="badge badge-pill badge-info float-right">'+dateFns.format(session_startdatetime, 'h:mm a')+'</span>'+':</div>';
session_detail += '<div class="card-body">';
session_detail += '<ul class="list-group">';
for (var k in launcher.sessions[i].presentations[j].files) {
//console.log(launcher.sessions[i].presentations[j].files[k].event_file_filename);
session_detail += '<li class="list-group-item data-hash_sha256="'+launcher.sessions[i].presentations[j].files[k].hash_sha256+'.file" data-filename="'+launcher.sessions[i].presentations[j].files[k].event_file_filename+'">';
session_detail += '<button class="btn btn-info open_local_file" data-hash_sha256="'+launcher.sessions[i].presentations[j].files[k].hash_sha256+'.file" data-filename="'+launcher.sessions[i].presentations[j].files[k].event_file_filename+'">'+launcher.sessions[i].presentations[j].files[k].event_file_filename+'</button>';
var event_file_size = launcher.sessions[i].presentations[j].files[k].size;
var event_file_created_on = new Date(launcher.sessions[i].presentations[j].files[k].created_on);
session_detail += '<span class="badge badge-pill badge-light float-right">'+format_bytes(event_file_size, 2)+'; '+dateFns.format(event_file_created_on, 'MMM M h:mm A')+'; '+launcher.sessions[i].presentations[j].files[k].internal_os+'</span>';
session_detail += '</li>';
}
session_detail += '</ul>';
session_detail += '<ul>';
for (var k in launcher.sessions[i].presentations[j].presenters) {
//console.log(launcher.sessions[i].presentations[j].presenters[k].given_name);
session_detail += '<li>'+launcher.sessions[i].presentations[j].presenters[k].given_name+' '+launcher.sessions[i].presentations[j].presenters[k].family_name;
session_detail += '<ul class="list-group">';
for (var l in launcher.sessions[i].presentations[j].presenters[k].files) {
//console.log(launcher.sessions[i].presentations[j].presenters[k].files[l].event_file_filename);
//session_detail += '<li class="list-group-item" data-hash_sha256="'+launcher.sessions[i].presentations[j].presenters[k].files[l].hash_sha256+'.file" data-filename="'+launcher.sessions[i].presentations[j].presenters[k].files[l].event_file_filename+'">'+launcher.sessions[i].presentations[j].presenters[k].files[l].event_file_filename;
session_detail += '<li class="list-group-item" data-hash_sha256="'+launcher.sessions[i].presentations[j].presenters[k].files[l].hash_sha256+'.file" data-filename="'+launcher.sessions[i].presentations[j].presenters[k].files[l].event_file_filename+'">';
session_detail += '<button class="btn btn-info open_local_file" data-hash_sha256="'+launcher.sessions[i].presentations[j].presenters[k].files[l].hash_sha256+'.file" data-filename="'+launcher.sessions[i].presentations[j].presenters[k].files[l].event_file_filename+'">'+launcher.sessions[i].presentations[j].presenters[k].files[l].event_file_filename+'</button>';
var event_file_size = launcher.sessions[i].presentations[j].presenters[k].files[l].size;
var event_file_created_on = new Date(launcher.sessions[i].presentations[j].presenters[k].files[l].created_on);
session_detail += '<span class="badge badge-pill badge-light float-right">'+format_bytes(event_file_size, 2)+'; '+dateFns.format(event_file_created_on, 'MMM M h:mm A')+'; '+launcher.sessions[i].presentations[j].presenters[k].files[l].internal_os+'</span>';
session_detail += '</li>';
}
session_detail += '</ul>';
session_detail +='</li>';
}
session_detail += '</ul>';
session_detail += '</ul>';
session_detail += '</div>'; // for card-body
session_detail += '</div> <!-- for card -->'; // for card
}
//session_detail += '</div> <!-- for session_presentations -->'; // for session_presentations
//session_detail += '</div>'; // for card-group
session_detail += '</div> <!-- End session detail for '+launcher.sessions[i].id+' -->';
//document.getElementById('location_detail').innerHTML += session_detail;
if (typeof(document.getElementById('detail_session_id_'+launcher.sessions[i].id)) != 'undefined' && document.getElementById('detail_session_id_'+launcher.sessions[i].id) != null) {
document.getElementById('detail_session_id_'+launcher.sessions[i].id).innerHTML = session_detail;
} else {
document.getElementById('location_detail').innerHTML += session_detail;
}
}
document.getElementById('sessions_menu').innerHTML += '</ul>';
index_location_detail('btn_view_session');
index_open_file_buttons('open_local_file');
//const btn_session_{{ event_presentation.id }}_name = document.querySelector('button#presentation_{{ event_presentation.id }}_name');
//btn_presentation_{{ event_presentation.id }}_name.onclick = display_hide_poster_for_type_id.bind(this, true, 'presentation', {{ event_presentation.id }});
console.log('Rendering launcher finished.');
return true;
}
/* Updated 2019-12-19 */
function index_location_detail(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')) } );
}
return true;
}
/* Updated 2019-12-19 */
function view_session(session_id) {
var class_elements = document.getElementsByClassName('session_detail');
console.log('*** 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 2019-12-20 */
function index_open_file_buttons(class_name) {
var class_elements = document.getElementsByClassName(class_name);
for (var i = 0; i < class_elements.length; i++) {
//class_elements[i].addEventListener( 'click', function() {open_local_file( this.getAttribute('data-filename')) } );
//let directory = 'file_cache/';
//directory_and_filename = path.join(directory, class_elements[i].getAttribute('data-filename'));
let file_path = path.join(host_file_cache_path, class_elements[i].getAttribute('data-hash_sha256'));
let filename = class_elements[i].getAttribute('data-filename');
class_elements[i].addEventListener( 'click', function() { ipcRenderer.send('open_local_file', file_path, filename) } );
//ipcRenderer.send('open_local_file', this.getAttribute('data-filename')); // in render thread
}
return true;
}
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];
}

View File

@@ -1,436 +0,0 @@
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;
} else {
console.log('Event not it.');
}
}).then(function() {
console.log('idb_to_ui: Iterate tbl_event_file complete')
tbl_event_complete = true;
});
}
// NOTE: The event_file table should probably only be looped through once when the table is actually updated.
// NOTE: Not each time the other objects (event, location, session, presentation, presenter) are updated.
exports.render_event_file_records = function (event_files, event_id) {
console.log('Rendering event file records...');
/*
tbl_event_file.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;
} else {
console.log('Event not it.');
}
}).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...');
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;
} else {
console.log('Event location not it.');
}
}).then(function() {
console.log('idb_to_ui: Iterate tbl_event_file complete')
tbl_event_location_complete = true;
});
}
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...');
// 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';
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.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('Sessions 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.className = 'list-group list-group-flush';
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.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.className = 'list-group list-group-flush';
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);
//console.log(session_list_items.length);
for (var i in session_list_items) {
console.log(session_list_items[i].getAttribute('data-session_id'));
//console.log(session_list_items[i]);
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('********** ********* ****** ** * ** ****** ********* *********');
console.log('Rendering event presentation records...');
let launcher_sessions = document.getElementById('launcher_sessions').childNodes; //_list_items
console.log(launcher_sessions);
console.log(tbl_event_presentation);
for (let i in launcher_sessions) {
console.log(launcher_sessions[i].getAttribute('data-session_id'));
let session_id = launcher_sessions[i].getAttribute('data-session_id');
//console.log(launcher_sessions[i].getElementsByClassName('session_presentations')[0].getElementsByTagName('ul').childElementCount);
let presentations_list = launcher_sessions[i].getElementsByClassName('session_presentations')[0].getElementsByTagName('ul')[0].childNodes;
console.log(presentations_list);
//console.log(presentations_list.length);
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'));
/*
* loop through list of presentations
* if in
*/
await tbl_event_presentation.iterate(function(value, key, iteration) {
if (document.getElementById('event_presentation_'+value.id)) {
// Update the launcher presentations list for a session
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 {
}
}).then(function() {
});
} else {
console.log('No presentations listed under this session (id='+session_id+'). Time to iterate through presentations table. (launcher sessions loop i = '+i+')');
let new_i = i;
console.log(new_i);
//if (!looping_tbl_event_presentation) {
// looping_tbl_event_presentation = true;
await tbl_event_presentation.iterate(function(value, key, iteration) {
console.log('Launcher sessions loop i: '+i+' : '+new_i);
if (value.event_session_id == session_id) {
console.log('*** Presentation id ('+value.id+') is part of this session ('+session_id+'). (launcher sessions loop i='+i+')');
// Add the new session to the launcher sessions list
let presentation_li_node = document.createElement('LI');
presentation_li_node.id = 'event_presentation_'+value.id;
presentation_li_node.className = 'list-group-item';
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);
presentation_li_node.appendChild(presentation_li_heading_div_node);
console.log('************ ISSUE ************');
console.log(launcher_sessions[i].getElementsByClassName('session_presentations'));
//launcher_sessions[i].getElementsByClassName('session_presentations')[0].getElementsByTagName('ul')[0].appendChild(presentation_li_node);
let launcher_session_details = document.getElementById('detail_session_'+session_id);
console.log(launcher_session_details.getElementsByClassName('session_presentations'));
let session = document.getElementById('detail_session_'+session_id).getElementsByClassName('session_presentations')[0].getElementsByTagName('ul')[0].appendChild(presentation_li_node);
} else {
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 update or add is complete');
looping_tbl_event_presentation = true;
//tbl_event_presentation_iterate_count++;
/*
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
}
*/
});
//} else {
// console.log('Waiting until tbl_event_presentation has finished iterating...');
//}
/*
<div class="card session_presentations">
<div class="card-header">Presentations:</div>
<div class="card-body">
<ul class="list-group list-group-flush"></ul>
</div>
</div>
*/
}
//} else {
// console.log('Waiting until launcher_sessions has finished looping...');
//}
}
return true;
}
exports.render_event_presention_file_records = function (events) {
console.log('Rendering event presentation file records...');
}
exports.render_event_presenter_records = function (events) {
console.log('Rendering event presenter records...');
}
exports.render_event_presenter_file_records = function (events) {
console.log('Rendering event presenter file records...');
}
/* 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;
}
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];
}

View File

@@ -1,459 +0,0 @@
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;
} else {
console.log('Event not it.');
}
}).then(function() {
console.log('idb_to_ui: Iterate tbl_event_file complete')
tbl_event_complete = true;
});
}
// NOTE: The event_file table should probably only be looped through once when the table is actually updated.
// NOTE: Not each time the other objects (event, location, session, presentation, presenter) are updated.
exports.render_event_file_records = function (event_files, event_id) {
console.log('Rendering event file records...');
/*
tbl_event_file.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;
} else {
console.log('Event not it.');
}
}).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...');
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;
} else {
console.log('Event location not it.');
}
}).then(function() {
console.log('idb_to_ui: Iterate tbl_event_file complete')
tbl_event_location_complete = true;
});
}
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...');
// 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';
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.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('Sessions 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.className = 'list-group list-group-flush';
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.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.className = 'list-group list-group-flush';
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);
//console.log(session_list_items.length);
for (var i in session_list_items) {
console.log(session_list_items[i].getAttribute('data-session_id'));
//console.log(session_list_items[i]);
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('********** ********* ****** ** * ** ****** ********* *********');
console.log('Rendering event presentation records...');
let launcher_sessions = document.getElementById('launcher_sessions').childNodes; //_list_items
console.log(launcher_sessions);
console.log(tbl_event_presentation);
/*
loop through the sessions list (not table) {
let session_id = ;
attempt to loop through list of presentations (possibly empty) {
let presentation_id = ;
let presentation_id_found = false;
iterate through tbl_event_presentation
if (li presentation_id = tbl_event_presentation.id and session id = tbl_event_presentation.event_session_id) {
update the presentation_id
presentation_id_found = true;
} else if (session id = tbl_event_presentation.event_session_id) {
add in the new presentation_id from the table
presentation_id_found = true;
}
if (presentation_id_found == false) {
// remove the presentation
}
}
}
*/
for (let i in launcher_sessions) {
console.log(launcher_sessions[i].getAttribute('data-session_id'));
let session_id = launcher_sessions[i].getAttribute('data-session_id');
//console.log(launcher_sessions[i].getElementsByClassName('session_presentations')[0].getElementsByTagName('ul').childElementCount);
let presentations_list = launcher_sessions[i].getElementsByClassName('session_presentations')[0].getElementsByTagName('ul')[0].childNodes;
console.log(presentations_list);
//console.log(presentations_list.length);
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'));
/*
* loop through list of presentations
* if in
*/
await tbl_event_presentation.iterate(function(value, key, iteration) {
if (document.getElementById('event_presentation_'+value.id)) {
// Update the launcher presentations list for a session
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 {
}
}).then(function() {
});
} else {
console.log('No presentations listed under this session (id='+session_id+'). Time to iterate through presentations table. (launcher sessions loop i = '+i+')');
let new_i = i;
console.log(new_i);
//if (!looping_tbl_event_presentation) {
// looping_tbl_event_presentation = true;
await tbl_event_presentation.iterate(function(value, key, iteration) {
console.log('Launcher sessions loop i: '+i+' : '+new_i);
if (value.event_session_id == session_id) {
console.log('*** Presentation id ('+value.id+') is part of this session ('+session_id+'). (launcher sessions loop i='+i+')');
// Add the new session to the launcher sessions list
let presentation_li_node = document.createElement('LI');
presentation_li_node.id = 'event_presentation_'+value.id;
presentation_li_node.className = 'list-group-item';
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);
presentation_li_node.appendChild(presentation_li_heading_div_node);
console.log('************ ISSUE ************');
console.log(launcher_sessions[i].getElementsByClassName('session_presentations'));
//launcher_sessions[i].getElementsByClassName('session_presentations')[0].getElementsByTagName('ul')[0].appendChild(presentation_li_node);
let launcher_session_details = document.getElementById('detail_session_'+session_id);
console.log(launcher_session_details.getElementsByClassName('session_presentations'));
let session = document.getElementById('detail_session_'+session_id).getElementsByClassName('session_presentations')[0].getElementsByTagName('ul')[0].appendChild(presentation_li_node);
} else {
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 update or add is complete');
looping_tbl_event_presentation = true;
//tbl_event_presentation_iterate_count++;
/*
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
}
*/
});
//} else {
// console.log('Waiting until tbl_event_presentation has finished iterating...');
//}
/*
<div class="card session_presentations">
<div class="card-header">Presentations:</div>
<div class="card-body">
<ul class="list-group list-group-flush"></ul>
</div>
</div>
*/
}
//} else {
// console.log('Waiting until launcher_sessions has finished looping...');
//}
}
return true;
}
exports.render_event_presention_file_records = function (events) {
console.log('Rendering event presentation file records...');
}
exports.render_event_presenter_records = function (events) {
console.log('Rendering event presenter records...');
}
exports.render_event_presenter_file_records = function (events) {
console.log('Rendering event presenter file records...');
}
/* 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;
}
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];
}

View File

@@ -1,639 +0,0 @@
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;
} else {
console.log('Event not it.');
}
}).then(function() {
console.log('idb_to_ui: Iterate tbl_event_file complete')
tbl_event_complete = true;
});
}
// This function is used to render all event file records to the UI.
// NOTE: The event_file table should probably only be looped through once when the table is actually updated.
// NOTE: Not each time the other objects (event, location, session, presentation, presenter) are updated.
exports.render_event_file_records = function (event_files, event_id) {
console.log('Rendering event file records...');
/*
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...');
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;
} else {
console.log('Event location not it.');
}
}).then(function() {
console.log('idb_to_ui: Iterate tbl_event_file complete')
tbl_event_location_complete = true;
});
}
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...');
// 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 = 'event_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('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('********** ********* ****** ** * ** ****** ********* *********');
console.log('Rendering event presentation records...');
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 = 'event_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.');
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_presentation_id = value.event_presentation_id;
let tbl_presenter_id = value.id;
console.log('presenter tbl iteration='+iteration+' | tbl_presenter_id='+tbl_presenter_id+' for tbl_presentation_id='+tbl_presentation_id);
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('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;
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;
if (presentation_presenters_list_items.length) {
for (let j=0, len=presentation_presenters_list_items.length; j < len; j++) {
console.log('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 remove presenter ID '+li_presenter_id);
remove_presenter_id = true;
} else {
// Remove presenter here?????
// 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 {
// Remove presenter here?????
// NOTE: This section is not finished!!!
add_presenter_id = false;
//remove_presenter_id = true;
}
// 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+').');
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 = 'event_presentation_presenter_files_'+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);
console.log('BEFORE appendChild:');
console.log(document.getElementById('event_presentation_presenters_'+tbl_presentation_id));
document.getElementById('event_presentation_presenters_'+tbl_presentation_id).appendChild(presenter_li_node);
console.log('AFTER appendChild:');
console.log(document.getElementById('event_presentation_presenters_'+tbl_presentation_id));
//document.getElementById('event_presentation_presenters_'+tbl_presentation_id).innerHTML = 'WTF';
//document.getElementById('event_presentation_presenters_'+tbl_presentation_id).appendChild(presentation_presenters_ul_group_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
try {
presentations_presenters_lists[i].remove();
//document.getElementById('event_presentation_'+tbl_presenter_id).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.');
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 list of presenters found under any presentations');
}
}).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;
}
exports.render_event_presenter_file_records = function (events) {
console.log('Rendering event presenter file records...');
}
/* 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;
}
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];
}