3 final class DrydockLeaseViewController
extends DrydockLeaseController
{
5 public function handleRequest(AphrontRequest
$request) {
6 $viewer = $request->getViewer();
7 $id = $request->getURIData('id');
9 $lease = id(new DrydockLeaseQuery())
12 ->needUnconsumedCommands(true)
15 return new Aphront404Response();
18 $id = $lease->getID();
19 $lease_uri = $this->getApplicationURI("lease/{$id}/");
21 $title = pht('Lease %d', $lease->getID());
23 $header = id(new PHUIHeaderView())
25 ->setHeaderIcon('fa-link')
27 $lease->getStatusIcon(),
28 $lease->getStatusColor(),
29 $lease->getStatusDisplayName());
31 if ($lease->isReleasing()) {
34 ->setType(PHUITagView
::TYPE_SHADE
)
35 ->setIcon('fa-exclamation-triangle')
37 ->setName('Releasing'));
40 $curtain = $this->buildCurtain($lease);
41 $properties = $this->buildPropertyListView($lease);
43 $log_query = id(new DrydockLogQuery())
44 ->withLeasePHIDs(array($lease->getPHID()));
46 $log_table = $this->buildLogTable($log_query)
47 ->setHideLeases(true);
49 $logs = $this->buildLogBox(
51 $this->getApplicationURI("lease/{$id}/logs/query/all/"));
53 $crumbs = $this->buildApplicationCrumbs();
54 $crumbs->addTextCrumb($title, $lease_uri);
55 $crumbs->setBorder(true);
57 $locks = $this->buildLocksTab($lease->getPHID());
58 $commands = $this->buildCommandsTab($lease->getPHID());
60 $tab_group = id(new PHUITabGroupView())
63 ->setName(pht('Properties'))
64 ->setKey('properties')
65 ->appendChild($properties))
68 ->setName(pht('Slot Locks'))
70 ->appendChild($locks))
73 ->setName(pht('Commands'))
75 ->appendChild($commands));
77 $object_box = id(new PHUIObjectBoxView())
78 ->setHeaderText(pht('Properties'))
79 ->setBackground(PHUIObjectBoxView
::BLUE_PROPERTY
)
80 ->addTabGroup($tab_group);
82 $view = id(new PHUITwoColumnView())
84 ->setCurtain($curtain)
85 ->setMainColumn(array(
90 return $this->newPage()
100 private function buildCurtain(DrydockLease
$lease) {
101 $viewer = $this->getViewer();
103 $curtain = $this->newCurtainView($lease);
104 $id = $lease->getID();
106 $can_release = $lease->canRelease();
107 if ($lease->isReleasing()) {
108 $can_release = false;
111 $can_edit = PhabricatorPolicyFilter
::hasCapability(
114 PhabricatorPolicyCapability
::CAN_EDIT
);
117 id(new PhabricatorActionView())
118 ->setName(pht('Release Lease'))
119 ->setIcon('fa-times')
120 ->setHref($this->getApplicationURI("/lease/{$id}/release/"))
122 ->setDisabled(!$can_release ||
!$can_edit));
127 private function buildPropertyListView(
128 DrydockLease
$lease) {
129 $viewer = $this->getViewer();
131 $view = new PHUIPropertyListView();
134 pht('Resource Type'),
135 $lease->getResourceType());
137 $owner_phid = $lease->getOwnerPHID();
139 $owner_display = $viewer->renderHandle($owner_phid);
141 $owner_display = phutil_tag('em', array(), pht('No Owner'));
143 $view->addProperty(pht('Owner'), $owner_display);
145 $authorizing_phid = $lease->getAuthorizingPHID();
146 if ($authorizing_phid) {
147 $authorizing_display = $viewer->renderHandle($authorizing_phid);
149 $authorizing_display = phutil_tag('em', array(), pht('None'));
151 $view->addProperty(pht('Authorized By'), $authorizing_display);
153 $resource_phid = $lease->getResourcePHID();
154 if ($resource_phid) {
155 $resource_display = $viewer->renderHandle($resource_phid);
157 $resource_display = phutil_tag('em', array(), pht('No Resource'));
159 $view->addProperty(pht('Resource'), $resource_display);
161 $until = $lease->getUntil();
163 $until_display = phabricator_datetime($until, $viewer);
165 $until_display = phutil_tag('em', array(), pht('Never'));
167 $view->addProperty(pht('Expires'), $until_display);
169 $acquired_epoch = $lease->getAcquiredEpoch();
170 $activated_epoch = $lease->getActivatedEpoch();
172 if ($acquired_epoch) {
173 $acquired_display = phabricator_datetime($acquired_epoch, $viewer);
175 if ($activated_epoch) {
176 $acquired_display = phutil_tag(
179 pht('Activated on Acquisition'));
181 $acquired_display = phutil_tag('em', array(), pht('Not Acquired'));
184 $view->addProperty(pht('Acquired'), $acquired_display);
186 if ($activated_epoch) {
187 $activated_display = phabricator_datetime($activated_epoch, $viewer);
189 $activated_display = phutil_tag('em', array(), pht('Not Activated'));
191 $view->addProperty(pht('Activated'), $activated_display);
193 $attributes = $lease->getAttributes();
195 $view->addSectionHeader(
196 pht('Attributes'), 'fa-list-ul');
197 foreach ($attributes as $key => $value) {
198 $view->addProperty($key, $value);