1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 05:50:55 +01:00

Make minor improvements to Drydock web interface

Summary: Consolidate some code and start on lease detail pages.

Test Plan: {F22783}

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2015

Differential Revision: https://secure.phabricator.com/D3901
This commit is contained in:
epriestley 2012-11-06 15:28:33 -08:00
parent 19c840edf2
commit 0e774dac93
6 changed files with 186 additions and 36 deletions

View file

@ -424,6 +424,7 @@ phutil_register_library_map(array(
'DrydockLease' => 'applications/drydock/storage/DrydockLease.php', 'DrydockLease' => 'applications/drydock/storage/DrydockLease.php',
'DrydockLeaseListController' => 'applications/drydock/controller/DrydockLeaseListController.php', 'DrydockLeaseListController' => 'applications/drydock/controller/DrydockLeaseListController.php',
'DrydockLeaseStatus' => 'applications/drydock/constants/DrydockLeaseStatus.php', 'DrydockLeaseStatus' => 'applications/drydock/constants/DrydockLeaseStatus.php',
'DrydockLeaseViewController' => 'applications/drydock/controller/DrydockLeaseViewController.php',
'DrydockLocalCommandInterface' => 'applications/drydock/interface/command/DrydockLocalCommandInterface.php', 'DrydockLocalCommandInterface' => 'applications/drydock/interface/command/DrydockLocalCommandInterface.php',
'DrydockLocalHostBlueprint' => 'applications/drydock/blueprint/DrydockLocalHostBlueprint.php', 'DrydockLocalHostBlueprint' => 'applications/drydock/blueprint/DrydockLocalHostBlueprint.php',
'DrydockLog' => 'applications/drydock/storage/DrydockLog.php', 'DrydockLog' => 'applications/drydock/storage/DrydockLog.php',
@ -1657,6 +1658,7 @@ phutil_register_library_map(array(
'DrydockLease' => 'DrydockDAO', 'DrydockLease' => 'DrydockDAO',
'DrydockLeaseListController' => 'DrydockController', 'DrydockLeaseListController' => 'DrydockController',
'DrydockLeaseStatus' => 'DrydockConstants', 'DrydockLeaseStatus' => 'DrydockConstants',
'DrydockLeaseViewController' => 'DrydockController',
'DrydockLocalCommandInterface' => 'DrydockCommandInterface', 'DrydockLocalCommandInterface' => 'DrydockCommandInterface',
'DrydockLocalHostBlueprint' => 'DrydockBlueprint', 'DrydockLocalHostBlueprint' => 'DrydockBlueprint',
'DrydockLog' => 'DrydockDAO', 'DrydockLog' => 'DrydockDAO',

View file

@ -32,7 +32,10 @@ final class PhabricatorApplicationDrydock extends PhabricatorApplication {
'' => 'DrydockResourceListController', '' => 'DrydockResourceListController',
'resource/' => 'DrydockResourceListController', 'resource/' => 'DrydockResourceListController',
'resource/allocate/' => 'DrydockResourceAllocateController', 'resource/allocate/' => 'DrydockResourceAllocateController',
'lease/' => 'DrydockLeaseListController', 'lease/' => array(
'' => 'DrydockLeaseListController',
'(?P<id>[1-9]\d*)/' => 'DrydockLeaseViewController',
),
'log/' => 'DrydockLogController', 'log/' => 'DrydockLogController',
), ),
); );

View file

@ -30,4 +30,44 @@ abstract class DrydockController extends PhabricatorController {
return $nav; return $nav;
} }
protected function buildLogTableView(array $logs) {
assert_instances_of($logs, 'DrydockLog');
$user = $this->getRequest()->getUser();
// TODO: It's probably a stretch to claim this works on mobile.
$rows = array();
foreach ($logs as $log) {
$rows[] = array(
$log->getResourceID(),
$log->getLeaseID(),
phutil_escape_html($log->getMessage()),
phabricator_datetime($log->getEpoch(), $user),
);
}
$table = new AphrontTableView($rows);
$table->setHeaders(
array(
'Resource',
'Lease',
'Message',
'Date',
));
$table->setColumnClasses(
array(
'',
'',
'wide',
'',
));
$panel = new AphrontPanelView();
$panel->setHeader('Logs');
$panel->appendChild($table);
return $panel;
}
} }

View file

@ -9,7 +9,8 @@ final class DrydockLeaseListController extends DrydockController {
$nav = $this->buildSideNav('lease'); $nav = $this->buildSideNav('lease');
$pager = new AphrontPagerView(); $pager = new AphrontPagerView();
$pager->setURI(new PhutilURI('/drydock/lease/'), 'page'); $pager->setURI(new PhutilURI('/drydock/lease/'), 'offset');
$pager->setOffset($request->getInt('offset'));
$data = id(new DrydockLease())->loadAllWhere( $data = id(new DrydockLease())->loadAllWhere(
'1 = 1 ORDER BY id DESC LIMIT %d, %d', '1 = 1 ORDER BY id DESC LIMIT %d, %d',
@ -32,8 +33,14 @@ final class DrydockLeaseListController extends DrydockController {
foreach ($data as $lease) { foreach ($data as $lease) {
$resource = idx($resources, $lease->getResourceID()); $resource = idx($resources, $lease->getResourceID());
$rows[] = array( $rows[] = array(
$lease->getID(), phutil_render_tag(
'a',
array(
'href' => $this->getApplicationURI('/lease/'.$lease->getID().'/'),
),
$lease->getID()),
DrydockLeaseStatus::getNameForStatus($lease->getStatus()), DrydockLeaseStatus::getNameForStatus($lease->getStatus()),
phutil_escape_html($lease->getResourceType()),
($lease->getOwnerPHID() ($lease->getOwnerPHID()
? $handles[$lease->getOwnerPHID()]->renderLink() ? $handles[$lease->getOwnerPHID()]->renderLink()
: null), : null),
@ -50,8 +57,9 @@ final class DrydockLeaseListController extends DrydockController {
array( array(
'ID', 'ID',
'Status', 'Status',
'Owner', 'Resource Type',
'Resource ID', 'Resource ID',
'Owner',
'Resource', 'Resource',
'Created', 'Created',
)); ));
@ -61,6 +69,7 @@ final class DrydockLeaseListController extends DrydockController {
'', '',
'', '',
'', '',
'',
'wide pri', 'wide pri',
'right', 'right',
)); ));
@ -75,7 +84,8 @@ final class DrydockLeaseListController extends DrydockController {
return $this->buildStandardPageResponse( return $this->buildStandardPageResponse(
$nav, $nav,
array( array(
'title' => 'Leases', 'device' => true,
'title' => 'Leases',
)); ));
} }

View file

@ -0,0 +1,123 @@
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
final class DrydockLeaseViewController extends DrydockController {
private $id;
public function willProcessRequest(array $data) {
$this->id = $data['id'];
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$nav = $this->buildSideNav('lease');
$lease = id(new DrydockLease())->load($this->id);
if (!$lease) {
return new Aphront404Response();
}
$title = 'Lease '.$lease->getID();
$header = id(new PhabricatorHeaderView())
->setHeader($title);
$actions = $this->buildActionListView($lease);
$properties = $this->buildPropertyListView($lease);
$pager = new AphrontPagerView();
$pager->setURI(
new PhutilURI($this->getApplicationURI('lease/'.$lease->getID().'/')),
'offset');
$pager->setOffset($request->getInt('offset'));
$logs = id(new DrydockLogQuery())
->withLeaseIDs(array($lease->getID()))
->executeWithOffsetPager($pager);
$log_table = $this->buildLogTableView($logs);
$log_table->appendChild($pager);
$nav->appendChild(
array(
$header,
$actions,
$properties,
$log_table,
));
return $this->buildApplicationPage(
$nav,
array(
'device' => true,
'title' => $title,
));
}
private function buildActionListView(DrydockLease $lease) {
$view = id(new PhabricatorActionListView())
->setUser($this->getRequest()->getUser())
->setObject($lease);
return $view;
}
private function buildPropertyListView(DrydockLease $lease) {
$view = new PhabricatorPropertyListView();
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'),
phutil_escape_html($lease->getResourceType()));
$view->addProperty(
pht('Resource'),
phutil_escape_html($lease->getResourceID()));
return $view;
}
}

View file

@ -27,38 +27,10 @@ final class DrydockLogController extends DrydockController {
$logs = $query->executeWithOffsetPager($pager); $logs = $query->executeWithOffsetPager($pager);
$rows = array(); $table = $this->buildLogTableView($logs);
foreach ($logs as $log) { $table->appendChild($pager);
$rows[] = array(
$log->getResourceID(),
$log->getLeaseID(),
phutil_escape_html($log->getMessage()),
phabricator_datetime($log->getEpoch(), $user),
);
}
$table = new AphrontTableView($rows); $nav->appendChild($table);
$table->setHeaders(
array(
'Resource',
'Lease',
'Message',
'Date',
));
$table->setColumnClasses(
array(
'',
'',
'wide',
'',
));
$panel = new AphrontPanelView();
$panel->setHeader('Drydock Logs');
$panel->appendChild($table);
$panel->appendChild($pager);
$nav->appendChild($panel);
return $this->buildStandardPageResponse( return $this->buildStandardPageResponse(
$nav, $nav,