1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-19 05:12:41 +01:00

Parameterize search in Pholio

Summary:
Ref T4100. Ref T5595.

  - Add project query + edgelogic support.
  - Support user selector functions.

Test Plan:
  - Used search to find stuff.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T5595, T4100

Differential Revision: https://secure.phabricator.com/D12531
This commit is contained in:
epriestley 2015-04-23 07:47:28 -07:00
parent f64ca87bfe
commit e094af4618
2 changed files with 49 additions and 14 deletions

View file

@ -59,10 +59,14 @@ final class PholioMockQuery
$data = queryfx_all( $data = queryfx_all(
$conn_r, $conn_r,
'SELECT * FROM %T %Q %Q %Q', '%Q FROM %T mock %Q %Q %Q %Q %Q %Q',
$this->buildSelectClause($conn_r),
$table->getTableName(), $table->getTableName(),
$this->buildJoinClause($conn_r),
$this->buildWhereClause($conn_r), $this->buildWhereClause($conn_r),
$this->buildGroupClause($conn_r),
$this->buildOrderClause($conn_r), $this->buildOrderClause($conn_r),
$this->buildHavingClause($conn_r),
$this->buildLimitClause($conn_r)); $this->buildLimitClause($conn_r));
$mocks = $table->loadAllFromArray($data); $mocks = $table->loadAllFromArray($data);
@ -85,33 +89,33 @@ final class PholioMockQuery
protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { protected function buildWhereClause(AphrontDatabaseConnection $conn_r) {
$where = array(); $where = array();
$where[] = $this->buildPagingClause($conn_r); $where[] = $this->buildWhereClauseParts($conn_r);
if ($this->ids) { if ($this->ids !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn_r,
'id IN (%Ld)', 'mock.id IN (%Ld)',
$this->ids); $this->ids);
} }
if ($this->phids) { if ($this->phids !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn_r,
'phid IN (%Ls)', 'mock.phid IN (%Ls)',
$this->phids); $this->phids);
} }
if ($this->authorPHIDs) { if ($this->authorPHIDs !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn_r,
'authorPHID in (%Ls)', 'mock.authorPHID in (%Ls)',
$this->authorPHIDs); $this->authorPHIDs);
} }
if ($this->statuses) { if ($this->statuses !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn_r,
'status IN (%Ls)', 'mock.status IN (%Ls)',
$this->statuses); $this->statuses);
} }
@ -178,4 +182,8 @@ final class PholioMockQuery
return 'PhabricatorPholioApplication'; return 'PhabricatorPholioApplication';
} }
public function getPrimaryTableAlias() {
return 'mock';
}
} }

View file

@ -12,9 +12,15 @@ final class PholioMockSearchEngine extends PhabricatorApplicationSearchEngine {
public function buildSavedQueryFromRequest(AphrontRequest $request) { public function buildSavedQueryFromRequest(AphrontRequest $request) {
$saved = new PhabricatorSavedQuery(); $saved = new PhabricatorSavedQuery();
$saved->setParameter( $saved->setParameter(
'authorPHIDs', 'authorPHIDs',
$this->readUsersFromRequest($request, 'authors')); $this->readUsersFromRequest($request, 'authors'));
$saved->setParameter(
'projects',
$this->readProjectsFromRequest($request, 'projects'));
$saved->setParameter( $saved->setParameter(
'statuses', 'statuses',
$request->getStrList('status')); $request->getStrList('status'));
@ -26,9 +32,23 @@ final class PholioMockSearchEngine extends PhabricatorApplicationSearchEngine {
$query = id(new PholioMockQuery()) $query = id(new PholioMockQuery())
->needCoverFiles(true) ->needCoverFiles(true)
->needImages(true) ->needImages(true)
->needTokenCounts(true) ->needTokenCounts(true);
->withAuthorPHIDs($saved->getParameter('authorPHIDs', array()))
->withStatuses($saved->getParameter('statuses', array())); $datasource = id(new PhabricatorTypeaheadUserParameterizedDatasource())
->setViewer($this->requireViewer());
$author_phids = $saved->getParameter('authorPHIDs', array());
$author_phids = $datasource->evaluateTokens($author_phids);
if ($author_phids) {
$query->withAuthorPHIDs($author_phids);
}
$statuses = $saved->getParameter('statuses', array());
if ($statuses) {
$query->withStatuses($statuses);
}
$this->setQueryProjects($query, $saved);
return $query; return $query;
} }
@ -38,6 +58,7 @@ final class PholioMockSearchEngine extends PhabricatorApplicationSearchEngine {
PhabricatorSavedQuery $saved_query) { PhabricatorSavedQuery $saved_query) {
$author_phids = $saved_query->getParameter('authorPHIDs', array()); $author_phids = $saved_query->getParameter('authorPHIDs', array());
$projects = $saved_query->getParameter('projects', array());
$statuses = array( $statuses = array(
'' => pht('Any Status'), '' => pht('Any Status'),
@ -51,10 +72,16 @@ final class PholioMockSearchEngine extends PhabricatorApplicationSearchEngine {
$form $form
->appendControl( ->appendControl(
id(new AphrontFormTokenizerControl()) id(new AphrontFormTokenizerControl())
->setDatasource(new PhabricatorPeopleDatasource()) ->setDatasource(new PhabricatorTypeaheadUserParameterizedDatasource())
->setName('authors') ->setName('authors')
->setLabel(pht('Authors')) ->setLabel(pht('Authors'))
->setValue($author_phids)) ->setValue($author_phids))
->appendControl(
id(new AphrontFormTokenizerControl())
->setDatasource(new PhabricatorProjectLogicalDatasource())
->setName('projects')
->setLabel(pht('Projects'))
->setValue($projects))
->appendChild( ->appendChild(
id(new AphrontFormSelectControl()) id(new AphrontFormSelectControl())
->setLabel(pht('Status')) ->setLabel(pht('Status'))