From 3b2f4c258f1bae4d65391987045c0b7385cf7d63 Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 24 Sep 2015 13:52:43 -0700 Subject: [PATCH] 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 --- .../PhabricatorDrydockApplication.php | 2 + .../DrydockBlueprintViewController.php | 61 ++++++++++++------- .../controller/DrydockResourceController.php | 36 +++++++++-- .../DrydockResourceListController.php | 20 +++++- .../query/DrydockResourceSearchEngine.php | 28 ++++++++- 5 files changed, 118 insertions(+), 29 deletions(-) diff --git a/src/applications/drydock/application/PhabricatorDrydockApplication.php b/src/applications/drydock/application/PhabricatorDrydockApplication.php index afc4219d1f..bf95a57009 100644 --- a/src/applications/drydock/application/PhabricatorDrydockApplication.php +++ b/src/applications/drydock/application/PhabricatorDrydockApplication.php @@ -53,6 +53,8 @@ final class PhabricatorDrydockApplication extends PhabricatorApplication { '' => 'DrydockBlueprintViewController', '(?Pdisable|enable)/' => 'DrydockBlueprintDisableController', + 'resources/(?:query/(?P[^/]+)/)?' => + 'DrydockResourceListController', ), 'create/' => 'DrydockBlueprintCreateController', 'edit/(?:(?P[1-9]\d*)/)?' => 'DrydockBlueprintEditController', diff --git a/src/applications/drydock/controller/DrydockBlueprintViewController.php b/src/applications/drydock/controller/DrydockBlueprintViewController.php index 815ace7026..6991e18fa2 100644 --- a/src/applications/drydock/controller/DrydockBlueprintViewController.php +++ b/src/applications/drydock/controller/DrydockBlueprintViewController.php @@ -30,24 +30,6 @@ final class DrydockBlueprintViewController extends DrydockBlueprintController { $actions = $this->buildActionListView($blueprint); $properties = $this->buildPropertyListView($blueprint, $actions); - $blueprint_uri = 'blueprint/'.$blueprint->getID().'/'; - $blueprint_uri = $this->getApplicationURI($blueprint_uri); - - $resources = id(new DrydockResourceQuery()) - ->withBlueprintPHIDs(array($blueprint->getPHID())) - ->setViewer($viewer) - ->execute(); - - $resource_list = id(new DrydockResourceListView()) - ->setUser($viewer) - ->setResources($resources) - ->render(); - $resource_list->setNoDataString(pht('This blueprint has no resources.')); - - $pager = new PHUIPagerView(); - $pager->setURI(new PhutilURI($blueprint_uri), 'offset'); - $pager->setOffset($request->getInt('offset')); - $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb(pht('Blueprint %d', $blueprint->getID())); @@ -67,9 +49,7 @@ final class DrydockBlueprintViewController extends DrydockBlueprintController { $viewer, $properties); - $resource_box = id(new PHUIObjectBoxView()) - ->setHeaderText(pht('Resources')) - ->setObjectList($resource_list); + $resource_box = $this->buildResourceBox($blueprint); $timeline = $this->buildTransactionTimeline( $blueprint, @@ -148,4 +128,43 @@ final class DrydockBlueprintViewController extends DrydockBlueprintController { return $view; } + private function buildResourceBox(DrydockBlueprint $blueprint) { + $viewer = $this->getViewer(); + + $resources = id(new DrydockResourceQuery()) + ->setViewer($viewer) + ->withBlueprintPHIDs(array($blueprint->getPHID())) + ->withStatuses( + array( + DrydockResourceStatus::STATUS_PENDING, + DrydockResourceStatus::STATUS_ACTIVE, + )) + ->setLimit(100) + ->execute(); + + $resource_list = id(new DrydockResourceListView()) + ->setUser($viewer) + ->setResources($resources) + ->render() + ->setNoDataString(pht('This blueprint has no active resources.')); + + $id = $blueprint->getID(); + $resources_uri = "blueprint/{$id}/resources/query/all/"; + $resources_uri = $this->getApplicationURI($resources_uri); + + $resource_header = id(new PHUIHeaderView()) + ->setHeader(pht('Active Resources')) + ->addActionLink( + id(new PHUIButtonView()) + ->setTag('a') + ->setHref($resources_uri) + ->setIconFont('fa-search') + ->setText(pht('View All Resources'))); + + return id(new PHUIObjectBoxView()) + ->setHeader($resource_header) + ->setObjectList($resource_list); + } + + } diff --git a/src/applications/drydock/controller/DrydockResourceController.php b/src/applications/drydock/controller/DrydockResourceController.php index e29b13e2c2..8675b5bf59 100644 --- a/src/applications/drydock/controller/DrydockResourceController.php +++ b/src/applications/drydock/controller/DrydockResourceController.php @@ -3,12 +3,23 @@ abstract class DrydockResourceController extends DrydockController { + private $blueprint; + + public function setBlueprint($blueprint) { + $this->blueprint = $blueprint; + return $this; + } + + public function getBlueprint() { + return $this->blueprint; + } + public function buildSideNavView() { $nav = new AphrontSideNavFilterView(); $nav->setBaseURI(new PhutilURI($this->getApplicationURI())); id(new DrydockResourceSearchEngine()) - ->setViewer($this->getRequest()->getUser()) + ->setViewer($this->getViewer()) ->addNavigationItems($nav->getMenu()); $nav->selectFilter(null); @@ -18,9 +29,26 @@ abstract class DrydockResourceController protected function buildApplicationCrumbs() { $crumbs = parent::buildApplicationCrumbs(); - $crumbs->addTextCrumb( - pht('Resources'), - $this->getApplicationURI('resource/')); + + $blueprint = $this->getBlueprint(); + if ($blueprint) { + $id = $blueprint->getID(); + $crumbs->addTextCrumb( + pht('Blueprints'), + $this->getApplicationURI('blueprint/')); + + $crumbs->addTextCrumb( + $blueprint->getBlueprintName(), + $this->getApplicationURI("blueprint/{$id}/")); + + $crumbs->addTextCrumb( + pht('Resources'), + $this->getApplicationURI("blueprint/{$id}/resources/")); + } else { + $crumbs->addTextCrumb( + pht('Resources'), + $this->getApplicationURI('resource/')); + } return $crumbs; } diff --git a/src/applications/drydock/controller/DrydockResourceListController.php b/src/applications/drydock/controller/DrydockResourceListController.php index d2f34ec25b..6e1f80cbd6 100644 --- a/src/applications/drydock/controller/DrydockResourceListController.php +++ b/src/applications/drydock/controller/DrydockResourceListController.php @@ -7,12 +7,28 @@ final class DrydockResourceListController extends DrydockResourceController { } public function handleRequest(AphrontRequest $request) { - $viewer = $request->getViewer(); + $viewer = $this->getViewer(); + + $engine = new DrydockResourceSearchEngine(); + + $id = $request->getURIData('id'); + if ($id) { + $blueprint = id(new DrydockBlueprintQuery()) + ->setViewer($viewer) + ->withIDs(array($id)) + ->executeOne(); + if (!$blueprint) { + return new Aphront404Response(); + } + $this->setBlueprint($blueprint); + $engine->setBlueprint($blueprint); + } + $querykey = $request->getURIData('queryKey'); $controller = id(new PhabricatorApplicationSearchController()) ->setQueryKey($querykey) - ->setSearchEngine(new DrydockResourceSearchEngine()) + ->setSearchEngine($engine) ->setNavigation($this->buildSideNavView()); return $this->delegateToController($controller); diff --git a/src/applications/drydock/query/DrydockResourceSearchEngine.php b/src/applications/drydock/query/DrydockResourceSearchEngine.php index 7b0bca0324..8f72fdf217 100644 --- a/src/applications/drydock/query/DrydockResourceSearchEngine.php +++ b/src/applications/drydock/query/DrydockResourceSearchEngine.php @@ -3,6 +3,17 @@ final class DrydockResourceSearchEngine extends PhabricatorApplicationSearchEngine { + private $blueprint; + + public function setBlueprint(DrydockBlueprint $blueprint) { + $this->blueprint = $blueprint; + return $this; + } + + public function getBlueprint() { + return $this->blueprint; + } + public function getResultTypeDescription() { return pht('Drydock Resources'); } @@ -12,7 +23,14 @@ final class DrydockResourceSearchEngine } public function newQuery() { - return new DrydockResourceQuery(); + $query = new DrydockResourceQuery(); + + $blueprint = $this->getBlueprint(); + if ($blueprint) { + $query->withBlueprintPHIDs(array($blueprint->getPHID())); + } + + return $query; } protected function buildQueryFromParameters(array $map) { @@ -35,7 +53,13 @@ final class DrydockResourceSearchEngine } protected function getURI($path) { - return '/drydock/resource/'.$path; + $blueprint = $this->getBlueprint(); + if ($blueprint) { + $id = $blueprint->getID(); + return "/drydock/blueprint/{$id}/resources/".$path; + } else { + return '/drydock/resource/'.$path; + } } protected function getBuiltinQueryNames() {