2025-05-24 14:35:35 +02:00

192 lines
8.3 KiB
HTML

{% extends "base.html" %}
{% block title %}Images - SEREACT Web Client{% endblock %}
{% block content %}
<div class="d-flex justify-content-between align-items-center mb-4">
<h2><i class="fas fa-images"></i> Images</h2>
<a href="{{ url_for('upload_image') }}" class="btn btn-primary">
<i class="fas fa-upload"></i> Upload Image
</a>
</div>
<!-- Filter Form -->
<div class="card mb-4">
<div class="card-body">
<form method="GET" class="row g-3">
<div class="col-md-8">
<label for="tags" class="form-label">Filter by Tags</label>
<input type="text" class="form-control" id="tags" name="tags"
value="{{ request.args.get('tags', '') }}"
placeholder="Enter tags separated by commas">
</div>
<div class="col-md-4 d-flex align-items-end">
<button type="submit" class="btn btn-outline-primary me-2">
<i class="fas fa-filter"></i> Filter
</button>
<a href="{{ url_for('images') }}" class="btn btn-outline-secondary">
<i class="fas fa-times"></i> Clear
</a>
</div>
</form>
</div>
</div>
{% if images %}
<!-- Images Grid -->
<div class="row">
{% for image in images %}
<div class="col-md-6 col-lg-4 col-xl-3 mb-4">
<div class="card h-100">
<div class="card-img-top bg-light d-flex align-items-center justify-content-center" style="height: 200px;">
<img src="{{ get_api_base_url() }}/api/v1/images/{{ image.id }}/download"
alt="{{ image.filename }}"
class="image-thumbnail"
onerror="this.src='data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjAwIiBoZWlnaHQ9IjIwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cmVjdCB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIiBmaWxsPSIjZGRkIi8+PHRleHQgeD0iNTAlIiB5PSI1MCUiIGZvbnQtZmFtaWx5PSJBcmlhbCIgZm9udC1zaXplPSIxNCIgZmlsbD0iIzk5OSIgdGV4dC1hbmNob3I9Im1pZGRsZSIgZHk9Ii4zZW0iPkltYWdlIE5vdCBGb3VuZDwvdGV4dD48L3N2Zz4='">
</div>
<div class="card-body">
<h6 class="card-title text-truncate" title="{{ image.filename }}">
{{ image.filename }}
</h6>
<p class="card-text small text-muted">
{{ image.description or 'No description' }}
</p>
<div class="small text-muted">
<div><i class="fas fa-weight"></i> {{ (image.file_size / 1024 / 1024) | round(2) }} MB</div>
<div><i class="fas fa-calendar"></i> {{ image.upload_date.strftime('%Y-%m-%d') if image.upload_date else 'Unknown' }}</div>
{% if image.tags %}
<div class="mt-2">
{% for tag in image.tags %}
<span class="badge bg-secondary me-1">{{ tag }}</span>
{% endfor %}
</div>
{% endif %}
{% if image.has_embedding %}
<div class="mt-1">
<span class="badge bg-success">
<i class="fas fa-brain"></i> AI Ready
</span>
</div>
{% endif %}
</div>
</div>
<div class="card-footer bg-transparent">
<div class="btn-group w-100" role="group">
<a href="{{ url_for('view_image', image_id=image.id) }}" class="btn btn-outline-primary btn-sm">
<i class="fas fa-eye"></i> View
</a>
<a href="{{ url_for('edit_image', image_id=image.id) }}" class="btn btn-outline-secondary btn-sm">
<i class="fas fa-edit"></i> Edit
</a>
<button type="button" class="btn btn-outline-danger btn-sm"
onclick="confirmDelete('{{ image.filename }}', '{{ url_for('delete_image', image_id=image.id) }}')">
<i class="fas fa-trash"></i>
</button>
</div>
</div>
</div>
</div>
{% endfor %}
</div>
<!-- Pagination -->
{% if total > limit %}
<nav aria-label="Image pagination">
<ul class="pagination justify-content-center">
{% set total_pages = (total / limit) | round(0, 'ceil') | int %}
{% set current_page = page %}
<!-- Previous Page -->
{% if current_page > 1 %}
<li class="page-item">
<a class="page-link" href="{{ url_for('images', page=current_page-1, tags=request.args.get('tags', '')) }}">
<i class="fas fa-chevron-left"></i> Previous
</a>
</li>
{% endif %}
<!-- Page Numbers -->
{% for page_num in range(1, total_pages + 1) %}
{% if page_num == current_page %}
<li class="page-item active">
<span class="page-link">{{ page_num }}</span>
</li>
{% elif page_num <= 3 or page_num > total_pages - 3 or (page_num >= current_page - 1 and page_num <= current_page + 1) %}
<li class="page-item">
<a class="page-link" href="{{ url_for('images', page=page_num, tags=request.args.get('tags', '')) }}">{{ page_num }}</a>
</li>
{% elif page_num == 4 or page_num == total_pages - 3 %}
<li class="page-item disabled">
<span class="page-link">...</span>
</li>
{% endif %}
{% endfor %}
<!-- Next Page -->
{% if current_page < total_pages %}
<li class="page-item">
<a class="page-link" href="{{ url_for('images', page=current_page+1, tags=request.args.get('tags', '')) }}">
Next <i class="fas fa-chevron-right"></i>
</a>
</li>
{% endif %}
</ul>
</nav>
<div class="text-center text-muted">
Showing {{ ((page - 1) * limit + 1) }} to {{ [page * limit, total] | min }} of {{ total }} images
</div>
{% endif %}
{% else %}
<div class="text-center py-5">
<i class="fas fa-images fa-4x text-muted mb-3"></i>
<h4 class="text-muted">No Images Found</h4>
<p class="text-muted">Upload your first image to get started.</p>
<a href="{{ url_for('upload_image') }}" class="btn btn-primary">
<i class="fas fa-upload"></i> Upload First Image
</a>
</div>
{% endif %}
<!-- Delete Confirmation Modal -->
<div class="modal fade" id="deleteModal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">
<i class="fas fa-exclamation-triangle text-warning"></i> Confirm Delete
</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<p>Are you sure you want to delete the image "<span id="deleteImageName"></span>"?</p>
<div class="alert alert-warning" role="alert">
<i class="fas fa-exclamation-triangle"></i>
<strong>Warning:</strong> This action cannot be undone. The image will be permanently removed from storage.
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
<i class="fas fa-times"></i> Cancel
</button>
<form id="deleteForm" method="POST" style="display: inline;">
<button type="submit" class="btn btn-danger">
<i class="fas fa-trash"></i> Delete Image
</button>
</form>
</div>
</div>
</div>
</div>
{% endblock %}
{% block scripts %}
<script>
function confirmDelete(imageName, deleteUrl) {
document.getElementById('deleteImageName').textContent = imageName;
document.getElementById('deleteForm').action = deleteUrl;
new bootstrap.Modal(document.getElementById('deleteModal')).show();
}
</script>
{% endblock %}