feat: add pagination to equipment and licence search screens
This commit is contained in:
@@ -139,14 +139,25 @@ public class LicenceController {
|
||||
@RequestParam(required = false) String numeroLicence,
|
||||
@RequestParam(required = false) String email,
|
||||
@RequestParam(required = false) String typeDemande,
|
||||
@RequestParam(defaultValue = "0") int page,
|
||||
@RequestParam(defaultValue = "20") int size,
|
||||
org.springframework.ui.Model model) {
|
||||
|
||||
Saison saisonActive = saisonRepository.findByEstActiveTrue().orElse(null);
|
||||
org.springframework.data.jpa.domain.Specification<Licence> spec = buildLicenceSpecification(nom, prenom, categorieId, numeroLicence, email, typeDemande, saisonActive);
|
||||
|
||||
List<Licence> licences = licenceRepository.findAll(spec);
|
||||
List<Licence> allLicences = licenceRepository.findAll(spec);
|
||||
|
||||
model.addAttribute("licences", licences);
|
||||
int totalElements = allLicences.size();
|
||||
int totalPages = (int) Math.ceil((double) totalElements / size);
|
||||
if (page < 0) page = 0;
|
||||
if (page >= totalPages && totalPages > 0) page = totalPages - 1;
|
||||
|
||||
int start = page * size;
|
||||
int end = Math.min(start + size, totalElements);
|
||||
List<Licence> pageContent = (start < totalElements) ? allLicences.subList(start, end) : List.of();
|
||||
|
||||
model.addAttribute("licences", pageContent);
|
||||
model.addAttribute("categories", categorieRepository.findAll());
|
||||
model.addAttribute("nomFilter", nom);
|
||||
model.addAttribute("prenomFilter", prenom);
|
||||
@@ -155,6 +166,11 @@ public class LicenceController {
|
||||
model.addAttribute("emailFilter", email);
|
||||
model.addAttribute("typeDemandeFilter", typeDemande);
|
||||
|
||||
model.addAttribute("currentPage", page);
|
||||
model.addAttribute("totalPages", totalPages);
|
||||
model.addAttribute("totalElements", totalElements);
|
||||
model.addAttribute("pageSize", size);
|
||||
|
||||
return "parametrage/licences_recherche";
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user