mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-02 02:40:58 +01:00
Partially refactor paste search.
Summary: Move some search code from the paste application to the search infrastructure. Test Plan: Check paste searches still work. Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin, AnhNhan Maniphest Tasks: T2625 Differential Revision: https://secure.phabricator.com/D5734
This commit is contained in:
parent
725373386a
commit
0f0c2a6f9e
2 changed files with 26 additions and 18 deletions
|
@ -21,29 +21,20 @@ final class PhabricatorPasteListController extends PhabricatorPasteController {
|
|||
$nav = $this->buildSideNavView($this->filter);
|
||||
$filter = $nav->getSelectedFilter();
|
||||
|
||||
switch ($filter) {
|
||||
case 'my':
|
||||
$saved_query->setParameter('authorPHIDs', array($user->getPHID()));
|
||||
$title = pht('My Pastes');
|
||||
$nodata = pht("You haven't created any Pastes yet.");
|
||||
break;
|
||||
case 'all':
|
||||
$title = pht('All Pastes');
|
||||
$nodata = pht("There are no Pastes yet.");
|
||||
break;
|
||||
}
|
||||
$engine = id(new PhabricatorPasteSearchEngine())
|
||||
->setPasteSearchFilter($filter);
|
||||
$saved_query = $engine->buildSavedQueryFromRequest($request);
|
||||
$query = $engine->buildQueryFromSavedQuery($saved_query);
|
||||
|
||||
$pager = new AphrontCursorPagerView();
|
||||
$pager->readFromRequest($request);
|
||||
$engine = new PhabricatorPasteSearchEngine();
|
||||
$query = $engine->buildQueryFromSavedQuery($saved_query);
|
||||
$pastes = $query->setViewer($request->getUser())
|
||||
->needContent(true)
|
||||
->executeWithCursorPager($pager);
|
||||
|
||||
$list = $this->buildPasteList($pastes);
|
||||
$list->setPager($pager);
|
||||
$list->setNoDataString($nodata);
|
||||
$list->setNoDataString(pht("No results found for this query."));
|
||||
|
||||
$nav->appendChild(
|
||||
array(
|
||||
|
@ -54,7 +45,7 @@ final class PhabricatorPasteListController extends PhabricatorPasteController {
|
|||
->buildApplicationCrumbs($nav)
|
||||
->addCrumb(
|
||||
id(new PhabricatorCrumbView())
|
||||
->setName($title)
|
||||
->setName(pht("Pastes"))
|
||||
->setHref($this->getApplicationURI('filter/'.$filter.'/')));
|
||||
|
||||
$nav->setCrumbs($crumbs);
|
||||
|
@ -62,7 +53,7 @@ final class PhabricatorPasteListController extends PhabricatorPasteController {
|
|||
return $this->buildApplicationPage(
|
||||
$nav,
|
||||
array(
|
||||
'title' => $title,
|
||||
'title' => pht("Pastes"),
|
||||
'device' => true,
|
||||
'dust' => true,
|
||||
));
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
final class PhabricatorPasteSearchEngine
|
||||
extends PhabricatorApplicationSearchEngine {
|
||||
|
||||
protected $filter;
|
||||
|
||||
/**
|
||||
* Create a saved query object from the request.
|
||||
*
|
||||
|
@ -15,9 +17,15 @@ final class PhabricatorPasteSearchEngine
|
|||
* @return The saved query that is built.
|
||||
*/
|
||||
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
||||
$query = new PhabricatorSavedQuery();
|
||||
|
||||
return $query;
|
||||
$saved = new PhabricatorSavedQuery();
|
||||
|
||||
if ($this->filter == "my") {
|
||||
$user = $request->getUser();
|
||||
$saved->setParameter('authorPHIDs', array($user->getPHID()));
|
||||
}
|
||||
|
||||
return $saved;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -45,4 +53,13 @@ final class PhabricatorPasteSearchEngine
|
|||
public function buildSearchForm(PhabricatorSavedQuery $saved_query) {
|
||||
}
|
||||
|
||||
public function setPasteSearchFilter($filter) {
|
||||
$this->filter = $filter;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPasteSearchFilter() {
|
||||
return $this->filter;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue