mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-26 16:52:41 +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:
parent
c87ff2622b
commit
e7904ed59d
5 changed files with 84 additions and 7 deletions
|
@ -36,6 +36,7 @@ final class PhabricatorApplicationPaste extends PhabricatorApplication {
|
||||||
'create/' => 'PhabricatorPasteEditController',
|
'create/' => 'PhabricatorPasteEditController',
|
||||||
'edit/(?P<id>[1-9]\d*)/' => 'PhabricatorPasteEditController',
|
'edit/(?P<id>[1-9]\d*)/' => 'PhabricatorPasteEditController',
|
||||||
'filter/(?P<filter>\w+)/' => 'PhabricatorPasteListController',
|
'filter/(?P<filter>\w+)/' => 'PhabricatorPasteListController',
|
||||||
|
'query/(?P<queryKey>\w+)/'=> 'PhabricatorPasteListController',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ abstract class PhabricatorPasteController extends PhabricatorController {
|
||||||
if ($user->isLoggedIn()) {
|
if ($user->isLoggedIn()) {
|
||||||
$nav->addFilter('my', pht('My Pastes'));
|
$nav->addFilter('my', pht('My Pastes'));
|
||||||
}
|
}
|
||||||
|
$nav->addFilter('advanced', pht('Advanced Search'));
|
||||||
|
|
||||||
$nav->selectFilter($filter, 'all');
|
$nav->selectFilter($filter, 'all');
|
||||||
|
|
||||||
|
|
|
@ -7,24 +7,51 @@ final class PhabricatorPasteListController extends PhabricatorPasteController {
|
||||||
}
|
}
|
||||||
|
|
||||||
private $filter;
|
private $filter;
|
||||||
|
private $queryKey;
|
||||||
|
|
||||||
public function willProcessRequest(array $data) {
|
public function willProcessRequest(array $data) {
|
||||||
$this->filter = idx($data, 'filter');
|
$this->filter = idx($data, 'filter');
|
||||||
|
$this->queryKey = idx($data, 'queryKey');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function processRequest() {
|
public function processRequest() {
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
$user = $request->getUser();
|
$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);
|
$nav = $this->buildSideNavView($this->filter);
|
||||||
$filter = $nav->getSelectedFilter();
|
$filter = $nav->getSelectedFilter();
|
||||||
|
|
||||||
|
$saved_query = new PhabricatorSavedQuery();
|
||||||
$engine = id(new PhabricatorPasteSearchEngine())
|
$engine = id(new PhabricatorPasteSearchEngine())
|
||||||
->setPasteSearchFilter($filter);
|
->setPasteSearchFilter($filter)
|
||||||
$saved_query = $engine->buildSavedQueryFromRequest($request);
|
->setPasteSearchUser($request->getUser());
|
||||||
$query = $engine->buildQueryFromSavedQuery($saved_query);
|
|
||||||
|
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 = new AphrontCursorPagerView();
|
||||||
$pager->readFromRequest($request);
|
$pager->readFromRequest($request);
|
||||||
|
@ -36,6 +63,14 @@ final class PhabricatorPasteListController extends PhabricatorPasteController {
|
||||||
$list->setPager($pager);
|
$list->setPager($pager);
|
||||||
$list->setNoDataString(pht("No results found for this query."));
|
$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(
|
$nav->appendChild(
|
||||||
array(
|
array(
|
||||||
$list,
|
$list,
|
||||||
|
|
|
@ -9,6 +9,7 @@ final class PhabricatorPasteSearchEngine
|
||||||
extends PhabricatorApplicationSearchEngine {
|
extends PhabricatorApplicationSearchEngine {
|
||||||
|
|
||||||
protected $filter;
|
protected $filter;
|
||||||
|
protected $user;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a saved query object from the request.
|
* Create a saved query object from the request.
|
||||||
|
@ -23,6 +24,19 @@ final class PhabricatorPasteSearchEngine
|
||||||
if ($this->filter == "my") {
|
if ($this->filter == "my") {
|
||||||
$user = $request->getUser();
|
$user = $request->getUser();
|
||||||
$saved->setParameter('authorPHIDs', array($user->getPHID()));
|
$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;
|
return $saved;
|
||||||
|
@ -48,9 +62,30 @@ final class PhabricatorPasteSearchEngine
|
||||||
* Builds the search form using the request.
|
* Builds the search form using the request.
|
||||||
*
|
*
|
||||||
* @param PhabricatorSavedQuery The query to populate the form with.
|
* @param PhabricatorSavedQuery The query to populate the form with.
|
||||||
* @return void
|
* @return AphrontFormView The built form.
|
||||||
*/
|
*/
|
||||||
public function buildSearchForm(PhabricatorSavedQuery $saved_query) {
|
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) {
|
public function setPasteSearchFilter($filter) {
|
||||||
|
@ -62,4 +97,9 @@ final class PhabricatorPasteSearchEngine
|
||||||
return $this->filter;
|
return $this->filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setPasteSearchUser($user) {
|
||||||
|
$this->user = $user;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,11 +26,11 @@ final class PhabricatorSavedQuery extends PhabricatorSearchDAO {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function save() {
|
public function save() {
|
||||||
if ($this->getEngineClass() === null) {
|
if ($this->getEngineClassName() === null) {
|
||||||
throw new Exception(pht("Engine class is 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);
|
$this->queryKey = PhabricatorHash::digestForIndex($serial);
|
||||||
|
|
||||||
return parent::save();
|
return parent::save();
|
||||||
|
|
Loading…
Reference in a new issue