1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-27 09:12:41 +01:00

Modernize Slowvote Search

Summary: Updates slowvote search forms and results. Note I can't seem to get the Joins clause to fire anymore, is there a modern equiv?

Test Plan: Search on polls by state, votes, author, projects.

Reviewers: btrahan, epriestley

Reviewed By: epriestley

Subscribers: epriestley, Korvin

Differential Revision: https://secure.phabricator.com/D13666
This commit is contained in:
Chad Little 2015-07-22 16:27:53 -07:00
parent ffadf64751
commit 3bfb436296
2 changed files with 57 additions and 81 deletions

View file

@ -53,20 +53,12 @@ final class PhabricatorSlowvoteQuery
return $this; return $this;
} }
public function newResultObject() {
return new PhabricatorSlowvotePoll();
}
protected function loadPage() { protected function loadPage() {
$table = new PhabricatorSlowvotePoll(); return $this->loadStandardPage($this->newResultObject());
$conn_r = $table->establishConnection('r');
$data = queryfx_all(
$conn_r,
'SELECT p.* FROM %T p %Q %Q %Q %Q',
$table->getTableName(),
$this->buildJoinsClause($conn_r),
$this->buildWhereClause($conn_r),
$this->buildOrderClause($conn_r),
$this->buildLimitClause($conn_r));
return $table->loadAllFromArray($data);
} }
protected function willFilterPage(array $polls) { protected function willFilterPage(array $polls) {
@ -125,53 +117,50 @@ final class PhabricatorSlowvoteQuery
return $polls; return $polls;
} }
protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
$where = array(); $where = parent::buildWhereClauseParts($conn);
if ($this->ids) { if ($this->ids !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn,
'p.id IN (%Ld)', 'p.id IN (%Ld)',
$this->ids); $this->ids);
} }
if ($this->phids) { if ($this->phids !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn,
'p.phid IN (%Ls)', 'p.phid IN (%Ls)',
$this->phids); $this->phids);
} }
if ($this->authorPHIDs) { if ($this->authorPHIDs !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn,
'p.authorPHID IN (%Ls)', 'p.authorPHID IN (%Ls)',
$this->authorPHIDs); $this->authorPHIDs);
} }
if ($this->isClosed !== null) { if ($this->isClosed !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn,
'p.isClosed = %d', 'p.isClosed = %d',
(int)$this->isClosed); (int)$this->isClosed);
} }
return $where;
$where[] = $this->buildPagingClause($conn_r);
return $this->formatWhereClause($where);
} }
private function buildJoinsClause(AphrontDatabaseConnection $conn_r) { protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) {
$joins = array(); $joins = parent::buildJoinClauseParts($conn);
if ($this->withVotesByViewer) { if ($this->withVotesByViewer !== null) {
$joins[] = qsprintf( $joins[] = qsprintf(
$conn_r, $conn,
'JOIN %T vv ON vv.pollID = p.id AND vv.authorPHID = %s', 'JOIN %T vv ON vv.pollID = p.id AND vv.authorPHID = %s',
id(new PhabricatorSlowvoteChoice())->getTableName(), id(new PhabricatorSlowvoteChoice())->getTableName(),
$this->getViewer()->getPHID()); $this->getViewer()->getPHID());
} }
return $joins;
return implode(' ', $joins);
} }
protected function getPrimaryTableAlias() { protected function getPrimaryTableAlias() {

View file

@ -11,27 +11,22 @@ final class PhabricatorSlowvoteSearchEngine
return 'PhabricatorSlowvoteApplication'; return 'PhabricatorSlowvoteApplication';
} }
public function buildSavedQueryFromRequest(AphrontRequest $request) { public function newQuery() {
$saved = new PhabricatorSavedQuery(); return new PhabricatorSlowvoteQuery();
$saved->setParameter(
'authorPHIDs',
$this->readUsersFromRequest($request, 'authors'));
$saved->setParameter('voted', $request->getBool('voted'));
$saved->setParameter('statuses', $request->getArr('statuses'));
return $saved;
} }
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { protected function buildQueryFromParameters(array $map) {
$query = id(new PhabricatorSlowvoteQuery()) $query = $this->newQuery();
->withAuthorPHIDs($saved->getParameter('authorPHIDs', array()));
if ($saved->getParameter('voted')) { if ($map['voted']) {
$query->withVotesByViewer(true); $query->withVotesByViewer(true);
} }
$statuses = $saved->getParameter('statuses', array()); if ($map['authorPHIDs']) {
$query->withAuthorPHIDs($map['authorPHIDs']);
}
$statuses = $map['statuses'];
if (count($statuses) == 1) { if (count($statuses) == 1) {
$status = head($statuses); $status = head($statuses);
if ($status == 'open') { if ($status == 'open') {
@ -44,41 +39,27 @@ final class PhabricatorSlowvoteSearchEngine
return $query; return $query;
} }
public function buildSearchForm( protected function buildCustomSearchFields() {
AphrontFormView $form,
PhabricatorSavedQuery $saved_query) {
$author_phids = $saved_query->getParameter('authorPHIDs', array());
$voted = $saved_query->getParameter('voted', false); return array(
$statuses = $saved_query->getParameter('statuses', array()); id(new PhabricatorUsersSearchField())
->setKey('authorPHIDs')
->setAliases(array('authors'))
->setLabel(pht('Authors')),
$form id(new PhabricatorSearchCheckboxesField())
->appendControl( ->setKey('voted')
id(new AphrontFormTokenizerControl()) ->setOptions(array(
->setDatasource(new PhabricatorPeopleDatasource()) 'voted' => pht("Show only polls I've voted in."),
->setName('authors') )),
->setLabel(pht('Authors'))
->setValue($author_phids)) id(new PhabricatorSearchCheckboxesField())
->appendChild( ->setKey('statuses')
id(new AphrontFormCheckboxControl()) ->setOptions(array(
->addCheckbox( 'open' => pht('Open'),
'voted', 'closed' => pht('Closed'),
1, )),
pht("Show only polls I've voted in."), );
$voted))
->appendChild(
id(new AphrontFormCheckboxControl())
->setLabel(pht('Status'))
->addCheckbox(
'statuses[]',
'open',
pht('Open'),
in_array('open', $statuses))
->addCheckbox(
'statuses[]',
'closed',
pht('Closed'),
in_array('closed', $statuses)));
} }
protected function getURI($path) { protected function getURI($path) {
@ -113,7 +94,7 @@ final class PhabricatorSlowvoteSearchEngine
'authorPHIDs', 'authorPHIDs',
array($this->requireViewer()->getPHID())); array($this->requireViewer()->getPHID()));
case 'voted': case 'voted':
return $query->setParameter('voted', true); return $query->setParameter('voted', array('voted'));
} }
return parent::buildSavedQueryFromBuiltin($query_key); return parent::buildSavedQueryFromBuiltin($query_key);
@ -152,9 +133,15 @@ final class PhabricatorSlowvoteSearchEngine
->setObjectName('V'.$poll->getID()) ->setObjectName('V'.$poll->getID())
->setHeader($poll->getQuestion()) ->setHeader($poll->getQuestion())
->setHref('/V'.$poll->getID()) ->setHref('/V'.$poll->getID())
->setDisabled($poll->getIsClosed())
->addIcon('none', $date_created); ->addIcon('none', $date_created);
if ($poll->getIsClosed()) {
$item->setStatusIcon('fa-ban grey');
$item->setDisabled(true);
} else {
$item->setStatusIcon('fa-bar-chart');
}
$description = $poll->getDescription(); $description = $poll->getDescription();
if (strlen($description)) { if (strlen($description)) {
$item->addAttribute(id(new PhutilUTF8StringTruncator()) $item->addAttribute(id(new PhutilUTF8StringTruncator())