1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 23:02:42 +01:00

Add advanced search ability to paste.

Summary: Partially complete advanced search (building a form that might be right).

Test Plan: Check that form appears for advanced filter.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin, AnhNhan

Differential Revision: https://secure.phabricator.com/D5807
This commit is contained in:
Bryan Cuccioli 2013-05-06 07:28:49 -07:00 committed by epriestley
parent c87ff2622b
commit e7904ed59d
5 changed files with 84 additions and 7 deletions

View file

@ -36,6 +36,7 @@ final class PhabricatorApplicationPaste extends PhabricatorApplication {
'create/' => 'PhabricatorPasteEditController',
'edit/(?P<id>[1-9]\d*)/' => 'PhabricatorPasteEditController',
'filter/(?P<filter>\w+)/' => 'PhabricatorPasteListController',
'query/(?P<queryKey>\w+)/'=> 'PhabricatorPasteListController',
),
);
}

View file

@ -18,6 +18,7 @@ abstract class PhabricatorPasteController extends PhabricatorController {
if ($user->isLoggedIn()) {
$nav->addFilter('my', pht('My Pastes'));
}
$nav->addFilter('advanced', pht('Advanced Search'));
$nav->selectFilter($filter, 'all');

View file

@ -7,24 +7,51 @@ final class PhabricatorPasteListController extends PhabricatorPasteController {
}
private $filter;
private $queryKey;
public function willProcessRequest(array $data) {
$this->filter = idx($data, 'filter');
$this->queryKey = idx($data, 'queryKey');
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$saved_query = new PhabricatorSavedQuery();
if ($request->isFormPost()) {
$saved = id(new PhabricatorPasteSearchEngine())
->buildSavedQueryFromRequest($request);
if (count($saved->getParameter('authorPHIDs')) == 0) {
return id(new AphrontRedirectResponse())
->setURI('/paste/filter/advanced/');
}
return id(new AphrontRedirectResponse())
->setURI('/paste/query/'.$saved->getQueryKey().'/');
}
$nav = $this->buildSideNavView($this->filter);
$filter = $nav->getSelectedFilter();
$saved_query = new PhabricatorSavedQuery();
$engine = id(new PhabricatorPasteSearchEngine())
->setPasteSearchFilter($filter);
$saved_query = $engine->buildSavedQueryFromRequest($request);
$query = $engine->buildQueryFromSavedQuery($saved_query);
->setPasteSearchFilter($filter)
->setPasteSearchUser($request->getUser());
if ($this->queryKey !== null) {
$saved_query = id(new PhabricatorSavedQuery())->loadOneWhere(
'queryKey = %s',
$this->queryKey);
if (!$saved_query) {
return new Aphront404Response();
}
$query = id(new PhabricatorPasteSearchEngine())
->buildQueryFromSavedQuery($saved_query);
} else {
$saved_query = $engine->buildSavedQueryFromRequest($request);
$query = $engine->buildQueryFromSavedQuery($saved_query);
}
$pager = new AphrontCursorPagerView();
$pager->readFromRequest($request);
@ -36,6 +63,14 @@ final class PhabricatorPasteListController extends PhabricatorPasteController {
$list->setPager($pager);
$list->setNoDataString(pht("No results found for this query."));
if ($this->queryKey !== null || $filter == "advanced") {
$form = $engine->buildSearchForm($saved_query);
$nav->appendChild(
array(
$form
));
}
$nav->appendChild(
array(
$list,

View file

@ -9,6 +9,7 @@ final class PhabricatorPasteSearchEngine
extends PhabricatorApplicationSearchEngine {
protected $filter;
protected $user;
/**
* Create a saved query object from the request.
@ -23,6 +24,19 @@ final class PhabricatorPasteSearchEngine
if ($this->filter == "my") {
$user = $request->getUser();
$saved->setParameter('authorPHIDs', array($user->getPHID()));
} else {
$data = $request->getRequestData();
if (array_key_exists('set_users', $data)) {
$saved->setParameter('authorPHIDs', $data['set_users']);
}
}
try {
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
$saved->save();
unset($unguarded);
} catch (AphrontQueryDuplicateKeyException $ex) {
// Ignore, this is just a repeated search.
}
return $saved;
@ -48,9 +62,30 @@ final class PhabricatorPasteSearchEngine
* Builds the search form using the request.
*
* @param PhabricatorSavedQuery The query to populate the form with.
* @return void
* @return AphrontFormView The built form.
*/
public function buildSearchForm(PhabricatorSavedQuery $saved_query) {
$phids = $saved_query->getParameter('authorPHIDs', array());
$handles = id(new PhabricatorObjectHandleData($phids))
->setViewer($this->user)
->loadHandles();
$users_searched = mpull($handles, 'getFullName', 'getPHID');
$form = id(new AphrontFormView())
->setUser($this->user);
$form->appendChild(
id(new AphrontFormTokenizerControl())
->setDatasource('/typeahead/common/searchowner/')
->setName('set_users')
->setLabel(pht('Users'))
->setValue($users_searched));
$form->appendChild(
id(new AphrontFormSubmitControl())
->setValue(pht('Filter Pastes')));
return $form;
}
public function setPasteSearchFilter($filter) {
@ -62,4 +97,9 @@ final class PhabricatorPasteSearchEngine
return $this->filter;
}
public function setPasteSearchUser($user) {
$this->user = $user;
return $this;
}
}

View file

@ -26,11 +26,11 @@ final class PhabricatorSavedQuery extends PhabricatorSearchDAO {
}
public function save() {
if ($this->getEngineClass() === null) {
if ($this->getEngineClassName() === null) {
throw new Exception(pht("Engine class is null."));
}
$serial = $this->getEngineClass().serialize($this->parameters);
$serial = $this->getEngineClassName().serialize($this->parameters);
$this->queryKey = PhabricatorHash::digestForIndex($serial);
return parent::save();