From c01f3525ff3c392f07ace6f048ab46943de9c1c1 Mon Sep 17 00:00:00 2001 From: "mathis.moulin" Date: Thu, 5 Jun 2025 08:21:14 +0200 Subject: [PATCH] =?UTF-8?q?Ajout=202=20ligne=20=C3=A9moji=20+=20pagination?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/css/home.css | 33 ++++++++++++++++ public/js/home.js | 63 +++++++++++++++++++++++++++++++ src/Controller/HomeController.php | 35 ++++++++++++++++- templates/home/index.html.twig | 4 +- 4 files changed, 133 insertions(+), 2 deletions(-) diff --git a/public/css/home.css b/public/css/home.css index 33e7935..f0e0550 100644 --- a/public/css/home.css +++ b/public/css/home.css @@ -278,4 +278,37 @@ color: #555; .vs-text { font-size: 1.5rem; font-weight: bold; +} + +/* Pagination */ + +.pagination-bar { + margin: 4rem 4rem; + display: flex; + justify-content: center; + align-items: center; + gap: 10px; + color: #f8f5e0; + font-family: 'Georgia', serif; +} + +.pagination-bar button { + background: none; + border: none; + font-size: 1.1rem; + color: #f8f5e0; + cursor: pointer; + padding: 5px 10px; + border-radius: 50%; + transition: background 0.2s ease; +} + +.pagination-bar button.active { + background: #333; + color: white; + font-weight: bold; +} + +.pagination-bar button:hover:not(.active) { + color: #f8b435; } \ No newline at end of file diff --git a/public/js/home.js b/public/js/home.js index 0bb1623..9d92bc5 100644 --- a/public/js/home.js +++ b/public/js/home.js @@ -111,6 +111,7 @@ document.addEventListener('DOMContentLoaded', () => { }); visibleCards.forEach(card => container.appendChild(card)); + paginateCards(); } } @@ -147,4 +148,66 @@ document.addEventListener('DOMContentLoaded', () => { document.getElementById('search-input').addEventListener('input', applyFilters); document.getElementById('rarete-filter').addEventListener('change', applyFilters); document.getElementById('sort-select').addEventListener('change', applyFilters); + + /***** Partie Pagination ******/ + + const ITEMS_PER_PAGE = 10; + let currentPage = 1; + + function paginateCards() { + const allCards = Array.from(document.querySelectorAll('#collection-container .emoji-card')); + const container = document.getElementById('collection-container'); + const totalPages = Math.ceil(allCards.length / ITEMS_PER_PAGE); + + // Masquer toutes les cartes + allCards.forEach(card => card.style.display = 'none'); + + // Afficher uniquement les cartes de la page courante + const start = (currentPage - 1) * ITEMS_PER_PAGE; + const end = start + ITEMS_PER_PAGE; + + allCards.slice(start, end).forEach(card => card.style.display = 'block'); + + renderPagination(totalPages); + } + + function renderPagination(totalPages) { + const pagination = document.getElementById('pagination'); + pagination.innerHTML = ''; + + const addBtn = (text, page = null, isActive = false, disabled = false) => { + const btn = document.createElement('button'); + btn.textContent = text; + if (isActive) btn.classList.add('active'); + if (disabled) btn.disabled = true; + if (page !== null) { + btn.addEventListener('click', () => { + currentPage = page; + paginateCards(); + }); + } + pagination.appendChild(btn); + }; + + addBtn('Précédent', currentPage - 1, false, currentPage === 1); + + for (let i = 1; i <= totalPages; i++) { + if ( + i === 1 || + i === totalPages || + (i >= currentPage - 1 && i <= currentPage + 1) + ) { + addBtn(i, i, i === currentPage); + } else if ( + i === 2 && currentPage > 3 || + i === totalPages - 1 && currentPage < totalPages - 2 + ) { + addBtn('...'); + } + } + + addBtn('Suivant', currentPage + 1, false, currentPage === totalPages); + } + + paginateCards(); }); \ No newline at end of file diff --git a/src/Controller/HomeController.php b/src/Controller/HomeController.php index c760e76..170ef39 100644 --- a/src/Controller/HomeController.php +++ b/src/Controller/HomeController.php @@ -146,7 +146,40 @@ class HomeController extends AbstractController 'vitesse' => 4.5, 'nbCombatGagne' => 1, 'rarete' => 1, // commun - ] + ], + [ + 'id' => 13, + 'nom' => 'George', + 'code' => '😜', + 'force' => 11.0, + 'robustesse' => 10.0, + 'intelligence' => 12.0, + 'vitesse' => 13.5, + 'nbCombatGagne' => 2, + 'rarete' => 2, // épique + ], + [ + 'id' => 14, + 'nom' => 'Hannah', + 'code' => '😏', + 'force' => 3.0, + 'robustesse' => 2.5, + 'intelligence' => 4.0, + 'vitesse' => 3.5, + 'nbCombatGagne' => 0, + 'rarete' => 1, // commun + ], + [ + 'id' => 15, + 'nom' => 'Ian', + 'code' => '😬', + 'force' => 17.0, + 'robustesse' => 14.0, + 'intelligence' => 16.0, + 'vitesse' => 18.0, + 'nbCombatGagne' => 7, + 'rarete' => 4, // légendaire + ], ]; foreach ($emojisDeBase as &$emoji) { diff --git a/templates/home/index.html.twig b/templates/home/index.html.twig index a28ae63..2f191c6 100644 --- a/templates/home/index.html.twig +++ b/templates/home/index.html.twig @@ -21,7 +21,7 @@ data-level="{{ emoji.nbCombatGagne }}" data-force="{{ emoji.force }}" data-vitesse="{{ emoji.vitesse }}"> - +
Level {{ emoji.nbCombatGagne }}
{{ emoji.code }}
{{ emoji.nom }}
@@ -90,6 +90,8 @@ {% endfor %} + +
Sélectionnez 2 créatures de votre choix pour commencer ...