Actualiser js/admin.js
This commit is contained in:
+26
-15
@@ -162,16 +162,29 @@ function openPasswordModal() { document.getElementById('pwd-error').style.displa
|
|||||||
function closePasswordModal() { document.getElementById('password-modal').classList.remove('open'); }
|
function closePasswordModal() { document.getElementById('password-modal').classList.remove('open'); }
|
||||||
function logout() { localStorage.removeItem('token'); window.location.href = 'login.html'; }
|
function logout() { localStorage.removeItem('token'); window.location.href = 'login.html'; }
|
||||||
|
|
||||||
function showProgressModal(total) { document.getElementById('progress-text').textContent = 'Traitement et récupération des jaquettes...'; document.getElementById('progress-bar').style.width = '0%'; document.getElementById('progress-count').textContent = `0 / ${total}`; document.getElementById('progress-overlay').classList.add('open'); }
|
function showProgressModal(total) {
|
||||||
function updateProgressModal(current, total) { const pct = Math.round((current / total) * 100); document.getElementById('progress-bar').style.width = pct + '%'; document.getElementById('progress-count').textContent = `${current} / ${total}`; }
|
document.getElementById('progress-text').textContent = 'Récupération des jaquettes...';
|
||||||
function closeProgressModal() { document.getElementById('progress-overlay').classList.remove('open'); }
|
document.getElementById('progress-bar').style.width = '0%';
|
||||||
|
document.getElementById('progress-count').textContent = `0 / ${total}`;
|
||||||
|
document.getElementById('progress-overlay').classList.add('open');
|
||||||
|
}
|
||||||
|
function updateProgressModal(current, total, mpdbHits = 0, upcHits = 0, tmdbHits = 0, noImage = 0) {
|
||||||
|
const pct = Math.round((current / total) * 100);
|
||||||
|
document.getElementById('progress-bar').style.width = pct + '%';
|
||||||
|
document.getElementById('progress-count').textContent =
|
||||||
|
`${current} / ${total} | ${mpdbHits} MPDB | ${upcHits} UPC | ${tmdbHits} TMDB | ${noImage}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function closeProgressModal() {
|
||||||
|
document.getElementById('progress-overlay').classList.remove('open');
|
||||||
|
}
|
||||||
async function saveFilmForm(e) {
|
async function saveFilmForm(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const payload = { type: currentAdminTab, id: safeGetValue('f-id'), title: safeGetValue('f-title'), year: safeGetValue('f-year'), director: safeGetValue('f-director'), poster: safeGetValue('f-poster'), rating: safeGetValue('f-rating', 3), review: safeGetValue('f-review'), streaming: safeGetValue('f-streaming'), format: safeGetValue('f-format'), length: safeGetValue('f-length'), publisher: safeGetValue('f-publisher'), aspect_ratio: safeGetValue('f-aspect'), ean_isbn13: safeGetValue('f-ean'), number_of_discs: safeGetValue('f-discs', 1), description: safeGetValue('f-description') };
|
const payload = { type: currentAdminTab, id: safeGetValue('f-id'), title: safeGetValue('f-title'), year: safeGetValue('f-year'), director: safeGetValue('f-director'), poster: safeGetValue('f-poster'), rating: safeGetValue('f-rating', 3), review: safeGetValue('f-review'), streaming: safeGetValue('f-streaming'), format: safeGetValue('f-format'), length: safeGetValue('f-length'), publisher: safeGetValue('f-publisher'), aspect_ratio: safeGetValue('f-aspect'), ean_isbn13: safeGetValue('f-ean'), number_of_discs: safeGetValue('f-discs', 1), description: safeGetValue('f-description') };
|
||||||
try { await fetch(`${API_URL}?action=save_film`, { method: 'POST', headers: { 'Authorization': localStorage.getItem('token'), 'Content-Type': 'application/json' }, body: JSON.stringify(payload) }); closeAdminModal(); loadDashboardData(); } catch (err) { console.error('Erreur sauvegarde :', err); }
|
try { await fetch(`${API_URL}?action=save_film`, { method: 'POST', headers: { 'Authorization': localStorage.getItem('token'), 'Content-Type': 'application/json' }, body: JSON.stringify(payload) }); closeAdminModal(); loadDashboardData(); } catch (err) { console.error('Erreur sauvegarde :', err); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/ ── IMPORT CSV OPTIMISÉ (lots de 15) ──
|
||||||
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];
|
||||||
@@ -181,15 +194,16 @@ async function handleCsvUpload(input) {
|
|||||||
const text = await file.text();
|
const text = await file.text();
|
||||||
const allData = parseCSV(text);
|
const allData = parseCSV(text);
|
||||||
if (allData.length === 0) {
|
if (allData.length === 0) {
|
||||||
alert(' Le fichier CSV est vide ou mal formaté.');
|
alert('❌ Le fichier CSV est vide ou mal formaté.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
closeConfigModal();
|
closeConfigModal();
|
||||||
showProgressModal(allData.length);
|
showProgressModal(allData.length);
|
||||||
|
|
||||||
const batchSize = 15; // Augmenté pour réduire les requêtes
|
const batchSize = 15; // Lots de 15 pour réduire les requêtes
|
||||||
let processed = 0;
|
let processed = 0;
|
||||||
let totalEanHits = 0;
|
let totalMpdbHits = 0;
|
||||||
|
let totalUpcHits = 0;
|
||||||
let totalTmdbHits = 0;
|
let totalTmdbHits = 0;
|
||||||
let totalNoImage = 0;
|
let totalNoImage = 0;
|
||||||
const startTime = Date.now();
|
const startTime = Date.now();
|
||||||
@@ -207,7 +221,8 @@ async function handleCsvUpload(input) {
|
|||||||
});
|
});
|
||||||
const result = await res.json();
|
const result = await res.json();
|
||||||
if (result.stats) {
|
if (result.stats) {
|
||||||
totalEanHits += (result.stats.ean_hits || 0);
|
totalMpdbHits += (result.stats.mpdb_hits || 0);
|
||||||
|
totalUpcHits += (result.stats.upc_hits || 0);
|
||||||
totalTmdbHits += (result.stats.tmdb_hits || 0);
|
totalTmdbHits += (result.stats.tmdb_hits || 0);
|
||||||
totalNoImage += (result.stats.no_image || 0);
|
totalNoImage += (result.stats.no_image || 0);
|
||||||
}
|
}
|
||||||
@@ -217,21 +232,17 @@ async function handleCsvUpload(input) {
|
|||||||
const elapsed = ((Date.now() - startTime) / 1000).toFixed(1);
|
const elapsed = ((Date.now() - startTime) / 1000).toFixed(1);
|
||||||
const speed = (processed / (Date.now() - startTime) * 1000).toFixed(1);
|
const speed = (processed / (Date.now() - startTime) * 1000).toFixed(1);
|
||||||
|
|
||||||
const pct = Math.round((processed / allData.length) * 100);
|
updateProgressModal(processed, allData.length, totalMpdbHits, totalUpcHits, totalTmdbHits, totalNoImage);
|
||||||
document.getElementById('progress-bar').style.width = pct + '%';
|
document.getElementById('progress-text').textContent = `Import en cours... (${speed} films/s)`;
|
||||||
document.getElementById('progress-text').textContent =
|
|
||||||
`Import en cours... (${speed} films/s)`;
|
|
||||||
document.getElementById('progress-count').textContent =
|
|
||||||
`${processed} / ${allData.length} | 🖼️ ${totalEanHits} EAN | 🎬 ${totalTmdbHits} TMDB | ❌ ${totalNoImage} sans image | ⏱️ ${elapsed}s`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
closeProgressModal();
|
closeProgressModal();
|
||||||
const totalTime = ((Date.now() - startTime) / 1000).toFixed(1);
|
const totalTime = ((Date.now() - startTime) / 1000).toFixed(1);
|
||||||
alert(`✅ Import terminé en ${totalTime}s !\n📦 ${allData.length} film(s)\n🖼️ ${totalEanHits} jaquette(s) via EAN\n🎬 ${totalTmdbHits} affiche(s) via TMDB\n ${totalNoImage} sans image`);
|
alert(`✅ Import terminé en ${totalTime}s !\n📦 ${allData.length} film(s)\n🎬 ${totalMpdbHits} jaquette(s) MoviePosterDB\n ${totalUpcHits} jaquette(s) UPCitemdb\n🌟 ${totalTmdbHits} affiche(s) TMDB\n❌ ${totalNoImage} sans image`);
|
||||||
loadDashboardData();
|
loadDashboardData();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
closeProgressModal();
|
closeProgressModal();
|
||||||
alert(' Impossible de lire le fichier CSV.');
|
alert('❌ Impossible de lire le fichier CSV.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user