From 9c9a9a919e7a7949ea375cd0a78e9dac9e349c94 Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 26 Dec 2013 12:30:29 -0800 Subject: [PATCH] Use ApplicationSearch for DrydockLog Summary: Ref T2015. Move logs over to ApplicationSearch. Test Plan: Browsed logs in UI. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T2015 Differential Revision: https://secure.phabricator.com/D7832 --- src/__phutil_library_map__.php | 18 ++++-- .../PhabricatorApplicationDrydock.php | 4 +- .../drydock/controller/DrydockController.php | 5 +- .../controller/DrydockLogController.php | 59 ------------------- .../controller/DrydockLogListController.php | 34 +++++++++++ .../drydock/query/DrydockLogSearchEngine.php | 48 +++++++++++++++ 6 files changed, 102 insertions(+), 66 deletions(-) delete mode 100644 src/applications/drydock/controller/DrydockLogController.php create mode 100644 src/applications/drydock/controller/DrydockLogListController.php create mode 100644 src/applications/drydock/query/DrydockLogSearchEngine.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index f3ee3cf6c0..8913843fac 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -660,8 +660,9 @@ phutil_register_library_map(array( 'DrydockLocalCommandInterface' => 'applications/drydock/interface/command/DrydockLocalCommandInterface.php', 'DrydockLocalHostBlueprintImplementation' => 'applications/drydock/blueprint/DrydockLocalHostBlueprintImplementation.php', 'DrydockLog' => 'applications/drydock/storage/DrydockLog.php', - 'DrydockLogController' => 'applications/drydock/controller/DrydockLogController.php', + 'DrydockLogListController' => 'applications/drydock/controller/DrydockLogListController.php', 'DrydockLogQuery' => 'applications/drydock/query/DrydockLogQuery.php', + 'DrydockLogSearchEngine' => 'applications/drydock/query/DrydockLogSearchEngine.php', 'DrydockManagementCloseWorkflow' => 'applications/drydock/management/DrydockManagementCloseWorkflow.php', 'DrydockManagementCreateResourceWorkflow' => 'applications/drydock/management/DrydockManagementCreateResourceWorkflow.php', 'DrydockManagementLeaseWorkflow' => 'applications/drydock/management/DrydockManagementLeaseWorkflow.php', @@ -3073,9 +3074,18 @@ phutil_register_library_map(array( 'DrydockLeaseViewController' => 'DrydockController', 'DrydockLocalCommandInterface' => 'DrydockCommandInterface', 'DrydockLocalHostBlueprintImplementation' => 'DrydockBlueprintImplementation', - 'DrydockLog' => 'DrydockDAO', - 'DrydockLogController' => 'DrydockController', - 'DrydockLogQuery' => 'PhabricatorOffsetPagedQuery', + 'DrydockLog' => + array( + 0 => 'DrydockDAO', + 1 => 'PhabricatorPolicyInterface', + ), + 'DrydockLogListController' => + array( + 0 => 'DrydockController', + 1 => 'PhabricatorApplicationSearchResultsControllerInterface', + ), + 'DrydockLogQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', + 'DrydockLogSearchEngine' => 'PhabricatorApplicationSearchEngine', 'DrydockManagementCloseWorkflow' => 'DrydockManagementWorkflow', 'DrydockManagementCreateResourceWorkflow' => 'DrydockManagementWorkflow', 'DrydockManagementLeaseWorkflow' => 'DrydockManagementWorkflow', diff --git a/src/applications/drydock/application/PhabricatorApplicationDrydock.php b/src/applications/drydock/application/PhabricatorApplicationDrydock.php index 6b7df2c03d..172038d75a 100644 --- a/src/applications/drydock/application/PhabricatorApplicationDrydock.php +++ b/src/applications/drydock/application/PhabricatorApplicationDrydock.php @@ -50,7 +50,9 @@ final class PhabricatorApplicationDrydock extends PhabricatorApplication { '(?P[1-9]\d*)/' => 'DrydockLeaseViewController', '(?P[1-9]\d*)/release/' => 'DrydockLeaseReleaseController', ), - 'log/' => 'DrydockLogController', + 'log/' => array( + '(?:query/(?P[^/]+)/)?' => 'DrydockLogListController', + ), ), ); } diff --git a/src/applications/drydock/controller/DrydockController.php b/src/applications/drydock/controller/DrydockController.php index c36251890d..aade76c710 100644 --- a/src/applications/drydock/controller/DrydockController.php +++ b/src/applications/drydock/controller/DrydockController.php @@ -18,8 +18,9 @@ abstract class DrydockController extends PhabricatorController { ->setViewer($this->getRequest()->getUser()) ->addNavigationItems($nav->getMenu(), pht('Resources')); - $nav->addLabel(pht('Logs')); - $nav->addFilter('log', 'Logs'); + id(new DrydockLogSearchEngine()) + ->setViewer($this->getRequest()->getUser()) + ->addNavigationItems($nav->getMenu(), pht('Logs')); $nav->selectFilter($selected, 'resource'); diff --git a/src/applications/drydock/controller/DrydockLogController.php b/src/applications/drydock/controller/DrydockLogController.php deleted file mode 100644 index f17bfa816e..0000000000 --- a/src/applications/drydock/controller/DrydockLogController.php +++ /dev/null @@ -1,59 +0,0 @@ -getRequest(); - $user = $request->getUser(); - - $nav = $this->buildSideNav('log'); - - $query = id(new DrydockLogQuery()) - ->setViewer($user); - - $resource_ids = $request->getStrList('resource'); - if ($resource_ids) { - $query->withResourceIDs($resource_ids); - } - - $lease_ids = $request->getStrList('lease'); - if ($lease_ids) { - $query->withLeaseIDs($lease_ids); - } - - $pager = new AphrontPagerView(); - $pager->setPageSize(500); - $pager->setOffset($request->getInt('offset')); - $pager->setURI($request->getRequestURI(), 'offset'); - - $logs = $query->executeWithOffsetPager($pager); - - $title = pht('Logs'); - - $header = id(new PHUIHeaderView()) - ->setHeader($title); - - $table = $this->buildLogTableView($logs); - $table->appendChild($pager); - - $nav->appendChild( - array( - $header, - $table, - $pager, - )); - - $crumbs = $this->buildApplicationCrumbs(); - $crumbs->addTextCrumb($title, $this->getApplicationURI('/logs/')); - $nav->setCrumbs($crumbs); - - return $this->buildApplicationPage( - $nav, - array( - 'title' => $title, - 'device' => true, - )); - - } - -} diff --git a/src/applications/drydock/controller/DrydockLogListController.php b/src/applications/drydock/controller/DrydockLogListController.php new file mode 100644 index 0000000000..cd06e5a753 --- /dev/null +++ b/src/applications/drydock/controller/DrydockLogListController.php @@ -0,0 +1,34 @@ +queryKey = idx($data, 'queryKey'); + } + + public function processRequest() { + $request = $this->getRequest(); + $controller = id(new PhabricatorApplicationSearchController($request)) + ->setQueryKey($this->queryKey) + ->setSearchEngine(new DrydockLogSearchEngine()) + ->setNavigation($this->buildSideNav()); + + return $this->delegateToController($controller); + } + + public function renderResultsList( + array $logs, + PhabricatorSavedQuery $query) { + assert_instances_of($logs, 'DrydockLog'); + + return $this->buildLogTableView($logs); + } + +} diff --git a/src/applications/drydock/query/DrydockLogSearchEngine.php b/src/applications/drydock/query/DrydockLogSearchEngine.php new file mode 100644 index 0000000000..c090ae52e9 --- /dev/null +++ b/src/applications/drydock/query/DrydockLogSearchEngine.php @@ -0,0 +1,48 @@ + pht('All Logs'), + ); + + return $names; + } + + public function buildSavedQueryFromBuiltin($query_key) { + $query = $this->newSavedQuery(); + $query->setQueryKey($query_key); + + switch ($query_key) { + case 'all': + return $query; + } + + return parent::buildSavedQueryFromBuiltin($query_key); + } + +}