feat: paginate the staffing matrix preview

This commit is contained in:
fromme committed 2026-10-16 10:05:42 +02:00
1 parent c7e0ad67e6
commit d159cb212c
3 files changed
+36 -5

No files matched your search

@@ -4,20 +4,24 @@ namespace App\Controller\Admin\System\StaffingRule;
use App\Service\Assignment\StaffingConfigurationException; use App\Service\Assignment\StaffingConfigurationException;
use App\Service\Export\StaffingPreviewExporter; use App\Service\Export\StaffingPreviewExporter;
use Knp\Component\Pager\PaginatorInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted; use Symfony\Component\Security\Http\Attribute\IsGranted;
class PreviewController extends AbstractController 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')] #[Route('/admin/system/staffing-rule/preview', name: 'app_admin_system_staffing_rule_preview')]
#[IsGranted('ROLE_TEAM_ADMIN')] #[IsGranted('ROLE_TEAM_ADMIN')]
public function index(): Response public function index(Request $request): Response
{ {
try { try {
$rows = $this->previewExporter->rows(); $rows = $this->previewExporter->rows();
@@ -27,8 +31,16 @@ class PreviewController extends AbstractController
return $this->redirectToRoute('app_admin_system_staffing_rule_index'); 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', [ return $this->render('admin/system/staffing_rule/preview.html.twig', [
'rows' => $rows, 'pagination' => $pagination,
]); ]);
} }
} }
@@ -33,7 +33,7 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for row in rows %} {% for row in pagination %}
<tr> <tr>
<td>{{ row.productCode }}</td> <td>{{ row.productCode }}</td>
<td> <td>
@@ -72,6 +72,7 @@
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
{{ knp_pagination_render(pagination) }}
</div> </div>
</div> </div>
{% endblock %} {% endblock %}
@@ -100,6 +100,24 @@ class StaffingRuleControllerTest extends WebTestCase
$this->assertStringContainsString('Ski-/Snowboardkurs (pro Stunde)', $content); $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 public function testThePreviewDownloadsAsXlsx(): void
{ {
$this->staffingRule($this->entityManager, 'DKIMP'); $this->staffingRule($this->entityManager, 'DKIMP');