1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-27 01:02:42 +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:
epriestley 2013-09-10 15:26:23 -07:00
parent 904add9f44
commit 9872d57f87
2 changed files with 72 additions and 1 deletions

View file

@ -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();

View file

@ -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,
);
}
}