feat: file search, type/tag filters, and pagination
Sync from dev: tsvector search, type/tag filters, pagination, dropdown folder picker. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
{% extends "base.html" %}
|
||||
{% block content %}
|
||||
<div class="page-header">
|
||||
<h1 class="page-title">Files<span class="page-count">{{ items|length }}</span></h1>
|
||||
<h1 class="page-title">Files<span class="page-count">{{ total_files }}</span></h1>
|
||||
<div class="flex gap-2">
|
||||
<form action="/files/sync" method="post" style="display:inline">
|
||||
<button type="submit" class="btn btn-secondary">Sync Files</button>
|
||||
@@ -16,18 +16,51 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div style="display: flex; align-items: center; gap: 8px; margin-bottom: 16px;">
|
||||
<label style="color: var(--muted); font-size: 0.85rem; white-space: nowrap;">Folder:</label>
|
||||
<select class="form-input" style="max-width: 280px; padding: 6px 10px; font-size: 0.85rem;" onchange="window.location.href=this.value">
|
||||
<option value="/files" {{ 'selected' if current_folder is none }}>All folders</option>
|
||||
<option value="/files?folder=" {{ 'selected' if current_folder is not none and current_folder == '' }}>/ (root)</option>
|
||||
<form class="filters-bar" method="get" action="/files" style="display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 16px;">
|
||||
<input type="text" name="q" value="{{ current_q }}" class="form-input" placeholder="Search files..." style="max-width: 220px; padding: 6px 10px; font-size: 0.85rem;">
|
||||
|
||||
<select name="folder" class="form-input" style="max-width: 200px; padding: 6px 10px; font-size: 0.85rem;" onchange="this.form.submit()">
|
||||
<option value="" {{ 'selected' if current_folder is none }}>All folders</option>
|
||||
<option value=" " {{ 'selected' if current_folder is not none and current_folder == '' }}>/ (root)</option>
|
||||
{% for f in folders %}
|
||||
<option value="/files?folder={{ f }}" {{ 'selected' if current_folder == f }}>{% if '/' in f %} {{ f.split('/')[-1] }}{% else %}{{ f }}{% endif %}</option>
|
||||
<option value="{{ f }}" {{ 'selected' if current_folder == f }}>{% if '/' in f %} {{ f.split('/')[-1] }}{% else %}{{ f }}{% endif %}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
{% set sort_base = '/files?' ~ ('folder=' ~ current_folder ~ '&' if current_folder is not none else '') %}
|
||||
<select name="file_type" class="form-input" style="max-width: 160px; padding: 6px 10px; font-size: 0.85rem;" onchange="this.form.submit()">
|
||||
<option value="">All types</option>
|
||||
<option value="image" {{ 'selected' if current_type == 'image' }}>Images</option>
|
||||
<option value="document" {{ 'selected' if current_type == 'document' }}>Documents</option>
|
||||
<option value="text" {{ 'selected' if current_type == 'text' }}>Text</option>
|
||||
<option value="spreadsheet" {{ 'selected' if current_type == 'spreadsheet' }}>Spreadsheets</option>
|
||||
<option value="archive" {{ 'selected' if current_type == 'archive' }}>Archives</option>
|
||||
</select>
|
||||
|
||||
{% if all_tags %}
|
||||
<select name="tag" class="form-input" style="max-width: 160px; padding: 6px 10px; font-size: 0.85rem;" onchange="this.form.submit()">
|
||||
<option value="">All tags</option>
|
||||
{% for t in all_tags %}
|
||||
<option value="{{ t }}" {{ 'selected' if current_tag == t }}>{{ t }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
{% endif %}
|
||||
|
||||
{% if current_q or current_type or current_tag or current_folder is not none %}
|
||||
<input type="hidden" name="sort" value="{{ current_sort }}">
|
||||
<button type="submit" class="btn btn-primary btn-xs">Search</button>
|
||||
<a href="/files" class="btn btn-ghost btn-xs">Clear</a>
|
||||
{% else %}
|
||||
<button type="submit" class="btn btn-primary btn-xs">Search</button>
|
||||
{% endif %}
|
||||
</form>
|
||||
|
||||
{% set qp = [] %}
|
||||
{% if current_folder is not none %}{% if current_folder == '' %}{{ qp.append('folder= ') or '' }}{% else %}{{ qp.append('folder=' ~ current_folder) or '' }}{% endif %}{% endif %}
|
||||
{% if current_q %}{{ qp.append('q=' ~ current_q) or '' }}{% endif %}
|
||||
{% if current_type %}{{ qp.append('file_type=' ~ current_type) or '' }}{% endif %}
|
||||
{% if current_tag %}{{ qp.append('tag=' ~ current_tag) or '' }}{% endif %}
|
||||
{% set filter_qs = qp | join('&') %}
|
||||
{% set sort_base = '/files?' ~ (filter_qs ~ '&' if filter_qs else '') %}
|
||||
|
||||
{% if items %}
|
||||
<div class="card" style="overflow-x: auto;">
|
||||
@@ -81,11 +114,42 @@
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
{% if total_pages > 1 %}
|
||||
{% set page_base = sort_base ~ 'sort=' ~ current_sort ~ '&' %}
|
||||
<div style="display: flex; justify-content: center; align-items: center; gap: 8px; margin-top: 16px;">
|
||||
{% if current_page > 1 %}
|
||||
<a href="{{ page_base }}page={{ current_page - 1 }}" class="btn btn-ghost btn-xs">Prev</a>
|
||||
{% endif %}
|
||||
|
||||
{% for p in range(1, total_pages + 1) %}
|
||||
{% if p == current_page %}
|
||||
<span class="btn btn-primary btn-xs" style="pointer-events: none;">{{ p }}</span>
|
||||
{% elif p <= 3 or p >= total_pages - 2 or (p >= current_page - 1 and p <= current_page + 1) %}
|
||||
<a href="{{ page_base }}page={{ p }}" class="btn btn-ghost btn-xs">{{ p }}</a>
|
||||
{% elif p == 4 and current_page > 5 %}
|
||||
<span style="color: var(--muted);">...</span>
|
||||
{% elif p == total_pages - 3 and current_page < total_pages - 4 %}
|
||||
<span style="color: var(--muted);">...</span>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
{% if current_page < total_pages %}
|
||||
<a href="{{ page_base }}page={{ current_page + 1 }}" class="btn btn-ghost btn-xs">Next</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% else %}
|
||||
<div class="empty-state">
|
||||
<div class="empty-state-icon">📁</div>
|
||||
{% if current_q or current_type or current_tag %}
|
||||
<div class="empty-state-text">No files match your filters</div>
|
||||
<a href="/files" class="btn btn-secondary">Clear Filters</a>
|
||||
{% else %}
|
||||
<div class="empty-state-text">No files{{ ' in this folder' if current_folder is not none else ' uploaded yet' }}</div>
|
||||
<a href="/files/upload" class="btn btn-primary">Upload First File</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user