From 38f5894b58f3d94c25a6229a89be919ec36b6475 Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 13 May 2014 12:14:33 -0700 Subject: [PATCH] Move Drydock object list rendering to SearchEngine Summary: Ref T4986. Allows the Drydock search engines to render as panels. Test Plan: Viewed affected interfaces in Drydock. Created panels from each engine. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T4986 Differential Revision: https://secure.phabricator.com/D9103 --- src/__phutil_library_map__.php | 24 ++- .../DrydockBlueprintViewController.php | 5 +- .../drydock/controller/DrydockController.php | 141 ------------------ .../controller/DrydockLeaseListController.php | 11 +- .../controller/DrydockLeaseViewController.php | 5 +- .../controller/DrydockLogListController.php | 11 +- .../DrydockResourceListController.php | 11 +- .../DrydockResourceViewController.php | 10 +- .../query/DrydockLeaseSearchEngine.php | 15 ++ .../drydock/query/DrydockLogSearchEngine.php | 15 ++ .../query/DrydockResourceSearchEngine.php | 15 ++ .../drydock/view/DrydockLeaseListView.php | 56 +++++++ .../drydock/view/DrydockLogListView.php | 69 +++++++++ .../drydock/view/DrydockResourceListView.php | 49 ++++++ 14 files changed, 247 insertions(+), 190 deletions(-) create mode 100644 src/applications/drydock/view/DrydockLeaseListView.php create mode 100644 src/applications/drydock/view/DrydockLogListView.php create mode 100644 src/applications/drydock/view/DrydockResourceListView.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 8b1e8fadbc..080ba7456f 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -661,6 +661,7 @@ phutil_register_library_map(array( 'DrydockLease' => 'applications/drydock/storage/DrydockLease.php', 'DrydockLeaseController' => 'applications/drydock/controller/DrydockLeaseController.php', 'DrydockLeaseListController' => 'applications/drydock/controller/DrydockLeaseListController.php', + 'DrydockLeaseListView' => 'applications/drydock/view/DrydockLeaseListView.php', 'DrydockLeaseQuery' => 'applications/drydock/query/DrydockLeaseQuery.php', 'DrydockLeaseReleaseController' => 'applications/drydock/controller/DrydockLeaseReleaseController.php', 'DrydockLeaseSearchEngine' => 'applications/drydock/query/DrydockLeaseSearchEngine.php', @@ -671,6 +672,7 @@ phutil_register_library_map(array( 'DrydockLog' => 'applications/drydock/storage/DrydockLog.php', 'DrydockLogController' => 'applications/drydock/controller/DrydockLogController.php', 'DrydockLogListController' => 'applications/drydock/controller/DrydockLogListController.php', + 'DrydockLogListView' => 'applications/drydock/view/DrydockLogListView.php', 'DrydockLogQuery' => 'applications/drydock/query/DrydockLogQuery.php', 'DrydockLogSearchEngine' => 'applications/drydock/query/DrydockLogSearchEngine.php', 'DrydockManagementCloseWorkflow' => 'applications/drydock/management/DrydockManagementCloseWorkflow.php', @@ -687,6 +689,7 @@ phutil_register_library_map(array( 'DrydockResourceCloseController' => 'applications/drydock/controller/DrydockResourceCloseController.php', 'DrydockResourceController' => 'applications/drydock/controller/DrydockResourceController.php', 'DrydockResourceListController' => 'applications/drydock/controller/DrydockResourceListController.php', + 'DrydockResourceListView' => 'applications/drydock/view/DrydockResourceListView.php', 'DrydockResourceQuery' => 'applications/drydock/query/DrydockResourceQuery.php', 'DrydockResourceSearchEngine' => 'applications/drydock/query/DrydockResourceSearchEngine.php', 'DrydockResourceStatus' => 'applications/drydock/constants/DrydockResourceStatus.php', @@ -3305,11 +3308,8 @@ phutil_register_library_map(array( 1 => 'PhabricatorPolicyInterface', ), 'DrydockLeaseController' => 'DrydockController', - 'DrydockLeaseListController' => - array( - 0 => 'DrydockLeaseController', - 1 => 'PhabricatorApplicationSearchResultsControllerInterface', - ), + 'DrydockLeaseListController' => 'DrydockLeaseController', + 'DrydockLeaseListView' => 'AphrontView', 'DrydockLeaseQuery' => 'DrydockQuery', 'DrydockLeaseReleaseController' => 'DrydockLeaseController', 'DrydockLeaseSearchEngine' => 'PhabricatorApplicationSearchEngine', @@ -3323,11 +3323,8 @@ phutil_register_library_map(array( 1 => 'PhabricatorPolicyInterface', ), 'DrydockLogController' => 'DrydockController', - 'DrydockLogListController' => - array( - 0 => 'DrydockLogController', - 1 => 'PhabricatorApplicationSearchResultsControllerInterface', - ), + 'DrydockLogListController' => 'DrydockLogController', + 'DrydockLogListView' => 'AphrontView', 'DrydockLogQuery' => 'DrydockQuery', 'DrydockLogSearchEngine' => 'PhabricatorApplicationSearchEngine', 'DrydockManagementCloseWorkflow' => 'DrydockManagementWorkflow', @@ -3347,11 +3344,8 @@ phutil_register_library_map(array( ), 'DrydockResourceCloseController' => 'DrydockResourceController', 'DrydockResourceController' => 'DrydockController', - 'DrydockResourceListController' => - array( - 0 => 'DrydockResourceController', - 1 => 'PhabricatorApplicationSearchResultsControllerInterface', - ), + 'DrydockResourceListController' => 'DrydockResourceController', + 'DrydockResourceListView' => 'AphrontView', 'DrydockResourceQuery' => 'DrydockQuery', 'DrydockResourceSearchEngine' => 'PhabricatorApplicationSearchEngine', 'DrydockResourceStatus' => 'DrydockConstants', diff --git a/src/applications/drydock/controller/DrydockBlueprintViewController.php b/src/applications/drydock/controller/DrydockBlueprintViewController.php index d09052a79c..3491d0473b 100644 --- a/src/applications/drydock/controller/DrydockBlueprintViewController.php +++ b/src/applications/drydock/controller/DrydockBlueprintViewController.php @@ -38,7 +38,10 @@ final class DrydockBlueprintViewController extends DrydockBlueprintController { ->setViewer($viewer) ->execute(); - $resource_list = $this->buildResourceListView($resources); + $resource_list = id(new DrydockResourceListView()) + ->setUser($viewer) + ->setResources($resources) + ->render(); $resource_list->setNoDataString(pht('This blueprint has no resources.')); $pager = new AphrontPagerView(); diff --git a/src/applications/drydock/controller/DrydockController.php b/src/applications/drydock/controller/DrydockController.php index 567961c5bb..1d5d847484 100644 --- a/src/applications/drydock/controller/DrydockController.php +++ b/src/applications/drydock/controller/DrydockController.php @@ -8,145 +8,4 @@ abstract class DrydockController extends PhabricatorController { return $this->buildSideNavView()->getMenu(); } - protected function buildLogTableView(array $logs) { - assert_instances_of($logs, 'DrydockLog'); - - $user = $this->getRequest()->getUser(); - - $rows = array(); - foreach ($logs as $log) { - $resource_uri = '/resource/'.$log->getResourceID().'/'; - $resource_uri = $this->getApplicationURI($resource_uri); - - $lease_uri = '/lease/'.$log->getLeaseID().'/'; - $lease_uri = $this->getApplicationURI($lease_uri); - - $rows[] = array( - phutil_tag( - 'a', - array( - 'href' => $resource_uri, - ), - $log->getResourceID()), - phutil_tag( - 'a', - array( - 'href' => $lease_uri, - ), - $log->getLeaseID()), - $log->getMessage(), - phabricator_date($log->getEpoch(), $user), - ); - } - - $table = new AphrontTableView($rows); - $table->setDeviceReadyTable(true); - $table->setHeaders( - array( - 'Resource', - 'Lease', - 'Message', - 'Date', - )); - $table->setShortHeaders( - array( - 'R', - 'L', - 'Message', - '', - )); - $table->setColumnClasses( - array( - '', - '', - 'wide', - '', - )); - - return $table; - } - - protected function buildLeaseListView(array $leases) { - assert_instances_of($leases, 'DrydockLease'); - - $viewer = $this->getRequest()->getUser(); - $view = new PHUIObjectItemListView(); - - foreach ($leases as $lease) { - $item = id(new PHUIObjectItemView()) - ->setUser($viewer) - ->setHeader($lease->getLeaseName()) - ->setHref($this->getApplicationURI('/lease/'.$lease->getID().'/')); - - if ($lease->hasAttachedResource()) { - $resource = $lease->getResource(); - - $resource_href = '/resource/'.$resource->getID().'/'; - $resource_href = $this->getApplicationURI($resource_href); - - $resource_name = $resource->getName(); - - $item->addAttribute( - phutil_tag( - 'a', - array( - 'href' => $resource_href, - ), - $resource_name)); - } - - $status = DrydockLeaseStatus::getNameForStatus($lease->getStatus()); - $item->addAttribute($status); - $item->setEpoch($lease->getDateCreated()); - - if ($lease->isActive()) { - $item->setBarColor('green'); - } else { - $item->setBarColor('red'); - } - - $view->addItem($item); - } - - return $view; - } - - protected function buildResourceListView(array $resources) { - assert_instances_of($resources, 'DrydockResource'); - - $user = $this->getRequest()->getUser(); - $view = new PHUIObjectItemListView(); - - foreach ($resources as $resource) { - $name = pht('Resource %d', $resource->getID()).': '.$resource->getName(); - - $item = id(new PHUIObjectItemView()) - ->setHref($this->getApplicationURI('/resource/'.$resource->getID().'/')) - ->setHeader($name); - - $status = DrydockResourceStatus::getNameForStatus($resource->getStatus()); - $item->addAttribute($status); - - switch ($resource->getStatus()) { - case DrydockResourceStatus::STATUS_PENDING: - $item->setBarColor('yellow'); - break; - case DrydockResourceStatus::STATUS_OPEN: - $item->setBarColor('green'); - break; - case DrydockResourceStatus::STATUS_DESTROYED: - $item->setBarColor('black'); - break; - default: - $item->setBarColor('red'); - break; - } - - $view->addItem($item); - } - - return $view; - } - - } diff --git a/src/applications/drydock/controller/DrydockLeaseListController.php b/src/applications/drydock/controller/DrydockLeaseListController.php index 2b3111ebe1..6d8835770d 100644 --- a/src/applications/drydock/controller/DrydockLeaseListController.php +++ b/src/applications/drydock/controller/DrydockLeaseListController.php @@ -1,7 +1,6 @@ delegateToController($controller); } - public function renderResultsList( - array $leases, - PhabricatorSavedQuery $query) { - assert_instances_of($leases, 'DrydockLease'); - - return $this->buildLeaseListView($leases); - } - } diff --git a/src/applications/drydock/controller/DrydockLeaseViewController.php b/src/applications/drydock/controller/DrydockLeaseViewController.php index 7075e55128..2895cad39e 100644 --- a/src/applications/drydock/controller/DrydockLeaseViewController.php +++ b/src/applications/drydock/controller/DrydockLeaseViewController.php @@ -39,7 +39,10 @@ final class DrydockLeaseViewController extends DrydockLeaseController { ->withLeaseIDs(array($lease->getID())) ->executeWithOffsetPager($pager); - $log_table = $this->buildLogTableView($logs); + $log_table = id(new DrydockLogListView()) + ->setUser($viewer) + ->setLogs($logs) + ->render(); $log_table->appendChild($pager); $crumbs = $this->buildApplicationCrumbs(); diff --git a/src/applications/drydock/controller/DrydockLogListController.php b/src/applications/drydock/controller/DrydockLogListController.php index 6ccd4f6fb1..68047922f2 100644 --- a/src/applications/drydock/controller/DrydockLogListController.php +++ b/src/applications/drydock/controller/DrydockLogListController.php @@ -1,7 +1,6 @@ delegateToController($controller); } - public function renderResultsList( - array $logs, - PhabricatorSavedQuery $query) { - assert_instances_of($logs, 'DrydockLog'); - - return $this->buildLogTableView($logs); - } - } diff --git a/src/applications/drydock/controller/DrydockResourceListController.php b/src/applications/drydock/controller/DrydockResourceListController.php index fe80a314cb..3da5841e21 100644 --- a/src/applications/drydock/controller/DrydockResourceListController.php +++ b/src/applications/drydock/controller/DrydockResourceListController.php @@ -1,7 +1,6 @@ delegateToController($controller); } - public function renderResultsList( - array $resources, - PhabricatorSavedQuery $query) { - assert_instances_of($resources, 'DrydockResource'); - - return $this->buildResourceListView($resources); - } - } diff --git a/src/applications/drydock/controller/DrydockResourceViewController.php b/src/applications/drydock/controller/DrydockResourceViewController.php index 9ac417bad3..93d0e9dfd5 100644 --- a/src/applications/drydock/controller/DrydockResourceViewController.php +++ b/src/applications/drydock/controller/DrydockResourceViewController.php @@ -36,7 +36,10 @@ final class DrydockResourceViewController extends DrydockResourceController { ->withResourceIDs(array($resource->getID())) ->execute(); - $lease_list = $this->buildLeaseListView($leases); + $lease_list = id(new DrydockLeaseListView()) + ->setUser($viewer) + ->setLeases($leases) + ->render(); $lease_list->setNoDataString(pht('This resource has no leases.')); $pager = new AphrontPagerView(); @@ -48,7 +51,10 @@ final class DrydockResourceViewController extends DrydockResourceController { ->withResourceIDs(array($resource->getID())) ->executeWithOffsetPager($pager); - $log_table = $this->buildLogTableView($logs); + $log_table = id(new DrydockLogListView()) + ->setUser($viewer) + ->setLogs($logs) + ->render(); $log_table->appendChild($pager); $crumbs = $this->buildApplicationCrumbs(); diff --git a/src/applications/drydock/query/DrydockLeaseSearchEngine.php b/src/applications/drydock/query/DrydockLeaseSearchEngine.php index 9f4d8bf549..3b0e744873 100644 --- a/src/applications/drydock/query/DrydockLeaseSearchEngine.php +++ b/src/applications/drydock/query/DrydockLeaseSearchEngine.php @@ -3,6 +3,10 @@ final class DrydockLeaseSearchEngine extends PhabricatorApplicationSearchEngine { + public function getApplicationClassName() { + return 'PhabricatorApplicationDrydock'; + } + public function buildSavedQueryFromRequest(AphrontRequest $request) { $saved = new PhabricatorSavedQuery(); @@ -78,4 +82,15 @@ final class DrydockLeaseSearchEngine return parent::buildSavedQueryFromBuiltin($query_key); } + protected function renderResultList( + array $leases, + PhabricatorSavedQuery $saved, + array $handles) { + + return id(new DrydockLeaseListView()) + ->setUser($this->requireViewer()) + ->setLeases($leases) + ->render(); + } + } diff --git a/src/applications/drydock/query/DrydockLogSearchEngine.php b/src/applications/drydock/query/DrydockLogSearchEngine.php index c090ae52e9..69cd2a5c55 100644 --- a/src/applications/drydock/query/DrydockLogSearchEngine.php +++ b/src/applications/drydock/query/DrydockLogSearchEngine.php @@ -3,6 +3,10 @@ final class DrydockLogSearchEngine extends PhabricatorApplicationSearchEngine { + public function getApplicationClassName() { + return 'PhabricatorApplicationDrydock'; + } + public function buildSavedQueryFromRequest(AphrontRequest $request) { $saved = new PhabricatorSavedQuery(); @@ -45,4 +49,15 @@ final class DrydockLogSearchEngine return parent::buildSavedQueryFromBuiltin($query_key); } + protected function renderResultList( + array $logs, + PhabricatorSavedQuery $query, + array $handles) { + + return id(new DrydockLogListView()) + ->setUser($this->requireViewer()) + ->setLogs($logs) + ->render(); + } + } diff --git a/src/applications/drydock/query/DrydockResourceSearchEngine.php b/src/applications/drydock/query/DrydockResourceSearchEngine.php index 80a54212c9..3489bfa547 100644 --- a/src/applications/drydock/query/DrydockResourceSearchEngine.php +++ b/src/applications/drydock/query/DrydockResourceSearchEngine.php @@ -3,6 +3,10 @@ final class DrydockResourceSearchEngine extends PhabricatorApplicationSearchEngine { + public function getApplicationClassName() { + return 'PhabricatorApplicationDrydock'; + } + public function buildSavedQueryFromRequest(AphrontRequest $request) { $saved = new PhabricatorSavedQuery(); @@ -77,4 +81,15 @@ final class DrydockResourceSearchEngine return parent::buildSavedQueryFromBuiltin($query_key); } + protected function renderResultList( + array $resources, + PhabricatorSavedQuery $query, + array $handles) { + + return id(new DrydockResourceListView()) + ->setUser($this->requireViewer()) + ->setResources($resources) + ->render(); + } + } diff --git a/src/applications/drydock/view/DrydockLeaseListView.php b/src/applications/drydock/view/DrydockLeaseListView.php new file mode 100644 index 0000000000..dcafd59419 --- /dev/null +++ b/src/applications/drydock/view/DrydockLeaseListView.php @@ -0,0 +1,56 @@ +leases = $leases; + return $this; + } + + public function render() { + $leases = $this->leases; + $viewer = $this->getUser(); + + $view = new PHUIObjectItemListView(); + + foreach ($leases as $lease) { + $item = id(new PHUIObjectItemView()) + ->setUser($viewer) + ->setHeader($lease->getLeaseName()) + ->setHref('/drydock/lease/'.$lease->getID().'/'); + + if ($lease->hasAttachedResource()) { + $resource = $lease->getResource(); + + $resource_href = '/drydock/resource/'.$resource->getID().'/'; + $resource_name = $resource->getName(); + + $item->addAttribute( + phutil_tag( + 'a', + array( + 'href' => $resource_href, + ), + $resource_name)); + } + + $status = DrydockLeaseStatus::getNameForStatus($lease->getStatus()); + $item->addAttribute($status); + $item->setEpoch($lease->getDateCreated()); + + if ($lease->isActive()) { + $item->setBarColor('green'); + } else { + $item->setBarColor('red'); + } + + $view->addItem($item); + } + + return $view; + } + +} diff --git a/src/applications/drydock/view/DrydockLogListView.php b/src/applications/drydock/view/DrydockLogListView.php new file mode 100644 index 0000000000..aba883ed65 --- /dev/null +++ b/src/applications/drydock/view/DrydockLogListView.php @@ -0,0 +1,69 @@ +logs = $logs; + return $this; + } + + public function render() { + $logs = $this->logs; + $viewer = $this->getUser(); + + $view = new PHUIObjectItemListView(); + + $rows = array(); + foreach ($logs as $log) { + $resource_uri = '/drydock/resource/'.$log->getResourceID().'/'; + $lease_uri = '/drydock/lease/'.$log->getLeaseID().'/'; + + $rows[] = array( + phutil_tag( + 'a', + array( + 'href' => $resource_uri, + ), + $log->getResourceID()), + phutil_tag( + 'a', + array( + 'href' => $lease_uri, + ), + $log->getLeaseID()), + $log->getMessage(), + phabricator_date($log->getEpoch(), $viewer), + ); + } + + $table = new AphrontTableView($rows); + $table->setDeviceReadyTable(true); + $table->setHeaders( + array( + 'Resource', + 'Lease', + 'Message', + 'Date', + )); + $table->setShortHeaders( + array( + 'R', + 'L', + 'Message', + '', + )); + $table->setColumnClasses( + array( + '', + '', + 'wide', + '', + )); + + return $table; + } + +} diff --git a/src/applications/drydock/view/DrydockResourceListView.php b/src/applications/drydock/view/DrydockResourceListView.php new file mode 100644 index 0000000000..a0e32c2d3a --- /dev/null +++ b/src/applications/drydock/view/DrydockResourceListView.php @@ -0,0 +1,49 @@ +resources = $resources; + return $this; + } + + public function render() { + $resources = $this->resources; + $viewer = $this->getUser(); + + $view = new PHUIObjectItemListView(); + foreach ($resources as $resource) { + $name = pht('Resource %d', $resource->getID()).': '.$resource->getName(); + + $item = id(new PHUIObjectItemView()) + ->setHref('/drydock/resource/'.$resource->getID().'/') + ->setHeader($name); + + $status = DrydockResourceStatus::getNameForStatus($resource->getStatus()); + $item->addAttribute($status); + + switch ($resource->getStatus()) { + case DrydockResourceStatus::STATUS_PENDING: + $item->setBarColor('yellow'); + break; + case DrydockResourceStatus::STATUS_OPEN: + $item->setBarColor('green'); + break; + case DrydockResourceStatus::STATUS_DESTROYED: + $item->setBarColor('black'); + break; + default: + $item->setBarColor('red'); + break; + } + + $view->addItem($item); + } + + return $view; + } + +}