1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 00:42:41 +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:
Tarmo Lehtpuu 2013-08-08 18:54:35 -07:00 committed by epriestley
parent 399c3e4ee6
commit 8c01cc97f4
3 changed files with 61 additions and 1 deletions

View file

@ -5,6 +5,7 @@ final class PhabricatorFlagQuery {
private $ownerPHIDs; private $ownerPHIDs;
private $types; private $types;
private $objectPHIDs; private $objectPHIDs;
private $color;
private $limit; private $limit;
private $offset; private $offset;
@ -39,6 +40,11 @@ final class PhabricatorFlagQuery {
return $this; return $this;
} }
public function withColor($color) {
$this->color = $color;
return $this;
}
public function withOrder($order) { public function withOrder($order) {
$this->order = $order; $this->order = $order;
return $this; return $this;
@ -146,6 +152,13 @@ final class PhabricatorFlagQuery {
$this->objectPHIDs); $this->objectPHIDs);
} }
if (strlen($this->color)) {
$where[] = qsprintf(
$conn_r,
'flag.color = %d',
$this->color);
}
if ($where) { if ($where) {
return 'WHERE ('.implode(') AND (', $where).')'; return 'WHERE ('.implode(') AND (', $where).')';
} else { } else {

View file

@ -13,6 +13,7 @@ final class PhabricatorMacroQuery
private $nameLike; private $nameLike;
private $dateCreatedAfter; private $dateCreatedAfter;
private $dateCreatedBefore; private $dateCreatedBefore;
private $flagColor;
private $status = 'status-any'; private $status = 'status-any';
const STATUS_ANY = '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) { public function withIDs(array $ids) {
$this->ids = $ids; $this->ids = $ids;
return $this; return $this;
@ -67,6 +79,11 @@ final class PhabricatorMacroQuery
return $this; return $this;
} }
public function withFlagColor($flag_color) {
$this->flagColor = $flag_color;
return $this;
}
protected function loadPage() { protected function loadPage() {
$macro_table = new PhabricatorFileImageMacro(); $macro_table = new PhabricatorFileImageMacro();
$conn = $macro_table->establishConnection('r'); $conn = $macro_table->establishConnection('r');
@ -151,6 +168,23 @@ final class PhabricatorMacroQuery
$this->dateCreatedBefore); $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); $where[] = $this->buildPagingClause($conn);
return $this->formatWhereClause($where); return $this->formatWhereClause($where);

View file

@ -14,6 +14,7 @@ final class PhabricatorMacroSearchEngine
$saved->setParameter('nameLike', $request->getStr('nameLike')); $saved->setParameter('nameLike', $request->getStr('nameLike'));
$saved->setParameter('createdStart', $request->getStr('createdStart')); $saved->setParameter('createdStart', $request->getStr('createdStart'));
$saved->setParameter('createdEnd', $request->getStr('createdEnd')); $saved->setParameter('createdEnd', $request->getStr('createdEnd'));
$saved->setParameter('flagColor', $request->getStr('flagColor'));
return $saved; return $saved;
} }
@ -52,6 +53,11 @@ final class PhabricatorMacroSearchEngine
$query->withDateCreatedBefore($end); $query->withDateCreatedBefore($end);
} }
$color = $saved->getParameter('flagColor');
if (strlen($color)) {
$query->withFlagColor($color);
}
return $query; return $query;
} }
@ -68,6 +74,7 @@ final class PhabricatorMacroSearchEngine
$status = $saved_query->getParameter('status'); $status = $saved_query->getParameter('status');
$names = implode(', ', $saved_query->getParameter('names', array())); $names = implode(', ', $saved_query->getParameter('names', array()));
$like = $saved_query->getParameter('nameLike'); $like = $saved_query->getParameter('nameLike');
$color = $saved_query->getParameter('flagColor', "-1");
$form $form
->appendChild( ->appendChild(
@ -91,7 +98,13 @@ final class PhabricatorMacroSearchEngine
id(new AphrontFormTextControl()) id(new AphrontFormTextControl())
->setName('names') ->setName('names')
->setLabel(pht('Exact 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( $this->buildDateRange(
$form, $form,