Actualiser js/public.js
This commit is contained in:
+37
-24
@@ -21,6 +21,7 @@ function getStarsHTML(rating) {
|
|||||||
function generateStreamingSelect() {
|
function generateStreamingSelect() {
|
||||||
const select = document.getElementById('pub-streaming-select');
|
const select = document.getElementById('pub-streaming-select');
|
||||||
if (!select) return;
|
if (!select) return;
|
||||||
|
|
||||||
const platforms = new Set();
|
const platforms = new Set();
|
||||||
films.forEach(f => {
|
films.forEach(f => {
|
||||||
if (f.type === 'critique' && f.streaming &&
|
if (f.type === 'critique' && f.streaming &&
|
||||||
@@ -32,6 +33,7 @@ function generateStreamingSelect() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const sortedPlatforms = Array.from(platforms).sort();
|
const sortedPlatforms = Array.from(platforms).sort();
|
||||||
select.innerHTML = '<option value="">Toutes les plateformes</option>';
|
select.innerHTML = '<option value="">Toutes les plateformes</option>';
|
||||||
sortedPlatforms.forEach(platform => {
|
sortedPlatforms.forEach(platform => {
|
||||||
@@ -40,6 +42,7 @@ function generateStreamingSelect() {
|
|||||||
option.textContent = platform;
|
option.textContent = platform;
|
||||||
select.appendChild(option);
|
select.appendChild(option);
|
||||||
});
|
});
|
||||||
|
|
||||||
select.addEventListener('change', (e) => {
|
select.addEventListener('change', (e) => {
|
||||||
activeStreamingFilter = e.target.value;
|
activeStreamingFilter = e.target.value;
|
||||||
currentPage = 1;
|
currentPage = 1;
|
||||||
@@ -52,12 +55,11 @@ async function loadPublicData() {
|
|||||||
const response = await fetch(`${API_URL}?action=get_films`, { cache: 'default' });
|
const response = await fetch(`${API_URL}?action=get_films`, { cache: 'default' });
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|
||||||
// ✅ CORRECTION : Fusionner les deux tableaux en un seul
|
// ✅ CORRECTION : Fusionner les deux tableaux
|
||||||
films = [...(data.critique || []), ...(data.videotheque || [])];
|
films = [...(data.critique || []), ...(data.videotheque || [])];
|
||||||
|
|
||||||
generateStreamingSelect();
|
generateStreamingSelect();
|
||||||
|
|
||||||
// Écouteur pour le filtre physique
|
|
||||||
const physicalCheckbox = document.getElementById('physical-only-checkbox');
|
const physicalCheckbox = document.getElementById('physical-only-checkbox');
|
||||||
if (physicalCheckbox) {
|
if (physicalCheckbox) {
|
||||||
physicalCheckbox.addEventListener('change', () => {
|
physicalCheckbox.addEventListener('change', () => {
|
||||||
@@ -77,13 +79,15 @@ function switchPubTab(tabName) {
|
|||||||
activeRatingFilter = 0;
|
activeRatingFilter = 0;
|
||||||
activeStreamingFilter = '';
|
activeStreamingFilter = '';
|
||||||
currentPage = 1;
|
currentPage = 1;
|
||||||
|
|
||||||
const select = document.getElementById('pub-streaming-select');
|
const select = document.getElementById('pub-streaming-select');
|
||||||
if (select) select.value = '';
|
if (select) select.value = '';
|
||||||
|
|
||||||
const ratingBar = document.getElementById('rating-filter-bar');
|
const ratingBar = document.getElementById('rating-filter-bar');
|
||||||
if (ratingBar) ratingBar.style.display = (tabName === 'critique') ? 'flex' : 'none';
|
if (ratingBar) ratingBar.style.display = (tabName === 'critique') ? 'flex' : 'none';
|
||||||
|
|
||||||
if (select) select.style.display = (tabName === 'critique') ? 'block' : 'none';
|
if (select) select.style.display = (tabName === 'critique') ? 'block' : 'none';
|
||||||
|
|
||||||
// 🔥 Cacher la case physique en mode vidéothèque
|
|
||||||
const physicalBox = document.querySelector('.physical-filter-box');
|
const physicalBox = document.querySelector('.physical-filter-box');
|
||||||
if (physicalBox) {
|
if (physicalBox) {
|
||||||
physicalBox.style.display = (tabName === 'critique') ? 'block' : 'none';
|
physicalBox.style.display = (tabName === 'critique') ? 'block' : 'none';
|
||||||
@@ -93,15 +97,19 @@ function switchPubTab(tabName) {
|
|||||||
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'));
|
||||||
});
|
});
|
||||||
|
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
function filterByRating(stars) {
|
function filterByRating(stars) {
|
||||||
if (currentPubTab !== 'critique') return;
|
if (currentPubTab !== 'critique') return;
|
||||||
|
|
||||||
activeRatingFilter = (activeRatingFilter === stars) ? 0 : stars;
|
activeRatingFilter = (activeRatingFilter === stars) ? 0 : stars;
|
||||||
|
|
||||||
document.querySelectorAll('.rating-filter-btn').forEach(btn => {
|
document.querySelectorAll('.rating-filter-btn').forEach(btn => {
|
||||||
const n = parseInt(btn.dataset.stars);
|
const n = parseInt(btn.dataset.stars);
|
||||||
btn.classList.toggle('active', n === activeRatingFilter);
|
btn.classList.toggle('active', n === activeRatingFilter);
|
||||||
@@ -109,6 +117,7 @@ function filterByRating(stars) {
|
|||||||
s.classList.toggle('filled', i < activeRatingFilter);
|
s.classList.toggle('filled', i < activeRatingFilter);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
renderPublicGrid();
|
renderPublicGrid();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,20 +125,18 @@ function renderPublicGrid() {
|
|||||||
const grid = document.getElementById('grid');
|
const grid = document.getElementById('grid');
|
||||||
const emptyState = document.getElementById('empty-state');
|
const emptyState = document.getElementById('empty-state');
|
||||||
const countLabel = document.getElementById('count-label');
|
const countLabel = document.getElementById('count-label');
|
||||||
|
|
||||||
if (!grid) return;
|
if (!grid) return;
|
||||||
grid.innerHTML = '';
|
grid.innerHTML = '';
|
||||||
|
|
||||||
let filtered = films.filter(f => f.type === currentPubTab);
|
let filtered = films.filter(f => f.type === currentPubTab);
|
||||||
|
|
||||||
// 🔥 FILTRE PHYSIQUE UNIQUEMENT (CORRIGÉ)
|
|
||||||
const physicalFilter = document.getElementById('physical-only-checkbox');
|
const physicalFilter = document.getElementById('physical-only-checkbox');
|
||||||
if (physicalFilter && physicalFilter.checked) {
|
if (physicalFilter && physicalFilter.checked) {
|
||||||
filtered = filtered.filter(f => {
|
filtered = filtered.filter(f => {
|
||||||
// Pour les critiques : vérifier le champ streaming
|
|
||||||
if (f.type === 'critique') {
|
if (f.type === 'critique') {
|
||||||
return f.streaming && f.streaming.toLowerCase().includes('support physique');
|
return f.streaming && f.streaming.toLowerCase().includes('support physique');
|
||||||
}
|
}
|
||||||
// Pour la vidéothèque : tout est physique par défaut
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -140,7 +147,7 @@ function renderPublicGrid() {
|
|||||||
return Math.round(rating) === activeRatingFilter;
|
return Math.round(rating) === activeRatingFilter;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentPubTab === 'critique' && activeStreamingFilter) {
|
if (currentPubTab === 'critique' && activeStreamingFilter) {
|
||||||
const filterLower = activeStreamingFilter.toLowerCase();
|
const filterLower = activeStreamingFilter.toLowerCase();
|
||||||
filtered = filtered.filter(f => {
|
filtered = filtered.filter(f => {
|
||||||
@@ -149,7 +156,7 @@ function renderPublicGrid() {
|
|||||||
return platforms.includes(filterLower);
|
return platforms.includes(filterLower);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (searchQuery) {
|
if (searchQuery) {
|
||||||
const q = searchQuery.toLowerCase();
|
const q = searchQuery.toLowerCase();
|
||||||
filtered = filtered.filter(f =>
|
filtered = filtered.filter(f =>
|
||||||
@@ -157,23 +164,24 @@ function renderPublicGrid() {
|
|||||||
(f.director && f.director.toLowerCase().includes(q))
|
(f.director && f.director.toLowerCase().includes(q))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (countLabel) {
|
if (countLabel) {
|
||||||
countLabel.textContent = `${filtered.length} ${currentPubTab === 'critique' ? 'critique' : 'œuvre'}${filtered.length > 1 ? 's' : ''}`;
|
countLabel.textContent = `${filtered.length} ${currentPubTab === 'critique' ? 'critique' : 'œuvre'}${filtered.length > 1 ? 's' : ''}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filtered.length === 0) {
|
if (filtered.length === 0) {
|
||||||
if (emptyState) emptyState.style.display = 'block';
|
if (emptyState) emptyState.style.display = 'block';
|
||||||
renderPagination(0);
|
renderPagination(0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (emptyState) emptyState.style.display = 'none';
|
if (emptyState) emptyState.style.display = 'none';
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
pageItems.forEach(f => {
|
pageItems.forEach(f => {
|
||||||
const card = document.createElement('div');
|
const card = document.createElement('div');
|
||||||
card.className = 'card';
|
card.className = 'card';
|
||||||
@@ -182,7 +190,7 @@ function renderPublicGrid() {
|
|||||||
let posterHTML = f.poster
|
let posterHTML = f.poster
|
||||||
? `<div class="card-poster-wrap"><img class="card-poster" src="${f.poster}" alt="${f.title}" loading="lazy"></div>`
|
? `<div class="card-poster-wrap"><img class="card-poster" src="${f.poster}" alt="${f.title}" loading="lazy"></div>`
|
||||||
: `<div class="card-poster-wrap"><div class="card-poster-placeholder"><i class="ti ti-movie"></i><span>Pas d'affiche</span></div></div>`;
|
: `<div class="card-poster-wrap"><div class="card-poster-placeholder"><i class="ti ti-movie"></i><span>Pas d'affiche</span></div></div>`;
|
||||||
|
|
||||||
if (f.type === 'critique') {
|
if (f.type === 'critique') {
|
||||||
const starsHTML = getStarsHTML(f.rating) + `<span class="card-rating-badge">${parseFloat(f.rating)}</span>`;
|
const starsHTML = getStarsHTML(f.rating) + `<span class="card-rating-badge">${parseFloat(f.rating)}</span>`;
|
||||||
card.innerHTML = `
|
card.innerHTML = `
|
||||||
@@ -206,15 +214,17 @@ function renderPublicGrid() {
|
|||||||
</div>
|
</div>
|
||||||
</div>`;
|
</div>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
grid.appendChild(card);
|
grid.appendChild(card);
|
||||||
});
|
});
|
||||||
|
|
||||||
renderPagination(totalPages);
|
renderPagination(totalPages);
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderPagination(totalPages) {
|
function renderPagination(totalPages) {
|
||||||
const container = document.getElementById('pub-pagination');
|
const container = document.getElementById('pub-pagination');
|
||||||
if (!container) return;
|
if (!container) return;
|
||||||
|
|
||||||
container.innerHTML = '';
|
container.innerHTML = '';
|
||||||
if (totalPages <= 1) return;
|
if (totalPages <= 1) return;
|
||||||
|
|
||||||
@@ -222,31 +232,35 @@ function renderPagination(totalPages) {
|
|||||||
info.className = 'pub-pagination-info';
|
info.className = 'pub-pagination-info';
|
||||||
info.textContent = `Page ${currentPage} / ${totalPages}`;
|
info.textContent = `Page ${currentPage} / ${totalPages}`;
|
||||||
container.appendChild(info);
|
container.appendChild(info);
|
||||||
|
|
||||||
const prevBtn = document.createElement('button');
|
const prevBtn = document.createElement('button');
|
||||||
prevBtn.innerHTML = '<i class="ti ti-chevron-left"></i>';
|
prevBtn.innerHTML = '<i class="ti ti-chevron-left"></i>';
|
||||||
prevBtn.disabled = currentPage === 1;
|
prevBtn.disabled = currentPage === 1;
|
||||||
prevBtn.onclick = () => { currentPage--; renderPublicGrid(); window.scrollTo({ top: 0, behavior: 'smooth' }); };
|
prevBtn.onclick = () => { currentPage--; renderPublicGrid(); window.scrollTo({ top: 0, behavior: 'smooth' }); };
|
||||||
container.appendChild(prevBtn);
|
container.appendChild(prevBtn);
|
||||||
|
|
||||||
const maxButtons = 5;
|
const maxButtons = 5;
|
||||||
let startPage = Math.max(1, currentPage - Math.floor(maxButtons / 2));
|
let startPage = Math.max(1, currentPage - Math.floor(maxButtons / 2));
|
||||||
let endPage = Math.min(totalPages, startPage + maxButtons - 1);
|
let endPage = Math.min(totalPages, startPage + maxButtons - 1);
|
||||||
|
|
||||||
if (endPage - startPage + 1 < maxButtons) {
|
if (endPage - startPage + 1 < maxButtons) {
|
||||||
startPage = Math.max(1, endPage - maxButtons + 1);
|
startPage = Math.max(1, endPage - maxButtons + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (startPage > 1) {
|
if (startPage > 1) {
|
||||||
container.appendChild(createPubPageBtn(1));
|
container.appendChild(createPubPageBtn(1));
|
||||||
if (startPage > 2) container.appendChild(createPubEllipsis());
|
if (startPage > 2) container.appendChild(createPubEllipsis());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = startPage; i <= endPage; i++) {
|
for (let i = startPage; i <= endPage; i++) {
|
||||||
container.appendChild(createPubPageBtn(i));
|
container.appendChild(createPubPageBtn(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (endPage < totalPages) {
|
if (endPage < totalPages) {
|
||||||
if (endPage < totalPages - 1) container.appendChild(createPubEllipsis());
|
if (endPage < totalPages - 1) container.appendChild(createPubEllipsis());
|
||||||
container.appendChild(createPubPageBtn(totalPages));
|
container.appendChild(createPubPageBtn(totalPages));
|
||||||
}
|
}
|
||||||
|
|
||||||
const nextBtn = document.createElement('button');
|
const nextBtn = document.createElement('button');
|
||||||
nextBtn.innerHTML = '<i class="ti ti-chevron-right"></i>';
|
nextBtn.innerHTML = '<i class="ti ti-chevron-right"></i>';
|
||||||
nextBtn.disabled = currentPage === totalPages;
|
nextBtn.disabled = currentPage === totalPages;
|
||||||
@@ -273,6 +287,7 @@ function createPubEllipsis() {
|
|||||||
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;
|
||||||
|
|
||||||
const dPoster = document.getElementById('d-poster');
|
const dPoster = document.getElementById('d-poster');
|
||||||
const dPosterWrap = document.getElementById('d-poster-wrap');
|
const dPosterWrap = document.getElementById('d-poster-wrap');
|
||||||
const dTitle = document.getElementById('d-title');
|
const dTitle = document.getElementById('d-title');
|
||||||
@@ -292,10 +307,10 @@ function openDetail(id) {
|
|||||||
if (dPosterWrap) dPosterWrap.style.display = 'none';
|
if (dPosterWrap) dPosterWrap.style.display = 'none';
|
||||||
if (detailModalLayout) detailModalLayout.classList.add('no-poster');
|
if (detailModalLayout) detailModalLayout.classList.add('no-poster');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dTitle) dTitle.textContent = f.title;
|
if (dTitle) dTitle.textContent = f.title;
|
||||||
if (dMeta) dMeta.textContent = `${f.year ? f.year + ' | ' : ''}${f.director || 'Réalisateur inconnu'}`;
|
if (dMeta) dMeta.textContent = `${f.year ? f.year + ' | ' : ''}${f.director || 'Réalisateur inconnu'}`;
|
||||||
|
|
||||||
if (dBody) {
|
if (dBody) {
|
||||||
if (f.type === 'critique') {
|
if (f.type === 'critique') {
|
||||||
const stars = getStarsHTML(f.rating) + `<span style="font-size:1rem; color:var(--muted); margin-left:0.5rem;">${parseFloat(f.rating)}/5</span>`;
|
const stars = getStarsHTML(f.rating) + `<span style="font-size:1rem; color:var(--muted); margin-left:0.5rem;">${parseFloat(f.rating)}/5</span>`;
|
||||||
@@ -308,25 +323,21 @@ function openDetail(id) {
|
|||||||
${f.streaming ? `<div class="tech-pill" style="margin-top:1.5rem; width:fit-content;"><i class="ti ti-device-tv"></i> Visionnage : ${f.streaming}</div>` : ''}
|
${f.streaming ? `<div class="tech-pill" style="margin-top:1.5rem; width:fit-content;"><i class="ti ti-device-tv"></i> Visionnage : ${f.streaming}</div>` : ''}
|
||||||
`;
|
`;
|
||||||
} else {
|
} else {
|
||||||
// Modification : Ajout du bloc "Casting & Équipe" avec les réalisateurs et acteurs
|
|
||||||
dBody.innerHTML = `
|
dBody.innerHTML = `
|
||||||
<div class="pub-tech-badges">
|
<div class="pub-tech-badges">
|
||||||
${f.format ? `<span class="tech-pill format-gold"><i class="ti ti-disc"></i> ${f.format}</span>` : ''}
|
${f.format ? `<span class="tech-pill format-gold"><i class="ti ti-disc"></i> ${f.format}</span>` : ''}
|
||||||
${f.length ? `<span class="tech-pill"><i class="ti ti-clock"></i> ${f.length} Min</span>` : ''}
|
${f.length ? `<span class="tech-pill"><i class="ti ti-clock"></i> ${f.length} Min</span>` : ''}
|
||||||
${f.number_of_discs ? `<span class="tech-pill"><i class="ti ti-layers-intersect"></i> ${f.number_of_discs} Disque(s)</span>` : ''}
|
${f.number_of_discs ? `<span class="tech-pill"><i class="ti ti-layers-intersect"></i> ${f.number_of_discs} Disque(s)</span>` : ''}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="pub-cast-crew">
|
<div class="pub-cast-crew">
|
||||||
<p><span class="cast-label">Réalisation :</span> <span class="cast-value">${f.director ? f.director : 'Non renseignée'}</span></p>
|
<p><span class="cast-label">Réalisation :</span> <span class="cast-value">${f.director ? f.director : 'Non renseignée'}</span></p>
|
||||||
<p><span class="cast-label">Casting :</span> <span class="cast-value">${f.actors ? f.actors : 'Non renseigné'}</span></p>
|
<p><span class="cast-label">Casting :</span> <span class="cast-value">${f.actors ? f.actors : 'Non renseigné'}</span></p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="pub-tech-grid">
|
<div class="pub-tech-grid">
|
||||||
<div class="tech-meta-item"><span class="tech-meta-label">Éditeur</span><span class="tech-meta-value">${f.publisher || '—'}</span></div>
|
<div class="tech-meta-item"><span class="tech-meta-label">Éditeur</span><span class="tech-meta-value">${f.publisher || '—'}</span></div>
|
||||||
<div class="tech-meta-item"><span class="tech-meta-label">Format Image</span><span class="tech-meta-value">${f.aspect_ratio || '—'}</span></div>
|
<div class="tech-meta-item"><span class="tech-meta-label">Format Image</span><span class="tech-meta-value">${f.aspect_ratio || '—'}</span></div>
|
||||||
<div class="tech-meta-item" style="grid-column: span 2;"><span class="tech-meta-label">Code Barre (EAN)</span><span class="tech-meta-value">${f.ean_isbn13 || '—'}</span></div>
|
<div class="tech-meta-item" style="grid-column: span 2;"><span class="tech-meta-label">Code Barre (EAN)</span><span class="tech-meta-value">${f.ean_isbn13 || '—'}</span></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="pub-synopsis-box">
|
<div class="pub-synopsis-box">
|
||||||
<h4>Synopsis</h4>
|
<h4>Synopsis</h4>
|
||||||
<p>${f.description ? f.description : 'Aucun synopsis disponible pour ce support.'}</p>
|
<p>${f.description ? f.description : 'Aucun synopsis disponible pour ce support.'}</p>
|
||||||
@@ -334,6 +345,7 @@ function openDetail(id) {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (detailOverlay) detailOverlay.classList.add('open');
|
if (detailOverlay) detailOverlay.classList.add('open');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -344,6 +356,7 @@ function closeDetail() {
|
|||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
loadPublicData();
|
loadPublicData();
|
||||||
|
|
||||||
const searchInput = document.getElementById('pub-search-input');
|
const searchInput = document.getElementById('pub-search-input');
|
||||||
if (searchInput) {
|
if (searchInput) {
|
||||||
searchInput.addEventListener('input', (e) => {
|
searchInput.addEventListener('input', (e) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user