mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-21 04:50:55 +01:00
Let feed panels render something meaningful-ish
Summary: Ref T4986. We need to introduce alternate views to make this more pleasant, but let rendering move to engines so it can be shared between panels and controllers. I also moved some of the pagination logic in to avoid duplicating that. So far, only Feed works. I'm going to do these gradually since we have ~40-50 of them. Test Plan: - Used global search to check for collateral damage. - Used not-global search too. - Used normal feed. {F151541} Reviewers: btrahan Reviewed By: btrahan Subscribers: chad, epriestley Maniphest Tasks: T4986 Differential Revision: https://secure.phabricator.com/D9008
This commit is contained in:
parent
d30f43b15b
commit
dadd9a9dd9
8 changed files with 90 additions and 70 deletions
|
@ -4377,11 +4377,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorFeedController' => 'PhabricatorController',
|
||||
'PhabricatorFeedDAO' => 'PhabricatorLiskDAO',
|
||||
'PhabricatorFeedDetailController' => 'PhabricatorFeedController',
|
||||
'PhabricatorFeedListController' =>
|
||||
array(
|
||||
0 => 'PhabricatorFeedController',
|
||||
1 => 'PhabricatorApplicationSearchResultsControllerInterface',
|
||||
),
|
||||
'PhabricatorFeedListController' => 'PhabricatorFeedController',
|
||||
'PhabricatorFeedManagementRepublishWorkflow' => 'PhabricatorFeedManagementWorkflow',
|
||||
'PhabricatorFeedManagementWorkflow' => 'PhabricatorManagementWorkflow',
|
||||
'PhabricatorFeedPublicStreamController' => 'PhabricatorFeedController',
|
||||
|
|
|
@ -66,17 +66,10 @@ final class PhabricatorDashboardPanelTypeQuery
|
|||
}
|
||||
|
||||
$query = $engine->buildQueryFromSavedQuery($saved);
|
||||
$pager = $engine->newPagerForSavedQuery($saved);
|
||||
$results = $engine->executeQuery($query, $pager);
|
||||
|
||||
$results = $query
|
||||
->setViewer($viewer)
|
||||
->execute();
|
||||
|
||||
$out = array();
|
||||
foreach ($results as $result) {
|
||||
$out[] = phutil_tag('div', array(), $result->getPHID());
|
||||
}
|
||||
|
||||
return $out;
|
||||
return $engine->renderResults($results, $saved);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorFeedListController extends PhabricatorFeedController
|
||||
implements PhabricatorApplicationSearchResultsControllerInterface {
|
||||
final class PhabricatorFeedListController extends PhabricatorFeedController {
|
||||
|
||||
private $queryKey;
|
||||
|
||||
|
@ -23,16 +22,4 @@ final class PhabricatorFeedListController extends PhabricatorFeedController
|
|||
return $this->delegateToController($controller);
|
||||
}
|
||||
|
||||
public function renderResultsList(
|
||||
array $feed,
|
||||
PhabricatorSavedQuery $query) {
|
||||
|
||||
$builder = new PhabricatorFeedBuilder($feed);
|
||||
$builder->setShowHovercards(true);
|
||||
$builder->setUser($this->getRequest()->getUser());
|
||||
$view = $builder->buildView();
|
||||
|
||||
return phutil_tag_div('phabricator-feed-frame', $view);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -124,4 +124,16 @@ final class PhabricatorFeedSearchEngine
|
|||
return parent::buildSavedQueryFromBuiltin($query_key);
|
||||
}
|
||||
|
||||
public function renderResults(
|
||||
array $objects,
|
||||
PhabricatorSavedQuery $query) {
|
||||
|
||||
$builder = new PhabricatorFeedBuilder($objects);
|
||||
$builder->setShowHovercards(true);
|
||||
$builder->setUser($this->requireViewer());
|
||||
$view = $builder->buildView();
|
||||
|
||||
return phutil_tag_div('phabricator-feed-frame', $view);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,16 +7,6 @@ final class PhabricatorApplicationSearchController
|
|||
private $navigation;
|
||||
private $queryKey;
|
||||
private $preface;
|
||||
private $useOffsetPaging;
|
||||
|
||||
public function setUseOffsetPaging($use_offset_paging) {
|
||||
$this->useOffsetPaging = $use_offset_paging;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getUseOffsetPaging() {
|
||||
return $this->useOffsetPaging;
|
||||
}
|
||||
|
||||
public function setPreface($preface) {
|
||||
$this->preface = $preface;
|
||||
|
@ -78,11 +68,6 @@ final class PhabricatorApplicationSearchController
|
|||
$engine->setViewer($this->getRequest()->getUser());
|
||||
|
||||
$parent = $this->getDelegatingController();
|
||||
$interface = 'PhabricatorApplicationSearchResultsControllerInterface';
|
||||
if (!$parent instanceof $interface) {
|
||||
throw new Exception(
|
||||
"Delegating controller must implement '{$interface}'.");
|
||||
}
|
||||
}
|
||||
|
||||
public function processRequest() {
|
||||
|
@ -223,34 +208,23 @@ final class PhabricatorApplicationSearchController
|
|||
|
||||
$query = $engine->buildQueryFromSavedQuery($saved_query);
|
||||
|
||||
$use_offset_paging = $this->getUseOffsetPaging();
|
||||
if ($use_offset_paging) {
|
||||
$pager = new AphrontPagerView();
|
||||
} else {
|
||||
$pager = new AphrontCursorPagerView();
|
||||
}
|
||||
$pager = $engine->newPagerForSavedQuery($saved_query);
|
||||
$pager->readFromRequest($request);
|
||||
$page_size = $engine->getPageSize($saved_query);
|
||||
if (is_finite($page_size)) {
|
||||
$pager->setPageSize($page_size);
|
||||
|
||||
$objects = $engine->executeQuery($query, $pager);
|
||||
|
||||
// TODO: To support Dashboard panels, rendering is moving into
|
||||
// SearchEngines. Move it all the way in and then get rid of this.
|
||||
|
||||
$interface = 'PhabricatorApplicationSearchResultsControllerInterface';
|
||||
if ($parent instanceof $interface) {
|
||||
$list = $parent->renderResultsList($objects, $saved_query);
|
||||
} else {
|
||||
// Consider an INF pagesize to mean a large finite pagesize.
|
||||
|
||||
// TODO: It would be nice to handle this more gracefully, but math
|
||||
// with INF seems to vary across PHP versions, systems, and runtimes.
|
||||
$pager->setPageSize(0xFFFF);
|
||||
$list = $engine->renderResults(
|
||||
$objects,
|
||||
$saved_query);
|
||||
}
|
||||
|
||||
$query->setViewer($request->getUser());
|
||||
|
||||
if ($use_offset_paging) {
|
||||
$objects = $query->executeWithOffsetPager($pager);
|
||||
} else {
|
||||
$objects = $query->executeWithCursorPager($pager);
|
||||
}
|
||||
|
||||
$list = $parent->renderResultsList($objects, $saved_query);
|
||||
|
||||
$nav->appendChild($list);
|
||||
|
||||
// TODO: This is a bit hacky.
|
||||
|
|
|
@ -76,7 +76,6 @@ final class PhabricatorSearchController
|
|||
$controller = id(new PhabricatorApplicationSearchController($request))
|
||||
->setQueryKey($this->queryKey)
|
||||
->setSearchEngine($engine)
|
||||
->setUseOffsetPaging(true)
|
||||
->setNavigation($this->buildSideNavView());
|
||||
|
||||
return $this->delegateToController($controller);
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
* @task uri Query URIs
|
||||
* @task dates Date Filters
|
||||
* @task read Reading Utilities
|
||||
* @task exec Paging and Executing Queries
|
||||
* @task render Rendering Results
|
||||
*
|
||||
* @group search
|
||||
*/
|
||||
|
@ -502,7 +504,7 @@ abstract class PhabricatorApplicationSearchEngine {
|
|||
}
|
||||
|
||||
|
||||
/* -( Pagination )--------------------------------------------------------- */
|
||||
/* -( Paging and Executing Queries )--------------------------------------- */
|
||||
|
||||
|
||||
public function getPageSize(PhabricatorSavedQuery $saved) {
|
||||
|
@ -510,6 +512,59 @@ abstract class PhabricatorApplicationSearchEngine {
|
|||
}
|
||||
|
||||
|
||||
public function shouldUseOffsetPaging() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function newPagerForSavedQuery(PhabricatorSavedQuery $saved) {
|
||||
if ($this->shouldUseOffsetPaging()) {
|
||||
$pager = new AphrontPagerView();
|
||||
} else {
|
||||
$pager = new AphrontCursorPagerView();
|
||||
}
|
||||
|
||||
$page_size = $this->getPageSize($saved);
|
||||
if (is_finite($page_size)) {
|
||||
$pager->setPageSize($page_size);
|
||||
} else {
|
||||
// Consider an INF pagesize to mean a large finite pagesize.
|
||||
|
||||
// TODO: It would be nice to handle this more gracefully, but math
|
||||
// with INF seems to vary across PHP versions, systems, and runtimes.
|
||||
$pager->setPageSize(0xFFFF);
|
||||
}
|
||||
|
||||
return $pager;
|
||||
}
|
||||
|
||||
|
||||
public function executeQuery(
|
||||
PhabricatorPolicyAwareQuery $query,
|
||||
AphrontView $pager) {
|
||||
|
||||
$query->setViewer($this->requireViewer());
|
||||
|
||||
if ($this->shouldUseOffsetPaging()) {
|
||||
$objects = $query->executeWithOffsetPager($pager);
|
||||
} else {
|
||||
$objects = $query->executeWithCursorPager($pager);
|
||||
}
|
||||
|
||||
return $objects;
|
||||
}
|
||||
|
||||
|
||||
/* -( Rendering )---------------------------------------------------------- */
|
||||
|
||||
|
||||
public function renderResults(
|
||||
array $objects,
|
||||
PhabricatorSavedQuery $query) {
|
||||
throw new Exception(pht('Not supported here yet!'));
|
||||
}
|
||||
|
||||
|
||||
/* -( Application Search )------------------------------------------------- */
|
||||
|
||||
|
||||
|
|
|
@ -229,5 +229,9 @@ final class PhabricatorSearchApplicationSearchEngine
|
|||
return $results;
|
||||
}
|
||||
|
||||
public function shouldUseOffsetPaging() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue