1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 09:18:48 +02:00

Improve browsability of Almanac service datasource query

Summary: Ref T5750. Update the Almanac service query to be browsable.

Test Plan:
  - Browsed and reordered Diffusion.
  - Browsed and reordered services in Almanac.

{F373735}

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T5750

Differential Revision: https://secure.phabricator.com/D12433
This commit is contained in:
epriestley 2015-04-16 07:43:13 -07:00
parent c8dc11d81a
commit 9437414f17
6 changed files with 85 additions and 29 deletions

View file

@ -192,4 +192,33 @@ final class AlmanacServiceQuery
return parent::didFilterPage($services);
}
public function getOrderableColumns() {
return parent::getOrderableColumns() + array(
'name' => array(
'table' => 'service',
'column' => 'name',
'type' => 'string',
'unique' => true,
'reverse' => true,
),
);
}
protected function getValueMap($cursor, array $keys) {
$service = $this->loadCursorObject($cursor);
return array(
'id' => $service->getID(),
'name' => $service->getServiceName(),
);
}
public function getBuiltinOrders() {
return array(
'name' => array(
'vector' => array('name'),
'name' => pht('Service Name'),
),
) + parent::getBuiltinOrders();
}
}

View file

@ -14,18 +14,28 @@ final class AlmanacServiceSearchEngine
public function buildSavedQueryFromRequest(AphrontRequest $request) {
$saved = new PhabricatorSavedQuery();
$this->saveQueryOrder($saved, $request);
return $saved;
}
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
$query = id(new AlmanacServiceQuery());
$this->setQueryOrder($query, $saved);
return $query;
}
public function buildSearchForm(
AphrontFormView $form,
PhabricatorSavedQuery $saved_query) {}
PhabricatorSavedQuery $saved) {
$this->appendOrderFieldsToForm(
$form,
$saved,
new AlmanacServiceQuery());
}
protected function getURI($path) {
return '/almanac/service/'.$path;

View file

@ -16,10 +16,10 @@ final class AlmanacServiceDatasource
$raw_query = $this->getRawQuery();
$services = id(new AlmanacServiceQuery())
->setViewer($viewer)
->withNamePrefix($raw_query)
->setLimit($this->getLimit())
->execute();
->setOrder('name');
$services = $this->executeQuery($services);
if ($services) {
$handles = id(new PhabricatorHandleQuery())

View file

@ -27,7 +27,6 @@ final class PhabricatorRepositorySearchEngine
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
$query = id(new PhabricatorRepositoryQuery())
->setDefaultBuiltinOrder()
->needProjectPHIDs(true)
->needCommitCounts(true)
->needMostRecentCommits(true);
@ -43,10 +42,7 @@ final class PhabricatorRepositorySearchEngine
$query->withStatus($status);
}
$order = $saved->getParameter('order');
if ($order) {
$query->setOrder($order);
}
$this->setQueryOrder($query, $saved);
$hosted = $saved->getParameter('hosted');
$hosted = idx($this->getHostedValues(), $hosted);

View file

@ -580,6 +580,47 @@ abstract class PhabricatorApplicationSearchEngine {
/* -( Result Ordering )---------------------------------------------------- */
/**
* Save order selection to a @{class:PhabricatorSavedQuery}.
*/
protected function saveQueryOrder(
PhabricatorSavedQuery $saved,
AphrontRequest $request) {
$saved->setParameter('order', $request->getStr('order'));
return $this;
}
/**
* Set query ordering from a saved value.
*/
protected function setQueryOrder(
PhabricatorCursorPagedPolicyAwareQuery $query,
PhabricatorSavedQuery $saved) {
$order = $saved->getParameter('order');
if (strlen($order)) {
$builtin = $query->getBuiltinOrders();
if (isset($builtin[$order])) {
$query->setOrder($order);
} else {
// If the order is invalid or not available, we choose the first
// builtin order. This isn't always the default order for the query,
// but is the first value in the "Order" dropdown, and makes the query
// behavior more consistent with the UI. In queries where the two
// orders differ, this order is the preferred order for humans.
$query->setOrder(head_key($builtin));
}
}
return $this;
}
protected function appendOrderFieldsToForm(
AphrontFormView $form,
PhabricatorSavedQuery $saved,

View file

@ -479,26 +479,6 @@ abstract class PhabricatorCursorPagedPolicyAwareQuery
}
/**
* Select the default builtin result ordering.
*
* This sets the result order to the default order among the builtin result
* orders (see @{method:getBuiltinOrders}). This is often the same as the
* query's builtin default order vector, but some objects have different
* default vectors (which are internally-facing) and builtin orders (which
* are user-facing).
*
* For example, repositories sort by ID internally (which is efficient and
* consistent), but sort by most recent commit as a default builtin (which
* better aligns with user expectations).
*
* @return this
*/
public function setDefaultBuiltinOrder() {
return $this->setOrder(head_key($this->getBuiltinOrders()));
}
/**
* Get builtin orders for this class.
*