Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / releeph / view / ReleephRequestView.php
blobef00c5d63d935b82580c11d4e59fcca45e417446
1 <?php
3 final class ReleephRequestView extends AphrontView {
5 private $pullRequest;
6 private $customFields;
7 private $isListView;
9 public function setIsListView($is_list_view) {
10 $this->isListView = $is_list_view;
11 return $this;
14 public function getIsListView() {
15 return $this->isListView;
18 public function setCustomFields(PhabricatorCustomFieldList $custom_fields) {
19 $this->customFields = $custom_fields;
20 return $this;
23 public function getCustomFields() {
24 return $this->customFields;
27 public function setPullRequest(ReleephRequest $pull_request) {
28 $this->pullRequest = $pull_request;
29 return $this;
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())
47 ->setUser($viewer)
48 ->setActionList($action_list);
50 $field_list->appendFieldsToPropertyList(
51 $pull,
52 $viewer,
53 $property_list);
55 $warnings = $this->getWarnings($pull);
57 if ($this->getIsListView()) {
58 Javelin::initBehavior('releeph-request-state-change');
61 return id(new PHUIObjectBoxView())
62 ->setHeader($header)
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(
73 'a',
74 array(
75 'href' => '/'.$pull->getMonogram(),
77 $header_text);
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:
87 $icon = 'open';
88 $color = null;
89 break;
90 case ReleephRequestStatus::STATUS_REJECTED:
91 $icon = 'reject';
92 $color = 'red';
93 break;
94 case ReleephRequestStatus::STATUS_PICKED:
95 $icon = 'accept';
96 $color = 'green';
97 break;
98 case ReleephRequestStatus::STATUS_REVERTED:
99 case ReleephRequestStatus::STATUS_ABANDONED:
100 $icon = 'reject';
101 $color = 'dark';
102 break;
103 case ReleephRequestStatus::STATUS_NEEDS_PICK:
104 $icon = 'warning';
105 $color = 'green';
106 break;
107 case ReleephRequestStatus::STATUS_NEEDS_REVERT:
108 $icon = 'warning';
109 $color = 'red';
110 break;
111 default:
112 $icon = 'question';
113 $color = null;
114 break;
116 $text = ReleephRequestStatus::getStatusDescriptionFor($pull->getStatus());
117 $header->setStatus($icon, $color, $text);
119 return $header;
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())
129 ->setUser($viewer);
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';
145 } else {
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());
163 $view->addAction(
164 id(new PhabricatorActionView())
165 ->setName($yes_text)
166 ->setHref($yes_href)
167 ->setWorkflow($use_workflow)
168 ->setRenderAsForm($use_workflow)
169 ->setDisabled($yes_disabled)
170 ->addSigil('releeph-request-state-change')
171 ->addSigil('want')
172 ->setIcon($yes_icon));
174 $view->addAction(
175 id(new PhabricatorActionView())
176 ->setName($no_text)
177 ->setHref($no_href)
178 ->setWorkflow($use_workflow)
179 ->setRenderAsForm($use_workflow)
180 ->setDisabled($no_disabled)
181 ->addSigil('releeph-request-state-change')
182 ->addSigil('pass')
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()) {
192 $view->addAction(
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));
201 } else {
202 $view->addAction(
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()) {
216 $view->addAction(
217 id(new PhabricatorActionView())
218 ->setName(pht('Edit Pull Request'))
219 ->setIcon('fa-pencil')
220 ->setHref($edit_uri));
223 return $view;
226 private function getWarnings(ReleephRequest $pull) {
227 $warnings = array();
229 switch ($pull->getStatus()) {
230 case ReleephRequestStatus::STATUS_NEEDS_PICK:
231 if ($pull->getPickStatus() == ReleephRequest::PICK_FAILED) {
232 $warnings[] = pht('Last pull failed!');
234 break;
235 case ReleephRequestStatus::STATUS_NEEDS_REVERT:
236 if ($pull->getPickStatus() == ReleephRequest::REVERT_FAILED) {
237 $warnings[] = pht('Last revert failed!');
239 break;
242 return $warnings;