mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 22:10:55 +01:00
Use ApplicationSearch in Diffusion
Summary: Ref T2625. Switches Diffusion to ApplicationSearch. Notes: - Rendering is a bit rough, I'll clean that up next. - Ordering is a bit arbitrary, also coming shortly. Test Plan: Used `/diffusion/` to execute various searches. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T2625 Differential Revision: https://secure.phabricator.com/D6917
This commit is contained in:
parent
b4728104f8
commit
904add9f44
4 changed files with 158 additions and 77 deletions
|
@ -1533,6 +1533,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorRepositoryPullEngine' => 'applications/repository/engine/PhabricatorRepositoryPullEngine.php',
|
||||
'PhabricatorRepositoryPullLocalDaemon' => 'applications/repository/daemon/PhabricatorRepositoryPullLocalDaemon.php',
|
||||
'PhabricatorRepositoryQuery' => 'applications/repository/query/PhabricatorRepositoryQuery.php',
|
||||
'PhabricatorRepositorySearchEngine' => 'applications/repository/query/PhabricatorRepositorySearchEngine.php',
|
||||
'PhabricatorRepositoryShortcut' => 'applications/repository/storage/PhabricatorRepositoryShortcut.php',
|
||||
'PhabricatorRepositorySvnCommitChangeParserWorker' => 'applications/repository/worker/commitchangeparser/PhabricatorRepositorySvnCommitChangeParserWorker.php',
|
||||
'PhabricatorRepositorySvnCommitMessageParserWorker' => 'applications/repository/worker/commitmessageparser/PhabricatorRepositorySvnCommitMessageParserWorker.php',
|
||||
|
@ -2536,7 +2537,11 @@ phutil_register_library_map(array(
|
|||
'DiffusionRepositoryEditBasicController' => 'DiffusionController',
|
||||
'DiffusionRepositoryEditController' => 'DiffusionController',
|
||||
'DiffusionRepositoryEditEncodingController' => 'DiffusionController',
|
||||
'DiffusionRepositoryListController' => 'DiffusionController',
|
||||
'DiffusionRepositoryListController' =>
|
||||
array(
|
||||
0 => 'DiffusionController',
|
||||
1 => 'PhabricatorApplicationSearchResultsControllerInterface',
|
||||
),
|
||||
'DiffusionSetupException' => 'AphrontUsageException',
|
||||
'DiffusionStableCommitNameQuery' => 'DiffusionQuery',
|
||||
'DiffusionSvnCommitParentsQuery' => 'DiffusionCommitParentsQuery',
|
||||
|
@ -3665,6 +3670,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorRepositoryPullEngine' => 'PhabricatorRepositoryEngine',
|
||||
'PhabricatorRepositoryPullLocalDaemon' => 'PhabricatorDaemon',
|
||||
'PhabricatorRepositoryQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
'PhabricatorRepositorySearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||
'PhabricatorRepositoryShortcut' => 'PhabricatorRepositoryDAO',
|
||||
'PhabricatorRepositorySvnCommitChangeParserWorker' => 'PhabricatorRepositoryCommitChangeParserWorker',
|
||||
'PhabricatorRepositorySvnCommitMessageParserWorker' => 'PhabricatorRepositoryCommitMessageParserWorker',
|
||||
|
|
|
@ -41,7 +41,8 @@ final class PhabricatorApplicationDiffusion extends PhabricatorApplication {
|
|||
'/r(?P<callsign>[A-Z]+)(?P<commit>[a-z0-9]+)'
|
||||
=> 'DiffusionCommitController',
|
||||
'/diffusion/' => array(
|
||||
'' => 'DiffusionRepositoryListController',
|
||||
'(?:query/(?P<queryKey>[^/]+)/)?'
|
||||
=> 'DiffusionRepositoryListController',
|
||||
'create/' => 'DiffusionRepositoryCreateController',
|
||||
'(?P<callsign>[A-Z]+)/' => array(
|
||||
'' => 'DiffusionRepositoryController',
|
||||
|
|
|
@ -1,56 +1,35 @@
|
|||
<?php
|
||||
|
||||
final class DiffusionRepositoryListController extends DiffusionController {
|
||||
final class DiffusionRepositoryListController extends DiffusionController
|
||||
implements PhabricatorApplicationSearchResultsControllerInterface {
|
||||
|
||||
private $queryKey;
|
||||
|
||||
public function shouldAllowPublic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function willProcessRequest(array $data) {
|
||||
$this->queryKey = idx($data, 'queryKey');
|
||||
}
|
||||
|
||||
public function processRequest() {
|
||||
$request = $this->getRequest();
|
||||
$user = $request->getUser();
|
||||
$controller = id(new PhabricatorApplicationSearchController($request))
|
||||
->setQueryKey($this->queryKey)
|
||||
// ->setPreamble($this->buildShortcuts())
|
||||
->setSearchEngine(new PhabricatorRepositorySearchEngine())
|
||||
->setNavigation($this->buildSideNavView());
|
||||
|
||||
$shortcuts = id(new PhabricatorRepositoryShortcut())->loadAll();
|
||||
if ($shortcuts) {
|
||||
$shortcuts = msort($shortcuts, 'getSequence');
|
||||
return $this->delegateToController($controller);
|
||||
}
|
||||
|
||||
$rows = array();
|
||||
foreach ($shortcuts as $shortcut) {
|
||||
$rows[] = array(
|
||||
$shortcut->getName(),
|
||||
$shortcut->getHref(),
|
||||
$shortcut->getDescription(),
|
||||
);
|
||||
}
|
||||
public function renderResultsList(
|
||||
array $repositories,
|
||||
PhabricatorSavedQuery $query) {
|
||||
assert_instances_of($repositories, 'PhabricatorRepository');
|
||||
|
||||
$list = new PHUIObjectItemListView();
|
||||
$list->setCards(true);
|
||||
$list->setFlush(true);
|
||||
foreach ($rows as $row) {
|
||||
$item = id(new PHUIObjectItemView())
|
||||
->setHeader($row[0])
|
||||
->setHref($row[1])
|
||||
->setSubhead(($row[2] ? $row[2] : pht('No Description')));
|
||||
$list->addItem($item);
|
||||
}
|
||||
|
||||
$shortcut_panel = id(new AphrontPanelView())
|
||||
->setNoBackground(true)
|
||||
->setHeader(pht('Shortcuts'))
|
||||
->appendChild($list);
|
||||
|
||||
} else {
|
||||
$shortcut_panel = null;
|
||||
}
|
||||
|
||||
$repositories = id(new PhabricatorRepositoryQuery())
|
||||
->setViewer($user)
|
||||
->needCommitCounts(true)
|
||||
->needMostRecentCommits(true)
|
||||
->execute();
|
||||
|
||||
foreach ($repositories as $key => $repo) {
|
||||
if (!$repo->isTracked()) {
|
||||
unset($repositories[$key]);
|
||||
}
|
||||
}
|
||||
$repositories = msort($repositories, 'getName');
|
||||
$viewer = $this->getRequest()->getUser();
|
||||
|
||||
$rows = array();
|
||||
foreach ($repositories as $repository) {
|
||||
|
@ -70,8 +49,8 @@ final class DiffusionRepositoryListController extends DiffusionController {
|
|||
$datetime = '';
|
||||
$most_recent_commit = $repository->getMostRecentCommit();
|
||||
if ($most_recent_commit) {
|
||||
$date = phabricator_date($most_recent_commit->getEpoch(), $user);
|
||||
$time = phabricator_time($most_recent_commit->getEpoch(), $user);
|
||||
$date = phabricator_date($most_recent_commit->getEpoch(), $viewer);
|
||||
$time = phabricator_time($most_recent_commit->getEpoch(), $viewer);
|
||||
$datetime = $date.' '.$time;
|
||||
}
|
||||
|
||||
|
@ -99,7 +78,7 @@ final class DiffusionRepositoryListController extends DiffusionController {
|
|||
'repository tool');
|
||||
$preface = pht('This instance of Phabricator does not have any '.
|
||||
'configured repositories.');
|
||||
if ($user->getIsAdmin()) {
|
||||
if ($viewer->getIsAdmin()) {
|
||||
$no_repositories_txt = hsprintf(
|
||||
'%s %s',
|
||||
$preface,
|
||||
|
@ -117,41 +96,70 @@ final class DiffusionRepositoryListController extends DiffusionController {
|
|||
}
|
||||
|
||||
$list = new PHUIObjectItemListView();
|
||||
$list->setCards(true);
|
||||
$list->setFlush(true);
|
||||
foreach ($rows as $row) {
|
||||
$item = id(new PHUIObjectItemView())
|
||||
->setHeader($row[0])
|
||||
->setSubHead($row[4])
|
||||
->setHref($row[1])
|
||||
->addAttribute(($row[2] ? $row[2] : pht('No Information')))
|
||||
->addAttribute(($row[3] ? $row[3] : pht('0 Commits')))
|
||||
->addIcon('none', $row[5]);
|
||||
->setHeader($row[0])
|
||||
->setSubHead($row[4])
|
||||
->setHref($row[1])
|
||||
->addAttribute(($row[2] ? $row[2] : pht('No Information')))
|
||||
->addAttribute(($row[3] ? $row[3] : pht('0 Commits')))
|
||||
->addIcon('none', $row[5]);
|
||||
$list->addItem($item);
|
||||
}
|
||||
|
||||
$list = id(new AphrontPanelView())
|
||||
->setNoBackground(true)
|
||||
->setHeader(pht('Repositories'))
|
||||
->appendChild($list);
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function buildSideNavView($for_app = false) {
|
||||
$viewer = $this->getRequest()->getUser();
|
||||
|
||||
$nav = new AphrontSideNavFilterView();
|
||||
$nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
|
||||
|
||||
|
||||
$crumbs = $this->buildCrumbs();
|
||||
$crumbs->addCrumb(
|
||||
id(new PhabricatorCrumbView())
|
||||
->setName(pht('All Repositories'))
|
||||
->setHref($this->getApplicationURI()));
|
||||
id(new PhabricatorRepositorySearchEngine())
|
||||
->setViewer($viewer)
|
||||
->addNavigationItems($nav->getMenu());
|
||||
|
||||
return $this->buildApplicationPage(
|
||||
array(
|
||||
$crumbs,
|
||||
$shortcut_panel,
|
||||
$list,
|
||||
),
|
||||
array(
|
||||
'title' => pht('Diffusion'),
|
||||
'device' => true,
|
||||
));
|
||||
$nav->selectFilter(null);
|
||||
|
||||
return $nav;
|
||||
}
|
||||
|
||||
private function buildShortcuts() {
|
||||
$shortcuts = id(new PhabricatorRepositoryShortcut())->loadAll();
|
||||
if ($shortcuts) {
|
||||
$shortcuts = msort($shortcuts, 'getSequence');
|
||||
|
||||
$rows = array();
|
||||
foreach ($shortcuts as $shortcut) {
|
||||
$rows[] = array(
|
||||
$shortcut->getName(),
|
||||
$shortcut->getHref(),
|
||||
$shortcut->getDescription(),
|
||||
);
|
||||
}
|
||||
|
||||
$list = new PHUIObjectItemListView();
|
||||
$list->setCards(true);
|
||||
$list->setFlush(true);
|
||||
foreach ($rows as $row) {
|
||||
$item = id(new PHUIObjectItemView())
|
||||
->setHeader($row[0])
|
||||
->setHref($row[1])
|
||||
->setSubhead(($row[2] ? $row[2] : pht('No Description')));
|
||||
$list->addItem($item);
|
||||
}
|
||||
|
||||
$shortcut_panel = id(new AphrontPanelView())
|
||||
->setNoBackground(true)
|
||||
->setHeader(pht('Shortcuts'))
|
||||
->appendChild($list);
|
||||
|
||||
} else {
|
||||
$shortcut_panel = null;
|
||||
}
|
||||
return $shortcut_panel;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorRepositorySearchEngine
|
||||
extends PhabricatorApplicationSearchEngine {
|
||||
|
||||
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
||||
$saved = new PhabricatorSavedQuery();
|
||||
|
||||
$saved->setParameter('callsigns', $request->getStrList('callsigns'));
|
||||
|
||||
return $saved;
|
||||
}
|
||||
|
||||
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
||||
$query = id(new PhabricatorRepositoryQuery())
|
||||
->needCommitCounts(true)
|
||||
->needMostRecentCommits(true);
|
||||
|
||||
$callsigns = $saved->getParameter('callsigns');
|
||||
if ($callsigns) {
|
||||
$query->withCallsigns($callsigns);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function buildSearchForm(
|
||||
AphrontFormView $form,
|
||||
PhabricatorSavedQuery $saved_query) {
|
||||
|
||||
$callsigns = $saved_query->getParameter('callsigns', array());
|
||||
|
||||
$form
|
||||
->appendChild(
|
||||
id(new AphrontFormTextControl())
|
||||
->setName('callsigns')
|
||||
->setLabel(pht('Callsigns'))
|
||||
->setValue(implode(', ', $callsigns)));
|
||||
}
|
||||
|
||||
protected function getURI($path) {
|
||||
return '/diffusion/'.$path;
|
||||
}
|
||||
|
||||
public function getBuiltinQueryNames() {
|
||||
$names = array(
|
||||
'all' => pht('All Repositories'),
|
||||
);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue