mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-26 23:40: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
|
@ -8,6 +8,7 @@ final class PhabricatorMacroQuery
|
||||||
private $authors;
|
private $authors;
|
||||||
private $names;
|
private $names;
|
||||||
private $nameLike;
|
private $nameLike;
|
||||||
|
private $namePrefix;
|
||||||
private $dateCreatedAfter;
|
private $dateCreatedAfter;
|
||||||
private $dateCreatedBefore;
|
private $dateCreatedBefore;
|
||||||
private $flagColor;
|
private $flagColor;
|
||||||
|
@ -65,6 +66,11 @@ final class PhabricatorMacroQuery
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function withNamePrefix($prefix) {
|
||||||
|
$this->namePrefix = $prefix;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function withStatus($status) {
|
public function withStatus($status) {
|
||||||
$this->status = $status;
|
$this->status = $status;
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -143,6 +149,13 @@ final class PhabricatorMacroQuery
|
||||||
$this->names);
|
$this->names);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (strlen($this->namePrefix)) {
|
||||||
|
$where[] = qsprintf(
|
||||||
|
$conn,
|
||||||
|
'm.name LIKE %>',
|
||||||
|
$this->namePrefix);
|
||||||
|
}
|
||||||
|
|
||||||
switch ($this->status) {
|
switch ($this->status) {
|
||||||
case self::STATUS_ACTIVE:
|
case self::STATUS_ACTIVE:
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
|
@ -233,4 +246,33 @@ final class PhabricatorMacroQuery
|
||||||
return 'PhabricatorMacroApplication';
|
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('createdEnd', $request->getStr('createdEnd'));
|
||||||
$saved->setParameter('flagColor', $request->getStr('flagColor', '-1'));
|
$saved->setParameter('flagColor', $request->getStr('flagColor', '-1'));
|
||||||
|
|
||||||
|
$this->saveQueryOrder($saved, $request);
|
||||||
|
|
||||||
return $saved;
|
return $saved;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,6 +36,8 @@ final class PhabricatorMacroSearchEngine
|
||||||
->withPHIDs($saved->getParameter('phids', array()))
|
->withPHIDs($saved->getParameter('phids', array()))
|
||||||
->withAuthorPHIDs($saved->getParameter('authorPHIDs', array()));
|
->withAuthorPHIDs($saved->getParameter('authorPHIDs', array()));
|
||||||
|
|
||||||
|
$this->setQueryOrder($query, $saved);
|
||||||
|
|
||||||
$status = $saved->getParameter('status');
|
$status = $saved->getParameter('status');
|
||||||
$options = PhabricatorMacroQuery::getStatusOptions();
|
$options = PhabricatorMacroQuery::getStatusOptions();
|
||||||
if (empty($options[$status])) {
|
if (empty($options[$status])) {
|
||||||
|
@ -72,13 +76,13 @@ final class PhabricatorMacroSearchEngine
|
||||||
|
|
||||||
public function buildSearchForm(
|
public function buildSearchForm(
|
||||||
AphrontFormView $form,
|
AphrontFormView $form,
|
||||||
PhabricatorSavedQuery $saved_query) {
|
PhabricatorSavedQuery $saved) {
|
||||||
|
|
||||||
$author_phids = $saved_query->getParameter('authorPHIDs', array());
|
$author_phids = $saved->getParameter('authorPHIDs', array());
|
||||||
$status = $saved_query->getParameter('status');
|
$status = $saved->getParameter('status');
|
||||||
$names = implode(', ', $saved_query->getParameter('names', array()));
|
$names = implode(', ', $saved->getParameter('names', array()));
|
||||||
$like = $saved_query->getParameter('nameLike');
|
$like = $saved->getParameter('nameLike');
|
||||||
$color = $saved_query->getParameter('flagColor', '-1');
|
$color = $saved->getParameter('flagColor', '-1');
|
||||||
|
|
||||||
$form
|
$form
|
||||||
->appendChild(
|
->appendChild(
|
||||||
|
@ -112,11 +116,16 @@ final class PhabricatorMacroSearchEngine
|
||||||
|
|
||||||
$this->buildDateRange(
|
$this->buildDateRange(
|
||||||
$form,
|
$form,
|
||||||
$saved_query,
|
$saved,
|
||||||
'createdStart',
|
'createdStart',
|
||||||
pht('Created After'),
|
pht('Created After'),
|
||||||
'createdEnd',
|
'createdEnd',
|
||||||
pht('Created Before'));
|
pht('Created Before'));
|
||||||
|
|
||||||
|
$this->appendOrderFieldsToForm(
|
||||||
|
$form,
|
||||||
|
$saved,
|
||||||
|
new PhabricatorMacroQuery());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getURI($path) {
|
protected function getURI($path) {
|
||||||
|
|
|
@ -2,11 +2,6 @@
|
||||||
|
|
||||||
final class PhabricatorMacroDatasource extends PhabricatorTypeaheadDatasource {
|
final class PhabricatorMacroDatasource extends PhabricatorTypeaheadDatasource {
|
||||||
|
|
||||||
public function isBrowsable() {
|
|
||||||
// TODO: This should be made browsable.
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getPlaceholderText() {
|
public function getPlaceholderText() {
|
||||||
return pht('Type a macro name...');
|
return pht('Type a macro name...');
|
||||||
}
|
}
|
||||||
|
@ -16,19 +11,23 @@ final class PhabricatorMacroDatasource extends PhabricatorTypeaheadDatasource {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function loadResults() {
|
public function loadResults() {
|
||||||
$viewer = $this->getViewer();
|
|
||||||
$raw_query = $this->getRawQuery();
|
$raw_query = $this->getRawQuery();
|
||||||
|
|
||||||
|
$query = id(new PhabricatorMacroQuery())
|
||||||
|
->setOrder('name')
|
||||||
|
->withNamePrefix($raw_query);
|
||||||
|
$macros = $this->executeQuery($query);
|
||||||
|
|
||||||
$results = array();
|
$results = array();
|
||||||
|
|
||||||
$macros = id(new PhabricatorMacroQuery())
|
|
||||||
->setViewer($viewer)
|
|
||||||
->withStatus(PhabricatorMacroQuery::STATUS_ACTIVE)
|
|
||||||
->execute();
|
|
||||||
|
|
||||||
foreach ($macros as $macro) {
|
foreach ($macros as $macro) {
|
||||||
|
$closed = null;
|
||||||
|
if ($macro->getIsDisabled()) {
|
||||||
|
$closed = pht('Disabled');
|
||||||
|
}
|
||||||
|
|
||||||
$results[] = id(new PhabricatorTypeaheadResult())
|
$results[] = id(new PhabricatorTypeaheadResult())
|
||||||
->setPHID($macro->getPHID())
|
->setPHID($macro->getPHID())
|
||||||
|
->setClosed($closed)
|
||||||
->setName($macro->getName());
|
->setName($macro->getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -602,9 +602,8 @@ abstract class PhabricatorApplicationSearchEngine {
|
||||||
PhabricatorSavedQuery $saved) {
|
PhabricatorSavedQuery $saved) {
|
||||||
|
|
||||||
$order = $saved->getParameter('order');
|
$order = $saved->getParameter('order');
|
||||||
if (strlen($order)) {
|
|
||||||
$builtin = $query->getBuiltinOrders();
|
$builtin = $query->getBuiltinOrders();
|
||||||
if (isset($builtin[$order])) {
|
if (strlen($order) && isset($builtin[$order])) {
|
||||||
$query->setOrder($order);
|
$query->setOrder($order);
|
||||||
} else {
|
} else {
|
||||||
// If the order is invalid or not available, we choose the first
|
// If the order is invalid or not available, we choose the first
|
||||||
|
@ -614,7 +613,6 @@ abstract class PhabricatorApplicationSearchEngine {
|
||||||
// orders differ, this order is the preferred order for humans.
|
// orders differ, this order is the preferred order for humans.
|
||||||
$query->setOrder(head_key($builtin));
|
$query->setOrder(head_key($builtin));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue