1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 08:52:39 +01:00

Use ApplicationSearch for Drydock Resources

Summary: Ref T2015. Bring ApplicationSearch to Resources, too.

Test Plan: Browsed/queried resources in UI.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2015

Differential Revision: https://secure.phabricator.com/D7830
This commit is contained in:
epriestley 2013-12-26 12:30:10 -08:00
parent fa00e86f87
commit bc3912e641
6 changed files with 130 additions and 42 deletions

View file

@ -676,6 +676,7 @@ phutil_register_library_map(array(
'DrydockResourceCloseController' => 'applications/drydock/controller/DrydockResourceCloseController.php', 'DrydockResourceCloseController' => 'applications/drydock/controller/DrydockResourceCloseController.php',
'DrydockResourceListController' => 'applications/drydock/controller/DrydockResourceListController.php', 'DrydockResourceListController' => 'applications/drydock/controller/DrydockResourceListController.php',
'DrydockResourceQuery' => 'applications/drydock/query/DrydockResourceQuery.php', 'DrydockResourceQuery' => 'applications/drydock/query/DrydockResourceQuery.php',
'DrydockResourceSearchEngine' => 'applications/drydock/query/DrydockResourceSearchEngine.php',
'DrydockResourceStatus' => 'applications/drydock/constants/DrydockResourceStatus.php', 'DrydockResourceStatus' => 'applications/drydock/constants/DrydockResourceStatus.php',
'DrydockResourceViewController' => 'applications/drydock/controller/DrydockResourceViewController.php', 'DrydockResourceViewController' => 'applications/drydock/controller/DrydockResourceViewController.php',
'DrydockSFTPFilesystemInterface' => 'applications/drydock/interface/filesystem/DrydockSFTPFilesystemInterface.php', 'DrydockSFTPFilesystemInterface' => 'applications/drydock/interface/filesystem/DrydockSFTPFilesystemInterface.php',
@ -3091,8 +3092,13 @@ phutil_register_library_map(array(
1 => 'PhabricatorPolicyInterface', 1 => 'PhabricatorPolicyInterface',
), ),
'DrydockResourceCloseController' => 'DrydockController', 'DrydockResourceCloseController' => 'DrydockController',
'DrydockResourceListController' => 'DrydockController', 'DrydockResourceListController' =>
array(
0 => 'DrydockController',
1 => 'PhabricatorApplicationSearchResultsControllerInterface',
),
'DrydockResourceQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'DrydockResourceQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'DrydockResourceSearchEngine' => 'PhabricatorApplicationSearchEngine',
'DrydockResourceStatus' => 'DrydockConstants', 'DrydockResourceStatus' => 'DrydockConstants',
'DrydockResourceViewController' => 'DrydockController', 'DrydockResourceViewController' => 'DrydockController',
'DrydockSFTPFilesystemInterface' => 'DrydockFilesystemInterface', 'DrydockSFTPFilesystemInterface' => 'DrydockFilesystemInterface',

View file

@ -41,7 +41,7 @@ final class PhabricatorApplicationDrydock extends PhabricatorApplication {
'edit/(?P<id>[1-9]\d*)/' => 'DrydockBlueprintEditController', 'edit/(?P<id>[1-9]\d*)/' => 'DrydockBlueprintEditController',
), ),
'resource/' => array( 'resource/' => array(
'' => 'DrydockResourceListController', '(?:query/(?P<queryKey>[^/]+)/)?' => 'DrydockResourceListController',
'(?P<id>[1-9]\d*)/' => 'DrydockResourceViewController', '(?P<id>[1-9]\d*)/' => 'DrydockResourceViewController',
'(?P<id>[1-9]\d*)/close/' => 'DrydockResourceCloseController', '(?P<id>[1-9]\d*)/close/' => 'DrydockResourceCloseController',
), ),

View file

@ -9,15 +9,25 @@ final class DrydockResourceStatus extends DrydockConstants {
const STATUS_DESTROYED = 4; const STATUS_DESTROYED = 4;
public static function getNameForStatus($status) { public static function getNameForStatus($status) {
static $map = array( $map = array(
self::STATUS_PENDING => 'Pending', self::STATUS_PENDING => pht('Pending'),
self::STATUS_OPEN => 'Open', self::STATUS_OPEN => pht('Open'),
self::STATUS_CLOSED => 'Closed', self::STATUS_CLOSED => pht('Closed'),
self::STATUS_BROKEN => 'Broken', self::STATUS_BROKEN => pht('Broken'),
self::STATUS_DESTROYED => 'Destroyed', self::STATUS_DESTROYED => pht('Destroyed'),
); );
return idx($map, $status, 'Unknown'); return idx($map, $status, 'Unknown');
} }
public static function getAllStatuses() {
return array(
self::STATUS_PENDING,
self::STATUS_OPEN,
self::STATUS_CLOSED,
self::STATUS_BROKEN,
self::STATUS_DESTROYED,
);
}
} }

View file

@ -14,8 +14,9 @@ abstract class DrydockController extends PhabricatorController {
->setViewer($this->getRequest()->getUser()) ->setViewer($this->getRequest()->getUser())
->addNavigationItems($nav->getMenu(), pht('Leases')); ->addNavigationItems($nav->getMenu(), pht('Leases'));
$nav->addLabel(pht('Resources')); id(new DrydockResourceSearchEngine())
$nav->addFilter('resource', 'Resources'); ->setViewer($this->getRequest()->getUser())
->addNavigationItems($nav->getMenu(), pht('Resources'));
$nav->addLabel(pht('Logs')); $nav->addLabel(pht('Logs'));
$nav->addFilter('log', 'Logs'); $nav->addFilter('log', 'Logs');

View file

@ -1,43 +1,34 @@
<?php <?php
final class DrydockResourceListController extends DrydockController { final class DrydockResourceListController extends DrydockController
implements PhabricatorApplicationSearchResultsControllerInterface {
private $queryKey;
public function shouldAllowPublic() {
return true;
}
public function willProcessRequest(array $data) {
$this->queryKey = idx($data, 'queryKey');
}
public function processRequest() { public function processRequest() {
$request = $this->getRequest(); $request = $this->getRequest();
$user = $request->getUser(); $controller = id(new PhabricatorApplicationSearchController($request))
->setQueryKey($this->queryKey)
->setSearchEngine(new DrydockResourceSearchEngine())
->setNavigation($this->buildSideNav());
$title = pht('Resources'); return $this->delegateToController($controller);
}
$resource_header = id(new PHUIHeaderView()) public function renderResultsList(
->setHeader($title); array $resources,
PhabricatorSavedQuery $query) {
$pager = new AphrontPagerView(); assert_instances_of($resources, 'DrydockResource');
$pager->setURI(new PhutilURI('/drydock/resource/'), 'offset');
$resources = id(new DrydockResourceQuery())
->setViewer($user)
->executeWithOffsetPager($pager);
$resource_list = $this->buildResourceListView($resources);
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb($title, $request->getRequestURI());
$nav = $this->buildSideNav('resource');
$nav->setCrumbs($crumbs);
$nav->appendChild(
array(
$resource_header,
$resource_list,
$pager,
));
return $this->buildApplicationPage(
$nav,
array(
'title' => $title,
'device' => true,
));
return $this->buildResourceListView($resources);
} }
} }

View file

@ -0,0 +1,80 @@
<?php
final class DrydockResourceSearchEngine
extends PhabricatorApplicationSearchEngine {
public function buildSavedQueryFromRequest(AphrontRequest $request) {
$saved = new PhabricatorSavedQuery();
$saved->setParameter(
'statuses',
$this->readListFromRequest($request, 'statuses'));
return $saved;
}
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
$query = id(new DrydockResourceQuery());
$statuses = $saved->getParameter('statuses', array());
if ($statuses) {
$query->withStatuses($statuses);
}
return $query;
}
public function buildSearchForm(
AphrontFormView $form,
PhabricatorSavedQuery $saved) {
$statuses = $saved->getParameter('statuses', array());
$status_control = id(new AphrontFormCheckboxControl())
->setLabel(pht('Status'));
foreach (DrydockResourceStatus::getAllStatuses() as $status) {
$status_control->addCheckbox(
'statuses[]',
$status,
DrydockResourceStatus::getNameForStatus($status),
in_array($status, $statuses));
}
$form
->appendChild($status_control);
}
protected function getURI($path) {
return '/drydock/resource/'.$path;
}
public function getBuiltinQueryNames() {
$names = array(
'active' => pht('Active Resources'),
'all' => pht('All Resources'),
);
return $names;
}
public function buildSavedQueryFromBuiltin($query_key) {
$query = $this->newSavedQuery();
$query->setQueryKey($query_key);
switch ($query_key) {
case 'active':
return $query->setParameter(
'statuses',
array(
DrydockResourceStatus::STATUS_PENDING,
DrydockResourceStatus::STATUS_OPEN,
));
case 'all':
return $query;
}
return parent::buildSavedQueryFromBuiltin($query_key);
}
}