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:
parent
19c840edf2
commit
0e774dac93
6 changed files with 186 additions and 36 deletions
|
@ -424,6 +424,7 @@ phutil_register_library_map(array(
|
|||
'DrydockLease' => 'applications/drydock/storage/DrydockLease.php',
|
||||
'DrydockLeaseListController' => 'applications/drydock/controller/DrydockLeaseListController.php',
|
||||
'DrydockLeaseStatus' => 'applications/drydock/constants/DrydockLeaseStatus.php',
|
||||
'DrydockLeaseViewController' => 'applications/drydock/controller/DrydockLeaseViewController.php',
|
||||
'DrydockLocalCommandInterface' => 'applications/drydock/interface/command/DrydockLocalCommandInterface.php',
|
||||
'DrydockLocalHostBlueprint' => 'applications/drydock/blueprint/DrydockLocalHostBlueprint.php',
|
||||
'DrydockLog' => 'applications/drydock/storage/DrydockLog.php',
|
||||
|
@ -1657,6 +1658,7 @@ phutil_register_library_map(array(
|
|||
'DrydockLease' => 'DrydockDAO',
|
||||
'DrydockLeaseListController' => 'DrydockController',
|
||||
'DrydockLeaseStatus' => 'DrydockConstants',
|
||||
'DrydockLeaseViewController' => 'DrydockController',
|
||||
'DrydockLocalCommandInterface' => 'DrydockCommandInterface',
|
||||
'DrydockLocalHostBlueprint' => 'DrydockBlueprint',
|
||||
'DrydockLog' => 'DrydockDAO',
|
||||
|
|
|
@ -32,7 +32,10 @@ final class PhabricatorApplicationDrydock extends PhabricatorApplication {
|
|||
'' => 'DrydockResourceListController',
|
||||
'resource/' => 'DrydockResourceListController',
|
||||
'resource/allocate/' => 'DrydockResourceAllocateController',
|
||||
'lease/' => 'DrydockLeaseListController',
|
||||
'lease/' => array(
|
||||
'' => 'DrydockLeaseListController',
|
||||
'(?P<id>[1-9]\d*)/' => 'DrydockLeaseViewController',
|
||||
),
|
||||
'log/' => 'DrydockLogController',
|
||||
),
|
||||
);
|
||||
|
|
|
@ -30,4 +30,44 @@ abstract class DrydockController extends PhabricatorController {
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,7 +9,8 @@ final class DrydockLeaseListController extends DrydockController {
|
|||
$nav = $this->buildSideNav('lease');
|
||||
|
||||
$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(
|
||||
'1 = 1 ORDER BY id DESC LIMIT %d, %d',
|
||||
|
@ -32,8 +33,14 @@ final class DrydockLeaseListController extends DrydockController {
|
|||
foreach ($data as $lease) {
|
||||
$resource = idx($resources, $lease->getResourceID());
|
||||
$rows[] = array(
|
||||
$lease->getID(),
|
||||
phutil_render_tag(
|
||||
'a',
|
||||
array(
|
||||
'href' => $this->getApplicationURI('/lease/'.$lease->getID().'/'),
|
||||
),
|
||||
$lease->getID()),
|
||||
DrydockLeaseStatus::getNameForStatus($lease->getStatus()),
|
||||
phutil_escape_html($lease->getResourceType()),
|
||||
($lease->getOwnerPHID()
|
||||
? $handles[$lease->getOwnerPHID()]->renderLink()
|
||||
: null),
|
||||
|
@ -50,8 +57,9 @@ final class DrydockLeaseListController extends DrydockController {
|
|||
array(
|
||||
'ID',
|
||||
'Status',
|
||||
'Owner',
|
||||
'Resource Type',
|
||||
'Resource ID',
|
||||
'Owner',
|
||||
'Resource',
|
||||
'Created',
|
||||
));
|
||||
|
@ -61,6 +69,7 @@ final class DrydockLeaseListController extends DrydockController {
|
|||
'',
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'wide pri',
|
||||
'right',
|
||||
));
|
||||
|
@ -75,6 +84,7 @@ final class DrydockLeaseListController extends DrydockController {
|
|||
return $this->buildStandardPageResponse(
|
||||
$nav,
|
||||
array(
|
||||
'device' => true,
|
||||
'title' => 'Leases',
|
||||
));
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -27,38 +27,10 @@ final class DrydockLogController extends DrydockController {
|
|||
|
||||
$logs = $query->executeWithOffsetPager($pager);
|
||||
|
||||
$rows = array();
|
||||
foreach ($logs as $log) {
|
||||
$rows[] = array(
|
||||
$log->getResourceID(),
|
||||
$log->getLeaseID(),
|
||||
phutil_escape_html($log->getMessage()),
|
||||
phabricator_datetime($log->getEpoch(), $user),
|
||||
);
|
||||
}
|
||||
$table = $this->buildLogTableView($logs);
|
||||
$table->appendChild($pager);
|
||||
|
||||
$table = new AphrontTableView($rows);
|
||||
$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);
|
||||
$nav->appendChild($table);
|
||||
|
||||
return $this->buildStandardPageResponse(
|
||||
$nav,
|
||||
|
|
Loading…
Reference in a new issue