2013-09-10 15:26:08 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
final class PhabricatorRepositorySearchEngine
|
|
|
|
|
extends PhabricatorApplicationSearchEngine {
|
|
|
|
|
|
|
|
|
|
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
|
|
|
|
$saved = new PhabricatorSavedQuery();
|
|
|
|
|
|
|
|
|
|
$saved->setParameter('callsigns', $request->getStrList('callsigns'));
|
2013-09-10 15:26:23 -07:00
|
|
|
$saved->setParameter('status', $request->getStr('status'));
|
2013-09-08 11:49:06 -07:00
|
|
|
$saved->setParameter('order', $request->getStr('order'));
|
2013-09-10 15:26:08 -07:00
|
|
|
|
|
|
|
|
return $saved;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
|
|
|
|
$query = id(new PhabricatorRepositoryQuery())
|
|
|
|
|
->needCommitCounts(true)
|
|
|
|
|
->needMostRecentCommits(true);
|
|
|
|
|
|
|
|
|
|
$callsigns = $saved->getParameter('callsigns');
|
|
|
|
|
if ($callsigns) {
|
|
|
|
|
$query->withCallsigns($callsigns);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-10 15:26:23 -07:00
|
|
|
$status = $saved->getParameter('status');
|
|
|
|
|
$status = idx($this->getStatusValues(), $status);
|
|
|
|
|
if ($status) {
|
|
|
|
|
$query->withStatus($status);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-08 11:49:06 -07:00
|
|
|
$order = $saved->getParameter('order');
|
|
|
|
|
$order = idx($this->getOrderValues(), $order);
|
|
|
|
|
if ($order) {
|
|
|
|
|
$query->setOrder($order);
|
|
|
|
|
} else {
|
|
|
|
|
$query->setOrder(head($this->getOrderValues()));
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-10 15:26:08 -07:00
|
|
|
return $query;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function buildSearchForm(
|
|
|
|
|
AphrontFormView $form,
|
|
|
|
|
PhabricatorSavedQuery $saved_query) {
|
|
|
|
|
|
|
|
|
|
$callsigns = $saved_query->getParameter('callsigns', array());
|
|
|
|
|
|
|
|
|
|
$form
|
|
|
|
|
->appendChild(
|
|
|
|
|
id(new AphrontFormTextControl())
|
|
|
|
|
->setName('callsigns')
|
|
|
|
|
->setLabel(pht('Callsigns'))
|
2013-09-10 15:26:23 -07:00
|
|
|
->setValue(implode(', ', $callsigns)))
|
|
|
|
|
->appendChild(
|
|
|
|
|
id(new AphrontFormSelectControl())
|
|
|
|
|
->setName('status')
|
|
|
|
|
->setLabel(pht('Status'))
|
|
|
|
|
->setValue($saved_query->getParameter('status'))
|
2013-09-08 11:49:06 -07:00
|
|
|
->setOptions($this->getStatusOptions()))
|
|
|
|
|
->appendChild(
|
|
|
|
|
id(new AphrontFormSelectControl())
|
|
|
|
|
->setName('order')
|
|
|
|
|
->setLabel(pht('Order'))
|
|
|
|
|
->setValue($saved_query->getParameter('order'))
|
|
|
|
|
->setOptions($this->getOrderOptions()));
|
2013-09-10 15:26:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function getURI($path) {
|
|
|
|
|
return '/diffusion/'.$path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getBuiltinQueryNames() {
|
|
|
|
|
$names = array(
|
2013-09-10 15:26:23 -07:00
|
|
|
'active' => pht('Active Repositories'),
|
2013-09-10 15:26:08 -07:00
|
|
|
'all' => pht('All Repositories'),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return $names;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function buildSavedQueryFromBuiltin($query_key) {
|
|
|
|
|
|
|
|
|
|
$query = $this->newSavedQuery();
|
|
|
|
|
$query->setQueryKey($query_key);
|
|
|
|
|
|
|
|
|
|
switch ($query_key) {
|
2013-09-10 15:26:23 -07:00
|
|
|
case 'active':
|
|
|
|
|
return $query->setParameter('status', 'open');
|
2013-09-10 15:26:08 -07:00
|
|
|
case 'all':
|
|
|
|
|
return $query;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return parent::buildSavedQueryFromBuiltin($query_key);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-10 15:26:23 -07:00
|
|
|
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,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-08 11:49:06 -07:00
|
|
|
private function getOrderOptions() {
|
|
|
|
|
return array(
|
|
|
|
|
'committed' => pht('Most Recent Commit'),
|
|
|
|
|
'name' => pht('Name'),
|
|
|
|
|
'callsign' => pht('Callsign'),
|
|
|
|
|
'created' => pht('Date Created'),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function getOrderValues() {
|
|
|
|
|
return array(
|
|
|
|
|
'committed' => PhabricatorRepositoryQuery::ORDER_COMMITTED,
|
|
|
|
|
'name' => PhabricatorRepositoryQuery::ORDER_NAME,
|
|
|
|
|
'callsign' => PhabricatorRepositoryQuery::ORDER_CALLSIGN,
|
|
|
|
|
'created' => PhabricatorRepositoryQuery::ORDER_CREATED,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-09-10 15:26:08 -07:00
|
|
|
}
|