1
0
Fork 0
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:
epriestley 2014-05-08 08:24:47 -07:00
parent d30f43b15b
commit dadd9a9dd9
8 changed files with 90 additions and 70 deletions

View file

@ -4377,11 +4377,7 @@ phutil_register_library_map(array(
'PhabricatorFeedController' => 'PhabricatorController', 'PhabricatorFeedController' => 'PhabricatorController',
'PhabricatorFeedDAO' => 'PhabricatorLiskDAO', 'PhabricatorFeedDAO' => 'PhabricatorLiskDAO',
'PhabricatorFeedDetailController' => 'PhabricatorFeedController', 'PhabricatorFeedDetailController' => 'PhabricatorFeedController',
'PhabricatorFeedListController' => 'PhabricatorFeedListController' => 'PhabricatorFeedController',
array(
0 => 'PhabricatorFeedController',
1 => 'PhabricatorApplicationSearchResultsControllerInterface',
),
'PhabricatorFeedManagementRepublishWorkflow' => 'PhabricatorFeedManagementWorkflow', 'PhabricatorFeedManagementRepublishWorkflow' => 'PhabricatorFeedManagementWorkflow',
'PhabricatorFeedManagementWorkflow' => 'PhabricatorManagementWorkflow', 'PhabricatorFeedManagementWorkflow' => 'PhabricatorManagementWorkflow',
'PhabricatorFeedPublicStreamController' => 'PhabricatorFeedController', 'PhabricatorFeedPublicStreamController' => 'PhabricatorFeedController',

View file

@ -66,17 +66,10 @@ final class PhabricatorDashboardPanelTypeQuery
} }
$query = $engine->buildQueryFromSavedQuery($saved); $query = $engine->buildQueryFromSavedQuery($saved);
$pager = $engine->newPagerForSavedQuery($saved);
$results = $engine->executeQuery($query, $pager);
$results = $query return $engine->renderResults($results, $saved);
->setViewer($viewer)
->execute();
$out = array();
foreach ($results as $result) {
$out[] = phutil_tag('div', array(), $result->getPHID());
}
return $out;
} }
} }

View file

@ -1,7 +1,6 @@
<?php <?php
final class PhabricatorFeedListController extends PhabricatorFeedController final class PhabricatorFeedListController extends PhabricatorFeedController {
implements PhabricatorApplicationSearchResultsControllerInterface {
private $queryKey; private $queryKey;
@ -23,16 +22,4 @@ final class PhabricatorFeedListController extends PhabricatorFeedController
return $this->delegateToController($controller); 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);
}
} }

View file

@ -124,4 +124,16 @@ final class PhabricatorFeedSearchEngine
return parent::buildSavedQueryFromBuiltin($query_key); 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);
}
} }

View file

@ -7,16 +7,6 @@ final class PhabricatorApplicationSearchController
private $navigation; private $navigation;
private $queryKey; private $queryKey;
private $preface; 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) { public function setPreface($preface) {
$this->preface = $preface; $this->preface = $preface;
@ -78,11 +68,6 @@ final class PhabricatorApplicationSearchController
$engine->setViewer($this->getRequest()->getUser()); $engine->setViewer($this->getRequest()->getUser());
$parent = $this->getDelegatingController(); $parent = $this->getDelegatingController();
$interface = 'PhabricatorApplicationSearchResultsControllerInterface';
if (!$parent instanceof $interface) {
throw new Exception(
"Delegating controller must implement '{$interface}'.");
}
} }
public function processRequest() { public function processRequest() {
@ -223,34 +208,23 @@ final class PhabricatorApplicationSearchController
$query = $engine->buildQueryFromSavedQuery($saved_query); $query = $engine->buildQueryFromSavedQuery($saved_query);
$use_offset_paging = $this->getUseOffsetPaging(); $pager = $engine->newPagerForSavedQuery($saved_query);
if ($use_offset_paging) {
$pager = new AphrontPagerView();
} else {
$pager = new AphrontCursorPagerView();
}
$pager->readFromRequest($request); $pager->readFromRequest($request);
$page_size = $engine->getPageSize($saved_query);
if (is_finite($page_size)) { $objects = $engine->executeQuery($query, $pager);
$pager->setPageSize($page_size);
// 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 { } else {
// Consider an INF pagesize to mean a large finite pagesize. $list = $engine->renderResults(
$objects,
// TODO: It would be nice to handle this more gracefully, but math $saved_query);
// with INF seems to vary across PHP versions, systems, and runtimes.
$pager->setPageSize(0xFFFF);
} }
$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); $nav->appendChild($list);
// TODO: This is a bit hacky. // TODO: This is a bit hacky.

View file

@ -76,7 +76,6 @@ final class PhabricatorSearchController
$controller = id(new PhabricatorApplicationSearchController($request)) $controller = id(new PhabricatorApplicationSearchController($request))
->setQueryKey($this->queryKey) ->setQueryKey($this->queryKey)
->setSearchEngine($engine) ->setSearchEngine($engine)
->setUseOffsetPaging(true)
->setNavigation($this->buildSideNavView()); ->setNavigation($this->buildSideNavView());
return $this->delegateToController($controller); return $this->delegateToController($controller);

View file

@ -9,6 +9,8 @@
* @task uri Query URIs * @task uri Query URIs
* @task dates Date Filters * @task dates Date Filters
* @task read Reading Utilities * @task read Reading Utilities
* @task exec Paging and Executing Queries
* @task render Rendering Results
* *
* @group search * @group search
*/ */
@ -502,7 +504,7 @@ abstract class PhabricatorApplicationSearchEngine {
} }
/* -( Pagination )--------------------------------------------------------- */ /* -( Paging and Executing Queries )--------------------------------------- */
public function getPageSize(PhabricatorSavedQuery $saved) { 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 )------------------------------------------------- */ /* -( Application Search )------------------------------------------------- */

View file

@ -229,5 +229,9 @@ final class PhabricatorSearchApplicationSearchEngine
return $results; return $results;
} }
public function shouldUseOffsetPaging() {
return true;
}
} }