@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.

Show recent active resources on Drydock blueprint detail, with link to all

Summary:
Ref T9252. Currently, Drydock blueprint pages:

- show all resources, even if there are a million;
- show resources in all states, although destroyed resources are usually uninteresting;
- have some junky `$pager` code.

Instead, show the few most recent active resources and link to a filtered resource view in ApplicationSearch.

Test Plan:
- Viewed some blueprints.
- Clicked "View All Resources".
- Saw all resources.
- Used query / crumbs / etc.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T9252

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

+118 -29
+2
src/applications/drydock/application/PhabricatorDrydockApplication.php
··· 53 53 '' => 'DrydockBlueprintViewController', 54 54 '(?P<action>disable|enable)/' => 55 55 'DrydockBlueprintDisableController', 56 + 'resources/(?:query/(?P<queryKey>[^/]+)/)?' => 57 + 'DrydockResourceListController', 56 58 ), 57 59 'create/' => 'DrydockBlueprintCreateController', 58 60 'edit/(?:(?P<id>[1-9]\d*)/)?' => 'DrydockBlueprintEditController',
+40 -21
src/applications/drydock/controller/DrydockBlueprintViewController.php
··· 30 30 $actions = $this->buildActionListView($blueprint); 31 31 $properties = $this->buildPropertyListView($blueprint, $actions); 32 32 33 - $blueprint_uri = 'blueprint/'.$blueprint->getID().'/'; 34 - $blueprint_uri = $this->getApplicationURI($blueprint_uri); 35 - 36 - $resources = id(new DrydockResourceQuery()) 37 - ->withBlueprintPHIDs(array($blueprint->getPHID())) 38 - ->setViewer($viewer) 39 - ->execute(); 40 - 41 - $resource_list = id(new DrydockResourceListView()) 42 - ->setUser($viewer) 43 - ->setResources($resources) 44 - ->render(); 45 - $resource_list->setNoDataString(pht('This blueprint has no resources.')); 46 - 47 - $pager = new PHUIPagerView(); 48 - $pager->setURI(new PhutilURI($blueprint_uri), 'offset'); 49 - $pager->setOffset($request->getInt('offset')); 50 - 51 33 $crumbs = $this->buildApplicationCrumbs(); 52 34 $crumbs->addTextCrumb(pht('Blueprint %d', $blueprint->getID())); 53 35 ··· 67 49 $viewer, 68 50 $properties); 69 51 70 - $resource_box = id(new PHUIObjectBoxView()) 71 - ->setHeaderText(pht('Resources')) 72 - ->setObjectList($resource_list); 52 + $resource_box = $this->buildResourceBox($blueprint); 73 53 74 54 $timeline = $this->buildTransactionTimeline( 75 55 $blueprint, ··· 147 127 148 128 return $view; 149 129 } 130 + 131 + private function buildResourceBox(DrydockBlueprint $blueprint) { 132 + $viewer = $this->getViewer(); 133 + 134 + $resources = id(new DrydockResourceQuery()) 135 + ->setViewer($viewer) 136 + ->withBlueprintPHIDs(array($blueprint->getPHID())) 137 + ->withStatuses( 138 + array( 139 + DrydockResourceStatus::STATUS_PENDING, 140 + DrydockResourceStatus::STATUS_ACTIVE, 141 + )) 142 + ->setLimit(100) 143 + ->execute(); 144 + 145 + $resource_list = id(new DrydockResourceListView()) 146 + ->setUser($viewer) 147 + ->setResources($resources) 148 + ->render() 149 + ->setNoDataString(pht('This blueprint has no active resources.')); 150 + 151 + $id = $blueprint->getID(); 152 + $resources_uri = "blueprint/{$id}/resources/query/all/"; 153 + $resources_uri = $this->getApplicationURI($resources_uri); 154 + 155 + $resource_header = id(new PHUIHeaderView()) 156 + ->setHeader(pht('Active Resources')) 157 + ->addActionLink( 158 + id(new PHUIButtonView()) 159 + ->setTag('a') 160 + ->setHref($resources_uri) 161 + ->setIconFont('fa-search') 162 + ->setText(pht('View All Resources'))); 163 + 164 + return id(new PHUIObjectBoxView()) 165 + ->setHeader($resource_header) 166 + ->setObjectList($resource_list); 167 + } 168 + 150 169 151 170 }
+32 -4
src/applications/drydock/controller/DrydockResourceController.php
··· 3 3 abstract class DrydockResourceController 4 4 extends DrydockController { 5 5 6 + private $blueprint; 7 + 8 + public function setBlueprint($blueprint) { 9 + $this->blueprint = $blueprint; 10 + return $this; 11 + } 12 + 13 + public function getBlueprint() { 14 + return $this->blueprint; 15 + } 16 + 6 17 public function buildSideNavView() { 7 18 $nav = new AphrontSideNavFilterView(); 8 19 $nav->setBaseURI(new PhutilURI($this->getApplicationURI())); 9 20 10 21 id(new DrydockResourceSearchEngine()) 11 - ->setViewer($this->getRequest()->getUser()) 22 + ->setViewer($this->getViewer()) 12 23 ->addNavigationItems($nav->getMenu()); 13 24 14 25 $nav->selectFilter(null); ··· 18 29 19 30 protected function buildApplicationCrumbs() { 20 31 $crumbs = parent::buildApplicationCrumbs(); 21 - $crumbs->addTextCrumb( 22 - pht('Resources'), 23 - $this->getApplicationURI('resource/')); 32 + 33 + $blueprint = $this->getBlueprint(); 34 + if ($blueprint) { 35 + $id = $blueprint->getID(); 36 + $crumbs->addTextCrumb( 37 + pht('Blueprints'), 38 + $this->getApplicationURI('blueprint/')); 39 + 40 + $crumbs->addTextCrumb( 41 + $blueprint->getBlueprintName(), 42 + $this->getApplicationURI("blueprint/{$id}/")); 43 + 44 + $crumbs->addTextCrumb( 45 + pht('Resources'), 46 + $this->getApplicationURI("blueprint/{$id}/resources/")); 47 + } else { 48 + $crumbs->addTextCrumb( 49 + pht('Resources'), 50 + $this->getApplicationURI('resource/')); 51 + } 24 52 return $crumbs; 25 53 } 26 54
+18 -2
src/applications/drydock/controller/DrydockResourceListController.php
··· 7 7 } 8 8 9 9 public function handleRequest(AphrontRequest $request) { 10 - $viewer = $request->getViewer(); 10 + $viewer = $this->getViewer(); 11 + 12 + $engine = new DrydockResourceSearchEngine(); 13 + 14 + $id = $request->getURIData('id'); 15 + if ($id) { 16 + $blueprint = id(new DrydockBlueprintQuery()) 17 + ->setViewer($viewer) 18 + ->withIDs(array($id)) 19 + ->executeOne(); 20 + if (!$blueprint) { 21 + return new Aphront404Response(); 22 + } 23 + $this->setBlueprint($blueprint); 24 + $engine->setBlueprint($blueprint); 25 + } 26 + 11 27 $querykey = $request->getURIData('queryKey'); 12 28 13 29 $controller = id(new PhabricatorApplicationSearchController()) 14 30 ->setQueryKey($querykey) 15 - ->setSearchEngine(new DrydockResourceSearchEngine()) 31 + ->setSearchEngine($engine) 16 32 ->setNavigation($this->buildSideNavView()); 17 33 18 34 return $this->delegateToController($controller);
+26 -2
src/applications/drydock/query/DrydockResourceSearchEngine.php
··· 3 3 final class DrydockResourceSearchEngine 4 4 extends PhabricatorApplicationSearchEngine { 5 5 6 + private $blueprint; 7 + 8 + public function setBlueprint(DrydockBlueprint $blueprint) { 9 + $this->blueprint = $blueprint; 10 + return $this; 11 + } 12 + 13 + public function getBlueprint() { 14 + return $this->blueprint; 15 + } 16 + 6 17 public function getResultTypeDescription() { 7 18 return pht('Drydock Resources'); 8 19 } ··· 12 23 } 13 24 14 25 public function newQuery() { 15 - return new DrydockResourceQuery(); 26 + $query = new DrydockResourceQuery(); 27 + 28 + $blueprint = $this->getBlueprint(); 29 + if ($blueprint) { 30 + $query->withBlueprintPHIDs(array($blueprint->getPHID())); 31 + } 32 + 33 + return $query; 16 34 } 17 35 18 36 protected function buildQueryFromParameters(array $map) { ··· 35 53 } 36 54 37 55 protected function getURI($path) { 38 - return '/drydock/resource/'.$path; 56 + $blueprint = $this->getBlueprint(); 57 + if ($blueprint) { 58 + $id = $blueprint->getID(); 59 + return "/drydock/blueprint/{$id}/resources/".$path; 60 + } else { 61 + return '/drydock/resource/'.$path; 62 + } 39 63 } 40 64 41 65 protected function getBuiltinQueryNames() {