Commit f384cbdc authored by webchick's avatar webchick

Issue #2087327 by damiankloip: Add text search functionality to views listing page.

parent 6fd72a2c
(function ($, Drupal) {
"use strict";
/**
* Filters the view listing tables by a text input search string.
*
* Text search input: input.views-filter-text
* Target table: input.views-filter-text[data-table]
* Source text: .views-table-filter-text-source
*/
Drupal.behaviors.viewTableFilterByText = {
attach: function (context, settings) {
var $input = $('input.views-filter-text').once('views-filter-text');
var $table = $($input.attr('data-table'));
var $rows;
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 {
$rows.show();
}
}
if ($table.length) {
$rows = $table.find('tbody tr');
$input.on('keyup', filterViewList);
}
}
};
}(jQuery, Drupal));
......@@ -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'] = '<h2>' . t('Enabled') . '</h2>';
$list['disabled']['heading']['#markup'] = '<h2>' . t('Disabled') . '</h2>';
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(),
);
......
......@@ -12,5 +12,5 @@
* @ingroup themeable
*/
#}
<h3 class="views-ui-view-title">{{ title }}</h3>
<h3 class="views-ui-view-title views-table-filter-text-source">{{ title }}</h3>
<div class="views-ui-view-displays">{{ displays }}</div>
......@@ -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;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment