@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Use ApplicationSearch in Owners

Summary:
Ref T8320. Modernize search and major interfaces.

This slightly regresses some list view and search features; I'll probably restore some later (once the Query has proper `needX(...)` methods) and drop the rest.

Test Plan: Browsed, edited, deleted, and created packages.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T8320

Differential Revision: https://secure.phabricator.com/D13024

+244 -452
+2
src/__phutil_library_map__.php
··· 2178 2178 'PhabricatorOwnersPackagePHIDType' => 'applications/owners/phid/PhabricatorOwnersPackagePHIDType.php', 2179 2179 'PhabricatorOwnersPackagePathValidator' => 'applications/repository/worker/commitchangeparser/PhabricatorOwnersPackagePathValidator.php', 2180 2180 'PhabricatorOwnersPackageQuery' => 'applications/owners/query/PhabricatorOwnersPackageQuery.php', 2181 + 'PhabricatorOwnersPackageSearchEngine' => 'applications/owners/query/PhabricatorOwnersPackageSearchEngine.php', 2181 2182 'PhabricatorOwnersPackageTestCase' => 'applications/owners/storage/__tests__/PhabricatorOwnersPackageTestCase.php', 2182 2183 'PhabricatorOwnersPath' => 'applications/owners/storage/PhabricatorOwnersPath.php', 2183 2184 'PhabricatorPHDConfigOptions' => 'applications/config/option/PhabricatorPHDConfigOptions.php', ··· 5584 5585 'PhabricatorOwnersPackageEditor' => 'PhabricatorEditor', 5585 5586 'PhabricatorOwnersPackagePHIDType' => 'PhabricatorPHIDType', 5586 5587 'PhabricatorOwnersPackageQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 5588 + 'PhabricatorOwnersPackageSearchEngine' => 'PhabricatorApplicationSearchEngine', 5587 5589 'PhabricatorOwnersPackageTestCase' => 'PhabricatorTestCase', 5588 5590 'PhabricatorOwnersPath' => 'PhabricatorOwnersDAO', 5589 5591 'PhabricatorPHDConfigOptions' => 'PhabricatorApplicationConfigOptions',
+1 -2
src/applications/owners/application/PhabricatorOwnersApplication.php
··· 42 42 public function getRoutes() { 43 43 return array( 44 44 '/owners/' => array( 45 - '' => 'PhabricatorOwnersListController', 46 - 'view/(?P<view>[^/]+)/' => 'PhabricatorOwnersListController', 45 + '(?:query/(?P<queryKey>[^/]+)/)?' => 'PhabricatorOwnersListController', 47 46 'edit/(?P<id>[1-9]\d*)/' => 'PhabricatorOwnersEditController', 48 47 'new/' => 'PhabricatorOwnersEditController', 49 48 'package/(?P<id>[1-9]\d*)/' => 'PhabricatorOwnersDetailController',
+1 -68
src/applications/owners/controller/PhabricatorOwnersController.php
··· 1 1 <?php 2 2 3 - abstract class PhabricatorOwnersController extends PhabricatorController { 4 - 5 - private $filter; 6 - 7 - private function getSideNavFilter() { 8 - return $this->filter; 9 - } 10 - protected function setSideNavFilter($filter) { 11 - $this->filter = $filter; 12 - return $this; 13 - } 14 - 15 - public function buildSideNavView() { 16 - $nav = new AphrontSideNavFilterView(); 17 - $base_uri = new PhutilURI('/owners/'); 18 - $nav->setBaseURI($base_uri); 19 - 20 - $nav->addLabel(pht('Packages')); 21 - $this->getExtraPackageViews($nav); 22 - $nav->addFilter('view/owned', pht('Owned')); 23 - $nav->addFilter('view/projects', pht('Projects')); 24 - $nav->addFilter('view/all', pht('All')); 25 - 26 - $nav->selectFilter($this->getSideNavFilter(), 'view/owned'); 27 - 28 - $filter = $nav->getSelectedFilter(); 29 - switch ($filter) { 30 - case 'view/owned': 31 - $title = pht('Owned Packages'); 32 - break; 33 - case 'view/all': 34 - $title = pht('All Packages'); 35 - break; 36 - case 'view/projects': 37 - $title = pht('Projects'); 38 - break; 39 - case 'new': 40 - $title = pht('New Package'); 41 - break; 42 - default: 43 - $title = pht('Package'); 44 - break; 45 - } 46 - 47 - return $nav; 48 - } 49 - 50 - protected function buildApplicationCrumbs() { 51 - $crumbs = parent::buildApplicationCrumbs(); 52 - 53 - $crumbs->addAction( 54 - id(new PHUIListItemView()) 55 - ->setName(pht('Create Package')) 56 - ->setHref('/owners/new/') 57 - ->setIcon('fa-plus-square')); 58 - 59 - return $crumbs; 60 - } 61 - 62 - public function buildApplicationMenu() { 63 - return $this->buildSideNavView()->getMenu(); 64 - } 65 - 66 - protected function getExtraPackageViews(AphrontSideNavFilterView $view) { 67 - return; 68 - } 69 - 70 - } 3 + abstract class PhabricatorOwnersController extends PhabricatorController {}
+16 -27
src/applications/owners/controller/PhabricatorOwnersDetailController.php
··· 3 3 final class PhabricatorOwnersDetailController 4 4 extends PhabricatorOwnersController { 5 5 6 - private $id; 7 - private $package; 8 - 9 - public function willProcessRequest(array $data) { 10 - $this->id = $data['id']; 6 + public function shouldAllowPublic() { 7 + return true; 11 8 } 12 9 13 - public function processRequest() { 14 - $request = $this->getRequest(); 15 - $user = $request->getUser(); 10 + public function handleRequest(AphrontRequest $request) { 11 + $viewer = $this->getViewer(); 16 12 17 - $package = id(new PhabricatorOwnersPackage())->load($this->id); 13 + $package = id(new PhabricatorOwnersPackageQuery()) 14 + ->setViewer($viewer) 15 + ->withIDs(array($request->getURIData('id'))) 16 + ->executeOne(); 18 17 if (!$package) { 19 18 return new Aphront404Response(); 20 19 } 21 - $this->package = $package; 22 20 23 21 $paths = $package->loadPaths(); 24 22 $owners = $package->loadOwners(); ··· 30 28 31 29 if ($repository_phids) { 32 30 $repositories = id(new PhabricatorRepositoryQuery()) 33 - ->setViewer($user) 31 + ->setViewer($viewer) 34 32 ->withPHIDs(array_keys($repository_phids)) 35 33 ->execute(); 36 34 $repositories = mpull($repositories, null, 'getPHID'); ··· 131 129 $panel->setHeader($header); 132 130 $panel->appendChild($table); 133 131 134 - $key = 'package/'.$package->getID(); 135 - $this->setSideNavFilter($key); 136 - 137 132 $commit_views = array(); 138 133 139 134 $commit_uri = id(new PhutilURI('/audit/')) ··· 151 146 ->execute(); 152 147 if ($attention_commits) { 153 148 $view = id(new PhabricatorAuditListView()) 154 - ->setUser($user) 149 + ->setUser($viewer) 155 150 ->setCommits($attention_commits); 156 151 157 152 $commit_views[] = array( ··· 172 167 ->execute(); 173 168 174 169 $view = id(new PhabricatorAuditListView()) 175 - ->setUser($user) 170 + ->setUser($viewer) 176 171 ->setCommits($all_commits) 177 172 ->setNoDataString(pht('No commits in this package.')); 178 173 ··· 210 205 $crumbs = $this->buildApplicationCrumbs(); 211 206 $crumbs->addTextCrumb($package->getName()); 212 207 213 - $nav = $this->buildSideNavView(); 214 - $nav->appendChild($crumbs); 215 - $nav->appendChild($panel); 216 - $nav->appendChild($commit_panels); 217 - 218 208 return $this->buildApplicationPage( 219 - $nav, 209 + array( 210 + $crumbs, 211 + $panel, 212 + $commit_panels, 213 + ), 220 214 array( 221 215 'title' => pht('Package %s', $package->getName()), 222 216 )); 223 - } 224 - 225 - protected function getExtraPackageViews(AphrontSideNavFilterView $view) { 226 - $package = $this->package; 227 - $view->addFilter('package/'.$package->getID(), pht('Details')); 228 217 } 229 218 230 219 }
+20 -30
src/applications/owners/controller/PhabricatorOwnersEditController.php
··· 3 3 final class PhabricatorOwnersEditController 4 4 extends PhabricatorOwnersController { 5 5 6 - private $id; 6 + public function handleRequest(AphrontRequest $request) { 7 + $viewer = $request->getUser(); 7 8 8 - public function willProcessRequest(array $data) { 9 - $this->id = idx($data, 'id'); 10 - } 11 - 12 - public function processRequest() { 13 - $request = $this->getRequest(); 14 - $user = $request->getUser(); 15 - 16 - if ($this->id) { 17 - $package = id(new PhabricatorOwnersPackage())->load($this->id); 9 + $id = $request->getURIData('id'); 10 + if ($id) { 11 + $package = id(new PhabricatorOwnersPackageQuery()) 12 + ->setViewer($viewer) 13 + ->withIDs(array($id)) 14 + ->requireCapabilities( 15 + array( 16 + PhabricatorPolicyCapability::CAN_VIEW, 17 + // TODO: Support this capability. 18 + // PhabricatorPolicyCapability::CAN_EDIT, 19 + )) 20 + ->executeOne(); 18 21 if (!$package) { 19 22 return new Aphront404Response(); 20 23 } 21 24 } else { 22 25 $package = new PhabricatorOwnersPackage(); 23 - $package->setPrimaryOwnerPHID($user->getPHID()); 26 + $package->setPrimaryOwnerPHID($viewer->getPHID()); 24 27 } 25 28 26 29 $e_name = true; ··· 89 92 $package->attachOldPrimaryOwnerPHID($old_primary); 90 93 try { 91 94 id(new PhabricatorOwnersPackageEditor()) 92 - ->setActor($user) 95 + ->setActor($viewer) 93 96 ->setPackage($package) 94 97 ->save(); 95 98 return id(new AphrontRedirectResponse()) ··· 123 126 124 127 if ($package->getID()) { 125 128 $title = pht('Edit Package'); 126 - $side_nav_filter = 'edit/'.$this->id; 127 129 } else { 128 130 $title = pht('New Package'); 129 - $side_nav_filter = 'new'; 130 131 } 131 - $this->setSideNavFilter($side_nav_filter); 132 132 133 133 $repos = id(new PhabricatorRepositoryQuery()) 134 - ->setViewer($user) 134 + ->setViewer($viewer) 135 135 ->execute(); 136 136 137 137 $default_paths = array(); ··· 171 171 : '/owners/'; 172 172 173 173 $form = id(new AphrontFormView()) 174 - ->setUser($user) 174 + ->setUser($viewer) 175 175 ->appendChild( 176 176 id(new AphrontFormTextControl()) 177 177 ->setLabel(pht('Name')) ··· 256 256 $crumbs->addTextCrumb(pht('New Package')); 257 257 } 258 258 259 - $nav = $this->buildSideNavView(); 260 - $nav->appendChild($crumbs); 261 - $nav->appendChild($form_box); 262 - 263 259 return $this->buildApplicationPage( 264 260 array( 265 - $nav, 261 + $crumbs, 262 + $form_box, 266 263 ), 267 264 array( 268 265 'title' => $title, 269 266 )); 270 267 } 271 268 272 - protected function getExtraPackageViews(AphrontSideNavFilterView $view) { 273 - if ($this->id) { 274 - $view->addFilter('edit/'.$this->id, pht('Edit')); 275 - } else { 276 - $view->addFilter('new', pht('New')); 277 - } 278 - } 279 269 }
+31 -320
src/applications/owners/controller/PhabricatorOwnersListController.php
··· 3 3 final class PhabricatorOwnersListController 4 4 extends PhabricatorOwnersController { 5 5 6 - protected $view; 7 - 8 - public function willProcessRequest(array $data) { 9 - $this->view = idx($data, 'view', 'owned'); 10 - $this->setSideNavFilter('view/'.$this->view); 6 + public function shouldAllowPublic() { 7 + return true; 11 8 } 12 9 13 - public function processRequest() { 14 - 15 - $request = $this->getRequest(); 16 - $user = $request->getUser(); 17 - 18 - $package = new PhabricatorOwnersPackage(); 19 - $owner = new PhabricatorOwnersOwner(); 20 - $path = new PhabricatorOwnersPath(); 21 - 22 - $repository_phid = ''; 23 - if ($request->getStr('repository') != '') { 24 - $repository_phid = id(new PhabricatorRepositoryQuery()) 25 - ->setViewer($user) 26 - ->withCallsigns(array($request->getStr('repository'))) 27 - ->executeOne() 28 - ->getPHID(); 29 - } 30 - 31 - switch ($this->view) { 32 - case 'search': 33 - $packages = array(); 34 - 35 - $conn_r = $package->establishConnection('r'); 36 - 37 - $where = array('1 = 1'); 38 - $join = array(); 39 - $having = ''; 40 - 41 - if ($request->getStr('name')) { 42 - $where[] = qsprintf( 43 - $conn_r, 44 - 'p.name LIKE %~', 45 - $request->getStr('name')); 46 - } 47 - 48 - if ($repository_phid || $request->getStr('path')) { 49 - 50 - $join[] = qsprintf( 51 - $conn_r, 52 - 'JOIN %T path ON path.packageID = p.id', 53 - $path->getTableName()); 54 - 55 - if ($repository_phid) { 56 - $where[] = qsprintf( 57 - $conn_r, 58 - 'path.repositoryPHID = %s', 59 - $repository_phid); 60 - } 61 - 62 - if ($request->getStr('path')) { 63 - $where[] = qsprintf( 64 - $conn_r, 65 - '(path.path LIKE %~ AND NOT path.excluded) OR 66 - %s LIKE CONCAT(REPLACE(path.path, %s, %s), %s)', 67 - $request->getStr('path'), 68 - $request->getStr('path'), 69 - '_', 70 - '\_', 71 - '%'); 72 - $having = 'HAVING MAX(path.excluded) = 0'; 73 - } 74 - 75 - } 76 - 77 - if ($request->getArr('owner')) { 78 - $join[] = qsprintf( 79 - $conn_r, 80 - 'JOIN %T o ON o.packageID = p.id', 81 - $owner->getTableName()); 82 - $where[] = qsprintf( 83 - $conn_r, 84 - 'o.userPHID IN (%Ls)', 85 - $request->getArr('owner')); 86 - } 87 - 88 - $data = queryfx_all( 89 - $conn_r, 90 - 'SELECT p.* FROM %T p %Q WHERE %Q GROUP BY p.id %Q', 91 - $package->getTableName(), 92 - implode(' ', $join), 93 - '('.implode(') AND (', $where).')', 94 - $having); 95 - $packages = $package->loadAllFromArray($data); 10 + public function handleRequest(AphrontRequest $request) { 11 + $controller = id(new PhabricatorApplicationSearchController()) 12 + ->setQueryKey($request->getURIData('queryKey')) 13 + ->setSearchEngine(new PhabricatorOwnersPackageSearchEngine()) 14 + ->setNavigation($this->buildSideNavView()); 96 15 97 - $header = pht('Search Results'); 98 - $nodata = pht('No packages match your query.'); 99 - break; 100 - case 'owned': 101 - $data = queryfx_all( 102 - $package->establishConnection('r'), 103 - 'SELECT p.* FROM %T p JOIN %T o ON p.id = o.packageID 104 - WHERE o.userPHID = %s GROUP BY p.id', 105 - $package->getTableName(), 106 - $owner->getTableName(), 107 - $user->getPHID()); 108 - $packages = $package->loadAllFromArray($data); 16 + return $this->delegateToController($controller); 17 + } 109 18 110 - $header = pht('Owned Packages'); 111 - $nodata = pht('No owned packages'); 112 - break; 113 - case 'projects': 114 - $projects = id(new PhabricatorProjectQuery()) 115 - ->setViewer($user) 116 - ->withMemberPHIDs(array($user->getPHID())) 117 - ->withStatus(PhabricatorProjectQuery::STATUS_ANY) 118 - ->execute(); 119 - $owner_phids = mpull($projects, 'getPHID'); 120 - if ($owner_phids) { 121 - $data = queryfx_all( 122 - $package->establishConnection('r'), 123 - 'SELECT p.* FROM %T p JOIN %T o ON p.id = o.packageID 124 - WHERE o.userPHID IN (%Ls) GROUP BY p.id', 125 - $package->getTableName(), 126 - $owner->getTableName(), 127 - $owner_phids); 128 - } else { 129 - $data = array(); 130 - } 131 - $packages = $package->loadAllFromArray($data); 19 + public function buildSideNavView($for_app = false) { 20 + $viewer = $this->getViewer(); 132 21 133 - $header = pht('Project Packages'); 134 - $nodata = pht('No owned packages'); 135 - break; 136 - case 'all': 137 - $packages = $package->loadAll(); 22 + $nav = new AphrontSideNavFilterView(); 23 + $nav->setBaseURI(new PhutilURI($this->getApplicationURI())); 138 24 139 - $header = pht('All Packages'); 140 - $nodata = pht('There are no defined packages.'); 141 - break; 25 + if ($for_app) { 26 + $nav->addFilter('new/', pht('Create Package')); 142 27 } 143 28 144 - $content = $this->renderPackageTable( 145 - $packages, 146 - $header, 147 - $nodata); 148 - 149 - $filter = new AphrontListFilterView(); 29 + id(new PhabricatorOwnersPackageSearchEngine()) 30 + ->setViewer($viewer) 31 + ->addNavigationItems($nav->getMenu()); 150 32 151 - $owner_phids = $request->getArr('owner'); 33 + $nav->selectFilter(null); 152 34 153 - $callsigns = array('' => pht('(Any Repository)')); 154 - $repositories = id(new PhabricatorRepositoryQuery()) 155 - ->setViewer($user) 156 - ->setOrder('callsign') 157 - ->execute(); 158 - foreach ($repositories as $repository) { 159 - $callsigns[$repository->getCallsign()] = 160 - $repository->getCallsign().': '.$repository->getName(); 161 - } 35 + return $nav; 36 + } 162 37 163 - $form = id(new AphrontFormView()) 164 - ->setUser($user) 165 - ->setAction('/owners/view/search/') 166 - ->setMethod('GET') 167 - ->appendChild( 168 - id(new AphrontFormTextControl()) 169 - ->setName('name') 170 - ->setLabel(pht('Name')) 171 - ->setValue($request->getStr('name'))) 172 - ->appendControl( 173 - id(new AphrontFormTokenizerControl()) 174 - ->setDatasource(new PhabricatorProjectOrUserDatasource()) 175 - ->setLimit(1) 176 - ->setName('owner') 177 - ->setLabel(pht('Owner')) 178 - ->setValue($owner_phids)) 179 - ->appendChild( 180 - id(new AphrontFormSelectControl()) 181 - ->setName('repository') 182 - ->setLabel(pht('Repository')) 183 - ->setOptions($callsigns) 184 - ->setValue($request->getStr('repository'))) 185 - ->appendChild( 186 - id(new AphrontFormTextControl()) 187 - ->setName('path') 188 - ->setLabel(pht('Path')) 189 - ->setValue($request->getStr('path'))) 190 - ->appendChild( 191 - id(new AphrontFormSubmitControl()) 192 - ->setValue(pht('Search for Packages'))); 193 - 194 - $filter->appendChild($form); 195 - $title = pht('Package Index'); 196 - 197 - $crumbs = $this->buildApplicationCrumbs(); 198 - $crumbs->addTextCrumb($header); 199 - $crumbs->setBorder(true); 200 - 201 - $nav = $this->buildSideNavView(); 202 - $nav->appendChild($crumbs); 203 - $nav->appendChild($filter); 204 - $nav->appendChild($content); 205 - 206 - return $this->buildApplicationPage( 207 - $nav, 208 - array( 209 - 'title' => pht('Package Index'), 210 - )); 38 + public function buildApplicationMenu() { 39 + return $this->buildSideNavView(true)->getMenu(); 211 40 } 212 41 213 - private function renderPackageTable(array $packages, $header, $nodata) { 214 - assert_instances_of($packages, 'PhabricatorOwnersPackage'); 215 - 216 - if ($packages) { 217 - $package_ids = mpull($packages, 'getID'); 218 - 219 - $owners = id(new PhabricatorOwnersOwner())->loadAllWhere( 220 - 'packageID IN (%Ld)', 221 - $package_ids); 222 - 223 - $paths = id(new PhabricatorOwnersPath())->loadAllWhere( 224 - 'packageID in (%Ld)', 225 - $package_ids); 226 - 227 - $phids = array(); 228 - foreach ($owners as $owner) { 229 - $phids[$owner->getUserPHID()] = true; 230 - } 231 - $phids = array_keys($phids); 232 - $handles = $this->loadViewerHandles($phids); 233 - 234 - $repository_phids = array(); 235 - foreach ($paths as $path) { 236 - $repository_phids[$path->getRepositoryPHID()] = true; 237 - } 42 + protected function buildApplicationCrumbs() { 43 + $crumbs = parent::buildApplicationCrumbs(); 238 44 239 - if ($repository_phids) { 240 - $repositories = id(new PhabricatorRepositoryQuery()) 241 - ->setViewer($this->getRequest()->getUser()) 242 - ->withPHIDs(array_keys($repository_phids)) 243 - ->execute(); 244 - } else { 245 - $repositories = array(); 246 - } 45 + $crumbs->addAction( 46 + id(new PHUIListItemView()) 47 + ->setName(pht('Create Package')) 48 + ->setHref($this->getApplicationURI('new/')) 49 + ->setIcon('fa-plus-square')); 247 50 248 - $repositories = mpull($repositories, null, 'getPHID'); 249 - $owners = mgroup($owners, 'getPackageID'); 250 - $paths = mgroup($paths, 'getPackageID'); 251 - } else { 252 - $handles = array(); 253 - $repositories = array(); 254 - $owners = array(); 255 - $paths = array(); 256 - } 257 - 258 - $rows = array(); 259 - foreach ($packages as $package) { 260 - 261 - $pkg_owners = idx($owners, $package->getID(), array()); 262 - foreach ($pkg_owners as $key => $owner) { 263 - $pkg_owners[$key] = $handles[$owner->getUserPHID()]->renderLink(); 264 - if ($owner->getUserPHID() == $package->getPrimaryOwnerPHID()) { 265 - $pkg_owners[$key] = phutil_tag('strong', array(), $pkg_owners[$key]); 266 - } 267 - } 268 - $pkg_owners = phutil_implode_html(phutil_tag('br'), $pkg_owners); 269 - 270 - $pkg_paths = idx($paths, $package->getID(), array()); 271 - foreach ($pkg_paths as $key => $path) { 272 - $repo = idx($repositories, $path->getRepositoryPHID()); 273 - if ($repo) { 274 - $href = DiffusionRequest::generateDiffusionURI( 275 - array( 276 - 'callsign' => $repo->getCallsign(), 277 - 'branch' => $repo->getDefaultBranch(), 278 - 'path' => $path->getPath(), 279 - 'action' => 'browse', 280 - )); 281 - $pkg_paths[$key] = hsprintf( 282 - '%s %s%s', 283 - ($path->getExcluded() ? "\xE2\x80\x93" : '+'), 284 - phutil_tag('strong', array(), $repo->getName()), 285 - phutil_tag( 286 - 'a', 287 - array( 288 - 'href' => (string)$href, 289 - ), 290 - $path->getPath())); 291 - } else { 292 - $pkg_paths[$key] = $path->getPath(); 293 - } 294 - } 295 - $pkg_paths = phutil_implode_html(phutil_tag('br'), $pkg_paths); 296 - 297 - $rows[] = array( 298 - phutil_tag( 299 - 'a', 300 - array( 301 - 'href' => '/owners/package/'.$package->getID().'/', 302 - ), 303 - $package->getName()), 304 - $pkg_owners, 305 - $pkg_paths, 306 - phutil_tag( 307 - 'a', 308 - array( 309 - 'href' => '/audit/?auditorPHIDs='.$package->getPHID(), 310 - ), 311 - pht('Related Commits')), 312 - ); 313 - } 314 - 315 - $table = new AphrontTableView($rows); 316 - $table->setHeaders( 317 - array( 318 - pht('Name'), 319 - pht('Owners'), 320 - pht('Paths'), 321 - pht('Related Commits'), 322 - )); 323 - $table->setColumnClasses( 324 - array( 325 - 'pri', 326 - '', 327 - 'wide wrap', 328 - 'narrow', 329 - )); 330 - 331 - $panel = new PHUIObjectBoxView(); 332 - $panel->setHeaderText($header); 333 - $panel->appendChild($table); 334 - 335 - return $panel; 51 + return $crumbs; 336 52 } 337 53 338 - protected function getExtraPackageViews(AphrontSideNavFilterView $view) { 339 - if ($this->view == 'search') { 340 - $view->addFilter('view/search', pht('Search Results')); 341 - } 342 - } 343 54 }
+36 -3
src/applications/owners/query/PhabricatorOwnersPackageQuery.php
··· 3 3 final class PhabricatorOwnersPackageQuery 4 4 extends PhabricatorCursorPagedPolicyAwareQuery { 5 5 6 + private $ids; 6 7 private $phids; 7 8 private $ownerPHIDs; 9 + private $repositoryPHIDs; 8 10 9 11 /** 10 12 * Owners are direct owners, and members of owning projects. ··· 19 21 return $this; 20 22 } 21 23 24 + public function withIDs(array $ids) { 25 + $this->ids = $ids; 26 + return $this; 27 + } 28 + 29 + public function withRepositoryPHIDs(array $phids) { 30 + $this->repositoryPHIDs = $phids; 31 + return $this; 32 + } 33 + 22 34 protected function loadPage() { 23 35 $table = new PhabricatorOwnersPackage(); 24 36 $conn_r = $table->establishConnection('r'); ··· 38 50 protected function buildJoinClause(AphrontDatabaseConnection $conn_r) { 39 51 $joins = array(); 40 52 41 - if ($this->ownerPHIDs) { 53 + if ($this->ownerPHIDs !== null) { 42 54 $joins[] = qsprintf( 43 55 $conn_r, 44 56 'JOIN %T o ON o.packageID = p.id', 45 57 id(new PhabricatorOwnersOwner())->getTableName()); 46 58 } 47 59 60 + if ($this->repositoryPHIDs !== null) { 61 + $joins[] = qsprintf( 62 + $conn_r, 63 + 'JOIN %T rpath ON rpath.packageID = p.id', 64 + id(new PhabricatorOwnersPath())->getTableName()); 65 + } 66 + 48 67 return implode(' ', $joins); 49 68 } 50 69 51 70 protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { 52 71 $where = array(); 53 72 54 - if ($this->phids) { 73 + if ($this->phids !== null) { 55 74 $where[] = qsprintf( 56 75 $conn_r, 57 76 'p.phid IN (%Ls)', 58 77 $this->phids); 59 78 } 60 79 61 - if ($this->ownerPHIDs) { 80 + if ($this->ids !== null) { 81 + $where[] = qsprintf( 82 + $conn_r, 83 + 'p.id IN (%Ld)', 84 + $this->ids); 85 + } 86 + 87 + if ($this->repositoryPHIDs !== null) { 88 + $where[] = qsprintf( 89 + $conn_r, 90 + 'rpath.repositoryPHID IN (%Ls)', 91 + $this->repositoryPHIDs); 92 + } 93 + 94 + if ($this->ownerPHIDs !== null) { 62 95 $base_phids = $this->ownerPHIDs; 63 96 64 97 $query = new PhabricatorProjectQuery();
+134
src/applications/owners/query/PhabricatorOwnersPackageSearchEngine.php
··· 1 + <?php 2 + 3 + final class PhabricatorOwnersPackageSearchEngine 4 + extends PhabricatorApplicationSearchEngine { 5 + 6 + public function getResultTypeDescription() { 7 + return pht('Owners Packages'); 8 + } 9 + 10 + public function getApplicationClassName() { 11 + return 'PhabricatorOwnersApplication'; 12 + } 13 + 14 + public function buildSavedQueryFromRequest(AphrontRequest $request) { 15 + $saved = new PhabricatorSavedQuery(); 16 + 17 + $saved->setParameter( 18 + 'ownerPHIDs', 19 + $this->readUsersFromRequest( 20 + $request, 21 + 'owners', 22 + array( 23 + PhabricatorProjectProjectPHIDType::TYPECONST, 24 + ))); 25 + 26 + $saved->setParameter( 27 + 'repositoryPHIDs', 28 + $this->readPHIDsFromRequest( 29 + $request, 30 + 'repositories', 31 + array( 32 + PhabricatorRepositoryRepositoryPHIDType::TYPECONST, 33 + ))); 34 + 35 + return $saved; 36 + } 37 + 38 + public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { 39 + $query = id(new PhabricatorOwnersPackageQuery()); 40 + 41 + $owner_phids = $saved->getParameter('ownerPHIDs', array()); 42 + if ($owner_phids) { 43 + $query->withOwnerPHIDs($owner_phids); 44 + } 45 + 46 + $repository_phids = $saved->getParameter('repositoryPHIDs', array()); 47 + if ($repository_phids) { 48 + $query->withRepositoryPHIDs($repository_phids); 49 + } 50 + 51 + return $query; 52 + } 53 + 54 + public function buildSearchForm( 55 + AphrontFormView $form, 56 + PhabricatorSavedQuery $saved) { 57 + 58 + $owner_phids = $saved->getParameter('ownerPHIDs', array()); 59 + $repository_phids = $saved->getParameter('repositoryPHIDs', array()); 60 + 61 + $form 62 + ->appendControl( 63 + id(new AphrontFormTokenizerControl()) 64 + ->setDatasource(new PhabricatorProjectOrUserDatasource()) 65 + ->setName('owners') 66 + ->setLabel(pht('Owners')) 67 + ->setValue($owner_phids)) 68 + ->appendControl( 69 + id(new AphrontFormTokenizerControl()) 70 + ->setDatasource(new DiffusionRepositoryDatasource()) 71 + ->setName('repositories') 72 + ->setLabel(pht('Repositories')) 73 + ->setValue($repository_phids)); 74 + } 75 + 76 + protected function getURI($path) { 77 + return '/owners/'.$path; 78 + } 79 + 80 + protected function getBuiltinQueryNames() { 81 + $names = array(); 82 + 83 + if ($this->requireViewer()->isLoggedIn()) { 84 + $names['owned'] = pht('Owned'); 85 + } 86 + 87 + $names += array( 88 + 'all' => pht('All Packages'), 89 + ); 90 + 91 + return $names; 92 + } 93 + 94 + public function buildSavedQueryFromBuiltin($query_key) { 95 + $query = $this->newSavedQuery(); 96 + $query->setQueryKey($query_key); 97 + 98 + switch ($query_key) { 99 + case 'all': 100 + return $query; 101 + case 'owned': 102 + return $query->setParameter( 103 + 'ownerPHIDs', 104 + array($this->requireViewer()->getPHID())); 105 + } 106 + 107 + return parent::buildSavedQueryFromBuiltin($query_key); 108 + } 109 + 110 + protected function renderResultList( 111 + array $packages, 112 + PhabricatorSavedQuery $query, 113 + array $handles) { 114 + assert_instances_of($packages, 'PhabricatorOwnersPackage'); 115 + 116 + $viewer = $this->requireViewer(); 117 + 118 + $list = id(new PHUIObjectItemListView()) 119 + ->setUser($viewer); 120 + foreach ($packages as $package) { 121 + $id = $package->getID(); 122 + 123 + $item = id(new PHUIObjectItemView()) 124 + ->setObject($package) 125 + ->setObjectName(pht('Package %d', $id)) 126 + ->setHeader($package->getName()) 127 + ->setHref('/owners/package/'.$id.'/'); 128 + 129 + $list->addItem($item); 130 + } 131 + 132 + return $list; 133 + } 134 + }
+3 -2
src/applications/owners/storage/PhabricatorOwnersPackage.php
··· 37 37 return array( 38 38 // This information is better available from the history table. 39 39 self::CONFIG_TIMESTAMPS => false, 40 - self::CONFIG_AUX_PHID => true, 40 + self::CONFIG_AUX_PHID => true, 41 41 self::CONFIG_COLUMN_SCHEMA => array( 42 42 'name' => 'text128', 43 43 'originalName' => 'text255', ··· 60 60 } 61 61 62 62 public function generatePHID() { 63 - return PhabricatorPHID::generateNewPHID('OPKG'); 63 + return PhabricatorPHID::generateNewPHID( 64 + PhabricatorOwnersPackagePHIDType::TYPECONST); 64 65 } 65 66 66 67 public function attachUnsavedOwners(array $owners) {