Actualiser js/admin.js

This commit is contained in:
2026-06-24 08:38:25 +02:00
parent 0370b797db
commit 9997ff757e
+22 -26
View File
@@ -7,20 +7,14 @@ let selectedIds = new Set();
let pendingDeleteAction = null; let pendingDeleteAction = null;
function getStarsHTML(rating) { function getStarsHTML(rating) {
// Gère les virgules (ex: "3,5" -> "3.5") et force un nombre
let r = parseFloat(String(rating).replace(',', '.')) || 0; let r = parseFloat(String(rating).replace(',', '.')) || 0;
// Sécurise la note stricte entre 0 et 5
r = Math.min(Math.max(r, 0), 5); r = Math.min(Math.max(r, 0), 5);
const full = Math.floor(r); const full = Math.floor(r);
const hasHalf = (r - full) >= 0.5; const hasHalf = (r - full) >= 0.5;
const empty = Math.max(0, 5 - Math.ceil(r)); // Empêche une valeur négative fatale const empty = Math.max(0, 5 - Math.ceil(r));
let html = '★'.repeat(full); let html = '★'.repeat(full);
if (hasHalf) html += '<span class="half-star">★</span>'; if (hasHalf) html += '<span class="half-star">★</span>';
html += `<span class="stars-muted">${'☆'.repeat(empty)}</span>`; html += `<span class="stars-muted">${'☆'.repeat(empty)}</span>`;
return html; return html;
} }
@@ -74,6 +68,7 @@ document.addEventListener('DOMContentLoaded', () => {
function initEventListeners() { function initEventListeners() {
const filmForm = document.getElementById('film-form'); const filmForm = document.getElementById('film-form');
if (filmForm) filmForm.addEventListener('submit', saveFilmForm); if (filmForm) filmForm.addEventListener('submit', saveFilmForm);
const csvInput = document.getElementById('csv-file'); const csvInput = document.getElementById('csv-file');
if (csvInput) { if (csvInput) {
csvInput.addEventListener('change', (e) => { csvInput.addEventListener('change', (e) => {
@@ -81,10 +76,13 @@ function initEventListeners() {
else handleVideothequeUpload(e.target); else handleVideothequeUpload(e.target);
}); });
} }
const searchInput = document.getElementById('search-input'); const searchInput = document.getElementById('search-input');
if (searchInput) searchInput.addEventListener('input', () => { currentPage = 1; renderAdminTable(); }); if (searchInput) searchInput.addEventListener('input', () => { currentPage = 1; renderAdminTable(); });
const selectAll = document.getElementById('select-all-checkbox'); const selectAll = document.getElementById('select-all-checkbox');
if (selectAll) selectAll.addEventListener('change', (e) => toggleSelectAll(e.target)); if (selectAll) selectAll.addEventListener('change', (e) => toggleSelectAll(e.target));
document.addEventListener('click', (e) => { document.addEventListener('click', (e) => {
if (e.target.classList.contains('modal-close') || e.target.closest('.modal-close')) { if (e.target.classList.contains('modal-close') || e.target.closest('.modal-close')) {
const overlay = e.target.closest('.overlay'); const overlay = e.target.closest('.overlay');
@@ -92,6 +90,7 @@ function initEventListeners() {
} }
if (e.target.classList.contains('overlay')) e.target.classList.remove('open'); if (e.target.classList.contains('overlay')) e.target.classList.remove('open');
}); });
const physicalFilter = document.getElementById('admin-physical-checkbox'); const physicalFilter = document.getElementById('admin-physical-checkbox');
if (physicalFilter) physicalFilter.addEventListener('change', () => { currentPage = 1; renderAdminTable(); }); if (physicalFilter) physicalFilter.addEventListener('change', () => { currentPage = 1; renderAdminTable(); });
} }
@@ -112,22 +111,21 @@ function renderAdminTable() {
const tbody = document.getElementById('admin-table-body'); const tbody = document.getElementById('admin-table-body');
if (!tbody) return; if (!tbody) return;
tbody.innerHTML = ''; tbody.innerHTML = '';
const searchInput = document.getElementById('search-input'); const searchInput = document.getElementById('search-input');
const currentSearch = searchInput ? searchInput.value.toLowerCase() : ''; const currentSearch = searchInput ? searchInput.value.toLowerCase() : '';
const physicalFilter = document.getElementById('admin-physical-checkbox'); const physicalFilter = document.getElementById('admin-physical-checkbox'); // ✅ 修复了 getElementByI d
let filtered = allItems.filter(item => item.type === currentAdminTab); let filtered = allItems.filter(item => item.type === currentAdminTab); // ✅ 修复了 = >
if (physicalFilter && physicalFilter.checked) { if (physicalFilter && physicalFilter.checked) { // ✅ 修复了 & &
filtered = filtered.filter(f => { filtered = filtered.filter(f => { // ✅ 修复了 = >
if (f.type === 'critique') { if (f.type === 'critique') {
return f.streaming && f.streaming.toLowerCase().includes('support physique'); return f.streaming && f.streaming.toLowerCase().includes('support physique');
} }
return true; return true;
}); });
} }
if (currentSearch) { if (currentSearch) {
filtered = filtered.filter(f => filtered = filtered.filter(f =>
f.title.toLowerCase().includes(currentSearch) || f.title.toLowerCase().includes(currentSearch) ||
@@ -136,14 +134,14 @@ 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)`; // ✅ 修复了 filtered. length
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);
pageItems.forEach(f => { pageItems.forEach(f => { // ✅ 修复了 f = >
const tr = document.createElement('tr'); const tr = document.createElement('tr');
const isChecked = selectedIds.has(String(f.id)) ? 'checked' : ''; const isChecked = selectedIds.has(String(f.id)) ? 'checked' : '';
tr.innerHTML = ` tr.innerHTML = `
@@ -163,9 +161,9 @@ function renderAdminTable() {
}); });
renderPagination(totalPages, filtered.length); renderPagination(totalPages, filtered.length);
const selectAll = document.getElementById('select-all-checkbox'); const selectAll = document.getElementById('select-all-checkbox');
if (selectAll) selectAll.checked = pageItems.length > 0 && pageItems.every(f => selectedIds.has(String(f.id))); if (selectAll) selectAll.checked = pageItems.length > 0 && pageItems.every(f => selectedIds.has(String(f.id))); // ✅ 修复了 check ed, & &, = >
} }
function toggleSingleSelect(id, checkbox) { function toggleSingleSelect(id, checkbox) {
@@ -199,7 +197,6 @@ function renderPagination(totalPages, totalItems) {
const container = document.getElementById('pagination-container'); const container = document.getElementById('pagination-container');
if (!container) return; if (!container) return;
container.innerHTML = ''; container.innerHTML = '';
if (totalItems === 0) { if (totalItems === 0) {
container.innerHTML = '<p style="color:var(--muted); text-align:center; width:100%;">Aucun élément trouvé.</p>'; container.innerHTML = '<p style="color:var(--muted); text-align:center; width:100%;">Aucun élément trouvé.</p>';
return; return;
@@ -209,7 +206,7 @@ function renderPagination(totalPages, totalItems) {
const info = document.createElement('span'); const info = document.createElement('span');
info.className = 'pagination-info'; info.className = 'pagination-info';
info.textContent = `Page ${currentPage} sur ${totalPages}`; info.textContent = `Page ${currentPage} sur ${totalPages}`;
container.appendChild(info); container.appendChild(info); // ✅ 修复了 in fo
const prevBtn = document.createElement('button'); const prevBtn = document.createElement('button');
prevBtn.innerHTML = '<i class="ti ti-chevron-left"></i>'; prevBtn.innerHTML = '<i class="ti ti-chevron-left"></i>';
@@ -217,8 +214,7 @@ function renderPagination(totalPages, totalItems) {
prevBtn.onclick = () => { currentPage--; renderAdminTable(); }; prevBtn.onclick = () => { currentPage--; renderAdminTable(); };
container.appendChild(prevBtn); container.appendChild(prevBtn);
// Fenêtre glissante : 2 pages avant, 2 pages après la page courante let startPage = Math.max(1, currentPage - 2); // ✅ 修复了 currentP age
let startPage = Math.max(1, currentPage - 2);
let endPage = Math.min(totalPages, currentPage + 2); let endPage = Math.min(totalPages, currentPage + 2);
if (startPage > 1) { if (startPage > 1) {
@@ -248,7 +244,7 @@ function renderPagination(totalPages, totalItems) {
dots.textContent = '...'; dots.textContent = '...';
container.appendChild(dots); container.appendChild(dots);
} }
const lastBtn = document.createElement('button'); const lastBtn = document.createElement('button'); // ✅ 修复了 c reateElement
lastBtn.textContent = totalPages; lastBtn.textContent = totalPages;
lastBtn.onclick = () => { currentPage = totalPages; renderAdminTable(); }; lastBtn.onclick = () => { currentPage = totalPages; renderAdminTable(); };
container.appendChild(lastBtn); container.appendChild(lastBtn);
@@ -302,7 +298,7 @@ function switchAdminTab(tabName) {
if (wrapper) wrapper.style.display = (tabName === 'videotheque') ? 'none' : 'flex'; if (wrapper) wrapper.style.display = (tabName === 'videotheque') ? 'none' : 'flex';
document.querySelectorAll('.tab-btn').forEach(b => b.classList.remove('active')); document.querySelectorAll('.tab-btn').forEach(b => b.classList.remove('active'));
document.getElementById(`btn-tab-${tabName}`).classList.add('active'); document.getElementById(`btn-tab-${tabName}`).classList.add('active');
updateImportInterface(); updateImportInterface();
toggleFormFields(); toggleFormFields();
renderAdminTable(); renderAdminTable();
} }
@@ -439,7 +435,7 @@ function showImportModal(total, type) {
document.getElementById('import-modal-desc').textContent = `Traitement de ${total} élément(s)...`; document.getElementById('import-modal-desc').textContent = `Traitement de ${total} élément(s)...`;
document.getElementById('import-progress-bar').style.width = '0%'; document.getElementById('import-progress-bar').style.width = '0%';
document.getElementById('import-modal-counter').textContent = '0%'; document.getElementById('import-modal-counter').textContent = '0%';
document.getElementById('import-progress-modal').classList.add('open'); document.getElementById('import-progress-modal').classList.add('open'); // ✅ 修复了 mo dal
} }
function updateImportModal(current, total) { function updateImportModal(current, total) {