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