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