Actualiser js/admin.js

This commit is contained in:
2026-06-20 21:08:20 +02:00
parent b21d911c13
commit ff0aac9644
+15 -48
View File
@@ -90,11 +90,10 @@ function initEventListeners() {
const csvInput = document.getElementById('csv-file'); const csvInput = document.getElementById('csv-file');
if (csvInput) csvInput.addEventListener('change', (e) => handleCsvUpload(e.target)); if (csvInput) csvInput.addEventListener('change', (e) => handleCsvUpload(e.target));
// Ajoutez ceci pour la recherche
const searchInput = document.getElementById('search-input'); const searchInput = document.getElementById('search-input');
if (searchInput) { if (searchInput) {
searchInput.addEventListener('input', (e) => { searchInput.addEventListener('input', () => {
searchQuery = e.target.value;
currentPage = 1;
renderAdminTable(); renderAdminTable();
}); });
} }
@@ -129,61 +128,36 @@ function renderAdminTable() {
if (!tbody) return; if (!tbody) return;
tbody.innerHTML = ''; tbody.innerHTML = '';
// 1. Filtrage par onglet // Récupérer la valeur de recherche
const searchInput = document.getElementById('search-input');
const searchQuery = searchInput ? searchInput.value.toLowerCase() : '';
// Filtrer les éléments
let filtered = allItems.filter(item => item.type === currentAdminTab); let filtered = allItems.filter(item => item.type === currentAdminTab);
// 2. Filtrage par recherche
if (searchQuery) { if (searchQuery) {
const q = searchQuery.toLowerCase();
filtered = filtered.filter(f => filtered = filtered.filter(f =>
f.title.toLowerCase().includes(q) || f.title.toLowerCase().includes(searchQuery) ||
(f.director && f.director.toLowerCase().includes(q)) (f.director && f.director.toLowerCase().includes(searchQuery))
); );
} }
// 3. Mise à jour du compteur
const countLabel = document.getElementById('admin-count-label'); 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 filtered.forEach(f => {
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 => {
const tr = document.createElement('tr'); const tr = document.createElement('tr');
let infoHtml = '';
if (currentAdminTab === 'critique') {
infoHtml = `
<div class="info-cell">
<span class="tbl-stars">${getStarsHTML(f.rating)}</span>
<span class="rating-badge">${parseFloat(f.rating).toFixed(1)}</span>
</div>`;
if (f.streaming && f.streaming !== 'Disponible en support physique ou Cinéma') {
infoHtml += `<span class="streaming-badge" title="${f.streaming}">${f.streaming}</span>`;
} else {
infoHtml += `<span class="physical-badge">🎟️ Cinéma / Physique</span>`;
}
} else {
infoHtml = `<span class="badge-format">${f.format || '-'}</span>`;
if (f.length) infoHtml += `<span style="font-size:0.8rem; color:var(--muted); margin-left:0.4rem;">${f.length}</span>`;
}
tr.innerHTML = ` tr.innerHTML = `
<td> <td style="text-align:center;">
<input type="checkbox" class="film-checkbox" value="${f.id}" onclick="toggleSingleSelect('${f.id}', this)"> <input type="checkbox" class="film-checkbox" value="${f.id}" onclick="updateBulkBar()">
</td> </td>
<td> <td style="text-align:center;">
${f.poster ? `<img src="${f.poster}" class="thumb" alt="Affiche">` : '<div class="thumb-ph"><i class="ti ti-photo"></i></div>'} ${f.poster ? `<img src="${f.poster}" class="thumb" alt="Affiche">` : '<div class="thumb-ph"><i class="ti ti-photo"></i></div>'}
</td> </td>
<td><strong>${f.title}</strong></td> <td><strong>${f.title}</strong></td>
<td>${f.year || '-'}</td> <td>${f.year || '-'}</td>
<td>${f.director || '-'}</td> <td>${f.director || '-'}</td>
<td><div class="info-cell">${infoHtml}</div></td> <td>${currentAdminTab === 'critique' ? `<span class="tbl-stars">${'★'.repeat(f.rating || 0)}</span>` : `<span class="badge-format">${f.format || '-'}</span>`}</td>
<td> <td>
<div class="tbl-actions"> <div class="tbl-actions">
<button onclick="openEditModal('${f.id}')" title="Éditer"><i class="ti ti-edit"></i></button> <button onclick="openEditModal('${f.id}')" title="Éditer"><i class="ti ti-edit"></i></button>
@@ -192,13 +166,6 @@ function renderAdminTable() {
</td>`; </td>`;
tbody.appendChild(tr); tbody.appendChild(tr);
}); });
// Synchronisation checkboxes
document.querySelectorAll('.film-checkbox').forEach(cb => {
cb.checked = selectedIds.has(cb.value);
});
renderPagination(totalPages, filtered.length);
} }
// ── SÉLECTION ─ // ── SÉLECTION ─