suppressDirectories -> ignoreDirectories
Add support for wildcards in ignoreDirectories
This commit is contained in:
parent
6e7fa7de88
commit
31f74adb70
|
|
@ -1,6 +1,7 @@
|
||||||
<?php namespace Cms\Widgets;
|
<?php namespace Cms\Widgets;
|
||||||
|
|
||||||
use Str;
|
use Str;
|
||||||
|
use File;
|
||||||
use Input;
|
use Input;
|
||||||
use Request;
|
use Request;
|
||||||
use Response;
|
use Response;
|
||||||
|
|
@ -64,9 +65,9 @@ class TemplateList extends WidgetBase
|
||||||
public $controlClass = null;
|
public $controlClass = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string A list of directories to suppress / hide.
|
* @var string A list of file name patterns to suppress / hide.
|
||||||
*/
|
*/
|
||||||
public $suppressDirectories = [];
|
public $ignoreDirectories = [];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Public methods
|
* Public methods
|
||||||
|
|
@ -107,7 +108,7 @@ class TemplateList extends WidgetBase
|
||||||
$this->vars['toolbarClass'] = $toolbarClass;
|
$this->vars['toolbarClass'] = $toolbarClass;
|
||||||
|
|
||||||
return $this->makePartial('body', [
|
return $this->makePartial('body', [
|
||||||
'data'=>$this->getData()
|
'data' => $this->getData()
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -143,6 +144,7 @@ class TemplateList extends WidgetBase
|
||||||
//
|
//
|
||||||
// Methods for the internal use
|
// Methods for the internal use
|
||||||
//
|
//
|
||||||
|
|
||||||
protected function getData()
|
protected function getData()
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
|
|
@ -150,21 +152,15 @@ class TemplateList extends WidgetBase
|
||||||
*/
|
*/
|
||||||
$items = call_user_func($this->dataSource);
|
$items = call_user_func($this->dataSource);
|
||||||
|
|
||||||
$normalizedItems = [];
|
if ($items instanceof \October\Rain\Support\Collection) {
|
||||||
foreach ($items as $item) {
|
$items = $items->all();
|
||||||
if ($this->suppressDirectories) {
|
|
||||||
$fileName = $item->getBaseFileName();
|
|
||||||
$dir = dirname($fileName);
|
|
||||||
|
|
||||||
if (in_array($dir, $this->suppressDirectories)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$normalizedItems[] = $this->normalizeItem($item);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
usort($normalizedItems, function ($a, $b) {
|
$items = $this->removeIgnoredDirectories($items);
|
||||||
|
|
||||||
|
$items = array_map([$this, 'normalizeItem'], $items);
|
||||||
|
|
||||||
|
usort($items, function ($a, $b) {
|
||||||
return strcmp($a->fileName, $b->fileName);
|
return strcmp($a->fileName, $b->fileName);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -178,10 +174,10 @@ class TemplateList extends WidgetBase
|
||||||
/*
|
/*
|
||||||
* Exact
|
* Exact
|
||||||
*/
|
*/
|
||||||
foreach ($normalizedItems as $index => $item) {
|
foreach ($items as $index => $item) {
|
||||||
if ($this->itemContainsWord($searchTerm, $item, true)) {
|
if ($this->itemContainsWord($searchTerm, $item, true)) {
|
||||||
$filteredItems[] = $item;
|
$filteredItems[] = $item;
|
||||||
unset($normalizedItems[$index]);
|
unset($items[$index]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -189,14 +185,14 @@ class TemplateList extends WidgetBase
|
||||||
* Fuzzy
|
* Fuzzy
|
||||||
*/
|
*/
|
||||||
$words = explode(' ', $searchTerm);
|
$words = explode(' ', $searchTerm);
|
||||||
foreach ($normalizedItems as $item) {
|
foreach ($items as $item) {
|
||||||
if ($this->itemMatchesSearch($words, $item)) {
|
if ($this->itemMatchesSearch($words, $item)) {
|
||||||
$filteredItems[] = $item;
|
$filteredItems[] = $item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$filteredItems = $normalizedItems;
|
$filteredItems = $items;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -232,6 +228,35 @@ class TemplateList extends WidgetBase
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function removeIgnoredDirectories($items)
|
||||||
|
{
|
||||||
|
if (!$this->ignoreDirectories) {
|
||||||
|
return $items;
|
||||||
|
}
|
||||||
|
|
||||||
|
$ignoreCache = [];
|
||||||
|
|
||||||
|
$items = array_filter($items, function($item) use (&$ignoreCache) {
|
||||||
|
$fileName = $item->getBaseFileName();
|
||||||
|
$dirName = dirname($fileName);
|
||||||
|
|
||||||
|
if (isset($ignoreCache[$dirName])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($this->ignoreDirectories as $ignoreDir) {
|
||||||
|
if (File::fileNameMatch($dirName, $ignoreDir)) {
|
||||||
|
$ignoreCache[$dirName] = true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
return $items;
|
||||||
|
}
|
||||||
|
|
||||||
protected function normalizeItem($item)
|
protected function normalizeItem($item)
|
||||||
{
|
{
|
||||||
$description = null;
|
$description = null;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue