mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-22 21:40: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:
parent
2d79229083
commit
6fed08a98e
2 changed files with 55 additions and 59 deletions
|
@ -89,6 +89,20 @@ final class PhabricatorFeedQuery
|
|||
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() {
|
||||
$table = ($this->filterPHIDs ? 'ref' : 'story');
|
||||
return array(
|
||||
|
|
|
@ -11,50 +11,62 @@ final class PhabricatorFeedSearchEngine
|
|||
return 'PhabricatorFeedApplication';
|
||||
}
|
||||
|
||||
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
||||
$saved = new PhabricatorSavedQuery();
|
||||
|
||||
$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 newQuery() {
|
||||
return new PhabricatorFeedQuery();
|
||||
}
|
||||
|
||||
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
||||
$query = id(new PhabricatorFeedQuery());
|
||||
protected function shouldShowOrderField() {
|
||||
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();
|
||||
|
||||
$user_phids = $saved->getParameter('userPHIDs');
|
||||
if ($user_phids) {
|
||||
$phids[] = $user_phids;
|
||||
if ($map['userPHIDs']) {
|
||||
$phids += array_fuse($map['userPHIDs']);
|
||||
}
|
||||
|
||||
$proj_phids = $saved->getParameter('projectPHIDs');
|
||||
if ($proj_phids) {
|
||||
$phids[] = $proj_phids;
|
||||
if ($map['projectPHIDs']) {
|
||||
$phids += array_fuse($map['projectPHIDs']);
|
||||
}
|
||||
|
||||
$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) {
|
||||
$viewer = $this->requireViewer();
|
||||
$projects = id(new PhabricatorProjectQuery())
|
||||
->setViewer($viewer)
|
||||
->withMemberPHIDs(array($viewer->getPHID()))
|
||||
->execute();
|
||||
$phids[] = mpull($projects, 'getPHID');
|
||||
$phids += array_fuse(mpull($projects, 'getPHID'));
|
||||
}
|
||||
|
||||
$phids = array_mergev($phids);
|
||||
if ($phids) {
|
||||
$query->withFilterPHIDs($phids);
|
||||
}
|
||||
|
@ -62,36 +74,6 @@ final class PhabricatorFeedSearchEngine
|
|||
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) {
|
||||
return '/feed/'.$path;
|
||||
}
|
||||
|
@ -117,7 +99,7 @@ final class PhabricatorFeedSearchEngine
|
|||
case 'all':
|
||||
return $query;
|
||||
case 'projects':
|
||||
return $query->setParameter('viewerProjects', true);
|
||||
return $query->setParameter('viewerProjects', array('self'));
|
||||
}
|
||||
|
||||
return parent::buildSavedQueryFromBuiltin($query_key);
|
||||
|
|
Loading…
Reference in a new issue