Actualiser js/admin.js
This commit is contained in:
+14
-82
@@ -1,6 +1,6 @@
|
|||||||
const API_URL = '../api.php';
|
const API_URL = '../api.php';
|
||||||
let allItems = [];
|
let allItems = [];
|
||||||
let currentAdminTab = 'videotheque'; // ✅ CORRIGÉ : Défaut sur vidéothèque
|
let currentAdminTab = 'videotheque'; // Défaut sur vidéothèque
|
||||||
let currentPage = 1;
|
let currentPage = 1;
|
||||||
const itemsPerPage = 12;
|
const itemsPerPage = 12;
|
||||||
let selectedIds = new Set();
|
let selectedIds = new Set();
|
||||||
@@ -389,62 +389,6 @@ async function saveFilmForm(e) {
|
|||||||
} catch (err) { console.error(err); }
|
} catch (err) { console.error(err); }
|
||||||
}
|
}
|
||||||
|
|
||||||
// ✅ NOUVELLE FONCTION : Recherche par EAN pour la vidéothèque
|
|
||||||
async function searchByEan() {
|
|
||||||
const eanInput = document.getElementById('f-ean');
|
|
||||||
const ean = eanInput ? eanInput.value.trim() : '';
|
|
||||||
|
|
||||||
if (!ean) {
|
|
||||||
alert('Veuillez entrer un code EAN/UPC');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const searchBtn = document.getElementById('search-ean-btn');
|
|
||||||
if (searchBtn) {
|
|
||||||
searchBtn.disabled = true;
|
|
||||||
searchBtn.innerHTML = '<i class="ti ti-loader"></i> Recherche...';
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const res = await fetch(`${API_URL}?action=search_by_ean&ean=${encodeURIComponent(ean)}`, {
|
|
||||||
headers: { 'Authorization': localStorage.getItem('token') }
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!res.ok) throw new Error(`Erreur HTTP ${res.status}`);
|
|
||||||
|
|
||||||
const data = await res.json();
|
|
||||||
|
|
||||||
if (!data.success) {
|
|
||||||
alert('❌ ' + (data.error || 'Film non trouvé'));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remplir le formulaire avec les données trouvées
|
|
||||||
if (data.title) document.getElementById('f-title').value = data.title;
|
|
||||||
if (data.year) document.getElementById('f-year').value = data.year;
|
|
||||||
if (data.director) document.getElementById('f-director').value = data.director;
|
|
||||||
if (data.poster) document.getElementById('f-poster').value = data.poster;
|
|
||||||
if (data.format) document.getElementById('f-format').value = data.format;
|
|
||||||
if (data.length) document.getElementById('f-length').value = data.length;
|
|
||||||
if (data.publisher) document.getElementById('f-publisher').value = data.publisher;
|
|
||||||
if (data.number_of_discs) document.getElementById('f-discs').value = data.number_of_discs;
|
|
||||||
if (data.aspect_ratio) document.getElementById('f-aspect').value = data.aspect_ratio;
|
|
||||||
if (data.actors) document.getElementById('f-actors').value = data.actors;
|
|
||||||
if (data.description) document.getElementById('f-description').value = data.description;
|
|
||||||
|
|
||||||
alert('✅ Film trouvé ! Les informations ont été remplies.');
|
|
||||||
|
|
||||||
} catch (err) {
|
|
||||||
console.error(err);
|
|
||||||
alert('❌ Erreur lors de la recherche : ' + err.message);
|
|
||||||
} finally {
|
|
||||||
if (searchBtn) {
|
|
||||||
searchBtn.disabled = false;
|
|
||||||
searchBtn.innerHTML = '<i class="ti ti-search"></i> Rechercher';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function handleCritiqueUpload(input) {
|
async function handleCritiqueUpload(input) {
|
||||||
if (!input.files || input.files.length === 0) return;
|
if (!input.files || input.files.length === 0) return;
|
||||||
let allData = [];
|
let allData = [];
|
||||||
@@ -470,28 +414,15 @@ async function handleCritiqueUpload(input) {
|
|||||||
loadDashboardData();
|
loadDashboardData();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ✅ CORRECTION : Retourne TOUTES les données du CSV
|
// ✅ 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'] || '';
|
||||||
if (ean) ean = String(ean).replace(/[^0-9]/g, '');
|
ean = String(ean).replace(/[^0-9]/g, '');
|
||||||
|
|
||||||
let title = row['title'] || row['Title'] || row['Titre'] || '';
|
// Si pas d'EAN valide, on ignore la ligne
|
||||||
title = String(title).trim();
|
if (!ean || ean.length < 8) return null;
|
||||||
if (!ean && !title) return null;
|
|
||||||
|
|
||||||
return {
|
return { ean: ean };
|
||||||
ean: ean,
|
|
||||||
title: title,
|
|
||||||
year: row['publish_date'] ? String(row['publish_date']).substring(0, 4) : (row['Year'] || row['year'] || ''),
|
|
||||||
synopsis: row['description'] || '',
|
|
||||||
review: row['review'] || '',
|
|
||||||
rating: row['rating'] || '',
|
|
||||||
publisher: row['publisher'] || '',
|
|
||||||
length: row['length'] || '',
|
|
||||||
number_of_discs: row['number_of_discs'] || 1,
|
|
||||||
aspect_ratio: row['aspect_ratio'] || '',
|
|
||||||
actors: row['creators'] || row['ensemble'] || ''
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleVideothequeUpload(input) {
|
function handleVideothequeUpload(input) {
|
||||||
@@ -503,16 +434,17 @@ 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 titre ou EAN valide trouvé."); return; }
|
if (!items.length) { alert("❌ Aucun code EAN valide trouvé dans le CSV."); return; }
|
||||||
|
|
||||||
showImportModal(items.length, 'videotheque');
|
showImportModal(items.length, 'videotheque');
|
||||||
let processed = 0, totalImp = 0, totalSkp = 0;
|
let processed = 0, totalImp = 0, totalSkp = 0;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const BATCH_SIZE = 5;
|
// Envoi par lot de 1 pour respecter le throttle de Blu-ray.com
|
||||||
for (let i = 0; i < items.length; i += BATCH_SIZE) {
|
for (let i = 0; i < items.length; i += 1) {
|
||||||
const batch = items.slice(i, i + BATCH_SIZE);
|
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`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Authorization': localStorage.getItem('token'), 'Content-Type': 'application/json' },
|
headers: { 'Authorization': localStorage.getItem('token'), 'Content-Type': 'application/json' },
|
||||||
@@ -527,7 +459,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, 500));
|
await new Promise(r => setTimeout(r, 300)); // Petit délai réseau
|
||||||
}
|
}
|
||||||
|
|
||||||
input.value = '';
|
input.value = '';
|
||||||
@@ -590,10 +522,10 @@ 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 (ex: CLC, MediaControl). Le système récupérera les jaquettes HD via MovieCovers/Blu-ray.com et complétera avec 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 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 ou export personnalisé).';
|
desc.textContent = 'Importez vos fichiers CSV de notes et critiques (ex: Letterboxd).';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user