const os = require('os'); const path = require('path'); const fs = require('fs'); const { ipcRenderer } = require('electron'); exports.render_launcher = function (launcher_tmp) { console.log('Rendering based on launcher_tmp...'); console.log('In module_app_ui.js v2 idb to launcher object: ***'); console.log(launcher_tmp); console.log('In module_app_ui.js v2 idb to launcher object: ^^^'); /* if (launcher_tmp.event) { for (var i in launcher_tmp.event) { if (launcher_tmp.event[i].id == event_id) { console.log('*** Event id ('+event_id+') found in launcher object.'); for (var j in launcher_tmp.location) { if (launcher_tmp.location[j].id == event_location_id) { console.log('*** Location id ('+event_location_id+') found in launcher object.'); document.title = launcher_tmp.location[j].name+'@'+launcher_tmp.event[i].name; document.getElementById('location_name').innerHTML = ' '+launcher_tmp.location[j].name+'@'+launcher_tmp.event[i].name; } else { console.log('Event location not it.'); } } } else { console.log('Event not it.'); } } console.log('Data in launcher object'); console.log(launcher_tmp); } else { console.log('Missing data in launcher object'); return false; } */ document.getElementById('event_files_menu').innerHTML = '

Event Files

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

Location Files

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

Sessions

'; //document.getElementById('sessions_menu').innerHTML += ''; index_launcher_sessions('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_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')) } ); } return true; } /* Updated 2019-12-19 */ function view_session(session_id) { var class_elements = document.getElementsByClassName('launcher_sessions'); console.log('*** View session ID: '+session_id); for (var i = 0; i < class_elements.length; i++) { //console.log('*** checking: '+class_elements[i].getAttribute('data-session_id')); if (class_elements[i].getAttribute('data-session_id') == session_id) { //console.log('show'); class_elements[i].classList.remove('d-none'); class_elements[i].classList.add('d-block'); } else { //console.log('hide'); class_elements[i].classList.remove('d-block'); class_elements[i].classList.add('d-none'); } } return true; } /* Updated 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]; }