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");
// 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 timeAgo(timestampStr) {
const timestamp = parseFloat(timestampStr);
const now = Date.now() / 1000;
const diff = now - timestamp;
if (diff < 0) return "In the future";
const hours = Math.floor(diff / 3600);
const minutes = Math.floor((diff % 3600) / 60);
return `${hours}h ${minutes}m`;
}
function updateBuildsTable(builds) {
let output_container = document.getElementById('build_table_container');
if (builds.length == 0) {
output_container.innerHTML = `
Welcome!
No builds were queued to run on the server recently. To queue one, please click add a build.
`;
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;
builds.forEach((build_info) => {
let status_color = 'primary';
if (build_info['progress']['state'] == 'SUCCESS') {
status_color = 'success';
} else if (build_info['progress']['state'] == 'PENDING') {
status_color = 'warning';
} else if (build_info['progress']['state'] == 'FAILURE' || build_info['progress']['state'] == 'ERROR' || build_info['progress']['state'] == 'TIMED_OUT') {
status_color = 'danger';
}
const features_string = build_info['selected_features'].join(', ')
const build_age = timeAgo(build_info['time_created'])
const isNonTerminal = (build_info['progress']['state'] == 'PENDING' || build_info['progress']['state'] == 'RUNNING');
const downloadDisabled = isNonTerminal ? 'disabled' : '';
const download_button_color = isNonTerminal ? 'secondary' : 'primary';
table_body_html += `