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

  1. {# @var ea \EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext #}
  2. {# @var entities \EasyCorp\Bundle\EasyAdminBundle\Collection\EntityCollection #}
  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. {% set ea_field_assets = ea.crud.fieldAssets(constant('EasyCorp\\Bundle\\EasyAdminBundle\\Config\\Crud::PAGE_INDEX')) %}
  9. {% block configured_head_contents %}
  10.     {{ parent() }}
  11.     {% for htmlContent in ea_field_assets.headContents %}
  12.         {{ htmlContent|raw }}
  13.     {% endfor %}
  14. {% endblock %}
  15. {% block configured_body_contents %}
  16.     {{ parent() }}
  17.     {% for htmlContent in ea_field_assets.bodyContents %}
  18.         {{ htmlContent|raw }}
  19.     {% endfor %}
  20. {% endblock %}
  21. {% block configured_stylesheets %}
  22.     {{ parent() }}
  23.     {{ include('@EasyAdmin/includes/_css_assets.html.twig', { assets: ea_field_assets.cssAssets }, with_context = false) }}
  24.     {{ include('@EasyAdmin/includes/_encore_link_tags.html.twig', { assets: ea_field_assets.webpackEncoreAssets }, with_context = false) }}
  25. {% endblock %}
  26. {% block content_title %}
  27.     {%- apply spaceless -%}
  28.         {% set custom_page_title = ea.crud.customPageTitle('index', null, ea.i18n.translationParameters) %}
  29.         {{ custom_page_title is null
  30.             ? ea.crud.defaultPageTitle('index', null, ea.i18n.translationParameters)|trans|raw
  31.             : custom_page_title|trans|raw }}
  32.     {%- endapply -%}
  33. {% endblock %}
  34. {% set has_batch_actions = batch_actions|length > 0 %}
  35. {% block page_actions %}
  36.     {% if filters|length > 0 %}
  37.         <div class="datagrid-filters">
  38.             {% block filters %}
  39.                 {% set applied_filters = ea.request.query.all['filters']|default([])|keys %}
  40.                 <div class="btn-group action-filters">
  41.                     <a href="#" data-href="{{ ea_url().setAction('renderFilters').includeReferrer() }}" class="btn btn-secondary btn-labeled btn-labeled-right action-filters-button disabled {{ applied_filters ? 'action-filters-applied' }}" data-bs-toggle="modal" data-bs-target="#modal-filters">
  42.                         <i class="fa fa-filter fa-fw"></i> {{ t('filter.title', ea.i18n.translationParameters, 'EasyAdminBundle')|trans }}{% if applied_filters %} <span class="action-filters-button-count">({{ applied_filters|length }})</span>{% endif %}
  43.                     </a>
  44.                     {% if applied_filters %}
  45.                         <a href="{{ ea_url().unset('filters') }}" class="btn btn-secondary action-filters-reset">
  46.                             <i class="fa fa-close"></i>
  47.                         </a>
  48.                     {% endif %}
  49.                 </div>
  50.             {% endblock filters %}
  51.         </div>
  52.     {% endif %}
  53.     {% block global_actions %}
  54.         <div class="global-actions">
  55.             {% for action in global_actions %}
  56.                 {{ include(action.templatePath, { action: action }, with_context = false) }}
  57.             {% endfor %}
  58.         </div>
  59.     {% endblock global_actions %}
  60.     {% block batch_actions %}
  61.         {% if has_batch_actions %}
  62.             <div class="batch-actions d-none">
  63.                 {% for action in batch_actions %}
  64.                     {{ include(action.templatePath, { action: action }, with_context = false) }}
  65.                 {% endfor %}
  66.             </div>
  67.         {% endif %}
  68.     {% endblock %}
  69. {% endblock page_actions %}
  70. {% block main %}
  71.     {# sort can be multiple; let's consider the sorting field the first one #}
  72.     {% set sort_field_name = app.request.get('sort')|keys|first %}
  73.     {% set sort_order = app.request.get('sort')|first %}
  74.     {% set some_results_are_hidden = entities|reduce((some_results_are_hidden, entity) => some_results_are_hidden or not entity.isAccessible, false) %}
  75.     {% set has_footer = entities|length != 0 %}
  76.     {% set has_search = ea.crud.isSearchEnabled %}
  77.     {% set has_filters = filters|length > 0 %}
  78.     {% set num_results = entities|length %}
  79.     <table  class="table datagrid {{ entities is empty ? 'datagrid-empty' }}" {% if entities|length <= 4 %}style="overflow:initial ;"{% endif %}>
  80.         {% if num_results > 0 %}
  81.             <thead>
  82.             {% block table_head %}
  83.                 <tr>
  84.                     {% if has_batch_actions %}
  85.                         <th>
  86.                             <div class="form-check">
  87.                                 <span><input type="checkbox" class="form-check-input form-batch-checkbox-all"></span>
  88.                             </div>
  89.                         </th>
  90.                     {% endif %}
  91.                     {% set ea_sort_asc = constant('EasyCorp\\Bundle\\EasyAdminBundle\\Config\\Option\\SortOrder::ASC') %}
  92.                     {% set ea_sort_desc = constant('EasyCorp\\Bundle\\EasyAdminBundle\\Config\\Option\\SortOrder::DESC') %}
  93.                     {% for field in entities|first.fields ?? [] %}
  94.                         {% set is_sorting_field = ea.search.isSortingField(field.property) %}
  95.                         {% set next_sort_direction = is_sorting_field ? (ea.search.sortDirection(field.property) == ea_sort_desc ? ea_sort_asc : ea_sort_desc) : ea_sort_desc %}
  96.                         {% set column_icon = is_sorting_field ? (next_sort_direction == ea_sort_desc ? 'fa-arrow-up' : 'fa-arrow-down') : 'fa-sort' %}
  97.                         <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 }}">
  98.                             {% if field.isSortable %}
  99.                                 <a href="{{ ea_url({ page: 1, sort: { (field.property): next_sort_direction } }).includeReferrer() }}">
  100.                                     {{ field.label|trans|raw }} <i class="fa fa-fw {{ column_icon }}"></i>
  101.                                 </a>
  102.                             {% else %}
  103.                                 <span>{{ field.label|trans|raw }}</span>
  104.                             {% endif %}
  105.                         </th>
  106.                     {% endfor %}
  107.                     <th class="{{ ea.crud.showEntityActionsAsDropdown ? 'actions-as-dropdown-table-head' }}" dir="{{ ea.i18n.textDirection }}">
  108.                         <span class="sr-only">{{ t('action.entity_actions', ea.i18n.translationParameters, 'EasyAdminBundle')|trans }}</span>
  109.                     </th>
  110.                 </tr>
  111.             {% endblock table_head %}
  112.             </thead>
  113.         {% endif %}
  114.         <tbody>
  115.         {% block table_body %}
  116.             {% for entity in entities %}
  117.                 {% if entity.isAccessible %}
  118.                     <tr data-id="{{ entity.primaryKeyValueAsString }}">
  119.                         {% if has_batch_actions %}
  120.                             <td class="batch-actions-selector">
  121.                                 <div class="form-check">
  122.                                     <input type="checkbox" class="form-check-input form-batch-checkbox" value="{{ entity.primaryKeyValue }}">
  123.                                 </div>
  124.                             </td>
  125.                         {% endif %}
  126.                         {% for field in entity.fields %}
  127.                             <td data-label="{{ field.label|trans|e('html_attr') }}" class="{{ field.property == sort_field_name ? 'sorted' }} text-{{ field.textAlign }} {{ field.cssClass }}" dir="{{ ea.i18n.textDirection }}">
  128.                                 {{ include(field.templatePath, { field: field, entity: entity }, with_context = false) }}
  129.                             </td>
  130.                         {% endfor %}
  131.                         {% block entity_actions %}
  132.                             <td class="actions {{ ea.crud.showEntityActionsAsDropdown ? 'actions-as-dropdown' }}">
  133.                                 {% if entity.actions.count > 0 %}
  134.                                     {% if ea.crud.showEntityActionsAsDropdown %}
  135.                                         <div class="dropdown dropdown-actions">
  136.                                             <a class="dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  137.                                                 {# don't use FontAwesome 'fa-ellipsis-h' icon here because it doesn't look good #}
  138.                                                 {# this icon is 'dots-horizontal' icon from https://heroicons.com/ #}
  139.                                                 <svg xmlns="http://www.w3.org/2000/svg" height="21" width="21" fill="none" viewBox="0 0 24 24" stroke="currentColor">
  140.                                                     <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" />
  141.                                                 </svg>
  142.                                             </a>
  143.                                             <div class="dropdown-menu dropdown-menu-right">
  144.                                                 {% for action in entity.actions %}
  145.                                                     {{ include(action.templatePath, { action: action, entity: entity, isIncludedInDropdown: ea.crud.showEntityActionsAsDropdown }, with_context = false) }}
  146.                                                 {% endfor %}
  147.                                             </div>
  148.                                         </div>
  149.                                     {% else %}
  150.                                         {% for action in entity.actions %}
  151.                                             {{ include(action.templatePath, { action: action, entity: entity, isIncludedInDropdown: ea.crud.showEntityActionsAsDropdown }, with_context = false) }}
  152.                                         {% endfor %}
  153.                                     {% endif %}
  154.                                 {% endif %}
  155.                             </td>
  156.                         {% endblock entity_actions %}
  157.                     </tr>
  158.                 {% endif %}
  159.             {% else %}
  160.                 {% block table_body_empty %}
  161.                     {% for i in 1..14 %}
  162.                         <tr class="empty-row">
  163.                             <td><span></span></td>
  164.                             <td><span></span></td>
  165.                             <td><span></span></td>
  166.                             <td><span></span></td>
  167.                             <td><span></span></td>
  168.                             <td><span></span></td>
  169.                         </tr>
  170.                         {% if 3 == loop.index %}
  171.                             <tr class="no-results">
  172.                                 <td colspan="100">
  173.                                     {{ t('datagrid.no_results', ea.i18n.translationParameters, 'EasyAdminBundle')|trans }}
  174.                                 </td>
  175.                             </tr>
  176.                         {% endif %}
  177.                     {% endfor %}
  178.                 {% endblock table_body_empty %}
  179.             {% endfor %}
  180.             {% if some_results_are_hidden %}
  181.                 <tr class="datagrid-row-empty">
  182.                     <td class="text-center" colspan="100">
  183.                         <span class="datagrid-row-empty-message"><i class="fa fa-lock mr-1"></i> {{ 'datagrid.hidden_results'|trans({}, 'EasyAdminBundle') }}</span>
  184.                     </td>
  185.                 </tr>
  186.             {% endif %}
  187.         {% endblock table_body %}
  188.         </tbody>
  189.         <tfoot>
  190.         {% block table_footer %}
  191.         {% endblock table_footer %}
  192.         </tfoot>
  193.     </table>
  194.     {% if entities|length > 0 %}
  195.         <div class="content-panel-footer without-padding without-border">
  196.             {% block paginator %}
  197.                 {{ include(ea.templatePath('crud/paginator'), { render_detailed_pagination: not some_results_are_hidden }) }}
  198.             {% endblock paginator %}
  199.         </div>
  200.     {% endif %}
  201.     {% block delete_form %}
  202.         {{ include('@EasyAdmin/crud/includes/_delete_form.html.twig', with_context = false) }}
  203.     {% endblock delete_form %}
  204.     {% if has_filters %}
  205.         {{ include('@EasyAdmin/crud/includes/_filters_modal.html.twig') }}
  206.     {% endif %}
  207.     {% if has_batch_actions %}
  208.         {{ include('@EasyAdmin/crud/includes/_batch_action_modal.html.twig', {}, with_context = false) }}
  209.     {% endif %}
  210. {% endblock main %}