diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 73688f1c07..e3f6dd753e 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -424,6 +424,7 @@ phutil_register_library_map(array( 'DrydockLease' => 'applications/drydock/storage/DrydockLease.php', 'DrydockLeaseListController' => 'applications/drydock/controller/DrydockLeaseListController.php', 'DrydockLeaseStatus' => 'applications/drydock/constants/DrydockLeaseStatus.php', + 'DrydockLeaseViewController' => 'applications/drydock/controller/DrydockLeaseViewController.php', 'DrydockLocalCommandInterface' => 'applications/drydock/interface/command/DrydockLocalCommandInterface.php', 'DrydockLocalHostBlueprint' => 'applications/drydock/blueprint/DrydockLocalHostBlueprint.php', 'DrydockLog' => 'applications/drydock/storage/DrydockLog.php', @@ -1657,6 +1658,7 @@ phutil_register_library_map(array( 'DrydockLease' => 'DrydockDAO', 'DrydockLeaseListController' => 'DrydockController', 'DrydockLeaseStatus' => 'DrydockConstants', + 'DrydockLeaseViewController' => 'DrydockController', 'DrydockLocalCommandInterface' => 'DrydockCommandInterface', 'DrydockLocalHostBlueprint' => 'DrydockBlueprint', 'DrydockLog' => 'DrydockDAO', diff --git a/src/applications/drydock/application/PhabricatorApplicationDrydock.php b/src/applications/drydock/application/PhabricatorApplicationDrydock.php index bc65e9deed..ea4af89f4a 100644 --- a/src/applications/drydock/application/PhabricatorApplicationDrydock.php +++ b/src/applications/drydock/application/PhabricatorApplicationDrydock.php @@ -32,7 +32,10 @@ final class PhabricatorApplicationDrydock extends PhabricatorApplication { '' => 'DrydockResourceListController', 'resource/' => 'DrydockResourceListController', 'resource/allocate/' => 'DrydockResourceAllocateController', - 'lease/' => 'DrydockLeaseListController', + 'lease/' => array( + '' => 'DrydockLeaseListController', + '(?P[1-9]\d*)/' => 'DrydockLeaseViewController', + ), 'log/' => 'DrydockLogController', ), ); diff --git a/src/applications/drydock/controller/DrydockController.php b/src/applications/drydock/controller/DrydockController.php index 957e438cfb..edd34a71a7 100644 --- a/src/applications/drydock/controller/DrydockController.php +++ b/src/applications/drydock/controller/DrydockController.php @@ -30,4 +30,44 @@ abstract class DrydockController extends PhabricatorController { return $nav; } + protected function buildLogTableView(array $logs) { + assert_instances_of($logs, 'DrydockLog'); + + $user = $this->getRequest()->getUser(); + + // TODO: It's probably a stretch to claim this works on mobile. + + $rows = array(); + foreach ($logs as $log) { + $rows[] = array( + $log->getResourceID(), + $log->getLeaseID(), + phutil_escape_html($log->getMessage()), + phabricator_datetime($log->getEpoch(), $user), + ); + } + + $table = new AphrontTableView($rows); + $table->setHeaders( + array( + 'Resource', + 'Lease', + 'Message', + 'Date', + )); + $table->setColumnClasses( + array( + '', + '', + 'wide', + '', + )); + + $panel = new AphrontPanelView(); + $panel->setHeader('Logs'); + $panel->appendChild($table); + + return $panel; + } + } diff --git a/src/applications/drydock/controller/DrydockLeaseListController.php b/src/applications/drydock/controller/DrydockLeaseListController.php index 19413edf0a..7ba868ca7f 100644 --- a/src/applications/drydock/controller/DrydockLeaseListController.php +++ b/src/applications/drydock/controller/DrydockLeaseListController.php @@ -9,7 +9,8 @@ final class DrydockLeaseListController extends DrydockController { $nav = $this->buildSideNav('lease'); $pager = new AphrontPagerView(); - $pager->setURI(new PhutilURI('/drydock/lease/'), 'page'); + $pager->setURI(new PhutilURI('/drydock/lease/'), 'offset'); + $pager->setOffset($request->getInt('offset')); $data = id(new DrydockLease())->loadAllWhere( '1 = 1 ORDER BY id DESC LIMIT %d, %d', @@ -32,8 +33,14 @@ final class DrydockLeaseListController extends DrydockController { foreach ($data as $lease) { $resource = idx($resources, $lease->getResourceID()); $rows[] = array( - $lease->getID(), + phutil_render_tag( + 'a', + array( + 'href' => $this->getApplicationURI('/lease/'.$lease->getID().'/'), + ), + $lease->getID()), DrydockLeaseStatus::getNameForStatus($lease->getStatus()), + phutil_escape_html($lease->getResourceType()), ($lease->getOwnerPHID() ? $handles[$lease->getOwnerPHID()]->renderLink() : null), @@ -50,8 +57,9 @@ final class DrydockLeaseListController extends DrydockController { array( 'ID', 'Status', - 'Owner', + 'Resource Type', 'Resource ID', + 'Owner', 'Resource', 'Created', )); @@ -61,6 +69,7 @@ final class DrydockLeaseListController extends DrydockController { '', '', '', + '', 'wide pri', 'right', )); @@ -75,7 +84,8 @@ final class DrydockLeaseListController extends DrydockController { return $this->buildStandardPageResponse( $nav, array( - 'title' => 'Leases', + 'device' => true, + 'title' => 'Leases', )); } diff --git a/src/applications/drydock/controller/DrydockLeaseViewController.php b/src/applications/drydock/controller/DrydockLeaseViewController.php new file mode 100644 index 0000000000..15f432fa3e --- /dev/null +++ b/src/applications/drydock/controller/DrydockLeaseViewController.php @@ -0,0 +1,123 @@ +id = $data['id']; + } + + public function processRequest() { + $request = $this->getRequest(); + $user = $request->getUser(); + + $nav = $this->buildSideNav('lease'); + + $lease = id(new DrydockLease())->load($this->id); + if (!$lease) { + return new Aphront404Response(); + } + + $title = 'Lease '.$lease->getID(); + + $header = id(new PhabricatorHeaderView()) + ->setHeader($title); + + $actions = $this->buildActionListView($lease); + $properties = $this->buildPropertyListView($lease); + + $pager = new AphrontPagerView(); + $pager->setURI( + new PhutilURI($this->getApplicationURI('lease/'.$lease->getID().'/')), + 'offset'); + $pager->setOffset($request->getInt('offset')); + + $logs = id(new DrydockLogQuery()) + ->withLeaseIDs(array($lease->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(DrydockLease $lease) { + $view = id(new PhabricatorActionListView()) + ->setUser($this->getRequest()->getUser()) + ->setObject($lease); + + return $view; + } + + private function buildPropertyListView(DrydockLease $lease) { + $view = new PhabricatorPropertyListView(); + + switch ($lease->getStatus()) { + case DrydockLeaseStatus::STATUS_ACTIVE: + $status = pht('Active'); + break; + case DrydockLeaseStatus::STATUS_RELEASED: + $status = pht('Released'); + break; + case DrydockLeaseStatus::STATUS_EXPIRED: + $status = pht('Expired'); + break; + case DrydockLeaseStatus::STATUS_PENDING: + $status = pht('Pending'); + break; + case DrydockLeaseStatus::STATUS_BROKEN: + $status = pht('Broken'); + break; + default: + $status = pht('Unknown'); + break; + } + + $view->addProperty( + pht('Status'), + $status); + + $view->addProperty( + pht('Resource Type'), + phutil_escape_html($lease->getResourceType())); + + $view->addProperty( + pht('Resource'), + phutil_escape_html($lease->getResourceID())); + + return $view; + } + +} diff --git a/src/applications/drydock/controller/DrydockLogController.php b/src/applications/drydock/controller/DrydockLogController.php index d19181245d..c8c77e52d9 100644 --- a/src/applications/drydock/controller/DrydockLogController.php +++ b/src/applications/drydock/controller/DrydockLogController.php @@ -27,38 +27,10 @@ final class DrydockLogController extends DrydockController { $logs = $query->executeWithOffsetPager($pager); - $rows = array(); - foreach ($logs as $log) { - $rows[] = array( - $log->getResourceID(), - $log->getLeaseID(), - phutil_escape_html($log->getMessage()), - phabricator_datetime($log->getEpoch(), $user), - ); - } + $table = $this->buildLogTableView($logs); + $table->appendChild($pager); - $table = new AphrontTableView($rows); - $table->setHeaders( - array( - 'Resource', - 'Lease', - 'Message', - 'Date', - )); - $table->setColumnClasses( - array( - '', - '', - 'wide', - '', - )); - - $panel = new AphrontPanelView(); - $panel->setHeader('Drydock Logs'); - $panel->appendChild($table); - $panel->appendChild($pager); - - $nav->appendChild($panel); + $nav->appendChild($table); return $this->buildStandardPageResponse( $nav,