Actualiser js/admin.js

This commit is contained in:
2026-06-19 15:36:43 +02:00
parent 10ecc7a87d
commit 2876e227c0
+20 -21
View File
@@ -65,7 +65,7 @@ function renderAdminTable() {
if (!tbody) return; if (!tbody) return;
tbody.innerHTML = ''; tbody.innerHTML = '';
// 1. Filtrage par onglet et recherche // 1. Filtrage
let filtered = allItems.filter(item => item.type === currentAdminTab); let filtered = allItems.filter(item => item.type === currentAdminTab);
if (searchQuery) { if (searchQuery) {
const q = searchQuery.toLowerCase(); const q = searchQuery.toLowerCase();
@@ -78,24 +78,31 @@ function renderAdminTable() {
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)`;
// 2. Gestion de la pagination // 2. Pagination
const totalPages = Math.ceil(filtered.length / itemsPerPage) || 1; const totalPages = Math.ceil(filtered.length / itemsPerPage) || 1;
if (currentPage > totalPages) currentPage = totalPages; if (currentPage > totalPages) currentPage = totalPages;
const startIdx = (currentPage - 1) * itemsPerPage; const startIdx = (currentPage - 1) * itemsPerPage;
const pageItems = filtered.slice(startIdx, startIdx + itemsPerPage); const pageItems = filtered.slice(startIdx, startIdx + itemsPerPage);
// 3. Rendu des lignes // 3. Rendu — 7 cellules pour correspondre aux 7 <th>
pageItems.forEach(f => { pageItems.forEach(f => {
const tr = document.createElement('tr'); const tr = document.createElement('tr');
let infoHtml = ''; let infoHtml = '';
if (currentAdminTab === 'critique') { if (currentAdminTab === 'critique') {
const rating = Math.round(f.rating || 0); // 🌟 Gestion précise des notes Letterboxd (0.5 à 5)
const stars = '★'.repeat(rating) + '☆'.repeat(5 - rating); const rating = parseFloat(f.rating) || 0;
infoHtml = `<span class="tbl-stars">${stars}</span>`; const fullStars = Math.floor(rating); // partie entière
const emptyStars = 5 - Math.ceil(rating); // étoiles vides
const stars = '★'.repeat(fullStars) + '☆'.repeat(emptyStars);
// Affichage Streaming ou Physique infoHtml = `
<div style="display:flex; align-items:center; gap:0.6rem; flex-wrap:wrap;">
<span class="tbl-stars" style="font-size:1.05rem;">${stars}</span>
<span class="rating-badge">${rating.toFixed(1)}</span>
</div>`;
// Badge streaming
if (f.streaming && f.streaming !== 'Disponible en support physique ou Cinéma') { if (f.streaming && f.streaming !== 'Disponible en support physique ou Cinéma') {
infoHtml += `<span class="streaming-badge" title="${f.streaming}">${f.streaming}</span>`; infoHtml += `<span class="streaming-badge" title="${f.streaming}">${f.streaming}</span>`;
} else { } else {
@@ -103,9 +110,10 @@ function renderAdminTable() {
} }
} else { } else {
infoHtml = `<span class="badge-format">${f.format || '-'}</span>`; infoHtml = `<span class="badge-format">${f.format || '-'}</span>`;
if(f.length) infoHtml += `<span style="font-size:0.8rem; color:var(--muted);">${f.length}</span>`; if(f.length) infoHtml += `<span style="font-size:0.8rem; color:var(--muted); margin-left:0.4rem;">${f.length}</span>`;
} }
// ✅ 7 cellules <td> pour 7 colonnes <th>
tr.innerHTML = ` tr.innerHTML = `
<td style="text-align:center; width:40px;"> <td style="text-align:center; width:40px;">
<input type="checkbox" class="film-checkbox" value="${f.id}" onclick="updateBulkBar()"> <input type="checkbox" class="film-checkbox" value="${f.id}" onclick="updateBulkBar()">
@@ -113,18 +121,10 @@ function renderAdminTable() {
<td style="width:60px; text-align:center;"> <td style="width:60px; 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> <td><strong>${f.title}</strong></td>
<div class="film-title-cell"> <td style="color:var(--text-secondary);">${f.year || '-'}</td>
<strong>${f.title}</strong>
<span>${f.year || '-'}</span>
</div>
</td>
<td style="color:var(--text-secondary);">${f.director || '-'}</td> <td style="color:var(--text-secondary);">${f.director || '-'}</td>
<td> <td><div class="info-cell">${infoHtml}</div></td>
<div class="info-cell">
${infoHtml}
</div>
</td>
<td class="tbl-actions" style="width:100px; text-align:right;"> <td class="tbl-actions" style="width:100px; text-align:right;">
<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>
<button class="del" onclick="deleteSingleFilm('${f.id}')" title="Supprimer"><i class="ti ti-trash"></i></button> <button class="del" onclick="deleteSingleFilm('${f.id}')" title="Supprimer"><i class="ti ti-trash"></i></button>
@@ -132,7 +132,6 @@ function renderAdminTable() {
tbody.appendChild(tr); tbody.appendChild(tr);
}); });
// 4. Rendu de la pagination
renderPagination(totalPages, filtered.length); renderPagination(totalPages, filtered.length);
} }