templates/bundles/EasyAdminBundle/crud/index.html.twig line 1

Open in your IDE?
  1. {# @var ea \EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext #}
  2. {# @var entities \EasyCorp\Bundle\EasyAdminBundle\Collection\EntityDtoCollection #}
  3. {# @var paginator \EasyCorp\Bundle\EasyAdminBundle\Orm\EntityPaginator #}
  4. {% extends ea.templatePath('layout') %}
  5. {% trans_default_domain ea.i18n.translationDomain %}
  6. {% block body_id entities|length > 0 ? 'ea-index-' ~ entities|first.name : '' %}
  7. {% block body_class 'ea-index' ~ (entities|length > 0 ? ' ea-index-' ~ entities|first.name : '') %}
  8. {% block content_title %}
  9.     {%- apply spaceless -%}
  10.         {% set custom_page_title = ea.crud.customPageTitle('index') %}
  11.         {{ custom_page_title is null
  12.         ? (ea.crud.defaultPageTitle('index')|trans(ea.i18n.translationParameters, 'EasyAdminBundle'))|raw
  13.         : (custom_page_title|trans(ea.i18n.translationParameters))|raw }}
  14.     {%- endapply -%}
  15. {% endblock %}
  16. {% set has_batch_actions = batch_actions|length > 0 %}
  17. {% block page_actions %}
  18.     {% block global_actions %}
  19.         <div class="global-actions">
  20.             {% for action in global_actions%}
  21.                 {%  if action.name != 'export'%}
  22.                     {{ include(action.templatePath, { action: action }, with_context = false) }}
  23.                 {% endif  %}
  24.             {% endfor %}
  25.         </div>
  26.     {% endblock global_actions %}
  27.     {% block batch_actions %}
  28.         {% if has_batch_actions %}
  29.             <div class="batch-actions" style="display: none">
  30.                 {% for action in batch_actions %}
  31.                     {{ include(action.templatePath, { action: action }, with_context = false) }}
  32.                 {% endfor %}
  33.             </div>
  34.         {% endif %}
  35.     {% endblock %}
  36. {% endblock page_actions %}
  37. {% block main %}
  38.     {# sort can be multiple; let's consider the sorting field the first one #}
  39.     {% set sort_field_name = app.request.get('sort')|keys|first %}
  40.     {% set sort_order = app.request.get('sort')|first %}
  41.     {% set some_results_are_hidden = false %}
  42.     {% set has_footer = entities|length != 0 %}
  43.     {% set has_search = ea.crud.isSearchEnabled %}
  44.     {% set has_filters = filters|length > 0 %}
  45.     {% set num_results = entities|length %}
  46.     {% set has_export = false %}
  47.     {% for action in global_actions %}
  48.         {% if action.name == 'export' %}
  49.             {% set has_export = true %}
  50.         {% endif %}
  51.     {% endfor %}
  52.     {% if has_filters %}
  53.         {{ include('@Public/admin/crud/modules/filters.html.twig', {form: filters_form, action_query_array: form_action_query_string_as_array, has_export: has_export}, with_context = false)}}
  54.     {% endif %}
  55.     <table class="table datagrid {{ entities is empty ? 'datagrid-empty' }}">
  56.         {% if num_results > 0 %}
  57.             <thead>
  58.             {% block table_head %}
  59.                 <tr>
  60.                     {% if has_batch_actions %}
  61.                         <th>
  62.                             <div class="form-check">
  63.                                 <span><input type="checkbox" class="form-check-input form-batch-checkbox-all"></span>
  64.                             </div>
  65.                         </th>
  66.                     {% endif %}
  67.                     {% set ea_sort_asc = constant('EasyCorp\\Bundle\\EasyAdminBundle\\Config\\Option\\SortOrder::ASC') %}
  68.                     {% set ea_sort_desc = constant('EasyCorp\\Bundle\\EasyAdminBundle\\Config\\Option\\SortOrder::DESC') %}
  69.                     {% for field in entities|first.fields ?? [] %}
  70.                         {% set is_sorting_field = ea.search.isSortingField(field.property) %}
  71.                         {% set next_sort_direction = is_sorting_field ? (ea.search.sortDirection(field.property) == ea_sort_desc ? ea_sort_asc : ea_sort_desc) : ea_sort_desc %}
  72.                         {% set column_icon = is_sorting_field ? (next_sort_direction == ea_sort_desc ? 'fa-arrow-up' : 'fa-arrow-down') : 'fa-sort' %}
  73.                         <th class="{{ is_sorting_field ? 'sorted' }} {{ field.isVirtual ? 'field-virtual' }} header-for-{{ field.cssClass|split(' ')|filter(class => class starts with 'field-')|join('') }} text-{{ field.textAlign }}" dir="{{ ea.i18n.textDirection }}">
  74.                             {% if field.isSortable %}
  75.                                 <a href="{{ ea_url({ page: 1, sort: { (field.property): next_sort_direction } }).includeReferrer() }}">
  76.                                     {{ field.label|raw }} <i class="fa fa-fw {{ column_icon }}"></i>
  77.                                 </a>
  78.                             {% else %}
  79.                                 <span>{{ field.label|raw }}</span>
  80.                             {% endif %}
  81.                         </th>
  82.                     {% endfor %}
  83.                     <th {% if ea.crud.showEntityActionsAsDropdown %}width="10px"{% endif %} dir="{{ ea.i18n.textDirection }}">
  84.                         <span class="sr-only">{{ 'action.entity_actions'|trans(ea.i18n.translationParameters, 'EasyAdminBundle') }}</span>
  85.                     </th>
  86.                 </tr>
  87.             {% endblock table_head %}
  88.             </thead>
  89.         {% endif %}
  90.         <tbody>
  91.         {% block table_body %}
  92.             {% for entity in entities %}
  93.                 {% if not entity.isAccessible %}
  94.                     {% set some_results_are_hidden = true %}
  95.                 {% else %}
  96.                     <tr data-id="{{ entity.primaryKeyValueAsString }}">
  97.                         {% if has_batch_actions %}
  98.                             <td class="batch-actions-selector">
  99.                                 <div class="form-check">
  100.                                     <input type="checkbox" class="form-check-input form-batch-checkbox" value="{{ entity.primaryKeyValue }}">
  101.                                 </div>
  102.                             </td>
  103.                         {% endif %}
  104.                         {% for field in entity.fields %}
  105.                             <td data-label="{{ field.label|e('html_attr') }}" class="{{ field.property == sort_field_name ? 'sorted' }} text-{{ field.textAlign }} {{ field.cssClass }}" dir="{{ ea.i18n.textDirection }}">
  106.                                 {{ include(field.templatePath, { field: field, entity: entity }, with_context = false) }}
  107.                             </td>
  108.                         {% endfor %}
  109.                         {% block entity_actions %}
  110.                             <td class="actions {{ ea.crud.showEntityActionsAsDropdown ? 'actions-as-dropdown' }}">
  111.                                 {% if entity.actions.count > 0 %}
  112.                                     {% if ea.crud.showEntityActionsAsDropdown %}
  113.                                         <div class="dropdown dropdown-actions">
  114.                                             <a class="dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  115.                                                 {# don't use FontAwesome 'fa-ellipsis-h' icon here because it doesn't look good #}
  116.                                                 {# this icon is 'dots-horizontal' icon from https://heroicons.com/ #}
  117.                                                 <svg xmlns="http://www.w3.org/2000/svg" height="21" width="21" fill="none" viewBox="0 0 24 24" stroke="currentColor">
  118.                                                     <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 12h.01M12 12h.01M19 12h.01M6 12a1 1 0 11-2 0 1 1 0 012 0zm7 0a1 1 0 11-2 0 1 1 0 012 0zm7 0a1 1 0 11-2 0 1 1 0 012 0z" />
  119.                                                 </svg>
  120.                                             </a>
  121.                                             <div class="dropdown-menu dropdown-menu-right">
  122.                                                 {% for action in entity.actions %}
  123.                                                     {{ include(action.templatePath, { action: action, entity: entity, isIncludedInDropdown: ea.crud.showEntityActionsAsDropdown }, with_context = false) }}
  124.                                                 {% endfor %}
  125.                                             </div>
  126.                                         </div>
  127.                                     {% else %}
  128.                                         {% for action in entity.actions %}
  129.                                             {{ include(action.templatePath, { action: action, entity: entity, isIncludedInDropdown: ea.crud.showEntityActionsAsDropdown }, with_context = false) }}
  130.                                         {% endfor %}
  131.                                     {% endif %}
  132.                                 {% endif %}
  133.                             </td>
  134.                         {% endblock entity_actions %}
  135.                     </tr>
  136.                 {% endif %}
  137.             {% else %}
  138.                 {% block table_body_empty %}
  139.                     {% for i in 1..14 %}
  140.                         <tr class="empty-row">
  141.                             <td><span></span></td>
  142.                             <td><span></span></td>
  143.                             <td><span></span></td>
  144.                             <td><span></span></td>
  145.                             <td><span></span></td>
  146.                             <td><span></span></td>
  147.                         </tr>
  148.                         {% if 3 == loop.index %}
  149.                             <tr class="no-results">
  150.                                 <td colspan="100">
  151.                                     {{ 'datagrid.no_results'|trans(ea.i18n.translationParameters, 'EasyAdminBundle') }}
  152.                                 </td>
  153.                             </tr>
  154.                         {% endif %}
  155.                     {% endfor %}
  156.                 {% endblock table_body_empty %}
  157.             {% endfor %}
  158.             {% if some_results_are_hidden %}
  159.                 <tr class="datagrid-row-empty">
  160.                     <td class="text-center" colspan="{{ entities|first.fields|length + 1 }}">
  161.                         <span class="datagrid-row-empty-message"><i class="fa fa-lock mr-1"></i> {{ 'datagrid.hidden_results'|trans({}, 'EasyAdminBundle') }}</span>
  162.                     </td>
  163.                 </tr>
  164.             {% endif %}
  165.         {% endblock table_body %}
  166.         </tbody>
  167.         <tfoot>
  168.         {% block table_footer %}
  169.         {% endblock table_footer %}
  170.         </tfoot>
  171.     </table>
  172.     {% if entities|length > 0 %}
  173.         <div class="content-panel-footer without-padding without-border">
  174.             {% block paginator %}
  175.                 {{ include(ea.templatePath('crud/paginator'), { render_detailed_pagination: not some_results_are_hidden }) }}
  176.             {% endblock paginator %}
  177.         </div>
  178.     {% endif %}
  179.     {% block delete_form %}
  180.         {{ include('@EasyAdmin/crud/includes/_delete_form.html.twig', with_context = false) }}
  181.     {% endblock delete_form %}
  182.     {% if has_batch_actions %}
  183.         {{ include('@EasyAdmin/crud/includes/_batch_action_modal.html.twig', {}, with_context = false) }}
  184.     {% endif %}
  185. {% endblock main %}