Actualiser js/admin.js
This commit is contained in:
+7
-59
@@ -68,7 +68,6 @@ 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) => {
|
||||||
@@ -76,13 +75,10 @@ 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');
|
||||||
@@ -90,7 +86,6 @@ 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(); });
|
||||||
}
|
}
|
||||||
@@ -425,72 +420,25 @@ function normalizeVideothequeRow(row) {
|
|||||||
async function handleVideothequeUpload(input) {
|
async function handleVideothequeUpload(input) {
|
||||||
if (!input.files || input.files.length === 0) return;
|
if (!input.files || input.files.length === 0) return;
|
||||||
let allData = [];
|
let allData = [];
|
||||||
for (const file of input.files) {
|
for (const file of input.files) { try { allData = allData.concat(parseCSV(await file.text())); } catch(e) {} }
|
||||||
try {
|
if (allData.length === 0) { input.value = ''; return alert('❌ Fichier vide.'); }
|
||||||
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.');
|
|
||||||
}
|
|
||||||
|
|
||||||
allData = allData.map(normalizeVideothequeRow);
|
allData = allData.map(normalizeVideothequeRow);
|
||||||
showImportModal(allData.length, 'videotheque');
|
showImportModal(allData.length, 'videotheque');
|
||||||
let processed = 0;
|
let processed = 0;
|
||||||
let allDebugLogs = []; // 🔥 COLLECTER LES LOGS
|
|
||||||
|
|
||||||
for (let i = 0; i < allData.length; i += 3) {
|
for (let i = 0; i < allData.length; i += 3) {
|
||||||
const batch = allData.slice(i, i + 3);
|
const batch = allData.slice(i, i + 3);
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${API_URL}?action=import_batch`, {
|
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' }) });
|
||||||
method: 'POST',
|
if (!response.ok) throw new Error(`Erreur serveur ${response.status}`);
|
||||||
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 result = await response.json();
|
const result = await response.json();
|
||||||
|
if (!result.success) throw new Error(result.error || "Erreur inconnue.");
|
||||||
// 🔥 COLLECTER LES LOGS DE DÉBOGAGE
|
|
||||||
if (result.debug) {
|
|
||||||
allDebugLogs = allDebugLogs.concat(result.debug);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!result.success) {
|
|
||||||
throw new Error(result.error || "Erreur inconnue.");
|
|
||||||
}
|
|
||||||
} catch (err) {
|
} 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;
|
processed += batch.length;
|
||||||
updateImportModal(processed, allData.length);
|
updateImportModal(processed, allData.length);
|
||||||
}
|
}
|
||||||
|
input.value = ''; closeImportModal();
|
||||||
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)`);
|
|
||||||
}
|
|
||||||
|
|
||||||
showSuccessModal(`${allData.length} support(s) importé(s) avec succès.`);
|
showSuccessModal(`${allData.length} support(s) importé(s) avec succès.`);
|
||||||
loadDashboardData();
|
loadDashboardData();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user