2012-11-20 22:25:22 +01:00
|
|
|
<?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();
|
|
|
|
|
|
|
|
$resource = id(new DrydockResource())->load($this->id);
|
|
|
|
if (!$resource) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$title = 'Resource '.$resource->getID().' '.$resource->getName();
|
|
|
|
|
2013-09-17 18:12:37 +02:00
|
|
|
$header = id(new PHUIHeaderView())
|
2012-11-20 22:25:22 +01:00
|
|
|
->setHeader($title);
|
|
|
|
|
|
|
|
$actions = $this->buildActionListView($resource);
|
2013-10-11 16:53:56 +02:00
|
|
|
$properties = $this->buildPropertyListView($resource, $actions);
|
2012-11-20 22:25:22 +01:00
|
|
|
|
|
|
|
$resource_uri = 'resource/'.$resource->getID().'/';
|
|
|
|
$resource_uri = $this->getApplicationURI($resource_uri);
|
|
|
|
|
2012-12-17 22:53:32 +01:00
|
|
|
$leases = id(new DrydockLeaseQuery())
|
2013-12-26 19:41:36 +01:00
|
|
|
->setViewer($user)
|
2012-12-17 22:53:32 +01:00
|
|
|
->withResourceIDs(array($resource->getID()))
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
$lease_list = $this->buildLeaseListView($leases);
|
|
|
|
$lease_list->setNoDataString(pht('This resource has no leases.'));
|
|
|
|
|
2012-11-20 22:25:22 +01:00
|
|
|
$pager = new AphrontPagerView();
|
|
|
|
$pager->setURI(new PhutilURI($resource_uri), 'offset');
|
|
|
|
$pager->setOffset($request->getInt('offset'));
|
|
|
|
|
|
|
|
$logs = id(new DrydockLogQuery())
|
2013-12-26 21:30:17 +01:00
|
|
|
->setViewer($user)
|
2012-11-20 22:25:22 +01:00
|
|
|
->withResourceIDs(array($resource->getID()))
|
|
|
|
->executeWithOffsetPager($pager);
|
|
|
|
|
|
|
|
$log_table = $this->buildLogTableView($logs);
|
|
|
|
$log_table->appendChild($pager);
|
|
|
|
|
2012-12-17 23:47:21 +01:00
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
2013-04-10 22:08:36 +02:00
|
|
|
$crumbs->setActionList($actions);
|
2013-12-19 02:47:34 +01:00
|
|
|
$crumbs->addTextCrumb(pht('Resource %d', $resource->getID()));
|
2012-12-17 23:47:21 +01:00
|
|
|
|
2013-09-29 00:55:38 +02:00
|
|
|
$object_box = id(new PHUIObjectBoxView())
|
|
|
|
->setHeader($header)
|
2013-10-11 16:53:56 +02:00
|
|
|
->addPropertyList($properties);
|
2013-09-29 00:55:38 +02:00
|
|
|
|
2012-12-17 23:47:21 +01:00
|
|
|
return $this->buildApplicationPage(
|
2012-11-20 22:25:22 +01:00
|
|
|
array(
|
2012-12-17 23:47:21 +01:00
|
|
|
$crumbs,
|
2013-09-29 00:55:38 +02:00
|
|
|
$object_box,
|
2012-12-17 22:53:32 +01:00
|
|
|
$lease_list,
|
2012-11-20 22:25:22 +01:00
|
|
|
$log_table,
|
2012-12-17 23:47:21 +01:00
|
|
|
),
|
2012-11-20 22:25:22 +01:00
|
|
|
array(
|
|
|
|
'device' => true,
|
|
|
|
'title' => $title,
|
|
|
|
));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private function buildActionListView(DrydockResource $resource) {
|
|
|
|
$view = id(new PhabricatorActionListView())
|
|
|
|
->setUser($this->getRequest()->getUser())
|
2013-07-12 20:39:47 +02:00
|
|
|
->setObjectURI($this->getRequest()->getRequestURI())
|
2012-11-20 22:25:22 +01:00
|
|
|
->setObject($resource);
|
|
|
|
|
2012-11-27 21:48:03 +01:00
|
|
|
$can_close = ($resource->getStatus() == DrydockResourceStatus::STATUS_OPEN);
|
|
|
|
$uri = '/resource/'.$resource->getID().'/close/';
|
|
|
|
$uri = $this->getApplicationURI($uri);
|
|
|
|
|
|
|
|
$view->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setHref($uri)
|
|
|
|
->setName(pht('Close Resource'))
|
|
|
|
->setIcon('delete')
|
|
|
|
->setWorkflow(true)
|
|
|
|
->setDisabled(!$can_close));
|
|
|
|
|
2012-11-20 22:25:22 +01:00
|
|
|
return $view;
|
|
|
|
}
|
|
|
|
|
2013-10-11 16:53:56 +02:00
|
|
|
private function buildPropertyListView(
|
|
|
|
DrydockResource $resource,
|
|
|
|
PhabricatorActionListView $actions) {
|
|
|
|
|
|
|
|
$view = new PHUIPropertyListView();
|
|
|
|
$view->setActionList($actions);
|
2012-11-20 22:25:22 +01:00
|
|
|
|
|
|
|
$status = $resource->getStatus();
|
|
|
|
$status = DrydockResourceStatus::getNameForStatus($status);
|
|
|
|
|
|
|
|
$view->addProperty(
|
|
|
|
pht('Status'),
|
|
|
|
$status);
|
|
|
|
|
|
|
|
$view->addProperty(
|
|
|
|
pht('Resource Type'),
|
2013-01-29 20:01:47 +01:00
|
|
|
$resource->getType());
|
2012-11-20 22:25:22 +01:00
|
|
|
|
2013-12-03 01:09:07 +01:00
|
|
|
// TODO: Load handle.
|
|
|
|
$view->addProperty(
|
|
|
|
pht('Blueprint'),
|
|
|
|
$resource->getBlueprintPHID());
|
|
|
|
|
2012-12-12 16:36:53 +01:00
|
|
|
$attributes = $resource->getAttributes();
|
|
|
|
if ($attributes) {
|
|
|
|
$view->addSectionHeader(pht('Attributes'));
|
|
|
|
foreach ($attributes as $key => $value) {
|
2013-01-29 20:01:47 +01:00
|
|
|
$view->addProperty($key, $value);
|
2012-12-12 16:36:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-20 22:25:22 +01:00
|
|
|
return $view;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|