2011-03-07 15:13:36 -08:00
|
|
|
<?php
|
|
|
|
|
|
2013-09-10 15:26:08 -07:00
|
|
|
final class DiffusionRepositoryListController extends DiffusionController
|
|
|
|
|
implements PhabricatorApplicationSearchResultsControllerInterface {
|
2011-03-07 15:13:36 -08:00
|
|
|
|
2013-09-10 15:26:08 -07:00
|
|
|
private $queryKey;
|
2011-03-31 00:33:44 -07:00
|
|
|
|
2013-09-10 15:26:08 -07:00
|
|
|
public function shouldAllowPublic() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2011-03-31 00:33:44 -07:00
|
|
|
|
2013-09-10 15:26:08 -07:00
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
|
$this->queryKey = idx($data, 'queryKey');
|
|
|
|
|
}
|
2013-05-11 08:23:19 -07:00
|
|
|
|
2013-09-10 15:26:08 -07:00
|
|
|
public function processRequest() {
|
|
|
|
|
$request = $this->getRequest();
|
|
|
|
|
$controller = id(new PhabricatorApplicationSearchController($request))
|
|
|
|
|
->setQueryKey($this->queryKey)
|
2013-09-08 11:52:49 -07:00
|
|
|
->setPreface($this->buildShortcuts())
|
2013-09-10 15:26:08 -07:00
|
|
|
->setSearchEngine(new PhabricatorRepositorySearchEngine())
|
|
|
|
|
->setNavigation($this->buildSideNavView());
|
2013-05-11 08:23:19 -07:00
|
|
|
|
2013-09-10 15:26:08 -07:00
|
|
|
return $this->delegateToController($controller);
|
|
|
|
|
}
|
2011-03-07 15:13:36 -08:00
|
|
|
|
2013-09-10 15:26:08 -07:00
|
|
|
public function renderResultsList(
|
|
|
|
|
array $repositories,
|
|
|
|
|
PhabricatorSavedQuery $query) {
|
|
|
|
|
assert_instances_of($repositories, 'PhabricatorRepository');
|
2011-03-20 17:46:02 -07:00
|
|
|
|
2013-09-10 15:26:08 -07:00
|
|
|
$viewer = $this->getRequest()->getUser();
|
2011-03-07 15:13:36 -08:00
|
|
|
|
2013-09-10 15:41:27 -07:00
|
|
|
$list = new PHUIObjectItemListView();
|
2011-03-07 15:13:36 -08:00
|
|
|
foreach ($repositories as $repository) {
|
2011-03-12 22:51:40 -08:00
|
|
|
$id = $repository->getID();
|
2011-03-20 17:46:02 -07:00
|
|
|
|
2013-09-10 15:42:37 -07:00
|
|
|
$item = id(new PHUIObjectItemView())
|
2013-09-08 12:10:11 -07:00
|
|
|
->setUser($viewer)
|
|
|
|
|
->setHeader($repository->getName())
|
|
|
|
|
->setHref($this->getApplicationURI($repository->getCallsign().'/'));
|
|
|
|
|
|
|
|
|
|
$commit = $repository->getMostRecentCommit();
|
|
|
|
|
if ($commit) {
|
|
|
|
|
$commit_link = DiffusionView::linkCommit(
|
|
|
|
|
$repository,
|
|
|
|
|
$commit->getCommitIdentifier(),
|
|
|
|
|
$commit->getSummary());
|
|
|
|
|
$item->setSubhead($commit_link);
|
|
|
|
|
$item->setEpoch($commit->getEpoch());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$item->addAttribute(
|
|
|
|
|
PhabricatorRepositoryType::getNameForRepositoryType(
|
|
|
|
|
$repository->getVersionControlSystem()));
|
|
|
|
|
|
2013-09-10 15:22:41 -07:00
|
|
|
$size = $repository->getCommitCount();
|
|
|
|
|
if ($size) {
|
2013-09-08 12:10:11 -07:00
|
|
|
$history_uri = DiffusionRequest::generateDiffusionURI(
|
|
|
|
|
array(
|
2012-11-08 13:45:21 -08:00
|
|
|
'callsign' => $repository->getCallsign(),
|
|
|
|
|
'action' => 'history',
|
2013-09-08 12:10:11 -07:00
|
|
|
));
|
|
|
|
|
|
|
|
|
|
$item->addAttribute(
|
|
|
|
|
phutil_tag(
|
|
|
|
|
'a',
|
|
|
|
|
array(
|
|
|
|
|
'href' => $history_uri,
|
|
|
|
|
),
|
|
|
|
|
pht('%s Commit(s)', new PhutilNumber($size))));
|
|
|
|
|
} else {
|
|
|
|
|
$item->addAttribute(pht('No Commits'));
|
2012-11-08 13:45:21 -08:00
|
|
|
}
|
2011-03-20 17:46:02 -07:00
|
|
|
|
2013-09-08 12:10:11 -07:00
|
|
|
if (!$repository->isTracked()) {
|
|
|
|
|
$item->setDisabled(true);
|
|
|
|
|
$item->addIcon('disable-grey', pht('Inactive'));
|
2011-03-12 22:51:40 -08:00
|
|
|
}
|
|
|
|
|
|
2013-05-11 08:23:19 -07:00
|
|
|
$list->addItem($item);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-10 15:26:08 -07:00
|
|
|
return $list;
|
|
|
|
|
}
|
2011-03-07 15:13:36 -08:00
|
|
|
|
2013-09-10 15:26:08 -07:00
|
|
|
public function buildSideNavView($for_app = false) {
|
|
|
|
|
$viewer = $this->getRequest()->getUser();
|
2011-03-07 15:13:36 -08:00
|
|
|
|
2013-09-10 15:26:08 -07:00
|
|
|
$nav = new AphrontSideNavFilterView();
|
|
|
|
|
$nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
|
2011-03-12 16:17:34 -08:00
|
|
|
|
2013-09-10 15:26:08 -07:00
|
|
|
|
|
|
|
|
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');
|
|
|
|
|
|
|
|
|
|
$rows = array();
|
|
|
|
|
foreach ($shortcuts as $shortcut) {
|
|
|
|
|
$rows[] = array(
|
|
|
|
|
$shortcut->getName(),
|
|
|
|
|
$shortcut->getHref(),
|
|
|
|
|
$shortcut->getDescription(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$list = new PHUIObjectItemListView();
|
|
|
|
|
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);
|
|
|
|
|
}
|
2013-09-08 11:52:49 -07:00
|
|
|
$shortcut_panel = array($list, phutil_tag('hr'));
|
2013-09-10 15:26:08 -07:00
|
|
|
} else {
|
|
|
|
|
$shortcut_panel = null;
|
|
|
|
|
}
|
|
|
|
|
return $shortcut_panel;
|
2011-03-07 15:13:36 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|