Skip to content

Commit

Permalink
fix(bo): use pagination on BO landing page
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabien committed Dec 4, 2024
1 parent 0c8e036 commit 83209d1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import fr.dossierfacile.common.enums.Role;
import fr.dossierfacile.common.service.interfaces.PartnerCallBackService;
import fr.gouv.bo.amqp.Producer;
import fr.gouv.bo.dto.*;
import fr.gouv.bo.dto.BooleanDTO;
import fr.gouv.bo.dto.ReGroupDTO;
import fr.gouv.bo.dto.ResultDTO;
import fr.gouv.bo.service.DocumentService;
import fr.gouv.bo.service.TenantService;
import fr.gouv.bo.service.UserService;
Expand Down Expand Up @@ -38,18 +40,12 @@
@Controller
@RequiredArgsConstructor
public class BOController {
private static final int BUTTONS_TO_SHOW = 5;
private static final String EMAIL = "email";
private static final String PAGER = "pager";
private static final String PAGE_SIZES_STRING = "pageSizes";
private static final String SELECTED_PAGE_SIZE = "selectedPageSize";
private static final String OLDEST_APPLICATION = "oldestApplication";
private static final String REDIRECT_BO_COLOCATION = "redirect:/bo/colocation/";
private static final String SHOW_ALERT = "showAlert";

private static final String INITIAL_PAGE = "0";
private static final String INITIAL_PAGE_SIZE = "100";
private static final int[] PAGE_SIZES = {100, 200};
private static final String INITIAL_PAGE_SIZE = "50";
private static final int[] PAGE_SIZES = {50, 100, 200};
private static final String REDIRECT_BO = "redirect:/bo";
private final TenantService tenantService;
private final UserService userService;
Expand Down Expand Up @@ -106,11 +102,11 @@ public String documentFailedList(Model model,
public String bo(@ModelAttribute("numberOfDocumentsToProcess") ResultDTO numberOfDocumentsToProcess,
Model model,
@RequestParam(value = "pageSize", defaultValue = INITIAL_PAGE_SIZE) int pageSize,
@RequestParam(value = "page", defaultValue = INITIAL_PAGE) int page,
@RequestParam(value = "page", defaultValue = "1") int page,
Principal principal) {

Page<Tenant> tenants = tenantService.listTenantsToProcess(PageRequest.of(page, pageSize));
Pager pager = new Pager(tenants.getTotalPages(), tenants.getNumber(), BUTTONS_TO_SHOW);
Page<Tenant> tenants = tenantService.listTenantsToProcess(PageRequest.of(page - 1, pageSize));

User login_user = userService.findUserByEmail(principal.getName());
boolean is_admin = login_user.getUserRoles().stream().anyMatch(userRole -> userRole.getRole().name().equals(Role.ROLE_ADMIN.name()));
model.addAttribute("numberOfTenantsToProcess", tenantService.countTenantsWithStatusInToProcess());
Expand All @@ -121,9 +117,9 @@ public String bo(@ModelAttribute("numberOfDocumentsToProcess") ResultDTO numberO
model.addAttribute("TenantsWithFailedGeneratedPdf", result);
model.addAttribute("isUserAdmin", is_admin);
model.addAttribute("tenants", tenants);
model.addAttribute(SELECTED_PAGE_SIZE, pageSize);
model.addAttribute(PAGE_SIZES_STRING, PAGE_SIZES);
model.addAttribute(PAGER, pager);
model.addAttribute("pageSize", pageSize);
model.addAttribute("pageSizes", PAGE_SIZES);

model.addAttribute(OLDEST_APPLICATION, tenantService.getOldestToProcessApplication());
return "bo/index";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public Tenant getTenantById(Long id) {

public Page<Tenant> listTenantsToProcess(Pageable pageable) {
LocalDateTime localDateTime = LocalDateTime.now().minusMinutes(timeReprocessApplicationMinutes);
return new PageImpl<>(tenantRepository.findTenantsToProcess(localDateTime, pageable).toList());
return tenantRepository.findTenantsToProcess(localDateTime, pageable);
}

public Tenant find(Long id) {
Expand Down
31 changes: 1 addition & 30 deletions dossierfacile-bo/src/main/resources/templates/bo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -130,36 +130,7 @@
</table>
</div>
<div class="row">
<div class="mb-3 col-md-1">
<select class="form-select form-control pagination pageSizeSelect" data-url="/bo">
<option th:each="pageSize : ${pageSizes}" th:text="${pageSize}" th:value="${pageSize}"
th:selected="${pageSize} == ${selectedPageSize}"></option>
</select>
</div>
<div th:if="${tenants.totalPages > 1}" class="mb-3 col-md-11 pagination-centered">
<ul class="pagination">
<li class="page-item" th:classappend="${tenants.number == 0} ? disabled">
<a class="page-link" th:href="@{/bo(pageSize=${selectedPageSize}, page=1)}">&laquo;</a>
</li>
<li class="page-item" th:classappend="${tenants.number == 0} ? disabled">
<a class="page-link"
th:href="@{/bo(pageSize=${selectedPageSize}, page=${tenants.number})}">&larr;</a>
</li>
<li class="page-item" th:classappend="${tenants.number == (page - 1)} ? 'active pointer-disabled'"
th:each="page : ${#numbers.sequence(pager.startPage, pager.endPage)}">
<a class="page-link" th:href="@{/bo(pageSize=${selectedPageSize}, page=${page})}"
th:text="${page}"></a>
</li>
<li class="page-item" th:classappend="${tenants.number + 1 == tenants.totalPages} ? disabled">
<a class="page-link"
th:href="@{/bo(pageSize=${selectedPageSize}, page=${tenants.number + 2})}">&rarr;</a>
</li>
<li class="page-item" th:classappend="${tenants.number + 1 == tenants.totalPages} ? disabled">
<a class="page-link"
th:href="@{/bo(pageSize=${selectedPageSize}, page=${tenants.totalPages})}">&raquo;</a>
</li>
</ul>
</div>
<div th:replace="~{bo/fragments/pagination :: pagination (items=${tenants}, paramKey='none', paramValue='', pageSizes=${pageSizes}, endpoint='/bo')}"></div>
</div>

</div>
Expand Down

0 comments on commit 83209d1

Please sign in to comment.