mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +01:00
Modernize "repositories" typeahead datasource
Summary: Ref T4420. - Allow tokenizers to accept either a `Datasource` object (new style) or a URI (old style). - Read URI and placeholder text from object, if available. - Swap the "repositories" datasource (which seemed like the simplest one) over to the new stuff. - Tweak/update the repo tokens a little bit. Test Plan: - Used tokenizer in Herald, Differential (search), Differential (edit), Push Logs. - Grepped for other callsites. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T4420 Differential Revision: https://secure.phabricator.com/D9874
This commit is contained in:
parent
e281c5ee90
commit
34628002fd
10 changed files with 66 additions and 28 deletions
|
@ -5,7 +5,6 @@
|
|||
* @generated
|
||||
* @phutil-library-version 2
|
||||
*/
|
||||
|
||||
phutil_register_library_map(array(
|
||||
'__library_version__' => 2,
|
||||
'class' =>
|
||||
|
@ -544,6 +543,7 @@ phutil_register_library_map(array(
|
|||
'DiffusionRenameHistoryQuery' => 'applications/diffusion/query/DiffusionRenameHistoryQuery.php',
|
||||
'DiffusionRepositoryController' => 'applications/diffusion/controller/DiffusionRepositoryController.php',
|
||||
'DiffusionRepositoryCreateController' => 'applications/diffusion/controller/DiffusionRepositoryCreateController.php',
|
||||
'DiffusionRepositoryDatasource' => 'applications/diffusion/typeahead/DiffusionRepositoryDatasource.php',
|
||||
'DiffusionRepositoryDefaultController' => 'applications/diffusion/controller/DiffusionRepositoryDefaultController.php',
|
||||
'DiffusionRepositoryEditActionsController' => 'applications/diffusion/controller/DiffusionRepositoryEditActionsController.php',
|
||||
'DiffusionRepositoryEditActivateController' => 'applications/diffusion/controller/DiffusionRepositoryEditActivateController.php',
|
||||
|
@ -3245,6 +3245,7 @@ phutil_register_library_map(array(
|
|||
'DiffusionRefNotFoundException' => 'Exception',
|
||||
'DiffusionRepositoryController' => 'DiffusionController',
|
||||
'DiffusionRepositoryCreateController' => 'DiffusionRepositoryEditController',
|
||||
'DiffusionRepositoryDatasource' => 'PhabricatorTypeaheadDatasource',
|
||||
'DiffusionRepositoryDefaultController' => 'DiffusionController',
|
||||
'DiffusionRepositoryEditActionsController' => 'DiffusionRepositoryEditController',
|
||||
'DiffusionRepositoryEditActivateController' => 'DiffusionRepositoryEditController',
|
||||
|
|
|
@ -49,7 +49,7 @@ final class DifferentialRepositoryField
|
|||
|
||||
return id(new AphrontFormTokenizerControl())
|
||||
->setName($this->getFieldKey())
|
||||
->setDatasource('/typeahead/common/repositories/')
|
||||
->setDatasource(new DiffusionRepositoryDatasource())
|
||||
->setValue($control_value)
|
||||
->setError($this->getFieldError())
|
||||
->setLabel($this->getFieldName())
|
||||
|
|
|
@ -167,7 +167,7 @@ final class DifferentialRevisionSearchEngine
|
|||
id(new AphrontFormTokenizerControl())
|
||||
->setLabel(pht('Repositories'))
|
||||
->setName('repositories')
|
||||
->setDatasource('/typeahead/common/repositories/')
|
||||
->setDatasource(new DiffusionRepositoryDatasource())
|
||||
->setValue(array_select_keys($handles, $repository_phids)))
|
||||
->appendChild(
|
||||
id(new AphrontFormSelectControl())
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
final class DiffusionRepositoryDatasource
|
||||
extends PhabricatorTypeaheadDatasource {
|
||||
|
||||
public function getPlaceholderText() {
|
||||
return pht('Type a repository name...');
|
||||
}
|
||||
|
||||
public function getDatasourceApplicationClass() {
|
||||
return 'PhabricatorApplicationDiffusion';
|
||||
}
|
||||
|
||||
public function loadResults() {
|
||||
$viewer = $this->getViewer();
|
||||
$raw_query = $this->getRawQuery();
|
||||
|
||||
$results = array();
|
||||
|
||||
$repos = id(new PhabricatorRepositoryQuery())
|
||||
->setViewer($viewer)
|
||||
->execute();
|
||||
foreach ($repos as $repo) {
|
||||
$results[] = id(new PhabricatorTypeaheadResult())
|
||||
->setName($repo->getMonogram().' '.$repo->getName())
|
||||
->setURI('/diffusion/'.$repo->getCallsign().'/')
|
||||
->setPHID($repo->getPHID())
|
||||
->setPriorityString($repo->getMonogram())
|
||||
->setIcon('fa-database bluegrey');
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
}
|
|
@ -592,7 +592,8 @@ final class HeraldRuleController extends HeraldController {
|
|||
'source' => array(
|
||||
'email' => '/typeahead/common/mailable/',
|
||||
'user' => '/typeahead/common/accounts/',
|
||||
'repository' => '/typeahead/common/repositories/',
|
||||
'repository' =>
|
||||
id(new DiffusionRepositoryDatasource())->getDatasourceURI(),
|
||||
'package' => '/typeahead/common/packages/',
|
||||
'project' => '/typeahead/common/projects/',
|
||||
'userorproject' => '/typeahead/common/accountsorprojects/',
|
||||
|
|
|
@ -33,12 +33,14 @@ final class PhabricatorRepositoryPHIDTypeRepository
|
|||
foreach ($handles as $phid => $handle) {
|
||||
$repository = $objects[$phid];
|
||||
|
||||
$monogram = $repository->getMonogram();
|
||||
$callsign = $repository->getCallsign();
|
||||
$name = $repository->getName();
|
||||
|
||||
$handle->setName("r{$callsign}");
|
||||
$handle->setFullName("r{$callsign} ({$name})");
|
||||
$handle->setName($monogram);
|
||||
$handle->setFullName("{$monogram} {$name}");
|
||||
$handle->setURI("/diffusion/{$callsign}/");
|
||||
$handle->setIcon('fa-database');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ final class PhabricatorRepositoryPushLogSearchEngine
|
|||
$form
|
||||
->appendChild(
|
||||
id(new AphrontFormTokenizerControl())
|
||||
->setDatasource('/typeahead/common/repositories/')
|
||||
->setDatasource(new DiffusionRepositoryDatasource())
|
||||
->setName('repositories')
|
||||
->setLabel(pht('Repositories'))
|
||||
->setValue($repository_handles))
|
||||
|
|
|
@ -26,7 +26,6 @@ final class PhabricatorTypeaheadCommonDatasourceController
|
|||
$need_applications = false;
|
||||
$need_lists = false;
|
||||
$need_projs = false;
|
||||
$need_repos = false;
|
||||
$need_packages = false;
|
||||
$need_upforgrabs = false;
|
||||
$need_arcanist_projects = false;
|
||||
|
@ -78,9 +77,6 @@ final class PhabricatorTypeaheadCommonDatasourceController
|
|||
$need_projs = true;
|
||||
$need_packages = true;
|
||||
break;
|
||||
case 'repositories':
|
||||
$need_repos = true;
|
||||
break;
|
||||
case 'packages':
|
||||
$need_packages = true;
|
||||
break;
|
||||
|
@ -298,19 +294,6 @@ final class PhabricatorTypeaheadCommonDatasourceController
|
|||
}
|
||||
}
|
||||
|
||||
if ($need_repos) {
|
||||
$repos = id(new PhabricatorRepositoryQuery())
|
||||
->setViewer($viewer)
|
||||
->execute();
|
||||
foreach ($repos as $repo) {
|
||||
$results[] = id(new PhabricatorTypeaheadResult())
|
||||
->setName('r'.$repo->getCallsign().' ('.$repo->getName().')')
|
||||
->setURI('/diffusion/'.$repo->getCallsign().'/')
|
||||
->setPHID($repo->getPHID())
|
||||
->setPriorityString('r'.$repo->getCallsign());
|
||||
}
|
||||
}
|
||||
|
||||
if ($need_packages) {
|
||||
$packages = id(new PhabricatorOwnersPackage())->loadAll();
|
||||
foreach ($packages as $package) {
|
||||
|
|
|
@ -43,6 +43,10 @@ abstract class PhabricatorTypeaheadDatasource extends Phobject {
|
|||
return $this->query;
|
||||
}
|
||||
|
||||
public function getDatasourceURI() {
|
||||
return '/typeahead/class/'.get_class($this).'/';
|
||||
}
|
||||
|
||||
abstract public function getPlaceholderText();
|
||||
abstract public function getDatasourceApplicationClass();
|
||||
abstract public function loadResults();
|
||||
|
|
|
@ -43,8 +43,10 @@ final class AphrontFormTokenizerControl extends AphrontFormControl {
|
|||
$id = celerity_generate_unique_node_id();
|
||||
}
|
||||
|
||||
if (!$this->placeholder) {
|
||||
$this->placeholder = $this->getDefaultPlaceholder();
|
||||
if (!strlen($this->placeholder)) {
|
||||
$placeholder = $this->getDefaultPlaceholder();
|
||||
} else {
|
||||
$placeholder = $this->placeholder;
|
||||
}
|
||||
|
||||
$template = new AphrontTokenizerTemplateView();
|
||||
|
@ -57,15 +59,21 @@ final class AphrontFormTokenizerControl extends AphrontFormControl {
|
|||
$username = $this->user->getUsername();
|
||||
}
|
||||
|
||||
if ($this->datasource instanceof PhabricatorTypeaheadDatasource) {
|
||||
$datasource_uri = $this->datasource->getDatasourceURI();
|
||||
} else {
|
||||
$datasource_uri = $this->datasource;
|
||||
}
|
||||
|
||||
if (!$this->disableBehavior) {
|
||||
Javelin::initBehavior('aphront-basic-tokenizer', array(
|
||||
'id' => $id,
|
||||
'src' => $this->datasource,
|
||||
'src' => $datasource_uri,
|
||||
'value' => mpull($values, 'getFullName', 'getPHID'),
|
||||
'icons' => mpull($values, 'getIcon', 'getPHID'),
|
||||
'limit' => $this->limit,
|
||||
'username' => $username,
|
||||
'placeholder' => $this->placeholder,
|
||||
'placeholder' => $placeholder,
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -75,6 +83,10 @@ final class AphrontFormTokenizerControl extends AphrontFormControl {
|
|||
private function getDefaultPlaceholder() {
|
||||
$datasource = $this->datasource;
|
||||
|
||||
if ($datasource instanceof PhabricatorTypeaheadDatasource) {
|
||||
return $datasource->getPlaceholderText();
|
||||
}
|
||||
|
||||
$matches = null;
|
||||
if (!preg_match('@^/typeahead/common/(.*)/$@', $datasource, $matches)) {
|
||||
return null;
|
||||
|
|
Loading…
Reference in a new issue