1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 05:50:55 +01:00

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
This commit is contained in:
epriestley 2012-11-20 13:25:22 -08:00
parent 27626e6d47
commit b2bf634795
6 changed files with 135 additions and 23 deletions

View file

@ -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',

View file

@ -30,7 +30,10 @@ final class PhabricatorApplicationDrydock extends PhabricatorApplication {
return array(
'/drydock/' => array(
'' => 'DrydockResourceListController',
'resource/' => 'DrydockResourceListController',
'resource/' => array(
'' => 'DrydockResourceListController',
'(?P<id>[1-9]\d*)/' => 'DrydockResourceViewController',
),
'lease/' => array(
'' => 'DrydockLeaseListController',
'(?P<id>[1-9]\d*)/' => 'DrydockLeaseViewController',

View file

@ -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),
);

View file

@ -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',
));

View file

@ -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',
));

View file

@ -0,0 +1,87 @@
<?php
final class DrydockResourceViewController extends DrydockController {
private $id;
public function willProcessRequest(array $data) {
$this->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;
}
}