diff --git a/src/applications/macro/query/PhabricatorMacroQuery.php b/src/applications/macro/query/PhabricatorMacroQuery.php index a326f97697..83d9f1abd6 100644 --- a/src/applications/macro/query/PhabricatorMacroQuery.php +++ b/src/applications/macro/query/PhabricatorMacroQuery.php @@ -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(); + } + } diff --git a/src/applications/macro/query/PhabricatorMacroSearchEngine.php b/src/applications/macro/query/PhabricatorMacroSearchEngine.php index 9207685dc5..8a810c886f 100644 --- a/src/applications/macro/query/PhabricatorMacroSearchEngine.php +++ b/src/applications/macro/query/PhabricatorMacroSearchEngine.php @@ -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) { diff --git a/src/applications/macro/typeahead/PhabricatorMacroDatasource.php b/src/applications/macro/typeahead/PhabricatorMacroDatasource.php index 4b8d52b4d4..1d978683cc 100644 --- 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 @@ 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()); } diff --git a/src/applications/search/engine/PhabricatorApplicationSearchEngine.php b/src/applications/search/engine/PhabricatorApplicationSearchEngine.php index 9705c64c89..b10aff4f17 100644 --- a/src/applications/search/engine/PhabricatorApplicationSearchEngine.php +++ b/src/applications/search/engine/PhabricatorApplicationSearchEngine.php @@ -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;