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

Add a DiffusionRefDatasource for typeahead'ing branches, tags, bookmarks and refs

Summary: Ref T9952. This will let me put a "Branch: [____]" control on the "Land Revision" dialog so users can choose a branch to target.

Test Plan: Used `/typeahead/class/` to vet basic behavior.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T9952

Differential Revision: https://secure.phabricator.com/D14732
This commit is contained in:
epriestley 2015-12-10 13:17:11 -08:00
parent 2a203fbab1
commit 8dcdc7534d
3 changed files with 65 additions and 0 deletions

View file

@ -692,6 +692,7 @@ phutil_register_library_map(array(
'DiffusionRawDiffQuery' => 'applications/diffusion/query/rawdiff/DiffusionRawDiffQuery.php',
'DiffusionRawDiffQueryConduitAPIMethod' => 'applications/diffusion/conduit/DiffusionRawDiffQueryConduitAPIMethod.php',
'DiffusionReadmeView' => 'applications/diffusion/view/DiffusionReadmeView.php',
'DiffusionRefDatasource' => 'applications/diffusion/typeahead/DiffusionRefDatasource.php',
'DiffusionRefNotFoundException' => 'applications/diffusion/exception/DiffusionRefNotFoundException.php',
'DiffusionRefTableController' => 'applications/diffusion/controller/DiffusionRefTableController.php',
'DiffusionRefsQueryConduitAPIMethod' => 'applications/diffusion/conduit/DiffusionRefsQueryConduitAPIMethod.php',
@ -4566,6 +4567,7 @@ phutil_register_library_map(array(
'DiffusionRawDiffQuery' => 'DiffusionQuery',
'DiffusionRawDiffQueryConduitAPIMethod' => 'DiffusionQueryConduitAPIMethod',
'DiffusionReadmeView' => 'DiffusionView',
'DiffusionRefDatasource' => 'PhabricatorTypeaheadDatasource',
'DiffusionRefNotFoundException' => 'Exception',
'DiffusionRefTableController' => 'DiffusionController',
'DiffusionRefsQueryConduitAPIMethod' => 'DiffusionQueryConduitAPIMethod',

View file

@ -0,0 +1,50 @@
<?php
final class DiffusionRefDatasource
extends PhabricatorTypeaheadDatasource {
public function getBrowseTitle() {
return pht('Browse Branches');
}
public function getPlaceholderText() {
// TODO: This is really "branch, tag, bookmark or ref" but we are only
// using it to pick branches for now and sometimes the UI won't let you
// pick some of these types. See also "Browse Branches" above.
return pht('Type a branch name...');
}
public function getDatasourceApplicationClass() {
return 'PhabricatorDiffusionApplication';
}
public function loadResults() {
$viewer = $this->getViewer();
$raw_query = $this->getRawQuery();
$query = id(new PhabricatorRepositoryRefCursorQuery())
->withDatasourceQuery($raw_query);
$types = $this->getParameter('refTypes');
if ($types) {
$query->withRefTypes($types);
}
$repository_phids = $this->getParameter('repositoryPHIDs');
if ($repository_phids) {
$query->withRepositoryPHIDs($repository_phids);
}
$refs = $this->executeQuery($query);
$results = array();
foreach ($refs as $ref) {
$results[] = id(new PhabricatorTypeaheadResult())
->setName($ref->getRefName())
->setPHID($ref->getPHID());
}
return $results;
}
}

View file

@ -8,6 +8,7 @@ final class PhabricatorRepositoryRefCursorQuery
private $repositoryPHIDs;
private $refTypes;
private $refNames;
private $datasourceQuery;
public function withIDs(array $ids) {
$this->ids = $ids;
@ -34,6 +35,11 @@ final class PhabricatorRepositoryRefCursorQuery
return $this;
}
public function withDatasourceQuery($query) {
$this->datasourceQuery = $query;
return $this;
}
public function newResultObject() {
return new PhabricatorRepositoryRefCursor();
}
@ -108,6 +114,13 @@ final class PhabricatorRepositoryRefCursorQuery
$name_hashes);
}
if (strlen($this->datasourceQuery)) {
$where[] = qsprintf(
$conn,
'refNameRaw LIKE %>',
$this->datasourceQuery);
}
return $where;
}