1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 05:50:55 +01:00

Modernize FeedSearchEngine a little bit

Summary:
Ref T12762. This updates FeedSeachEngine to user modern construction.

I've tried to retain behavior exactly, although the "Include stories about projects I'm a member of" checkbox is now nonstandard/obsolete. We could likely fold that into "Include Projects" in a future change which does a backward compatibility break.

Test Plan:
  - Queried feed without constraints.
  - Queried feed by user, project, "stuff I'm a member of", prebuilt "Tags" query.
  - Viewed user profile / project profile feeds.
  - Used function tokens (`viewer()`, etc).

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T12762

Differential Revision: https://secure.phabricator.com/D18028
This commit is contained in:
epriestley 2017-05-26 10:08:33 -07:00
parent 2d79229083
commit 6fed08a98e
2 changed files with 55 additions and 59 deletions

View file

@ -89,6 +89,20 @@ final class PhabricatorFeedQuery
return array('key'); return array('key');
} }
public function getBuiltinOrders() {
return array(
'newest' => array(
'vector' => array('key'),
'name' => pht('Creation (Newest First)'),
'aliases' => array('created'),
),
'oldest' => array(
'vector' => array('-key'),
'name' => pht('Creation (Oldest First)'),
),
);
}
public function getOrderableColumns() { public function getOrderableColumns() {
$table = ($this->filterPHIDs ? 'ref' : 'story'); $table = ($this->filterPHIDs ? 'ref' : 'story');
return array( return array(

View file

@ -11,50 +11,62 @@ final class PhabricatorFeedSearchEngine
return 'PhabricatorFeedApplication'; return 'PhabricatorFeedApplication';
} }
public function buildSavedQueryFromRequest(AphrontRequest $request) { public function newQuery() {
$saved = new PhabricatorSavedQuery(); return new PhabricatorFeedQuery();
$saved->setParameter(
'userPHIDs',
$this->readUsersFromRequest($request, 'users'));
$saved->setParameter(
'projectPHIDs',
array_values($request->getArr('projectPHIDs')));
$saved->setParameter(
'viewerProjects',
$request->getBool('viewerProjects'));
return $saved;
} }
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { protected function shouldShowOrderField() {
$query = id(new PhabricatorFeedQuery()); return false;
}
protected function buildCustomSearchFields() {
return array(
id(new PhabricatorUsersSearchField())
->setLabel(pht('Include Users'))
->setKey('userPHIDs'),
// NOTE: This query is not executed with EdgeLogic, so we can't use
// a fancy logical datasource.
id(new PhabricatorSearchDatasourceField())
->setDatasource(new PhabricatorProjectDatasource())
->setLabel(pht('Include Projects'))
->setKey('projectPHIDs'),
// NOTE: This is a legacy field retained only for backward
// compatibility. If the projects field used EdgeLogic, we could use
// `viewerprojects()` to execute an equivalent query.
id(new PhabricatorSearchCheckboxesField())
->setKey('viewerProjects')
->setOptions(
array(
'self' => pht('Include stories about projects I am a member of.'),
)),
);
}
protected function buildQueryFromParameters(array $map) {
$query = $this->newQuery();
$phids = array(); $phids = array();
if ($map['userPHIDs']) {
$user_phids = $saved->getParameter('userPHIDs'); $phids += array_fuse($map['userPHIDs']);
if ($user_phids) {
$phids[] = $user_phids;
} }
$proj_phids = $saved->getParameter('projectPHIDs'); if ($map['projectPHIDs']) {
if ($proj_phids) { $phids += array_fuse($map['projectPHIDs']);
$phids[] = $proj_phids;
} }
$viewer_projects = $saved->getParameter('viewerProjects'); // NOTE: This value may be `true` for older saved queries, or
// `array('self')` for newer ones.
$viewer_projects = $map['viewerProjects'];
if ($viewer_projects) { if ($viewer_projects) {
$viewer = $this->requireViewer(); $viewer = $this->requireViewer();
$projects = id(new PhabricatorProjectQuery()) $projects = id(new PhabricatorProjectQuery())
->setViewer($viewer) ->setViewer($viewer)
->withMemberPHIDs(array($viewer->getPHID())) ->withMemberPHIDs(array($viewer->getPHID()))
->execute(); ->execute();
$phids[] = mpull($projects, 'getPHID'); $phids += array_fuse(mpull($projects, 'getPHID'));
} }
$phids = array_mergev($phids);
if ($phids) { if ($phids) {
$query->withFilterPHIDs($phids); $query->withFilterPHIDs($phids);
} }
@ -62,36 +74,6 @@ final class PhabricatorFeedSearchEngine
return $query; return $query;
} }
public function buildSearchForm(
AphrontFormView $form,
PhabricatorSavedQuery $saved_query) {
$user_phids = $saved_query->getParameter('userPHIDs', array());
$proj_phids = $saved_query->getParameter('projectPHIDs', array());
$viewer_projects = $saved_query->getParameter('viewerProjects');
$form
->appendControl(
id(new AphrontFormTokenizerControl())
->setDatasource(new PhabricatorPeopleDatasource())
->setName('users')
->setLabel(pht('Include Users'))
->setValue($user_phids))
->appendControl(
id(new AphrontFormTokenizerControl())
->setDatasource(new PhabricatorProjectDatasource())
->setName('projectPHIDs')
->setLabel(pht('Include Projects'))
->setValue($proj_phids))
->appendChild(
id(new AphrontFormCheckboxControl())
->addCheckbox(
'viewerProjects',
1,
pht('Include stories about projects I am a member of.'),
$viewer_projects));
}
protected function getURI($path) { protected function getURI($path) {
return '/feed/'.$path; return '/feed/'.$path;
} }
@ -117,7 +99,7 @@ final class PhabricatorFeedSearchEngine
case 'all': case 'all':
return $query; return $query;
case 'projects': case 'projects':
return $query->setParameter('viewerProjects', true); return $query->setParameter('viewerProjects', array('self'));
} }
return parent::buildSavedQueryFromBuiltin($query_key); return parent::buildSavedQueryFromBuiltin($query_key);