1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-29 16:08:22 +01:00

Move Slowvote rendering into SearchEngine

Summary:
Ref T4986. This adds a bit of structure for handles, since we used to have Controller utilities but no longer do.

Hopefully these will start going faster soon...

Test Plan:

  - Checked feed for collateral damage.
  - Checked slowvote for collateral damage.
  - Made a slowvote panel.

{F151550}

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T4986

Differential Revision: https://secure.phabricator.com/D9010
This commit is contained in:
epriestley 2014-05-08 08:40:59 -07:00
parent dadd9a9dd9
commit 8f42f4b538
5 changed files with 79 additions and 54 deletions

View file

@ -5066,11 +5066,7 @@ phutil_register_library_map(array(
'PhabricatorSlowvoteDAO' => 'PhabricatorLiskDAO',
'PhabricatorSlowvoteEditController' => 'PhabricatorSlowvoteController',
'PhabricatorSlowvoteEditor' => 'PhabricatorApplicationTransactionEditor',
'PhabricatorSlowvoteListController' =>
array(
0 => 'PhabricatorSlowvoteController',
1 => 'PhabricatorApplicationSearchResultsControllerInterface',
),
'PhabricatorSlowvoteListController' => 'PhabricatorSlowvoteController',
'PhabricatorSlowvoteOption' => 'PhabricatorSlowvoteDAO',
'PhabricatorSlowvotePHIDTypePoll' => 'PhabricatorPHIDType',
'PhabricatorSlowvotePoll' =>

View file

@ -124,9 +124,10 @@ final class PhabricatorFeedSearchEngine
return parent::buildSavedQueryFromBuiltin($query_key);
}
public function renderResults(
public function renderResultList(
array $objects,
PhabricatorSavedQuery $query) {
PhabricatorSavedQuery $query,
array $handles) {
$builder = new PhabricatorFeedBuilder($objects);
$builder->setShowHovercards(true);

View file

@ -561,6 +561,31 @@ abstract class PhabricatorApplicationSearchEngine {
public function renderResults(
array $objects,
PhabricatorSavedQuery $query) {
$phids = $this->getRequiredHandlePHIDsForResultList($objects, $query);
if ($phids) {
$handles = id(new PhabricatorHandleQuery())
->setViewer($this->requireViewer())
->witHPHIDs($phids)
->execute();
} else {
$handles = array();
}
return $this->renderResultList($objects, $query, $handles);
}
public function getRequiredHandlePHIDsForResultList(
array $objects,
PhabricatorSavedQuery $query) {
return array();
}
public function renderResultList(
array $objects,
PhabricatorSavedQuery $query,
array $handles) {
throw new Exception(pht('Not supported here yet!'));
}

View file

@ -1,11 +1,7 @@
<?php
/**
* @group slowvote
*/
final class PhabricatorSlowvoteListController
extends PhabricatorSlowvoteController
implements PhabricatorApplicationSearchResultsControllerInterface {
extends PhabricatorSlowvoteController {
private $queryKey;
@ -27,46 +23,4 @@ final class PhabricatorSlowvoteListController
return $this->delegateToController($controller);
}
public function renderResultsList(
array $polls,
PhabricatorSavedQuery $query) {
assert_instances_of($polls, 'PhabricatorSlowvotePoll');
$viewer = $this->getRequest()->getUser();
$list = id(new PHUIObjectItemListView())
->setUser($viewer);
$phids = mpull($polls, 'getAuthorPHID');
$handles = $this->loadViewerHandles($phids);
foreach ($polls as $poll) {
$date_created = phabricator_datetime($poll->getDateCreated(), $viewer);
if ($poll->getAuthorPHID()) {
$author = $handles[$poll->getAuthorPHID()]->renderLink();
} else {
$author = null;
}
$item = id(new PHUIObjectItemView())
->setObjectName('V'.$poll->getID())
->setHeader($poll->getQuestion())
->setHref('/V'.$poll->getID())
->setDisabled($poll->getIsClosed())
->addIcon('none', $date_created);
$description = $poll->getDescription();
if (strlen($description)) {
$item->addAttribute(phutil_utf8_shorten($poll->getDescription(), 120));
}
if ($author) {
$item->addByline(pht('Author: %s', $author));
}
$list->addItem($item);
}
return $list;
}
}

View file

@ -115,4 +115,53 @@ final class PhabricatorSlowvoteSearchEngine
return parent::buildSavedQueryFromBuiltin($query_key);
}
public function getRequiredHandlePHIDsForResultList(
array $polls,
PhabricatorSavedQuery $query) {
return mpull($polls, 'getAuthorPHID');
}
public function renderResultList(
array $polls,
PhabricatorSavedQuery $query,
array $handles) {
assert_instances_of($polls, 'PhabricatorSlowvotePoll');
$viewer = $this->requireViewer();
$list = id(new PHUIObjectItemListView())
->setUser($viewer);
$phids = mpull($polls, 'getAuthorPHID');
foreach ($polls as $poll) {
$date_created = phabricator_datetime($poll->getDateCreated(), $viewer);
if ($poll->getAuthorPHID()) {
$author = $handles[$poll->getAuthorPHID()]->renderLink();
} else {
$author = null;
}
$item = id(new PHUIObjectItemView())
->setObjectName('V'.$poll->getID())
->setHeader($poll->getQuestion())
->setHref('/V'.$poll->getID())
->setDisabled($poll->getIsClosed())
->addIcon('none', $date_created);
$description = $poll->getDescription();
if (strlen($description)) {
$item->addAttribute(phutil_utf8_shorten($poll->getDescription(), 120));
}
if ($author) {
$item->addByline(pht('Author: %s', $author));
}
$list->addItem($item);
}
return $list;
}
}