1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-30 01:10:58 +01:00

Use ApplicationSearch for DrydockLog

Summary: Ref T2015. Move logs over to ApplicationSearch.

Test Plan: Browsed logs in UI.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2015

Differential Revision: https://secure.phabricator.com/D7832
This commit is contained in:
epriestley 2013-12-26 12:30:29 -08:00
parent 3db5833622
commit 9c9a9a919e
6 changed files with 102 additions and 66 deletions

View file

@ -660,8 +660,9 @@ phutil_register_library_map(array(
'DrydockLocalCommandInterface' => 'applications/drydock/interface/command/DrydockLocalCommandInterface.php',
'DrydockLocalHostBlueprintImplementation' => 'applications/drydock/blueprint/DrydockLocalHostBlueprintImplementation.php',
'DrydockLog' => 'applications/drydock/storage/DrydockLog.php',
'DrydockLogController' => 'applications/drydock/controller/DrydockLogController.php',
'DrydockLogListController' => 'applications/drydock/controller/DrydockLogListController.php',
'DrydockLogQuery' => 'applications/drydock/query/DrydockLogQuery.php',
'DrydockLogSearchEngine' => 'applications/drydock/query/DrydockLogSearchEngine.php',
'DrydockManagementCloseWorkflow' => 'applications/drydock/management/DrydockManagementCloseWorkflow.php',
'DrydockManagementCreateResourceWorkflow' => 'applications/drydock/management/DrydockManagementCreateResourceWorkflow.php',
'DrydockManagementLeaseWorkflow' => 'applications/drydock/management/DrydockManagementLeaseWorkflow.php',
@ -3073,9 +3074,18 @@ phutil_register_library_map(array(
'DrydockLeaseViewController' => 'DrydockController',
'DrydockLocalCommandInterface' => 'DrydockCommandInterface',
'DrydockLocalHostBlueprintImplementation' => 'DrydockBlueprintImplementation',
'DrydockLog' => 'DrydockDAO',
'DrydockLogController' => 'DrydockController',
'DrydockLogQuery' => 'PhabricatorOffsetPagedQuery',
'DrydockLog' =>
array(
0 => 'DrydockDAO',
1 => 'PhabricatorPolicyInterface',
),
'DrydockLogListController' =>
array(
0 => 'DrydockController',
1 => 'PhabricatorApplicationSearchResultsControllerInterface',
),
'DrydockLogQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'DrydockLogSearchEngine' => 'PhabricatorApplicationSearchEngine',
'DrydockManagementCloseWorkflow' => 'DrydockManagementWorkflow',
'DrydockManagementCreateResourceWorkflow' => 'DrydockManagementWorkflow',
'DrydockManagementLeaseWorkflow' => 'DrydockManagementWorkflow',

View file

@ -50,7 +50,9 @@ final class PhabricatorApplicationDrydock extends PhabricatorApplication {
'(?P<id>[1-9]\d*)/' => 'DrydockLeaseViewController',
'(?P<id>[1-9]\d*)/release/' => 'DrydockLeaseReleaseController',
),
'log/' => 'DrydockLogController',
'log/' => array(
'(?:query/(?P<queryKey>[^/]+)/)?' => 'DrydockLogListController',
),
),
);
}

View file

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

View file

@ -1,59 +0,0 @@
<?php
final class DrydockLogController extends DrydockController {
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$nav = $this->buildSideNav('log');
$query = id(new DrydockLogQuery())
->setViewer($user);
$resource_ids = $request->getStrList('resource');
if ($resource_ids) {
$query->withResourceIDs($resource_ids);
}
$lease_ids = $request->getStrList('lease');
if ($lease_ids) {
$query->withLeaseIDs($lease_ids);
}
$pager = new AphrontPagerView();
$pager->setPageSize(500);
$pager->setOffset($request->getInt('offset'));
$pager->setURI($request->getRequestURI(), 'offset');
$logs = $query->executeWithOffsetPager($pager);
$title = pht('Logs');
$header = id(new PHUIHeaderView())
->setHeader($title);
$table = $this->buildLogTableView($logs);
$table->appendChild($pager);
$nav->appendChild(
array(
$header,
$table,
$pager,
));
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb($title, $this->getApplicationURI('/logs/'));
$nav->setCrumbs($crumbs);
return $this->buildApplicationPage(
$nav,
array(
'title' => $title,
'device' => true,
));
}
}

View file

@ -0,0 +1,34 @@
<?php
final class DrydockLogListController 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();
$controller = id(new PhabricatorApplicationSearchController($request))
->setQueryKey($this->queryKey)
->setSearchEngine(new DrydockLogSearchEngine())
->setNavigation($this->buildSideNav());
return $this->delegateToController($controller);
}
public function renderResultsList(
array $logs,
PhabricatorSavedQuery $query) {
assert_instances_of($logs, 'DrydockLog');
return $this->buildLogTableView($logs);
}
}

View file

@ -0,0 +1,48 @@
<?php
final class DrydockLogSearchEngine
extends PhabricatorApplicationSearchEngine {
public function buildSavedQueryFromRequest(AphrontRequest $request) {
$saved = new PhabricatorSavedQuery();
return $saved;
}
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
$query = id(new DrydockLogQuery());
return $query;
}
public function buildSearchForm(
AphrontFormView $form,
PhabricatorSavedQuery $saved) {
}
protected function getURI($path) {
return '/drydock/log/'.$path;
}
public function getBuiltinQueryNames() {
$names = array(
'all' => pht('All Logs'),
);
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);
}
}