mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-25 23:10:57 +01:00
Uncheat Macro datasource browse support
Summary: Ref T5750. Macro browse support is actually useful (in the meme dialog) and fairly straightforward to implement. Test Plan: - Browsed macros. - Queired macros. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T5750 Differential Revision: https://secure.phabricator.com/D12439
This commit is contained in:
parent
7db362a4b6
commit
ba48e05964
4 changed files with 79 additions and 31 deletions
src/applications
macro
query
typeahead
search/engine
|
@ -8,6 +8,7 @@ final class PhabricatorMacroQuery
|
|||
private $authors;
|
||||
private $names;
|
||||
private $nameLike;
|
||||
private $namePrefix;
|
||||
private $dateCreatedAfter;
|
||||
private $dateCreatedBefore;
|
||||
private $flagColor;
|
||||
|
@ -65,6 +66,11 @@ final class PhabricatorMacroQuery
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function withNamePrefix($prefix) {
|
||||
$this->namePrefix = $prefix;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withStatus($status) {
|
||||
$this->status = $status;
|
||||
return $this;
|
||||
|
@ -143,6 +149,13 @@ final class PhabricatorMacroQuery
|
|||
$this->names);
|
||||
}
|
||||
|
||||
if (strlen($this->namePrefix)) {
|
||||
$where[] = qsprintf(
|
||||
$conn,
|
||||
'm.name LIKE %>',
|
||||
$this->namePrefix);
|
||||
}
|
||||
|
||||
switch ($this->status) {
|
||||
case self::STATUS_ACTIVE:
|
||||
$where[] = qsprintf(
|
||||
|
@ -233,4 +246,33 @@ final class PhabricatorMacroQuery
|
|||
return 'PhabricatorMacroApplication';
|
||||
}
|
||||
|
||||
public function getOrderableColumns() {
|
||||
return parent::getOrderableColumns() + array(
|
||||
'name' => array(
|
||||
'table' => 'm',
|
||||
'column' => 'name',
|
||||
'type' => 'string',
|
||||
'reverse' => true,
|
||||
'unique' => true,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function getPagingValueMap($cursor, array $keys) {
|
||||
$macro = $this->loadCursorObject($cursor);
|
||||
return array(
|
||||
'id' => $macro->getID(),
|
||||
'name' => $macro->getName(),
|
||||
);
|
||||
}
|
||||
|
||||
public function getBuiltinOrders() {
|
||||
return array(
|
||||
'name' => array(
|
||||
'vector' => array('name'),
|
||||
'name' => pht('Name'),
|
||||
),
|
||||
) + parent::getBuiltinOrders();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,6 +24,8 @@ final class PhabricatorMacroSearchEngine
|
|||
$saved->setParameter('createdEnd', $request->getStr('createdEnd'));
|
||||
$saved->setParameter('flagColor', $request->getStr('flagColor', '-1'));
|
||||
|
||||
$this->saveQueryOrder($saved, $request);
|
||||
|
||||
return $saved;
|
||||
}
|
||||
|
||||
|
@ -34,6 +36,8 @@ final class PhabricatorMacroSearchEngine
|
|||
->withPHIDs($saved->getParameter('phids', array()))
|
||||
->withAuthorPHIDs($saved->getParameter('authorPHIDs', array()));
|
||||
|
||||
$this->setQueryOrder($query, $saved);
|
||||
|
||||
$status = $saved->getParameter('status');
|
||||
$options = PhabricatorMacroQuery::getStatusOptions();
|
||||
if (empty($options[$status])) {
|
||||
|
@ -72,13 +76,13 @@ final class PhabricatorMacroSearchEngine
|
|||
|
||||
public function buildSearchForm(
|
||||
AphrontFormView $form,
|
||||
PhabricatorSavedQuery $saved_query) {
|
||||
PhabricatorSavedQuery $saved) {
|
||||
|
||||
$author_phids = $saved_query->getParameter('authorPHIDs', array());
|
||||
$status = $saved_query->getParameter('status');
|
||||
$names = implode(', ', $saved_query->getParameter('names', array()));
|
||||
$like = $saved_query->getParameter('nameLike');
|
||||
$color = $saved_query->getParameter('flagColor', '-1');
|
||||
$author_phids = $saved->getParameter('authorPHIDs', array());
|
||||
$status = $saved->getParameter('status');
|
||||
$names = implode(', ', $saved->getParameter('names', array()));
|
||||
$like = $saved->getParameter('nameLike');
|
||||
$color = $saved->getParameter('flagColor', '-1');
|
||||
|
||||
$form
|
||||
->appendChild(
|
||||
|
@ -112,11 +116,16 @@ final class PhabricatorMacroSearchEngine
|
|||
|
||||
$this->buildDateRange(
|
||||
$form,
|
||||
$saved_query,
|
||||
$saved,
|
||||
'createdStart',
|
||||
pht('Created After'),
|
||||
'createdEnd',
|
||||
pht('Created Before'));
|
||||
|
||||
$this->appendOrderFieldsToForm(
|
||||
$form,
|
||||
$saved,
|
||||
new PhabricatorMacroQuery());
|
||||
}
|
||||
|
||||
protected function getURI($path) {
|
||||
|
|
|
@ -2,11 +2,6 @@
|
|||
|
||||
final class PhabricatorMacroDatasource extends PhabricatorTypeaheadDatasource {
|
||||
|
||||
public function isBrowsable() {
|
||||
// TODO: This should be made browsable.
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getPlaceholderText() {
|
||||
return pht('Type a macro name...');
|
||||
}
|
||||
|
@ -16,19 +11,23 @@ final class PhabricatorMacroDatasource extends PhabricatorTypeaheadDatasource {
|
|||
}
|
||||
|
||||
public function loadResults() {
|
||||
$viewer = $this->getViewer();
|
||||
$raw_query = $this->getRawQuery();
|
||||
|
||||
$query = id(new PhabricatorMacroQuery())
|
||||
->setOrder('name')
|
||||
->withNamePrefix($raw_query);
|
||||
$macros = $this->executeQuery($query);
|
||||
|
||||
$results = array();
|
||||
|
||||
$macros = id(new PhabricatorMacroQuery())
|
||||
->setViewer($viewer)
|
||||
->withStatus(PhabricatorMacroQuery::STATUS_ACTIVE)
|
||||
->execute();
|
||||
|
||||
foreach ($macros as $macro) {
|
||||
$closed = null;
|
||||
if ($macro->getIsDisabled()) {
|
||||
$closed = pht('Disabled');
|
||||
}
|
||||
|
||||
$results[] = id(new PhabricatorTypeaheadResult())
|
||||
->setPHID($macro->getPHID())
|
||||
->setClosed($closed)
|
||||
->setName($macro->getName());
|
||||
}
|
||||
|
||||
|
|
|
@ -602,18 +602,16 @@ abstract class PhabricatorApplicationSearchEngine {
|
|||
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));
|
||||
}
|
||||
$builtin = $query->getBuiltinOrders();
|
||||
if (strlen($order) && 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;
|
||||
|
|
Loading…
Reference in a new issue