mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-20 20:40:56 +01:00
Use ApplicationSearch for Drydock Blueprints
Summary: Ref T2015. This turns the side nav into a bigger mess for now, but uses ApplicationSearch for blueprints. Test Plan: Queried blueprints in the UI. Reviewers: btrahan Reviewed By: btrahan CC: hach-que, aran Maniphest Tasks: T2015 Differential Revision: https://secure.phabricator.com/D7829
This commit is contained in:
parent
1a82743491
commit
fa00e86f87
7 changed files with 101 additions and 48 deletions
|
@ -642,6 +642,7 @@ phutil_register_library_map(array(
|
||||||
'DrydockBlueprintListController' => 'applications/drydock/controller/DrydockBlueprintListController.php',
|
'DrydockBlueprintListController' => 'applications/drydock/controller/DrydockBlueprintListController.php',
|
||||||
'DrydockBlueprintQuery' => 'applications/drydock/query/DrydockBlueprintQuery.php',
|
'DrydockBlueprintQuery' => 'applications/drydock/query/DrydockBlueprintQuery.php',
|
||||||
'DrydockBlueprintScopeGuard' => 'applications/drydock/util/DrydockBlueprintScopeGuard.php',
|
'DrydockBlueprintScopeGuard' => 'applications/drydock/util/DrydockBlueprintScopeGuard.php',
|
||||||
|
'DrydockBlueprintSearchEngine' => 'applications/drydock/query/DrydockBlueprintSearchEngine.php',
|
||||||
'DrydockBlueprintViewController' => 'applications/drydock/controller/DrydockBlueprintViewController.php',
|
'DrydockBlueprintViewController' => 'applications/drydock/controller/DrydockBlueprintViewController.php',
|
||||||
'DrydockCommandInterface' => 'applications/drydock/interface/command/DrydockCommandInterface.php',
|
'DrydockCommandInterface' => 'applications/drydock/interface/command/DrydockCommandInterface.php',
|
||||||
'DrydockConstants' => 'applications/drydock/constants/DrydockConstants.php',
|
'DrydockConstants' => 'applications/drydock/constants/DrydockConstants.php',
|
||||||
|
@ -3042,8 +3043,13 @@ phutil_register_library_map(array(
|
||||||
),
|
),
|
||||||
'DrydockBlueprintCreateController' => 'DrydockController',
|
'DrydockBlueprintCreateController' => 'DrydockController',
|
||||||
'DrydockBlueprintEditController' => 'DrydockController',
|
'DrydockBlueprintEditController' => 'DrydockController',
|
||||||
'DrydockBlueprintListController' => 'DrydockController',
|
'DrydockBlueprintListController' =>
|
||||||
|
array(
|
||||||
|
0 => 'DrydockController',
|
||||||
|
1 => 'PhabricatorApplicationSearchResultsControllerInterface',
|
||||||
|
),
|
||||||
'DrydockBlueprintQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
'DrydockBlueprintQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||||
|
'DrydockBlueprintSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||||
'DrydockBlueprintViewController' => 'DrydockController',
|
'DrydockBlueprintViewController' => 'DrydockController',
|
||||||
'DrydockCommandInterface' => 'DrydockInterface',
|
'DrydockCommandInterface' => 'DrydockInterface',
|
||||||
'DrydockController' => 'PhabricatorController',
|
'DrydockController' => 'PhabricatorController',
|
||||||
|
|
|
@ -35,7 +35,7 @@ final class PhabricatorApplicationDrydock extends PhabricatorApplication {
|
||||||
'/drydock/' => array(
|
'/drydock/' => array(
|
||||||
'' => 'DrydockResourceListController',
|
'' => 'DrydockResourceListController',
|
||||||
'blueprint/' => array(
|
'blueprint/' => array(
|
||||||
'' => 'DrydockBlueprintListController',
|
'(?:query/(?P<queryKey>[^/]+)/)?' => 'DrydockBlueprintListController',
|
||||||
'(?P<id>[1-9]\d*)/' => 'DrydockBlueprintViewController',
|
'(?P<id>[1-9]\d*)/' => 'DrydockBlueprintViewController',
|
||||||
'create/' => 'DrydockBlueprintCreateController',
|
'create/' => 'DrydockBlueprintCreateController',
|
||||||
'edit/(?P<id>[1-9]\d*)/' => 'DrydockBlueprintEditController',
|
'edit/(?P<id>[1-9]\d*)/' => 'DrydockBlueprintEditController',
|
||||||
|
|
|
@ -1,52 +1,34 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
final class DrydockBlueprintListController extends DrydockController {
|
final class DrydockBlueprintListController 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)
|
||||||
$title = pht('Blueprints');
|
->setSearchEngine(new DrydockBlueprintSearchEngine())
|
||||||
|
->setNavigation($this->buildSideNav());
|
||||||
$blueprint_header = id(new PHUIHeaderView())
|
|
||||||
->setHeader($title);
|
|
||||||
|
|
||||||
$blueprints = id(new DrydockBlueprintQuery())
|
|
||||||
->setViewer($user)
|
|
||||||
->execute();
|
|
||||||
|
|
||||||
$blueprint_list = $this->buildBlueprintListView($blueprints);
|
|
||||||
|
|
||||||
$crumbs = $this->buildApplicationCrumbs();
|
|
||||||
$crumbs->addTextCrumb($title, $request->getRequestURI());
|
|
||||||
|
|
||||||
$crumbs->addAction(
|
|
||||||
id(new PHUIListItemView())
|
|
||||||
->setName(pht('New Blueprint'))
|
|
||||||
->setHref($this->getApplicationURI('blueprint/create/'))
|
|
||||||
->setIcon('create'));
|
|
||||||
|
|
||||||
$nav = $this->buildSideNav('blueprint');
|
|
||||||
$nav->setCrumbs($crumbs);
|
|
||||||
$nav->appendChild(
|
|
||||||
array(
|
|
||||||
$blueprint_header,
|
|
||||||
$blueprint_list
|
|
||||||
));
|
|
||||||
|
|
||||||
return $this->buildApplicationPage(
|
|
||||||
$nav,
|
|
||||||
array(
|
|
||||||
'title' => $title,
|
|
||||||
'device' => true,
|
|
||||||
));
|
|
||||||
|
|
||||||
|
return $this->delegateToController($controller);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function buildBlueprintListView(array $blueprints) {
|
public function renderResultsList(
|
||||||
|
array $blueprints,
|
||||||
|
PhabricatorSavedQuery $query) {
|
||||||
assert_instances_of($blueprints, 'DrydockBlueprint');
|
assert_instances_of($blueprints, 'DrydockBlueprint');
|
||||||
|
|
||||||
$user = $this->getRequest()->getUser();
|
$viewer = $this->getRequest()->getUser();
|
||||||
$view = new PHUIObjectItemListView();
|
$view = new PHUIObjectItemListView();
|
||||||
|
|
||||||
foreach ($blueprints as $blueprint) {
|
foreach ($blueprints as $blueprint) {
|
||||||
|
|
|
@ -5,13 +5,18 @@ abstract class DrydockController extends PhabricatorController {
|
||||||
final protected function buildSideNav($selected = null) {
|
final protected function buildSideNav($selected = null) {
|
||||||
$nav = new AphrontSideNavFilterView();
|
$nav = new AphrontSideNavFilterView();
|
||||||
$nav->setBaseURI(new PhutilURI('/drydock/'));
|
$nav->setBaseURI(new PhutilURI('/drydock/'));
|
||||||
$nav->addFilter('blueprint', 'Blueprints');
|
|
||||||
$nav->addFilter('resource', 'Resources');
|
id(new DrydockBlueprintSearchEngine())
|
||||||
|
->setViewer($this->getRequest()->getUser())
|
||||||
|
->addNavigationItems($nav->getMenu(), pht('Blueprints'));
|
||||||
|
|
||||||
id(new DrydockLeaseSearchEngine())
|
id(new DrydockLeaseSearchEngine())
|
||||||
->setViewer($this->getRequest()->getUser())
|
->setViewer($this->getRequest()->getUser())
|
||||||
->addNavigationItems($nav->getMenu(), pht('Leases'));
|
->addNavigationItems($nav->getMenu(), pht('Leases'));
|
||||||
|
|
||||||
|
$nav->addLabel(pht('Resources'));
|
||||||
|
$nav->addFilter('resource', 'Resources');
|
||||||
|
|
||||||
$nav->addLabel(pht('Logs'));
|
$nav->addLabel(pht('Logs'));
|
||||||
$nav->addFilter('log', 'Logs');
|
$nav->addFilter('log', 'Logs');
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class DrydockBlueprintSearchEngine
|
||||||
|
extends PhabricatorApplicationSearchEngine {
|
||||||
|
|
||||||
|
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
||||||
|
$saved = new PhabricatorSavedQuery();
|
||||||
|
|
||||||
|
return $saved;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
||||||
|
$query = id(new DrydockBlueprintQuery());
|
||||||
|
|
||||||
|
return $query;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function buildSearchForm(
|
||||||
|
AphrontFormView $form,
|
||||||
|
PhabricatorSavedQuery $saved) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getURI($path) {
|
||||||
|
return '/drydock/blueprint/'.$path;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBuiltinQueryNames() {
|
||||||
|
$names = array(
|
||||||
|
'all' => pht('All Blueprints'),
|
||||||
|
);
|
||||||
|
|
||||||
|
return $names;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function buildSavedQueryFromBuiltin($query_key) {
|
||||||
|
$query = $this->newSavedQuery();
|
||||||
|
$query->setQueryKey($query_key);
|
||||||
|
|
||||||
|
switch ($query_key) {
|
||||||
|
case 'all':
|
||||||
|
return $query;
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent::buildSavedQueryFromBuiltin($query_key);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -154,8 +154,8 @@ final class PhabricatorApplicationSearchController
|
||||||
}
|
}
|
||||||
|
|
||||||
$nav->selectFilter(
|
$nav->selectFilter(
|
||||||
'query/'.$saved_query->getQueryKey(),
|
$engine->getNavPrefix().'query/'.$saved_query->getQueryKey(),
|
||||||
'query/advanced');
|
$engine->getNavPrefix().'query/advanced');
|
||||||
|
|
||||||
$form = id(new AphrontFormView())
|
$form = id(new AphrontFormView())
|
||||||
->setUser($user);
|
->setUser($user);
|
||||||
|
|
|
@ -107,6 +107,9 @@ abstract class PhabricatorApplicationSearchEngine {
|
||||||
->setEngineClassName(get_class($this));
|
->setEngineClassName(get_class($this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getNavPrefix() {
|
||||||
|
return get_class($this).':';
|
||||||
|
}
|
||||||
|
|
||||||
public function addNavigationItems(PHUIListView $menu, $label = null) {
|
public function addNavigationItems(PHUIListView $menu, $label = null) {
|
||||||
$viewer = $this->requireViewer();
|
$viewer = $this->requireViewer();
|
||||||
|
@ -114,21 +117,30 @@ abstract class PhabricatorApplicationSearchEngine {
|
||||||
$menu->newLabel(coalesce($label, pht('Queries')));
|
$menu->newLabel(coalesce($label, pht('Queries')));
|
||||||
|
|
||||||
$named_queries = $this->loadEnabledNamedQueries();
|
$named_queries = $this->loadEnabledNamedQueries();
|
||||||
|
$prefix = $this->getNavPrefix();
|
||||||
|
|
||||||
foreach ($named_queries as $query) {
|
foreach ($named_queries as $query) {
|
||||||
$key = $query->getQueryKey();
|
$key = $query->getQueryKey();
|
||||||
$uri = $this->getQueryResultsPageURI($key);
|
$uri = $this->getQueryResultsPageURI($key);
|
||||||
$menu->newLink($query->getQueryName(), $uri, 'query/'.$key);
|
$menu->newLink(
|
||||||
|
$query->getQueryName(),
|
||||||
|
$uri,
|
||||||
|
$prefix.'query/'.$key);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($viewer->isLoggedIn()) {
|
if ($viewer->isLoggedIn()) {
|
||||||
$manage_uri = $this->getQueryManagementURI();
|
$manage_uri = $this->getQueryManagementURI();
|
||||||
$menu->newLink(pht('Edit Queries...'), $manage_uri, 'query/edit');
|
$menu->newLink(
|
||||||
|
pht('Edit Queries...'),
|
||||||
|
$manage_uri,
|
||||||
|
$prefix.'query/edit');
|
||||||
}
|
}
|
||||||
|
|
||||||
$menu->newLabel(pht('Search'));
|
$menu->newLabel(pht('Search'));
|
||||||
$advanced_uri = $this->getQueryResultsPageURI('advanced');
|
$advanced_uri = $this->getQueryResultsPageURI('advanced');
|
||||||
$menu->newLink(pht('Advanced Search'), $advanced_uri, 'query/advanced');
|
$menu->newLink(
|
||||||
|
pht('Advanced Search'),
|
||||||
|
$advanced_uri, $prefix.'query/advanced');
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue