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);
|
$nav = $this->buildSideNavView($this->filter);
|
||||||
$filter = $nav->getSelectedFilter();
|
$filter = $nav->getSelectedFilter();
|
||||||
|
|
||||||
switch ($filter) {
|
$engine = id(new PhabricatorPasteSearchEngine())
|
||||||
case 'my':
|
->setPasteSearchFilter($filter);
|
||||||
$saved_query->setParameter('authorPHIDs', array($user->getPHID()));
|
$saved_query = $engine->buildSavedQueryFromRequest($request);
|
||||||
$title = pht('My Pastes');
|
$query = $engine->buildQueryFromSavedQuery($saved_query);
|
||||||
$nodata = pht("You haven't created any Pastes yet.");
|
|
||||||
break;
|
|
||||||
case 'all':
|
|
||||||
$title = pht('All Pastes');
|
|
||||||
$nodata = pht("There are no Pastes yet.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$pager = new AphrontCursorPagerView();
|
$pager = new AphrontCursorPagerView();
|
||||||
$pager->readFromRequest($request);
|
$pager->readFromRequest($request);
|
||||||
$engine = new PhabricatorPasteSearchEngine();
|
|
||||||
$query = $engine->buildQueryFromSavedQuery($saved_query);
|
|
||||||
$pastes = $query->setViewer($request->getUser())
|
$pastes = $query->setViewer($request->getUser())
|
||||||
->needContent(true)
|
->needContent(true)
|
||||||
->executeWithCursorPager($pager);
|
->executeWithCursorPager($pager);
|
||||||
|
|
||||||
$list = $this->buildPasteList($pastes);
|
$list = $this->buildPasteList($pastes);
|
||||||
$list->setPager($pager);
|
$list->setPager($pager);
|
||||||
$list->setNoDataString($nodata);
|
$list->setNoDataString(pht("No results found for this query."));
|
||||||
|
|
||||||
$nav->appendChild(
|
$nav->appendChild(
|
||||||
array(
|
array(
|
||||||
|
@ -54,7 +45,7 @@ final class PhabricatorPasteListController extends PhabricatorPasteController {
|
||||||
->buildApplicationCrumbs($nav)
|
->buildApplicationCrumbs($nav)
|
||||||
->addCrumb(
|
->addCrumb(
|
||||||
id(new PhabricatorCrumbView())
|
id(new PhabricatorCrumbView())
|
||||||
->setName($title)
|
->setName(pht("Pastes"))
|
||||||
->setHref($this->getApplicationURI('filter/'.$filter.'/')));
|
->setHref($this->getApplicationURI('filter/'.$filter.'/')));
|
||||||
|
|
||||||
$nav->setCrumbs($crumbs);
|
$nav->setCrumbs($crumbs);
|
||||||
|
@ -62,7 +53,7 @@ final class PhabricatorPasteListController extends PhabricatorPasteController {
|
||||||
return $this->buildApplicationPage(
|
return $this->buildApplicationPage(
|
||||||
$nav,
|
$nav,
|
||||||
array(
|
array(
|
||||||
'title' => $title,
|
'title' => pht("Pastes"),
|
||||||
'device' => true,
|
'device' => true,
|
||||||
'dust' => true,
|
'dust' => true,
|
||||||
));
|
));
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
final class PhabricatorPasteSearchEngine
|
final class PhabricatorPasteSearchEngine
|
||||||
extends PhabricatorApplicationSearchEngine {
|
extends PhabricatorApplicationSearchEngine {
|
||||||
|
|
||||||
|
protected $filter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a saved query object from the request.
|
* Create a saved query object from the request.
|
||||||
*
|
*
|
||||||
|
@ -15,9 +17,15 @@ final class PhabricatorPasteSearchEngine
|
||||||
* @return The saved query that is built.
|
* @return The saved query that is built.
|
||||||
*/
|
*/
|
||||||
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
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 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