Skip to content

Commit

Permalink
Merge pull request #19 from borriglione/ENH-6-filter-modules
Browse files Browse the repository at this point in the history
filter and search module list - fixes #6
  • Loading branch information
Fabian Schmengler / committed Oct 5, 2018
2 parents 09a1227 + 5ca5b6b commit dd199fd
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 9 deletions.
6 changes: 5 additions & 1 deletion src/ViewModel/Widget/ModuleList.php
Expand Up @@ -16,6 +16,10 @@ public function __construct(ModuleListInterface $moduleListInterface)

public function getModuleList()
{
return $this->moduleListInterface->getAll();
return array_map(function($module) {
$module['type'] = (strpos($module['name'], 'Magento_') !== false) ?
__('Core') : __('External');
return $module;
}, $this->moduleListInterface->getAll());
}
}
22 changes: 22 additions & 0 deletions src/view/adminhtml/templates/scripts.phtml
Expand Up @@ -3,6 +3,18 @@
?>
<script type="text/javascript">
require(['jquery', 'Magento_Theme/js/sortable'], function ($) {
var searchValue = null, typeFilterValue = null;

function filterModuleListTable() {
$("table.module_list tbody tr").filter(function() {
var filterValues = [searchValue, typeFilterValue].filter(Boolean);
var trText = $(this).text();
$(this).toggle(filterValues.every(function(filterValue) {
return trText.toLowerCase().indexOf(filterValue) > -1
}))
});
}

$(window).load(function () {
$(".devdashboard_developer_widgets").sortable({
placeholder: "devdashboard_developer_widgets_placeholder",
Expand All @@ -11,6 +23,16 @@
connectWith: ".devdashboard_developer_widgets"
});
$(".devdashboard_developer_widgets h2").addClass('devdashboard_developer_widgets_handle');

$("#search_module_list").on("keyup", function() {
searchValue = $(this).val().toLowerCase();
filterModuleListTable();
});

$(".module_list_filter_type").on("change", function() {
typeFilterValue = $(this).val().toLowerCase();
filterModuleListTable();
});
});
});
</script>
34 changes: 26 additions & 8 deletions src/view/adminhtml/templates/widgets/module_list.phtml
Expand Up @@ -2,15 +2,33 @@
/** @var \Firegento\DevDashboard\ViewModel\Widget\ModuleList $viewModel */
$viewModel = $block->getData('viewModel');
?>
<label for="search_module_list">
<?php echo __('Search Module List: ') ?>
</label>
<input id="search_module_list" name="search_module_list" placeholder="<?php echo __('Search...') ?>" type="text" />

<table class="module_list">
<tr>
<th><?php echo __('Name') ?></th>
<th><?php echo __('Version') ?></th>
</tr>
<?php foreach ($viewModel->getModuleList() as $module) : ?>
<thead>
<tr>
<td><?php echo $module['name'] ?>
<td><?php echo $module['setup_version'] ?></td>
<th><?php echo __('Name') ?></th>
<th>
<?php echo __('Type') ?>
<select class='module_list_filter_type' style='display:inline-block'>
<option disabled selected><?php echo __('Select') ?></option>
<option value='core'><?php echo __('Core') ?></option>
<option value='external'><?php echo __('External') ?></option>
</select>
</th>
<th><?php echo __('Version') ?></th>
</tr>
<?php endforeach; ?>
</thead>
<tbody>
<?php foreach ($viewModel->getModuleList() as $module) : ?>
<tr>
<td><?php echo $module['name'] ?>
<td><?php echo $module['type'] ?>
<td><?php echo $module['setup_version'] ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>

0 comments on commit dd199fd

Please sign in to comment.