Remove product literal strings in "pht()", part 6
[phabricator.git] / src / applications / drydock / controller / DrydockResourceViewController.php
blobec0dce53e17c7e758c700b7398afe3c0328ca7fd
1 <?php
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())
10 ->setViewer($viewer)
11 ->withIDs(array($id))
12 ->needUnconsumedCommands(true)
13 ->executeOne();
14 if (!$resource) {
15 return new Aphront404Response();
18 $title = pht(
19 'Resource %s %s',
20 $resource->getID(),
21 $resource->getResourceName());
23 $header = id(new PHUIHeaderView())
24 ->setUser($viewer)
25 ->setPolicyObject($resource)
26 ->setHeader($title)
27 ->setHeaderIcon('fa-map')
28 ->setStatus(
29 $resource->getStatusIcon(),
30 $resource->getStatusColor(),
31 $resource->getStatusDisplayName());
33 if ($resource->isReleasing()) {
34 $header->addTag(
35 id(new PHUITagView())
36 ->setType(PHUITagView::TYPE_SHADE)
37 ->setIcon('fa-exclamation-triangle')
38 ->setColor('red')
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(
55 $log_table,
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())
66 ->addTab(
67 id(new PHUITabView())
68 ->setName(pht('Properties'))
69 ->setKey('properties')
70 ->appendChild($properties))
71 ->addTab(
72 id(new PHUITabView())
73 ->setName(pht('Slot Locks'))
74 ->setKey('locks')
75 ->appendChild($locks))
76 ->addTab(
77 id(new PHUITabView())
78 ->setName(pht('Commands'))
79 ->setKey('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())
90 ->setHeader($header)
91 ->setCurtain($curtain)
92 ->setMainColumn(
93 array(
94 $object_box,
95 $lease_box,
96 $logs,
97 ));
99 return $this->newPage()
100 ->setTitle($title)
101 ->setCrumbs($crumbs)
102 ->appendChild(
103 array(
104 $view,
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(
120 $viewer,
121 $resource,
122 PhabricatorPolicyCapability::CAN_EDIT);
124 $uri = '/resource/'.$resource->getID().'/release/';
125 $uri = $this->getApplicationURI($uri);
127 $curtain->addAction(
128 id(new PhabricatorActionView())
129 ->setHref($uri)
130 ->setName(pht('Release Resource'))
131 ->setIcon('fa-times')
132 ->setWorkflow(true)
133 ->setDisabled(!$can_release || !$can_edit));
135 return $curtain;
138 private function buildPropertyListView(
139 DrydockResource $resource) {
140 $viewer = $this->getViewer();
142 $view = new PHUIPropertyListView();
144 $until = $resource->getUntil();
145 if ($until) {
146 $until_display = phabricator_datetime($until, $viewer);
147 } else {
148 $until_display = phutil_tag('em', array(), pht('Never'));
150 $view->addProperty(pht('Expires'), $until_display);
152 $view->addProperty(
153 pht('Resource Type'),
154 $resource->getType());
156 $view->addProperty(
157 pht('Blueprint'),
158 $viewer->renderHandle($resource->getBlueprintPHID()));
160 $attributes = $resource->getAttributes();
161 if ($attributes) {
162 $view->addSectionHeader(
163 pht('Attributes'), 'fa-list-ul');
164 foreach ($attributes as $key => $value) {
165 $view->addProperty($key, $value);
169 return $view;
172 private function buildLeaseBox(DrydockResource $resource) {
173 $viewer = $this->getViewer();
175 $leases = id(new DrydockLeaseQuery())
176 ->setViewer($viewer)
177 ->withResourcePHIDs(array($resource->getPHID()))
178 ->withStatuses(
179 array(
180 DrydockLeaseStatus::STATUS_PENDING,
181 DrydockLeaseStatus::STATUS_ACQUIRED,
182 DrydockLeaseStatus::STATUS_ACTIVE,
184 ->setLimit(100)
185 ->execute();
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'))
193 ->addActionLink(
194 id(new PHUIButtonView())
195 ->setTag('a')
196 ->setHref($leases_uri)
197 ->setIcon('fa-search')
198 ->setText(pht('View All')));
200 $lease_list = id(new DrydockLeaseListView())
201 ->setUser($viewer)
202 ->setLeases($leases)
203 ->render()
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);