1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-30 01:10:58 +01:00

Allow atoms to be queried by book

Summary: Ref T4558. Allows querying for atoms from specified books. Depends on D13091.

Test Plan: Poked around at `/diviner/query/`.

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: epriestley, Korvin

Maniphest Tasks: T4558

Differential Revision: https://secure.phabricator.com/D13303
This commit is contained in:
Joshua Spence 2015-06-19 18:06:53 +10:00
parent 44dee47c28
commit 9921cbc41a
4 changed files with 109 additions and 1 deletions

View file

@ -649,6 +649,7 @@ phutil_register_library_map(array(
'DivinerAtomizeWorkflow' => 'applications/diviner/workflow/DivinerAtomizeWorkflow.php',
'DivinerAtomizer' => 'applications/diviner/atomizer/DivinerAtomizer.php',
'DivinerBookController' => 'applications/diviner/controller/DivinerBookController.php',
'DivinerBookDatasource' => 'applications/diviner/typeahead/DivinerBookDatasource.php',
'DivinerBookEditController' => 'applications/diviner/controller/DivinerBookEditController.php',
'DivinerBookItemView' => 'applications/diviner/view/DivinerBookItemView.php',
'DivinerBookPHIDType' => 'applications/diviner/phid/DivinerBookPHIDType.php',
@ -4016,6 +4017,7 @@ phutil_register_library_map(array(
'DivinerAtomizeWorkflow' => 'DivinerWorkflow',
'DivinerAtomizer' => 'Phobject',
'DivinerBookController' => 'DivinerController',
'DivinerBookDatasource' => 'PhabricatorTypeaheadDatasource',
'DivinerBookEditController' => 'DivinerController',
'DivinerBookItemView' => 'AphrontTagView',
'DivinerBookPHIDType' => 'PhabricatorPHIDType',

View file

@ -13,6 +13,9 @@ final class DivinerAtomSearchEngine extends PhabricatorApplicationSearchEngine {
public function buildSavedQueryFromRequest(AphrontRequest $request) {
$saved = new PhabricatorSavedQuery();
$saved->setParameter(
'bookPHIDs',
$this->readPHIDsFromRequest($request, 'bookPHIDs'));
$saved->setParameter(
'repositoryPHIDs',
$this->readPHIDsFromRequest($request, 'repositoryPHIDs'));
@ -27,6 +30,11 @@ final class DivinerAtomSearchEngine extends PhabricatorApplicationSearchEngine {
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
$query = id(new DivinerAtomQuery());
$books = $saved->getParameter('bookPHIDs');
if ($books) {
$query->withBookPHIDs($books);
}
$repository_phids = $saved->getParameter('repositoryPHIDs');
if ($repository_phids) {
$query->withRepositoryPHIDs($repository_phids);
@ -74,6 +82,13 @@ final class DivinerAtomSearchEngine extends PhabricatorApplicationSearchEngine {
}
$form->appendChild($type_control);
$form->appendControl(
id(new AphrontFormTokenizerControl())
->setDatasource(new DivinerBookDatasource())
->setName('bookPHIDs')
->setLabel(pht('Books'))
->setValue($saved->getParameter('bookPHIDs')));
$form->appendControl(
id(new AphrontFormTokenizerControl())
->setLabel(pht('Repositories'))

View file

@ -5,6 +5,8 @@ final class DivinerBookQuery extends PhabricatorCursorPagedPolicyAwareQuery {
private $ids;
private $phids;
private $names;
private $nameLike;
private $namePrefix;
private $repositoryPHIDs;
private $needProjectPHIDs;
@ -20,11 +22,21 @@ final class DivinerBookQuery extends PhabricatorCursorPagedPolicyAwareQuery {
return $this;
}
public function withNameLike($name) {
$this->nameLike = $name;
return $this;
}
public function withNames(array $names) {
$this->names = $names;
return $this;
}
public function withNamePrefix($prefix) {
$this->namePrefix = $prefix;
return $this;
}
public function withRepositoryPHIDs(array $repository_phids) {
$this->repositoryPHIDs = $repository_phids;
return $this;
@ -121,13 +133,27 @@ final class DivinerBookQuery extends PhabricatorCursorPagedPolicyAwareQuery {
$this->phids);
}
if ($this->names) {
if (strlen($this->nameLike)) {
$where[] = qsprintf(
$conn_r,
'name LIKE %~',
$this->nameLike);
}
if ($this->names !== null) {
$where[] = qsprintf(
$conn_r,
'name IN (%Ls)',
$this->names);
}
if (strlen($this->namePrefix)) {
$where[] = qsprintf(
$conn_r,
'name LIKE %>',
$this->namePrefix);
}
if ($this->repositoryPHIDs !== null) {
$where[] = qsprintf(
$conn_r,
@ -144,4 +170,32 @@ final class DivinerBookQuery extends PhabricatorCursorPagedPolicyAwareQuery {
return 'PhabricatorDivinerApplication';
}
public function getOrderableColumns() {
return parent::getOrderableColumns() + array(
'name' => array(
'column' => 'name',
'type' => 'string',
'reverse' => true,
'unique' => true,
),
);
}
protected function getPagingValueMap($cursor, array $keys) {
$book = $this->loadCursorObject($cursor);
return array(
'name' => $book->getName(),
);
}
public function getBuiltinOrders() {
return array(
'name' => array(
'vector' => array('name'),
'name' => pht('Name'),
),
) + parent::getBuiltinOrders();
}
}

View file

@ -0,0 +1,37 @@
<?php
final class DivinerBookDatasource extends PhabricatorTypeaheadDatasource {
public function getBrowseTitle() {
return pht('Browse Books');
}
public function getPlaceholderText() {
return pht('Type a book name...');
}
public function getDatasourceApplicationClass() {
return 'PhabricatorDivinerApplication';
}
public function loadResults() {
$raw_query = $this->getRawQuery();
$query = id(new DivinerBookQuery())
->setOrder('name')
->withNamePrefix($raw_query);
$books = $this->executeQuery($query);
$results = array();
foreach ($books as $book) {
$results[] = id(new PhabricatorTypeaheadResult())
->setName($book->getTitle())
->setURI('/book/'.$book->getName().'/')
->setPHID($book->getPHID())
->setPriorityString($book->getName());
}
return $results;
}
}