Files
MediaCollectorLibary/resources/views/movies/index.twig
Lars Behrends 1b053148f0 xbvr sync
2025-11-14 02:42:44 +01:00

668 lines
38 KiB
Twig

{% extends "layouts/app.twig" %}
{% block nav_controls %}
<!-- Search form -->
<form method="GET" class="flex gap-2">
<input type="hidden" name="view" value="{{ view_mode }}">
<input type="hidden" name="per_page" value="{{ pagination.per_page }}">
{% for genre in filters.genres %}
<input type="hidden" name="genres[]" value="{{ genre }}">
{% endfor %}
{% for director in filters.directors %}
<input type="hidden" name="directors[]" value="{{ director }}">
{% endfor %}
</form>
<!-- Enhanced View mode switcher -->
<div class="flex gap-1 bg-gray-100 rounded-lg p-1" role="group">
{% for mode in view_modes %}
<a
href="?view={{ mode }}{% if search %}&search={{ search }}{% endif %}{% if pagination.per_page != 24 %}&per_page={{ pagination.per_page }}{% endif %}{% for genre in filters.genres %}&genres[]={{ genre }}{% endfor %}{% for director in filters.directors %}&directors[]={{ director }}{% endfor %}"
class="inline-flex items-center px-3 py-2 text-sm font-medium rounded-md transition-all duration-200 {{ view_mode == mode ? 'bg-white text-blue-600 shadow-sm' : 'text-gray-600 hover:text-gray-900 hover:bg-gray-200' }}"
title="{{ mode|title }} View"
>
{% if mode == 'grid' %}
<svg class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2V6zM14 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2V6zM4 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2v-2zM14 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2v-2z"/>
</svg>
{% endif %}
{% if mode == 'list' %}
<svg class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 10h16M4 14h16M4 18h16"/>
</svg>
{% endif %}
{% if mode == 'covers' %}
<svg class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"/>
</svg>
{% endif %}
<span class="hidden sm:inline ml-1">{{ mode|title }}</span>
</a>
{% endfor %}
</div>
<!-- Size slider -->
<div class="flex items-center gap-2 bg-gray-100 rounded-lg px-3 py-2" x-data="{
size: localStorage.getItem('movieCardSize') || 'medium',
sizes: {
small: { label: 'S', cols: 'grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6', scale: 'scale-90' },
medium: { label: 'M', cols: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-6', scale: 'scale-100' },
large: { label: 'L', cols: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4', scale: 'scale-110' },
xlarge: { label: 'XL', cols: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3', scale: 'scale-125' }
},
updateSize(newSize) {
this.size = newSize;
localStorage.setItem('movieCardSize', newSize);
// Dispatch custom event to update grid
window.dispatchEvent(new CustomEvent('movieCardSizeChanged', { detail: { sizeKey: newSize, sizeData: this.sizes[newSize] } }));
}
}" @mounted="updateSize(size)">
<svg class="h-4 w-4 text-gray-600" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5l-5-5m5 5v-4m0 4h-4"/>
</svg>
<span class="text-xs font-medium text-gray-600 hidden sm:inline mr-1">Size:</span>
<div class="flex items-center gap-1">
<template x-for="(sizeData, sizeKey) in sizes" :key="sizeKey">
<button
@click="updateSize(sizeKey)"
:class="size === sizeKey ? 'bg-blue-600 text-white shadow-sm' : 'text-gray-600 hover:text-gray-900 hover:bg-gray-200'"
class="px-2 py-1 text-xs font-medium rounded transition-all duration-200"
:title="'Set card size to ' + sizeKey"
>
<span x-text="sizeData.label"></span>
</button>
</template>
</div>
</div>
<!-- Sort dropdown -->
<div class="relative gap-1 bg-gray-100 rounded-lg p-1" x-data="{ open: false }">
<button @click="open = !open" class="inline-flex items-center px-3 py-2 text-sm font-medium rounded-md transition-all duration-200 {{ view_mode == mode ? 'bg-white text-blue-600 shadow-sm' : 'text-gray-600 hover:text-gray-900 hover:bg-gray-200' }}">
<svg class="mr-1 h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 4h14M3 8h9m-9 4h6m4 0l4-4m0 0l4 4m-4-4v12"/>
</svg>
<span class="hidden sm:inline">Sort</span>
</button>
<div x-show="open" @click.away="open = false" class="absolute right-0 z-50 mt-2 w-56 bg-white rounded-md shadow-lg ring-1 ring-black ring-opacity-5">
<div class="py-1">
{% for key, label in sort_options %}
<a class="flex items-center justify-between px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 {{ sort == key ? 'bg-gray-50' : '' }}"
href="?sort={{ key }}&view={{ view_mode }}{% if search %}&search={{ search }}{% endif %}{% if pagination.per_page != 24 %}&per_page={{ pagination.per_page }}{% endif %}{% for genre in filters.genres %}&genres[]={{ genre }}{% endfor %}{% for director in filters.directors %}&directors[]={{ director }}{% endfor %}">
{{ label }}
{% if sort == key %}
<svg class="h-4 w-4 text-blue-600" fill="currentColor" viewBox="0 0 16 16">
<path d="M12.5 15a.5.5 0 0 1-.5-.5v-13a.5.5 0 0 1 1 0v13a.5.5 0 0 1-.5.5zM10 8a.5.5 0 0 1-.5.5H3.707l2.147 2.146a.5.5 0 0 1-.708.708l-3-3a.5.5 0 0 1 0-.708l3-3a.5.5 0 1 1 .708.708L3.707 7.5H9.5a.5.5 0 0 1 .5.5z"/>
</svg>
{% endif %}
</a>
{% endfor %}
</div>
</div>
</div>
{% endblock %}
{% block item_list %}
{% if view_mode == 'list' and movies %}
<div class="space-y-4">
<!-- Group movies by first letter -->
{% set grouped_movies = {} %}
{% for movie in movies %}
{% set first_letter = movie.title|first|upper %}
{% if grouped_movies[first_letter] is not defined %}
{% set grouped_movies = grouped_movies|merge({(first_letter): []}) %}
{% endif %}
{% set grouped_movies = grouped_movies|merge({(first_letter): grouped_movies[first_letter]|merge([movie])}) %}
{% endfor %}
{% for letter, letter_movies in grouped_movies|sort %}
<div class="space-y-2">
<h4 class="text-sm font-semibold text-gray-900 border-b border-gray-200 pb-1">{{ letter }}</h4>
<div class="space-y-1">
{% for movie in letter_movies %}
<a href="{{ path_for('movies.show', {'id': movie.id}) }}" class="flex items-center p-2 rounded-md hover:bg-gray-100 transition-colors">
{% if movie.poster_url %}
<img class="w-8 h-12 object-cover rounded mr-3 flex-shrink-0" src="/images/{{ movie.poster_url }}" alt="{{ movie.title }}">
{% else %}
<div class="w-8 h-12 bg-gray-200 rounded mr-3 flex-shrink-0 flex items-center justify-center">
<svg class="w-4 h-4 text-gray-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 4V2a1 1 0 011-1h8a1 1 0 011 1v2h4a1 1 0 010 2h-1v14a2 2 0 01-2 2H6a2 2 0 01-2-2V6H3a1 1 0 010-2h4z"/>
</svg>
</div>
{% endif %}
<div class="flex-1 min-w-0">
<div class="text-sm font-medium text-gray-900 truncate">{{ movie.title }}</div>
{% if movie.release_date %}
<div class="text-xs text-gray-500">{{ movie.release_date|date('Y') }}</div>
{% endif %}
</div>
{% if movie.watched %}
<div class="flex-shrink-0 ml-2">
<svg class="w-4 h-4 text-green-600" fill="currentColor" viewBox="0 0 16 16">
<path d="M10.97 4.97a.75.75 0 0 1 1.07 1.05l-3.99 4.99a.75.75 0 0 1-1.08.02L4.324 8.384a.75.75 0 1 1 1.06-1.06l2.094 2.093 3.473-4.425a.267.267 0 0 1 .02-.022z"/>
</svg>
</div>
{% endif %}
</a>
{% endfor %}
</div>
</div>
{% endfor %}
</div>
{% else %}
<div class="space-y-4">
<div class="text-sm text-gray-500 text-center py-8">
No items to display
</div>
</div>
{% endif %}
{% endblock %}
{% block sidebar %}
<div class="space-y-4">
<!-- Filters -->
<div class="bg-gray-50 rounded-lg p-4">
<h3 class="text-sm font-medium text-gray-900 mb-4">Filters</h3>
<!-- Filter form -->
<form method="GET" id="filterForm">
<input type="hidden" name="view" value="{{ view_mode }}">
<input type="hidden" name="per_page" value="{{ pagination.per_page }}">
<input type="hidden" name="search" value="{{ search }}">
<!-- Genre filter -->
{% if available_filters.genres %}
<div class="mb-4">
<label class="block text-xs font-medium text-gray-700 mb-1">Genres</label>
<select class="select2 w-full text-sm border border-gray-300 rounded focus:ring-blue-500 focus:border-blue-500" name="genres[]" multiple data-placeholder="Select genres...">
{% for genre in available_filters.genres %}
<option value="{{ genre }}" {{ genre in filters.genres ? 'selected' : '' }}>
{{ genre }}
</option>
{% endfor %}
</select>
</div>
{% endif %}
<!-- Director filter -->
{% if available_filters.directors %}
<div class="mb-4">
<label class="block text-xs font-medium text-gray-700 mb-1">Directors</label>
<select class="select2 w-full text-sm border border-gray-300 rounded focus:ring-blue-500 focus:border-blue-500" name="directors[]" multiple data-placeholder="Select directors...">
{% for director in available_filters.directors %}
<option value="{{ director }}" {{ director in filters.directors ? 'selected' : '' }}>
{{ director }}
</option>
{% endfor %}
</select>
</div>
{% endif %}
<!-- Filter actions -->
<div class="space-y-2">
<button type="submit" class="w-full bg-blue-600 text-white px-3 py-2 rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 text-sm">
Apply Filters
</button>
<a href="{{ path_for('movies.index') }}" class="w-full bg-gray-100 text-gray-700 px-3 py-2 rounded-md hover:bg-gray-200 focus:outline-none focus:ring-2 focus:ring-gray-500 focus:ring-offset-2 block text-center text-sm">
Clear All
</a>
</div>
</form>
</div>
<!-- Active Filters Summary -->
{% if filters.genres or filters.directors or search %}
<div class="bg-blue-50 rounded-lg p-4">
<h3 class="text-sm font-medium text-gray-900 mb-3">Active Filters</h3>
<div class="space-y-2">
{% if search %}
<div class="flex items-center justify-between">
<span class="text-sm text-gray-600">Search: "{{ search }}"</span>
<a href="?{% for key, value in filters %}{% if key != 'search' %}{{ key }}={{ value }}&{% endif %}{% endfor %}" class="text-blue-600 hover:text-blue-800">
<svg class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
</svg>
</a>
</div>
{% endif %}
{% for genre in filters.genres %}
<div class="flex items-center justify-between">
<span class="text-sm text-gray-600">Genre: {{ genre }}</span>
<a href="?{% for key, value in filters %}{% if key != 'genres' or (key == 'genres' and value != genre) %}{{ key }}={{ value }}&{% endif %}{% endfor %}" class="text-blue-600 hover:text-blue-800">
<svg class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
</svg>
</a>
</div>
{% endfor %}
{% for director in filters.directors %}
<div class="flex items-center justify-between">
<span class="text-sm text-gray-600">Director: {{ director }}</span>
<a href="?{% for key, value in filters %}{% if key != 'directors' or (key == 'directors' and value != director) %}{{ key }}={{ value }}&{% endif %}{% endfor %}" class="text-blue-600 hover:text-blue-800">
<svg class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
</svg>
</a>
</div>
{% endfor %}
</div>
</div>
{% endif %}
<!-- Quick Stats -->
<div class="bg-gray-50 rounded-lg p-4">
<h3 class="text-sm font-medium text-gray-900 mb-3">Quick Stats</h3>
<div class="space-y-2">
<div class="flex justify-between text-sm">
<span class="text-gray-600">Total Movies</span>
<span class="font-medium text-gray-900">{{ pagination.total_items }}</span>
</div>
<div class="flex justify-between text-sm">
<span class="text-gray-600">This Page</span>
<span class="font-medium text-gray-900">{{ movies|length }}</span>
</div>
{% if pagination.total_pages > 1 %}
<div class="flex justify-between text-sm">
<span class="text-gray-600">Page</span>
<span class="font-medium text-gray-900">{{ pagination.current_page }} of {{ pagination.total_pages }}</span>
</div>
{% endif %}
</div>
</div>
</div>
{% endblock %}
{% block content %}
<!-- Main content area -->
<div class="min-h-screen bg-gradient-to-br from-slate-50 via-blue-50 to-indigo-50">
<div class="p-6">
<!-- Header -->
<div class="mb-8">
<div class="flex items-center justify-between">
<div>
<h1 class="text-4xl font-bold bg-gradient-to-r from-slate-900 via-blue-900 to-indigo-900 bg-clip-text text-transparent">Movies Library</h1>
{% if pagination.total_items > 0 %}
<div class="text-slate-600 text-sm mt-2 flex items-center gap-2">
<svg class="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 10l4.553-2.276A1 1 0 0121 8.618v6.764a1 1 0 01-1.447.894L15 14M5 18h8a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v8a2 2 0 002 2z"/>
</svg>
{{ pagination.total_items }} movies from {{ movies|length > 0 ? movies|reduce((carry, movie) => carry + 1, 0) : 0 }} sources
{% if search %}
<span class="inline-flex items-center px-2 py-1 rounded-full text-xs font-medium bg-blue-100 text-blue-800">
<svg class="w-3 h-3 mr-1" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"/>
</svg>
"{{ search }}"
</span>
{% endif %}
</div>
{% endif %}
</div>
{% if pagination.total_items > 0 %}
<div class="flex flex-wrap gap-2">
{% if filters.genres %}
<span class="inline-flex items-center px-3 py-1 rounded-full text-xs font-medium bg-gradient-to-r from-blue-500 to-blue-600 text-white shadow-sm">
<svg class="w-3 h-3 mr-1" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a.997.997 0 01-1.414 0l-7-7A1.994 1.994 0 013 12V7a4 4 0 014-4z"/>
</svg>
{{ filters.genres|join(', ') }}
</span>
{% endif %}
{% if filters.directors %}
<span class="inline-flex items-center px-3 py-1 rounded-full text-xs font-medium bg-gradient-to-r from-purple-500 to-purple-600 text-white shadow-sm">
<svg class="w-3 h-3 mr-1" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"/>
</svg>
{{ filters.directors|join(', ') }}
</span>
{% endif %}
</div>
{% endif %}
</div>
</div>
{% if movies is empty %}
<!-- Enhanced empty state -->
<div class="flex flex-col items-center justify-center py-16 px-4">
<div class="relative mb-8">
<!-- Animated background circles -->
<div class="absolute inset-0 flex items-center justify-center">
<div class="w-32 h-32 bg-gradient-to-br from-blue-100 to-indigo-100 rounded-full animate-pulse"></div>
<div class="absolute w-24 h-24 bg-gradient-to-br from-indigo-100 to-purple-100 rounded-full animate-pulse animation-delay-1000"></div>
<div class="absolute w-16 h-16 bg-gradient-to-br from-purple-100 to-pink-100 rounded-full animate-pulse animation-delay-2000"></div>
</div>
<!-- Main icon -->
<div class="relative bg-white rounded-2xl shadow-xl p-8 border border-gray-100">
<svg class="w-20 h-20 text-slate-400 mx-auto" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M15 10l4.553-2.276A1 1 0 0121 8.618v6.764a1 1 0 01-1.447.894L15 14M5 18h8a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v8a2 2 0 002 2z"/>
</svg>
</div>
</div>
<div class="text-center max-w-md">
<h3 class="text-2xl font-bold text-gray-900 mb-3">
{% if search or filters.genres or filters.directors %}
No movies found
{% else %}
Your library is empty
{% endif %}
</h3>
<p class="text-slate-600 text-lg mb-8 leading-relaxed">
{% if search or filters.genres or filters.directors %}
We couldn't find any movies matching your current search and filter criteria. Try adjusting your filters or search terms to discover more movies.
{% else %}
Start building your movie library by syncing with Jellyfin, Plex, or other media sources. Your movies will appear here once synced.
{% endif %}
</p>
<div class="flex flex-col sm:flex-row gap-4 justify-center">
{% if search or filters.genres or filters.directors %}
<a href="{{ path_for('movies.index') }}"
class="inline-flex items-center px-6 py-3 bg-gradient-to-r from-blue-600 to-blue-700 text-white font-semibold rounded-xl hover:from-blue-700 hover:to-blue-800 transition-all duration-200 shadow-lg hover:shadow-xl transform hover:-translate-y-0.5">
<svg class="w-5 h-5 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"/>
</svg>
Clear Filters
</a>
{% else %}
<a href="{{ path_for('admin.index') }}"
class="inline-flex items-center px-6 py-3 bg-gradient-to-r from-indigo-600 to-purple-600 text-white font-semibold rounded-xl hover:from-indigo-700 hover:to-purple-700 transition-all duration-200 shadow-lg hover:shadow-xl transform hover:-translate-y-0.5">
<svg class="w-5 h-5 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"/>
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/>
</svg>
Setup Sync
</a>
{% endif %}
<a href="{{ path_for('search.index') }}"
class="inline-flex items-center px-6 py-3 bg-white text-gray-700 font-semibold rounded-xl border-2 border-gray-200 hover:border-gray-300 hover:bg-gray-50 transition-all duration-200 shadow-sm hover:shadow-md">
<svg class="w-5 h-5 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"/>
</svg>
Search All Media
</a>
</div>
<!-- Additional help text -->
{% if not (search or filters.genres or filters.directors) %}
<div class="mt-8 p-4 bg-blue-50 rounded-lg border border-blue-200">
<div class="flex items-start">
<svg class="w-5 h-5 text-blue-600 mt-0.5 mr-3 flex-shrink-0" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>
</svg>
<div class="text-left">
<p class="text-sm font-medium text-blue-900 mb-1">Need help getting started?</p>
<p class="text-sm text-blue-700">Check out the Jellyfin or Plex integration documentation for assistance with syncing your movie libraries.</p>
</div>
</div>
</div>
{% endif %}
</div>
</div>
{% else %}
<!-- Movies content based on view mode -->
{% if view_mode == 'list' %}
<!-- Enhanced list view using component -->
<div class="bg-white rounded-xl shadow-lg border border-gray-100 overflow-hidden">
<ul class="divide-y divide-gray-100">
{% for movie in movies %}
{% include 'components/movie-card.twig' with {'movie': movie, 'view_mode': 'list'} %}
{% endfor %}
</ul>
</div>
{% elseif view_mode == 'covers' %}
<!-- Enhanced cover grid view using component with dynamic sizing -->
<div
class="grid gap-6 transition-all duration-300"
x-data="{
currentSize: localStorage.getItem('movieCardSize') || 'medium',
sizeClasses: {
small: 'grid-cols-3 sm:grid-cols-4 md:grid-cols-5 lg:grid-cols-6 xl:grid-cols-8',
medium: 'grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6',
large: 'grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5',
xlarge: 'grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4'
}
}"
:class="sizeClasses[currentSize]"
x-init="
window.addEventListener('movieCardSizeChanged', (e) => {
currentSize = e.detail.sizeKey;
});
// Set initial class
$el.classList.add(...sizeClasses[currentSize].split(' '));
"
>
{% for movie in movies %}
{% include 'components/movie-card.twig' with {'movie': movie, 'view_mode': 'covers'} %}
{% endfor %}
</div>
{% else %}
<!-- Enhanced grid view using component with dynamic sizing -->
<div
class="grid gap-6 transition-all duration-300"
x-data="{
currentSize: localStorage.getItem('movieCardSize') || 'medium',
sizeClasses: {
small: 'grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6',
medium: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-6',
large: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4',
xlarge: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3'
}
}"
:class="sizeClasses[currentSize]"
x-init="
window.addEventListener('movieCardSizeChanged', (e) => {
currentSize = e.detail.sizeKey;
});
// Set initial class
$el.classList.add(...sizeClasses[currentSize].split(' '));
"
>
{% for movie in movies %}
{% include 'components/movie-card.twig' with {'movie': movie, 'view_mode': 'grid'} %}
{% endfor %}
</div>
{% endif %}
<!-- Top Pagination & Controls -->
{% if pagination.total_pages > 1 %}
<div class="flex items-center justify-between mb-6 p-4 bg-gray-50 rounded-lg">
<div class="flex items-center gap-4">
<div class="text-sm text-gray-700">
Showing {{ (pagination.current_page - 1) * pagination.per_page + 1 }} to {{ min(pagination.current_page * pagination.per_page, pagination.total_items) }} of {{ pagination.total_items }} movies
</div>
<div class="flex items-center gap-2">
<label for="per_page_top" class="text-sm font-medium text-gray-700">Show:</label>
<select id="per_page_top" class="text-sm border border-gray-300 rounded px-2 py-1 focus:ring-blue-500 focus:border-blue-500">
<option value="12" {{ pagination.per_page == 12 ? 'selected' : '' }}>12</option>
<option value="24" {{ pagination.per_page == 24 ? 'selected' : '' }}>24</option>
<option value="48" {{ pagination.per_page == 48 ? 'selected' : '' }}>48</option>
<option value="100" {{ pagination.per_page == 100 ? 'selected' : '' }}>100</option>
</select>
<span class="text-sm text-gray-600">per page</span>
</div>
</div>
<div class="flex items-center space-x-2">
<!-- Previous Button -->
{% if pagination.has_prev %}
<a href="?page={{ pagination.prev_page }}{% if search %}&search={{ search }}{% endif %}{% if pagination.per_page != 24 %}&per_page={{ pagination.per_page }}{% endif %}&view={{ view_mode }}{% for genre in filters.genres %}&genres[]={{ genre }}{% endfor %}{% for director in filters.directors %}&directors[]={{ director }}{% endfor %}"
class="px-3 py-2 text-sm font-medium text-gray-500 bg-white border border-gray-300 rounded-lg hover:bg-gray-50 hover:text-gray-700 transition-colors flex items-center">
<svg class="w-4 h-4 mr-1" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"/>
</svg>
Previous
</a>
{% else %}
<span class="px-3 py-2 text-sm font-medium text-gray-300 bg-gray-100 border border-gray-200 rounded-lg cursor-not-allowed flex items-center">
<svg class="w-4 h-4 mr-1" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"/>
</svg>
Previous
</span>
{% endif %}
<!-- Page Numbers -->
{% set start_page = max(1, pagination.current_page - 2) %}
{% set end_page = min(pagination.total_pages, pagination.current_page + 2) %}
{% if start_page > 1 %}
<a href="?page=1{% if search %}&search={{ search }}{% endif %}{% if pagination.per_page != 24 %}&per_page={{ pagination.per_page }}{% endif %}&view={{ view_mode }}{% for genre in filters.genres %}&genres[]={{ genre }}{% endfor %}{% for director in filters.directors %}&directors[]={{ director }}{% endfor %}"
class="px-3 py-2 text-sm font-medium text-gray-500 bg-white border border-gray-300 rounded-lg hover:bg-gray-50 hover:text-gray-700 transition-colors">1</a>
{% if start_page > 2 %}
<span class="px-2 py-2 text-sm font-medium text-gray-500">...</span>
{% endif %}
{% endif %}
{% for page_num in start_page..end_page %}
{% if page_num == pagination.current_page %}
<span class="px-3 py-2 text-sm font-medium text-white bg-blue-600 border border-blue-600 rounded-lg">{{ page_num }}</span>
{% else %}
<a href="?page={{ page_num }}{% if search %}&search={{ search }}{% endif %}{% if pagination.per_page != 24 %}&per_page={{ pagination.per_page }}{% endif %}&view={{ view_mode }}{% for genre in filters.genres %}&genres[]={{ genre }}{% endfor %}{% for director in filters.directors %}&directors[]={{ director }}{% endfor %}"
class="px-3 py-2 text-sm font-medium text-gray-500 bg-white border border-gray-300 rounded-lg hover:bg-gray-50 hover:text-gray-700 transition-colors">{{ page_num }}</a>
{% endif %}
{% endfor %}
{% if end_page < pagination.total_pages %}
{% if end_page < pagination.total_pages - 1 %}
<span class="px-2 py-2 text-sm font-medium text-gray-500">...</span>
{% endif %}
<a href="?page={{ pagination.total_pages }}{% if search %}&search={{ search }}{% endif %}{% if pagination.per_page != 24 %}&per_page={{ pagination.per_page }}{% endif %}&view={{ view_mode }}{% for genre in filters.genres %}&genres[]={{ genre }}{% endfor %}{% for director in filters.directors %}&directors[]={{ director }}{% endfor %}"
class="px-3 py-2 text-sm font-medium text-gray-500 bg-white border border-gray-300 rounded-lg hover:bg-gray-50 hover:text-gray-700 transition-colors">{{ pagination.total_pages }}</a>
{% endif %}
<!-- Next Button -->
{% if pagination.has_next %}
<a href="?page={{ pagination.next_page }}{% if search %}&search={{ search }}{% endif %}{% if pagination.per_page != 24 %}&per_page={{ pagination.per_page }}{% endif %}&view={{ view_mode }}{% for genre in filters.genres %}&genres[]={{ genre }}{% endfor %}{% for director in filters.directors %}&directors[]={{ director }}{% endfor %}"
class="px-3 py-2 text-sm font-medium text-gray-500 bg-white border border-gray-300 rounded-lg hover:bg-gray-50 hover:text-gray-700 transition-colors flex items-center">
Next
<svg class="w-4 h-4 ml-1" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"/>
</svg>
</a>
{% else %}
<span class="px-3 py-2 text-sm font-medium text-gray-300 bg-gray-100 border border-gray-200 rounded-lg cursor-not-allowed flex items-center">
Next
<svg class="w-4 h-4 ml-1" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"/>
</svg>
</span>
{% endif %}
</div>
</div>
{% endif %}
{% endif %}
</div>
</div>
</div>
</div>
<style>
/* Sort dropdown styles */
.dropdown-menu {
min-width: 250px;
max-height: 400px;
overflow-y: auto;
}
.dropdown-item {
padding: 0.5rem 1.25rem;
white-space: normal;
line-height: 1.4;
}
.dropdown-item svg {
margin-top: 0.15rem;
}
/* Make sure the dropdown works on mobile */
@media (max-width: 575.98px) {
.dropdown-menu {
position: fixed !important;
top: auto !important;
left: 1rem !important;
right: 1rem !important;
width: auto !important;
margin-top: 0.5rem;
max-height: 70vh;
transform: none !important;
}
.dropdown-menu-end {
right: 1rem !important;
left: 1rem !important;
}
}
/* View mode buttons */
.btn-group .btn {
display: flex;
align-items: center;
justify-content: center;
padding: 0.375rem 0.75rem;
}
/* Custom styles for Select2 integration */
.select2-container {
z-index: 1050; /* Ensure Select2 dropdown appears above other elements */
}
.select2-selection {
min-height: 38px;
}
.select2-selection__choice {
background-color: #0d6efd !important;
border: none !important;
color: white !important;
}
.select2-selection__choice__remove {
color: white !important;
margin-right: 5px;
}
.select2-selection__choice__remove:hover {
color: #f8f9fa !important;
}
</style>
<script>
$(document).ready(function() {
// Initialize Select2 for all select2 elements
$('.select2').select2({
width: '100%',
allowClear: true,
placeholder: function() {
return $(this).data('placeholder');
}
});
// Auto-submit filter form when Select2 selection changes
$('.select2').on('change', function() {
document.getElementById('filterForm').submit();
});
});
document.getElementById('per_page')?.addEventListener('change', function() {
const url = new URL(window.location);
url.searchParams.set('per_page', this.value);
url.searchParams.set('page', '1'); // Reset to first page
window.location = url.toString();
});
document.getElementById('per_page_top')?.addEventListener('change', function() {
const url = new URL(window.location);
url.searchParams.set('per_page', this.value);
url.searchParams.set('page', '1'); // Reset to first page
window.location = url.toString();
});
</script>
{% endblock %}