1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-20 04:20:55 +01:00

Move even more rendering into SearchEngine

Summary: Ref T4986. I think this is the last of the easy ones, there are about 10 not-quite-so-trivial ones left.

Test Plan:
  - Viewed app results.
  - Created panels.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T4986

Differential Revision: https://secure.phabricator.com/D9025
This commit is contained in:
epriestley 2014-05-09 12:28:02 -07:00
parent 352d9f6b06
commit e6aff100f2
7 changed files with 103 additions and 97 deletions

View file

@ -4895,11 +4895,7 @@ phutil_register_library_map(array(
'PhabricatorSearchAttachController' => 'PhabricatorSearchBaseController',
'PhabricatorSearchBaseController' => 'PhabricatorController',
'PhabricatorSearchConfigOptions' => 'PhabricatorApplicationConfigOptions',
'PhabricatorSearchController' =>
array(
0 => 'PhabricatorSearchBaseController',
1 => 'PhabricatorApplicationSearchResultsControllerInterface',
),
'PhabricatorSearchController' => 'PhabricatorSearchBaseController',
'PhabricatorSearchDAO' => 'PhabricatorLiskDAO',
'PhabricatorSearchDeleteController' => 'PhabricatorSearchBaseController',
'PhabricatorSearchDocument' => 'PhabricatorSearchDAO',
@ -5524,11 +5520,7 @@ phutil_register_library_map(array(
'ReleephProductEditController' => 'ReleephProductController',
'ReleephProductEditor' => 'PhabricatorApplicationTransactionEditor',
'ReleephProductHistoryController' => 'ReleephProductController',
'ReleephProductListController' =>
array(
0 => 'ReleephController',
1 => 'PhabricatorApplicationSearchResultsControllerInterface',
),
'ReleephProductListController' => 'ReleephController',
'ReleephProductQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'ReleephProductSearchEngine' => 'PhabricatorApplicationSearchEngine',
'ReleephProductTransaction' => 'PhabricatorApplicationTransaction',

View file

@ -1,6 +1,7 @@
<?php
final class DiffusionPushLogListController extends DiffusionPushLogController {
final class DiffusionPushLogListController extends DiffusionPushLogController
implements PhabricatorApplicationSearchResultsControllerInterface {
private $queryKey;

View file

@ -1,7 +1,6 @@
<?php
final class ReleephProductListController extends ReleephController
implements PhabricatorApplicationSearchResultsControllerInterface {
final class ReleephProductListController extends ReleephController {
private $queryKey;
@ -23,47 +22,6 @@ final class ReleephProductListController extends ReleephController
return $this->delegateToController($controller);
}
public function renderResultsList(
array $products,
PhabricatorSavedQuery $query) {
assert_instances_of($products, 'ReleephProject');
$viewer = $this->getRequest()->getUser();
$list = id(new PHUIObjectItemListView())
->setUser($viewer);
foreach ($products as $product) {
$id = $product->getID();
$item = id(new PHUIObjectItemView())
->setHeader($product->getName())
->setHref($this->getApplicationURI("product/{$id}/"));
if (!$product->getIsActive()) {
$item->setDisabled(true);
$item->addIcon('none', pht('Inactive'));
}
$repo = $product->getRepository();
$item->addAttribute(
phutil_tag(
'a',
array(
'href' => '/diffusion/'.$repo->getCallsign().'/',
),
'r'.$repo->getCallsign()));
$arc = $product->getArcanistProject();
if ($arc) {
$item->addAttribute($arc->getName());
}
$list->addItem($item);
}
return $list;
}
public function buildApplicationCrumbs() {
$crumbs = parent::buildApplicationCrumbs();

View file

@ -3,6 +3,10 @@
final class ReleephProductSearchEngine
extends PhabricatorApplicationSearchEngine {
public function getApplicationClassName() {
return 'PhabricatorApplicationReleeph';
}
public function buildSavedQueryFromRequest(AphrontRequest $request) {
$saved = new PhabricatorSavedQuery();
@ -83,4 +87,48 @@ final class ReleephProductSearchEngine
);
}
protected function renderResultList(
array $products,
PhabricatorSavedQuery $query,
array $handles) {
assert_instances_of($products, 'ReleephProject');
$viewer = $this->requireViewer();
$list = id(new PHUIObjectItemListView())
->setUser($viewer);
foreach ($products as $product) {
$id = $product->getID();
$item = id(new PHUIObjectItemView())
->setHeader($product->getName())
->setHref($this->getApplicationURI("product/{$id}/"));
if (!$product->getIsActive()) {
$item->setDisabled(true);
$item->addIcon('none', pht('Inactive'));
}
$repo = $product->getRepository();
$item->addAttribute(
phutil_tag(
'a',
array(
'href' => '/diffusion/'.$repo->getCallsign().'/',
),
'r'.$repo->getCallsign()));
$arc = $product->getArcanistProject();
if ($arc) {
$item->addAttribute($arc->getName());
}
$list->addItem($item);
}
return $list;
}
}

View file

@ -3,6 +3,10 @@
final class PhabricatorRepositoryPushLogSearchEngine
extends PhabricatorApplicationSearchEngine {
public function getApplicationClassName() {
return 'PhabricatorApplicationDiffusion';
}
public function buildSavedQueryFromRequest(AphrontRequest $request) {
$saved = new PhabricatorSavedQuery();

View file

@ -1,8 +1,7 @@
<?php
final class PhabricatorSearchController
extends PhabricatorSearchBaseController
implements PhabricatorApplicationSearchResultsControllerInterface {
extends PhabricatorSearchBaseController {
private $queryKey;
@ -96,45 +95,4 @@ final class PhabricatorSearchController
return $nav;
}
public function renderResultsList(
array $results,
PhabricatorSavedQuery $query) {
$viewer = $this->getRequest()->getUser();
if ($results) {
$objects = id(new PhabricatorObjectQuery())
->setViewer($viewer)
->withPHIDs(mpull($results, 'getPHID'))
->execute();
$output = array();
foreach ($results as $phid => $handle) {
$view = id(new PhabricatorSearchResultView())
->setHandle($handle)
->setQuery($query)
->setObject(idx($objects, $phid));
$output[] = $view->render();
}
$results = phutil_tag_div(
'phabricator-search-result-list',
$output);
} else {
$results = phutil_tag_div(
'phabricator-search-result-list',
phutil_tag(
'p',
array('class' => 'phabricator-search-no-results'),
pht('No search results.')));
}
return id(new PHUIBoxView())
->addMargin(PHUI::MARGIN_LARGE)
->addPadding(PHUI::PADDING_LARGE)
->setBorder(true)
->appendChild($results)
->addClass('phabricator-search-result-box');
}
}

View file

@ -3,6 +3,10 @@
final class PhabricatorSearchApplicationSearchEngine
extends PhabricatorApplicationSearchEngine {
public function getApplicationClassName() {
return 'PhabricatorApplicationSearch';
}
public function buildSavedQueryFromRequest(AphrontRequest $request) {
$saved = new PhabricatorSavedQuery();
@ -233,5 +237,46 @@ final class PhabricatorSearchApplicationSearchEngine
return true;
}
protected function renderResultList(
array $results,
PhabricatorSavedQuery $query,
array $handles) {
$viewer = $this->requireViewer();
if ($results) {
$objects = id(new PhabricatorObjectQuery())
->setViewer($viewer)
->withPHIDs(mpull($results, 'getPHID'))
->execute();
$output = array();
foreach ($results as $phid => $handle) {
$view = id(new PhabricatorSearchResultView())
->setHandle($handle)
->setQuery($query)
->setObject(idx($objects, $phid));
$output[] = $view->render();
}
$results = phutil_tag_div(
'phabricator-search-result-list',
$output);
} else {
$results = phutil_tag_div(
'phabricator-search-result-list',
phutil_tag(
'p',
array('class' => 'phabricator-search-no-results'),
pht('No search results.')));
}
return id(new PHUIBoxView())
->addMargin(PHUI::MARGIN_LARGE)
->addPadding(PHUI::PADDING_LARGE)
->setBorder(true)
->appendChild($results)
->addClass('phabricator-search-result-box');
}
}