diff --git a/src/applications/repository/query/PhabricatorRepositoryQuery.php b/src/applications/repository/query/PhabricatorRepositoryQuery.php index 8b5af5fc19..7d5bb68e50 100644 --- a/src/applications/repository/query/PhabricatorRepositoryQuery.php +++ b/src/applications/repository/query/PhabricatorRepositoryQuery.php @@ -7,6 +7,11 @@ final class PhabricatorRepositoryQuery private $phids; private $callsigns; + const STATUS_OPEN = 'status-open'; + const STATUS_CLOSED = 'status-closed'; + const STATUS_ALL = 'status-all'; + private $status = self::STATUS_ALL; + private $needMostRecentCommits; private $needCommitCounts; @@ -29,6 +34,11 @@ final class PhabricatorRepositoryQuery return true; } + public function withStatus($status) { + $this->status = $status; + return $this; + } + public function needCommitCounts($need_counts) { $this->needCommitCounts = $need_counts; return $this; @@ -39,6 +49,7 @@ final class PhabricatorRepositoryQuery return $this; } + protected function loadPage() { $table = new PhabricatorRepository(); $conn_r = $table->establishConnection('r'); @@ -85,6 +96,34 @@ final class PhabricatorRepositoryQuery return $repositories; } + public function willFilterPage(array $repositories) { + assert_instances_of($repositories, 'PhabricatorRepository'); + + // TODO: Denormalize repository status into the PhabricatorRepository + // table so we can do this filtering in the database. + foreach ($repositories as $key => $repo) { + $status = $this->status; + switch ($status) { + case self::STATUS_OPEN: + if (!$repo->isTracked()) { + unset($repositories[$key]); + } + break; + case self::STATUS_CLOSED: + if ($repo->isTracked()) { + unset($repositories[$key]); + } + break; + case self::STATUS_ALL: + break; + default: + throw new Exception("Unknown status '{$status}'!"); + } + } + + return $repositories; + } + private function buildJoinsClause(AphrontDatabaseConnection $conn_r) { $joins = array(); diff --git a/src/applications/repository/query/PhabricatorRepositorySearchEngine.php b/src/applications/repository/query/PhabricatorRepositorySearchEngine.php index f4aaa74f1d..51c8d68641 100644 --- a/src/applications/repository/query/PhabricatorRepositorySearchEngine.php +++ b/src/applications/repository/query/PhabricatorRepositorySearchEngine.php @@ -7,6 +7,7 @@ final class PhabricatorRepositorySearchEngine $saved = new PhabricatorSavedQuery(); $saved->setParameter('callsigns', $request->getStrList('callsigns')); + $saved->setParameter('status', $request->getStr('status')); return $saved; } @@ -21,6 +22,12 @@ final class PhabricatorRepositorySearchEngine $query->withCallsigns($callsigns); } + $status = $saved->getParameter('status'); + $status = idx($this->getStatusValues(), $status); + if ($status) { + $query->withStatus($status); + } + return $query; } @@ -35,7 +42,13 @@ final class PhabricatorRepositorySearchEngine id(new AphrontFormTextControl()) ->setName('callsigns') ->setLabel(pht('Callsigns')) - ->setValue(implode(', ', $callsigns))); + ->setValue(implode(', ', $callsigns))) + ->appendChild( + id(new AphrontFormSelectControl()) + ->setName('status') + ->setLabel(pht('Status')) + ->setValue($saved_query->getParameter('status')) + ->setOptions($this->getStatusOptions())); } protected function getURI($path) { @@ -44,6 +57,7 @@ final class PhabricatorRepositorySearchEngine public function getBuiltinQueryNames() { $names = array( + 'active' => pht('Active Repositories'), 'all' => pht('All Repositories'), ); @@ -56,6 +70,8 @@ final class PhabricatorRepositorySearchEngine $query->setQueryKey($query_key); switch ($query_key) { + case 'active': + return $query->setParameter('status', 'open'); case 'all': return $query; } @@ -63,4 +79,20 @@ final class PhabricatorRepositorySearchEngine return parent::buildSavedQueryFromBuiltin($query_key); } + private function getStatusOptions() { + return array( + '' => pht('Active and Inactive Repositories'), + 'open' => pht('Active Repositories'), + 'closed' => pht('Inactive Repositories'), + ); + } + + private function getStatusValues() { + return array( + '' => PhabricatorRepositoryQuery::STATUS_ALL, + 'open' => PhabricatorRepositoryQuery::STATUS_OPEN, + 'closed' => PhabricatorRepositoryQuery::STATUS_CLOSED, + ); + } + }