2012-11-07 00:28:33 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class DrydockLeaseViewController extends DrydockController {
|
|
|
|
|
|
|
|
private $id;
|
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->id = $data['id'];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
|
|
|
$lease = id(new DrydockLease())->load($this->id);
|
|
|
|
if (!$lease) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
2012-12-17 23:47:21 +01:00
|
|
|
$lease_uri = $this->getApplicationURI('lease/'.$lease->getID().'/');
|
|
|
|
|
|
|
|
$title = pht('Lease %d', $lease->getID());
|
2012-11-07 00:28:33 +01:00
|
|
|
|
2013-09-17 18:12:37 +02:00
|
|
|
$header = id(new PHUIHeaderView())
|
2012-11-07 00:28:33 +01:00
|
|
|
->setHeader($title);
|
|
|
|
|
|
|
|
$actions = $this->buildActionListView($lease);
|
|
|
|
$properties = $this->buildPropertyListView($lease);
|
|
|
|
|
|
|
|
$pager = new AphrontPagerView();
|
2012-12-17 23:47:21 +01:00
|
|
|
$pager->setURI(new PhutilURI($lease_uri), 'offset');
|
2012-11-07 00:28:33 +01:00
|
|
|
$pager->setOffset($request->getInt('offset'));
|
|
|
|
|
|
|
|
$logs = id(new DrydockLogQuery())
|
|
|
|
->withLeaseIDs(array($lease->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);
|
2012-12-17 23:47:21 +01:00
|
|
|
$crumbs->addCrumb(
|
|
|
|
id(new PhabricatorCrumbView())
|
|
|
|
->setName($title)
|
|
|
|
->setHref($lease_uri));
|
|
|
|
|
2013-09-29 00:55:38 +02:00
|
|
|
$object_box = id(new PHUIObjectBoxView())
|
|
|
|
->setHeader($header)
|
|
|
|
->addContent($actions)
|
|
|
|
->addContent($properties);
|
|
|
|
|
2012-12-17 23:47:21 +01:00
|
|
|
return $this->buildApplicationPage(
|
2012-11-07 00:28:33 +01:00
|
|
|
array(
|
2012-12-17 23:47:21 +01:00
|
|
|
$crumbs,
|
2013-09-29 00:55:38 +02:00
|
|
|
$object_box,
|
2012-11-07 00:28:33 +01:00
|
|
|
$log_table,
|
2012-12-17 23:47:21 +01:00
|
|
|
),
|
2012-11-07 00:28:33 +01:00
|
|
|
array(
|
|
|
|
'device' => true,
|
|
|
|
'title' => $title,
|
|
|
|
));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private function buildActionListView(DrydockLease $lease) {
|
|
|
|
$view = id(new PhabricatorActionListView())
|
|
|
|
->setUser($this->getRequest()->getUser())
|
2013-07-12 20:39:47 +02:00
|
|
|
->setObjectURI($this->getRequest()->getRequestURI())
|
2012-11-07 00:28:33 +01:00
|
|
|
->setObject($lease);
|
|
|
|
|
2012-12-15 00:42:58 +01:00
|
|
|
$id = $lease->getID();
|
|
|
|
|
|
|
|
$can_release = ($lease->getStatus() == DrydockLeaseStatus::STATUS_ACTIVE);
|
|
|
|
|
|
|
|
$view->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setName(pht('Release Lease'))
|
|
|
|
->setIcon('delete')
|
|
|
|
->setHref($this->getApplicationURI("/lease/{$id}/release/"))
|
|
|
|
->setWorkflow(true)
|
|
|
|
->setDisabled(!$can_release));
|
|
|
|
|
2012-11-07 00:28:33 +01:00
|
|
|
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'),
|
2013-01-29 20:01:47 +01:00
|
|
|
$lease->getResourceType());
|
2012-11-07 00:28:33 +01:00
|
|
|
|
|
|
|
$view->addProperty(
|
|
|
|
pht('Resource'),
|
2013-01-29 20:01:47 +01:00
|
|
|
$lease->getResourceID());
|
2012-11-07 00:28:33 +01:00
|
|
|
|
2012-12-12 16:36:53 +01:00
|
|
|
$attributes = $lease->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-07 00:28:33 +01:00
|
|
|
return $view;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|