Page MenuHomePhabricator

D13303.id32186.diff
No OneTemporary

D13303.id32186.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -649,6 +649,7 @@
'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 @@
'DivinerAtomizeWorkflow' => 'DivinerWorkflow',
'DivinerAtomizer' => 'Phobject',
'DivinerBookController' => 'DivinerController',
+ 'DivinerBookDatasource' => 'PhabricatorTypeaheadDatasource',
'DivinerBookEditController' => 'DivinerController',
'DivinerBookItemView' => 'AphrontTagView',
'DivinerBookPHIDType' => 'PhabricatorPHIDType',
diff --git a/src/applications/diviner/query/DivinerAtomSearchEngine.php b/src/applications/diviner/query/DivinerAtomSearchEngine.php
--- a/src/applications/diviner/query/DivinerAtomSearchEngine.php
+++ b/src/applications/diviner/query/DivinerAtomSearchEngine.php
@@ -14,20 +14,23 @@
$saved = new PhabricatorSavedQuery();
$saved->setParameter(
+ 'bookPHIDs',
+ $this->readPHIDsFromRequest($request, 'bookPHIDs'));
+ $saved->setParameter('name', $request->getStr('name'));
+ $saved->setParameter(
'types',
$this->readListFromRequest($request, 'types'));
- $saved->setParameter('name', $request->getStr('name'));
-
return $saved;
}
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
$query = id(new DivinerAtomQuery());
- $types = $saved->getParameter('types');
- if ($types) {
- $query->withTypes($types);
+ $books = $saved->getParameter('bookPHIDs');
+
+ if ($books) {
+ $query->withBookPHIDs($books);
}
$name = $saved->getParameter('name');
@@ -35,6 +38,11 @@
$query->withNameContains($name);
}
+ $types = $saved->getParameter('types');
+ if ($types) {
+ $query->withTypes($types);
+ }
+
return $query;
}
@@ -42,10 +50,18 @@
AphrontFormView $form,
PhabricatorSavedQuery $saved) {
- $name_control = id(new AphrontFormTextControl())
- ->setLabel(pht('Name Contains'))
- ->setName('name')
- ->setValue($saved->getParameter('name')));
+ $form->appendControl(
+ id(new AphrontFormTokenizerControl())
+ ->setDatasource(new DivinerBookDatasource())
+ ->setName('bookPHIDs')
+ ->setLabel(pht('Books'))
+ ->setValue($saved->getParameter('bookPHIDs')));
+
+ $form->appendChild(
+ id(new AphrontFormTextControl())
+ ->setLabel(pht('Name Contains'))
+ ->setName('name')
+ ->setValue($saved->getParameter('name')));
$all_types = array();
foreach (DivinerAtom::getAllTypes() as $type) {
@@ -65,9 +81,7 @@
isset($types[$type]));
}
- $form
- ->appendChild($name_control)
- ->appendChild($type_control);
+ $form->appendChild($type_control);
}
protected function getURI($path) {
diff --git a/src/applications/diviner/query/DivinerBookQuery.php b/src/applications/diviner/query/DivinerBookQuery.php
--- a/src/applications/diviner/query/DivinerBookQuery.php
+++ b/src/applications/diviner/query/DivinerBookQuery.php
@@ -5,6 +5,8 @@
private $ids;
private $phids;
private $names;
+ private $nameLike;
+ private $namePrefix;
private $needProjectPHIDs;
@@ -18,11 +20,21 @@
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 needProjectPHIDs($need_phids) {
$this->needProjectPHIDs = $need_phids;
return $this;
@@ -82,13 +94,27 @@
$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);
+ }
+
$where[] = $this->buildPagingClause($conn_r);
return $this->formatWhereClause($where);
@@ -98,4 +124,32 @@
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();
+ }
+
}
diff --git a/src/applications/diviner/typeahead/DivinerBookDatasource.php b/src/applications/diviner/typeahead/DivinerBookDatasource.php
new file mode 100644
--- /dev/null
+++ b/src/applications/diviner/typeahead/DivinerBookDatasource.php
@@ -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;
+ }
+
+}

File Metadata

Mime Type
text/plain
Expires
Tue, Mar 11, 2:19 PM (2 w, 20 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7530485
Default Alt Text
D13303.id32186.diff (6 KB)

Event Timeline