fixes log pagination
This commit is contained in:
11
app.py
11
app.py
@@ -176,7 +176,8 @@ def logs():
|
|||||||
|
|
||||||
@app.route('/logfile', methods=['GET'])
|
@app.route('/logfile', methods=['GET'])
|
||||||
def logfile():
|
def logfile():
|
||||||
lines = int(request.args.get('lines', 100)) # Number of lines to read
|
page = int(request.args.get('page', 0)) # Page number
|
||||||
|
lines_per_page = int(request.args.get('lines_per_page', config['DEFAULT']['LOG_VIEW_LINES'])) # Lines per page
|
||||||
log_file_path = logFile # Path to the current log file
|
log_file_path = logFile # Path to the current log file
|
||||||
|
|
||||||
if not os.path.isfile(log_file_path):
|
if not os.path.isfile(log_file_path):
|
||||||
@@ -184,8 +185,14 @@ def logfile():
|
|||||||
|
|
||||||
with open(log_file_path, 'r') as file:
|
with open(log_file_path, 'r') as file:
|
||||||
log_lines = file.readlines()
|
log_lines = file.readlines()
|
||||||
|
|
||||||
|
log_lines = log_lines[::-1]
|
||||||
|
|
||||||
return jsonify({"log": log_lines[-lines:]})
|
start = page * lines_per_page
|
||||||
|
end = start + lines_per_page
|
||||||
|
paginated_lines = log_lines[start:end] if start < len(log_lines) else []
|
||||||
|
|
||||||
|
return jsonify({"log": paginated_lines, "total_lines": len(log_lines), "pages": len(log_lines) // lines_per_page})
|
||||||
|
|
||||||
@app.route('/results')
|
@app.route('/results')
|
||||||
def results():
|
def results():
|
||||||
|
|||||||
@@ -4,23 +4,27 @@ 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;
|
const linesPerPage = 50;
|
||||||
let autoRefreshInterval;
|
let autoRefreshInterval;
|
||||||
|
|
||||||
console.log('Form:', form);
|
|
||||||
console.log('Submit button:', form.querySelector('button[type="submit"]'));
|
|
||||||
|
|
||||||
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.total_lines - (page * linesPerPage + 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)}`;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -207,3 +207,11 @@
|
|||||||
#color-mode-toggle input:not(:checked) + label .sun {
|
#color-mode-toggle input:not(:checked) + label .sun {
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.line-number {
|
||||||
|
display: inline-block;
|
||||||
|
width: 30px;
|
||||||
|
text-align: right;
|
||||||
|
margin-right: 10px;
|
||||||
|
color: #888;
|
||||||
|
}
|
||||||
@@ -23,15 +23,17 @@
|
|||||||
<button id="stopButton" class="btn btn-primary">Stop Scraping</button>
|
<button id="stopButton" class="btn btn-primary">Stop Scraping</button>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section id="resultsContainer" class="container-fluid d-flex justify-content-center">
|
<section id="resultsContainer" class="container-fluid d-flex justify-content-center">
|
||||||
<div class="container-md my-5 mx-2 shadow-lg p-4" style="height: 500px;">
|
<div class="container-md my-5 mx-2 shadow-lg p-4" style="height: 500px;">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-7">
|
<div class="col-7">
|
||||||
<h2>Logs</h2>
|
<h2>Logs</h2>
|
||||||
<button id="prevPage">Previous</button>
|
<pre id="logs" class="pre-scrollable" style="height: 350px; overflow:scroll; "><code></code></pre>
|
||||||
<button id="nextPage">Next</button>
|
<div class="btn-group btn-group-sm">
|
||||||
<pre id="logs" class="pre-scrollable" style="height: 430px; overflow:scroll; "><code></code></pre>
|
<button class="btn btn-primary" id="prevPage">Previous</button>
|
||||||
|
<button class="btn btn-primary" id="pageInfo" disabled>Page 1 of 1</button>
|
||||||
|
<button class="btn btn-primary" id="nextPage">Next</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<h2>Stats</h2>
|
<h2>Stats</h2>
|
||||||
@@ -41,6 +43,7 @@
|
|||||||
</section>
|
</section>
|
||||||
{% block scripts %}
|
{% block scripts %}
|
||||||
{{ bootstrap.load_js() }}
|
{{ bootstrap.load_js() }}
|
||||||
|
<link rel="stylesheet" href="{{ url_for('.static', filename='style.css') }}">
|
||||||
<script src="{{url_for('.static', filename='app.js')}}"></script>
|
<script src="{{url_for('.static', filename='app.js')}}"></script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% include "footer.html" %}
|
{% include "footer.html" %}
|
||||||
Reference in New Issue
Block a user