Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EZP-28619: Add pagination to Role Assignments and Policies #260

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions src/bundle/Controller/PolicyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
use EzSystems\EzPlatformAdminUi\Form\Factory\FormFactory;
use EzSystems\EzPlatformAdminUi\Form\SubmitHandler;
use EzSystems\EzPlatformAdminUi\Notification\NotificationHandlerInterface;
use Pagerfanta\Adapter\ArrayAdapter;
use Pagerfanta\Pagerfanta;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand Down Expand Up @@ -53,6 +55,9 @@ class PolicyController extends Controller
/** @var SubmitHandler */
private $submitHandler;

/** @var int */
private $defaultPaginationLimit;

/**
* PolicyController constructor.
*
Expand All @@ -63,6 +68,7 @@ class PolicyController extends Controller
* @param PolicyUpdateMapper $policyUpdateMapper
* @param FormFactory $formFactory
* @param SubmitHandler $submitHandler
* @param int $defaultPaginationLimit
*/
public function __construct(
NotificationHandlerInterface $notificationHandler,
Expand All @@ -71,7 +77,8 @@ public function __construct(
PolicyCreateMapper $policyCreateMapper,
PolicyUpdateMapper $policyUpdateMapper,
FormFactory $formFactory,
SubmitHandler $submitHandler
SubmitHandler $submitHandler,
int $defaultPaginationLimit
) {
$this->notificationHandler = $notificationHandler;
$this->translator = $translator;
Expand All @@ -80,11 +87,20 @@ public function __construct(
$this->policyUpdateMapper = $policyUpdateMapper;
$this->formFactory = $formFactory;
$this->submitHandler = $submitHandler;
$this->defaultPaginationLimit = $defaultPaginationLimit;
}

public function listAction(Role $role): Response
public function listAction(Role $role, string $routeName, int $policyPage = 1): Response
{
$policies = $role->getPolicies();
$pagerfanta = new Pagerfanta(
new ArrayAdapter($role->getPolicies())
);

$pagerfanta->setMaxPerPage($this->defaultPaginationLimit);
$pagerfanta->setCurrentPage(min($policyPage, $pagerfanta->getNbPages()));

/** @var Policy[] $policies */
$policies = $pagerfanta->getCurrentPageResults();

$deletePoliciesForm = $this->formFactory->deletePolicies(
new PoliciesDeleteData($role, $this->getPoliciesNumbers($policies))
Expand All @@ -93,6 +109,8 @@ public function listAction(Role $role): Response
return $this->render('@EzPlatformAdminUi/admin/policy/list.html.twig', [
'form_policies_delete' => $deletePoliciesForm->createView(),
'role' => $role,
'pager' => $pagerfanta,
'route_name' => $routeName,
]);
}

Expand Down
32 changes: 28 additions & 4 deletions src/bundle/Controller/RoleAssignmentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
use EzSystems\EzPlatformAdminUi\Form\Factory\FormFactory;
use EzSystems\EzPlatformAdminUi\Form\SubmitHandler;
use EzSystems\EzPlatformAdminUi\Notification\NotificationHandlerInterface;
use Pagerfanta\Adapter\ArrayAdapter;
use Pagerfanta\Pagerfanta;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand All @@ -46,6 +48,9 @@ class RoleAssignmentController extends Controller
/** @var SubmitHandler */
private $submitHandler;

/** @var int */
private $defaultPaginationLimit;

/**
* PolicyController constructor.
*
Expand All @@ -54,24 +59,42 @@ class RoleAssignmentController extends Controller
* @param RoleService $roleService
* @param FormFactory $formFactory
* @param SubmitHandler $submitHandler
* @param int $defaultPaginationLimit
*/
public function __construct(
NotificationHandlerInterface $notificationHandler,
TranslatorInterface $translator,
RoleService $roleService,
FormFactory $formFactory,
SubmitHandler $submitHandler
SubmitHandler $submitHandler,
int $defaultPaginationLimit
) {
$this->notificationHandler = $notificationHandler;
$this->translator = $translator;
$this->roleService = $roleService;
$this->formFactory = $formFactory;
$this->submitHandler = $submitHandler;
$this->defaultPaginationLimit = $defaultPaginationLimit;
}

public function listAction(Role $role): Response
/**
* @param Role $role
* @param string $routeName
* @param int $assignmentPage
*
* @return Response
*/
public function listAction(Role $role, string $routeName, int $assignmentPage = 1): Response
{
$assignments = $this->roleService->getRoleAssignments($role);
$pagerfanta = new Pagerfanta(
new ArrayAdapter($this->roleService->getRoleAssignments($role))
);

$pagerfanta->setMaxPerPage($this->defaultPaginationLimit);
$pagerfanta->setCurrentPage(min($assignmentPage, $pagerfanta->getNbPages()));

/** @var RoleAssignment[] $assignments */
$assignments = $pagerfanta->getCurrentPageResults();

$deleteRoleAssignmentsForm = $this->formFactory->deleteRoleAssignments(
new RoleAssignmentsDeleteData($role, $this->getRoleAssignmentsNumbers($assignments))
Expand All @@ -80,7 +103,8 @@ public function listAction(Role $role): Response
return $this->render('@EzPlatformAdminUi/admin/role_assignment/list.html.twig', [
'role' => $role,
'form_role_assignments_delete' => $deleteRoleAssignmentsForm->createView(),
'assignments' => $assignments,
'pager' => $pagerfanta,
'route_name' => $routeName,
]);
}

Expand Down
16 changes: 15 additions & 1 deletion src/bundle/Controller/RoleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace EzSystems\EzPlatformAdminUiBundle\Controller;

use eZ\Publish\API\Repository\Exceptions\UnauthorizedException as APIUnauthorizedException;
use eZ\Publish\API\Repository\RoleService;
use eZ\Publish\API\Repository\Values\User\Role;
use EzSystems\EzPlatformAdminUi\Form\Data\Role\RoleCreateData;
Expand Down Expand Up @@ -120,7 +121,17 @@ public function listAction(Request $request): Response
]);
}

public function viewAction(Role $role): Response
/**
* @param Request $request
* @param Role $role
* @param int $policyPage
* @param int $assignmentPage
*
* @return Response
*
* @throws APIUnauthorizedException
*/
public function viewAction(Request $request, Role $role, int $policyPage = 1, int $assignmentPage = 1): Response
{
$deleteForm = $this->formFactory->deleteRole(
new RoleDeleteData($role)
Expand All @@ -132,6 +143,9 @@ public function viewAction(Role $role): Response
'role' => $role,
'assignments' => $assignments,
'delete_form' => $deleteForm->createView(),
'route_name' => $request->get('_route'),
'policyPage' => $policyPage,
'assignmentPage' => $assignmentPage,
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public function addSemanticConfig(NodeBuilder $nodeBuilder)
->scalarNode('section_limit')->isRequired()->end()
->scalarNode('language_limit')->isRequired()->end()
->scalarNode('role_limit')->isRequired()->end()
->scalarNode('role_assignment_limit')->isRequired()->end()
->scalarNode('policy_limit')->isRequired()->end()
->scalarNode('content_type_group_limit')->isRequired()->end()
->scalarNode('content_type_limit')->isRequired()->end()
->end()
Expand All @@ -67,6 +69,8 @@ public function mapConfig(array &$scopeSettings, $currentScope, ContextualizerIn
'section_limit',
'language_limit',
'role_limit',
'role_assignment_limit',
'policy_limit',
'content_type_group_limit',
'content_type_limit',
];
Expand Down
2 changes: 2 additions & 0 deletions src/bundle/Resources/config/ezplatform_default_settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ parameters:
ezsettings.default.pagination.role_limit: 10
ezsettings.default.pagination.content_type_group_limit: 10
ezsettings.default.pagination.content_type_limit: 10
ezsettings.default.pagination.role_assignment_limit: 10
ezsettings.default.pagination.policy_limit: 10

# Subitems Module
ezsettings.default.subitems_module.limit: 10
6 changes: 5 additions & 1 deletion src/bundle/Resources/config/routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,16 @@ ezplatform.role.list:
_controller: 'EzPlatformAdminUiBundle:Role:list'

ezplatform.role.view:
path: /role/{roleId}
path: /role/{roleId}/{policyPage}/{assignmentPage}
methods: ['GET']
defaults:
_controller: 'EzPlatformAdminUiBundle:Role:view'
policyPage: 1
assignmentPage: 1
requirements:
roleId: \d+
policyPage: \d+
assignmentPage: \d+

ezplatform.role.create:
path: /role/create
Expand Down
10 changes: 10 additions & 0 deletions src/bundle/Resources/config/services/controllers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,13 @@ services:
public: true
arguments:
$defaultPaginationLimit: '$pagination.role_limit$'

EzSystems\EzPlatformAdminUiBundle\Controller\RoleAssignmentController:
public: true
arguments:
$defaultPaginationLimit: '$pagination.role_assignment_limit$'

EzSystems\EzPlatformAdminUiBundle\Controller\PolicyController:
public: true
arguments:
$defaultPaginationLimit: '$pagination.policy_limit$'
19 changes: 18 additions & 1 deletion src/bundle/Resources/views/admin/policy/list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
</tr>
</thead>
<tbody>
{% for policy in role.policies %}
{% for policy in pager.currentPageResults %}
<tr>
<td class="ez-checkbox-cell">{{ form_widget(form_policies_delete.policies[policy.id]) }}</td>
<td>{{ policy.module|capitalize }}</td>
Expand Down Expand Up @@ -79,4 +79,21 @@
</tbody>
</table>
{{ form_end(form_policies_delete) }}

{% if pager.haveToPaginate %}
<div class="row justify-content-center align-items-center mb-2">
<span>
{{ 'pagination.viewing'|trans({
'%viewing%': pager.currentPageResults|length,
'%total%': pager.nbResults}, 'pagination')|desc('Viewing <strong>%viewing%</strong> out of <strong>%total%</strong> items')|raw }}
</span>
</div>
<div class="row justify-content-center align-items-center">
{{ pagerfanta(pager, 'ez',{
'routeName': route_name,
'routeParams': {'_fragment': 'policies', 'roleId': role.id},
'pageParameter': '[policyPage]',
}) }}
</div>
{% endif %}
</section>
15 changes: 10 additions & 5 deletions src/bundle/Resources/views/admin/role/view.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
iconName: 'roles'
} %}

<ul class="nav nav-tabs ez-nav-tabs--role px-4" role="tablist">
<ul class="nav nav-tabs ez-nav-tabs--role px-4 ez-tabs" role="tablist">
<li role="presentation" class="nav-item">
<a href="#policies" class="nav-link active" role="tab" data-toggle="tab">
{{ 'policy.view.list.title'|trans|desc('Policies') }}
Expand All @@ -34,14 +34,18 @@

{% block content %}
<div class="tab-content">
<div role="tabpanel" class="tab-pane fade show active" id="policies">
<div role="tabpanel" class="tab-pane active" id="policies">
{{ render(controller('EzPlatformAdminUiBundle:Policy:list', {
roleId: role.id
roleId: role.id,
policyPage: policyPage,
routeName: route_name
})) }}
</div>
<div role="tabpanel" class="tab-pane fade" id="users-and-groups">
<div role="tabpanel" class="tab-pane" id="users-and-groups">
{{ render(controller('EzPlatformAdminUiBundle:RoleAssignment:list', {
roleId: role.id
roleId: role.id,
assignmentPage: assignmentPage,
routeName: route_name
})) }}
</div>
</div>
Expand All @@ -50,6 +54,7 @@
{% block javascripts %}
{% javascripts
'@EzPlatformAdminUiBundle/Resources/public/js/scripts/button.state.toggle.js'
'@EzPlatformAdminUiBundle/Resources/public/js/scripts/admin.location.tab.js'
%}
<script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}
Expand Down
19 changes: 18 additions & 1 deletion src/bundle/Resources/views/admin/role_assignment/list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
</tr>
</thead>
<tbody>
{% for role_assignment in assignments %}
{% for role_assignment in pager.currentPageResults %}
<tr>
<td class="ez-checkbox-cell">{{ form_widget(form_role_assignments_delete.role_assignments[role_assignment.id]) }}</td>
<td>
Expand Down Expand Up @@ -72,4 +72,21 @@
</tbody>
</table>
{{ form_end(form_role_assignments_delete) }}

{% if pager.haveToPaginate %}
<div class="row justify-content-center align-items-center mb-2">
<span>
{{ 'pagination.viewing'|trans({
'%viewing%': pager.currentPageResults|length,
'%total%': pager.nbResults}, 'pagination')|desc('Viewing <strong>%viewing%</strong> out of <strong>%total%</strong> items')|raw }}
</span>
</div>
<div class="row justify-content-center align-items-center">
{{ pagerfanta(pager, 'ez',{
'routeName': route_name,
'routeParams': {'_fragment': 'users-and-groups', 'roleId': role.id},
'pageParameter': '[assignmentPage]',
}) }}
</div>
{% endif %}
</section>