[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class ReleephProductViewController extends ReleephProductController 4 implements PhabricatorApplicationSearchResultsControllerInterface { 5 6 private $productID; 7 private $queryKey; 8 9 public function shouldAllowPublic() { 10 return true; 11 } 12 13 public function willProcessRequest(array $data) { 14 $this->productID = idx($data, 'projectID'); 15 $this->queryKey = idx($data, 'queryKey'); 16 } 17 18 public function processRequest() { 19 $request = $this->getRequest(); 20 $viewer = $request->getUser(); 21 22 $product = id(new ReleephProductQuery()) 23 ->setViewer($viewer) 24 ->withIDs(array($this->productID)) 25 ->executeOne(); 26 if (!$product) { 27 return new Aphront404Response(); 28 } 29 $this->setProduct($product); 30 31 $controller = id(new PhabricatorApplicationSearchController()) 32 ->setQueryKey($this->queryKey) 33 ->setPreface($this->renderPreface()) 34 ->setSearchEngine( 35 id(new ReleephBranchSearchEngine()) 36 ->setProduct($product)) 37 ->setNavigation($this->buildSideNavView()); 38 39 return $this->delegateToController($controller); 40 } 41 42 public function renderResultsList( 43 array $branches, 44 PhabricatorSavedQuery $saved) { 45 assert_instances_of($branches, 'ReleephBranch'); 46 47 $viewer = $this->getRequest()->getUser(); 48 49 $products = mpull($branches, 'getProduct'); 50 $repo_phids = mpull($products, 'getRepositoryPHID'); 51 52 $repos = id(new PhabricatorRepositoryQuery()) 53 ->setViewer($viewer) 54 ->withPHIDs($repo_phids) 55 ->execute(); 56 $repos = mpull($repos, null, 'getPHID'); 57 58 $phids = mpull($branches, 'getCreatedByUserPHID'); 59 $this->loadHandles($phids); 60 61 $requests = array(); 62 if ($branches) { 63 $requests = id(new ReleephRequestQuery()) 64 ->setViewer($viewer) 65 ->withBranchIDs(mpull($branches, 'getID')) 66 ->withStatus(ReleephRequestQuery::STATUS_OPEN) 67 ->execute(); 68 $requests = mgroup($requests, 'getBranchID'); 69 } 70 71 $list = id(new PHUIObjectItemListView()) 72 ->setUser($viewer); 73 foreach ($branches as $branch) { 74 $diffusion_href = null; 75 $repo = idx($repos, $branch->getProduct()->getRepositoryPHID()); 76 if ($repo) { 77 $drequest = DiffusionRequest::newFromDictionary( 78 array( 79 'user' => $viewer, 80 'repository' => $repo, 81 )); 82 83 $diffusion_href = $drequest->generateURI( 84 array( 85 'action' => 'branch', 86 'branch' => $branch->getName(), 87 )); 88 } 89 90 $branch_link = $branch->getName(); 91 if ($diffusion_href) { 92 $branch_link = phutil_tag( 93 'a', 94 array( 95 'href' => $diffusion_href, 96 ), 97 $branch_link); 98 } 99 100 $item = id(new PHUIObjectItemView()) 101 ->setHeader($branch->getDisplayName()) 102 ->setHref($this->getApplicationURI('branch/'.$branch->getID().'/')) 103 ->addAttribute($branch_link); 104 105 if (!$branch->getIsActive()) { 106 $item->setDisabled(true); 107 } 108 109 $commit = $branch->getCutPointCommit(); 110 if ($commit) { 111 $item->addIcon( 112 'none', 113 phabricator_datetime($commit->getEpoch(), $viewer)); 114 } 115 116 $open_count = count(idx($requests, $branch->getID(), array())); 117 if ($open_count) { 118 $item->setBarColor('orange'); 119 $item->addIcon( 120 'fa-code-fork', 121 pht('%d Open Pull Request(s)', new PhutilNumber($open_count))); 122 } 123 124 $list->addItem($item); 125 } 126 127 return $list; 128 } 129 130 public function buildSideNavView($for_app = false) { 131 $viewer = $this->getRequest()->getUser(); 132 $product = $this->getProduct(); 133 134 $nav = new AphrontSideNavFilterView(); 135 $nav->setBaseURI(new PhutilURI($this->getApplicationURI())); 136 137 if ($for_app) { 138 $nav->addFilter('product/create/', pht('Create Product')); 139 } 140 141 id(new ReleephBranchSearchEngine()) 142 ->setProduct($product) 143 ->setViewer($viewer) 144 ->addNavigationItems($nav->getMenu()); 145 146 $nav->selectFilter(null); 147 148 return $nav; 149 } 150 151 public function buildApplicationCrumbs() { 152 $crumbs = parent::buildApplicationCrumbs(); 153 154 $product = $this->getProduct(); 155 if ($product) { 156 $crumbs->addAction( 157 id(new PHUIListItemView()) 158 ->setHref($product->getURI('cutbranch/')) 159 ->setName(pht('Cut New Branch')) 160 ->setIcon('fa-plus')); 161 } 162 163 return $crumbs; 164 } 165 166 private function renderPreface() { 167 $viewer = $this->getRequest()->getUser(); 168 $product = $this->getProduct(); 169 170 $id = $product->getID(); 171 172 $header = id(new PHUIHeaderView()) 173 ->setHeader($product->getName()) 174 ->setUser($viewer) 175 ->setPolicyObject($product); 176 177 if ($product->getIsActive()) { 178 $header->setStatus('fa-check', 'bluegrey', pht('Active')); 179 } else { 180 $header->setStatus('fa-ban', 'dark', pht('Inactive')); 181 } 182 183 $actions = id(new PhabricatorActionListView()) 184 ->setUser($viewer) 185 ->setObject($product) 186 ->setObjectURI($this->getRequest()->getRequestURI()); 187 188 $can_edit = PhabricatorPolicyFilter::hasCapability( 189 $viewer, 190 $product, 191 PhabricatorPolicyCapability::CAN_EDIT); 192 193 $edit_uri = $this->getApplicationURI("product/{$id}/edit/"); 194 $history_uri = $this->getApplicationURI("product/{$id}/history/"); 195 196 $actions->addAction( 197 id(new PhabricatorActionView()) 198 ->setName(pht('Edit Product')) 199 ->setHref($edit_uri) 200 ->setIcon('fa-pencil') 201 ->setDisabled(!$can_edit) 202 ->setWorkflow(!$can_edit)); 203 204 if ($product->getIsActive()) { 205 $status_name = pht('Deactivate Product'); 206 $status_href = "product/{$id}/action/deactivate/"; 207 $status_icon = 'fa-times'; 208 } else { 209 $status_name = pht('Reactivate Product'); 210 $status_href = "product/{$id}/action/activate/"; 211 $status_icon = 'fa-plus-circle-o'; 212 } 213 214 $actions->addAction( 215 id(new PhabricatorActionView()) 216 ->setName($status_name) 217 ->setHref($this->getApplicationURI($status_href)) 218 ->setIcon($status_icon) 219 ->setDisabled(!$can_edit) 220 ->setWorkflow(true)); 221 222 $actions->addAction( 223 id(new PhabricatorActionView()) 224 ->setName(pht('View History')) 225 ->setHref($history_uri) 226 ->setIcon('fa-list')); 227 228 $properties = id(new PHUIPropertyListView()) 229 ->setUser($viewer) 230 ->setObject($product); 231 232 $properties->addProperty( 233 pht('Repository'), 234 $product->getRepository()->getName()); 235 236 $properties->setActionList($actions); 237 238 $pushers = $product->getPushers(); 239 if ($pushers) { 240 $this->loadHandles($pushers); 241 $properties->addProperty( 242 pht('Pushers'), 243 $this->renderHandlesForPHIDs($pushers)); 244 } 245 246 return id(new PHUIObjectBoxView()) 247 ->setHeader($header) 248 ->addPropertyList($properties); 249 } 250 251 }
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 |