mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-27 09:12:41 +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,11 +1,132 @@
|
|||
<?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());
|
||||
|
||||
return $this->delegateToController($controller);
|
||||
}
|
||||
|
||||
public function renderResultsList(
|
||||
array $repositories,
|
||||
PhabricatorSavedQuery $query) {
|
||||
assert_instances_of($repositories, 'PhabricatorRepository');
|
||||
|
||||
$viewer = $this->getRequest()->getUser();
|
||||
|
||||
$rows = array();
|
||||
foreach ($repositories as $repository) {
|
||||
$id = $repository->getID();
|
||||
|
||||
$size = $repository->getCommitCount();
|
||||
if ($size) {
|
||||
$size = hsprintf(
|
||||
'<a href="%s">%s</a>',
|
||||
DiffusionRequest::generateDiffusionURI(array(
|
||||
'callsign' => $repository->getCallsign(),
|
||||
'action' => 'history',
|
||||
)),
|
||||
pht('%s Commits', new PhutilNumber($size)));
|
||||
}
|
||||
|
||||
$datetime = '';
|
||||
$most_recent_commit = $repository->getMostRecentCommit();
|
||||
if ($most_recent_commit) {
|
||||
$date = phabricator_date($most_recent_commit->getEpoch(), $viewer);
|
||||
$time = phabricator_time($most_recent_commit->getEpoch(), $viewer);
|
||||
$datetime = $date.' '.$time;
|
||||
}
|
||||
|
||||
$rows[] = array(
|
||||
$repository->getName(),
|
||||
('/diffusion/'.$repository->getCallsign().'/'),
|
||||
PhabricatorRepositoryType::getNameForRepositoryType(
|
||||
$repository->getVersionControlSystem()),
|
||||
$size ? $size : null,
|
||||
$most_recent_commit
|
||||
? DiffusionView::linkCommit(
|
||||
$repository,
|
||||
$most_recent_commit->getCommitIdentifier(),
|
||||
$most_recent_commit->getSummary())
|
||||
: pht('No Commits'),
|
||||
$datetime
|
||||
);
|
||||
}
|
||||
|
||||
$repository_tool_uri = PhabricatorEnv::getProductionURI('/repository/');
|
||||
$repository_tool = phutil_tag('a',
|
||||
array(
|
||||
'href' => $repository_tool_uri,
|
||||
),
|
||||
'repository tool');
|
||||
$preface = pht('This instance of Phabricator does not have any '.
|
||||
'configured repositories.');
|
||||
if ($viewer->getIsAdmin()) {
|
||||
$no_repositories_txt = hsprintf(
|
||||
'%s %s',
|
||||
$preface,
|
||||
pht(
|
||||
'To setup one or more repositories, visit the %s.',
|
||||
$repository_tool));
|
||||
} else {
|
||||
$no_repositories_txt = hsprintf(
|
||||
'%s %s',
|
||||
$preface,
|
||||
pht(
|
||||
'Ask an administrator to setup one or more repositories '.
|
||||
'via the %s.',
|
||||
$repository_tool));
|
||||
}
|
||||
|
||||
$list = new PHUIObjectItemListView();
|
||||
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]);
|
||||
$list->addItem($item);
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function buildSideNavView($for_app = false) {
|
||||
$viewer = $this->getRequest()->getUser();
|
||||
|
||||
$nav = new AphrontSideNavFilterView();
|
||||
$nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
|
||||
|
||||
|
||||
id(new PhabricatorRepositorySearchEngine())
|
||||
->setViewer($viewer)
|
||||
->addNavigationItems($nav->getMenu());
|
||||
|
||||
$nav->selectFilter(null);
|
||||
|
||||
return $nav;
|
||||
}
|
||||
|
||||
private function buildShortcuts() {
|
||||
$shortcuts = id(new PhabricatorRepositoryShortcut())->loadAll();
|
||||
if ($shortcuts) {
|
||||
$shortcuts = msort($shortcuts, 'getSequence');
|
||||
|
@ -38,120 +159,7 @@ final class DiffusionRepositoryListController extends DiffusionController {
|
|||
} 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');
|
||||
|
||||
$rows = array();
|
||||
foreach ($repositories as $repository) {
|
||||
$id = $repository->getID();
|
||||
|
||||
$size = $repository->getCommitCount();
|
||||
if ($size) {
|
||||
$size = hsprintf(
|
||||
'<a href="%s">%s</a>',
|
||||
DiffusionRequest::generateDiffusionURI(array(
|
||||
'callsign' => $repository->getCallsign(),
|
||||
'action' => 'history',
|
||||
)),
|
||||
pht('%s Commits', new PhutilNumber($size)));
|
||||
}
|
||||
|
||||
$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);
|
||||
$datetime = $date.' '.$time;
|
||||
}
|
||||
|
||||
$rows[] = array(
|
||||
$repository->getName(),
|
||||
('/diffusion/'.$repository->getCallsign().'/'),
|
||||
PhabricatorRepositoryType::getNameForRepositoryType(
|
||||
$repository->getVersionControlSystem()),
|
||||
$size ? $size : null,
|
||||
$most_recent_commit
|
||||
? DiffusionView::linkCommit(
|
||||
$repository,
|
||||
$most_recent_commit->getCommitIdentifier(),
|
||||
$most_recent_commit->getSummary())
|
||||
: pht('No Commits'),
|
||||
$datetime
|
||||
);
|
||||
}
|
||||
|
||||
$repository_tool_uri = PhabricatorEnv::getProductionURI('/repository/');
|
||||
$repository_tool = phutil_tag('a',
|
||||
array(
|
||||
'href' => $repository_tool_uri,
|
||||
),
|
||||
'repository tool');
|
||||
$preface = pht('This instance of Phabricator does not have any '.
|
||||
'configured repositories.');
|
||||
if ($user->getIsAdmin()) {
|
||||
$no_repositories_txt = hsprintf(
|
||||
'%s %s',
|
||||
$preface,
|
||||
pht(
|
||||
'To setup one or more repositories, visit the %s.',
|
||||
$repository_tool));
|
||||
} else {
|
||||
$no_repositories_txt = hsprintf(
|
||||
'%s %s',
|
||||
$preface,
|
||||
pht(
|
||||
'Ask an administrator to setup one or more repositories '.
|
||||
'via the %s.',
|
||||
$repository_tool));
|
||||
}
|
||||
|
||||
$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]);
|
||||
$list->addItem($item);
|
||||
}
|
||||
|
||||
$list = id(new AphrontPanelView())
|
||||
->setNoBackground(true)
|
||||
->setHeader(pht('Repositories'))
|
||||
->appendChild($list);
|
||||
|
||||
|
||||
$crumbs = $this->buildCrumbs();
|
||||
$crumbs->addCrumb(
|
||||
id(new PhabricatorCrumbView())
|
||||
->setName(pht('All Repositories'))
|
||||
->setHref($this->getApplicationURI()));
|
||||
|
||||
return $this->buildApplicationPage(
|
||||
array(
|
||||
$crumbs,
|
||||
$shortcut_panel,
|
||||
$list,
|
||||
),
|
||||
array(
|
||||
'title' => pht('Diffusion'),
|
||||
'device' => true,
|
||||
));
|
||||
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