2012-11-07 00:28:33 +01:00
|
|
|
<?php
|
|
|
|
|
2013-12-26 21:30:36 +01:00
|
|
|
final class DrydockLeaseViewController extends DrydockLeaseController {
|
2012-11-07 00:28:33 +01:00
|
|
|
|
|
|
|
private $id;
|
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->id = $data['id'];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
2013-12-27 22:15:19 +01:00
|
|
|
$viewer = $request->getUser();
|
2012-11-07 00:28:33 +01:00
|
|
|
|
2013-12-27 22:15:19 +01:00
|
|
|
$lease = id(new DrydockLeaseQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withIDs(array($this->id))
|
|
|
|
->executeOne();
|
2012-11-07 00:28:33 +01:00
|
|
|
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);
|
2013-10-11 16:53:56 +02:00
|
|
|
$properties = $this->buildPropertyListView($lease, $actions);
|
2012-11-07 00:28:33 +01:00
|
|
|
|
2015-06-02 23:34:04 +02:00
|
|
|
$pager = new PHUIPagerView();
|
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())
|
2013-12-27 22:15:19 +01:00
|
|
|
->setViewer($viewer)
|
2012-11-07 00:28:33 +01:00
|
|
|
->withLeaseIDs(array($lease->getID()))
|
|
|
|
->executeWithOffsetPager($pager);
|
|
|
|
|
2014-05-13 21:14:33 +02:00
|
|
|
$log_table = id(new DrydockLogListView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->setLogs($logs)
|
|
|
|
->render();
|
2012-11-07 00:28:33 +01:00
|
|
|
$log_table->appendChild($pager);
|
|
|
|
|
2012-12-17 23:47:21 +01:00
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
2013-12-19 02:47:34 +01:00
|
|
|
$crumbs->addTextCrumb($title, $lease_uri);
|
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-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(
|
|
|
|
'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'))
|
2014-05-13 16:45:39 +02:00
|
|
|
->setIcon('fa-times')
|
2012-12-15 00:42:58 +01:00
|
|
|
->setHref($this->getApplicationURI("/lease/{$id}/release/"))
|
|
|
|
->setWorkflow(true)
|
|
|
|
->setDisabled(!$can_release));
|
|
|
|
|
2012-11-07 00:28:33 +01:00
|
|
|
return $view;
|
|
|
|
}
|
|
|
|
|
2013-10-11 16:53:56 +02:00
|
|
|
private function buildPropertyListView(
|
|
|
|
DrydockLease $lease,
|
|
|
|
PhabricatorActionListView $actions) {
|
|
|
|
|
|
|
|
$view = new PHUIPropertyListView();
|
|
|
|
$view->setActionList($actions);
|
2012-11-07 00:28:33 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|