Skip to content

Commit

Permalink
EZP-28955: Adding pagination to URL Aliases in the URL alias tab
Browse files Browse the repository at this point in the history
  • Loading branch information
ViniTou committed Mar 30, 2018
1 parent 1101d28 commit 0a8e13d
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 63 deletions.
36 changes: 36 additions & 0 deletions src/bundle/Controller/ContentViewController.php
Expand Up @@ -94,6 +94,8 @@ public function locationViewAction(Request $request, ContentView $view)
$this->supplyContentActionForms($view);

$this->supplyDraftPagination($view, $request);
$this->supplyCustomUrlPagination($view, $request);
$this->supplySystemUrlPagination($view, $request);

return $view;
}
Expand Down Expand Up @@ -202,6 +204,40 @@ private function supplyDraftPagination(ContentView $view, Request $request): voi
]);
}

/**
* @param \eZ\Publish\Core\MVC\Symfony\View\ContentView $view
* @param \Symfony\Component\HttpFoundation\Request $request
*/
private function supplyCustomUrlPagination(ContentView $view, Request $request): void
{
$page = $request->query->get('page');

$view->addParameters([
'custom_urls_pagination_params' => [
'route_name' => $request->get('_route'),
'page' => $page['custom_url'] ?? 1,
'limit' => $this->defaultPaginationLimit,
],
]);
}

/**
* @param \eZ\Publish\Core\MVC\Symfony\View\ContentView $view
* @param \Symfony\Component\HttpFoundation\Request $request
*/
private function supplySystemUrlPagination(ContentView $view, Request $request): void
{
$page = $request->query->get('page');

$view->addParameters([
'system_urls_pagination_params' => [
'route_name' => $request->get('_route'),
'page' => $page['system_url'] ?? 1,
'limit' => $this->defaultPaginationLimit,
],
]);
}

/**
* @param Location|null $location
*
Expand Down
4 changes: 3 additions & 1 deletion src/bundle/Resources/views/content/locationview.html.twig
Expand Up @@ -48,7 +48,9 @@
'content': content,
'location': location,
'contentType': contentType,
'draft_pagination_params': draft_pagination_params
'draft_pagination_params': draft_pagination_params,
'custom_urls_pagination_params': custom_urls_pagination_params,
'system_urls_pagination_params': system_urls_pagination_params
}, 'EzPlatformAdminUiBundle:parts/tab:locationview.html.twig') }}

{% if contentType.isContainer %}
Expand Down
10 changes: 10 additions & 0 deletions src/bundle/Resources/views/content/tab/pagination.html.twig
@@ -0,0 +1,10 @@
<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 mb-3">
{{ pagerfanta(pager, 'ez', paginatonParams) }}
</div>
@@ -0,0 +1,36 @@
{% trans_default_domain 'content_url' %}
{% form_theme form_custom_url_remove '@EzPlatformAdminUi/parts/form/flat_widgets.html.twig' %}

{{ form_start(form_custom_url_remove, {
'action': path('ezplatform.custom_url.remove'),
'attr': { 'class': 'ez-toggle-btn-state', 'data-toggle-button-id': '#delete-custom-urls' }
}) }}
<table class="table">
<thead>
<tr>
<th></th>
<th>{{ 'tab.urls.url'|trans|desc('URL') }}</th>
<th>{{ 'tab.urls.language'|trans|desc('Language') }}</th>
<th>{{ 'tab.urls.type'|trans|desc('Type') }}</th>
</tr>
</thead>
<tbody>
{% for custom_url in custom_urls_pager.currentPageResults %}
<tr>
<td class="ez-checkbox-cell">{{ form_widget(form_custom_url_remove.url_aliases[custom_url.id]) }}</td>
<td>{{ custom_url.path }}</td>
<td>
{% for languageCode in custom_url.languageCodes %}{{ admin_ui_config.languages.mappings[languageCode].name }}<br>{% endfor %}
</td>
<td>
{% if custom_url.forward %}
{{ 'tab.urls.type.redirect'|trans|desc('Redirect') }}
{% else %}
{{ 'tab.urls.type.direct'|trans|desc('Direct') }}
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
{{ form_end(form_custom_url_remove) }}
@@ -0,0 +1,21 @@
{% trans_default_domain 'content_url' %}

<table class="table">
<thead>
<tr>
<th>{{ 'tab.urls.url'|trans|desc('URL') }}</th>
<th>{{ 'tab.urls.language'|trans|desc('Language') }}</th>
</tr>
</thead>
<tbody>
{% for system_url in system_urls_pager.currentPageResults %}
<tr>
<td>{{ system_url.path }}</td>
<td>
{% for languageCode in system_url.languageCodes %}{{ admin_ui_config.languages.mappings[languageCode].name }}<br>{% endfor %}
</td>
</tr>
{% endfor %}
</tbody>
</table>

@@ -1,76 +1,60 @@
{% trans_default_domain 'content_url' %}
{% import _self as tab %}
{% include '@EzPlatformAdminUi/parts/table_header.html.twig' with { headerText: 'tab.urls.custom_url_aliases'|trans({'%contentName%' : ez_content_name(content)})|desc('Custom URL aliases for %contentName%'), tools: tab.table_header_tools(form_custom_url_remove) } %}
{% form_theme form_custom_url_remove '@EzPlatformAdminUi/parts/form/flat_widgets.html.twig' %}

{% if custom_urls is not empty %}
{{ form_start(form_custom_url_remove, {
'action': path('ezplatform.custom_url.remove'),
'attr': { 'class': 'ez-toggle-btn-state', 'data-toggle-button-id': '#delete-custom-urls' }
{% if custom_urls_pager.currentPageResults is not empty %}
{{ include('@EzPlatformAdminUi/content/tab/url/custom_urls_table.html.twig', {
'custom_urls_pager': custom_urls_pager,
'form_custom_url_remove': form_custom_url_remove,
}) }}
<table class="table">
<thead>
<tr>
<th></th>
<th>{{ 'tab.urls.url'|trans|desc('URL') }}</th>
<th>{{ 'tab.urls.language'|trans|desc('Language') }}</th>
<th>{{ 'tab.urls.type'|trans|desc('Type') }}</th>
</tr>
</thead>
<tbody>
{% for custom_url in custom_urls %}
<tr>
<td class="ez-checkbox-cell">{{ form_widget(form_custom_url_remove.url_aliases[custom_url.id]) }}</td>
<td>{{ custom_url.path }}</td>
<td>
{% for languageCode in custom_url.languageCodes %}{{ admin_ui_config.languages.mappings[languageCode].name }}<br>{% endfor %}
</td>
<td>
{% if custom_url.forward %}
{{ 'tab.urls.type.redirect'|trans|desc('Redirect') }}
{% else %}
{{ 'tab.urls.type.direct'|trans|desc('Direct') }}
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
{{ form_end(form_custom_url_remove) }}

{% else %}
<p class="ez-table-no-content">
{{ 'tab.urls.no_custom_urls'|trans|desc('This content item has no custom url aliases.') }}
</p>
{% endif %}

{% if custom_urls_pager.haveToPaginate %}
{{ include('@EzPlatformAdminUi/content/tab/pagination.html.twig', {
'pager': custom_urls_pager,
'paginatonParams': {
'routeName': custom_urls_pagination_params.route_name,
'routeParams': {
'_fragment': constant('EzSystems\\EzPlatformAdminUi\\Tab\\LocationView\\UrlsTab::URI_FRAGMENT'),
'locationId': location.id,
'page[system_url]': system_urls_pagination_params.page
},
'pageParameter': '[page][custom_url]'
}
}) }}
{% endif %}

{% include '@EzPlatformAdminUi/parts/table_header.html.twig' with { headerText: 'tab.urls.system.title'|trans|desc('System URL') } %}

{% if system_urls is defined %}
<table class="table">
<thead>
<tr>
<th>{{ 'tab.urls.url'|trans|desc('URL') }}</th>
<th>{{ 'tab.urls.language'|trans|desc('Language') }}</th>
</tr>
</thead>
<tbody>
{% for system_url in system_urls %}
<tr>
<td>{{ system_url.path }}</td>
<td>
{% for languageCode in system_url.languageCodes %}{{ admin_ui_config.languages.mappings[languageCode].name }}<br>{% endfor %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% if system_urls_pager.currentPageResults is not empty %}
{{ include('@EzPlatformAdminUi/content/tab/url/system_urls_table.html.twig', {
'system_urls_pager': system_urls_pager,
}) }}
{% else %}
<p class="ez-table-no-content">
{{ 'tab.urls.no_system_urls'|trans|desc('This content item has no system urls.') }}
</p>
{% endif %}

{% if system_urls_pager.haveToPaginate %}
{{ include('@EzPlatformAdminUi/content/tab/pagination.html.twig', {
'pager': system_urls_pager,
'paginatonParams': {
'routeName': system_urls_pagination_params.route_name,
'routeParams': {
'_fragment': constant('EzSystems\\EzPlatformAdminUi\\Tab\\LocationView\\UrlsTab::URI_FRAGMENT'),
'locationId': location.id,
'page[custom_url]': custom_urls_pagination_params.page
},
'pageParameter': '[page][system_url]'
}
}) }}
{% endif %}

{% include '@EzPlatformAdminUi/content/tab/url/modal_add_custom_url.html.twig' with {'form': form_custom_url_add, 'parent_name': parent_name} only %}

{% macro table_header_tools(form_custom_url_remove) %}
Expand Down Expand Up @@ -101,4 +85,4 @@
%}
<script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}
{% endblock %}
{% endblock %}
35 changes: 28 additions & 7 deletions src/lib/Tab/LocationView/UrlsTab.php
Expand Up @@ -17,6 +17,8 @@
use EzSystems\EzPlatformAdminUi\Tab\AbstractTab;
use EzSystems\EzPlatformAdminUi\Tab\OrderedTabInterface;
use EzSystems\EzPlatformAdminUi\UI\Dataset\DatasetFactory;
use Pagerfanta\Adapter\ArrayAdapter;
use Pagerfanta\Pagerfanta;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Translation\TranslatorInterface;
use Twig\Environment;
Expand Down Expand Up @@ -99,23 +101,42 @@ public function renderView(array $parameters): string
/** @var \eZ\Publish\API\Repository\Values\Content\Location $location */
$location = $parameters['location'];

$translationsDataset = $this->datasetFactory->customUrls();
$translationsDataset->load($location);
$customUrlAliases = $translationsDataset->getCustomUrlAliases();
$customUrlsPaginationParams = $parameters['custom_urls_pagination_params'];
$systemUrlsPaginationParams = $parameters['system_urls_pagination_params'];

$customUrlsDataset = $this->datasetFactory->customUrls();
$customUrlsDataset->load($location);

$customUrlPagerfanta = new Pagerfanta(
new ArrayAdapter($customUrlsDataset->getCustomUrlAliases())
);

$customUrlPagerfanta->setMaxPerPage($customUrlsPaginationParams['limit']);
$customUrlPagerfanta->setCurrentPage(min($customUrlsPaginationParams['page'], $customUrlPagerfanta->getNbPages()));

$systemUrlPagerfanta = new Pagerfanta(
new ArrayAdapter($this->urlAliasService->listLocationAliases($location, false))
);

$systemUrlPagerfanta->setMaxPerPage($systemUrlsPaginationParams['limit']);
$systemUrlPagerfanta->setCurrentPage(min($systemUrlsPaginationParams['page'], $systemUrlPagerfanta->getNbPages()));

$customUrlAddForm = $this->createCustomUrlAddForm($location);
$customUrlRemoveForm = $this->createCustomUrlRemoveForm($location, $customUrlAliases);
$customUrlRemoveForm = $this->createCustomUrlRemoveForm($location, $customUrlPagerfanta->getCurrentPageResults());
$parentLocation = $this->locationService->loadLocation($location->parentLocationId);

$viewParameters = [
'custom_urls' => $this->urlAliasService->listLocationAliases($location, true, null, true),
'system_urls' => $this->urlAliasService->listLocationAliases($location, false),
'form_custom_url_add' => $customUrlAddForm->createView(),
'form_custom_url_remove' => $customUrlRemoveForm->createView(),
'parent_name' => $parentLocation->contentInfo->name,
'custom_urls_pager' => $customUrlPagerfanta,
'custom_urls_pagination_params' => $customUrlsPaginationParams,
'system_urls_pager' => $systemUrlPagerfanta,
'system_urls_pagination_params' => $systemUrlsPaginationParams,
];

return $this->twig->render(
'EzPlatformAdminUiBundle:content/tab:urls.html.twig',
'EzPlatformAdminUiBundle:content/tab/url:tab.html.twig',
array_merge($viewParameters, $parameters)
);
}
Expand Down

0 comments on commit 0a8e13d

Please sign in to comment.