mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-22 14:52:41 +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:
parent
fa00e86f87
commit
bc3912e641
6 changed files with 130 additions and 42 deletions
|
@ -676,6 +676,7 @@ phutil_register_library_map(array(
|
|||
'DrydockResourceCloseController' => 'applications/drydock/controller/DrydockResourceCloseController.php',
|
||||
'DrydockResourceListController' => 'applications/drydock/controller/DrydockResourceListController.php',
|
||||
'DrydockResourceQuery' => 'applications/drydock/query/DrydockResourceQuery.php',
|
||||
'DrydockResourceSearchEngine' => 'applications/drydock/query/DrydockResourceSearchEngine.php',
|
||||
'DrydockResourceStatus' => 'applications/drydock/constants/DrydockResourceStatus.php',
|
||||
'DrydockResourceViewController' => 'applications/drydock/controller/DrydockResourceViewController.php',
|
||||
'DrydockSFTPFilesystemInterface' => 'applications/drydock/interface/filesystem/DrydockSFTPFilesystemInterface.php',
|
||||
|
@ -3091,8 +3092,13 @@ phutil_register_library_map(array(
|
|||
1 => 'PhabricatorPolicyInterface',
|
||||
),
|
||||
'DrydockResourceCloseController' => 'DrydockController',
|
||||
'DrydockResourceListController' => 'DrydockController',
|
||||
'DrydockResourceListController' =>
|
||||
array(
|
||||
0 => 'DrydockController',
|
||||
1 => 'PhabricatorApplicationSearchResultsControllerInterface',
|
||||
),
|
||||
'DrydockResourceQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
'DrydockResourceSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||
'DrydockResourceStatus' => 'DrydockConstants',
|
||||
'DrydockResourceViewController' => 'DrydockController',
|
||||
'DrydockSFTPFilesystemInterface' => 'DrydockFilesystemInterface',
|
||||
|
|
|
@ -41,7 +41,7 @@ final class PhabricatorApplicationDrydock extends PhabricatorApplication {
|
|||
'edit/(?P<id>[1-9]\d*)/' => 'DrydockBlueprintEditController',
|
||||
),
|
||||
'resource/' => array(
|
||||
'' => 'DrydockResourceListController',
|
||||
'(?:query/(?P<queryKey>[^/]+)/)?' => 'DrydockResourceListController',
|
||||
'(?P<id>[1-9]\d*)/' => 'DrydockResourceViewController',
|
||||
'(?P<id>[1-9]\d*)/close/' => 'DrydockResourceCloseController',
|
||||
),
|
||||
|
|
|
@ -9,15 +9,25 @@ final class DrydockResourceStatus extends DrydockConstants {
|
|||
const STATUS_DESTROYED = 4;
|
||||
|
||||
public static function getNameForStatus($status) {
|
||||
static $map = array(
|
||||
self::STATUS_PENDING => 'Pending',
|
||||
self::STATUS_OPEN => 'Open',
|
||||
self::STATUS_CLOSED => 'Closed',
|
||||
self::STATUS_BROKEN => 'Broken',
|
||||
self::STATUS_DESTROYED => 'Destroyed',
|
||||
$map = array(
|
||||
self::STATUS_PENDING => pht('Pending'),
|
||||
self::STATUS_OPEN => pht('Open'),
|
||||
self::STATUS_CLOSED => pht('Closed'),
|
||||
self::STATUS_BROKEN => pht('Broken'),
|
||||
self::STATUS_DESTROYED => pht('Destroyed'),
|
||||
);
|
||||
|
||||
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,
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,8 +14,9 @@ abstract class DrydockController extends PhabricatorController {
|
|||
->setViewer($this->getRequest()->getUser())
|
||||
->addNavigationItems($nav->getMenu(), pht('Leases'));
|
||||
|
||||
$nav->addLabel(pht('Resources'));
|
||||
$nav->addFilter('resource', 'Resources');
|
||||
id(new DrydockResourceSearchEngine())
|
||||
->setViewer($this->getRequest()->getUser())
|
||||
->addNavigationItems($nav->getMenu(), pht('Resources'));
|
||||
|
||||
$nav->addLabel(pht('Logs'));
|
||||
$nav->addFilter('log', 'Logs');
|
||||
|
|
|
@ -1,43 +1,34 @@
|
|||
<?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() {
|
||||
$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())
|
||||
->setHeader($title);
|
||||
|
||||
$pager = new AphrontPagerView();
|
||||
$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,
|
||||
));
|
||||
public function renderResultsList(
|
||||
array $resources,
|
||||
PhabricatorSavedQuery $query) {
|
||||
assert_instances_of($resources, 'DrydockResource');
|
||||
|
||||
return $this->buildResourceListView($resources);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue