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,6 +14,9 @@ $saved = new PhabricatorSavedQuery(); $saved->setParameter( + 'bookPHIDs', + $this->readPHIDsFromRequest($request, 'bookPHIDs')); + $saved->setParameter( 'repositoryPHIDs', $this->readPHIDsFromRequest($request, 'repositoryPHIDs')); $saved->setParameter('name', $request->getStr('name')); @@ -27,6 +30,11 @@ 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); @@ -75,6 +83,13 @@ $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')) ->setName('repositoryPHIDs') 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 $repositoryPHIDs; private $needProjectPHIDs; @@ -20,11 +22,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 withRepositoryPHIDs(array $repository_phids) { $this->repositoryPHIDs = $repository_phids; return $this; @@ -121,13 +133,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); + } + if ($this->repositoryPHIDs !== null) { $where[] = qsprintf( $conn_r, @@ -144,4 +170,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 @@ +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; + } + +}