function init() { refresh_builds(); // initialise tooltips by selector $('body').tooltip({ selector: '[data-bs-toggle="tooltip"]' }); } function refresh_builds() { var xhr = new XMLHttpRequest(); xhr.open('GET', "/builds/status.json"); // disable cache, thanks to: https://stackoverflow.com/questions/22356025/force-cache-control-no-cache-in-chrome-via-xmlhttprequest-on-f5-reload xhr.setRequestHeader("Cache-Control", "no-cache, no-store, max-age=0"); xhr.setRequestHeader("Expires", "Tue, 01 Jan 1980 1:00:00 GMT"); xhr.setRequestHeader("Pragma", "no-cache"); xhr.onload = function () { if (xhr.status === 200) { updateBuildsTable(JSON.parse(xhr.response)); } setTimeout(refresh_builds, 5000); } xhr.send(); } function showFeatures(row_num) { document.getElementById("featureModalBody").innerHTML = document.getElementById(`${row_num}_features_all`).innerHTML; var feature_modal = bootstrap.Modal.getOrCreateInstance(document.getElementById('featureModal')); feature_modal.show(); return; } function updateBuildsTable(status_json) { let output_container = document.getElementById('build_table_container'); if (Object.keys(status_json).length == 0) { output_container.innerHTML = ``; return; } // hide any tooltips which are currently open // this is needed as they might get stuck // if the element to which they belong goes out of the dom tree $('.tooltip-button').tooltip("hide"); let table_body_html = ''; let row_num = 0; Object.keys(status_json).forEach((build_id) => { let build_info = status_json[build_id]; let status_color = 'primary'; if (build_info['status'] == 'SUCCESS') { status_color = 'success'; } else if (build_info['status'] == 'PENDING') { status_color = 'warning'; } else if (build_info['status'] == 'FAILURE' || build_info['status'] == 'ERROR') { status_color = 'danger'; } table_body_html += ` ${build_info['status']} ${build_info['age']} ${build_info['git_hash_short']} ${build_info['board']} ${build_info['vehicle']} ${build_info['features'].substring(0, 100)}... show more
${build_info['progress']}%
`; row_num += 1; }); let table_html = `${table_body_html}
Status Age (hr:min) Git Hash Board Vehicle Features Progress Actions
`; output_container.innerHTML = table_html; } const LogFetch = (() => { var stopFetch = true; var build_id = null; var scheduled_fetches = 0; function startLogFetch(new_build_id) { build_id = new_build_id; stopFetch = false; if (scheduled_fetches <= 0) { scheduled_fetches = 1; fetchLogFile(); } } function stopLogFetch() { stopFetch = true; } function getBuildId() { return build_id; } function fetchLogFile() { if (stopFetch || !build_id) { scheduled_fetches -= 1; return; } var xhr = new XMLHttpRequest(); xhr.open('GET', `/builds/${build_id}/build.log`); // disable cache, thanks to: https://stackoverflow.com/questions/22356025/force-cache-control-no-cache-in-chrome-via-xmlhttprequest-on-f5-reload xhr.setRequestHeader("Cache-Control", "no-cache, no-store, max-age=0"); xhr.setRequestHeader("Expires", "Tue, 01 Jan 1980 1:00:00 GMT"); xhr.setRequestHeader("Pragma", "no-cache"); xhr.onload = () => { if (xhr.status == 200) { let logTextArea = document.getElementById('logTextArea'); let autoScrollSwitch = document.getElementById('autoScrollSwitch'); logTextArea.textContent = xhr.responseText; if (autoScrollSwitch.checked) { logTextArea.scrollTop = logTextArea.scrollHeight; } if (xhr.responseText.includes('BUILD_FINISHED')) { stopFetch = true; } } if (!stopFetch) { setTimeout(fetchLogFile, 3000); } else { scheduled_fetches -= 1; } } xhr.send(); } return {startLogFetch, stopLogFetch, getBuildId}; })(); function launchLogModal(build_id) { document.getElementById('logTextArea').textContent = `Fetching build log...\nBuild ID: ${build_id}`; LogFetch.startLogFetch(build_id); let logModalElement = document.getElementById('logModal'); logModalElement.addEventListener('hide.bs.modal', () => { LogFetch.stopLogFetch(); }); let logModal = bootstrap.Modal.getOrCreateInstance(logModalElement); logModal.show(); }