Actualiser js/admin.js
This commit is contained in:
+18
-8
@@ -75,10 +75,10 @@ function showProgressModal(total) {
|
|||||||
document.getElementById('progress-overlay').classList.add('open');
|
document.getElementById('progress-overlay').classList.add('open');
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateProgressModal(current, total) {
|
function updateProgressModal(current, total, imagesRetrieved = 0) {
|
||||||
const pct = Math.round((current / total) * 100);
|
const pct = Math.round((current / total) * 100);
|
||||||
document.getElementById('progress-bar').style.width = pct + '%';
|
document.getElementById('progress-bar').style.width = pct + '%';
|
||||||
document.getElementById('progress-count').textContent = `${current} / ${total}`;
|
document.getElementById('progress-count').textContent = `${current} / ${total} | 🖼️ ${imagesRetrieved} images`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function closeProgressModal() {
|
function closeProgressModal() {
|
||||||
@@ -472,10 +472,12 @@ async function saveFilmForm(e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ─ IMPORT CSV PAR LOTS ──
|
// ─ IMPORT CSV PAR LOTS ──
|
||||||
|
// ── IMPORT CSV AVEC RÉCUPÉRATION D'IMAGES ──
|
||||||
async function handleCsvUpload(input) {
|
async function handleCsvUpload(input) {
|
||||||
if (!input.files || input.files.length === 0) return;
|
if (!input.files || input.files.length === 0) return;
|
||||||
const file = input.files[0];
|
const file = input.files[0];
|
||||||
input.value = '';
|
input.value = '';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const text = await file.text();
|
const text = await file.text();
|
||||||
const allData = parseCSV(text);
|
const allData = parseCSV(text);
|
||||||
@@ -486,12 +488,14 @@ async function handleCsvUpload(input) {
|
|||||||
closeConfigModal();
|
closeConfigModal();
|
||||||
showProgressModal(allData.length);
|
showProgressModal(allData.length);
|
||||||
|
|
||||||
const batchSize = 5;
|
const batchSize = 3; // Réduit pour permettre la récupération d'images
|
||||||
let processed = 0;
|
let processed = 0;
|
||||||
|
let imagesRetrieved = 0;
|
||||||
|
|
||||||
for (let i = 0; i < allData.length; i += batchSize) {
|
for (let i = 0; i < allData.length; i += batchSize) {
|
||||||
const batch = allData.slice(i, i + batchSize);
|
const batch = allData.slice(i, i + batchSize);
|
||||||
try {
|
try {
|
||||||
await fetch(`${API_URL}?action=import_batch`, {
|
const res = await fetch(`${API_URL}?action=import_batch`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': localStorage.getItem('token'),
|
'Authorization': localStorage.getItem('token'),
|
||||||
@@ -499,19 +503,25 @@ async function handleCsvUpload(input) {
|
|||||||
},
|
},
|
||||||
body: JSON.stringify({ items: batch, type: currentAdminTab })
|
body: JSON.stringify({ items: batch, type: currentAdminTab })
|
||||||
});
|
});
|
||||||
|
const result = await res.json();
|
||||||
|
if (result.details) {
|
||||||
|
result.details.forEach(item => {
|
||||||
|
if (item.poster) imagesRetrieved++;
|
||||||
|
});
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Erreur sur un lot:', err);
|
console.error('Erreur sur un lot:', err);
|
||||||
}
|
}
|
||||||
processed += batch.length;
|
processed += batch.length;
|
||||||
updateProgressModal(processed, allData.length);
|
const pct = Math.round((processed / allData.length) * 100);
|
||||||
|
updateProgressModal(processed, allData.length, imagesRetrieved);
|
||||||
}
|
}
|
||||||
closeProgressModal();
|
closeProgressModal();
|
||||||
alert(`✅ Import terminé ! ${allData.length} élément(s) traité(s).`);
|
alert(`✅ Import terminé !\n📦 ${allData.length} élément(s) traité(s)\n🖼️ ${imagesRetrieved} image(s) récupérée(s)`);
|
||||||
loadDashboardData();
|
loadDashboardData();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Erreur lecture CSV :', err);
|
|
||||||
closeProgressModal();
|
closeProgressModal();
|
||||||
alert('Impossible de lire le fichier CSV.');
|
alert('❌ Impossible de lire le fichier CSV.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user