From: Matthias Schmidt Date: Sun, 7 Oct 2018 08:33:32 +0000 (+0200) Subject: Add simple pip entry list filter X-Git-Tag: 5.2.0_Alpha_1~666 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=87cf14f2f8a3db6581fdcf264ca5bccf2ba8ed30;p=GitHub%2FWoltLab%2FWCF.git Add simple pip entry list filter See #2545 --- diff --git a/wcfsetup/install/files/acp/templates/devtoolsProjectPipEntryList.tpl b/wcfsetup/install/files/acp/templates/devtoolsProjectPipEntryList.tpl index 7067bef227..f600ba938b 100644 --- a/wcfsetup/install/files/acp/templates/devtoolsProjectPipEntryList.tpl +++ b/wcfsetup/install/files/acp/templates/devtoolsProjectPipEntryList.tpl @@ -32,6 +32,24 @@ +
+
+

{lang}wcf.global.filter{/lang}

+ +
+
+
+ +
+
+ +
+ + {@SECURITY_TOKEN_INPUT_TAG} +
+
+
+ {hascontent}
{content} diff --git a/wcfsetup/install/files/lib/acp/page/DevtoolsProjectPipEntryListPage.class.php b/wcfsetup/install/files/lib/acp/page/DevtoolsProjectPipEntryListPage.class.php index eaecf818e8..1be94b722e 100644 --- a/wcfsetup/install/files/lib/acp/page/DevtoolsProjectPipEntryListPage.class.php +++ b/wcfsetup/install/files/lib/acp/page/DevtoolsProjectPipEntryListPage.class.php @@ -5,6 +5,7 @@ use wcf\page\AbstractPage; use wcf\system\devtools\pip\DevtoolsPip; use wcf\system\devtools\pip\IDevtoolsPipEntryList; use wcf\system\exception\IllegalLinkException; +use wcf\system\request\LinkHandler; use wcf\system\WCF; use wcf\util\StringUtil; @@ -29,6 +30,12 @@ class DevtoolsProjectPipEntryListPage extends AbstractPage { */ public $endIndex = 0; + /** + * entry filter string + * @var string + */ + public $entryFilter; + /** * pip entry list * @var IDevtoolsPipEntryList @@ -41,6 +48,11 @@ class DevtoolsProjectPipEntryListPage extends AbstractPage { */ public $entryType; + /** + * @inheritDoc + */ + public $forceCanonicalURL = true; + /** * number of items shown per page * @var integer @@ -113,6 +125,7 @@ class DevtoolsProjectPipEntryListPage extends AbstractPage { /** * @inheritDoc + * @throws IllegalLinkException */ public function readParameters() { parent::readParameters(); @@ -161,6 +174,16 @@ class DevtoolsProjectPipEntryListPage extends AbstractPage { if ($this->entryType !== null) { $this->linkParameters .= '&entryType=' . $this->entryType; } + + if (isset($_REQUEST['entryFilter'])) $this->entryFilter = StringUtil::trim($_REQUEST['entryFilter']); + + if ($this->entryFilter !== null && $this->entryFilter !== '') { + $this->linkParameters .= '&entryFilter=' . $this->entryFilter; + } + + $this->canonicalURL = LinkHandler::getInstance()->getLink('DevtoolsProjectPipEntryList', [ + 'id' => $this->project->projectID, + ], $this->linkParameters); } /** @@ -172,6 +195,10 @@ class DevtoolsProjectPipEntryListPage extends AbstractPage { /** @var IDevtoolsPipEntryList entryList */ $this->entryList = $this->pipObject->getPip()->getEntryList(); + if ($this->entryFilter !== null && $this->entryFilter !== '') { + $this->entryList->filterEntries($this->entryFilter); + } + $this->items = count($this->entryList->getEntries()); $this->pages = intval(ceil($this->items / $this->itemsPerPage)); @@ -194,6 +221,7 @@ class DevtoolsProjectPipEntryListPage extends AbstractPage { WCF::getTPL()->assign([ 'endIndex' => $this->endIndex, + 'entryFilter' => $this->entryFilter, 'entryList' => $this->entryList, 'entryType' => $this->entryType, 'items' => $this->items, diff --git a/wcfsetup/install/files/lib/system/devtools/pip/DevtoolsPipEntryList.class.php b/wcfsetup/install/files/lib/system/devtools/pip/DevtoolsPipEntryList.class.php index 2d54cc6a51..7971a23d91 100644 --- a/wcfsetup/install/files/lib/system/devtools/pip/DevtoolsPipEntryList.class.php +++ b/wcfsetup/install/files/lib/system/devtools/pip/DevtoolsPipEntryList.class.php @@ -52,6 +52,52 @@ class DevtoolsPipEntryList implements IDevtoolsPipEntryList { $this->entries[$id] = $entry; } + /** + * @inheritDoc + */ + public function filterEntries($filter) { + $filterType = gettype($filter); + + switch ($filterType) { + case 'array': + $unknownFilters = array_diff(array_keys($filter), array_keys($this->keys)); + + if (!empty($unknownFilters)) { + throw new \InvalidArgumentException("Unknown filter" . (count($unknownFilters) > 1 ? 's' : '') . " '". implode(', ', $unknownFilters) ."'."); + } + + $filteredEntries = []; + foreach ($this->entries as $id => $entry) { + foreach ($filter as $filterKey => $filterString) { + if (isset($entry[$filterKey]) && strpos($entry[$filterKey], $filterString) !== false) { + $filteredEntries[$id] = $entry; + } + } + } + + $this->entries = $filteredEntries; + + break; + + case 'string': + $filteredEntries = []; + foreach ($this->entries as $id => $entry) { + foreach ($this->keys as $key => $label) { + if (isset($entry[$key]) && strpos($entry[$key], $filter) !== false) { + $filteredEntries[$id] = $entry; + } + } + } + + $this->entries = $filteredEntries; + + break; + + default: + throw new \InvalidArgumentException("Cannot use '{$filterType}' to filter entries."); + } + } + /** * @inheritDoc */ diff --git a/wcfsetup/install/files/lib/system/devtools/pip/IDevtoolsPipEntryList.class.php b/wcfsetup/install/files/lib/system/devtools/pip/IDevtoolsPipEntryList.class.php index ddfd95d112..1eab69ddc5 100644 --- a/wcfsetup/install/files/lib/system/devtools/pip/IDevtoolsPipEntryList.class.php +++ b/wcfsetup/install/files/lib/system/devtools/pip/IDevtoolsPipEntryList.class.php @@ -22,6 +22,19 @@ interface IDevtoolsPipEntryList { */ public function addEntry($id, array $entry); + /** + * Internally filters the entries using the given filter. + * `getEntries()` will only return filter entries afterwards. + * + * This filter is applied to the elements currently in the list. + * Entries added afterwards are not affected by this filter. + * + * Applying a second filter will filter the pre-filtered entries. + * + * @param string|array $filter either a string that is used to search all entry elements or filter map `key => searchString` + */ + public function filterEntries($filter); + /** * Returns all entries in the list. *