Page MenuHomePhabricator

D13194.diff
No OneTemporary

D13194.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
@@ -5,7 +5,7 @@
private $ids;
private $phids;
- private $authors;
+ private $authorPHIDs;
private $names;
private $nameLike;
private $namePrefix;
@@ -51,8 +51,8 @@
return $this;
}
- public function withAuthorPHIDs(array $authors) {
- $this->authors = $authors;
+ public function withAuthorPHIDs(array $author_phids) {
+ $this->authorPHIDs = $author_phids;
return $this;
}
@@ -96,53 +96,46 @@
return $this;
}
+ public function newResultObject() {
+ return new PhabricatorFileImageMacro();
+ }
+
protected function loadPage() {
- $macro_table = new PhabricatorFileImageMacro();
- $conn = $macro_table->establishConnection('r');
-
- $rows = queryfx_all(
- $conn,
- 'SELECT m.* FROM %T m %Q %Q %Q',
- $macro_table->getTableName(),
- $this->buildWhereClause($conn),
- $this->buildOrderClause($conn),
- $this->buildLimitClause($conn));
-
- return $macro_table->loadAllFromArray($rows);
+ return $this->loadStandardPage(new PhabricatorFileImageMacro());
}
- protected function buildWhereClause(AphrontDatabaseConnection $conn) {
- $where = array();
+ protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
+ $where = parent::buildWhereClauseParts($conn);
- if ($this->ids) {
+ if ($this->ids !== null) {
$where[] = qsprintf(
$conn,
'm.id IN (%Ld)',
$this->ids);
}
- if ($this->phids) {
+ if ($this->phids !== null) {
$where[] = qsprintf(
$conn,
'm.phid IN (%Ls)',
$this->phids);
}
- if ($this->authors) {
+ if ($this->authorPHIDs !== null) {
$where[] = qsprintf(
$conn,
'm.authorPHID IN (%Ls)',
- $this->authors);
+ $this->authorPHIDs);
}
- if ($this->nameLike) {
+ if (strlen($this->nameLike)) {
$where[] = qsprintf(
$conn,
'm.name LIKE %~',
$this->nameLike);
}
- if ($this->names) {
+ if ($this->names !== null) {
$where[] = qsprintf(
$conn,
'm.name IN (%Ls)',
@@ -210,9 +203,7 @@
}
}
- $where[] = $this->buildPagingClause($conn);
-
- return $this->formatWhereClause($where);
+ return $where;
}
protected function didFilterPage(array $macros) {
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
@@ -11,123 +11,83 @@
return 'PhabricatorMacroApplication';
}
- public function buildSavedQueryFromRequest(AphrontRequest $request) {
- $saved = new PhabricatorSavedQuery();
- $saved->setParameter(
- 'authorPHIDs',
- $this->readUsersFromRequest($request, 'authors'));
-
- $saved->setParameter('status', $request->getStr('status'));
- $saved->setParameter('names', $request->getStrList('names'));
- $saved->setParameter('nameLike', $request->getStr('nameLike'));
- $saved->setParameter('createdStart', $request->getStr('createdStart'));
- $saved->setParameter('createdEnd', $request->getStr('createdEnd'));
- $saved->setParameter('flagColor', $request->getStr('flagColor', '-1'));
-
- $this->saveQueryOrder($saved, $request);
-
- return $saved;
+ public function newQuery() {
+ return id(new PhabricatorMacroQuery())
+ ->needFiles(true);
}
- public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
- $query = id(new PhabricatorMacroQuery())
- ->needFiles(true)
- ->withIDs($saved->getParameter('ids', array()))
- ->withPHIDs($saved->getParameter('phids', array()))
- ->withAuthorPHIDs($saved->getParameter('authorPHIDs', array()));
+ protected function buildCustomSearchFields() {
+ return array(
+ id(new PhabricatorSearchSelectField())
+ ->setLabel(pht('Status'))
+ ->setKey('status')
+ ->setOptions(PhabricatorMacroQuery::getStatusOptions()),
+ id(new PhabricatorSearchUsersField())
+ ->setLabel(pht('Authors'))
+ ->setKey('authorPHIDs')
+ ->setAliases(array('author', 'authors')),
+ id(new PhabricatorSearchTextField())
+ ->setLabel(pht('Name Contains'))
+ ->setKey('nameLike'),
+ id(new PhabricatorSearchStringListField())
+ ->setLabel(pht('Exact Names'))
+ ->setKey('names'),
+ id(new PhabricatorSearchSelectField())
+ ->setLabel(pht('Marked with Flag'))
+ ->setKey('flagColor')
+ ->setDefault('-1')
+ ->setOptions(PhabricatorMacroQuery::getFlagColorsOptions()),
+ id(new PhabricatorSearchDateField())
+ ->setLabel(pht('Created After'))
+ ->setKey('createdStart'),
+ id(new PhabricatorSearchDateField())
+ ->setLabel(pht('Created Before'))
+ ->setKey('createdEnd'),
+ );
+ }
+
+ protected function getDefaultFieldOrder() {
+ return array(
+ '...',
+ 'createdStart',
+ 'createdEnd',
+ );
+ }
- $this->setQueryOrder($query, $saved);
+ public function buildQueryFromParameters(array $map) {
+ $query = $this->newQuery();
- $status = $saved->getParameter('status');
- $options = PhabricatorMacroQuery::getStatusOptions();
- if (empty($options[$status])) {
- $status = head_key($options);
+ if ($map['authorPHIDs']) {
+ $query->withAuthorPHIDs($map['authorPHIDs']);
}
- $query->withStatus($status);
- $names = $saved->getParameter('names', array());
- if ($names) {
- $query->withNames($names);
+ if ($map['status']) {
+ $query->withStatus($map['status']);
}
- $like = $saved->getParameter('nameLike');
- if (strlen($like)) {
- $query->withNameLike($like);
+ if ($map['names']) {
+ $query->withNames($map['names']);
}
- $start = $this->parseDateTime($saved->getParameter('createdStart'));
- $end = $this->parseDateTime($saved->getParameter('createdEnd'));
+ if (strlen($map['nameLike'])) {
+ $query->withNameLike($map['nameLike']);
+ }
- if ($start) {
- $query->withDateCreatedAfter($start);
+ if ($map['createdStart']) {
+ $query->withDateCreatedAfter($map['createdStart']);
}
- if ($end) {
- $query->withDateCreatedBefore($end);
+ if ($map['createdEnd']) {
+ $query->withDateCreatedBefore($map['createdEnd']);
}
- $color = $saved->getParameter('flagColor');
- if (strlen($color)) {
- $query->withFlagColor($color);
+ if ($map['flagColor'] !== null) {
+ $query->withFlagColor($map['flagColor']);
}
return $query;
}
- public function buildSearchForm(
- AphrontFormView $form,
- PhabricatorSavedQuery $saved) {
-
- $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(
- id(new AphrontFormSelectControl())
- ->setName('status')
- ->setLabel(pht('Status'))
- ->setOptions(PhabricatorMacroQuery::getStatusOptions())
- ->setValue($status))
- ->appendControl(
- id(new AphrontFormTokenizerControl())
- ->setDatasource(new PhabricatorPeopleDatasource())
- ->setName('authors')
- ->setLabel(pht('Authors'))
- ->setValue($author_phids))
- ->appendChild(
- id(new AphrontFormTextControl())
- ->setName('nameLike')
- ->setLabel(pht('Name Contains'))
- ->setValue($like))
- ->appendChild(
- id(new AphrontFormTextControl())
- ->setName('names')
- ->setLabel(pht('Exact Names'))
- ->setValue($names))
- ->appendChild(
- id(new AphrontFormSelectControl())
- ->setName('flagColor')
- ->setLabel(pht('Marked with Flag'))
- ->setOptions(PhabricatorMacroQuery::getFlagColorsOptions())
- ->setValue($color));
-
- $this->buildDateRange(
- $form,
- $saved,
- 'createdStart',
- pht('Created After'),
- 'createdEnd',
- pht('Created Before'));
-
- $this->appendOrderFieldsToForm(
- $form,
- $saved,
- new PhabricatorMacroQuery());
- }
-
protected function getURI($path) {
return '/macro/'.$path;
}
@@ -165,12 +125,6 @@
return parent::buildSavedQueryFromBuiltin($query_key);
}
- protected function getRequiredHandlePHIDsForResultList(
- array $macros,
- PhabricatorSavedQuery $query) {
- return mpull($macros, 'getAuthorPHID');
- }
-
protected function renderResultList(
array $macros,
PhabricatorSavedQuery $query,
@@ -178,6 +132,7 @@
assert_instances_of($macros, 'PhabricatorFileImageMacro');
$viewer = $this->requireViewer();
+ $handles = $viewer->loadHandles(mpull($macros, 'getAuthorPHID'));
$xform = PhabricatorFileTransform::getTransformByKey(
PhabricatorFileThumbnailTransform::TRANSFORM_PINBOARD);
diff --git a/src/applications/search/field/PhabricatorSearchSelectField.php b/src/applications/search/field/PhabricatorSearchSelectField.php
--- a/src/applications/search/field/PhabricatorSearchSelectField.php
+++ b/src/applications/search/field/PhabricatorSearchSelectField.php
@@ -4,6 +4,7 @@
extends PhabricatorSearchField {
private $options;
+ private $default;
public function setOptions(array $options) {
$this->options = $options;
@@ -15,7 +16,12 @@
}
protected function getDefaultValue() {
- return null;
+ return $this->default;
+ }
+
+ public function setDefault($default) {
+ $this->default = $default;
+ return $this;
}
protected function getValueFromRequest(AphrontRequest $request, $key) {

File Metadata

Mime Type
text/plain
Expires
Mon, May 20, 3:25 AM (2 w, 1 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6289294
Default Alt Text
D13194.diff (9 KB)

Event Timeline