[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class ReleephRequestView extends AphrontView { 4 5 private $pullRequest; 6 private $customFields; 7 private $isListView; 8 9 public function setIsListView($is_list_view) { 10 $this->isListView = $is_list_view; 11 return $this; 12 } 13 14 public function getIsListView() { 15 return $this->isListView; 16 } 17 18 public function setCustomFields(PhabricatorCustomFieldList $custom_fields) { 19 $this->customFields = $custom_fields; 20 return $this; 21 } 22 23 public function getCustomFields() { 24 return $this->customFields; 25 } 26 27 public function setPullRequest(ReleephRequest $pull_request) { 28 $this->pullRequest = $pull_request; 29 return $this; 30 } 31 32 public function getPullRequest() { 33 return $this->pullRequest; 34 } 35 36 public function render() { 37 $viewer = $this->getUser(); 38 39 $field_list = $this->getCustomFields(); 40 $pull = $this->getPullRequest(); 41 42 $header = $this->buildHeader($pull); 43 44 $action_list = $this->buildActionList($pull); 45 46 $property_list = id(new PHUIPropertyListView()) 47 ->setUser($viewer) 48 ->setActionList($action_list); 49 50 $field_list->appendFieldsToPropertyList( 51 $pull, 52 $viewer, 53 $property_list); 54 55 $warnings = $this->getWarnings($pull); 56 57 if ($this->getIsListView()) { 58 Javelin::initBehavior('releeph-request-state-change'); 59 } 60 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); 67 } 68 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(), 76 ), 77 $header_text); 78 } 79 80 $header = id(new PHUIHeaderView()) 81 ->setHeader($header_text) 82 ->setUser($this->getUser()) 83 ->setPolicyObject($pull); 84 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; 115 } 116 $text = ReleephRequestStatus::getStatusDescriptionFor($pull->getStatus()); 117 $header->setStatus($icon, $color, $text); 118 119 if ($this->getIsListView()) { 120 $header->setObjectName($pull->getMonogram()); 121 } 122 123 return $header; 124 } 125 126 private function buildActionList(ReleephRequest $pull) { 127 $viewer = $this->getUser(); 128 $id = $pull->getID(); 129 130 $edit_uri = '/releeph/request/edit/'.$id.'/'; 131 132 $view = id(new PhabricatorActionListView()) 133 ->setUser($viewer); 134 135 $product = $pull->getBranch()->getProduct(); 136 $viewer_is_pusher = $product->isAuthoritativePHID($viewer->getPHID()); 137 $viewer_is_requestor = ($pull->getRequestUserPHID() == $viewer->getPHID()); 138 139 if ($viewer_is_pusher) { 140 $yes_text = pht('Approve Pull'); 141 $no_text = pht('Reject Pull'); 142 $yes_icon = 'fa-check'; 143 $no_icon = 'fa-times'; 144 } else if ($viewer_is_requestor) { 145 $yes_text = pht('Request Pull'); 146 $no_text = pht('Cancel Pull'); 147 $yes_icon = 'fa-check'; 148 $no_icon = 'fa-times'; 149 } else { 150 $yes_text = pht('Support Pull'); 151 $no_text = pht('Discourage Pull'); 152 $yes_icon = 'fa-thumbs-o-up'; 153 $no_icon = 'fa-thumbs-o-down'; 154 } 155 156 $yes_href = '/releeph/request/action/want/'.$id.'/'; 157 $no_href = '/releeph/request/action/pass/'.$id.'/'; 158 159 $intents = $pull->getUserIntents(); 160 $current_intent = idx($intents, $viewer->getPHID()); 161 162 $yes_disabled = ($current_intent == ReleephRequest::INTENT_WANT); 163 $no_disabled = ($current_intent == ReleephRequest::INTENT_PASS); 164 165 $use_workflow = (!$this->getIsListView()); 166 167 $view->addAction( 168 id(new PhabricatorActionView()) 169 ->setName($yes_text) 170 ->setHref($yes_href) 171 ->setWorkflow($use_workflow) 172 ->setRenderAsForm($use_workflow) 173 ->setDisabled($yes_disabled) 174 ->addSigil('releeph-request-state-change') 175 ->addSigil('want') 176 ->setIcon($yes_icon)); 177 178 $view->addAction( 179 id(new PhabricatorActionView()) 180 ->setName($no_text) 181 ->setHref($no_href) 182 ->setWorkflow($use_workflow) 183 ->setRenderAsForm($use_workflow) 184 ->setDisabled($no_disabled) 185 ->addSigil('releeph-request-state-change') 186 ->addSigil('pass') 187 ->setIcon($no_icon)); 188 189 190 if ($viewer_is_pusher || $viewer_is_requestor) { 191 192 $pulled_href = '/releeph/request/action/mark-manually-picked/'.$id.'/'; 193 $revert_href = '/releeph/request/action/mark-manually-reverted/'.$id.'/'; 194 195 if ($pull->getInBranch()) { 196 $view->addAction( 197 id(new PhabricatorActionView()) 198 ->setName(pht('Mark as Reverted')) 199 ->setHref($revert_href) 200 ->setWorkflow($use_workflow) 201 ->setRenderAsForm($use_workflow) 202 ->addSigil('releeph-request-state-change') 203 ->addSigil('mark-manually-reverted') 204 ->setIcon($no_icon)); 205 } else { 206 $view->addAction( 207 id(new PhabricatorActionView()) 208 ->setName(pht('Mark as Pulled')) 209 ->setHref($pulled_href) 210 ->setWorkflow($use_workflow) 211 ->setRenderAsForm($use_workflow) 212 ->addSigil('releeph-request-state-change') 213 ->addSigil('mark-manually-picked') 214 ->setIcon('fa-exclamation-triangle')); 215 } 216 } 217 218 219 if (!$this->getIsListView()) { 220 $view->addAction( 221 id(new PhabricatorActionView()) 222 ->setName(pht('Edit Pull Request')) 223 ->setIcon('fa-pencil') 224 ->setHref($edit_uri)); 225 } 226 227 return $view; 228 } 229 230 private function getWarnings(ReleephRequest $pull) { 231 $warnings = array(); 232 233 switch ($pull->getStatus()) { 234 case ReleephRequestStatus::STATUS_NEEDS_PICK: 235 if ($pull->getPickStatus() == ReleephRequest::PICK_FAILED) { 236 $warnings[] = pht('Last pull failed!'); 237 } 238 break; 239 case ReleephRequestStatus::STATUS_NEEDS_REVERT: 240 if ($pull->getPickStatus() == ReleephRequest::REVERT_FAILED) { 241 $warnings[] = pht('Last revert failed!'); 242 } 243 break; 244 } 245 246 return $warnings; 247 } 248 249 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |