From b2bf634795e19596da7ea84442402ea12cf9bef5 Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 20 Nov 2012 13:25:22 -0800 Subject: [PATCH] Add a detail view for resources in Drydock Summary: Nothing fancy here, just add a detail page. Test Plan: Looked at detail page. {F24808} Reviewers: btrahan Reviewed By: btrahan CC: aran, vrana Maniphest Tasks: T2015 Differential Revision: https://secure.phabricator.com/D3995 --- src/__phutil_library_map__.php | 2 + .../PhabricatorApplicationDrydock.php | 5 +- .../drydock/controller/DrydockController.php | 20 ++++- .../controller/DrydockLeaseListController.php | 26 +++--- .../DrydockResourceListController.php | 18 ++-- .../DrydockResourceViewController.php | 87 +++++++++++++++++++ 6 files changed, 135 insertions(+), 23 deletions(-) create mode 100644 src/applications/drydock/controller/DrydockResourceViewController.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index c718cdf7c3..8dc76976b5 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -437,6 +437,7 @@ phutil_register_library_map(array( 'DrydockResource' => 'applications/drydock/storage/DrydockResource.php', 'DrydockResourceListController' => 'applications/drydock/controller/DrydockResourceListController.php', 'DrydockResourceStatus' => 'applications/drydock/constants/DrydockResourceStatus.php', + 'DrydockResourceViewController' => 'applications/drydock/controller/DrydockResourceViewController.php', 'DrydockSSHCommandInterface' => 'applications/drydock/interface/command/DrydockSSHCommandInterface.php', 'DrydockWebrootInterface' => 'applications/drydock/interface/webroot/DrydockWebrootInterface.php', 'FeedPublisherWorker' => 'applications/feed/worker/FeedPublisherWorker.php', @@ -1667,6 +1668,7 @@ phutil_register_library_map(array( 'DrydockResource' => 'DrydockDAO', 'DrydockResourceListController' => 'DrydockController', 'DrydockResourceStatus' => 'DrydockConstants', + 'DrydockResourceViewController' => 'DrydockController', 'DrydockSSHCommandInterface' => 'DrydockCommandInterface', 'DrydockWebrootInterface' => 'DrydockInterface', 'FeedPublisherWorker' => 'PhabricatorWorker', diff --git a/src/applications/drydock/application/PhabricatorApplicationDrydock.php b/src/applications/drydock/application/PhabricatorApplicationDrydock.php index 9b7d282ae1..3a3198cfd4 100644 --- a/src/applications/drydock/application/PhabricatorApplicationDrydock.php +++ b/src/applications/drydock/application/PhabricatorApplicationDrydock.php @@ -30,7 +30,10 @@ final class PhabricatorApplicationDrydock extends PhabricatorApplication { return array( '/drydock/' => array( '' => 'DrydockResourceListController', - 'resource/' => 'DrydockResourceListController', + 'resource/' => array( + '' => 'DrydockResourceListController', + '(?P[1-9]\d*)/' => 'DrydockResourceViewController', + ), 'lease/' => array( '' => 'DrydockLeaseListController', '(?P[1-9]\d*)/' => 'DrydockLeaseViewController', diff --git a/src/applications/drydock/controller/DrydockController.php b/src/applications/drydock/controller/DrydockController.php index edd34a71a7..103be607af 100644 --- a/src/applications/drydock/controller/DrydockController.php +++ b/src/applications/drydock/controller/DrydockController.php @@ -39,9 +39,25 @@ abstract class DrydockController extends PhabricatorController { $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( - $log->getResourceID(), - $log->getLeaseID(), + phutil_render_tag( + 'a', + array( + 'href' => $resource_uri, + ), + phutil_escape_html($log->getResourceID())), + phutil_render_tag( + 'a', + array( + 'href' => $lease_uri, + ), + phutil_escape_html($log->getLeaseID())), phutil_escape_html($log->getMessage()), phabricator_datetime($log->getEpoch(), $user), ); diff --git a/src/applications/drydock/controller/DrydockLeaseListController.php b/src/applications/drydock/controller/DrydockLeaseListController.php index 7ba868ca7f..f43d1d5716 100644 --- a/src/applications/drydock/controller/DrydockLeaseListController.php +++ b/src/applications/drydock/controller/DrydockLeaseListController.php @@ -18,9 +18,6 @@ final class DrydockLeaseListController extends DrydockController { $pager->getPageSize() + 1); $data = $pager->sliceResults($data); - $phids = mpull($data, 'getOwnerPHID'); - $handles = $this->loadViewerHandles($phids); - $resource_ids = mpull($data, 'getResourceID'); $resources = array(); if ($resource_ids) { @@ -32,19 +29,28 @@ final class DrydockLeaseListController extends DrydockController { $rows = array(); foreach ($data as $lease) { $resource = idx($resources, $lease->getResourceID()); + + $lease_uri = '/lease/'.$lease->getID().'/'; + $lease_uri = $this->getApplicationURI($lease_uri); + + $resource_uri = '/resource/'.$lease->getResourceID().'/'; + $resource_uri = $this->getApplicationURI($resource_uri); + $rows[] = array( phutil_render_tag( 'a', array( - 'href' => $this->getApplicationURI('/lease/'.$lease->getID().'/'), + 'href' => $lease_uri, ), $lease->getID()), + phutil_render_tag( + 'a', + array( + 'href' => $resource_uri, + ), + $lease->getResourceID()), DrydockLeaseStatus::getNameForStatus($lease->getStatus()), phutil_escape_html($lease->getResourceType()), - ($lease->getOwnerPHID() - ? $handles[$lease->getOwnerPHID()]->renderLink() - : null), - $lease->getResourceID(), ($resource ? phutil_escape_html($resource->getName()) : null), @@ -56,10 +62,9 @@ final class DrydockLeaseListController extends DrydockController { $table->setHeaders( array( 'ID', + 'Resource ID', 'Status', 'Resource Type', - 'Resource ID', - 'Owner', 'Resource', 'Created', )); @@ -69,7 +74,6 @@ final class DrydockLeaseListController extends DrydockController { '', '', '', - '', 'wide pri', 'right', )); diff --git a/src/applications/drydock/controller/DrydockResourceListController.php b/src/applications/drydock/controller/DrydockResourceListController.php index ac05cb12f9..8ca1e5c1fb 100644 --- a/src/applications/drydock/controller/DrydockResourceListController.php +++ b/src/applications/drydock/controller/DrydockResourceListController.php @@ -17,16 +17,18 @@ final class DrydockResourceListController extends DrydockController { $pager->getPageSize() + 1); $data = $pager->sliceResults($data); - $phids = mpull($data, 'getOwnerPHID'); - $handles = $this->loadViewerHandles($phids); - $rows = array(); foreach ($data as $resource) { + $resource_uri = '/resource/'.$resource->getID().'/'; + $resource_uri = $this->getApplicationURI($resource_uri); + $rows[] = array( - $resource->getID(), - ($resource->getOwnerPHID() - ? $handles[$resource->getOwnerPHID()]->renderLink() - : null), + phutil_render_tag( + 'a', + array( + 'href' => $resource_uri, + ), + $resource->getID()), phutil_escape_html($resource->getType()), DrydockResourceStatus::getNameForStatus($resource->getStatus()), phutil_escape_html(nonempty($resource->getName(), 'Unnamed')), @@ -38,7 +40,6 @@ final class DrydockResourceListController extends DrydockController { $table->setHeaders( array( 'ID', - 'Owner', 'Type', 'Status', 'Resource', @@ -49,7 +50,6 @@ final class DrydockResourceListController extends DrydockController { '', '', '', - '', 'pri wide', 'right', )); diff --git a/src/applications/drydock/controller/DrydockResourceViewController.php b/src/applications/drydock/controller/DrydockResourceViewController.php new file mode 100644 index 0000000000..3a1bbf0552 --- /dev/null +++ b/src/applications/drydock/controller/DrydockResourceViewController.php @@ -0,0 +1,87 @@ +id = $data['id']; + } + + public function processRequest() { + $request = $this->getRequest(); + $user = $request->getUser(); + + $nav = $this->buildSideNav('resource'); + + $resource = id(new DrydockResource())->load($this->id); + if (!$resource) { + return new Aphront404Response(); + } + + $title = 'Resource '.$resource->getID().' '.$resource->getName(); + + $header = id(new PhabricatorHeaderView()) + ->setHeader($title); + + $actions = $this->buildActionListView($resource); + $properties = $this->buildPropertyListView($resource); + + $resource_uri = 'resource/'.$resource->getID().'/'; + $resource_uri = $this->getApplicationURI($resource_uri); + + $pager = new AphrontPagerView(); + $pager->setURI(new PhutilURI($resource_uri), 'offset'); + $pager->setOffset($request->getInt('offset')); + + $logs = id(new DrydockLogQuery()) + ->withResourceIDs(array($resource->getID())) + ->executeWithOffsetPager($pager); + + $log_table = $this->buildLogTableView($logs); + $log_table->appendChild($pager); + + $nav->appendChild( + array( + $header, + $actions, + $properties, + $log_table, + )); + + return $this->buildApplicationPage( + $nav, + array( + 'device' => true, + 'title' => $title, + )); + + } + + private function buildActionListView(DrydockResource $resource) { + $view = id(new PhabricatorActionListView()) + ->setUser($this->getRequest()->getUser()) + ->setObject($resource); + + return $view; + } + + private function buildPropertyListView(DrydockResource $resource) { + $view = new PhabricatorPropertyListView(); + + $status = $resource->getStatus(); + $status = DrydockResourceStatus::getNameForStatus($status); + $status = phutil_escape_html($status); + + $view->addProperty( + pht('Status'), + $status); + + $view->addProperty( + pht('Resource Type'), + phutil_escape_html($resource->getType())); + + return $view; + } + +}