c7c5718f78
- Add /api/queue/stats endpoint with Redis queue lengths, Celery worker inspection, and DB processing summaries - Add /api/queue/pending-count lightweight endpoint for the files page banner - Add /admin/queue admin-only view with auto-refreshing queue dashboard - Add queue pending banner on /files page showing queued/processing count - Add Queue Monitor link to admin dropdown in navigation (desktop + mobile) - Add comprehensive tests for all new endpoints and views Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
1102 lines
38 KiB
HTML
1102 lines
38 KiB
HTML
{% extends "base.html" %}
|
||
{% block title %}File Records{% endblock %}
|
||
|
||
{% block head_extra %}
|
||
<script src="/static/js/common.js"></script>
|
||
<script>
|
||
window.uploadConfig = {
|
||
concurrency: {{ upload_concurrency }},
|
||
queueDelayMs: {{ upload_queue_delay_ms }}
|
||
};
|
||
</script>
|
||
<script src="/static/js/upload.js"></script>
|
||
<style>
|
||
/* Drop overlay styles - covers entire page for drag-and-drop anywhere */
|
||
.drop-overlay {
|
||
display: none;
|
||
position: fixed;
|
||
top: 0;
|
||
left: 0;
|
||
width: 100vw;
|
||
height: 100vh;
|
||
background-color: rgba(59, 130, 246, 0.15);
|
||
border: 6px dashed #3b82f6;
|
||
z-index: 999;
|
||
pointer-events: none;
|
||
justify-content: center;
|
||
align-items: center;
|
||
}
|
||
.drop-overlay.active {
|
||
display: flex;
|
||
animation: fadeIn 0.2s ease-in;
|
||
}
|
||
@keyframes fadeIn {
|
||
from { opacity: 0; }
|
||
to { opacity: 1; }
|
||
}
|
||
.drop-message {
|
||
background-color: white;
|
||
padding: 2rem 3rem;
|
||
border-radius: 0.5rem;
|
||
box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
|
||
text-align: center;
|
||
pointer-events: none;
|
||
}
|
||
.drop-message i {
|
||
font-size: 4rem;
|
||
color: #3b82f6;
|
||
margin-bottom: 1rem;
|
||
display: block;
|
||
}
|
||
.drop-message p {
|
||
font-size: 1.5rem;
|
||
font-weight: 600;
|
||
color: #1f2937;
|
||
margin-bottom: 0.5rem;
|
||
}
|
||
.drop-message .drop-hint {
|
||
font-size: 1rem;
|
||
color: #6b7280;
|
||
font-weight: 400;
|
||
margin-top: 0.5rem;
|
||
}
|
||
|
||
/* Upload progress modal */
|
||
.upload-modal {
|
||
display: none;
|
||
position: fixed;
|
||
bottom: 1rem;
|
||
right: 1rem;
|
||
width: 400px;
|
||
max-width: 90vw;
|
||
background-color: white;
|
||
border-radius: 0.5rem;
|
||
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
|
||
z-index: 1000;
|
||
overflow: hidden;
|
||
}
|
||
.upload-modal.active {
|
||
display: block;
|
||
}
|
||
.upload-modal-header {
|
||
background-color: #3b82f6;
|
||
color: white;
|
||
padding: 0.75rem 1rem;
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
}
|
||
.upload-modal-body {
|
||
padding: 1rem;
|
||
max-height: 400px;
|
||
overflow-y: auto;
|
||
}
|
||
.close-modal-btn {
|
||
background: none;
|
||
border: none;
|
||
color: white;
|
||
cursor: pointer;
|
||
font-size: 1.25rem;
|
||
}
|
||
.close-modal-btn:hover {
|
||
opacity: 0.8;
|
||
}
|
||
|
||
<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;
|
||
position: relative;
|
||
}
|
||
.file-table th.sortable {
|
||
cursor: pointer;
|
||
user-select: none;
|
||
}
|
||
.file-table th.sortable:hover {
|
||
background-color: #edf2f7;
|
||
}
|
||
.file-table tbody tr:hover {
|
||
background-color: #f7fafc;
|
||
cursor: pointer;
|
||
}
|
||
.sort-indicator {
|
||
display: inline-block;
|
||
margin-left: 0.5rem;
|
||
opacity: 0.5;
|
||
}
|
||
.sort-indicator.active {
|
||
opacity: 1;
|
||
font-weight: bold;
|
||
}
|
||
|
||
/* Status badges */
|
||
.status-badge {
|
||
display: inline-block;
|
||
padding: 0.25rem 0.75rem;
|
||
border-radius: 9999px;
|
||
font-size: 0.875rem;
|
||
font-weight: 600;
|
||
text-align: center;
|
||
}
|
||
.status-pending {
|
||
background-color: #FEF3C7;
|
||
color: #92400E;
|
||
}
|
||
.status-processing {
|
||
background-color: #DBEAFE;
|
||
color: #1E3A8A;
|
||
}
|
||
.status-completed {
|
||
background-color: #D1FAE5;
|
||
color: #065F46;
|
||
}
|
||
.status-failed {
|
||
background-color: #FEE2E2;
|
||
color: #991B1B;
|
||
}
|
||
.status-duplicate {
|
||
background-color: #E5E7EB;
|
||
color: #374151;
|
||
}
|
||
|
||
/* Action buttons */
|
||
.action-btn {
|
||
color: #3182ce;
|
||
cursor: pointer;
|
||
padding: 0.25rem 0.5rem;
|
||
border-radius: 0.25rem;
|
||
background: none;
|
||
border: none;
|
||
display: inline-flex;
|
||
align-items: center;
|
||
margin-right: 0.5rem;
|
||
}
|
||
.action-btn:hover {
|
||
background-color: #bee3f8;
|
||
}
|
||
.action-btn.delete {
|
||
color: #e53e3e;
|
||
}
|
||
.action-btn.delete:hover {
|
||
background-color: #fed7d7;
|
||
}
|
||
|
||
/* Filters section */
|
||
.filters-section {
|
||
background-color: #f7fafc;
|
||
padding: 1.5rem;
|
||
border-radius: 0.5rem;
|
||
margin-bottom: 1.5rem;
|
||
}
|
||
.filter-group {
|
||
display: flex;
|
||
gap: 1rem;
|
||
flex-wrap: wrap;
|
||
align-items: flex-end;
|
||
}
|
||
.filter-item {
|
||
flex: 1;
|
||
min-width: 200px;
|
||
}
|
||
.filter-item label {
|
||
display: block;
|
||
font-weight: 600;
|
||
margin-bottom: 0.5rem;
|
||
color: #2d3748;
|
||
}
|
||
.filter-item input,
|
||
.filter-item select {
|
||
width: 100%;
|
||
padding: 0.5rem;
|
||
border: 1px solid #cbd5e0;
|
||
border-radius: 0.25rem;
|
||
}
|
||
.filter-item button {
|
||
padding: 0.5rem 1rem;
|
||
background-color: #3182ce;
|
||
color: white;
|
||
border: none;
|
||
border-radius: 0.25rem;
|
||
cursor: pointer;
|
||
font-weight: 600;
|
||
}
|
||
.filter-item button:hover {
|
||
background-color: #2c5aa0;
|
||
}
|
||
.filter-item button.clear {
|
||
background-color: #718096;
|
||
}
|
||
.filter-item button.clear:hover {
|
||
background-color: #4a5568;
|
||
}
|
||
|
||
/* Pagination */
|
||
.pagination {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
margin-top: 1.5rem;
|
||
padding-top: 1rem;
|
||
border-top: 1px solid #e2e8f0;
|
||
}
|
||
.pagination-info {
|
||
color: #4a5568;
|
||
}
|
||
.pagination-buttons {
|
||
display: flex;
|
||
gap: 0.5rem;
|
||
}
|
||
.pagination-button {
|
||
padding: 0.5rem 1rem;
|
||
border: 1px solid #cbd5e0;
|
||
background-color: white;
|
||
border-radius: 0.25rem;
|
||
cursor: pointer;
|
||
color: #2d3748;
|
||
}
|
||
.pagination-button:hover:not(:disabled) {
|
||
background-color: #edf2f7;
|
||
}
|
||
.pagination-button:disabled {
|
||
opacity: 0.5;
|
||
cursor: not-allowed;
|
||
}
|
||
.pagination-button.active {
|
||
background-color: #3182ce;
|
||
color: white;
|
||
border-color: #3182ce;
|
||
}
|
||
|
||
/* 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;
|
||
}
|
||
|
||
.error-message {
|
||
background-color: #FEE2E2;
|
||
border: 1px solid #F87171;
|
||
color: #B91C1C;
|
||
padding: 1rem;
|
||
border-radius: 0.25rem;
|
||
margin-bottom: 1rem;
|
||
}
|
||
</style>
|
||
{% endblock %}
|
||
|
||
{% block content %}
|
||
<!-- Drop overlay -->
|
||
<div id="dropOverlay" class="drop-overlay">
|
||
<div class="drop-message">
|
||
<i class="fas fa-cloud-upload-alt"></i>
|
||
<p>Drop files or folders anywhere to upload</p>
|
||
<div class="drop-hint">Supports PDF, Office docs, images, HTML, Markdown, and more – folders are processed recursively</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Upload progress modal -->
|
||
<div id="uploadModal" class="upload-modal">
|
||
<div class="upload-modal-header">
|
||
<span><i class="fas fa-upload"></i> Uploading Files</span>
|
||
<button class="close-modal-btn" onclick="closeUploadModal()">
|
||
<i class="fas fa-times"></i>
|
||
</button>
|
||
</div>
|
||
<div class="upload-modal-body">
|
||
<div id="uploadStatusMessage" class="text-sm text-gray-700 mb-2"></div>
|
||
<div id="uploadProgressContainer" class="space-y-2"></div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="container mx-auto px-4 py-8">
|
||
<h2 class="text-3xl font-bold mb-6">File Records</h2>
|
||
|
||
<!-- Queue pending banner (populated via JS) -->
|
||
<div id="queueBanner" class="hidden bg-blue-50 border-l-4 border-blue-400 text-blue-800 p-4 mb-6 rounded-r-lg" role="status">
|
||
<div class="flex items-center justify-between">
|
||
<div class="flex items-center">
|
||
<i class="fas fa-spinner fa-spin mr-3 text-blue-500"></i>
|
||
<span>
|
||
<strong id="queueBannerCount">0</strong> item(s) are currently queued or being processed.
|
||
Files will appear here once processing completes.
|
||
</span>
|
||
</div>
|
||
<a href="/admin/queue" class="text-blue-600 hover:text-blue-800 text-sm font-medium whitespace-nowrap ml-4"
|
||
id="queueBannerLink" style="display:none;">
|
||
<i class="fas fa-external-link-alt mr-1"></i>View Queue
|
||
</a>
|
||
</div>
|
||
</div>
|
||
|
||
{% 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 %}
|
||
|
||
<!-- Filters Section -->
|
||
<div class="filters-section">
|
||
<form method="get" action="/files" class="filter-group">
|
||
<div class="filter-item">
|
||
<label for="search">Search Filename</label>
|
||
<input type="text" id="search" name="search" value="{{ search }}" placeholder="Enter filename...">
|
||
</div>
|
||
|
||
<div class="filter-item">
|
||
<label for="mime_type">MIME Type</label>
|
||
<select id="mime_type" name="mime_type">
|
||
<option value="">All Types</option>
|
||
{% for mt in mime_types %}
|
||
<option value="{{ mt }}" {% if mt == mime_type %}selected{% endif %}>{{ mt }}</option>
|
||
{% endfor %}
|
||
</select>
|
||
</div>
|
||
|
||
<div class="filter-item">
|
||
<label for="status">Status</label>
|
||
<select id="status" name="status">
|
||
<option value="">All Statuses</option>
|
||
<option value="pending" {% if status == "pending" %}selected{% endif %}>Pending</option>
|
||
<option value="processing" {% if status == "processing" %}selected{% endif %}>Processing</option>
|
||
<option value="completed" {% if status == "completed" %}selected{% endif %}>Completed</option>
|
||
<option value="failed" {% if status == "failed" %}selected{% endif %}>Failed</option>
|
||
<option value="duplicate" {% if status == "duplicate" %}selected{% endif %}>Duplicate</option>
|
||
</select>
|
||
</div>
|
||
|
||
<div class="filter-item">
|
||
<label> </label>
|
||
<button type="submit">Apply Filters</button>
|
||
</div>
|
||
|
||
<div class="filter-item">
|
||
<label> </label>
|
||
<button type="button" class="clear" onclick="clearFilters()">Clear</button>
|
||
</div>
|
||
|
||
<!-- Hidden fields to preserve sort order -->
|
||
<input type="hidden" name="sort_by" value="{{ sort_by }}">
|
||
<input type="hidden" name="sort_order" value="{{ sort_order }}">
|
||
<input type="hidden" name="per_page" value="{{ pagination.per_page }}">
|
||
</form>
|
||
</div>
|
||
|
||
<!-- Full-Text Search Section -->
|
||
<div class="filters-section" style="margin-top: 0.75rem;">
|
||
<div style="width: 100%;">
|
||
<label for="fulltext-search" style="font-weight: 600; display: block; margin-bottom: 0.4rem;">
|
||
<i class="fas fa-search"></i> Full-Text Search (OCR text, metadata, tags)
|
||
</label>
|
||
<div style="display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap;">
|
||
<input
|
||
type="text"
|
||
id="fulltext-search"
|
||
placeholder="Search document content, sender, tags, type..."
|
||
style="flex: 1; min-width: 220px; padding: 0.5rem 0.75rem; border: 1px solid #d1d5db; border-radius: 0.375rem; font-size: 0.875rem;"
|
||
oninput="debounceSearch(this.value)"
|
||
>
|
||
<button
|
||
type="button"
|
||
onclick="runFullTextSearch()"
|
||
style="padding: 0.5rem 1rem; background-color: #3182ce; color: white; border: none; border-radius: 0.375rem; cursor: pointer; font-size: 0.875rem; white-space: nowrap;"
|
||
>
|
||
Search
|
||
</button>
|
||
<button
|
||
type="button"
|
||
onclick="clearFullTextSearch()"
|
||
style="padding: 0.5rem 1rem; background-color: #6b7280; color: white; border: none; border-radius: 0.375rem; cursor: pointer; font-size: 0.875rem; white-space: nowrap;"
|
||
>
|
||
Clear
|
||
</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Full-Text Search Results Panel -->
|
||
<div id="search-results-panel" style="display: none; margin-top: 0.5rem; border: 1px solid #e5e7eb; border-radius: 0.5rem; background: white; box-shadow: 0 1px 3px rgba(0,0,0,0.08);">
|
||
<div style="padding: 0.75rem 1rem; border-bottom: 1px solid #e5e7eb; display: flex; justify-content: space-between; align-items: center; background: #f9fafb; border-radius: 0.5rem 0.5rem 0 0;">
|
||
<span id="search-results-summary" style="font-size: 0.875rem; color: #374151;"></span>
|
||
<div id="search-results-pagination" style="display: flex; gap: 0.5rem;"></div>
|
||
</div>
|
||
<div id="search-results-list" style="padding: 0.5rem 0;"></div>
|
||
</div>
|
||
|
||
<!-- Bulk Actions Section -->
|
||
<div id="bulkActionsBar" class="filters-section" style="display: none; background-color: #e6f3ff;">
|
||
<div class="flex flex-col sm:flex-row sm:justify-between sm:items-center gap-3">
|
||
<div>
|
||
<strong id="selectedCount">0</strong> files selected
|
||
</div>
|
||
<div class="flex flex-wrap gap-2">
|
||
<button type="button" onclick="bulkReprocess()" style="padding: 0.5rem 1rem; background-color: #3182ce; color: white; border: none; border-radius: 0.25rem; cursor: pointer; font-weight: 600; min-height: 44px;">
|
||
<i class="fas fa-sync"></i> Reprocess Selected
|
||
</button>
|
||
<button type="button" onclick="bulkDelete()" style="padding: 0.5rem 1rem; background-color: #e53e3e; color: white; border: none; border-radius: 0.25rem; cursor: pointer; font-weight: 600; min-height: 44px;">
|
||
<i class="fas fa-trash"></i> Delete Selected
|
||
</button>
|
||
<button type="button" onclick="clearSelection()" style="padding: 0.5rem 1rem; background-color: #718096; color: white; border: none; border-radius: 0.25rem; cursor: pointer; font-weight: 600; min-height: 44px;">
|
||
Clear Selection
|
||
</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- File table (desktop) -->
|
||
<div class="hidden md:block overflow-x-auto">
|
||
<table class="file-table" id="fileTable">
|
||
<thead>
|
||
<tr>
|
||
<th style="width: 40px;">
|
||
<input type="checkbox" id="selectAll" onclick="toggleSelectAll()" title="Select all files on this page">
|
||
</th>
|
||
<th class="sortable" onclick="sortTable('id')">
|
||
ID
|
||
<span class="sort-indicator {% if sort_by == 'id' %}active{% endif %}">
|
||
{% if sort_by == 'id' %}
|
||
{% if sort_order == 'asc' %}▲{% else %}▼{% endif %}
|
||
{% else %}
|
||
↕
|
||
{% endif %}
|
||
</span>
|
||
</th>
|
||
<th class="sortable" onclick="sortTable('original_filename')">
|
||
Original Filename
|
||
<span class="sort-indicator {% if sort_by == 'original_filename' %}active{% endif %}">
|
||
{% if sort_by == 'original_filename' %}
|
||
{% if sort_order == 'asc' %}▲{% else %}▼{% endif %}
|
||
{% else %}
|
||
↕
|
||
{% endif %}
|
||
</span>
|
||
</th>
|
||
<th class="sortable" onclick="sortTable('file_size')">
|
||
File Size
|
||
<span class="sort-indicator {% if sort_by == 'file_size' %}active{% endif %}">
|
||
{% if sort_by == 'file_size' %}
|
||
{% if sort_order == 'asc' %}▲{% else %}▼{% endif %}
|
||
{% else %}
|
||
↕
|
||
{% endif %}
|
||
</span>
|
||
</th>
|
||
<th class="sortable" onclick="sortTable('mime_type')">
|
||
MIME Type
|
||
<span class="sort-indicator {% if sort_by == 'mime_type' %}active{% endif %}">
|
||
{% if sort_by == 'mime_type' %}
|
||
{% if sort_order == 'asc' %}▲{% else %}▼{% endif %}
|
||
{% else %}
|
||
↕
|
||
{% endif %}
|
||
</span>
|
||
</th>
|
||
<th>Status</th>
|
||
<th class="sortable" onclick="sortTable('created_at')">
|
||
Created At
|
||
<span class="sort-indicator {% if sort_by == 'created_at' %}active{% endif %}">
|
||
{% if sort_by == 'created_at' %}
|
||
{% if sort_order == 'asc' %}▲{% else %}▼{% endif %}
|
||
{% else %}
|
||
↕
|
||
{% endif %}
|
||
</span>
|
||
</th>
|
||
<th>Actions</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
{% for file in files %}
|
||
<tr onclick="viewFileDetail({{ file.id }}, event)">
|
||
<td onclick="event.stopPropagation();">
|
||
<input type="checkbox" class="file-checkbox" value="{{ file.id }}" onchange="updateBulkActionsBar()">
|
||
</td>
|
||
<td>{{ file.id }}</td>
|
||
<td>{{ file.original_filename }}</td>
|
||
<td>{{ (file.file_size / 1024) | round(2) }} KB</td>
|
||
<td>{{ file.mime_type }}</td>
|
||
<td>
|
||
<span class="status-badge status-{{ file.processing_status }}">
|
||
{{ file.processing_status | title }}
|
||
</span>
|
||
</td>
|
||
<td>{{ file.created_at.strftime('%Y-%m-%d %H:%M:%S') if file.created_at else 'N/A' }}</td>
|
||
<td>
|
||
<div style="display: flex; align-items: center;">
|
||
<button onclick="viewFileDetail({{ file.id }}, event)" class="action-btn" title="View details" style="min-height:44px;min-width:44px;">
|
||
<i class="fas fa-info-circle"></i>
|
||
</button>
|
||
<button onclick="showDeleteModal({{ file.id }}, event)" class="action-btn delete" title="Delete file" style="min-height:44px;min-width:44px;">
|
||
<i class="fas fa-trash"></i>
|
||
</button>
|
||
</div>
|
||
</td>
|
||
</tr>
|
||
{% else %}
|
||
<tr>
|
||
<td colspan="8" class="text-center py-4">No files found</td>
|
||
</tr>
|
||
{% endfor %}
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
|
||
<!-- Mobile card view (visible on small screens only) -->
|
||
<div class="md:hidden space-y-3" id="mobileCardView">
|
||
{% for file in files %}
|
||
<div
|
||
class="bg-white rounded-lg shadow p-4 cursor-pointer"
|
||
role="button"
|
||
tabindex="0"
|
||
onclick="viewFileDetail({{ file.id }}, event)"
|
||
onkeydown="if(event.key==='Enter'||event.key===' '){viewFileDetail({{ file.id }}, event);}"
|
||
aria-label="View details for {{ file.original_filename }}"
|
||
>
|
||
<div class="flex items-start justify-between gap-2">
|
||
<div class="flex-1 min-w-0">
|
||
<p class="font-semibold text-gray-800 truncate">{{ file.original_filename }}</p>
|
||
<p class="text-xs text-gray-500 mt-1">ID: {{ file.id }} · {{ (file.file_size / 1024) | round(2) }} KB</p>
|
||
<p class="text-xs text-gray-500 mt-0.5">{{ file.mime_type }}</p>
|
||
<p class="text-xs text-gray-400 mt-0.5">{{ file.created_at.strftime('%Y-%m-%d %H:%M') if file.created_at else 'N/A' }}</p>
|
||
</div>
|
||
<div class="flex flex-col items-end gap-2 flex-shrink-0">
|
||
<span class="status-badge status-{{ file.processing_status }}">{{ file.processing_status | title }}</span>
|
||
<div class="flex gap-1" role="group" aria-label="File actions" onclick="event.stopPropagation();" onkeydown="event.stopPropagation();">
|
||
<button onclick="viewFileDetail({{ file.id }}, event)" class="action-btn" title="View details" style="min-height:44px;min-width:44px;">
|
||
<i class="fas fa-info-circle"></i>
|
||
</button>
|
||
<button onclick="showDeleteModal({{ file.id }}, event)" class="action-btn delete" title="Delete file" style="min-height:44px;min-width:44px;">
|
||
<i class="fas fa-trash"></i>
|
||
</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
{% else %}
|
||
<p class="text-center py-4 text-gray-500">No files found</p>
|
||
{% endfor %}
|
||
</div>
|
||
|
||
<!-- Pagination -->
|
||
{% if pagination.total_pages > 1 %}
|
||
<div class="pagination flex-wrap gap-2">
|
||
<div class="pagination-info">
|
||
Showing {{ ((pagination.page - 1) * pagination.per_page + 1) }} -
|
||
{{ min(pagination.page * pagination.per_page, pagination.total_items) }}
|
||
of {{ pagination.total_items }} files
|
||
</div>
|
||
<div class="pagination-buttons flex-wrap">
|
||
{% if pagination.page > 1 %}
|
||
<button class="pagination-button" onclick="goToPage(1)" style="min-height:44px;">First</button>
|
||
<button class="pagination-button" onclick="goToPage({{ pagination.page - 1 }})" style="min-height:44px;">Previous</button>
|
||
{% endif %}
|
||
|
||
{% for p in range(max(1, pagination.page - 2), min(pagination.total_pages + 1, pagination.page + 3)) %}
|
||
<button class="pagination-button {% if p == pagination.page %}active{% endif %}" onclick="goToPage({{ p }})" style="min-height:44px;">
|
||
{{ p }}
|
||
</button>
|
||
{% endfor %}
|
||
|
||
{% if pagination.page < pagination.total_pages %}
|
||
<button class="pagination-button" onclick="goToPage({{ pagination.page + 1 }})" style="min-height:44px;">Next</button>
|
||
<button class="pagination-button" onclick="goToPage({{ pagination.total_pages }})" style="min-height:44px;">Last</button>
|
||
{% endif %}
|
||
</div>
|
||
</div>
|
||
{% endif %}
|
||
|
||
<!-- 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" style="min-height:44px;min-width:80px;">Cancel</button>
|
||
<button id="confirmDelete" class="modal-btn modal-btn-delete" style="min-height:44px;min-width:80px;">Delete</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<script>
|
||
// Modal functionality
|
||
const deleteModal = document.getElementById('deleteModal');
|
||
const cancelDelete = document.getElementById('cancelDelete');
|
||
const confirmDelete = document.getElementById('confirmDelete');
|
||
let currentFileId = null;
|
||
|
||
function showDeleteModal(fileId, event) {
|
||
if (event) event.stopPropagation();
|
||
currentFileId = fileId;
|
||
deleteModal.style.display = 'flex';
|
||
}
|
||
|
||
function viewFileDetail(fileId, event) {
|
||
if (event) event.stopPropagation();
|
||
window.location.href = `/files/${fileId}/detail`;
|
||
}
|
||
|
||
cancelDelete.addEventListener('click', () => {
|
||
deleteModal.style.display = 'none';
|
||
});
|
||
|
||
confirmDelete.addEventListener('click', () => {
|
||
deleteFile(currentFileId);
|
||
deleteModal.style.display = 'none';
|
||
});
|
||
|
||
// Close modal if clicking outside of it
|
||
window.addEventListener('click', (event) => {
|
||
if (event.target === deleteModal) {
|
||
deleteModal.style.display = 'none';
|
||
}
|
||
});
|
||
|
||
function deleteFile(fileId) {
|
||
fetch(`/api/files/${fileId}`, {
|
||
method: 'DELETE',
|
||
headers: {
|
||
'Content-Type': 'application/json'
|
||
}
|
||
})
|
||
.then(response => {
|
||
if (!response.ok) {
|
||
// Try to parse JSON error response, but handle non-JSON gracefully
|
||
const contentType = response.headers.get('content-type');
|
||
if (contentType && contentType.includes('application/json')) {
|
||
return response.json().then(err => {
|
||
throw new Error(err.detail || 'Failed to delete file');
|
||
});
|
||
} else {
|
||
// Non-JSON response (likely HTML error page)
|
||
return response.text().then(text => {
|
||
// Extract a readable error message
|
||
const statusText = response.statusText || 'Error';
|
||
throw new Error(`${statusText} (${response.status}): Server returned non-JSON response`);
|
||
});
|
||
}
|
||
}
|
||
return response.json();
|
||
})
|
||
.then(data => {
|
||
// Reload the page to show updated file list
|
||
window.location.reload();
|
||
})
|
||
.catch(error => {
|
||
console.error('Error:', error);
|
||
alert(`Error deleting file: ${error.message}`);
|
||
});
|
||
}
|
||
|
||
function sortTable(column) {
|
||
const urlParams = new URLSearchParams(window.location.search);
|
||
const currentSortBy = urlParams.get('sort_by') || 'created_at';
|
||
const currentSortOrder = urlParams.get('sort_order') || 'desc';
|
||
|
||
// Toggle sort order if clicking the same column
|
||
let newSortOrder = 'asc';
|
||
if (column === currentSortBy) {
|
||
newSortOrder = currentSortOrder === 'asc' ? 'desc' : 'asc';
|
||
}
|
||
|
||
urlParams.set('sort_by', column);
|
||
urlParams.set('sort_order', newSortOrder);
|
||
urlParams.set('page', '1'); // Reset to first page on sort
|
||
|
||
window.location.search = urlParams.toString();
|
||
}
|
||
|
||
function goToPage(page) {
|
||
const urlParams = new URLSearchParams(window.location.search);
|
||
urlParams.set('page', page);
|
||
window.location.search = urlParams.toString();
|
||
}
|
||
|
||
function clearFilters() {
|
||
window.location.href = '/files';
|
||
}
|
||
|
||
// Bulk selection functionality
|
||
function toggleSelectAll() {
|
||
const selectAll = document.getElementById('selectAll');
|
||
const checkboxes = document.querySelectorAll('.file-checkbox');
|
||
checkboxes.forEach(checkbox => {
|
||
checkbox.checked = selectAll.checked;
|
||
});
|
||
updateBulkActionsBar();
|
||
}
|
||
|
||
function updateBulkActionsBar() {
|
||
const checkboxes = document.querySelectorAll('.file-checkbox:checked');
|
||
const selectedCount = checkboxes.length;
|
||
const bulkActionsBar = document.getElementById('bulkActionsBar');
|
||
const selectedCountEl = document.getElementById('selectedCount');
|
||
|
||
if (selectedCount > 0) {
|
||
bulkActionsBar.style.display = 'block';
|
||
selectedCountEl.textContent = selectedCount;
|
||
} else {
|
||
bulkActionsBar.style.display = 'none';
|
||
}
|
||
|
||
// Update "select all" checkbox state
|
||
const allCheckboxes = document.querySelectorAll('.file-checkbox');
|
||
const selectAll = document.getElementById('selectAll');
|
||
selectAll.checked = allCheckboxes.length > 0 && selectedCount === allCheckboxes.length;
|
||
}
|
||
|
||
function clearSelection() {
|
||
document.querySelectorAll('.file-checkbox').forEach(cb => cb.checked = false);
|
||
document.getElementById('selectAll').checked = false;
|
||
updateBulkActionsBar();
|
||
}
|
||
|
||
function getSelectedFileIds() {
|
||
const checkboxes = document.querySelectorAll('.file-checkbox:checked');
|
||
return Array.from(checkboxes).map(cb => parseInt(cb.value));
|
||
}
|
||
|
||
function bulkDelete() {
|
||
const fileIds = getSelectedFileIds();
|
||
if (fileIds.length === 0) {
|
||
alert('Please select files to delete');
|
||
return;
|
||
}
|
||
|
||
if (!confirm(`Are you sure you want to delete ${fileIds.length} file(s)?`)) {
|
||
return;
|
||
}
|
||
|
||
fetch('/api/files/bulk-delete', {
|
||
method: 'POST',
|
||
headers: {
|
||
'Content-Type': 'application/json'
|
||
},
|
||
body: JSON.stringify(fileIds)
|
||
})
|
||
.then(response => {
|
||
if (!response.ok) {
|
||
return response.json().then(err => {
|
||
throw new Error(err.detail || 'Failed to delete files');
|
||
});
|
||
}
|
||
return response.json();
|
||
})
|
||
.then(data => {
|
||
alert(data.message);
|
||
window.location.reload();
|
||
})
|
||
.catch(error => {
|
||
console.error('Error:', error);
|
||
alert(`Error deleting files: ${error.message}`);
|
||
});
|
||
}
|
||
|
||
function bulkReprocess() {
|
||
const fileIds = getSelectedFileIds();
|
||
if (fileIds.length === 0) {
|
||
alert('Please select files to reprocess');
|
||
return;
|
||
}
|
||
|
||
if (!confirm(`Are you sure you want to reprocess ${fileIds.length} file(s)?`)) {
|
||
return;
|
||
}
|
||
|
||
fetch('/api/files/bulk-reprocess', {
|
||
method: 'POST',
|
||
headers: {
|
||
'Content-Type': 'application/json'
|
||
},
|
||
body: JSON.stringify(fileIds)
|
||
})
|
||
.then(response => {
|
||
if (!response.ok) {
|
||
return response.json().then(err => {
|
||
throw new Error(err.detail || 'Failed to reprocess files');
|
||
});
|
||
}
|
||
return response.json();
|
||
})
|
||
.then(data => {
|
||
if (data.errors && data.errors.length > 0) {
|
||
const errorMsg = data.errors.map(e => `${e.filename}: ${e.error}`).join('\n');
|
||
alert(`${data.message}\n\nErrors:\n${errorMsg}`);
|
||
} else {
|
||
alert(data.message);
|
||
}
|
||
clearSelection();
|
||
window.location.reload();
|
||
})
|
||
.catch(error => {
|
||
console.error('Error:', error);
|
||
alert(`Error reprocessing files: ${error.message}`);
|
||
});
|
||
}
|
||
|
||
// ===== Drag-and-Drop Upload Functionality =====
|
||
const dropOverlay = document.getElementById('dropOverlay');
|
||
const uploadModal = document.getElementById('uploadModal');
|
||
const uploadStatusMessage = document.getElementById('uploadStatusMessage');
|
||
const uploadProgressContainer = document.getElementById('uploadProgressContainer');
|
||
|
||
let dragCounter = 0; // Track nested drag events
|
||
|
||
// Show overlay when dragging files over the window
|
||
window.addEventListener('dragenter', (e) => {
|
||
e.preventDefault();
|
||
dragCounter++;
|
||
|
||
// Only show overlay if dragging files
|
||
if (e.dataTransfer.types.includes('Files')) {
|
||
dropOverlay.classList.add('active');
|
||
}
|
||
});
|
||
|
||
window.addEventListener('dragleave', (e) => {
|
||
e.preventDefault();
|
||
dragCounter--;
|
||
|
||
if (dragCounter === 0) {
|
||
dropOverlay.classList.remove('active');
|
||
}
|
||
});
|
||
|
||
window.addEventListener('dragover', (e) => {
|
||
e.preventDefault();
|
||
e.dataTransfer.dropEffect = 'copy';
|
||
});
|
||
|
||
window.addEventListener('drop', async (e) => {
|
||
e.preventDefault();
|
||
dragCounter = 0;
|
||
dropOverlay.classList.remove('active');
|
||
|
||
const files = await getFilesFromDataTransfer(e.dataTransfer);
|
||
if (files.length > 0) {
|
||
// Show upload modal
|
||
uploadModal.classList.add('active');
|
||
uploadProgressContainer.innerHTML = '';
|
||
|
||
// Process the dropped files (queue-based, with adaptive throttling)
|
||
processFiles(files, uploadProgressContainer, uploadStatusMessage);
|
||
}
|
||
});
|
||
|
||
// Listen for upload completion event and reload the page to show new files
|
||
window.addEventListener('allUploadsComplete', (e) => {
|
||
// Wait 2 seconds to let users see the success message
|
||
setTimeout(() => {
|
||
window.location.reload();
|
||
}, 2000);
|
||
});
|
||
|
||
function closeUploadModal() {
|
||
uploadModal.classList.remove('active');
|
||
}
|
||
|
||
// ---- Full-Text Search (Meilisearch) ----
|
||
let _searchDebounceTimer = null;
|
||
let _searchCurrentPage = 1;
|
||
|
||
function debounceSearch(value) {
|
||
clearTimeout(_searchDebounceTimer);
|
||
if (!value || value.trim().length < 2) {
|
||
// Only hide the results panel; do NOT clear the input value so the
|
||
// user can continue typing characters until the query is long enough.
|
||
var _p = document.getElementById('search-results-panel');
|
||
if (_p) _p.style.display = 'none';
|
||
return;
|
||
}
|
||
_searchDebounceTimer = setTimeout(() => {
|
||
_searchCurrentPage = 1;
|
||
runFullTextSearch();
|
||
}, 400);
|
||
}
|
||
|
||
function runFullTextSearch(page) {
|
||
const input = document.getElementById('fulltext-search');
|
||
const q = input ? input.value.trim() : '';
|
||
if (!q) { clearFullTextSearch(); return; }
|
||
if (page) _searchCurrentPage = page;
|
||
|
||
const panel = document.getElementById('search-results-panel');
|
||
const list = document.getElementById('search-results-list');
|
||
const summary = document.getElementById('search-results-summary');
|
||
const pagination = document.getElementById('search-results-pagination');
|
||
|
||
list.innerHTML = '<div style="padding: 1rem; color: #6b7280; font-size: 0.875rem;"><i class="fas fa-spinner fa-spin"></i> Searching…</div>';
|
||
summary.textContent = '';
|
||
pagination.innerHTML = '';
|
||
panel.style.display = 'block';
|
||
|
||
const params = new URLSearchParams({ q, page: _searchCurrentPage, per_page: 20 });
|
||
fetch(`/api/search?${params.toString()}`)
|
||
.then(r => {
|
||
if (!r.ok) throw new Error(`Search returned ${r.status}`);
|
||
return r.json();
|
||
})
|
||
.then(data => renderSearchResults(data, q))
|
||
.catch(err => {
|
||
list.innerHTML = `<div style="padding: 1rem; color: #dc2626; font-size: 0.875rem;"><i class="fas fa-exclamation-triangle"></i> Search unavailable: ${err.message}</div>`;
|
||
summary.textContent = '';
|
||
});
|
||
}
|
||
|
||
function renderSearchResults(data, q) {
|
||
const panel = document.getElementById('search-results-panel');
|
||
const list = document.getElementById('search-results-list');
|
||
const summary = document.getElementById('search-results-summary');
|
||
const pagination = document.getElementById('search-results-pagination');
|
||
|
||
const { results, total, page, pages } = data;
|
||
summary.textContent = `${total} result${total !== 1 ? 's' : ''} for "${q}"`;
|
||
|
||
if (!results || results.length === 0) {
|
||
list.innerHTML = '<div style="padding: 1rem; color: #6b7280; font-size: 0.875rem;">No results found.</div>';
|
||
pagination.innerHTML = '';
|
||
return;
|
||
}
|
||
|
||
list.innerHTML = results.map(hit => {
|
||
const fmt = hit._formatted || {};
|
||
const title = fmt.document_title || hit.document_title || hit.original_filename || '(untitled)';
|
||
const filename = fmt.original_filename || hit.original_filename || '';
|
||
const snippet = fmt.ocr_text || '';
|
||
const tags = Array.isArray(hit.tags) ? hit.tags.join(', ') : (hit.tags || '');
|
||
const docType = hit.document_type || '';
|
||
|
||
return `<div style="padding: 0.75rem 1rem; border-bottom: 1px solid #f3f4f6; display: flex; gap: 0.75rem; align-items: flex-start;">
|
||
<div style="flex-shrink: 0; color: #3b82f6; font-size: 1.25rem; padding-top: 0.1rem;">
|
||
<i class="fas fa-file-pdf"></i>
|
||
</div>
|
||
<div style="flex: 1; min-width: 0;">
|
||
<div style="font-weight: 600; font-size: 0.9rem; color: #111827;">${title}</div>
|
||
${filename ? `<div style="font-size: 0.8rem; color: #6b7280; margin-top: 0.15rem;">${filename}</div>` : ''}
|
||
${docType ? `<span style="display: inline-block; margin-top: 0.25rem; padding: 0.1rem 0.5rem; background: #eff6ff; color: #1d4ed8; border-radius: 9999px; font-size: 0.75rem;">${docType}</span>` : ''}
|
||
${tags ? `<span style="display: inline-block; margin-top: 0.25rem; margin-left: 0.25rem; padding: 0.1rem 0.5rem; background: #f0fdf4; color: #15803d; border-radius: 9999px; font-size: 0.75rem;">${tags}</span>` : ''}
|
||
${snippet ? `<div style="margin-top: 0.4rem; font-size: 0.8rem; color: #374151; white-space: pre-wrap; word-break: break-word;">…${snippet}…</div>` : ''}
|
||
</div>
|
||
<div style="flex-shrink: 0;">
|
||
<a href="/files/${hit.file_id}" style="padding: 0.25rem 0.6rem; background: #f3f4f6; color: #374151; border-radius: 0.25rem; font-size: 0.8rem; text-decoration: none; white-space: nowrap;" title="View file">
|
||
<i class="fas fa-external-link-alt"></i>
|
||
</a>
|
||
</div>
|
||
</div>`;
|
||
}).join('');
|
||
|
||
// Pagination
|
||
if (pages > 1) {
|
||
const btns = [];
|
||
if (page > 1) {
|
||
btns.push(`<button onclick="runFullTextSearch(${page - 1})" style="padding: 0.25rem 0.6rem; border: 1px solid #d1d5db; border-radius: 0.25rem; font-size: 0.8rem; cursor: pointer; background: white;">« Prev</button>`);
|
||
}
|
||
btns.push(`<span style="padding: 0.25rem 0.6rem; font-size: 0.8rem; color: #6b7280;">Page ${page} / ${pages}</span>`);
|
||
if (page < pages) {
|
||
btns.push(`<button onclick="runFullTextSearch(${page + 1})" style="padding: 0.25rem 0.6rem; border: 1px solid #d1d5db; border-radius: 0.25rem; font-size: 0.8rem; cursor: pointer; background: white;">Next »</button>`);
|
||
}
|
||
pagination.innerHTML = btns.join('');
|
||
} else {
|
||
pagination.innerHTML = '';
|
||
}
|
||
}
|
||
|
||
function clearFullTextSearch() {
|
||
const panel = document.getElementById('search-results-panel');
|
||
const input = document.getElementById('fulltext-search');
|
||
if (panel) panel.style.display = 'none';
|
||
if (input) input.value = '';
|
||
_searchCurrentPage = 1;
|
||
}
|
||
</script>
|
||
|
||
<!-- Queue banner updater -->
|
||
<script>
|
||
(function () {
|
||
function updateQueueBanner() {
|
||
fetch('/api/queue/pending-count')
|
||
.then(function (r) { return r.ok ? r.json() : null; })
|
||
.then(function (data) {
|
||
if (!data) return;
|
||
var banner = document.getElementById('queueBanner');
|
||
var count = data.total_pending || 0;
|
||
if (count > 0) {
|
||
document.getElementById('queueBannerCount').textContent = count;
|
||
banner.classList.remove('hidden');
|
||
// Show admin link if user is admin (adminMenuContainer visible)
|
||
var adminMenu = document.getElementById('adminMenuContainer');
|
||
if (adminMenu && !adminMenu.classList.contains('hidden')) {
|
||
var link = document.getElementById('queueBannerLink');
|
||
if (link) link.style.display = '';
|
||
}
|
||
} else {
|
||
banner.classList.add('hidden');
|
||
}
|
||
})
|
||
.catch(function () { /* silently ignore */ });
|
||
}
|
||
updateQueueBanner();
|
||
setInterval(updateQueueBanner, 15000);
|
||
})();
|
||
</script>
|
||
</div>
|
||
{% endblock %}
|