Actualiser js/admin.js
This commit is contained in:
+45
-5
@@ -7,13 +7,20 @@ let selectedIds = new Set();
|
||||
let pendingDeleteAction = null;
|
||||
|
||||
function getStarsHTML(rating) {
|
||||
const r = parseFloat(rating) || 0;
|
||||
// Gère les virgules (ex: "3,5" -> "3.5") et force un nombre
|
||||
let r = parseFloat(String(rating).replace(',', '.')) || 0;
|
||||
|
||||
// Sécurise la note stricte entre 0 et 5
|
||||
r = Math.min(Math.max(r, 0), 5);
|
||||
|
||||
const full = Math.floor(r);
|
||||
const hasHalf = (r - full) >= 0.5;
|
||||
const empty = 5 - Math.ceil(r);
|
||||
const empty = Math.max(0, 5 - Math.ceil(r)); // Empêche une valeur négative fatale
|
||||
|
||||
let html = '★'.repeat(full);
|
||||
if (hasHalf) html += '<span class="half-star">★</span>';
|
||||
html += `<span class="stars-muted">${'☆'.repeat(empty)}</span>`;
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
@@ -192,7 +199,11 @@ function renderPagination(totalPages, totalItems) {
|
||||
const container = document.getElementById('pagination-container');
|
||||
if (!container) return;
|
||||
container.innerHTML = '';
|
||||
if (totalItems === 0) { container.innerHTML = '<p style="color:var(--muted); text-align:center; width:100%;">Aucun élément trouvé.</p>'; return; }
|
||||
|
||||
if (totalItems === 0) {
|
||||
container.innerHTML = '<p style="color:var(--muted); text-align:center; width:100%;">Aucun élément trouvé.</p>';
|
||||
return;
|
||||
}
|
||||
if (totalPages <= 1) return;
|
||||
|
||||
const info = document.createElement('span');
|
||||
@@ -206,7 +217,24 @@ function renderPagination(totalPages, totalItems) {
|
||||
prevBtn.onclick = () => { currentPage--; renderAdminTable(); };
|
||||
container.appendChild(prevBtn);
|
||||
|
||||
for (let i = 1; i <= totalPages; i++) {
|
||||
// Fenêtre glissante : 2 pages avant, 2 pages après la page courante
|
||||
let startPage = Math.max(1, currentPage - 2);
|
||||
let endPage = Math.min(totalPages, currentPage + 2);
|
||||
|
||||
if (startPage > 1) {
|
||||
const firstBtn = document.createElement('button');
|
||||
firstBtn.textContent = '1';
|
||||
firstBtn.onclick = () => { currentPage = 1; renderAdminTable(); };
|
||||
container.appendChild(firstBtn);
|
||||
|
||||
if (startPage > 2) {
|
||||
const dots = document.createElement('span');
|
||||
dots.textContent = '...';
|
||||
container.appendChild(dots);
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = startPage; i <= endPage; i++) {
|
||||
const btn = document.createElement('button');
|
||||
btn.textContent = i;
|
||||
if (i === currentPage) btn.classList.add('active');
|
||||
@@ -214,6 +242,18 @@ function renderPagination(totalPages, totalItems) {
|
||||
container.appendChild(btn);
|
||||
}
|
||||
|
||||
if (endPage < totalPages) {
|
||||
if (endPage < totalPages - 1) {
|
||||
const dots = document.createElement('span');
|
||||
dots.textContent = '...';
|
||||
container.appendChild(dots);
|
||||
}
|
||||
const lastBtn = document.createElement('button');
|
||||
lastBtn.textContent = totalPages;
|
||||
lastBtn.onclick = () => { currentPage = totalPages; renderAdminTable(); };
|
||||
container.appendChild(lastBtn);
|
||||
}
|
||||
|
||||
const nextBtn = document.createElement('button');
|
||||
nextBtn.innerHTML = '<i class="ti ti-chevron-right"></i>';
|
||||
nextBtn.disabled = currentPage === totalPages;
|
||||
@@ -257,7 +297,7 @@ function switchAdminTab(tabName) {
|
||||
selectedIds.clear();
|
||||
document.getElementById('search-input').value = '';
|
||||
const physicalFilter = document.getElementById('admin-physical-checkbox');
|
||||
physicalFilter.checked = false;
|
||||
if (physicalFilter) physicalFilter.checked = false;
|
||||
const wrapper = document.querySelector('.physical-filter-admin');
|
||||
if (wrapper) wrapper.style.display = (tabName === 'videotheque') ? 'none' : 'flex';
|
||||
document.querySelectorAll('.tab-btn').forEach(b => b.classList.remove('active'));
|
||||
|
||||
Reference in New Issue
Block a user