mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-26 16:52:41 +01:00
Use ApplicationSearch in Feed
Summary: Ref T2625. This doesn't do anything fancy, but gives feed a little more flexibility. Test Plan: Viewed `/feed/`. Reviewers: btrahan, chad Reviewed By: chad CC: aran Maniphest Tasks: T2625 Differential Revision: https://secure.phabricator.com/D6681
This commit is contained in:
parent
b20a0eed13
commit
42af0d66d9
7 changed files with 184 additions and 96 deletions
|
@ -1117,11 +1117,12 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorFeedController' => 'applications/feed/controller/PhabricatorFeedController.php',
|
'PhabricatorFeedController' => 'applications/feed/controller/PhabricatorFeedController.php',
|
||||||
'PhabricatorFeedDAO' => 'applications/feed/storage/PhabricatorFeedDAO.php',
|
'PhabricatorFeedDAO' => 'applications/feed/storage/PhabricatorFeedDAO.php',
|
||||||
'PhabricatorFeedDetailController' => 'applications/feed/controller/PhabricatorFeedDetailController.php',
|
'PhabricatorFeedDetailController' => 'applications/feed/controller/PhabricatorFeedDetailController.php',
|
||||||
'PhabricatorFeedMainController' => 'applications/feed/controller/PhabricatorFeedMainController.php',
|
'PhabricatorFeedListController' => 'applications/feed/controller/PhabricatorFeedListController.php',
|
||||||
'PhabricatorFeedManagementRepublishWorkflow' => 'applications/feed/management/PhabricatorFeedManagementRepublishWorkflow.php',
|
'PhabricatorFeedManagementRepublishWorkflow' => 'applications/feed/management/PhabricatorFeedManagementRepublishWorkflow.php',
|
||||||
'PhabricatorFeedManagementWorkflow' => 'applications/feed/management/PhabricatorFeedManagementWorkflow.php',
|
'PhabricatorFeedManagementWorkflow' => 'applications/feed/management/PhabricatorFeedManagementWorkflow.php',
|
||||||
'PhabricatorFeedPublicStreamController' => 'applications/feed/controller/PhabricatorFeedPublicStreamController.php',
|
'PhabricatorFeedPublicStreamController' => 'applications/feed/controller/PhabricatorFeedPublicStreamController.php',
|
||||||
'PhabricatorFeedQuery' => 'applications/feed/PhabricatorFeedQuery.php',
|
'PhabricatorFeedQuery' => 'applications/feed/query/PhabricatorFeedQuery.php',
|
||||||
|
'PhabricatorFeedSearchEngine' => 'applications/feed/query/PhabricatorFeedSearchEngine.php',
|
||||||
'PhabricatorFeedStory' => 'applications/feed/story/PhabricatorFeedStory.php',
|
'PhabricatorFeedStory' => 'applications/feed/story/PhabricatorFeedStory.php',
|
||||||
'PhabricatorFeedStoryAggregate' => 'applications/feed/story/PhabricatorFeedStoryAggregate.php',
|
'PhabricatorFeedStoryAggregate' => 'applications/feed/story/PhabricatorFeedStoryAggregate.php',
|
||||||
'PhabricatorFeedStoryAudit' => 'applications/feed/story/PhabricatorFeedStoryAudit.php',
|
'PhabricatorFeedStoryAudit' => 'applications/feed/story/PhabricatorFeedStoryAudit.php',
|
||||||
|
@ -3159,11 +3160,16 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorFeedController' => 'PhabricatorController',
|
'PhabricatorFeedController' => 'PhabricatorController',
|
||||||
'PhabricatorFeedDAO' => 'PhabricatorLiskDAO',
|
'PhabricatorFeedDAO' => 'PhabricatorLiskDAO',
|
||||||
'PhabricatorFeedDetailController' => 'PhabricatorFeedController',
|
'PhabricatorFeedDetailController' => 'PhabricatorFeedController',
|
||||||
'PhabricatorFeedMainController' => 'PhabricatorFeedController',
|
'PhabricatorFeedListController' =>
|
||||||
|
array(
|
||||||
|
0 => 'PhabricatorFeedController',
|
||||||
|
1 => 'PhabricatorApplicationSearchResultsControllerInterface',
|
||||||
|
),
|
||||||
'PhabricatorFeedManagementRepublishWorkflow' => 'PhabricatorFeedManagementWorkflow',
|
'PhabricatorFeedManagementRepublishWorkflow' => 'PhabricatorFeedManagementWorkflow',
|
||||||
'PhabricatorFeedManagementWorkflow' => 'PhutilArgumentWorkflow',
|
'PhabricatorFeedManagementWorkflow' => 'PhutilArgumentWorkflow',
|
||||||
'PhabricatorFeedPublicStreamController' => 'PhabricatorFeedController',
|
'PhabricatorFeedPublicStreamController' => 'PhabricatorFeedController',
|
||||||
'PhabricatorFeedQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
'PhabricatorFeedQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||||
|
'PhabricatorFeedSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||||
'PhabricatorFeedStory' => 'PhabricatorPolicyInterface',
|
'PhabricatorFeedStory' => 'PhabricatorPolicyInterface',
|
||||||
'PhabricatorFeedStoryAggregate' => 'PhabricatorFeedStory',
|
'PhabricatorFeedStoryAggregate' => 'PhabricatorFeedStory',
|
||||||
'PhabricatorFeedStoryAudit' => 'PhabricatorFeedStory',
|
'PhabricatorFeedStoryAudit' => 'PhabricatorFeedStory',
|
||||||
|
|
|
@ -23,7 +23,7 @@ final class PhabricatorApplicationFeed extends PhabricatorApplication {
|
||||||
'/feed/' => array(
|
'/feed/' => array(
|
||||||
'public/' => 'PhabricatorFeedPublicStreamController',
|
'public/' => 'PhabricatorFeedPublicStreamController',
|
||||||
'(?P<id>\d+)/' => 'PhabricatorFeedDetailController',
|
'(?P<id>\d+)/' => 'PhabricatorFeedDetailController',
|
||||||
'(?:(?P<filter>[^/]+)/)?' => 'PhabricatorFeedMainController',
|
'(?:query/(?P<queryKey>[^/]+)/)?' => 'PhabricatorFeedListController',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,12 +23,16 @@ abstract class PhabricatorFeedController extends PhabricatorController {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function buildSideNavView() {
|
protected function buildSideNavView() {
|
||||||
|
$user = $this->getRequest()->getUser();
|
||||||
|
|
||||||
$nav = new AphrontSideNavFilterView();
|
$nav = new AphrontSideNavFilterView();
|
||||||
$nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
|
$nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
|
||||||
|
|
||||||
$nav->addLabel(pht('Feed'));
|
id(new PhabricatorFeedSearchEngine())
|
||||||
$nav->addFilter('all', pht('All Activity'));
|
->setViewer($user)
|
||||||
$nav->addFilter('projects', pht('My Projects'));
|
->addNavigationItems($nav->getMenu());
|
||||||
|
|
||||||
|
$nav->selectFilter(null);
|
||||||
|
|
||||||
return $nav;
|
return $nav;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class PhabricatorFeedListController extends PhabricatorFeedController
|
||||||
|
implements PhabricatorApplicationSearchResultsControllerInterface {
|
||||||
|
|
||||||
|
private $queryKey;
|
||||||
|
|
||||||
|
public function shouldAllowPublic() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function willProcessRequest(array $data) {
|
||||||
|
$this->queryKey = idx($data, 'queryKey');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function processRequest() {
|
||||||
|
$request = $this->getRequest();
|
||||||
|
$controller = id(new PhabricatorApplicationSearchController($request))
|
||||||
|
->setQueryKey($this->queryKey)
|
||||||
|
->setSearchEngine(new PhabricatorFeedSearchEngine())
|
||||||
|
->setNavigation($this->buildSideNavView());
|
||||||
|
|
||||||
|
return $this->delegateToController($controller);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function renderResultsList(
|
||||||
|
array $feed,
|
||||||
|
PhabricatorSavedQuery $query) {
|
||||||
|
|
||||||
|
$builder = new PhabricatorFeedBuilder($feed);
|
||||||
|
$builder->setUser($this->getRequest()->getUser());
|
||||||
|
$view = $builder->buildView();
|
||||||
|
|
||||||
|
return hsprintf(
|
||||||
|
'<div class="phabricator-feed-frame">%s</div>',
|
||||||
|
$view);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,89 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
final class PhabricatorFeedMainController extends PhabricatorFeedController {
|
|
||||||
|
|
||||||
private $filter;
|
|
||||||
|
|
||||||
public function willProcessRequest(array $data) {
|
|
||||||
$this->filter = idx($data, 'filter');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function processRequest() {
|
|
||||||
$request = $this->getRequest();
|
|
||||||
$user = $request->getUser();
|
|
||||||
|
|
||||||
$nav = $this->buildSideNavView();
|
|
||||||
$filter = $nav->selectFilter($this->filter, 'all');
|
|
||||||
|
|
||||||
$pager = new AphrontCursorPagerView();
|
|
||||||
$pager->readFromRequest($request);
|
|
||||||
$pager->setPageSize(200);
|
|
||||||
|
|
||||||
|
|
||||||
$query = id(new PhabricatorFeedQuery())
|
|
||||||
->setViewer($user);
|
|
||||||
|
|
||||||
$nodata = null;
|
|
||||||
switch ($filter) {
|
|
||||||
case 'all':
|
|
||||||
$title = pht('Feed');
|
|
||||||
break;
|
|
||||||
case 'projects':
|
|
||||||
$projects = id(new PhabricatorProjectQuery())
|
|
||||||
->setViewer($user)
|
|
||||||
->withMemberPHIDs(array($user->getPHID()))
|
|
||||||
->execute();
|
|
||||||
|
|
||||||
if (!$projects) {
|
|
||||||
$nodata = pht('You have not joined any projects.');
|
|
||||||
} else {
|
|
||||||
$query->setFilterPHIDs(mpull($projects, 'getPHID'));
|
|
||||||
}
|
|
||||||
|
|
||||||
$title = pht('Feed: My Projects');
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($nodata) {
|
|
||||||
$feed_view = id(new AphrontErrorView())
|
|
||||||
->setSeverity(AphrontErrorView::SEVERITY_NODATA)
|
|
||||||
->setTitle(pht('No Stories'))
|
|
||||||
->appendChild($nodata);
|
|
||||||
} else {
|
|
||||||
$feed = $query->executeWithCursorPager($pager);
|
|
||||||
|
|
||||||
$builder = new PhabricatorFeedBuilder($feed);
|
|
||||||
$builder->setUser($user);
|
|
||||||
$feed_view = $builder->buildView();
|
|
||||||
}
|
|
||||||
|
|
||||||
$feed_view = hsprintf(
|
|
||||||
'<div class="phabricator-feed-frame">%s</div>',
|
|
||||||
$feed_view);
|
|
||||||
|
|
||||||
$crumbs = $this
|
|
||||||
->buildApplicationCrumbs($nav)
|
|
||||||
->addCrumb(
|
|
||||||
id(new PhabricatorCrumbView())
|
|
||||||
->setName($title)
|
|
||||||
->setHref($this->getApplicationURI('filter/'.$filter.'/')));
|
|
||||||
|
|
||||||
$nav->setCrumbs($crumbs);
|
|
||||||
|
|
||||||
|
|
||||||
$nav->appendChild(
|
|
||||||
array(
|
|
||||||
$feed_view,
|
|
||||||
$pager,
|
|
||||||
));
|
|
||||||
|
|
||||||
return $this->buildApplicationPage(
|
|
||||||
$nav,
|
|
||||||
array(
|
|
||||||
'title' => $title,
|
|
||||||
'device' => true,
|
|
||||||
'dust' => true,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
128
src/applications/feed/query/PhabricatorFeedSearchEngine.php
Normal file
128
src/applications/feed/query/PhabricatorFeedSearchEngine.php
Normal file
|
@ -0,0 +1,128 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class PhabricatorFeedSearchEngine
|
||||||
|
extends PhabricatorApplicationSearchEngine {
|
||||||
|
|
||||||
|
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
||||||
|
$saved = new PhabricatorSavedQuery();
|
||||||
|
|
||||||
|
$saved->setParameter(
|
||||||
|
'userPHIDs',
|
||||||
|
array_values($request->getArr('userPHIDs')));
|
||||||
|
|
||||||
|
$saved->setParameter(
|
||||||
|
'projectPHIDs',
|
||||||
|
array_values($request->getArr('projectPHIDs')));
|
||||||
|
|
||||||
|
$saved->setParameter(
|
||||||
|
'viewerProjects',
|
||||||
|
$request->getBool('viewerProjects'));
|
||||||
|
|
||||||
|
return $saved;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
||||||
|
$query = id(new PhabricatorFeedQuery());
|
||||||
|
|
||||||
|
$phids = array();
|
||||||
|
|
||||||
|
$user_phids = $saved->getParameter('userPHIDs');
|
||||||
|
if ($user_phids) {
|
||||||
|
$phids[] = $user_phids;
|
||||||
|
}
|
||||||
|
|
||||||
|
$proj_phids = $saved->getParameter('projectPHIDs');
|
||||||
|
if ($proj_phids) {
|
||||||
|
$phids[] = $proj_phids;
|
||||||
|
}
|
||||||
|
|
||||||
|
$viewer_projects = $saved->getParameter('viewerProjects');
|
||||||
|
if ($viewer_projects) {
|
||||||
|
$viewer = $this->requireViewer();
|
||||||
|
$projects = id(new PhabricatorProjectQuery())
|
||||||
|
->setViewer($viewer)
|
||||||
|
->withMemberPHIDs(array($viewer->getPHID()))
|
||||||
|
->execute();
|
||||||
|
$phids[] = mpull($projects, 'getPHID');
|
||||||
|
}
|
||||||
|
|
||||||
|
$phids = array_mergev($phids);
|
||||||
|
if ($phids) {
|
||||||
|
$query->setFilterPHIDs($phids);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $query;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function buildSearchForm(
|
||||||
|
AphrontFormView $form,
|
||||||
|
PhabricatorSavedQuery $saved_query) {
|
||||||
|
|
||||||
|
$user_phids = $saved_query->getParameter('userPHIDs', array());
|
||||||
|
$proj_phids = $saved_query->getParameter('projectPHIDs', array());
|
||||||
|
|
||||||
|
$phids = array_merge($user_phids, $proj_phids);
|
||||||
|
$handles = id(new PhabricatorHandleQuery())
|
||||||
|
->setViewer($this->requireViewer())
|
||||||
|
->withPHIDs($phids)
|
||||||
|
->execute();
|
||||||
|
$tokens = mpull($handles, 'getFullName', 'getPHID');
|
||||||
|
$user_tokens = array_select_keys($tokens, $user_phids);
|
||||||
|
$proj_tokens = array_select_keys($tokens, $proj_phids);
|
||||||
|
|
||||||
|
$viewer_projects = $saved_query->getParameter('viewerProjects');
|
||||||
|
|
||||||
|
$form
|
||||||
|
->appendChild(
|
||||||
|
id(new AphrontFormTokenizerControl())
|
||||||
|
->setDatasource('/typeahead/common/users/')
|
||||||
|
->setName('userPHIDs')
|
||||||
|
->setLabel(pht('Include Users'))
|
||||||
|
->setValue($user_tokens))
|
||||||
|
->appendChild(
|
||||||
|
id(new AphrontFormTokenizerControl())
|
||||||
|
->setDatasource('/typeahead/common/projects/')
|
||||||
|
->setName('projectPHIDs')
|
||||||
|
->setLabel(pht('Include Projects'))
|
||||||
|
->setValue($proj_tokens))
|
||||||
|
->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;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBuiltinQueryNames() {
|
||||||
|
$names = array(
|
||||||
|
'all' => pht('All Stories'),
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($this->requireViewer()->isLoggedIn()) {
|
||||||
|
$names['projects'] = pht('Projects');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $names;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function buildSavedQueryFromBuiltin($query_key) {
|
||||||
|
|
||||||
|
$query = $this->newSavedQuery();
|
||||||
|
$query->setQueryKey($query_key);
|
||||||
|
|
||||||
|
switch ($query_key) {
|
||||||
|
case 'all':
|
||||||
|
return $query;
|
||||||
|
case 'projects':
|
||||||
|
return $query->setParameter('viewerProjects', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent::buildSavedQueryFromBuiltin($query_key);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue