1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-27 09:12:41 +01:00

Add "assigned" and "authors" to Maniphest pro search

Summary: Ref T2625. Moves this a step toward being able to replace the current search.

Test Plan: Used search interface.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2625

Differential Revision: https://secure.phabricator.com/D6934
This commit is contained in:
epriestley 2013-09-10 10:44:42 -07:00
parent e814291526
commit 8c9d61bedc

View file

@ -6,20 +6,86 @@ final class ManiphestTaskSearchEngine
public function buildSavedQueryFromRequest(AphrontRequest $request) { public function buildSavedQueryFromRequest(AphrontRequest $request) {
$saved = new PhabricatorSavedQuery(); $saved = new PhabricatorSavedQuery();
$saved->setParameter(
'assignedPHIDs',
$this->readUsersFromRequest($request, 'assigned'));
$saved->setParameter('withUnassigned', $request->getBool('withUnassigned'));
$saved->setParameter(
'authorPHIDs',
$this->readUsersFromRequest($request, 'authors'));
return $saved; return $saved;
} }
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
$query = id(new ManiphestTaskQuery()); $query = id(new ManiphestTaskQuery());
$author_phids = $saved->getParameter('authorPHIDs');
if ($author_phids) {
$query->withAuthors($author_phids);
}
$with_unassigned = $saved->getParameter('withUnassigned');
if ($with_unassigned) {
$query->withOwners(array(null));
} else {
$assigned_phids = $saved->getParameter('assignedPHIDs', array());
if ($assigned_phids) {
$query->withOwners($assigned_phids);
}
}
return $query; return $query;
} }
public function buildSearchForm( public function buildSearchForm(
AphrontFormView $form, AphrontFormView $form,
PhabricatorSavedQuery $saved_query) { PhabricatorSavedQuery $saved) {
$assigned_phids = $saved->getParameter('assignedPHIDs', array());
$author_phids = $saved->getParameter('authorPHIDs', array());
$all_phids = array_merge($assigned_phids, $author_phids);
if ($all_phids) {
$handles = id(new PhabricatorHandleQuery())
->setViewer($this->requireViewer())
->withPHIDs($all_phids)
->execute();
} else {
$handles = array();
}
$assigned_tokens = array_select_keys($handles, $assigned_phids);
$assigned_tokens = mpull($assigned_tokens, 'getFullName', 'getPHID');
$author_tokens = array_select_keys($handles, $author_phids);
$author_tokens = mpull($author_tokens, 'getFullName', 'getPHID');
$with_unassigned = $saved->getParameter('withUnassigned');
$form
->appendChild(
id(new AphrontFormTokenizerControl())
->setDatasource('/typeahead/common/accounts/')
->setName('assigned')
->setLabel(pht('Assigned To'))
->setValue($assigned_tokens))
->appendChild(
id(new AphrontFormCheckboxControl())
->addCheckbox(
'withUnassigned',
1,
pht('Show only unassigned tasks.'),
$with_unassigned))
->appendChild(
id(new AphrontFormTokenizerControl())
->setDatasource('/typeahead/common/accounts/')
->setName('authors')
->setLabel(pht('Authors'))
->setValue($author_tokens));
} }
protected function getURI($path) { protected function getURI($path) {
@ -44,13 +110,15 @@ final class ManiphestTaskSearchEngine
$query = $this->newSavedQuery(); $query = $this->newSavedQuery();
$query->setQueryKey($query_key); $query->setQueryKey($query_key);
$viewer_phid = $this->requireViewer()->getPHID();
switch ($query_key) { switch ($query_key) {
case 'all': case 'all':
return $query; return $query;
case 'assigned': case 'assigned':
return $query; return $query->setParameter('assignedPHIDs', array($viewer_phid));
case 'authored': case 'authored':
return $query; return $query->setParameter('authorPHIDs', array($viewer_phid));
} }
return parent::buildSavedQueryFromBuiltin($query_key); return parent::buildSavedQueryFromBuiltin($query_key);