@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Convert tokens given to use SearchEngine

Summary:
Now the page /token/given/ allows to sort tokens by newest (default) and oldest.
The default sort is unchanged.

The given tokens are also now easily usable into any Dashboard.

This introduces creative space to add future filters.

refs T15988

Test Plan:
Tested that /token/ still renders fine.

Order by Creation (Newest First): it works.

Order by Creation (Oldest First): it works.

Activate the DarkConsole's top bar and open the tab Services to inspect the generated queries, that are like this, and not anything alien,
accordingly to the current "order by":

SELECT * FROM `token_given` ORDER BY `id` DESC LIMIT 101
SELECT * FROM `token_given` ORDER BY `id` ASC LIMIT 101

Test the page /token/given/ as logged-out: it the Tokens app is configured as public, it still works like before.

From the page /token/given/ order by "Creation (oldest first)", use {nav Use Results > Add Dashboard} and see that it works.

From the same Dashboard: {nav Create Panel > Query Panel} and select "Tokens Given" with Limit=1 and title "Most Recent Tokenzzz" and see that it works as expected.

Visit the Leader Board page at /token/leaders/: it still works like before.

Reviewers: O1 Blessed Committers, valerio.bozzolan

Reviewed By: O1 Blessed Committers, valerio.bozzolan

Subscribers: tobiaswiese, valerio.bozzolan, Matthew, Cigaryno

Maniphest Tasks: T15988

Differential Revision: https://we.phorge.it/D25863

+115 -65
+2
src/__phutil_library_map__.php
··· 5047 5047 'PhabricatorTokenGivenEditor' => 'applications/tokens/editor/PhabricatorTokenGivenEditor.php', 5048 5048 'PhabricatorTokenGivenFeedStory' => 'applications/tokens/feed/PhabricatorTokenGivenFeedStory.php', 5049 5049 'PhabricatorTokenGivenQuery' => 'applications/tokens/query/PhabricatorTokenGivenQuery.php', 5050 + 'PhabricatorTokenGivenSearchEngine' => 'applications/tokens/query/PhabricatorTokenGivenSearchEngine.php', 5050 5051 'PhabricatorTokenLeaderController' => 'applications/tokens/controller/PhabricatorTokenLeaderController.php', 5051 5052 'PhabricatorTokenQuery' => 'applications/tokens/query/PhabricatorTokenQuery.php', 5052 5053 'PhabricatorTokenReceiverInterface' => 'applications/tokens/interface/PhabricatorTokenReceiverInterface.php', ··· 11804 11805 'PhabricatorTokenGivenEditor' => 'PhabricatorEditor', 11805 11806 'PhabricatorTokenGivenFeedStory' => 'PhabricatorFeedStory', 11806 11807 'PhabricatorTokenGivenQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 11808 + 'PhabricatorTokenGivenSearchEngine' => 'PhabricatorApplicationSearchEngine', 11807 11809 'PhabricatorTokenLeaderController' => 'PhabricatorTokenController', 11808 11810 'PhabricatorTokenQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 11809 11811 'PhabricatorTokenReceiverQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
+2 -1
src/applications/tokens/application/PhabricatorTokensApplication.php
··· 30 30 return array( 31 31 '/token/' => array( 32 32 '' => 'PhabricatorTokenGivenController', 33 - 'given/' => 'PhabricatorTokenGivenController', 33 + $this->getQueryRoutePattern('given/') => 34 + 'PhabricatorTokenGivenController', 34 35 'give/(?<phid>[^/]+)/' => 'PhabricatorTokenGiveController', 35 36 'leaders/' => 'PhabricatorTokenLeaderController', 36 37 ),
+15 -64
src/applications/tokens/controller/PhabricatorTokenGivenController.php
··· 6 6 return true; 7 7 } 8 8 9 - public function handleRequest(AphrontRequest $request) { 10 - $viewer = $request->getViewer(); 9 + public function handleRequest(AphrontRequest $request) { 10 + $querykey = $request->getURIData('queryKey'); 11 11 12 - $pager = id(new AphrontCursorPagerView()) 13 - ->readFromRequest($request); 12 + $controller = id(new PhabricatorApplicationSearchController()) 13 + ->setQueryKey($querykey) 14 + ->setSearchEngine(new PhabricatorTokenGivenSearchEngine()) 15 + ->setNavigation($this->buildSideNav()); 14 16 15 - $tokens_given = id(new PhabricatorTokenGivenQuery()) 16 - ->setViewer($viewer) 17 - ->executeWithCursorPager($pager); 17 + return $this->delegateToController($controller); 18 + } 18 19 19 - $handles = array(); 20 - if ($tokens_given) { 21 - $object_phids = mpull($tokens_given, 'getObjectPHID'); 22 - $viewer_phids = mpull($tokens_given, 'getAuthorPHID'); 23 - $handle_phids = array_merge($object_phids, $viewer_phids); 24 - $handles = id(new PhabricatorHandleQuery()) 25 - ->setViewer($viewer) 26 - ->withPHIDs($handle_phids) 27 - ->execute(); 28 - } 20 + protected function buildSideNav() { 21 + $nav = parent::buildSideNav(); 22 + $viewer = $this->getViewer(); 29 23 30 - $tokens = array(); 31 - if ($tokens_given) { 32 - $token_phids = mpull($tokens_given, 'getTokenPHID'); 33 - $tokens = id(new PhabricatorTokenQuery()) 34 - ->setViewer($viewer) 35 - ->withPHIDs($token_phids) 36 - ->execute(); 37 - $tokens = mpull($tokens, null, 'getPHID'); 38 - } 24 + id(new PhabricatorTokenGivenSearchEngine()) 25 + ->setViewer($viewer) 26 + ->addNavigationItems($nav->getMenu()); 39 27 40 - $list = new PHUIObjectItemListView(); 41 - foreach ($tokens_given as $token_given) { 42 - $handle = $handles[$token_given->getObjectPHID()]; 43 - $token = idx($tokens, $token_given->getTokenPHID()); 44 - 45 - $item = id(new PHUIObjectItemView()); 46 - $item->setHeader($handle->getFullName()); 47 - $item->setHref($handle->getURI()); 48 - 49 - $item->addAttribute($token->renderIcon()); 50 - 51 - $item->addAttribute( 52 - pht( 53 - 'Given by %s on %s', 54 - $handles[$token_given->getAuthorPHID()]->renderLink(), 55 - phabricator_date($token_given->getDateCreated(), $viewer))); 56 - 57 - $list->addItem($item); 58 - } 59 - $title = pht('Tokens Given'); 60 - 61 - $box = id(new PHUIObjectBoxView()) 62 - ->setHeaderText($title) 63 - ->setObjectList($list); 64 - 65 - $nav = $this->buildSideNav(); 66 - $nav->setCrumbs( 67 - $this->buildApplicationCrumbs() 68 - ->addTextCrumb($title)); 69 - $nav->selectFilter('given/'); 70 - 71 - $nav->appendChild($box); 72 - $nav->appendChild($pager); 73 - 74 - return $this->newPage() 75 - ->setTitle($title) 76 - ->appendChild($nav); 77 - 28 + return $nav; 78 29 } 79 30 80 31 }
+96
src/applications/tokens/query/PhabricatorTokenGivenSearchEngine.php
··· 1 + <?php 2 + 3 + final class PhabricatorTokenGivenSearchEngine 4 + extends PhabricatorApplicationSearchEngine { 5 + 6 + public function getResultTypeDescription() { 7 + return pht('Tokens Given'); 8 + } 9 + 10 + public function getApplicationClassName() { 11 + return PhabricatorTokensApplication::class; 12 + } 13 + 14 + public function newQuery() { 15 + return new PhabricatorTokenGivenQuery(); 16 + } 17 + 18 + protected function buildCustomSearchFields() { 19 + return array(); 20 + } 21 + 22 + protected function buildQueryFromParameters(array $map) { 23 + return $this->newQuery(); 24 + } 25 + 26 + protected function getRequiredHandlePHIDsForResultList( 27 + array $tokens_given, 28 + PhabricatorSavedQuery $query) { 29 + $object_phids = mpull($tokens_given, 'getObjectPHID'); 30 + $viewer_phids = mpull($tokens_given, 'getAuthorPHID'); 31 + return array_merge($object_phids, $viewer_phids); 32 + } 33 + 34 + protected function renderResultList( 35 + array $tokens_given, 36 + PhabricatorSavedQuery $saved, 37 + array $handles) { 38 + $viewer = $this->requireViewer(); 39 + 40 + $tokens = array(); 41 + if ($tokens_given) { 42 + $token_phids = mpull($tokens_given, 'getTokenPHID'); 43 + $tokens = id(new PhabricatorTokenQuery()) 44 + ->setViewer($viewer) 45 + ->withPHIDs($token_phids) 46 + ->execute(); 47 + $tokens = mpull($tokens, null, 'getPHID'); 48 + } 49 + 50 + $list = new PHUIObjectItemListView(); 51 + foreach ($tokens_given as $token_given) { 52 + $handle = $handles[$token_given->getObjectPHID()]; 53 + $token = idx($tokens, $token_given->getTokenPHID()); 54 + 55 + $item = id(new PHUIObjectItemView()); 56 + $item->setHeader($handle->getFullName()); 57 + $item->setHref($handle->getURI()); 58 + 59 + $item->addAttribute($token->renderIcon()); 60 + 61 + $item->addAttribute( 62 + pht( 63 + 'Given by %s on %s', 64 + $handles[$token_given->getAuthorPHID()]->renderLink(), 65 + phabricator_date($token_given->getDateCreated(), $viewer))); 66 + 67 + $list->addItem($item); 68 + } 69 + 70 + return id(new PhabricatorApplicationSearchResultView()) 71 + ->setObjectList($list); 72 + } 73 + 74 + protected function getBuiltinQueryNames() { 75 + $names = array(); 76 + $names['all'] = pht('All Tokens Given'); 77 + 78 + return $names; 79 + } 80 + 81 + public function buildSavedQueryFromBuiltin($query_key) { 82 + $query = $this->newSavedQuery(); 83 + $query->setQueryKey($query_key); 84 + 85 + switch ($query_key) { 86 + case 'all': 87 + return $query; 88 + } 89 + 90 + return parent::buildSavedQueryFromBuiltin($query_key); 91 + } 92 + 93 + protected function getURI($path) { 94 + return '/token/given/'.$path; 95 + } 96 + }