mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-27 09:12:41 +01:00
Allow Diffusion repostories to be filtered by active/inactive status
Summary: Adds a status filter and makes the default query "active" repositories. Test Plan: Used new filter to execute queries. Reviewers: btrahan Reviewed By: btrahan CC: aran Differential Revision: https://secure.phabricator.com/D6918
This commit is contained in:
parent
904add9f44
commit
9872d57f87
2 changed files with 72 additions and 1 deletions
|
@ -7,6 +7,11 @@ final class PhabricatorRepositoryQuery
|
||||||
private $phids;
|
private $phids;
|
||||||
private $callsigns;
|
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 $needMostRecentCommits;
|
||||||
private $needCommitCounts;
|
private $needCommitCounts;
|
||||||
|
|
||||||
|
@ -29,6 +34,11 @@ final class PhabricatorRepositoryQuery
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function withStatus($status) {
|
||||||
|
$this->status = $status;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function needCommitCounts($need_counts) {
|
public function needCommitCounts($need_counts) {
|
||||||
$this->needCommitCounts = $need_counts;
|
$this->needCommitCounts = $need_counts;
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -39,6 +49,7 @@ final class PhabricatorRepositoryQuery
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected function loadPage() {
|
protected function loadPage() {
|
||||||
$table = new PhabricatorRepository();
|
$table = new PhabricatorRepository();
|
||||||
$conn_r = $table->establishConnection('r');
|
$conn_r = $table->establishConnection('r');
|
||||||
|
@ -85,6 +96,34 @@ final class PhabricatorRepositoryQuery
|
||||||
return $repositories;
|
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) {
|
private function buildJoinsClause(AphrontDatabaseConnection $conn_r) {
|
||||||
$joins = array();
|
$joins = array();
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ final class PhabricatorRepositorySearchEngine
|
||||||
$saved = new PhabricatorSavedQuery();
|
$saved = new PhabricatorSavedQuery();
|
||||||
|
|
||||||
$saved->setParameter('callsigns', $request->getStrList('callsigns'));
|
$saved->setParameter('callsigns', $request->getStrList('callsigns'));
|
||||||
|
$saved->setParameter('status', $request->getStr('status'));
|
||||||
|
|
||||||
return $saved;
|
return $saved;
|
||||||
}
|
}
|
||||||
|
@ -21,6 +22,12 @@ final class PhabricatorRepositorySearchEngine
|
||||||
$query->withCallsigns($callsigns);
|
$query->withCallsigns($callsigns);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$status = $saved->getParameter('status');
|
||||||
|
$status = idx($this->getStatusValues(), $status);
|
||||||
|
if ($status) {
|
||||||
|
$query->withStatus($status);
|
||||||
|
}
|
||||||
|
|
||||||
return $query;
|
return $query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +42,13 @@ final class PhabricatorRepositorySearchEngine
|
||||||
id(new AphrontFormTextControl())
|
id(new AphrontFormTextControl())
|
||||||
->setName('callsigns')
|
->setName('callsigns')
|
||||||
->setLabel(pht('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) {
|
protected function getURI($path) {
|
||||||
|
@ -44,6 +57,7 @@ final class PhabricatorRepositorySearchEngine
|
||||||
|
|
||||||
public function getBuiltinQueryNames() {
|
public function getBuiltinQueryNames() {
|
||||||
$names = array(
|
$names = array(
|
||||||
|
'active' => pht('Active Repositories'),
|
||||||
'all' => pht('All Repositories'),
|
'all' => pht('All Repositories'),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -56,6 +70,8 @@ final class PhabricatorRepositorySearchEngine
|
||||||
$query->setQueryKey($query_key);
|
$query->setQueryKey($query_key);
|
||||||
|
|
||||||
switch ($query_key) {
|
switch ($query_key) {
|
||||||
|
case 'active':
|
||||||
|
return $query->setParameter('status', 'open');
|
||||||
case 'all':
|
case 'all':
|
||||||
return $query;
|
return $query;
|
||||||
}
|
}
|
||||||
|
@ -63,4 +79,20 @@ final class PhabricatorRepositorySearchEngine
|
||||||
return parent::buildSavedQueryFromBuiltin($query_key);
|
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,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue