diff --git a/src/Controller/Admin/System/StaffingRule/PreviewController.php b/src/Controller/Admin/System/StaffingRule/PreviewController.php index a9025ee..0cd17f7 100644 --- a/src/Controller/Admin/System/StaffingRule/PreviewController.php +++ b/src/Controller/Admin/System/StaffingRule/PreviewController.php @@ -4,20 +4,24 @@ namespace App\Controller\Admin\System\StaffingRule; use App\Service\Assignment\StaffingConfigurationException; use App\Service\Export\StaffingPreviewExporter; +use Knp\Component\Pager\PaginatorInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\Security\Http\Attribute\IsGranted; class PreviewController extends AbstractController { - public function __construct(private readonly StaffingPreviewExporter $previewExporter) - { + public function __construct( + private readonly StaffingPreviewExporter $previewExporter, + private readonly PaginatorInterface $paginator, + ) { } #[Route('/admin/system/staffing-rule/preview', name: 'app_admin_system_staffing_rule_preview')] #[IsGranted('ROLE_TEAM_ADMIN')] - public function index(): Response + public function index(Request $request): Response { try { $rows = $this->previewExporter->rows(); @@ -27,8 +31,16 @@ class PreviewController extends AbstractController return $this->redirectToRoute('app_admin_system_staffing_rule_index'); } + // The candidates are a computed list, not a query: page the finished rows. The Excel + // export stays the full list. + $pagination = $this->paginator->paginate( + $rows, + $request->query->getInt('page', 1), + $request->query->getInt('limit', 50), + ); + return $this->render('admin/system/staffing_rule/preview.html.twig', [ - 'rows' => $rows, + 'pagination' => $pagination, ]); } } diff --git a/templates/admin/system/staffing_rule/preview.html.twig b/templates/admin/system/staffing_rule/preview.html.twig index d64ecb7..9e7987c 100644 --- a/templates/admin/system/staffing_rule/preview.html.twig +++ b/templates/admin/system/staffing_rule/preview.html.twig @@ -33,7 +33,7 @@ - {% for row in rows %} + {% for row in pagination %} {{ row.productCode }} @@ -72,6 +72,7 @@ {% endfor %} + {{ knp_pagination_render(pagination) }} {% endblock %} diff --git a/tests/Controller/Admin/System/StaffingRule/StaffingRuleControllerTest.php b/tests/Controller/Admin/System/StaffingRule/StaffingRuleControllerTest.php index 2f146dc..43af45a 100644 --- a/tests/Controller/Admin/System/StaffingRule/StaffingRuleControllerTest.php +++ b/tests/Controller/Admin/System/StaffingRule/StaffingRuleControllerTest.php @@ -100,6 +100,24 @@ class StaffingRuleControllerTest extends WebTestCase $this->assertStringContainsString('Ski-/Snowboardkurs (pro Stunde)', $content); } + public function testThePreviewIsPaginated(): void + { + $this->staffingRule($this->entityManager, 'DKIMP'); + $this->staffingRule($this->entityManager, 'DGSMP'); + $this->staffingDestination($this->entityManager, 'DKIMP110127', 'DKIMP'); + $this->staffingDestination($this->entityManager, 'DGSMP110127', 'DGSMP'); + $this->entityManager->flush(); + + // same date: ordered by product code + $this->client->request('GET', '/admin/system/staffing-rule/preview?limit=1&page=2'); + + $content = (string) $this->client->getResponse()->getContent(); + + $this->assertSame(Response::HTTP_OK, $this->client->getResponse()->getStatusCode()); + $this->assertStringContainsString('DKIMP110127', $content); + $this->assertStringNotContainsString('DGSMP110127', $content); + } + public function testThePreviewDownloadsAsXlsx(): void { $this->staffingRule($this->entityManager, 'DKIMP');