mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-27 01:02:42 +01:00
Implement macros search by flags.
Summary: Reuse the existing flags functionality for searching macros. Currently implemented as a simple select element (for color). Test Plan: Flagged some macros and tried searching by them. Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D6709
This commit is contained in:
parent
399c3e4ee6
commit
8c01cc97f4
3 changed files with 61 additions and 1 deletions
|
@ -5,6 +5,7 @@ final class PhabricatorFlagQuery {
|
|||
private $ownerPHIDs;
|
||||
private $types;
|
||||
private $objectPHIDs;
|
||||
private $color;
|
||||
|
||||
private $limit;
|
||||
private $offset;
|
||||
|
@ -39,6 +40,11 @@ final class PhabricatorFlagQuery {
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function withColor($color) {
|
||||
$this->color = $color;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withOrder($order) {
|
||||
$this->order = $order;
|
||||
return $this;
|
||||
|
@ -146,6 +152,13 @@ final class PhabricatorFlagQuery {
|
|||
$this->objectPHIDs);
|
||||
}
|
||||
|
||||
if (strlen($this->color)) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'flag.color = %d',
|
||||
$this->color);
|
||||
}
|
||||
|
||||
if ($where) {
|
||||
return 'WHERE ('.implode(') AND (', $where).')';
|
||||
} else {
|
||||
|
|
|
@ -13,6 +13,7 @@ final class PhabricatorMacroQuery
|
|||
private $nameLike;
|
||||
private $dateCreatedAfter;
|
||||
private $dateCreatedBefore;
|
||||
private $flagColor;
|
||||
|
||||
private $status = 'status-any';
|
||||
const STATUS_ANY = 'status-any';
|
||||
|
@ -27,6 +28,17 @@ final class PhabricatorMacroQuery
|
|||
);
|
||||
}
|
||||
|
||||
public static function getFlagColorsOptions() {
|
||||
|
||||
$options = array('-1' => pht('(No Filtering)'));
|
||||
|
||||
foreach (PhabricatorFlagColor::getColorNameMap() as $color => $name) {
|
||||
$options[$color] = $name;
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
public function withIDs(array $ids) {
|
||||
$this->ids = $ids;
|
||||
return $this;
|
||||
|
@ -67,6 +79,11 @@ final class PhabricatorMacroQuery
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function withFlagColor($flag_color) {
|
||||
$this->flagColor = $flag_color;
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function loadPage() {
|
||||
$macro_table = new PhabricatorFileImageMacro();
|
||||
$conn = $macro_table->establishConnection('r');
|
||||
|
@ -151,6 +168,23 @@ final class PhabricatorMacroQuery
|
|||
$this->dateCreatedBefore);
|
||||
}
|
||||
|
||||
if ($this->flagColor != '-1' && $this->flagColor !== null) {
|
||||
$flags = id(new PhabricatorFlagQuery())
|
||||
->withTypes(array(PhabricatorMacroPHIDTypeMacro::TYPECONST))
|
||||
->withColor($this->flagColor)
|
||||
->setViewer($this->getViewer())
|
||||
->execute();
|
||||
|
||||
if (empty($flags)) {
|
||||
throw new PhabricatorEmptyQueryException('No matching flags.');
|
||||
} else {
|
||||
$where[] = qsprintf(
|
||||
$conn,
|
||||
'm.phid IN (%Ls)',
|
||||
mpull($flags, 'getObjectPHID'));
|
||||
}
|
||||
}
|
||||
|
||||
$where[] = $this->buildPagingClause($conn);
|
||||
|
||||
return $this->formatWhereClause($where);
|
||||
|
|
|
@ -14,6 +14,7 @@ final class PhabricatorMacroSearchEngine
|
|||
$saved->setParameter('nameLike', $request->getStr('nameLike'));
|
||||
$saved->setParameter('createdStart', $request->getStr('createdStart'));
|
||||
$saved->setParameter('createdEnd', $request->getStr('createdEnd'));
|
||||
$saved->setParameter('flagColor', $request->getStr('flagColor'));
|
||||
|
||||
return $saved;
|
||||
}
|
||||
|
@ -52,6 +53,11 @@ final class PhabricatorMacroSearchEngine
|
|||
$query->withDateCreatedBefore($end);
|
||||
}
|
||||
|
||||
$color = $saved->getParameter('flagColor');
|
||||
if (strlen($color)) {
|
||||
$query->withFlagColor($color);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
@ -68,6 +74,7 @@ final class PhabricatorMacroSearchEngine
|
|||
$status = $saved_query->getParameter('status');
|
||||
$names = implode(', ', $saved_query->getParameter('names', array()));
|
||||
$like = $saved_query->getParameter('nameLike');
|
||||
$color = $saved_query->getParameter('flagColor', "-1");
|
||||
|
||||
$form
|
||||
->appendChild(
|
||||
|
@ -91,7 +98,13 @@ final class PhabricatorMacroSearchEngine
|
|||
id(new AphrontFormTextControl())
|
||||
->setName('names')
|
||||
->setLabel(pht('Exact Names'))
|
||||
->setValue($names));
|
||||
->setValue($names))
|
||||
->appendChild(
|
||||
id(new AphrontFormSelectControl())
|
||||
->setName('flagColor')
|
||||
->setLabel(pht('Marked with Flag'))
|
||||
->setOptions(PhabricatorMacroQuery::getFlagColorsOptions())
|
||||
->setValue($color));
|
||||
|
||||
$this->buildDateRange(
|
||||
$form,
|
||||
|
|
Loading…
Reference in a new issue