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();
|
|
|
|
|
|
|
|
$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);
|
|
|
|
|
2012-12-17 22:53:32 +01:00
|
|
|
$leases = id(new DrydockLeaseQuery())
|
|
|
|
->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())
|
|
|
|
->withResourceIDs(array($resource->getID()))
|
|
|
|
->executeWithOffsetPager($pager);
|
|
|
|
|
|
|
|
$log_table = $this->buildLogTableView($logs);
|
|
|
|
$log_table->appendChild($pager);
|
|
|
|
|
|
|
|
$nav->appendChild(
|
|
|
|
array(
|
|
|
|
$header,
|
|
|
|
$actions,
|
|
|
|
$properties,
|
2012-12-17 22:53:32 +01:00
|
|
|
$lease_list,
|
2012-11-20 22:25:22 +01:00
|
|
|
$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);
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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()));
|
|
|
|
|
2012-12-12 16:36:53 +01:00
|
|
|
$attributes = $resource->getAttributes();
|
|
|
|
if ($attributes) {
|
|
|
|
$view->addSectionHeader(pht('Attributes'));
|
|
|
|
foreach ($attributes as $key => $value) {
|
|
|
|
$view->addProperty(
|
|
|
|
phutil_escape_html($key),
|
|
|
|
phutil_escape_html($value));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-20 22:25:22 +01:00
|
|
|
return $view;
|
|
|
|
}
|
|
|
|
|
2012-12-17 22:53:32 +01:00
|
|
|
private function buildLeaseListView(array $leases) {
|
|
|
|
assert_instances_of($leases, 'DrydockLease');
|
|
|
|
|
|
|
|
$user = $this->getRequest()->getUser();
|
|
|
|
|
|
|
|
$view = new PhabricatorObjectItemListView();
|
|
|
|
|
|
|
|
foreach ($leases as $lease) {
|
|
|
|
$item = id(new PhabricatorObjectItemView())
|
|
|
|
->setHeader($lease->getLeaseName())
|
|
|
|
->setHref($this->getApplicationURI('/lease/'.$lease->getID().'/'));
|
|
|
|
|
|
|
|
$status = DrydockLeaseStatus::getNameForStatus($lease->getStatus());
|
|
|
|
$item->addAttribute(phutil_escape_html($status));
|
|
|
|
|
|
|
|
$date_created = phabricator_date($lease->getDateCreated(), $user);
|
|
|
|
$item->addAttribute(pht('Created on %s', $date_created));
|
|
|
|
|
|
|
|
if ($lease->isActive()) {
|
|
|
|
$item->setBarColor('green');
|
|
|
|
} else {
|
|
|
|
$item->setBarColor('red');
|
|
|
|
}
|
|
|
|
|
|
|
|
$view->addItem($item);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $view;
|
|
|
|
}
|
|
|
|
|
2012-11-20 22:25:22 +01:00
|
|
|
}
|