3 final class ReleephRequestView
extends AphrontView
{
9 public function setIsListView($is_list_view) {
10 $this->isListView
= $is_list_view;
14 public function getIsListView() {
15 return $this->isListView
;
18 public function setCustomFields(PhabricatorCustomFieldList
$custom_fields) {
19 $this->customFields
= $custom_fields;
23 public function getCustomFields() {
24 return $this->customFields
;
27 public function setPullRequest(ReleephRequest
$pull_request) {
28 $this->pullRequest
= $pull_request;
32 public function getPullRequest() {
33 return $this->pullRequest
;
36 public function render() {
37 $viewer = $this->getUser();
39 $field_list = $this->getCustomFields();
40 $pull = $this->getPullRequest();
42 $header = $this->buildHeader($pull);
44 $action_list = $this->buildActionList($pull);
46 $property_list = id(new PHUIPropertyListView())
48 ->setActionList($action_list);
50 $field_list->appendFieldsToPropertyList(
55 $warnings = $this->getWarnings($pull);
57 if ($this->getIsListView()) {
58 Javelin
::initBehavior('releeph-request-state-change');
61 return id(new PHUIObjectBoxView())
63 ->setFormErrors($warnings)
64 ->addSigil('releeph-request-box')
65 ->setMetadata(array('uri' => '/'.$pull->getMonogram()))
66 ->appendChild($property_list);
69 private function buildHeader(ReleephRequest
$pull) {
70 $header_text = $pull->getSummaryForDisplay();
71 if ($this->getIsListView()) {
72 $header_text = phutil_tag(
75 'href' => '/'.$pull->getMonogram(),
80 $header = id(new PHUIHeaderView())
81 ->setHeader($header_text)
82 ->setUser($this->getUser())
83 ->setPolicyObject($pull);
85 switch ($pull->getStatus()) {
86 case ReleephRequestStatus
::STATUS_REQUESTED
:
90 case ReleephRequestStatus
::STATUS_REJECTED
:
94 case ReleephRequestStatus
::STATUS_PICKED
:
98 case ReleephRequestStatus
::STATUS_REVERTED
:
99 case ReleephRequestStatus
::STATUS_ABANDONED
:
103 case ReleephRequestStatus
::STATUS_NEEDS_PICK
:
107 case ReleephRequestStatus
::STATUS_NEEDS_REVERT
:
116 $text = ReleephRequestStatus
::getStatusDescriptionFor($pull->getStatus());
117 $header->setStatus($icon, $color, $text);
122 private function buildActionList(ReleephRequest
$pull) {
123 $viewer = $this->getUser();
124 $id = $pull->getID();
126 $edit_uri = '/releeph/request/edit/'.$id.'/';
128 $view = id(new PhabricatorActionListView())
131 $product = $pull->getBranch()->getProduct();
132 $viewer_is_pusher = $product->isAuthoritativePHID($viewer->getPHID());
133 $viewer_is_requestor = ($pull->getRequestUserPHID() == $viewer->getPHID());
135 if ($viewer_is_pusher) {
136 $yes_text = pht('Approve Pull');
137 $no_text = pht('Reject Pull');
138 $yes_icon = 'fa-check';
139 $no_icon = 'fa-times';
140 } else if ($viewer_is_requestor) {
141 $yes_text = pht('Request Pull');
142 $no_text = pht('Cancel Pull');
143 $yes_icon = 'fa-check';
144 $no_icon = 'fa-times';
146 $yes_text = pht('Support Pull');
147 $no_text = pht('Discourage Pull');
148 $yes_icon = 'fa-thumbs-o-up';
149 $no_icon = 'fa-thumbs-o-down';
152 $yes_href = '/releeph/request/action/want/'.$id.'/';
153 $no_href = '/releeph/request/action/pass/'.$id.'/';
155 $intents = $pull->getUserIntents();
156 $current_intent = idx($intents, $viewer->getPHID());
158 $yes_disabled = ($current_intent == ReleephRequest
::INTENT_WANT
);
159 $no_disabled = ($current_intent == ReleephRequest
::INTENT_PASS
);
161 $use_workflow = (!$this->getIsListView());
164 id(new PhabricatorActionView())
167 ->setWorkflow($use_workflow)
168 ->setRenderAsForm($use_workflow)
169 ->setDisabled($yes_disabled)
170 ->addSigil('releeph-request-state-change')
172 ->setIcon($yes_icon));
175 id(new PhabricatorActionView())
178 ->setWorkflow($use_workflow)
179 ->setRenderAsForm($use_workflow)
180 ->setDisabled($no_disabled)
181 ->addSigil('releeph-request-state-change')
183 ->setIcon($no_icon));
186 if ($viewer_is_pusher ||
$viewer_is_requestor) {
188 $pulled_href = '/releeph/request/action/mark-manually-picked/'.$id.'/';
189 $revert_href = '/releeph/request/action/mark-manually-reverted/'.$id.'/';
191 if ($pull->getInBranch()) {
193 id(new PhabricatorActionView())
194 ->setName(pht('Mark as Reverted'))
195 ->setHref($revert_href)
196 ->setWorkflow($use_workflow)
197 ->setRenderAsForm($use_workflow)
198 ->addSigil('releeph-request-state-change')
199 ->addSigil('mark-manually-reverted')
200 ->setIcon($no_icon));
203 id(new PhabricatorActionView())
204 ->setName(pht('Mark as Pulled'))
205 ->setHref($pulled_href)
206 ->setWorkflow($use_workflow)
207 ->setRenderAsForm($use_workflow)
208 ->addSigil('releeph-request-state-change')
209 ->addSigil('mark-manually-picked')
210 ->setIcon('fa-exclamation-triangle'));
215 if (!$this->getIsListView()) {
217 id(new PhabricatorActionView())
218 ->setName(pht('Edit Pull Request'))
219 ->setIcon('fa-pencil')
220 ->setHref($edit_uri));
226 private function getWarnings(ReleephRequest
$pull) {
229 switch ($pull->getStatus()) {
230 case ReleephRequestStatus
::STATUS_NEEDS_PICK
:
231 if ($pull->getPickStatus() == ReleephRequest
::PICK_FAILED
) {
232 $warnings[] = pht('Last pull failed!');
235 case ReleephRequestStatus
::STATUS_NEEDS_REVERT
:
236 if ($pull->getPickStatus() == ReleephRequest
::REVERT_FAILED
) {
237 $warnings[] = pht('Last revert failed!');