mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-20 18:58:56 +01:00
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
This commit is contained in:
parent
6b6c3c84d1
commit
75267e24e7
4 changed files with 116 additions and 66 deletions
|
@ -5047,6 +5047,7 @@ phutil_register_library_map(array(
|
|||
'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 @@ phutil_register_library_map(array(
|
|||
'PhabricatorTokenGivenEditor' => 'PhabricatorEditor',
|
||||
'PhabricatorTokenGivenFeedStory' => 'PhabricatorFeedStory',
|
||||
'PhabricatorTokenGivenQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
'PhabricatorTokenGivenSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||
'PhabricatorTokenLeaderController' => 'PhabricatorTokenController',
|
||||
'PhabricatorTokenQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
'PhabricatorTokenReceiverQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
|
|
|
@ -30,7 +30,8 @@ final class PhabricatorTokensApplication extends PhabricatorApplication {
|
|||
return array(
|
||||
'/token/' => array(
|
||||
'' => 'PhabricatorTokenGivenController',
|
||||
'given/' => 'PhabricatorTokenGivenController',
|
||||
$this->getQueryRoutePattern('given/') =>
|
||||
'PhabricatorTokenGivenController',
|
||||
'give/(?<phid>[^/]+)/' => 'PhabricatorTokenGiveController',
|
||||
'leaders/' => 'PhabricatorTokenLeaderController',
|
||||
),
|
||||
|
|
|
@ -6,75 +6,26 @@ final class PhabricatorTokenGivenController extends PhabricatorTokenController {
|
|||
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);
|
||||
$controller = id(new PhabricatorApplicationSearchController())
|
||||
->setQueryKey($querykey)
|
||||
->setSearchEngine(new PhabricatorTokenGivenSearchEngine())
|
||||
->setNavigation($this->buildSideNav());
|
||||
|
||||
$tokens_given = id(new PhabricatorTokenGivenQuery())
|
||||
return $this->delegateToController($controller);
|
||||
}
|
||||
|
||||
protected function buildSideNav() {
|
||||
$nav = parent::buildSideNav();
|
||||
$viewer = $this->getViewer();
|
||||
|
||||
id(new PhabricatorTokenGivenSearchEngine())
|
||||
->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);
|
||||
->addNavigationItems($nav->getMenu());
|
||||
|
||||
return $nav;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue