diff --git a/js/overview.js b/js/overview.js index c635b4d..a11712f 100644 --- a/js/overview.js +++ b/js/overview.js @@ -10,27 +10,31 @@ /** * Filters the overview table by input search filters. * - * Text search input: input.table-filter-text - * Select group: select.table-filter-group-select - * Target table: input.table-filter-text[data-table] - * Source text: .table-filter-text-source - * Source group: .table-filter-group-source + * Target table: .table-filter[data-table] + * Text search input: input.table-filter-text + * Group search select: select.table-filter-group-select + * Source text: .table-filter-text-source + * Source group: .table-filter-group-source * * @type {Drupal~behavior} */ Drupal.behaviors.tableFilterByText = { attach: function (context, settings) { + var $filters = $('.table-filter').once('table-filter'); + var $table = $($filters.attr('data-table')); + // var $selects = $ var $text_input = $('input.table-filter-text').once('table-filter-text'); var $group_select = $('select.table-filter-group-select').once('table-filter-group-select'); - var $table = $($text_input.attr('data-table')); var $rows; - var $details; - function filterSensorList() { - var group_value = $group_select.val().toLowerCase(); + function filterItemList() { + var group_value; + if (typeof $group_select.val() !== 'undefined') { + group_value = $group_select.val().toLowerCase(); + } var text_value = $text_input.val().toLowerCase(); - function showSensorRow(index, row) { + function showItemRow(index, row) { var $row = $(row); var $group_sources = $row.find('.table-filter-group-source'); var $text_sources = $row.find('.table-filter-text-source'); @@ -49,24 +53,13 @@ $row.show(); } - $rows.each(showSensorRow); - - // // Filter if the length of the input field is longer than 2 characters - // // or an option is selected. - // if (group_value || text_value.length >= 2) { - // $rows.each(showSensorRow); - // } - // else { - // $rows.show(); - // $details.attr('open', false); - // } + $rows.each(showItemRow); } if ($table.length) { $rows = $table.find('tbody tr'); - $text_input.on('keyup', filterSensorList); - $group_select.on('change', filterSensorList); - // $details = $table.find('details'); + $text_input.on('keyup', filterItemList); + $group_select.on('change', filterItemList); } } }; diff --git a/paragraphs_collection.libraries.yml b/paragraphs_collection.libraries.yml index e7ee8d8..298bdec 100644 --- a/paragraphs_collection.libraries.yml +++ b/paragraphs_collection.libraries.yml @@ -1,6 +1,5 @@ overview: css: -# @todo Use "theme", instead? component: css/overview.css: {} js: diff --git a/paragraphs_collection.links.menu.yml b/paragraphs_collection.links.menu.yml index 4ad0cdf..70aeea3 100644 --- a/paragraphs_collection.links.menu.yml +++ b/paragraphs_collection.links.menu.yml @@ -1,6 +1,6 @@ paragraphs_collection.layouts: title: 'Paragraphs Collection' parent: system.admin_reports - description: 'Overview of all layouts and styles for the respective plugins.' + description: 'Overviews of items discoverable by behavior plugins.' route_name: paragraphs_collection.layouts menu_name: admin diff --git a/paragraphs_collection.links.task.yml b/paragraphs_collection.links.task.yml index b27a824..a7742b7 100644 --- a/paragraphs_collection.links.task.yml +++ b/paragraphs_collection.links.task.yml @@ -1,5 +1,3 @@ -# @todo Add all the tab links. - paragraphs_collection.layouts: title: Layouts route_name: paragraphs_collection.layouts diff --git a/paragraphs_collection.routing.yml b/paragraphs_collection.routing.yml index fef898f..6a87acf 100644 --- a/paragraphs_collection.routing.yml +++ b/paragraphs_collection.routing.yml @@ -1,18 +1,15 @@ -# @todo Just one class with two content functions, or two classes inheriting -# from one? - paragraphs_collection.layouts: path: '/admin/reports/paragraphs_collection/layouts' defaults: _controller: '\Drupal\paragraphs_collection\Controller\OverviewController::layouts' - _title: 'Available layouts (grid layout plugin)' + _title: 'Available grid layouts' requirements: - _permission: 'administer paragraphs types' # @todo Change this? + _permission: 'administer paragraphs types' paragraphs_collection.styles: path: '/admin/reports/paragraphs_collection/styles' defaults: _controller: '\Drupal\paragraphs_collection\Controller\OverviewController::styles' - _title: 'Available Styles (styles plugin)' + _title: 'Available styles' requirements: - _permission: 'administer paragraphs types' # @todo Change this? + _permission: 'administer paragraphs types' diff --git a/src/Controller/OverviewController.php b/src/Controller/OverviewController.php index 4f38ac9..80a7a43 100644 --- a/src/Controller/OverviewController.php +++ b/src/Controller/OverviewController.php @@ -87,7 +87,7 @@ class OverviewController extends ControllerBase { /** * Lists Paragraphs Types with discoverable items they allow for a plugin. * - * @param string + * @param string $plugin_id * The ID of the behaviour plugin that the discoverable items belong to. * Only "grid_layout" and "style" are currently supported. * @@ -181,87 +181,72 @@ class OverviewController extends ControllerBase { } /** - * Generates an overview page of available grid layouts. + * Generates an overview page of available layouts for the grid layout plugin. * * @return array * The output render array. */ public function layouts() { - $header = [ - 'label' => $this->t('Style'), - 'description' => $this->t('Description'), - 'use' => $this->t('Used in'), - ]; - - $layouts = $this->gridDiscovery->getGridLayouts(); - uasort($layouts, function ($layout1, $layout2) { - return strcasecmp($layout1['title'], $layout2['title']); - }); - - $rows =[]; - foreach ($layouts as $layout_id => $layout) { - $paragraphs_type_ids = $this->getParagraphsTypesPerLayout($layout_id); - $paragraphs_type_links = []; - foreach ($paragraphs_type_ids as $paragraphs_type_id) { - $paragraphs_type = ParagraphsType::load($paragraphs_type_id); - - if($paragraphs_type_links != []) { - $paragraphs_type_links[] = ['#plain_text' => ', ']; - } - - $paragraphs_type_links[] = [ - '#type' => 'link', - '#title' => $paragraphs_type->label(), - '#url' => $paragraphs_type->toUrl(), - ]; - } - - $rows[] = [ - 'label' => [ - '#plain_text' => $layout['title'], - ], - 'description' => [ - '#plain_text' => $layout['description'], - ], - 'use' => $paragraphs_type_links, - ]; - } - - $table = [ - '#type' => 'table', - '#header' => $header, - '#sticky' => TRUE, - ]; - $table += $rows; - - $build['table'] = $table; - $build['#attached']['library'] = ['paragraphs_collection/overview']; - - return $build; + return self::content('grid_layout'); } /** - * Generates an overview page of available styles. + * Generates an overview page of available styles for the styles plugin. * * @return array * The output render array. */ public function styles() { + return self::content('style'); + } + + /** + * Generates an overview page of available discoverable items for a plugin. + * + * Discoverable items are styles for the style plugin and layouts for the + * grid layout plugin. + * + * @param string $plugin_id + * The ID of the behaviour plugin that the discoverable items belong to. + * Only "grid_layout" and "style" are currently supported. + * + * @return array|null + * The output render array. NULL for invalid plugin IDs and unsupported + * behavior plugins. + */ + public function content($plugin_id) { $header = [ 'label' => $this->t('Style'), -// 'description' => $this->t('Description'), 'details' => $this->t('Details'), 'use' => $this->t('Used in'), ]; - $styles = $this->styleDiscovery->getStyles(); - uasort($styles, function ($style1, $style2) { - return strcasecmp($style1['title'], $style2['title']); + switch ($plugin_id) { + case 'grid_layout': + $items = $this->gridDiscovery->getGridLayouts(); + break; + case 'style': + $items = $this->styleDiscovery->getStyles(); + break; + default: + return NULL; + } + uasort($items, function ($item1, $item2) { + return strcasecmp($item1['title'], $item2['title']); }); $rows =[]; - foreach ($styles as $style_id => $style) { - $paragraphs_type_ids = $this->getParagraphsTypesPerStyle($style_id); + foreach ($items as $item_id => $item) { + switch ($plugin_id) { + case 'grid_layout': + $paragraphs_type_ids = $this->getParagraphsTypesPerLayout($item_id); + break; + case 'style': + $paragraphs_type_ids = $this->getParagraphsTypesPerStyle($item_id); + break; + default: + return NULL; + } $paragraphs_type_link_list = []; foreach ($paragraphs_type_ids as $paragraphs_type_id) { @@ -281,49 +266,49 @@ class OverviewController extends ControllerBase { ]; } - $group_list = []; - foreach ($style['groups'] as $group) { - if ($group_list != []) { - $group_list[] = ['#plain_text' => ', ']; - } - $group_list[] = [ - '#type' => 'markup', - '#markup' => Html::escape($group), - '#prefix' => '', - '#suffix' => '', - ]; - } - -// $row['label']['#plain_text'] = $style['title']; $row['label'] = [ '#type' => 'markup', - '#markup' => Html::escape($style['title']), + '#markup' => Html::escape($item['title']), '#prefix' => '', '#suffix' => '', ]; $row['details'] = [ '#type' => 'details', - '#title' => $this->t($style['description']) ?: $this->t('Details'), + '#title' => $this->t($item['description']) ?: $this->t('Details'), '#open' => FALSE, '#attributes' => ['class' => ['overview-details']], ]; $row['details']['id'] = [ '#type' => 'item', '#title' => $this->t('ID'), - '#markup' => ''. Html::escape($style_id) . '', - '#prefix' => '