Use ApplicationSearch for Releeph branch lists
Summary:
Releeph branch lists in project views have a bunch of custom UI right now; give them more standard UI and ApplicationSearch.
This drops a small piece of functionality: we now show only a total open request count instead of a detailed enumeration of each request status. I assume this is reasonable (that is, the important piece is "is there something to do on this branch?"), but we can muck with it if the more detailed status is important.
Test Plan: {F54344}
Reviewers: btrahan
Reviewed By: btrahan
CC: LegNeato, aran
Maniphest Tasks: T3656
Differential Revision: https://secure.phabricator.com/D6764
This commit is contained in:
@@ -1,45 +1,172 @@
|
||||
<?php
|
||||
|
||||
final class ReleephProjectViewController extends ReleephProjectController {
|
||||
final class ReleephProjectViewController extends ReleephProjectController
|
||||
implements PhabricatorApplicationSearchResultsControllerInterface {
|
||||
|
||||
private $queryKey;
|
||||
|
||||
public function shouldAllowPublic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function willProcessRequest(array $data) {
|
||||
parent::willProcessRequest($data);
|
||||
$this->queryKey = idx($data, 'queryKey');
|
||||
}
|
||||
|
||||
public function processRequest() {
|
||||
// Load all branches
|
||||
$releeph_project = $this->getReleephProject();
|
||||
$releeph_branches = id(new ReleephBranch())
|
||||
->loadAllWhere('releephProjectID = %d',
|
||||
$releeph_project->getID());
|
||||
$request = $this->getRequest();
|
||||
$controller = id(new PhabricatorApplicationSearchController($request))
|
||||
->setQueryKey($this->queryKey)
|
||||
->setSearchEngine(
|
||||
id(new ReleephBranchSearchEngine())
|
||||
->setProjectID($this->getReleephProject()->getID()))
|
||||
->setNavigation($this->buildSideNavView());
|
||||
|
||||
$path = $this->getRequest()->getRequestURI()->getPath();
|
||||
$is_open_branches = strpos($path, 'closedbranches/') === false;
|
||||
return $this->delegateToController($controller);
|
||||
}
|
||||
|
||||
$view = id(new ReleephProjectView())
|
||||
->setShowOpenBranches($is_open_branches)
|
||||
->setUser($this->getRequest()->getUser())
|
||||
->setReleephProject($releeph_project)
|
||||
->setBranches($releeph_branches);
|
||||
public function renderResultsList(
|
||||
array $branches,
|
||||
PhabricatorSavedQuery $saved) {
|
||||
assert_instances_of($branches, 'ReleephBranch');
|
||||
|
||||
$crumbs = $this->buildApplicationCrumbs()
|
||||
->addCrumb(
|
||||
id(new PhabricatorCrumbView())
|
||||
->setName($releeph_project->getName())
|
||||
->setHref($releeph_project->getURI()));
|
||||
$viewer = $this->getRequest()->getUser();
|
||||
|
||||
if ($releeph_project->getIsActive()) {
|
||||
$crumbs->addAction(
|
||||
id(new PHUIListItemView())
|
||||
->setHref($releeph_project->getURI('cutbranch'))
|
||||
->setName(pht('Cut New Branch'))
|
||||
->setIcon('create'));
|
||||
$projects = mpull($branches, 'getProject');
|
||||
$repo_phids = mpull($projects, 'getRepositoryPHID');
|
||||
|
||||
$repos = id(new PhabricatorRepositoryQuery())
|
||||
->setViewer($viewer)
|
||||
->withPHIDs($repo_phids)
|
||||
->execute();
|
||||
$repos = mpull($repos, null, 'getPHID');
|
||||
|
||||
$phids = mpull($branches, 'getCreatedByUserPHID');
|
||||
$this->loadHandles($phids);
|
||||
|
||||
$requests = array();
|
||||
if ($branches) {
|
||||
$requests = id(new ReleephRequestQuery())
|
||||
->setViewer($viewer)
|
||||
->withBranchIDs(mpull($branches, 'getID'))
|
||||
->withStatus(ReleephRequestQuery::STATUS_OPEN)
|
||||
->execute();
|
||||
$requests = mgroup($requests, 'getBranchID');
|
||||
}
|
||||
|
||||
return $this->buildStandardPageResponse(
|
||||
array(
|
||||
$crumbs,
|
||||
$view,
|
||||
),
|
||||
array(
|
||||
'title' => $releeph_project->getName()
|
||||
));
|
||||
$list = id(new PhabricatorObjectItemListView())
|
||||
->setUser($viewer);
|
||||
foreach ($branches as $branch) {
|
||||
$diffusion_href = null;
|
||||
$repo = idx($repos, $branch->getProject()->getRepositoryPHID());
|
||||
if ($repo) {
|
||||
$drequest = DiffusionRequest::newFromDictionary(
|
||||
array(
|
||||
'user' => $viewer,
|
||||
'repository' => $repo,
|
||||
));
|
||||
|
||||
$diffusion_href = $drequest->generateURI(
|
||||
array(
|
||||
'action' => 'branch',
|
||||
'branch' => $branch->getName(),
|
||||
));
|
||||
}
|
||||
|
||||
$branch_link = $branch->getName();
|
||||
if ($diffusion_href) {
|
||||
$branch_link = phutil_tag(
|
||||
'a',
|
||||
array(
|
||||
'href' => $diffusion_href,
|
||||
),
|
||||
$branch_link);
|
||||
}
|
||||
|
||||
$item = id(new PhabricatorObjectItemView())
|
||||
->setHeader($branch->getDisplayName())
|
||||
->setHref($branch->getURI())
|
||||
->addAttribute($branch_link);
|
||||
|
||||
$item->addAction(
|
||||
id(new PHUIListItemView())
|
||||
->setIcon('edit')
|
||||
->setHref($branch->getURI('edit/')));
|
||||
|
||||
if ($branch->getIsActive()) {
|
||||
$item->setBarColor('blue');
|
||||
$item->addAction(
|
||||
id(new PHUIListItemView())
|
||||
->setIcon('delete')
|
||||
->setWorkflow(true)
|
||||
->setHref($branch->getURI('close/')));
|
||||
} else {
|
||||
$item->setDisabled(true);
|
||||
$item->addAction(
|
||||
id(new PHUIListItemView())
|
||||
->setIcon('enable')
|
||||
->setWorkflow(true)
|
||||
->setHref($branch->getURI('re-open/')));
|
||||
}
|
||||
|
||||
$commit = $branch->getCutPointCommit();
|
||||
if ($commit) {
|
||||
$item->addIcon(
|
||||
'none',
|
||||
phabricator_datetime($commit->getEpoch(), $viewer));
|
||||
}
|
||||
|
||||
$open_count = count(idx($requests, $branch->getID(), array()));
|
||||
if ($open_count) {
|
||||
$item->setBarColor('orange');
|
||||
$item->addIcon(
|
||||
'fork',
|
||||
pht('%d Open Pull Request(s)', new PhutilNumber($open_count)));
|
||||
}
|
||||
|
||||
$list->addItem($item);
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function buildSideNavView($for_app = false) {
|
||||
$user = $this->getRequest()->getUser();
|
||||
|
||||
$nav = new AphrontSideNavFilterView();
|
||||
$nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
|
||||
|
||||
if ($for_app) {
|
||||
$nav->addFilter('project/create/', pht('Create Project'));
|
||||
}
|
||||
|
||||
id(new ReleephBranchSearchEngine())
|
||||
->setProjectID($this->getReleephProject()->getID())
|
||||
->setViewer($user)
|
||||
->addNavigationItems($nav->getMenu());
|
||||
|
||||
$nav->selectFilter(null);
|
||||
|
||||
return $nav;
|
||||
}
|
||||
|
||||
public function buildApplicationCrumbs() {
|
||||
$crumbs = parent::buildApplicationCrumbs();
|
||||
|
||||
$project = $this->getReleephProject();
|
||||
|
||||
$crumbs->addCrumb(
|
||||
id(new PhabricatorCrumbView())
|
||||
->setName($project->getName()));
|
||||
|
||||
$crumbs->addAction(
|
||||
id(new PHUIListItemView())
|
||||
->setHref($project->getURI('cutbranch'))
|
||||
->setName(pht('Cut New Branch'))
|
||||
->setIcon('create'));
|
||||
|
||||
return $crumbs;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user