vendor/easycorp/easyadmin-bundle/templates/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.                                 {% set sortable_url = ea_url().set('page', 1).set('sort', { (field.property): next_sort_direction }) %}
  104.                                 {% if ea.usePrettyUrls %}
  105.                                     {% set sortable_url = sortable_url.setController(ea.request.attributes.get('crudControllerFqcn')).setAction('index') %}
  106.                                 {% endif %}
  107.                                 <a href="{{ sortable_url }}">
  108.                                     {{ field.label|trans|raw }} <i class="fa fa-fw {{ column_icon }}"></i>
  109.                                 </a>
  110.                             {% else %}
  111.                                 <span>{{ field.label|trans|raw }}</span>
  112.                             {% endif %}
  113.                         </th>
  114.                     {% endfor %}
  115.                     <th class="{{ ea.crud.showEntityActionsAsDropdown ? 'actions-as-dropdown-table-head' }}" dir="{{ ea.i18n.textDirection }}">
  116.                         <span class="sr-only">{{ t('action.entity_actions', ea.i18n.translationParameters, 'EasyAdminBundle')|trans }}</span>
  117.                     </th>
  118.                 </tr>
  119.             {% endblock table_head %}
  120.             </thead>
  121.         {% endif %}
  122.         <tbody>
  123.         {% block table_body %}
  124.             {% for entity in entities %}
  125.                 {% if entity.isAccessible %}
  126.                     <tr data-id="{{ entity.primaryKeyValueAsString }}">
  127.                         {% if has_batch_actions %}
  128.                             <td class="batch-actions-selector">
  129.                                 <div class="form-check">
  130.                                     <input type="checkbox" class="form-check-input form-batch-checkbox" id="form-batch-checkbox-{{ loop.index0 }}" value="{{ entity.primaryKeyValue }}">
  131.                                 </div>
  132.                             </td>
  133.                         {% endif %}
  134.                         {% for field in entity.fields %}
  135.                             {% set is_searchable = null == ea.crud.searchFields or field.property in ea.crud.searchFields %}
  136.                             <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 }}" {% for name, value in field.htmlAttributes %}{{ name }}="{{ value|e('html_attr') }}" {% endfor %}>
  137.                                 {{ include(field.templatePath, { field: field, entity: entity }, with_context = false) }}
  138.                             </td>
  139.                         {% endfor %}
  140.                         {% block entity_actions %}
  141.                             <td class="actions {{ ea.crud.showEntityActionsAsDropdown ? 'actions-as-dropdown' }}">
  142.                                 {% if entity.actions.count > 0 %}
  143.                                     {% if ea.crud.showEntityActionsAsDropdown %}
  144.                                         <div class="dropdown dropdown-actions">
  145.                                             <a class="dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  146.                                                 {# don't use FontAwesome 'fa-ellipsis-h' icon here because it doesn't look good #}
  147.                                                 {# this icon is 'dots-horizontal' icon from https://heroicons.com/ #}
  148.                                                 <svg xmlns="http://www.w3.org/2000/svg" height="21" width="21" fill="none" viewBox="0 0 24 24" stroke="currentColor">
  149.                                                     <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" />
  150.                                                 </svg>
  151.                                             </a>
  152.                                             <div class="dropdown-menu dropdown-menu-right">
  153.                                                 {% for action in entity.actions %}
  154.                                                     {{ include(action.templatePath, { action: action, entity: entity, isIncludedInDropdown: ea.crud.showEntityActionsAsDropdown }, with_context = false) }}
  155.                                                 {% endfor %}
  156.                                             </div>
  157.                                         </div>
  158.                                     {% else %}
  159.                                         {% for action in entity.actions %}
  160.                                             {{ include(action.templatePath, { action: action, entity: entity, isIncludedInDropdown: ea.crud.showEntityActionsAsDropdown }, with_context = false) }}
  161.                                         {% endfor %}
  162.                                     {% endif %}
  163.                                 {% endif %}
  164.                             </td>
  165.                         {% endblock entity_actions %}
  166.                     </tr>
  167.                 {% endif %}
  168.             {% else %}
  169.                 {% block table_body_empty %}
  170.                     {% for i in 1..14 %}
  171.                         <tr class="empty-row">
  172.                             <td><span></span></td>
  173.                             <td><span></span></td>
  174.                             <td><span></span></td>
  175.                             <td><span></span></td>
  176.                             <td><span></span></td>
  177.                             <td><span></span></td>
  178.                         </tr>
  179.                         {% if 3 == loop.index %}
  180.                             <tr class="no-results">
  181.                                 <td colspan="100">
  182.                                     {{ t('datagrid.no_results', ea.i18n.translationParameters, 'EasyAdminBundle')|trans }}
  183.                                 </td>
  184.                             </tr>
  185.                         {% endif %}
  186.                     {% endfor %}
  187.                 {% endblock table_body_empty %}
  188.             {% endfor %}
  189.             {% if some_results_are_hidden %}
  190.                 <tr class="datagrid-row-empty">
  191.                     <td class="text-center" colspan="100">
  192.                         <span class="datagrid-row-empty-message"><i class="fa fa-lock mr-1"></i> {{ 'datagrid.hidden_results'|trans({}, 'EasyAdminBundle') }}</span>
  193.                     </td>
  194.                 </tr>
  195.             {% endif %}
  196.         {% endblock table_body %}
  197.         </tbody>
  198.         <tfoot>
  199.         {% block table_footer %}
  200.         {% endblock table_footer %}
  201.         </tfoot>
  202.     </table>
  203.     {% if entities|length > 0 %}
  204.         <div class="content-panel-footer without-padding without-border">
  205.             {% block paginator %}
  206.                 {{ include(ea.templatePath('crud/paginator'), { render_detailed_pagination: not some_results_are_hidden }) }}
  207.             {% endblock paginator %}
  208.         </div>
  209.     {% endif %}
  210.     {% block delete_form %}
  211.         {{ include('@EasyAdmin/crud/includes/_delete_form.html.twig', with_context = false) }}
  212.     {% endblock delete_form %}
  213.     {% if has_filters %}
  214.         {{ include('@EasyAdmin/crud/includes/_filters_modal.html.twig') }}
  215.     {% endif %}
  216.     {% if has_batch_actions %}
  217.         {{ include('@EasyAdmin/crud/includes/_batch_action_modal.html.twig', {}, with_context = false) }}
  218.     {% endif %}
  219. {% endblock main %}