forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReleephBranchViewController.php
202 lines (161 loc) · 5.65 KB
/
ReleephBranchViewController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<?php
final class ReleephBranchViewController extends ReleephBranchController
implements PhabricatorApplicationSearchResultsControllerInterface {
private $queryKey;
private $branchID;
public function shouldAllowPublic() {
return true;
}
public function willProcessRequest(array $data) {
$this->branchID = $data['branchID'];
$this->queryKey = idx($data, 'queryKey');
}
public function processRequest() {
$request = $this->getRequest();
$viewer = $request->getUser();
$branch = id(new ReleephBranchQuery())
->setViewer($viewer)
->withIDs(array($this->branchID))
->executeOne();
if (!$branch) {
return new Aphront404Response();
}
$this->setBranch($branch);
$controller = id(new PhabricatorApplicationSearchController())
->setPreface($this->renderPreface())
->setQueryKey($this->queryKey)
->setSearchEngine($this->getSearchEngine())
->setNavigation($this->buildSideNavView());
return $this->delegateToController($controller);
}
public function renderResultsList(
array $requests,
PhabricatorSavedQuery $query) {
assert_instances_of($requests, 'ReleephRequest');
$viewer = $this->getRequest()->getUser();
// TODO: This is generally a bit sketchy, but we don't do this kind of
// thing elsewhere at the moment. For the moment it shouldn't be hugely
// costly, and we can batch things later. Generally, this commits fewer
// sins than the old code did.
$engine = id(new PhabricatorMarkupEngine())
->setViewer($viewer);
$list = array();
foreach ($requests as $pull) {
$field_list = PhabricatorCustomField::getObjectFields(
$pull,
PhabricatorCustomField::ROLE_VIEW);
$field_list
->setViewer($viewer)
->readFieldsFromStorage($pull);
foreach ($field_list->getFields() as $field) {
if ($field->shouldMarkup()) {
$field->setMarkupEngine($engine);
}
}
$list[] = id(new ReleephRequestView())
->setUser($viewer)
->setCustomFields($field_list)
->setPullRequest($pull)
->setIsListView(true);
}
// This is quite sketchy, but the list has not actually rendered yet, so
// this still allows us to batch the markup rendering.
$engine->process();
return $list;
}
public function buildSideNavView($for_app = false) {
$user = $this->getRequest()->getUser();
$nav = new AphrontSideNavFilterView();
$nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
$this->getSearchEngine()->addNavigationItems($nav->getMenu());
$nav->selectFilter(null);
return $nav;
}
private function getSearchEngine() {
$branch = $this->getBranch();
return id(new ReleephRequestSearchEngine())
->setBranch($branch)
->setBaseURI($this->getApplicationURI('branch/'.$branch->getID().'/'))
->setViewer($this->getRequest()->getUser());
}
protected function buildApplicationCrumbs() {
$crumbs = parent::buildApplicationCrumbs();
$branch = $this->getBranch();
if ($branch) {
$pull_uri = $this->getApplicationURI('branch/pull/'.$branch->getID().'/');
$crumbs->addAction(
id(new PHUIListItemView())
->setHref($pull_uri)
->setName(pht('New Pull Request'))
->setIcon('fa-plus-square')
->setDisabled(!$branch->isActive()));
}
return $crumbs;
}
private function renderPreface() {
$viewer = $this->getRequest()->getUser();
$branch = $this->getBranch();
$id = $branch->getID();
$header = id(new PHUIHeaderView())
->setHeader($branch->getDisplayName())
->setUser($viewer)
->setPolicyObject($branch);
if ($branch->getIsActive()) {
$header->setStatus('fa-check', 'bluegrey', pht('Active'));
} else {
$header->setStatus('fa-ban', 'dark', pht('Closed'));
}
$actions = id(new PhabricatorActionListView())
->setUser($viewer)
->setObject($branch)
->setObjectURI($this->getRequest()->getRequestURI());
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$branch,
PhabricatorPolicyCapability::CAN_EDIT);
$edit_uri = $this->getApplicationURI("branch/edit/{$id}/");
$close_uri = $this->getApplicationURI("branch/close/{$id}/");
$reopen_uri = $this->getApplicationURI("branch/re-open/{$id}/");
$history_uri = $this->getApplicationURI("branch/{$id}/history/");
$actions->addAction(
id(new PhabricatorActionView())
->setName(pht('Edit Branch'))
->setHref($edit_uri)
->setIcon('fa-pencil')
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit));
if ($branch->getIsActive()) {
$actions->addAction(
id(new PhabricatorActionView())
->setName(pht('Close Branch'))
->setHref($close_uri)
->setIcon('fa-times')
->setDisabled(!$can_edit)
->setWorkflow(true));
} else {
$actions->addAction(
id(new PhabricatorActionView())
->setName(pht('Reopen Branch'))
->setHref($reopen_uri)
->setIcon('fa-plus')
->setUser($viewer)
->setDisabled(!$can_edit)
->setWorkflow(true));
}
$actions->addAction(
id(new PhabricatorActionView())
->setName(pht('View History'))
->setHref($history_uri)
->setIcon('fa-list'));
$properties = id(new PHUIPropertyListView())
->setUser($viewer)
->setObject($branch)
->setActionList($actions);
$properties->addProperty(
pht('Branch'),
$branch->getName());
return id(new PHUIObjectBoxView())
->setHeader($header)
->addPropertyList($properties);
}
}