Skip to content

Commit 210e30c

Browse files
author
epriestley
committedAug 17, 2013
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
1 parent f909a29 commit 210e30c

8 files changed

+322
-215
lines changed
 

‎src/__phutil_library_map__.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -1946,6 +1946,7 @@
19461946
'ReleephBranchNamePreviewController' => 'applications/releeph/controller/branch/ReleephBranchNamePreviewController.php',
19471947
'ReleephBranchPreviewView' => 'applications/releeph/view/branch/ReleephBranchPreviewView.php',
19481948
'ReleephBranchQuery' => 'applications/releeph/query/ReleephBranchQuery.php',
1949+
'ReleephBranchSearchEngine' => 'applications/releeph/query/ReleephBranchSearchEngine.php',
19491950
'ReleephBranchTemplate' => 'applications/releeph/view/branch/ReleephBranchTemplate.php',
19501951
'ReleephBranchViewController' => 'applications/releeph/controller/branch/ReleephBranchViewController.php',
19511952
'ReleephCommitFinder' => 'applications/releeph/commitfinder/ReleephCommitFinder.php',
@@ -1979,7 +1980,6 @@
19791980
'ReleephProjectListController' => 'applications/releeph/controller/project/ReleephProjectListController.php',
19801981
'ReleephProjectQuery' => 'applications/releeph/query/ReleephProjectQuery.php',
19811982
'ReleephProjectSearchEngine' => 'applications/releeph/query/ReleephProjectSearchEngine.php',
1982-
'ReleephProjectView' => 'applications/releeph/view/ReleephProjectView.php',
19831983
'ReleephProjectViewController' => 'applications/releeph/controller/project/ReleephProjectViewController.php',
19841984
'ReleephReasonFieldSpecification' => 'applications/releeph/field/specification/ReleephReasonFieldSpecification.php',
19851985
'ReleephRequest' => 'applications/releeph/storage/ReleephRequest.php',
@@ -4128,6 +4128,7 @@
41284128
'ReleephBranchNamePreviewController' => 'ReleephController',
41294129
'ReleephBranchPreviewView' => 'AphrontFormControl',
41304130
'ReleephBranchQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
4131+
'ReleephBranchSearchEngine' => 'PhabricatorApplicationSearchEngine',
41314132
'ReleephBranchViewController' =>
41324133
array(
41334134
0 => 'ReleephProjectController',
@@ -4172,8 +4173,11 @@
41724173
),
41734174
'ReleephProjectQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
41744175
'ReleephProjectSearchEngine' => 'PhabricatorApplicationSearchEngine',
4175-
'ReleephProjectView' => 'AphrontView',
4176-
'ReleephProjectViewController' => 'ReleephProjectController',
4176+
'ReleephProjectViewController' =>
4177+
array(
4178+
0 => 'ReleephProjectController',
4179+
1 => 'PhabricatorApplicationSearchResultsControllerInterface',
4180+
),
41774181
'ReleephReasonFieldSpecification' => 'ReleephFieldSpecification',
41784182
'ReleephRequest' =>
41794183
array(

‎src/applications/releeph/application/PhabricatorApplicationReleeph.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ public function getRoutes() {
3838
'(?:query/(?P<queryKey>[^/]+)/)?' => 'ReleephProjectListController',
3939
'create/' => 'ReleephProjectCreateController',
4040
'(?P<projectID>[1-9]\d*)/' => array(
41-
'' => 'ReleephProjectViewController',
42-
'closedbranches/' => 'ReleephProjectViewController',
41+
'(?:query/(?P<queryKey>[^/]+)/)?' => 'ReleephProjectViewController',
4342
'edit/' => 'ReleephProjectEditController',
4443
'cutbranch/' => 'ReleephBranchCreateController',
4544
'action/(?P<action>.+)/' => 'ReleephProjectActionController',

‎src/applications/releeph/controller/branch/ReleephBranchAccessController.php

+18-20
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,28 @@ public function willProcessRequest(array $data) {
1010
}
1111

1212
public function processRequest() {
13-
$rph_branch = $this->getReleephBranch();
13+
$branch = $this->getReleephBranch();
1414
$request = $this->getRequest();
1515

16-
$active_uri = '/releeph/project/'.$rph_branch->getReleephProjectID().'/';
17-
$inactive_uri = $active_uri.'inactive/';
16+
$done_uri = '/releeph/project/'.$branch->getReleephProjectID().'/';
1817

1918
switch ($this->action) {
2019
case 'close':
2120
$is_active = false;
22-
$origin_uri = $active_uri;
21+
$title_text = pht('Close Branch');
22+
$body_text = pht(
23+
'Really close the branch "%s"?',
24+
$branch->getBasename());
25+
$button_text = pht('Close Branch');
2326
break;
24-
2527
case 're-open':
2628
$is_active = true;
27-
$origin_uri = $inactive_uri;
29+
$title_text = pht('Reopen Branch');
30+
$body_text = pht(
31+
'Really reopen the branch "%s"?',
32+
$branch->getBasename());
33+
$button_text = pht('Reopen Branch');
2834
break;
29-
3035
default:
3136
throw new Exception("Unknown action '{$this->action}'!");
3237
break;
@@ -35,26 +40,19 @@ public function processRequest() {
3540
if ($request->isDialogFormPost()) {
3641
id(new ReleephBranchEditor())
3742
->setActor($request->getUser())
38-
->setReleephBranch($rph_branch)
43+
->setReleephBranch($branch)
3944
->changeBranchAccess($is_active ? 1 : 0);
40-
return id(new AphrontRedirectResponse())
41-
->setURI($origin_uri);
42-
}
43-
44-
$button_text = pht('%s Branch', $this->action);
45-
$text = pht('Really %s the branch: %s?',
46-
$this->action,
47-
$rph_branch->getBasename());
48-
$message = phutil_tag('p', array(), $text);
4945

46+
return id(new AphrontReloadResponse())->setURI($done_uri);
47+
}
5048

5149
$dialog = new AphrontDialogView();
5250
$dialog
5351
->setUser($request->getUser())
54-
->setTitle(pht('Confirm'))
55-
->appendChild($message)
52+
->setTitle($title_text)
53+
->appendChild($body_text)
5654
->addSubmitButton($button_text)
57-
->addCancelButton($origin_uri);
55+
->addCancelButton($done_uri);
5856

5957
return id(new AphrontDialogResponse())->setDialog($dialog);
6058
}
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,172 @@
11
<?php
22

3-
final class ReleephProjectViewController extends ReleephProjectController {
3+
final class ReleephProjectViewController extends ReleephProjectController
4+
implements PhabricatorApplicationSearchResultsControllerInterface {
5+
6+
private $queryKey;
7+
8+
public function shouldAllowPublic() {
9+
return true;
10+
}
11+
12+
public function willProcessRequest(array $data) {
13+
parent::willProcessRequest($data);
14+
$this->queryKey = idx($data, 'queryKey');
15+
}
416

517
public function processRequest() {
6-
// Load all branches
7-
$releeph_project = $this->getReleephProject();
8-
$releeph_branches = id(new ReleephBranch())
9-
->loadAllWhere('releephProjectID = %d',
10-
$releeph_project->getID());
11-
12-
$path = $this->getRequest()->getRequestURI()->getPath();
13-
$is_open_branches = strpos($path, 'closedbranches/') === false;
14-
15-
$view = id(new ReleephProjectView())
16-
->setShowOpenBranches($is_open_branches)
17-
->setUser($this->getRequest()->getUser())
18-
->setReleephProject($releeph_project)
19-
->setBranches($releeph_branches);
20-
21-
$crumbs = $this->buildApplicationCrumbs()
22-
->addCrumb(
23-
id(new PhabricatorCrumbView())
24-
->setName($releeph_project->getName())
25-
->setHref($releeph_project->getURI()));
26-
27-
if ($releeph_project->getIsActive()) {
28-
$crumbs->addAction(
18+
$request = $this->getRequest();
19+
$controller = id(new PhabricatorApplicationSearchController($request))
20+
->setQueryKey($this->queryKey)
21+
->setSearchEngine(
22+
id(new ReleephBranchSearchEngine())
23+
->setProjectID($this->getReleephProject()->getID()))
24+
->setNavigation($this->buildSideNavView());
25+
26+
return $this->delegateToController($controller);
27+
}
28+
29+
public function renderResultsList(
30+
array $branches,
31+
PhabricatorSavedQuery $saved) {
32+
assert_instances_of($branches, 'ReleephBranch');
33+
34+
$viewer = $this->getRequest()->getUser();
35+
36+
$projects = mpull($branches, 'getProject');
37+
$repo_phids = mpull($projects, 'getRepositoryPHID');
38+
39+
$repos = id(new PhabricatorRepositoryQuery())
40+
->setViewer($viewer)
41+
->withPHIDs($repo_phids)
42+
->execute();
43+
$repos = mpull($repos, null, 'getPHID');
44+
45+
$phids = mpull($branches, 'getCreatedByUserPHID');
46+
$this->loadHandles($phids);
47+
48+
$requests = array();
49+
if ($branches) {
50+
$requests = id(new ReleephRequestQuery())
51+
->setViewer($viewer)
52+
->withBranchIDs(mpull($branches, 'getID'))
53+
->withStatus(ReleephRequestQuery::STATUS_OPEN)
54+
->execute();
55+
$requests = mgroup($requests, 'getBranchID');
56+
}
57+
58+
$list = id(new PhabricatorObjectItemListView())
59+
->setUser($viewer);
60+
foreach ($branches as $branch) {
61+
$diffusion_href = null;
62+
$repo = idx($repos, $branch->getProject()->getRepositoryPHID());
63+
if ($repo) {
64+
$drequest = DiffusionRequest::newFromDictionary(
65+
array(
66+
'user' => $viewer,
67+
'repository' => $repo,
68+
));
69+
70+
$diffusion_href = $drequest->generateURI(
71+
array(
72+
'action' => 'branch',
73+
'branch' => $branch->getName(),
74+
));
75+
}
76+
77+
$branch_link = $branch->getName();
78+
if ($diffusion_href) {
79+
$branch_link = phutil_tag(
80+
'a',
81+
array(
82+
'href' => $diffusion_href,
83+
),
84+
$branch_link);
85+
}
86+
87+
$item = id(new PhabricatorObjectItemView())
88+
->setHeader($branch->getDisplayName())
89+
->setHref($branch->getURI())
90+
->addAttribute($branch_link);
91+
92+
$item->addAction(
2993
id(new PHUIListItemView())
30-
->setHref($releeph_project->getURI('cutbranch'))
31-
->setName(pht('Cut New Branch'))
32-
->setIcon('create'));
94+
->setIcon('edit')
95+
->setHref($branch->getURI('edit/')));
96+
97+
if ($branch->getIsActive()) {
98+
$item->setBarColor('blue');
99+
$item->addAction(
100+
id(new PHUIListItemView())
101+
->setIcon('delete')
102+
->setWorkflow(true)
103+
->setHref($branch->getURI('close/')));
104+
} else {
105+
$item->setDisabled(true);
106+
$item->addAction(
107+
id(new PHUIListItemView())
108+
->setIcon('enable')
109+
->setWorkflow(true)
110+
->setHref($branch->getURI('re-open/')));
111+
}
112+
113+
$commit = $branch->getCutPointCommit();
114+
if ($commit) {
115+
$item->addIcon(
116+
'none',
117+
phabricator_datetime($commit->getEpoch(), $viewer));
118+
}
119+
120+
$open_count = count(idx($requests, $branch->getID(), array()));
121+
if ($open_count) {
122+
$item->setBarColor('orange');
123+
$item->addIcon(
124+
'fork',
125+
pht('%d Open Pull Request(s)', new PhutilNumber($open_count)));
126+
}
127+
128+
$list->addItem($item);
129+
}
130+
131+
return $list;
132+
}
133+
134+
public function buildSideNavView($for_app = false) {
135+
$user = $this->getRequest()->getUser();
136+
137+
$nav = new AphrontSideNavFilterView();
138+
$nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
139+
140+
if ($for_app) {
141+
$nav->addFilter('project/create/', pht('Create Project'));
33142
}
34143

35-
return $this->buildStandardPageResponse(
36-
array(
37-
$crumbs,
38-
$view,
39-
),
40-
array(
41-
'title' => $releeph_project->getName()
42-
));
144+
id(new ReleephBranchSearchEngine())
145+
->setProjectID($this->getReleephProject()->getID())
146+
->setViewer($user)
147+
->addNavigationItems($nav->getMenu());
148+
149+
$nav->selectFilter(null);
150+
151+
return $nav;
152+
}
153+
154+
public function buildApplicationCrumbs() {
155+
$crumbs = parent::buildApplicationCrumbs();
156+
157+
$project = $this->getReleephProject();
158+
159+
$crumbs->addCrumb(
160+
id(new PhabricatorCrumbView())
161+
->setName($project->getName()));
162+
163+
$crumbs->addAction(
164+
id(new PHUIListItemView())
165+
->setHref($project->getURI('cutbranch'))
166+
->setName(pht('Cut New Branch'))
167+
->setIcon('create'));
168+
169+
return $crumbs;
43170
}
44171

45172
}

‎src/applications/releeph/query/ReleephBranchQuery.php

+35
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ final class ReleephBranchQuery
55

66
private $ids;
77
private $phids;
8+
private $projectIDs;
9+
10+
const STATUS_ALL = 'status-all';
11+
const STATUS_OPEN = 'status-open';
12+
private $status = self::STATUS_ALL;
813

914
private $needCutPointCommits;
1015

@@ -23,6 +28,16 @@ public function needCutPointCommits($need_commits) {
2328
return $this;
2429
}
2530

31+
public function withStatus($status) {
32+
$this->status = $status;
33+
return $this;
34+
}
35+
36+
public function withProjectIDs(array $ids) {
37+
$this->projectIDs = $ids;
38+
return $this;
39+
}
40+
2641
public function loadPage() {
2742
$table = new ReleephBranch();
2843
$conn_r = $table->establishConnection('r');
@@ -89,6 +104,26 @@ private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
89104
$this->phids);
90105
}
91106

107+
if ($this->projectIDs) {
108+
$where[] = qsprintf(
109+
$conn_r,
110+
'releephProjectID IN (%Ld)',
111+
$this->projectIDs);
112+
}
113+
114+
$status = $this->status;
115+
switch ($status) {
116+
case self::STATUS_ALL:
117+
break;
118+
case self::STATUS_OPEN:
119+
$where[] = qsprintf(
120+
$conn_r,
121+
'isActive = 1');
122+
break;
123+
default:
124+
throw new Exception("Unknown status constant '{$status}'!");
125+
}
126+
92127
$where[] = $this->buildPagingClause($conn_r);
93128

94129
return $this->formatWhereClause($where);

0 commit comments

Comments
 (0)
Failed to load comments.