Actualiser js/public.js
This commit is contained in:
+20
-21
@@ -2,8 +2,8 @@ let films = [];
|
|||||||
const API_URL = '../api.php';
|
const API_URL = '../api.php';
|
||||||
let currentPubTab = 'critique';
|
let currentPubTab = 'critique';
|
||||||
let activeRatingFilter = 0;
|
let activeRatingFilter = 0;
|
||||||
let activeStreamingFilter = ''; // Nouveau filtre
|
let activeStreamingFilter = '';
|
||||||
let searchQuery = ''; // Si vous avez ajouté la recherche
|
let searchQuery = '';
|
||||||
let currentPage = 1;
|
let currentPage = 1;
|
||||||
const itemsPerPage = 12;
|
const itemsPerPage = 12;
|
||||||
|
|
||||||
@@ -11,23 +11,23 @@ async function loadPublicData() {
|
|||||||
try {
|
try {
|
||||||
const response = await fetch(`${API_URL}?action=get_films`);
|
const response = await fetch(`${API_URL}?action=get_films`);
|
||||||
films = await response.json();
|
films = await response.json();
|
||||||
|
generateStreamingFilters(); // Génère les filtres AU CHARGEMENT
|
||||||
renderPublicGrid();
|
renderPublicGrid();
|
||||||
generateStreamingFilters(); // Générer les filtres dynamiquement
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Erreur de récupération :", error);
|
console.error("Erreur de récupération :", error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── GÉNÉRATION DYNAMIQUE DES FILTRES STREAMING ──
|
// ── GÉNÉRATION SIMPLE DES FILTRES STREAMING ──
|
||||||
function generateStreamingFilters() {
|
function generateStreamingFilters() {
|
||||||
const container = document.getElementById('streaming-filter-buttons');
|
const container = document.getElementById('streaming-filter-buttons');
|
||||||
if (!container) return;
|
const filterBar = document.getElementById('streaming-filter-bar');
|
||||||
|
if (!container || !filterBar) return;
|
||||||
|
|
||||||
// Extraire toutes les plateformes uniques
|
// Extraire toutes les plateformes uniques
|
||||||
const platforms = new Set();
|
const platforms = new Set();
|
||||||
films.forEach(f => {
|
films.forEach(f => {
|
||||||
if (f.type === 'critique' && f.streaming && f.streaming !== 'Disponible en support physique ou Cinéma') {
|
if (f.type === 'critique' && f.streaming && f.streaming !== 'Disponible en support physique ou Cinéma') {
|
||||||
// Séparer par virgule si plusieurs plateformes
|
|
||||||
f.streaming.split(',').forEach(p => {
|
f.streaming.split(',').forEach(p => {
|
||||||
const platform = p.trim();
|
const platform = p.trim();
|
||||||
if (platform) platforms.add(platform);
|
if (platform) platforms.add(platform);
|
||||||
@@ -35,7 +35,6 @@ function generateStreamingFilters() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Trier alphabétiquement
|
|
||||||
const sortedPlatforms = Array.from(platforms).sort();
|
const sortedPlatforms = Array.from(platforms).sort();
|
||||||
|
|
||||||
// Bouton "Toutes"
|
// Bouton "Toutes"
|
||||||
@@ -58,21 +57,27 @@ function generateStreamingFilters() {
|
|||||||
function switchPubTab(tabName) {
|
function switchPubTab(tabName) {
|
||||||
currentPubTab = tabName;
|
currentPubTab = tabName;
|
||||||
activeRatingFilter = 0;
|
activeRatingFilter = 0;
|
||||||
activeStreamingFilter = ''; // Reset
|
activeStreamingFilter = '';
|
||||||
currentPage = 1;
|
currentPage = 1;
|
||||||
|
|
||||||
const filterBar = document.getElementById('rating-filter-bar');
|
// Affiche/cache les barres de filtre SELON l'onglet
|
||||||
if(filterBar) filterBar.style.display = (tabName === 'critique') ? 'flex' : 'none';
|
const ratingBar = document.getElementById('rating-filter-bar');
|
||||||
|
|
||||||
const streamingBar = document.getElementById('streaming-filter-bar');
|
const streamingBar = document.getElementById('streaming-filter-bar');
|
||||||
if(streamingBar) streamingBar.style.display = (tabName === 'critique') ? 'flex' : 'none';
|
|
||||||
|
|
||||||
|
if (tabName === 'critique') {
|
||||||
|
if(ratingBar) ratingBar.style.display = 'flex';
|
||||||
|
if(streamingBar) streamingBar.style.display = 'flex';
|
||||||
|
} else {
|
||||||
|
if(ratingBar) ratingBar.style.display = 'none';
|
||||||
|
if(streamingBar) streamingBar.style.display = 'none';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset visuel des filtres
|
||||||
document.querySelectorAll('.rating-filter-btn').forEach(btn => {
|
document.querySelectorAll('.rating-filter-btn').forEach(btn => {
|
||||||
btn.classList.remove('active');
|
btn.classList.remove('active');
|
||||||
btn.querySelectorAll('.rf-star').forEach(s => s.classList.remove('filled'));
|
btn.querySelectorAll('.rf-star').forEach(s => s.classList.remove('filled'));
|
||||||
});
|
});
|
||||||
|
|
||||||
// Reset filtres streaming
|
|
||||||
document.querySelectorAll('.streaming-filter-btn').forEach(btn => {
|
document.querySelectorAll('.streaming-filter-btn').forEach(btn => {
|
||||||
btn.classList.remove('active');
|
btn.classList.remove('active');
|
||||||
});
|
});
|
||||||
@@ -82,6 +87,7 @@ function switchPubTab(tabName) {
|
|||||||
document.querySelectorAll('.tab-btn').forEach(btn => btn.classList.remove('active'));
|
document.querySelectorAll('.tab-btn').forEach(btn => btn.classList.remove('active'));
|
||||||
const activeBtn = document.getElementById(`tab-pub-${tabName}s`);
|
const activeBtn = document.getElementById(`tab-pub-${tabName}s`);
|
||||||
if(activeBtn) activeBtn.classList.add('active');
|
if(activeBtn) activeBtn.classList.add('active');
|
||||||
|
|
||||||
renderPublicGrid();
|
renderPublicGrid();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,7 +105,6 @@ function filterByRating(stars) {
|
|||||||
renderPublicGrid();
|
renderPublicGrid();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── NOUVEAU : FILTRE PAR STREAMING ─
|
|
||||||
function filterByStreaming(platform) {
|
function filterByStreaming(platform) {
|
||||||
if (currentPubTab !== 'critique') return;
|
if (currentPubTab !== 'critique') return;
|
||||||
activeStreamingFilter = platform;
|
activeStreamingFilter = platform;
|
||||||
@@ -118,14 +123,12 @@ function renderPublicGrid() {
|
|||||||
if (!grid) return;
|
if (!grid) return;
|
||||||
grid.innerHTML = '';
|
grid.innerHTML = '';
|
||||||
|
|
||||||
// 1. Filtrage
|
|
||||||
let filtered = films.filter(f => f.type === currentPubTab);
|
let filtered = films.filter(f => f.type === currentPubTab);
|
||||||
|
|
||||||
if (currentPubTab === 'critique' && activeRatingFilter > 0) {
|
if (currentPubTab === 'critique' && activeRatingFilter > 0) {
|
||||||
filtered = filtered.filter(f => Math.round(parseFloat(f.rating)) === activeRatingFilter);
|
filtered = filtered.filter(f => Math.round(parseFloat(f.rating)) === activeRatingFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOUVEAU : Filtre par plateforme
|
|
||||||
if (currentPubTab === 'critique' && activeStreamingFilter) {
|
if (currentPubTab === 'critique' && activeStreamingFilter) {
|
||||||
filtered = filtered.filter(f => {
|
filtered = filtered.filter(f => {
|
||||||
if (!f.streaming || f.streaming === 'Disponible en support physique ou Cinéma') return false;
|
if (!f.streaming || f.streaming === 'Disponible en support physique ou Cinéma') return false;
|
||||||
@@ -152,13 +155,11 @@ function renderPublicGrid() {
|
|||||||
}
|
}
|
||||||
if (emptyState) emptyState.style.display = 'none';
|
if (emptyState) emptyState.style.display = 'none';
|
||||||
|
|
||||||
// 2. Pagination
|
|
||||||
const totalPages = Math.ceil(filtered.length / itemsPerPage) || 1;
|
const totalPages = Math.ceil(filtered.length / itemsPerPage) || 1;
|
||||||
if (currentPage > totalPages) currentPage = totalPages;
|
if (currentPage > totalPages) currentPage = totalPages;
|
||||||
const startIdx = (currentPage - 1) * itemsPerPage;
|
const startIdx = (currentPage - 1) * itemsPerPage;
|
||||||
const pageItems = filtered.slice(startIdx, startIdx + itemsPerPage);
|
const pageItems = filtered.slice(startIdx, startIdx + itemsPerPage);
|
||||||
|
|
||||||
// 3. Rendu des cartes
|
|
||||||
pageItems.forEach(f => {
|
pageItems.forEach(f => {
|
||||||
const card = document.createElement('div');
|
const card = document.createElement('div');
|
||||||
card.className = 'card';
|
card.className = 'card';
|
||||||
@@ -171,7 +172,7 @@ function renderPublicGrid() {
|
|||||||
let streamingBadge = '';
|
let streamingBadge = '';
|
||||||
if (f.type === 'critique') {
|
if (f.type === 'critique') {
|
||||||
if (f.streaming && f.streaming !== 'Disponible en support physique ou Cinéma') {
|
if (f.streaming && f.streaming !== 'Disponible en support physique ou Cinéma') {
|
||||||
streamingBadge = `<div class="card-streaming-badge" title="${f.streaming}"> ${f.streaming.split(',')[0]}</div>`;
|
streamingBadge = `<div class="card-streaming-badge" title="${f.streaming}">📺 ${f.streaming.split(',')[0]}</div>`;
|
||||||
} else {
|
} else {
|
||||||
streamingBadge = `<div class="card-physical-badge">🎟️ Physique / Cinéma</div>`;
|
streamingBadge = `<div class="card-physical-badge">🎟️ Physique / Cinéma</div>`;
|
||||||
}
|
}
|
||||||
@@ -212,7 +213,6 @@ function renderPublicGrid() {
|
|||||||
renderPagination(totalPages);
|
renderPagination(totalPages);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── PAGINATION PUBLIQUE ──
|
|
||||||
function renderPagination(totalPages) {
|
function renderPagination(totalPages) {
|
||||||
const container = document.getElementById('pub-pagination');
|
const container = document.getElementById('pub-pagination');
|
||||||
if (!container) return;
|
if (!container) return;
|
||||||
@@ -273,7 +273,6 @@ function createPubEllipsis() {
|
|||||||
return span;
|
return span;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── DÉTAIL ──
|
|
||||||
function openDetail(id) {
|
function openDetail(id) {
|
||||||
const f = films.find(item => item.id == id);
|
const f = films.find(item => item.id == id);
|
||||||
if (!f) return;
|
if (!f) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user