diff --git a/js/admin.js b/js/admin.js index 5b12ecf..52370e0 100644 --- a/js/admin.js +++ b/js/admin.js @@ -90,11 +90,10 @@ function initEventListeners() { const csvInput = document.getElementById('csv-file'); if (csvInput) csvInput.addEventListener('change', (e) => handleCsvUpload(e.target)); + // Ajoutez ceci pour la recherche const searchInput = document.getElementById('search-input'); if (searchInput) { - searchInput.addEventListener('input', (e) => { - searchQuery = e.target.value; - currentPage = 1; + searchInput.addEventListener('input', () => { renderAdminTable(); }); } @@ -128,62 +127,37 @@ function renderAdminTable() { const tbody = document.getElementById('admin-table-body'); if (!tbody) return; tbody.innerHTML = ''; + + // Récupérer la valeur de recherche + const searchInput = document.getElementById('search-input'); + const searchQuery = searchInput ? searchInput.value.toLowerCase() : ''; - // 1. Filtrage par onglet + // Filtrer les éléments let filtered = allItems.filter(item => item.type === currentAdminTab); - // 2. Filtrage par recherche if (searchQuery) { - const q = searchQuery.toLowerCase(); filtered = filtered.filter(f => - f.title.toLowerCase().includes(q) || - (f.director && f.director.toLowerCase().includes(q)) + f.title.toLowerCase().includes(searchQuery) || + (f.director && f.director.toLowerCase().includes(searchQuery)) ); } - // 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. 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); - - // 5. Rendu - pageItems.forEach(f => { + filtered.forEach(f => { const tr = document.createElement('tr'); - - let infoHtml = ''; - if (currentAdminTab === 'critique') { - infoHtml = ` -
- ${getStarsHTML(f.rating)} - ${parseFloat(f.rating).toFixed(1)} -
`; - - if (f.streaming && f.streaming !== 'Disponible en support physique ou Cinéma') { - infoHtml += `${f.streaming}`; - } else { - infoHtml += `🎟️ Cinéma / Physique`; - } - } else { - infoHtml = `${f.format || '-'}`; - if (f.length) infoHtml += `${f.length}`; - } - tr.innerHTML = ` - - + + - + ${f.poster ? `Affiche` : '
'} ${f.title} ${f.year || '-'} ${f.director || '-'} -
${infoHtml}
+ ${currentAdminTab === 'critique' ? `${'★'.repeat(f.rating || 0)}` : `${f.format || '-'}`}
@@ -192,13 +166,6 @@ function renderAdminTable() { `; tbody.appendChild(tr); }); - - // Synchronisation checkboxes - document.querySelectorAll('.film-checkbox').forEach(cb => { - cb.checked = selectedIds.has(cb.value); - }); - - renderPagination(totalPages, filtered.length); } // ── SÉLECTION ─