renames app js
This commit is contained in:
@@ -4,34 +4,44 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
const logsElement = document.getElementById('logs');
|
const logsElement = document.getElementById('logs');
|
||||||
const prevPageButton = document.getElementById('prevPage');
|
const prevPageButton = document.getElementById('prevPage');
|
||||||
const nextPageButton = document.getElementById('nextPage');
|
const nextPageButton = document.getElementById('nextPage');
|
||||||
|
const pageInfo = document.getElementById('pageInfo');
|
||||||
let currentPage = 0;
|
let currentPage = 0;
|
||||||
const linesPerPage = 50;
|
let linesPerPage;
|
||||||
let autoRefreshInterval;
|
let autoRefreshInterval;
|
||||||
|
|
||||||
if (form) {
|
// Fetch the configuration value for linesPerPage
|
||||||
console.log('Form:', form);
|
fetch('/config/lines_per_page')
|
||||||
console.log('Submit button:', form.querySelector('button[type="submit"]'));
|
.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) => {
|
const fetchLogs = (page) => {
|
||||||
fetch(`/logfile?lines=${linesPerPage * (page + 1)}`)
|
fetch(`/logfile?page=${page}&lines_per_page=${linesPerPage}`)
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
if (data.error) {
|
if (data.error) {
|
||||||
logsElement.textContent = data.error;
|
logsElement.textContent = data.error;
|
||||||
} else {
|
} else {
|
||||||
// Reverse the order of log lines
|
logsElement.innerHTML = data.log.map((line, index) => {
|
||||||
const reversedLogs = data.log.reverse();
|
const lineNumber = data.start_line - index;
|
||||||
logsElement.textContent = reversedLogs.join('');
|
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(() => {
|
autoRefreshInterval = setInterval(() => {
|
||||||
fetchLogs(currentPage);
|
fetchLogs(currentPage);
|
||||||
}, 5000); // Refresh every 5 seconds
|
}, 5000); // Refresh every 5 seconds
|
||||||
};
|
}
|
||||||
|
|
||||||
const stopAutoRefresh = () => {
|
const stopAutoRefresh = () => {
|
||||||
clearInterval(autoRefreshInterval);
|
clearInterval(autoRefreshInterval);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
{% block content %}
|
{% block content %}
|
||||||
<section id="scrapingFormContainer" class="container-fluid d-flex justify-content-center">
|
<section id="scrapingFormContainer" class="container-fluid d-flex justify-content-center">
|
||||||
<div class="container-md my-5 mx-2 shadow-lg p-4 ">
|
<div class="container-md my-5 mx-2 shadow-lg p-4 ">
|
||||||
<h2>Config</h2>
|
<h2>Config <span id="activity_indicator" class="badge text-bg-danger">Inactive</span></h2>
|
||||||
<form id="scrapingForm" method="POST" action="{{ url_for('start_scraping') }}">
|
<form id="scrapingForm" method="POST" action="{{ url_for('start_scraping') }}">
|
||||||
{{ form.hidden_tag() }}
|
{{ form.hidden_tag() }}
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
@@ -43,6 +43,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
{% block scripts %}
|
{% block scripts %}
|
||||||
<script src="{{url_for('static', filename='app.js')}}"></script>
|
<script src="{{url_for('static', filename='index.js')}}"></script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
|
|||||||
Reference in New Issue
Block a user