From 3bfb436296029717710fec11bb2c0dead5cc6270 Mon Sep 17 00:00:00 2001 From: Chad Little Date: Wed, 22 Jul 2015 16:27:53 -0700 Subject: [PATCH] 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 --- .../query/PhabricatorSlowvoteQuery.php | 51 +++++------ .../query/PhabricatorSlowvoteSearchEngine.php | 87 ++++++++----------- 2 files changed, 57 insertions(+), 81 deletions(-) diff --git a/src/applications/slowvote/query/PhabricatorSlowvoteQuery.php b/src/applications/slowvote/query/PhabricatorSlowvoteQuery.php index b7449d06a9..0b7335326c 100644 --- a/src/applications/slowvote/query/PhabricatorSlowvoteQuery.php +++ b/src/applications/slowvote/query/PhabricatorSlowvoteQuery.php @@ -53,20 +53,12 @@ final class PhabricatorSlowvoteQuery return $this; } + public function newResultObject() { + return new PhabricatorSlowvotePoll(); + } + protected function loadPage() { - $table = new PhabricatorSlowvotePoll(); - $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); + return $this->loadStandardPage($this->newResultObject()); } protected function willFilterPage(array $polls) { @@ -125,53 +117,50 @@ final class PhabricatorSlowvoteQuery return $polls; } - protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { - $where = array(); + protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { + $where = parent::buildWhereClauseParts($conn); - if ($this->ids) { + if ($this->ids !== null) { $where[] = qsprintf( - $conn_r, + $conn, 'p.id IN (%Ld)', $this->ids); } - if ($this->phids) { + if ($this->phids !== null) { $where[] = qsprintf( - $conn_r, + $conn, 'p.phid IN (%Ls)', $this->phids); } - if ($this->authorPHIDs) { + if ($this->authorPHIDs !== null) { $where[] = qsprintf( - $conn_r, + $conn, 'p.authorPHID IN (%Ls)', $this->authorPHIDs); } if ($this->isClosed !== null) { $where[] = qsprintf( - $conn_r, + $conn, 'p.isClosed = %d', (int)$this->isClosed); } - - $where[] = $this->buildPagingClause($conn_r); - return $this->formatWhereClause($where); + return $where; } - private function buildJoinsClause(AphrontDatabaseConnection $conn_r) { - $joins = array(); + protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) { + $joins = parent::buildJoinClauseParts($conn); - if ($this->withVotesByViewer) { + if ($this->withVotesByViewer !== null) { $joins[] = qsprintf( - $conn_r, + $conn, 'JOIN %T vv ON vv.pollID = p.id AND vv.authorPHID = %s', id(new PhabricatorSlowvoteChoice())->getTableName(), $this->getViewer()->getPHID()); } - - return implode(' ', $joins); + return $joins; } protected function getPrimaryTableAlias() { diff --git a/src/applications/slowvote/query/PhabricatorSlowvoteSearchEngine.php b/src/applications/slowvote/query/PhabricatorSlowvoteSearchEngine.php index dc4bff410d..6605bc9ecc 100644 --- a/src/applications/slowvote/query/PhabricatorSlowvoteSearchEngine.php +++ b/src/applications/slowvote/query/PhabricatorSlowvoteSearchEngine.php @@ -11,27 +11,22 @@ final class PhabricatorSlowvoteSearchEngine return 'PhabricatorSlowvoteApplication'; } - public function buildSavedQueryFromRequest(AphrontRequest $request) { - $saved = new PhabricatorSavedQuery(); - $saved->setParameter( - 'authorPHIDs', - $this->readUsersFromRequest($request, 'authors')); - - $saved->setParameter('voted', $request->getBool('voted')); - $saved->setParameter('statuses', $request->getArr('statuses')); - - return $saved; + public function newQuery() { + return new PhabricatorSlowvoteQuery(); } - public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { - $query = id(new PhabricatorSlowvoteQuery()) - ->withAuthorPHIDs($saved->getParameter('authorPHIDs', array())); + protected function buildQueryFromParameters(array $map) { + $query = $this->newQuery(); - if ($saved->getParameter('voted')) { + if ($map['voted']) { $query->withVotesByViewer(true); } - $statuses = $saved->getParameter('statuses', array()); + if ($map['authorPHIDs']) { + $query->withAuthorPHIDs($map['authorPHIDs']); + } + + $statuses = $map['statuses']; if (count($statuses) == 1) { $status = head($statuses); if ($status == 'open') { @@ -44,41 +39,27 @@ final class PhabricatorSlowvoteSearchEngine return $query; } - public function buildSearchForm( - AphrontFormView $form, - PhabricatorSavedQuery $saved_query) { - $author_phids = $saved_query->getParameter('authorPHIDs', array()); + protected function buildCustomSearchFields() { - $voted = $saved_query->getParameter('voted', false); - $statuses = $saved_query->getParameter('statuses', array()); + return array( + id(new PhabricatorUsersSearchField()) + ->setKey('authorPHIDs') + ->setAliases(array('authors')) + ->setLabel(pht('Authors')), - $form - ->appendControl( - id(new AphrontFormTokenizerControl()) - ->setDatasource(new PhabricatorPeopleDatasource()) - ->setName('authors') - ->setLabel(pht('Authors')) - ->setValue($author_phids)) - ->appendChild( - id(new AphrontFormCheckboxControl()) - ->addCheckbox( - 'voted', - 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))); + id(new PhabricatorSearchCheckboxesField()) + ->setKey('voted') + ->setOptions(array( + 'voted' => pht("Show only polls I've voted in."), + )), + + id(new PhabricatorSearchCheckboxesField()) + ->setKey('statuses') + ->setOptions(array( + 'open' => pht('Open'), + 'closed' => pht('Closed'), + )), + ); } protected function getURI($path) { @@ -113,7 +94,7 @@ final class PhabricatorSlowvoteSearchEngine 'authorPHIDs', array($this->requireViewer()->getPHID())); case 'voted': - return $query->setParameter('voted', true); + return $query->setParameter('voted', array('voted')); } return parent::buildSavedQueryFromBuiltin($query_key); @@ -152,9 +133,15 @@ final class PhabricatorSlowvoteSearchEngine ->setObjectName('V'.$poll->getID()) ->setHeader($poll->getQuestion()) ->setHref('/V'.$poll->getID()) - ->setDisabled($poll->getIsClosed()) ->addIcon('none', $date_created); + if ($poll->getIsClosed()) { + $item->setStatusIcon('fa-ban grey'); + $item->setDisabled(true); + } else { + $item->setStatusIcon('fa-bar-chart'); + } + $description = $poll->getDescription(); if (strlen($description)) { $item->addAttribute(id(new PhutilUTF8StringTruncator())