Page MenuHomePhorge

D25863.1738846184.diff
No OneTemporary

D25863.1738846184.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -5047,6 +5047,7 @@
'PhabricatorTokenGivenEditor' => 'applications/tokens/editor/PhabricatorTokenGivenEditor.php',
'PhabricatorTokenGivenFeedStory' => 'applications/tokens/feed/PhabricatorTokenGivenFeedStory.php',
'PhabricatorTokenGivenQuery' => 'applications/tokens/query/PhabricatorTokenGivenQuery.php',
+ 'PhabricatorTokenGivenSearchEngine' => 'applications/tokens/query/PhabricatorTokenGivenSearchEngine.php',
'PhabricatorTokenLeaderController' => 'applications/tokens/controller/PhabricatorTokenLeaderController.php',
'PhabricatorTokenQuery' => 'applications/tokens/query/PhabricatorTokenQuery.php',
'PhabricatorTokenReceiverInterface' => 'applications/tokens/interface/PhabricatorTokenReceiverInterface.php',
@@ -11804,6 +11805,7 @@
'PhabricatorTokenGivenEditor' => 'PhabricatorEditor',
'PhabricatorTokenGivenFeedStory' => 'PhabricatorFeedStory',
'PhabricatorTokenGivenQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
+ 'PhabricatorTokenGivenSearchEngine' => 'PhabricatorApplicationSearchEngine',
'PhabricatorTokenLeaderController' => 'PhabricatorTokenController',
'PhabricatorTokenQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhabricatorTokenReceiverQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
diff --git a/src/applications/tokens/application/PhabricatorTokensApplication.php b/src/applications/tokens/application/PhabricatorTokensApplication.php
--- a/src/applications/tokens/application/PhabricatorTokensApplication.php
+++ b/src/applications/tokens/application/PhabricatorTokensApplication.php
@@ -30,7 +30,8 @@
return array(
'/token/' => array(
'' => 'PhabricatorTokenGivenController',
- 'given/' => 'PhabricatorTokenGivenController',
+ $this->getQueryRoutePattern('given/') =>
+ 'PhabricatorTokenGivenController',
'give/(?<phid>[^/]+)/' => 'PhabricatorTokenGiveController',
'leaders/' => 'PhabricatorTokenLeaderController',
),
diff --git a/src/applications/tokens/controller/PhabricatorTokenGivenController.php b/src/applications/tokens/controller/PhabricatorTokenGivenController.php
--- a/src/applications/tokens/controller/PhabricatorTokenGivenController.php
+++ b/src/applications/tokens/controller/PhabricatorTokenGivenController.php
@@ -6,75 +6,15 @@
return true;
}
- public function handleRequest(AphrontRequest $request) {
- $viewer = $request->getViewer();
+ public function handleRequest(AphrontRequest $request) {
+ $querykey = $request->getURIData('queryKey');
- $pager = id(new AphrontCursorPagerView())
- ->readFromRequest($request);
-
- $tokens_given = id(new PhabricatorTokenGivenQuery())
- ->setViewer($viewer)
- ->executeWithCursorPager($pager);
-
- $handles = array();
- if ($tokens_given) {
- $object_phids = mpull($tokens_given, 'getObjectPHID');
- $viewer_phids = mpull($tokens_given, 'getAuthorPHID');
- $handle_phids = array_merge($object_phids, $viewer_phids);
- $handles = id(new PhabricatorHandleQuery())
- ->setViewer($viewer)
- ->withPHIDs($handle_phids)
- ->execute();
- }
-
- $tokens = array();
- if ($tokens_given) {
- $token_phids = mpull($tokens_given, 'getTokenPHID');
- $tokens = id(new PhabricatorTokenQuery())
- ->setViewer($viewer)
- ->withPHIDs($token_phids)
- ->execute();
- $tokens = mpull($tokens, null, 'getPHID');
- }
-
- $list = new PHUIObjectItemListView();
- foreach ($tokens_given as $token_given) {
- $handle = $handles[$token_given->getObjectPHID()];
- $token = idx($tokens, $token_given->getTokenPHID());
-
- $item = id(new PHUIObjectItemView());
- $item->setHeader($handle->getFullName());
- $item->setHref($handle->getURI());
-
- $item->addAttribute($token->renderIcon());
-
- $item->addAttribute(
- pht(
- 'Given by %s on %s',
- $handles[$token_given->getAuthorPHID()]->renderLink(),
- phabricator_date($token_given->getDateCreated(), $viewer)));
-
- $list->addItem($item);
- }
- $title = pht('Tokens Given');
-
- $box = id(new PHUIObjectBoxView())
- ->setHeaderText($title)
- ->setObjectList($list);
-
- $nav = $this->buildSideNav();
- $nav->setCrumbs(
- $this->buildApplicationCrumbs()
- ->addTextCrumb($title));
- $nav->selectFilter('given/');
-
- $nav->appendChild($box);
- $nav->appendChild($pager);
-
- return $this->newPage()
- ->setTitle($title)
- ->appendChild($nav);
+ $controller = id(new PhabricatorApplicationSearchController())
+ ->setQueryKey($querykey)
+ ->setSearchEngine(new PhabricatorTokenGivenSearchEngine())
+ ->setNavigation($this->buildSideNav());
+ return $this->delegateToController($controller);
}
}
diff --git a/src/applications/tokens/query/PhabricatorTokenGivenSearchEngine.php b/src/applications/tokens/query/PhabricatorTokenGivenSearchEngine.php
new file mode 100644
--- /dev/null
+++ b/src/applications/tokens/query/PhabricatorTokenGivenSearchEngine.php
@@ -0,0 +1,96 @@
+<?php
+
+final class PhabricatorTokenGivenSearchEngine
+ extends PhabricatorApplicationSearchEngine {
+
+ public function getResultTypeDescription() {
+ return pht('Tokens Given');
+ }
+
+ public function getApplicationClassName() {
+ return PhabricatorTokensApplication::class;
+ }
+
+ public function newQuery() {
+ return new PhabricatorTokenGivenQuery();
+ }
+
+ protected function buildCustomSearchFields() {
+ return array();
+ }
+
+ protected function buildQueryFromParameters(array $map) {
+ return $this->newQuery();
+ }
+
+ protected function getRequiredHandlePHIDsForResultList(
+ array $tokens_given,
+ PhabricatorSavedQuery $query) {
+ $object_phids = mpull($tokens_given, 'getObjectPHID');
+ $viewer_phids = mpull($tokens_given, 'getAuthorPHID');
+ return array_merge($object_phids, $viewer_phids);
+ }
+
+ protected function renderResultList(
+ array $tokens_given,
+ PhabricatorSavedQuery $saved,
+ array $handles) {
+ $viewer = $this->requireViewer();
+
+ $tokens = array();
+ if ($tokens_given) {
+ $token_phids = mpull($tokens_given, 'getTokenPHID');
+ $tokens = id(new PhabricatorTokenQuery())
+ ->setViewer($viewer)
+ ->withPHIDs($token_phids)
+ ->execute();
+ $tokens = mpull($tokens, null, 'getPHID');
+ }
+
+ $list = new PHUIObjectItemListView();
+ foreach ($tokens_given as $token_given) {
+ $handle = $handles[$token_given->getObjectPHID()];
+ $token = idx($tokens, $token_given->getTokenPHID());
+
+ $item = id(new PHUIObjectItemView());
+ $item->setHeader($handle->getFullName());
+ $item->setHref($handle->getURI());
+
+ $item->addAttribute($token->renderIcon());
+
+ $item->addAttribute(
+ pht(
+ 'Given by %s on %s',
+ $handles[$token_given->getAuthorPHID()]->renderLink(),
+ phabricator_date($token_given->getDateCreated(), $viewer)));
+
+ $list->addItem($item);
+ }
+
+ return id(new PhabricatorApplicationSearchResultView())
+ ->setObjectList($list);
+ }
+
+ protected function getBuiltinQueryNames() {
+ $names = array();
+ $names['all'] = pht('All Tokens Given');
+
+ return $names;
+ }
+
+ public function buildSavedQueryFromBuiltin($query_key) {
+ $query = $this->newSavedQuery();
+ $query->setQueryKey($query_key);
+
+ switch ($query_key) {
+ case 'all':
+ return $query;
+ }
+
+ return parent::buildSavedQueryFromBuiltin($query_key);
+ }
+
+ protected function getURI($path) {
+ return '/token/given/'.$path;
+ }
+}

File Metadata

Mime Type
text/plain
Expires
Thu, Feb 6, 12:49 (20 h, 48 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1157481
Default Alt Text
D25863.1738846184.diff (7 KB)

Event Timeline