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