3 final class DrydockResourceViewController
extends DrydockResourceController
{
5 public function handleRequest(AphrontRequest
$request) {
6 $viewer = $request->getViewer();
7 $id = $request->getURIData('id');
9 $resource = id(new DrydockResourceQuery())
12 ->needUnconsumedCommands(true)
15 return new Aphront404Response();
21 $resource->getResourceName());
23 $header = id(new PHUIHeaderView())
25 ->setPolicyObject($resource)
27 ->setHeaderIcon('fa-map')
29 $resource->getStatusIcon(),
30 $resource->getStatusColor(),
31 $resource->getStatusDisplayName());
33 if ($resource->isReleasing()) {
36 ->setType(PHUITagView
::TYPE_SHADE
)
37 ->setIcon('fa-exclamation-triangle')
39 ->setName('Releasing'));
42 $curtain = $this->buildCurtain($resource);
43 $properties = $this->buildPropertyListView($resource);
45 $id = $resource->getID();
46 $resource_uri = $this->getApplicationURI("resource/{$id}/");
48 $log_query = id(new DrydockLogQuery())
49 ->withResourcePHIDs(array($resource->getPHID()));
51 $log_table = $this->buildLogTable($log_query)
52 ->setHideResources(true);
54 $logs = $this->buildLogBox(
56 $this->getApplicationURI("resource/{$id}/logs/query/all/"));
58 $crumbs = $this->buildApplicationCrumbs();
59 $crumbs->addTextCrumb(pht('Resource %d', $resource->getID()));
60 $crumbs->setBorder(true);
62 $locks = $this->buildLocksTab($resource->getPHID());
63 $commands = $this->buildCommandsTab($resource->getPHID());
65 $tab_group = id(new PHUITabGroupView())
68 ->setName(pht('Properties'))
69 ->setKey('properties')
70 ->appendChild($properties))
73 ->setName(pht('Slot Locks'))
75 ->appendChild($locks))
78 ->setName(pht('Commands'))
80 ->appendChild($commands));
82 $object_box = id(new PHUIObjectBoxView())
83 ->setHeaderText(pht('Properties'))
84 ->setBackground(PHUIObjectBoxView
::BLUE_PROPERTY
)
85 ->addTabGroup($tab_group);
87 $lease_box = $this->buildLeaseBox($resource);
89 $view = id(new PHUITwoColumnView())
91 ->setCurtain($curtain)
99 return $this->newPage()
109 private function buildCurtain(DrydockResource
$resource) {
110 $viewer = $this->getViewer();
112 $curtain = $this->newCurtainView($resource);
114 $can_release = $resource->canRelease();
115 if ($resource->isReleasing()) {
116 $can_release = false;
119 $can_edit = PhabricatorPolicyFilter
::hasCapability(
122 PhabricatorPolicyCapability
::CAN_EDIT
);
124 $uri = '/resource/'.$resource->getID().'/release/';
125 $uri = $this->getApplicationURI($uri);
128 id(new PhabricatorActionView())
130 ->setName(pht('Release Resource'))
131 ->setIcon('fa-times')
133 ->setDisabled(!$can_release ||
!$can_edit));
138 private function buildPropertyListView(
139 DrydockResource
$resource) {
140 $viewer = $this->getViewer();
142 $view = new PHUIPropertyListView();
144 $until = $resource->getUntil();
146 $until_display = phabricator_datetime($until, $viewer);
148 $until_display = phutil_tag('em', array(), pht('Never'));
150 $view->addProperty(pht('Expires'), $until_display);
153 pht('Resource Type'),
154 $resource->getType());
158 $viewer->renderHandle($resource->getBlueprintPHID()));
160 $attributes = $resource->getAttributes();
162 $view->addSectionHeader(
163 pht('Attributes'), 'fa-list-ul');
164 foreach ($attributes as $key => $value) {
165 $view->addProperty($key, $value);
172 private function buildLeaseBox(DrydockResource
$resource) {
173 $viewer = $this->getViewer();
175 $leases = id(new DrydockLeaseQuery())
177 ->withResourcePHIDs(array($resource->getPHID()))
180 DrydockLeaseStatus
::STATUS_PENDING
,
181 DrydockLeaseStatus
::STATUS_ACQUIRED
,
182 DrydockLeaseStatus
::STATUS_ACTIVE
,
187 $id = $resource->getID();
188 $leases_uri = "resource/{$id}/leases/query/all/";
189 $leases_uri = $this->getApplicationURI($leases_uri);
191 $lease_header = id(new PHUIHeaderView())
192 ->setHeader(pht('Active Leases'))
194 id(new PHUIButtonView())
196 ->setHref($leases_uri)
197 ->setIcon('fa-search')
198 ->setText(pht('View All')));
200 $lease_list = id(new DrydockLeaseListView())
204 ->setNoDataString(pht('This resource has no active leases.'));
206 return id(new PHUIObjectBoxView())
207 ->setHeader($lease_header)
208 ->setBackground(PHUIObjectBoxView
::BLUE_PROPERTY
)
209 ->setObjectList($lease_list);