function loadAdminPage() {
var html = '
';
html += ``;
html += '
';
html += '';
html += '
';
html += '';
html += `
`;
document.getElementById("setup").innerHTML = html;
get_log();
}
function get_log() {
document.getElementById("log_button").disabled = true;
document.getElementById("log_button").style.opacity = '0.5';
log_data_form = {};
var log_data_data = JSON.stringify(log_form);
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4) {
try {
var result= JSON.parse(this.responseText);
} catch(error) {
alert('Failed to parse API response.');
console.log('Failed to parse API response. Error: ' + this.responseText);
document.getElementById("log_button").disabled = false;
document.getElementById("log_button").style.opacity = '1';
return;
}
if(result.error) {
document.getElementById("log_button").disabled = false;
document.getElementById("log_button").style.opacity = '1';
alert(result.error);
} else {
document.getElementById("log_button").disabled = false;
document.getElementById("log_button").style.opacity = '1';
log_form(result.data, result.limit);
}
}
};
xhttp.withCredentials = true;
xhttp.open("post", api_url + "get/log", );
xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhttp.setRequestHeader("Authorization", cookie);
xhttp.send(log_data_data);
return;
}
function log_form(log_lines_array, limit) {
var log_table = `
Date |
Time |
Message |
`;
for(index = 0; index < log_lines_array.length; index++) {
var tablerow = `
` + log_lines_array[index].date + ` |
` + log_lines_array[index].time + ` |
` + log_lines_array[index].message + ` |
`;
log_table += tablerow
}
document.getElementById('log_results_body').innerHTML = log_table
document.getElementById('log_result_text').innerHTML = 'Retrieved last ' + limit + ' lines.';
var log_results = document.getElementById("log_results");
log_results.scrollTop = log_results.scrollHeight;
}