renames app js
This commit is contained in:
@@ -4,34 +4,44 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
const logsElement = document.getElementById('logs');
|
||||
const prevPageButton = document.getElementById('prevPage');
|
||||
const nextPageButton = document.getElementById('nextPage');
|
||||
const pageInfo = document.getElementById('pageInfo');
|
||||
let currentPage = 0;
|
||||
const linesPerPage = 50;
|
||||
let linesPerPage;
|
||||
let autoRefreshInterval;
|
||||
|
||||
if (form) {
|
||||
console.log('Form:', form);
|
||||
console.log('Submit button:', form.querySelector('button[type="submit"]'));
|
||||
}
|
||||
// Fetch the configuration value for linesPerPage
|
||||
fetch('/config/lines_per_page')
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
linesPerPage = data.lines_per_page;
|
||||
// Initial fetch of logs after getting the config value
|
||||
fetchLogs(currentPage);
|
||||
});
|
||||
|
||||
const fetchLogs = (page) => {
|
||||
fetch(`/logfile?lines=${linesPerPage * (page + 1)}`)
|
||||
fetch(`/logfile?page=${page}&lines_per_page=${linesPerPage}`)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.error) {
|
||||
logsElement.textContent = data.error;
|
||||
} else {
|
||||
// Reverse the order of log lines
|
||||
const reversedLogs = data.log.reverse();
|
||||
logsElement.textContent = reversedLogs.join('');
|
||||
logsElement.innerHTML = data.log.map((line, index) => {
|
||||
const lineNumber = data.start_line - index;
|
||||
return `<span class="line-number">${lineNumber}</span> ${line}`;
|
||||
}).join('');
|
||||
// Disable/enable pagination buttons based on the page number and total lines
|
||||
prevPageButton.disabled = page === 0;
|
||||
nextPageButton.disabled = (page + 1) * linesPerPage >= data.total_lines;
|
||||
pageInfo.textContent = `Page ${page + 1} of ${Math.ceil(data.total_lines / linesPerPage)}`;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const startAutoRefresh = () => {
|
||||
function startAutoRefresh() {
|
||||
autoRefreshInterval = setInterval(() => {
|
||||
fetchLogs(currentPage);
|
||||
}, 5000); // Refresh every 5 seconds
|
||||
};
|
||||
}
|
||||
|
||||
const stopAutoRefresh = () => {
|
||||
clearInterval(autoRefreshInterval);
|
||||
|
||||
Reference in New Issue
Block a user