Skip to content

Commit

Permalink
feature #1204 Added a new show.max_results config option (javiereguiluz)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the master branch (closes #1204).

Discussion
----------

Added a new show.max_results config option

This new option is consistent with the existing `list.max_results` and it will be used for anything related to limiting the number of items shown, such as the Doctrine associations in the `show` view and the autocomplete fields.

Commits
-------

5b48ad2 Added a new show.max_results config option
  • Loading branch information
javiereguiluz committed Jul 7, 2016
2 parents 277557e + 5b48ad2 commit 0a7f51f
Show file tree
Hide file tree
Showing 158 changed files with 230 additions and 28 deletions.
4 changes: 4 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,10 @@ private function addViewsSection(ArrayNodeDefinition $rootNode)
->prototype('variable')->end()
->info('The list of actions enabled in the "show" view.')
->end()
->integerNode('max_results')
->defaultValue(10)
->info('The maximum number of items displayed for related fields in the show page and for autocomplete fields in the new/edit pages.')
->end()
->end()
->end()
->end()
Expand Down
13 changes: 13 additions & 0 deletions Resources/doc/book/3-list-search-show-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,19 @@ easy_admin:
# ...
```
In addition, the `show` view displays a maximum of 10 items for fields related
with other entities (e.g. if `Category` and `Product` entities are related, it
displays a maximum of 10 products when browsing the details of some category).
Define the `max_results` option under the global `show` key to change this value:
```yaml
# app/config/config.yml
easy_admin:
show:
max_results: 20
# ...
```
### Customize the Properties Displayed
By default, the `show` view displays all the entity properties and the `list`
Expand Down
12 changes: 12 additions & 0 deletions Resources/doc/book/4-edit-new-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,18 @@ By default, the entity's primary key is used for the `id` property and the
must define the `__toString()` method in all the entities used in autocomplete
form fields.
If the number of autocomplete suggestions is large, they are paginated to
display a maximum of `10` results. Define the `show.max_results` option to
change this value:
```yaml
# app/config/config.yml
easy_admin:
show:
max_results: 20
# ...
```
Advanced Form Design
--------------------
Expand Down
24 changes: 21 additions & 3 deletions Resources/doc/book/configuration-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ customize your backends.
[actions](#actions)
* [show](#show)
[actions](#actions)
[max_results](#max_results)
* [entities](#entities)

### easy_admin
Expand Down Expand Up @@ -447,9 +448,26 @@ enabled for this view, as explained above for the `list` view.

### show

Defines the options applied globally for the `show` view of all entities. The
only option available for now is called `actions`, which defines the actions
enabled for this view, as explained above for the `list` view.
Defines the options applied globally for the `show` view of all entities.

#### actions

(**default value**: empty array, **type**: array)

It works as explained above for the `list` view.

#### max_results

(**default value**: 10, **type**: integer)

If some entity property defines a relation with another entity, in the `show`
view this property is displayed as a list of links to the related items. For
example, if your `User` and `Article` entities are related, when displaying the
details of any user you'll also see a list of links to their articles.

This option defines the maximum number of items displayed for those relations,
preventing issues when relations contains lots of elements. This option is also
used as the maximum number of suggestions displayed for autocomplete fields.

### entities

Expand Down
4 changes: 4 additions & 0 deletions Resources/translations/EasyAdminBundle.en.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@
<source>form.are_you_sure</source>
<target>You haven't saved the changes made on this form.</target>
</trans-unit>
<trans-unit id="show.remaining_items">
<source>show.remaining_items</source>
<target><![CDATA[{1} there is another item not displayed in this listing|]1,Inf] %count% other items are not displayed in this listing]]></target>
</trans-unit>
</body>
</file>
</xliff>
4 changes: 4 additions & 0 deletions Resources/translations/EasyAdminBundle.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@
<source>form.are_you_sure</source>
<target>No has guardado los cambios realizados en este formulario.</target>
</trans-unit>
<trans-unit id="show.remaining_items">
<source>show.remaining_items</source>
<target><![CDATA[{1} existe otro elemento que no se muestra en este listado|]1,Inf] existen otros %count% elementos que no se muestran en este listado]]></target>
</trans-unit>
</body>
</file>
</xliff>
34 changes: 17 additions & 17 deletions Resources/views/default/field_association.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
{% if value is iterable %}
{% if 'show' == view %}
{% if value|length > 0 %}
{% if value | length < 15 %}
<ul class="{{ value|length < 2 ? 'inline' }}">
{% for item in value %}
<li>
{% if link_parameters is defined %}
{% set primary_key_value = attribute(item, link_parameters.primary_key_name) %}
<a href="{{ path('easyadmin', link_parameters|merge({ id: primary_key_value, referer: '' })) }}">{{ item }}</a>
{% else %}
{{ item }}
{% endif %}
</li>
{% endfor %}
</ul>
{% else %}
{# Don't use list for large assoc. #}
<span class="badge">{{ value|length }}</span>
{% endif %}
<ul class="{{ value|length < 2 ? 'inline' }}">
{% for item in value|slice(0, easyadmin_config('show.max_results')) %}
<li>
{% if link_parameters is defined %}
{% set primary_key_value = attribute(item, link_parameters.primary_key_name) %}
<a href="{{ path('easyadmin', link_parameters|merge({ id: primary_key_value, referer: '' })) }}">{{ item }}</a>
{% else %}
{{ item }}
{% endif %}
</li>
{% endfor %}

{% set _remaining_items = value|length - easyadmin_config('show.max_results') %}
{% if _remaining_items > 0 %}
<li>({{ 'show.remaining_items'|transchoice(count = _remaining_items, domain = 'EasyAdminBundle') }})</li>
{% endif %}
</ul>
{% else %}
<div class="empty collection-empty">
<span class="label label-empty">{{ 'label.empty'|trans({}, 'EasyAdminBundle') }}</span>
Expand Down
2 changes: 1 addition & 1 deletion Resources/views/form/bootstrap_3_layout.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@
{% block easyadmin_autocomplete_row %}
{{ form_row(form.autocomplete, {
attr: attr|merge({
'data-easyadmin-autocomplete-max-results': easyadmin_config('list.max_results'),
'data-easyadmin-autocomplete-max-results': easyadmin_config('show.max_results'),
'data-easyadmin-autocomplete-url' : path('easyadmin', {
action: 'autocomplete',
entity: easyadmin.entity.name,
Expand Down
2 changes: 1 addition & 1 deletion Search/Autocomplete.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function find($entity, $property, $view, $query, $page = 1)
throw new \InvalidArgumentException(sprintf('The configuration of the "%s" entity is not available (this entity is used as the target of the "%s" autocomplete field in the "%s" view of the "%s" entity).', $targetEntityClass, $property, $view, $entity));
}

$paginator = $this->finder->findByAllProperties($targetEntityConfig, $query, $page, $backendConfig['list']['max_results']);
$paginator = $this->finder->findByAllProperties($targetEntityConfig, $query, $page, $backendConfig['show']['max_results']);

return array('results' => $this->processResults($paginator->getCurrentPageResults(), $targetEntityConfig));
}
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ easy_admin:
label: null
css_class: null
icon: null
max_results: 10
entities:
Category:
class: AppTestBundle\Entity\UnitTests\Category
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ easy_admin:
label: null
css_class: null
icon: null
max_results: 10
entities:
Category:
class: AppTestBundle\Entity\UnitTests\Category
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ easy_admin:
label: null
css_class: null
icon: null
max_results: 10
entities:
Category:
class: AppTestBundle\Entity\UnitTests\Category
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ easy_admin:
label: null
css_class: null
icon: null
max_results: 10
new:
actions:
'-list':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ easy_admin:
label: null
css_class: null
icon: null
max_results: 10
new:
actions:
'-list':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ easy_admin:
label: null
css_class: null
icon: null
max_results: 10
new:
actions:
'-list':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ easy_admin:
label: null
css_class: null
icon: null
max_results: 10
new:
actions:
'-list':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ easy_admin:
label: custom-list-label
css_class: custom-list-class
icon: custom-list-icon
max_results: 10
new:
actions:
list:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ easy_admin:
label: null
css_class: null
icon: null
max_results: 10
new:
actions:
custom_action_for_new:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ easy_admin:
label: null
css_class: null
icon: null
max_results: 10
new:
actions:
'-custom_action_for_new':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ easy_admin:
label: custom-show-label
css_class: custom-show-class
icon: custom-show-icon
max_results: 10
new:
actions:
custom_action_for_new:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ easy_admin:
label: null
css_class: null
icon: null
max_results: 10
new:
actions:
'-list':
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ easy_admin:
label: action.edit
css_class: 'btn btn-primary'
icon: edit
max_results: 10
new:
actions:
list:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ easy_admin:
label: null
css_class: null
icon: null
max_results: 10
new:
actions:
custom_new_action:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ easy_admin:
label: action.edit
css_class: 'btn btn-primary'
icon: edit
max_results: 10
new:
actions:
list:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ easy_admin:
label: null
css_class: null
icon: null
max_results: 10
new:
actions:
custom_new_action:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ easy_admin:
label: action.edit
css_class: 'btn btn-primary'
icon: edit
max_results: 10
new:
actions:
list:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ easy_admin:
label: null
css_class: null
icon: null
max_results: 10
new:
actions:
custom_new_action:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ easy_admin:
label: action.edit
css_class: 'btn btn-primary'
icon: edit
max_results: 10
new:
actions:
list:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ easy_admin:
label: null
css_class: null
icon: null
max_results: 10
new:
actions:
custom_new_action:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ easy_admin:
label: 'Global Edit Label'
css_class: 'btn btn-primary'
icon: global-edit-icon
max_results: 10
new:
actions:
list:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ easy_admin:
label: null
css_class: null
icon: null
max_results: 10
new:
actions:
CamelCaseAction:
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ easy_admin:
label: action.edit
css_class: 'btn btn-primary'
icon: edit
max_results: 10
entities:
Category:
class: AppTestBundle\Entity\UnitTests\Category
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ easy_admin:
label: action.edit
css_class: 'btn btn-primary'
icon: edit
max_results: 10
entities:
Category:
class: AppTestBundle\Entity\UnitTests\Category
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Tests/Controller/AutocompleteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ public function testAutocompleteText()
'query' => 'Parent Categ',
));

// the results are the first 15 parent categories
// the results are the first 10 parent categories
$response = json_decode($this->client->getResponse()->getContent(), true);
foreach (range(1, 15) as $i) {
foreach (range(1, 10) as $i) {
$this->assertEquals($i, $response['results'][$i-1]['id']);
$this->assertEquals('Parent Category #'.$i, $response['results'][$i-1]['text']);
}
Expand Down
8 changes: 4 additions & 4 deletions Tests/Search/AutocompleteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ public function testAutocompleteText()
// the query is 'Parent Categ' instead of 'Parent Category' to better test the autocomplete
$autocomplete = $this->client->getContainer()->get('easyadmin.autocomplete')->find('Category', 'parent', 'edit', 'Parent Categ');

// the results are the first 15 parent categories
foreach (range(1, 15) as $i => $n) {
// the results are the first batch of 10 parent categories
foreach (range(1, 10) as $i => $n) {
$this->assertEquals($n, $autocomplete['results'][$i]['id']);
$this->assertEquals('Parent Category #'.$n, $autocomplete['results'][$i]['text']);
}
Expand All @@ -100,8 +100,8 @@ public function testAutocompletePaginator()
// testing page 2
$autocomplete = $this->client->getContainer()->get('easyadmin.autocomplete')->find('Category', 'parent', 'edit', 'Parent Categ', 2);

// the results are the seconds 15 parent categories
foreach (range(16, 30) as $i => $n) {
// the results are the second batch of 10 parent categories
foreach (range(11, 20) as $i => $n) {
$this->assertEquals($n, $autocomplete['results'][$i]['id']);
$this->assertEquals('Parent Category #'.$n, $autocomplete['results'][$i]['text']);
}
Expand Down

0 comments on commit 0a7f51f

Please sign in to comment.