diff --git a/js/admin.js b/js/admin.js index 74cc682..b7417ec 100644 --- a/js/admin.js +++ b/js/admin.js @@ -80,6 +80,14 @@ document.addEventListener('DOMContentLoaded', () => { }); function initEventListeners() { + const physicalCheckbox = document.getElementById('admin-physical-checkbox'); + if (physicalCheckbox) { + physicalCheckbox.addEventListener('change', (e) => { + adminPhysicalOnlyFilter = e.target.checked; + currentPage = 1; + renderAdminTable(); + }); + } const filmForm = document.getElementById('film-form'); if (filmForm) filmForm.addEventListener('submit', saveFilmForm); @@ -137,70 +145,117 @@ function getFilteredItems() { return filtered; } -// ── RENDU DU TABLEAU (6 COLONNES) ── -// ── RENDU DU TABLEAU (7 COLONNES ALIGNÉES) ── +// ── RENDU DU TABLEAU (VERSION COMPLÈTE ET CORRIGÉE) ── function renderAdminTable() { const tbody = document.getElementById('admin-table-body'); if (!tbody) return; tbody.innerHTML = ''; + // 1. Récupération des valeurs de filtrage const searchInput = document.getElementById('search-input'); - const currentSearch = searchInput ? searchInput.value.toLowerCase() : ''; + const query = searchInput ? searchInput.value.toLowerCase().trim() : ''; + + const physicalCheckbox = document.getElementById('admin-physical-checkbox'); + const isPhysicalOnly = physicalCheckbox ? physicalCheckbox.checked : false; + // 2. Filtrage des données let filtered = allItems.filter(item => item.type === currentAdminTab); - // FILTRE PHYSIQUE UNIQUEMENT - if (adminPhysicalOnlyFilter) { - filtered = filtered.filter(f => - !f.streaming || - f.streaming === 'Disponible en support physique ou Cinéma' || - f.streaming.trim() === '' + // Filtre support physique / cinéma uniquement + if (isPhysicalOnly) { + filtered = filtered.filter(item => { + const streaming = item.streaming ? item.streaming.trim() : ''; + return !streaming || streaming === 'Disponible en support physique ou Cinéma'; + }); + } + + // Filtre recherche + if (query) { + filtered = filtered.filter(item => + item.title.toLowerCase().includes(query) || + (item.director && item.director.toLowerCase().includes(query)) ); } - - const filtered = getFilteredItems(); + // 3. Mise à jour du compteur const countLabel = document.getElementById('admin-count-label'); - if(countLabel) countLabel.textContent = `${filtered.length} élément(s)`; + if (countLabel) countLabel.textContent = `${filtered.length} élément(s)`; + // 4. Logique de pagination const totalPages = Math.ceil(filtered.length / itemsPerPage) || 1; if (currentPage > totalPages) currentPage = totalPages; - const startIdx = (currentPage - 1) * itemsPerPage; - const pageItems = filtered.slice(startIdx, startIdx + itemsPerPage); + const startIndex = (currentPage - 1) * itemsPerPage; + const pageItems = filtered.slice(startIndex, startIndex + itemsPerPage); - pageItems.forEach(f => { + // 5. Génération des lignes (6 colonnes : Checkbox, Titre, Année, Réalisateur, Info, Actions) + pageItems.forEach(item => { const tr = document.createElement('tr'); - const isChecked = selectedIds.has(String(f.id)) ? 'checked' : ''; + const isChecked = selectedIds.has(String(item.id)) ? 'checked' : ''; + const infoHTML = currentAdminTab === 'critique' + ? `${getStarsHTML(item.rating)}` + : `${item.format || '-'}`; + tr.innerHTML = `