mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-13 10:22:42 +01:00
edd5c208a6
Summary: This is probably not the most useful app to have work on mobile, but get the log view to do something fairly sensible. Test Plan: Looked at all Drydock views in mobile. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T2015 Differential Revision: https://secure.phabricator.com/D4224
164 lines
4.2 KiB
PHP
164 lines
4.2 KiB
PHP
<?php
|
|
|
|
abstract class DrydockController extends PhabricatorController {
|
|
|
|
final protected function buildSideNav($selected) {
|
|
$nav = new AphrontSideNavFilterView();
|
|
$nav->setBaseURI(new PhutilURI('/drydock/'));
|
|
$nav->addFilter('resource', 'Resources');
|
|
$nav->addFilter('lease', 'Leases');
|
|
$nav->addSpacer();
|
|
$nav->addFilter('log', 'Logs');
|
|
|
|
$nav->selectFilter($selected, 'resource');
|
|
|
|
return $nav;
|
|
}
|
|
|
|
public function buildApplicationMenu() {
|
|
return $this->buildSideNav(null)->getMenu();
|
|
}
|
|
|
|
protected function buildLogTableView(array $logs) {
|
|
assert_instances_of($logs, 'DrydockLog');
|
|
|
|
$user = $this->getRequest()->getUser();
|
|
|
|
$rows = array();
|
|
foreach ($logs as $log) {
|
|
$resource_uri = '/resource/'.$log->getResourceID().'/';
|
|
$resource_uri = $this->getApplicationURI($resource_uri);
|
|
|
|
$lease_uri = '/lease/'.$log->getLeaseID().'/';
|
|
$lease_uri = $this->getApplicationURI($lease_uri);
|
|
|
|
$rows[] = array(
|
|
phutil_render_tag(
|
|
'a',
|
|
array(
|
|
'href' => $resource_uri,
|
|
),
|
|
phutil_escape_html($log->getResourceID())),
|
|
phutil_render_tag(
|
|
'a',
|
|
array(
|
|
'href' => $lease_uri,
|
|
),
|
|
phutil_escape_html($log->getLeaseID())),
|
|
phutil_escape_html($log->getMessage()),
|
|
phabricator_date($log->getEpoch(), $user),
|
|
);
|
|
}
|
|
|
|
$table = new AphrontTableView($rows);
|
|
$table->setDeviceReadyTable(true);
|
|
$table->setHeaders(
|
|
array(
|
|
'Resource',
|
|
'Lease',
|
|
'Message',
|
|
'Date',
|
|
));
|
|
$table->setShortHeaders(
|
|
array(
|
|
'R',
|
|
'L',
|
|
'Message',
|
|
'',
|
|
));
|
|
$table->setColumnClasses(
|
|
array(
|
|
'',
|
|
'',
|
|
'wide',
|
|
'',
|
|
));
|
|
|
|
return $table;
|
|
}
|
|
|
|
protected function buildLeaseListView(array $leases) {
|
|
assert_instances_of($leases, 'DrydockLease');
|
|
|
|
$user = $this->getRequest()->getUser();
|
|
$view = new PhabricatorObjectItemListView();
|
|
|
|
foreach ($leases as $lease) {
|
|
$item = id(new PhabricatorObjectItemView())
|
|
->setHeader($lease->getLeaseName())
|
|
->setHref($this->getApplicationURI('/lease/'.$lease->getID().'/'));
|
|
|
|
if ($lease->hasAttachedResource()) {
|
|
$resource = $lease->getResource();
|
|
|
|
$resource_href = '/resource/'.$resource->getID().'/';
|
|
$resource_href = $this->getApplicationURI($resource_href);
|
|
|
|
$resource_name = $resource->getName();
|
|
|
|
$item->addAttribute(
|
|
phutil_render_tag(
|
|
'a',
|
|
array(
|
|
'href' => $resource_href,
|
|
),
|
|
phutil_escape_html($resource_name)));
|
|
}
|
|
|
|
$status = DrydockLeaseStatus::getNameForStatus($lease->getStatus());
|
|
$item->addAttribute(phutil_escape_html($status));
|
|
|
|
$date_created = phabricator_date($lease->getDateCreated(), $user);
|
|
$item->addAttribute(pht('Created on %s', $date_created));
|
|
|
|
if ($lease->isActive()) {
|
|
$item->setBarColor('green');
|
|
} else {
|
|
$item->setBarColor('red');
|
|
}
|
|
|
|
$view->addItem($item);
|
|
}
|
|
|
|
return $view;
|
|
}
|
|
|
|
protected function buildResourceListView(array $resources) {
|
|
assert_instances_of($resources, 'DrydockResource');
|
|
|
|
$user = $this->getRequest()->getUser();
|
|
$view = new PhabricatorObjectItemListView();
|
|
|
|
foreach ($resources as $resource) {
|
|
$name = pht('Resource %d', $resource->getID()).': '.$resource->getName();
|
|
|
|
$item = id(new PhabricatorObjectItemView())
|
|
->setHref($this->getApplicationURI('/resource/'.$resource->getID().'/'))
|
|
->setHeader($name);
|
|
|
|
$status = DrydockResourceStatus::getNameForStatus($resource->getStatus());
|
|
$item->addAttribute($status);
|
|
|
|
switch ($resource->getStatus()) {
|
|
case DrydockResourceStatus::STATUS_PENDING:
|
|
$item->setBarColor('yellow');
|
|
break;
|
|
case DrydockResourceStatus::STATUS_OPEN:
|
|
$item->setBarColor('green');
|
|
break;
|
|
case DrydockResourceStatus::STATUS_DESTROYED:
|
|
$item->setBarColor('black');
|
|
break;
|
|
default:
|
|
$item->setBarColor('red');
|
|
break;
|
|
}
|
|
|
|
$view->addItem($item);
|
|
}
|
|
|
|
return $view;
|
|
}
|
|
|
|
|
|
}
|