Actualiser js/admin.js
This commit is contained in:
+7
-59
@@ -68,7 +68,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
function initEventListeners() {
|
||||
const filmForm = document.getElementById('film-form');
|
||||
if (filmForm) filmForm.addEventListener('submit', saveFilmForm);
|
||||
|
||||
const csvInput = document.getElementById('csv-file');
|
||||
if (csvInput) {
|
||||
csvInput.addEventListener('change', (e) => {
|
||||
@@ -76,13 +75,10 @@ function initEventListeners() {
|
||||
else handleVideothequeUpload(e.target);
|
||||
});
|
||||
}
|
||||
|
||||
const searchInput = document.getElementById('search-input');
|
||||
if (searchInput) searchInput.addEventListener('input', () => { currentPage = 1; renderAdminTable(); });
|
||||
|
||||
const selectAll = document.getElementById('select-all-checkbox');
|
||||
if (selectAll) selectAll.addEventListener('change', (e) => toggleSelectAll(e.target));
|
||||
|
||||
document.addEventListener('click', (e) => {
|
||||
if (e.target.classList.contains('modal-close') || e.target.closest('.modal-close')) {
|
||||
const overlay = e.target.closest('.overlay');
|
||||
@@ -90,7 +86,6 @@ function initEventListeners() {
|
||||
}
|
||||
if (e.target.classList.contains('overlay')) e.target.classList.remove('open');
|
||||
});
|
||||
|
||||
const physicalFilter = document.getElementById('admin-physical-checkbox');
|
||||
if (physicalFilter) physicalFilter.addEventListener('change', () => { currentPage = 1; renderAdminTable(); });
|
||||
}
|
||||
@@ -425,72 +420,25 @@ function normalizeVideothequeRow(row) {
|
||||
async function handleVideothequeUpload(input) {
|
||||
if (!input.files || input.files.length === 0) return;
|
||||
let allData = [];
|
||||
for (const file of input.files) {
|
||||
try {
|
||||
allData = allData.concat(parseCSV(await file.text()));
|
||||
} catch(e) {
|
||||
console.error('Erreur parsing CSV:', e);
|
||||
}
|
||||
}
|
||||
if (allData.length === 0) {
|
||||
input.value = '';
|
||||
return alert('❌ Fichier vide.');
|
||||
}
|
||||
|
||||
for (const file of input.files) { try { allData = allData.concat(parseCSV(await file.text())); } catch(e) {} }
|
||||
if (allData.length === 0) { input.value = ''; return alert('❌ Fichier vide.'); }
|
||||
allData = allData.map(normalizeVideothequeRow);
|
||||
showImportModal(allData.length, 'videotheque');
|
||||
let processed = 0;
|
||||
let allDebugLogs = []; // 🔥 COLLECTER LES LOGS
|
||||
|
||||
for (let i = 0; i < allData.length; i += 3) {
|
||||
const batch = allData.slice(i, i + 3);
|
||||
try {
|
||||
const response = await fetch(`${API_URL}?action=import_batch`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': localStorage.getItem('token'),
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ items: batch, type: 'videotheque' })
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errText = await response.text();
|
||||
throw new Error(`Erreur serveur ${response.status}: ${errText}`);
|
||||
}
|
||||
|
||||
const response = await fetch(`${API_URL}?action=import_batch`, { method: 'POST', headers: { 'Authorization': localStorage.getItem('token'), 'Content-Type': 'application/json' }, body: JSON.stringify({ items: batch, type: 'videotheque' }) });
|
||||
if (!response.ok) throw new Error(`Erreur serveur ${response.status}`);
|
||||
const result = await response.json();
|
||||
|
||||
// 🔥 COLLECTER LES LOGS DE DÉBOGAGE
|
||||
if (result.debug) {
|
||||
allDebugLogs = allDebugLogs.concat(result.debug);
|
||||
}
|
||||
|
||||
if (!result.success) {
|
||||
throw new Error(result.error || "Erreur inconnue.");
|
||||
}
|
||||
if (!result.success) throw new Error(result.error || "Erreur inconnue.");
|
||||
} catch (err) {
|
||||
console.error('Erreur import:', err);
|
||||
closeImportModal();
|
||||
alert("❌ Échec de l'import : " + err.message);
|
||||
input.value = '';
|
||||
return;
|
||||
closeImportModal(); alert("❌ Échec de l'import : " + err.message); input.value = ''; return;
|
||||
}
|
||||
processed += batch.length;
|
||||
updateImportModal(processed, allData.length);
|
||||
}
|
||||
|
||||
input.value = '';
|
||||
closeImportModal();
|
||||
|
||||
// 🔥 AFFICHER LES LOGS DANS LA CONSOLE
|
||||
if (allDebugLogs.length > 0) {
|
||||
console.log('=== LOGS D\'IMPORT VIDÉOTHÈQUE ===');
|
||||
allDebugLogs.forEach(log => console.log(log));
|
||||
console.log('==================================');
|
||||
console.log(`✅ ${allData.length} film(s) importé(s)`);
|
||||
}
|
||||
|
||||
input.value = ''; closeImportModal();
|
||||
showSuccessModal(`${allData.length} support(s) importé(s) avec succès.`);
|
||||
loadDashboardData();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user