1903dc5bcd
- Added database logging to all major processing tasks - Created API endpoints for retrieving processing logs - Updated frontend to display processing logs per file - Logging includes: process_document, convert_to_pdf, extract_metadata_with_gpt, embed_metadata_into_pdf, finalize_document_storage, send_to_all_destinations Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
376 lines
10 KiB
HTML
376 lines
10 KiB
HTML
{% extends "base.html" %}
|
|
{% block title %}File Records{% endblock %}
|
|
|
|
{% block head_extra %}
|
|
<script src="/static/js/common.js"></script>
|
|
<!-- Add TableSorter library -->
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/2.31.3/js/jquery.tablesorter.min.js"></script>
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/2.31.3/css/theme.bootstrap_4.min.css">
|
|
<style>
|
|
.file-table {
|
|
width: 100%;
|
|
border-collapse: collapse;
|
|
margin-bottom: 1rem;
|
|
}
|
|
.file-table th,
|
|
.file-table td {
|
|
padding: 0.75rem;
|
|
text-align: left;
|
|
border-bottom: 1px solid #e2e8f0;
|
|
}
|
|
.file-table th {
|
|
background-color: #f7fafc;
|
|
font-weight: 600;
|
|
cursor: pointer;
|
|
}
|
|
.file-table th:hover {
|
|
background-color: #edf2f7;
|
|
}
|
|
.file-table tbody tr:hover {
|
|
background-color: #f7fafc;
|
|
}
|
|
.delete-btn {
|
|
color: #e53e3e;
|
|
cursor: pointer;
|
|
padding: 0.25rem 0.5rem;
|
|
border-radius: 0.25rem;
|
|
background: none;
|
|
border: none;
|
|
display: flex;
|
|
align-items: center;
|
|
}
|
|
.delete-btn:hover {
|
|
background-color: #fed7d7;
|
|
}
|
|
.view-logs-btn {
|
|
color: #3182ce;
|
|
cursor: pointer;
|
|
padding: 0.25rem 0.5rem;
|
|
border-radius: 0.25rem;
|
|
background: none;
|
|
border: none;
|
|
display: flex;
|
|
align-items: center;
|
|
margin-right: 0.5rem;
|
|
}
|
|
.view-logs-btn:hover {
|
|
background-color: #bee3f8;
|
|
}
|
|
.error-message {
|
|
background-color: #FEE2E2;
|
|
border: 1px solid #F87171;
|
|
color: #B91C1C;
|
|
padding: 1rem;
|
|
border-radius: 0.25rem;
|
|
margin-bottom: 1rem;
|
|
}
|
|
|
|
/* TableSorter specific styles */
|
|
.tablesorter-header-inner {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
}
|
|
|
|
/* Modal styles */
|
|
.modal {
|
|
display: none;
|
|
position: fixed;
|
|
top: 0;
|
|
left: 0;
|
|
width: 100%;
|
|
height: 100%;
|
|
background-color: rgba(0, 0, 0, 0.5);
|
|
z-index: 1000;
|
|
justify-content: center;
|
|
align-items: center;
|
|
}
|
|
.modal-content {
|
|
background-color: white;
|
|
border-radius: 0.5rem;
|
|
padding: 2rem;
|
|
max-width: 800px;
|
|
width: 90%;
|
|
max-height: 80vh;
|
|
overflow-y: auto;
|
|
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
|
}
|
|
.modal-title {
|
|
font-size: 1.25rem;
|
|
font-weight: bold;
|
|
margin-bottom: 1rem;
|
|
}
|
|
.modal-buttons {
|
|
display: flex;
|
|
justify-content: flex-end;
|
|
margin-top: 1.5rem;
|
|
gap: 0.75rem;
|
|
}
|
|
.modal-btn {
|
|
padding: 0.5rem 1rem;
|
|
border-radius: 0.25rem;
|
|
border: none;
|
|
cursor: pointer;
|
|
}
|
|
.modal-btn-cancel {
|
|
background-color: #e2e8f0;
|
|
}
|
|
.modal-btn-cancel:hover {
|
|
background-color: #cbd5e0;
|
|
}
|
|
.modal-btn-delete {
|
|
background-color: #e53e3e;
|
|
color: white;
|
|
}
|
|
.modal-btn-delete:hover {
|
|
background-color: #c53030;
|
|
}
|
|
|
|
/* Logs styles */
|
|
.logs-container {
|
|
margin-top: 1rem;
|
|
}
|
|
.log-entry {
|
|
padding: 0.75rem;
|
|
border-left: 3px solid #e2e8f0;
|
|
margin-bottom: 0.5rem;
|
|
background-color: #f7fafc;
|
|
border-radius: 0.25rem;
|
|
}
|
|
.log-entry.success {
|
|
border-left-color: #48bb78;
|
|
background-color: #f0fff4;
|
|
}
|
|
.log-entry.failure {
|
|
border-left-color: #f56565;
|
|
background-color: #fff5f5;
|
|
}
|
|
.log-entry.in_progress {
|
|
border-left-color: #4299e1;
|
|
background-color: #ebf8ff;
|
|
}
|
|
.log-step {
|
|
font-weight: 600;
|
|
color: #2d3748;
|
|
}
|
|
.log-message {
|
|
color: #4a5568;
|
|
margin-top: 0.25rem;
|
|
}
|
|
.log-timestamp {
|
|
font-size: 0.875rem;
|
|
color: #718096;
|
|
margin-top: 0.25rem;
|
|
}
|
|
.no-logs {
|
|
text-align: center;
|
|
padding: 2rem;
|
|
color: #718096;
|
|
}
|
|
</style>
|
|
{% endblock %}
|
|
|
|
{% block content %}
|
|
<div class="container mx-auto px-4 py-8">
|
|
<h2 class="text-3xl font-bold mb-6">File Records</h2>
|
|
|
|
{% if error %}
|
|
<div class="error-message">
|
|
<p><strong>Error:</strong> {{ error }}</p>
|
|
<p class="mt-2">This might be due to a configuration or import issue. Please check the server logs.</p>
|
|
</div>
|
|
{% endif %}
|
|
|
|
|
|
<!-- File table -->
|
|
<div class="overflow-x-auto">
|
|
<table class="file-table" id="fileTable">
|
|
<thead>
|
|
<tr>
|
|
<th>ID</th>
|
|
<th>Original Filename</th>
|
|
<th>File Size</th>
|
|
<th>Mime Type</th>
|
|
<th>Created At</th>
|
|
<th class="sorter-false">Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{% for file in files %}
|
|
<tr>
|
|
<td>{{ file.id }}</td>
|
|
<td>{{ file.original_filename }}</td>
|
|
<td data-sort-value="{{ file.file_size }}">{{ (file.file_size / 1024) | round(2) }} KB</td>
|
|
<td>{{ file.mime_type }}</td>
|
|
<td>{{ file.created_at }}</td>
|
|
<td>
|
|
<div style="display: flex; align-items: center;">
|
|
<button onclick="showLogs('{{ file.id }}')" class="view-logs-btn" title="View processing logs">
|
|
<i class="fas fa-list"></i>
|
|
</button>
|
|
<button onclick="showDeleteModal('{{ file.id }}')" class="delete-btn" title="Delete file">
|
|
<i class="fas fa-trash"></i>
|
|
</button>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
{% else %}
|
|
<tr>
|
|
<td colspan="6" class="text-center py-4">No files found</td>
|
|
</tr>
|
|
{% endfor %}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<!-- Delete confirmation modal -->
|
|
<div id="deleteModal" class="modal">
|
|
<div class="modal-content">
|
|
<div class="modal-title">Confirm Deletion</div>
|
|
<p>Are you sure you want to delete this file?</p>
|
|
<div class="modal-buttons">
|
|
<button id="cancelDelete" class="modal-btn modal-btn-cancel">Cancel</button>
|
|
<button id="confirmDelete" class="modal-btn modal-btn-delete">Delete</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Processing logs modal -->
|
|
<div id="logsModal" class="modal">
|
|
<div class="modal-content">
|
|
<div class="modal-title">Processing Logs</div>
|
|
<div id="logsContent">
|
|
<p>Loading logs...</p>
|
|
</div>
|
|
<div class="modal-buttons">
|
|
<button id="closeLogsModal" class="modal-btn modal-btn-cancel">Close</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Add JavaScript for handling DELETE requests -->
|
|
<script>
|
|
// Modal functionality
|
|
const deleteModal = document.getElementById('deleteModal');
|
|
const logsModal = document.getElementById('logsModal');
|
|
const cancelDelete = document.getElementById('cancelDelete');
|
|
const confirmDelete = document.getElementById('confirmDelete');
|
|
const closeLogsModal = document.getElementById('closeLogsModal');
|
|
let currentFileId = null;
|
|
|
|
function showDeleteModal(fileId) {
|
|
currentFileId = fileId;
|
|
deleteModal.style.display = 'flex';
|
|
}
|
|
|
|
function showLogs(fileId) {
|
|
logsModal.style.display = 'flex';
|
|
document.getElementById('logsContent').innerHTML = '<p>Loading logs...</p>';
|
|
|
|
// Fetch logs from API
|
|
fetch(`/api/logs/file/${fileId}`)
|
|
.then(response => {
|
|
if (!response.ok) {
|
|
throw new Error('Failed to fetch logs');
|
|
}
|
|
return response.json();
|
|
})
|
|
.then(data => {
|
|
displayLogs(data);
|
|
})
|
|
.catch(error => {
|
|
console.error('Error:', error);
|
|
document.getElementById('logsContent').innerHTML =
|
|
`<div class="error-message">Error loading logs: ${error.message}</div>`;
|
|
});
|
|
}
|
|
|
|
function displayLogs(data) {
|
|
const logsContent = document.getElementById('logsContent');
|
|
|
|
if (!data.logs || data.logs.length === 0) {
|
|
logsContent.innerHTML = '<div class="no-logs">No processing logs found for this file.</div>';
|
|
return;
|
|
}
|
|
|
|
let html = '<div class="logs-container">';
|
|
html += `<h3 style="margin-bottom: 1rem;">File: ${data.file.original_filename}</h3>`;
|
|
|
|
data.logs.forEach(log => {
|
|
const statusClass = log.status.toLowerCase().replace(' ', '_');
|
|
const timestamp = new Date(log.timestamp).toLocaleString();
|
|
|
|
html += `
|
|
<div class="log-entry ${statusClass}">
|
|
<div class="log-step">${log.step_name} - ${log.status}</div>
|
|
${log.message ? `<div class="log-message">${log.message}</div>` : ''}
|
|
<div class="log-timestamp">${timestamp}</div>
|
|
</div>
|
|
`;
|
|
});
|
|
|
|
html += '</div>';
|
|
logsContent.innerHTML = html;
|
|
}
|
|
|
|
cancelDelete.addEventListener('click', () => {
|
|
deleteModal.style.display = 'none';
|
|
});
|
|
|
|
confirmDelete.addEventListener('click', () => {
|
|
deleteFile(currentFileId);
|
|
deleteModal.style.display = 'none';
|
|
});
|
|
|
|
closeLogsModal.addEventListener('click', () => {
|
|
logsModal.style.display = 'none';
|
|
});
|
|
|
|
// Close modal if clicking outside of it
|
|
window.addEventListener('click', (event) => {
|
|
if (event.target === deleteModal) {
|
|
deleteModal.style.display = 'none';
|
|
}
|
|
if (event.target === logsModal) {
|
|
logsModal.style.display = 'none';
|
|
}
|
|
});
|
|
|
|
function deleteFile(fileId) {
|
|
fetch(`/api/files/${fileId}`, {
|
|
method: 'DELETE',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
}
|
|
})
|
|
.then(response => {
|
|
if (!response.ok) {
|
|
throw new Error('Failed to delete file');
|
|
}
|
|
// Reload the page to show updated file list
|
|
window.location.reload();
|
|
})
|
|
.catch(error => {
|
|
console.error('Error:', error);
|
|
alert(`Error deleting file: ${error.message}`);
|
|
});
|
|
}
|
|
|
|
// Initialize TableSorter
|
|
$(document).ready(function() {
|
|
$("#fileTable").tablesorter({
|
|
theme: 'bootstrap',
|
|
widthFixed: true,
|
|
headerTemplate: '{content} {icon}',
|
|
widgets: ['zebra', 'stickyHeaders'],
|
|
sortList: [[0, 0]], // Default sort on the first column ascending
|
|
headers: {
|
|
5: { sorter: false } // Disable sorting on the Actions column
|
|
}
|
|
});
|
|
});
|
|
</script>
|
|
</div>
|
|
{% endblock %}
|