Actualiser js/admin.js
This commit is contained in:
+20
-21
@@ -65,7 +65,7 @@ function renderAdminTable() {
|
||||
if (!tbody) return;
|
||||
tbody.innerHTML = '';
|
||||
|
||||
// 1. Filtrage par onglet et recherche
|
||||
// 1. Filtrage
|
||||
let filtered = allItems.filter(item => item.type === currentAdminTab);
|
||||
if (searchQuery) {
|
||||
const q = searchQuery.toLowerCase();
|
||||
@@ -78,24 +78,31 @@ function renderAdminTable() {
|
||||
const countLabel = document.getElementById('admin-count-label');
|
||||
if(countLabel) countLabel.textContent = `${filtered.length} élément(s)`;
|
||||
|
||||
// 2. Gestion de la pagination
|
||||
// 2. 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);
|
||||
|
||||
// 3. Rendu des lignes
|
||||
// 3. Rendu — 7 cellules pour correspondre aux 7 <th>
|
||||
pageItems.forEach(f => {
|
||||
const tr = document.createElement('tr');
|
||||
|
||||
let infoHtml = '';
|
||||
if (currentAdminTab === 'critique') {
|
||||
const rating = Math.round(f.rating || 0);
|
||||
const stars = '★'.repeat(rating) + '☆'.repeat(5 - rating);
|
||||
infoHtml = `<span class="tbl-stars">${stars}</span>`;
|
||||
// 🌟 Gestion précise des notes Letterboxd (0.5 à 5)
|
||||
const rating = parseFloat(f.rating) || 0;
|
||||
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') {
|
||||
infoHtml += `<span class="streaming-badge" title="${f.streaming}">${f.streaming}</span>`;
|
||||
} else {
|
||||
@@ -103,9 +110,10 @@ function renderAdminTable() {
|
||||
}
|
||||
} else {
|
||||
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 = `
|
||||
<td style="text-align:center; width:40px;">
|
||||
<input type="checkbox" class="film-checkbox" value="${f.id}" onclick="updateBulkBar()">
|
||||
@@ -113,18 +121,10 @@ function renderAdminTable() {
|
||||
<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>'}
|
||||
</td>
|
||||
<td>
|
||||
<div class="film-title-cell">
|
||||
<strong>${f.title}</strong>
|
||||
<span>${f.year || '-'}</span>
|
||||
</div>
|
||||
</td>
|
||||
<td><strong>${f.title}</strong></td>
|
||||
<td style="color:var(--text-secondary);">${f.year || '-'}</td>
|
||||
<td style="color:var(--text-secondary);">${f.director || '-'}</td>
|
||||
<td>
|
||||
<div class="info-cell">
|
||||
${infoHtml}
|
||||
</div>
|
||||
</td>
|
||||
<td><div class="info-cell">${infoHtml}</div></td>
|
||||
<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 class="del" onclick="deleteSingleFilm('${f.id}')" title="Supprimer"><i class="ti ti-trash"></i></button>
|
||||
@@ -132,7 +132,6 @@ function renderAdminTable() {
|
||||
tbody.appendChild(tr);
|
||||
});
|
||||
|
||||
// 4. Rendu de la pagination
|
||||
renderPagination(totalPages, filtered.length);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user