mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-19 03:01:11 +01: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:
parent
c8dc11d81a
commit
9437414f17
6 changed files with 85 additions and 29 deletions
|
@ -192,4 +192,33 @@ final class AlmanacServiceQuery
|
||||||
return parent::didFilterPage($services);
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,18 +14,28 @@ final class AlmanacServiceSearchEngine
|
||||||
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
||||||
$saved = new PhabricatorSavedQuery();
|
$saved = new PhabricatorSavedQuery();
|
||||||
|
|
||||||
|
$this->saveQueryOrder($saved, $request);
|
||||||
|
|
||||||
return $saved;
|
return $saved;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
||||||
$query = id(new AlmanacServiceQuery());
|
$query = id(new AlmanacServiceQuery());
|
||||||
|
|
||||||
|
$this->setQueryOrder($query, $saved);
|
||||||
|
|
||||||
return $query;
|
return $query;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function buildSearchForm(
|
public function buildSearchForm(
|
||||||
AphrontFormView $form,
|
AphrontFormView $form,
|
||||||
PhabricatorSavedQuery $saved_query) {}
|
PhabricatorSavedQuery $saved) {
|
||||||
|
|
||||||
|
$this->appendOrderFieldsToForm(
|
||||||
|
$form,
|
||||||
|
$saved,
|
||||||
|
new AlmanacServiceQuery());
|
||||||
|
}
|
||||||
|
|
||||||
protected function getURI($path) {
|
protected function getURI($path) {
|
||||||
return '/almanac/service/'.$path;
|
return '/almanac/service/'.$path;
|
||||||
|
|
|
@ -16,10 +16,10 @@ final class AlmanacServiceDatasource
|
||||||
$raw_query = $this->getRawQuery();
|
$raw_query = $this->getRawQuery();
|
||||||
|
|
||||||
$services = id(new AlmanacServiceQuery())
|
$services = id(new AlmanacServiceQuery())
|
||||||
->setViewer($viewer)
|
|
||||||
->withNamePrefix($raw_query)
|
->withNamePrefix($raw_query)
|
||||||
->setLimit($this->getLimit())
|
->setOrder('name');
|
||||||
->execute();
|
|
||||||
|
$services = $this->executeQuery($services);
|
||||||
|
|
||||||
if ($services) {
|
if ($services) {
|
||||||
$handles = id(new PhabricatorHandleQuery())
|
$handles = id(new PhabricatorHandleQuery())
|
||||||
|
|
|
@ -27,7 +27,6 @@ final class PhabricatorRepositorySearchEngine
|
||||||
|
|
||||||
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
||||||
$query = id(new PhabricatorRepositoryQuery())
|
$query = id(new PhabricatorRepositoryQuery())
|
||||||
->setDefaultBuiltinOrder()
|
|
||||||
->needProjectPHIDs(true)
|
->needProjectPHIDs(true)
|
||||||
->needCommitCounts(true)
|
->needCommitCounts(true)
|
||||||
->needMostRecentCommits(true);
|
->needMostRecentCommits(true);
|
||||||
|
@ -43,10 +42,7 @@ final class PhabricatorRepositorySearchEngine
|
||||||
$query->withStatus($status);
|
$query->withStatus($status);
|
||||||
}
|
}
|
||||||
|
|
||||||
$order = $saved->getParameter('order');
|
$this->setQueryOrder($query, $saved);
|
||||||
if ($order) {
|
|
||||||
$query->setOrder($order);
|
|
||||||
}
|
|
||||||
|
|
||||||
$hosted = $saved->getParameter('hosted');
|
$hosted = $saved->getParameter('hosted');
|
||||||
$hosted = idx($this->getHostedValues(), $hosted);
|
$hosted = idx($this->getHostedValues(), $hosted);
|
||||||
|
|
|
@ -580,6 +580,47 @@ abstract class PhabricatorApplicationSearchEngine {
|
||||||
|
|
||||||
/* -( Result Ordering )---------------------------------------------------- */
|
/* -( 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(
|
protected function appendOrderFieldsToForm(
|
||||||
AphrontFormView $form,
|
AphrontFormView $form,
|
||||||
PhabricatorSavedQuery $saved,
|
PhabricatorSavedQuery $saved,
|
||||||
|
|
|
@ -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.
|
* Get builtin orders for this class.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue