Page MenuHomePhabricator

D12439.diff
No OneTemporary

D12439.diff

diff --git a/src/applications/macro/query/PhabricatorMacroQuery.php b/src/applications/macro/query/PhabricatorMacroQuery.php
--- a/src/applications/macro/query/PhabricatorMacroQuery.php
+++ b/src/applications/macro/query/PhabricatorMacroQuery.php
@@ -8,6 +8,7 @@
private $authors;
private $names;
private $nameLike;
+ private $namePrefix;
private $dateCreatedAfter;
private $dateCreatedBefore;
private $flagColor;
@@ -65,6 +66,11 @@
return $this;
}
+ public function withNamePrefix($prefix) {
+ $this->namePrefix = $prefix;
+ return $this;
+ }
+
public function withStatus($status) {
$this->status = $status;
return $this;
@@ -143,6 +149,13 @@
$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 @@
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();
+ }
+
}
diff --git a/src/applications/macro/query/PhabricatorMacroSearchEngine.php b/src/applications/macro/query/PhabricatorMacroSearchEngine.php
--- a/src/applications/macro/query/PhabricatorMacroSearchEngine.php
+++ b/src/applications/macro/query/PhabricatorMacroSearchEngine.php
@@ -24,6 +24,8 @@
$saved->setParameter('createdEnd', $request->getStr('createdEnd'));
$saved->setParameter('flagColor', $request->getStr('flagColor', '-1'));
+ $this->saveQueryOrder($saved, $request);
+
return $saved;
}
@@ -34,6 +36,8 @@
->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 @@
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 @@
$this->buildDateRange(
$form,
- $saved_query,
+ $saved,
'createdStart',
pht('Created After'),
'createdEnd',
pht('Created Before'));
+
+ $this->appendOrderFieldsToForm(
+ $form,
+ $saved,
+ new PhabricatorMacroQuery());
}
protected function getURI($path) {
diff --git a/src/applications/macro/typeahead/PhabricatorMacroDatasource.php b/src/applications/macro/typeahead/PhabricatorMacroDatasource.php
--- a/src/applications/macro/typeahead/PhabricatorMacroDatasource.php
+++ b/src/applications/macro/typeahead/PhabricatorMacroDatasource.php
@@ -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 @@
}
public function loadResults() {
- $viewer = $this->getViewer();
$raw_query = $this->getRawQuery();
- $results = array();
-
- $macros = id(new PhabricatorMacroQuery())
- ->setViewer($viewer)
- ->withStatus(PhabricatorMacroQuery::STATUS_ACTIVE)
- ->execute();
+ $query = id(new PhabricatorMacroQuery())
+ ->setOrder('name')
+ ->withNamePrefix($raw_query);
+ $macros = $this->executeQuery($query);
+ $results = array();
foreach ($macros as $macro) {
+ $closed = null;
+ if ($macro->getIsDisabled()) {
+ $closed = pht('Disabled');
+ }
+
$results[] = id(new PhabricatorTypeaheadResult())
->setPHID($macro->getPHID())
+ ->setClosed($closed)
->setName($macro->getName());
}
diff --git a/src/applications/search/engine/PhabricatorApplicationSearchEngine.php b/src/applications/search/engine/PhabricatorApplicationSearchEngine.php
--- a/src/applications/search/engine/PhabricatorApplicationSearchEngine.php
+++ b/src/applications/search/engine/PhabricatorApplicationSearchEngine.php
@@ -602,18 +602,16 @@
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;

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 9, 4:41 AM (1 w, 3 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6727160
Default Alt Text
D12439.diff (6 KB)

Event Timeline