Actualiser js/admin.js

This commit is contained in:
2026-07-02 10:51:28 +02:00
parent 5950b3a633
commit 35132e8680
+6 -29
View File
@@ -100,7 +100,7 @@ function initEventListeners() {
async function loadDashboardData() { async function loadDashboardData() {
try { try {
const res = await fetch(`${API_URL}?action=get_films`, { cache: 'no-store' }); const res = await fetch(`${API_URL}?action=get_films`, { cache: 'no-store' });
const data = await res.json(); // Reçoit {critiques: [...], videotheque: [...]} const data = await res.json();
dataStore = data; dataStore = data;
const secRes = await fetch(`${API_URL}?action=check_security_status`, { cache: 'no-store' }); const secRes = await fetch(`${API_URL}?action=check_security_status`, { cache: 'no-store' });
@@ -121,7 +121,6 @@ function renderAdminTable() {
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');
// On prend directement la bonne liste dans dataStore
let filtered = dataStore[currentAdminTab] || []; let filtered = dataStore[currentAdminTab] || [];
if (physicalFilter && physicalFilter.checked && currentAdminTab === 'critique') { if (physicalFilter && physicalFilter.checked && currentAdminTab === 'critique') {
@@ -348,8 +347,6 @@ async function openConfigModal() {
const data = await res.json(); const data = await res.json();
const tmdbIn = document.getElementById('tmdb-key-input'); const tmdbIn = document.getElementById('tmdb-key-input');
if (tmdbIn) tmdbIn.placeholder = data.tmdb_api_key ? '✅ Clé TMDB configurée' : 'Entrez votre clé TMDB'; if (tmdbIn) tmdbIn.placeholder = data.tmdb_api_key ? '✅ Clé TMDB configurée' : 'Entrez votre clé TMDB';
const upcIn = document.getElementById('upcmdb-key-input');
if (upcIn) upcIn.placeholder = data.upcmdb_api_key ? '✅ Clé UPCMDB configurée' : 'Clé gratuite sur upcmdb.com';
} catch(e) { console.error(e); } } catch(e) { console.error(e); }
} }
@@ -415,14 +412,10 @@ async function handleCritiqueUpload(input) {
loadDashboardData(); loadDashboardData();
} }
// ✅ MODIFIÉ : Ne retourne QUE l'EAN
function normalizeVideothequeRow(row) { function normalizeVideothequeRow(row) {
let ean = row['ean_isbn13'] || row['EAN'] || row['ean'] || row['Barcode'] || row['UPC'] || row['upc_isbn10'] || ''; let ean = row['ean_isbn13'] || row['EAN'] || row['ean'] || row['Barcode'] || row['UPC'] || row['upc_isbn10'] || '';
ean = String(ean).replace(/[^0-9]/g, ''); ean = String(ean).replace(/[^0-9]/g, '');
// Si pas d'EAN valide, on ignore la ligne
if (!ean || ean.length < 8) return null; if (!ean || ean.length < 8) return null;
return { ean: ean }; return { ean: ean };
} }
@@ -435,7 +428,6 @@ function handleVideothequeUpload(input) {
const parsed = parseCSV(text); const parsed = parseCSV(text);
if (!parsed.length) { alert("❌ CSV vide."); return; } if (!parsed.length) { alert("❌ CSV vide."); return; }
// ✅ Ne garde que les EANs valides
const items = parsed.map(row => normalizeVideothequeRow(row)).filter(Boolean); const items = parsed.map(row => normalizeVideothequeRow(row)).filter(Boolean);
if (!items.length) { alert("❌ Aucun code EAN valide trouvé dans le CSV."); return; } if (!items.length) { alert("❌ Aucun code EAN valide trouvé dans le CSV."); return; }
@@ -443,7 +435,6 @@ function handleVideothequeUpload(input) {
let processed = 0, totalImp = 0, totalSkp = 0; let processed = 0, totalImp = 0, totalSkp = 0;
try { try {
// Envoi par lot de 1 pour respecter le throttle de Blu-ray.com
for (let i = 0; i < items.length; i += 1) { for (let i = 0; i < items.length; i += 1) {
const batch = items.slice(i, i + 1); const batch = items.slice(i, i + 1);
const res = await fetch(`${API_URL}?action=import_batch`, { const res = await fetch(`${API_URL}?action=import_batch`, {
@@ -460,7 +451,7 @@ function handleVideothequeUpload(input) {
totalSkp += data.skipped || 0; totalSkp += data.skipped || 0;
processed += batch.length; processed += batch.length;
updateImportModal(processed, items.length); updateImportModal(processed, items.length);
await new Promise(r => setTimeout(r, 300)); // Petit délai réseau await new Promise(r => setTimeout(r, 300));
} }
input.value = ''; input.value = '';
@@ -496,11 +487,9 @@ function closeImportModal() { document.getElementById('import-progress-modal').c
async function saveConfigKeys() { async function saveConfigKeys() {
const tmdb = document.getElementById('tmdb-key-input').value.trim(); const tmdb = document.getElementById('tmdb-key-input').value.trim();
const upcmdb = document.getElementById('upcmdb-key-input').value.trim();
try { try {
if (tmdb) await fetch(`${API_URL}?action=save_config`, { method:'POST', headers:{'Authorization':localStorage.getItem('token'),'Content-Type':'application/json'}, body:JSON.stringify({key_name:'tmdb_api_key',key_value:tmdb}) }); if (tmdb) await fetch(`${API_URL}?action=save_config`, { method:'POST', headers:{'Authorization':localStorage.getItem('token'),'Content-Type':'application/json'}, body:JSON.stringify({key_name:'tmdb_api_key',key_value:tmdb}) });
if (upcmdb) await fetch(`${API_URL}?action=save_config`, { method:'POST', headers:{'Authorization':localStorage.getItem('token'),'Content-Type':'application/json'}, body:JSON.stringify({key_name:'upcmdb_api_key',key_value:upcmdb}) }); alert('✅ Clé sauvegardée !');
alert('✅ Clés sauvegardées !');
closeConfigModal(); closeConfigModal();
} catch(e) { alert('Erreur serveur.'); } } catch(e) { alert('Erreur serveur.'); }
} }
@@ -523,7 +512,7 @@ function updateImportInterface() {
const desc = document.getElementById('import-desc'); const desc = document.getElementById('import-desc');
if (currentAdminTab === 'videotheque') { if (currentAdminTab === 'videotheque') {
title.innerHTML = '<strong>Importer ma Vidéothèque</strong>'; title.innerHTML = '<strong>Importer ma Vidéothèque</strong>';
desc.textContent = 'Importez votre CSV. Le système extraira uniquement les codes EAN pour récupérer les jaquettes HD et métadonnées via Blu-ray.com, MovieCovers et TMDB.'; desc.textContent = 'Importez votre CSV. Le système extraira uniquement les codes EAN pour récupérer les jaquettes HD et métadonnées via la FNAC, Blu-ray.com, MovieCovers et TMDB.';
} else { } else {
title.innerHTML = '<strong>Importer Critiques & Notes</strong>'; title.innerHTML = '<strong>Importer Critiques & Notes</strong>';
desc.textContent = 'Importez vos fichiers CSV de notes et critiques (ex: Letterboxd).'; desc.textContent = 'Importez vos fichiers CSV de notes et critiques (ex: Letterboxd).';
@@ -542,29 +531,17 @@ function closeSuccessModal() {
if (modalEl) modalEl.classList.remove('open'); if (modalEl) modalEl.classList.remove('open');
} }
// 1. Ouvre le choix entre Manuel ou EAN function openAddMethodModal() { document.getElementById('add-choice-modal').classList.add('open'); }
function openAddMethodModal() {
document.getElementById('add-choice-modal').classList.add('open');
}
// 2. Ouvre la saisie EAN et ferme le choix
function openEanModal() { function openEanModal() {
document.getElementById('add-choice-modal').classList.remove('open'); document.getElementById('add-choice-modal').classList.remove('open');
document.getElementById('ean-input-modal').classList.add('open'); document.getElementById('ean-input-modal').classList.add('open');
} }
// 3. Ouvre votre formulaire manuel existant (Adaptez le nom selon votre code actuel)
function openManualForm() { function openManualForm() {
document.getElementById('add-choice-modal').classList.remove('open'); document.getElementById('add-choice-modal').classList.remove('open');
// On appelle ici l'ancienne fonction qui ouvre le formulaire manuel
openAddModal(); openAddModal();
} }
function closeEanModal() { document.getElementById('ean-input-modal').classList.remove('open'); }
function closeEanModal() {
document.getElementById('ean-input-modal').classList.remove('open');
}
// 4. Soumission de l'EAN
async function submitEan() { async function submitEan() {
const ean = document.getElementById('ean-input').value.trim(); const ean = document.getElementById('ean-input').value.trim();
if (!ean) return; if (!ean) return;