diff --git a/core/modules/views_ui/js/views_ui.listing.js b/core/modules/views_ui/js/views_ui.listing.js new file mode 100644 index 0000000..1155d2c --- /dev/null +++ b/core/modules/views_ui/js/views_ui.listing.js @@ -0,0 +1,42 @@ +(function ($, Drupal) { + + "use strict"; + + /** + * Filters the view listing tables by a text input search string. + */ + Drupal.behaviors.viewTableFilterByText = { + attach: function (context, settings) { + var $input = $('input.views-filter-text').once('views-filter-text'); + var $table = $($input.attr('data-table')); + var $rowsAndDetails, $rows, $details; + + function filterViewList (e) { + var query = $(e.target).val().toLowerCase(); + + function showViewRow (index, row) { + var $row = $(row); + var $sources = $row.find('.views-table-filter-text-source'); + var textMatch = $sources.text().toLowerCase().indexOf(query) !== -1; + $row.closest('tr').toggle(textMatch); + } + + // Filter if the length of the query is at least 2 characters. + if (query.length >= 2) { + $rows.each(showViewRow); + } + else { + $rowsAndDetails.show(); + } + } + + if ($table.length) { + $rowsAndDetails = $table.find('tr, details'); + $rows = $table.find('tbody tr'); + + $input.on('keyup', filterViewList); + } + } + }; + +}(jQuery, Drupal)); diff --git a/core/modules/views_ui/lib/Drupal/views_ui/ViewListController.php b/core/modules/views_ui/lib/Drupal/views_ui/ViewListController.php index 33ac4de..d040df1 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/ViewListController.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/ViewListController.php @@ -94,7 +94,12 @@ public function buildRow(EntityInterface $view) { '#displays' => $this->getDisplaysList($view) ), ), - 'description' => $view->get('description'), + 'description' => array( + 'data' => array( + '#markup' => String::checkPlain($view->get('description')), + ), + 'class' => array('views-table-filter-text-source'), + ), 'tag' => $view->get('tag'), 'path' => implode(', ', $this->getDisplayPaths($view)), 'operations' => $row['operations'], @@ -179,9 +184,25 @@ public function buildOperations(EntityInterface $entity) { public function render() { $entities = $this->load(); $list['#type'] = 'container'; + $list['#attributes']['id'] = 'views-entity-list'; + $list['#attached']['css'] = ViewFormControllerBase::getAdminCSS(); $list['#attached']['library'][] = array('system', 'drupal.ajax'); - $list['#attributes']['id'] = 'views-entity-list'; + $list['#attached']['library'][] = array('views_ui', 'views_ui.listing'); + + $list['search'] = array( + '#type' => 'search', + '#title' => $this->t('Search'), + '#size' => 30, + '#placeholder' => $this->t('Enter view name'), + '#attributes' => array( + 'class' => array('views-filter-text'), + 'data-table' => '.views-listing-table', + 'autocomplete' => 'off', + 'title' => $this->t('Enter a part of the view name or description to filter by.'), + ), + ); + $list['enabled']['heading']['#markup'] = '

' . t('Enabled') . '

'; $list['disabled']['heading']['#markup'] = '

' . t('Disabled') . '

'; foreach (array('enabled', 'disabled') as $status) { @@ -189,6 +210,9 @@ public function render() { $list[$status]['#attributes'] = array('class' => array('views-list-section', $status)); $list[$status]['table'] = array( '#theme' => 'table', + '#attributes' => array( + 'class' => array('views-listing-table'), + ), '#header' => $this->buildHeader(), '#rows' => array(), ); diff --git a/core/modules/views_ui/templates/views-ui-view-info.html.twig b/core/modules/views_ui/templates/views-ui-view-info.html.twig index e773cd2..a0f286c 100644 --- a/core/modules/views_ui/templates/views-ui-view-info.html.twig +++ b/core/modules/views_ui/templates/views-ui-view-info.html.twig @@ -12,5 +12,5 @@ * @ingroup themeable */ #} -

{{ title }}

+

{{ title }}

{{ displays }}
diff --git a/core/modules/views_ui/views_ui.module b/core/modules/views_ui/views_ui.module index 9e61cfd..150bd36 100644 --- a/core/modules/views_ui/views_ui.module +++ b/core/modules/views_ui/views_ui.module @@ -210,6 +210,14 @@ function views_ui_library_info() { ), ); + $libraries['views_ui.listing'] = array( + 'title' => 'Views UI listing', + 'version' => Drupal::VERSION, + 'js' => array( + $path . 'views_ui.listing.js' => array('group' => JS_DEFAULT), + ), + ); + return $libraries; }