1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-24 06:20:56 +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:
epriestley 2014-07-10 16:18:04 -07:00
parent e281c5ee90
commit 34628002fd
10 changed files with 66 additions and 28 deletions

View file

@ -5,7 +5,6 @@
* @generated * @generated
* @phutil-library-version 2 * @phutil-library-version 2
*/ */
phutil_register_library_map(array( phutil_register_library_map(array(
'__library_version__' => 2, '__library_version__' => 2,
'class' => 'class' =>
@ -544,6 +543,7 @@ phutil_register_library_map(array(
'DiffusionRenameHistoryQuery' => 'applications/diffusion/query/DiffusionRenameHistoryQuery.php', 'DiffusionRenameHistoryQuery' => 'applications/diffusion/query/DiffusionRenameHistoryQuery.php',
'DiffusionRepositoryController' => 'applications/diffusion/controller/DiffusionRepositoryController.php', 'DiffusionRepositoryController' => 'applications/diffusion/controller/DiffusionRepositoryController.php',
'DiffusionRepositoryCreateController' => 'applications/diffusion/controller/DiffusionRepositoryCreateController.php', 'DiffusionRepositoryCreateController' => 'applications/diffusion/controller/DiffusionRepositoryCreateController.php',
'DiffusionRepositoryDatasource' => 'applications/diffusion/typeahead/DiffusionRepositoryDatasource.php',
'DiffusionRepositoryDefaultController' => 'applications/diffusion/controller/DiffusionRepositoryDefaultController.php', 'DiffusionRepositoryDefaultController' => 'applications/diffusion/controller/DiffusionRepositoryDefaultController.php',
'DiffusionRepositoryEditActionsController' => 'applications/diffusion/controller/DiffusionRepositoryEditActionsController.php', 'DiffusionRepositoryEditActionsController' => 'applications/diffusion/controller/DiffusionRepositoryEditActionsController.php',
'DiffusionRepositoryEditActivateController' => 'applications/diffusion/controller/DiffusionRepositoryEditActivateController.php', 'DiffusionRepositoryEditActivateController' => 'applications/diffusion/controller/DiffusionRepositoryEditActivateController.php',
@ -3245,6 +3245,7 @@ phutil_register_library_map(array(
'DiffusionRefNotFoundException' => 'Exception', 'DiffusionRefNotFoundException' => 'Exception',
'DiffusionRepositoryController' => 'DiffusionController', 'DiffusionRepositoryController' => 'DiffusionController',
'DiffusionRepositoryCreateController' => 'DiffusionRepositoryEditController', 'DiffusionRepositoryCreateController' => 'DiffusionRepositoryEditController',
'DiffusionRepositoryDatasource' => 'PhabricatorTypeaheadDatasource',
'DiffusionRepositoryDefaultController' => 'DiffusionController', 'DiffusionRepositoryDefaultController' => 'DiffusionController',
'DiffusionRepositoryEditActionsController' => 'DiffusionRepositoryEditController', 'DiffusionRepositoryEditActionsController' => 'DiffusionRepositoryEditController',
'DiffusionRepositoryEditActivateController' => 'DiffusionRepositoryEditController', 'DiffusionRepositoryEditActivateController' => 'DiffusionRepositoryEditController',

View file

@ -49,7 +49,7 @@ final class DifferentialRepositoryField
return id(new AphrontFormTokenizerControl()) return id(new AphrontFormTokenizerControl())
->setName($this->getFieldKey()) ->setName($this->getFieldKey())
->setDatasource('/typeahead/common/repositories/') ->setDatasource(new DiffusionRepositoryDatasource())
->setValue($control_value) ->setValue($control_value)
->setError($this->getFieldError()) ->setError($this->getFieldError())
->setLabel($this->getFieldName()) ->setLabel($this->getFieldName())

View file

@ -167,7 +167,7 @@ final class DifferentialRevisionSearchEngine
id(new AphrontFormTokenizerControl()) id(new AphrontFormTokenizerControl())
->setLabel(pht('Repositories')) ->setLabel(pht('Repositories'))
->setName('repositories') ->setName('repositories')
->setDatasource('/typeahead/common/repositories/') ->setDatasource(new DiffusionRepositoryDatasource())
->setValue(array_select_keys($handles, $repository_phids))) ->setValue(array_select_keys($handles, $repository_phids)))
->appendChild( ->appendChild(
id(new AphrontFormSelectControl()) id(new AphrontFormSelectControl())

View file

@ -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;
}
}

View file

@ -592,7 +592,8 @@ final class HeraldRuleController extends HeraldController {
'source' => array( 'source' => array(
'email' => '/typeahead/common/mailable/', 'email' => '/typeahead/common/mailable/',
'user' => '/typeahead/common/accounts/', 'user' => '/typeahead/common/accounts/',
'repository' => '/typeahead/common/repositories/', 'repository' =>
id(new DiffusionRepositoryDatasource())->getDatasourceURI(),
'package' => '/typeahead/common/packages/', 'package' => '/typeahead/common/packages/',
'project' => '/typeahead/common/projects/', 'project' => '/typeahead/common/projects/',
'userorproject' => '/typeahead/common/accountsorprojects/', 'userorproject' => '/typeahead/common/accountsorprojects/',

View file

@ -33,12 +33,14 @@ final class PhabricatorRepositoryPHIDTypeRepository
foreach ($handles as $phid => $handle) { foreach ($handles as $phid => $handle) {
$repository = $objects[$phid]; $repository = $objects[$phid];
$monogram = $repository->getMonogram();
$callsign = $repository->getCallsign(); $callsign = $repository->getCallsign();
$name = $repository->getName(); $name = $repository->getName();
$handle->setName("r{$callsign}"); $handle->setName($monogram);
$handle->setFullName("r{$callsign} ({$name})"); $handle->setFullName("{$monogram} {$name}");
$handle->setURI("/diffusion/{$callsign}/"); $handle->setURI("/diffusion/{$callsign}/");
$handle->setIcon('fa-database');
} }
} }

View file

@ -74,7 +74,7 @@ final class PhabricatorRepositoryPushLogSearchEngine
$form $form
->appendChild( ->appendChild(
id(new AphrontFormTokenizerControl()) id(new AphrontFormTokenizerControl())
->setDatasource('/typeahead/common/repositories/') ->setDatasource(new DiffusionRepositoryDatasource())
->setName('repositories') ->setName('repositories')
->setLabel(pht('Repositories')) ->setLabel(pht('Repositories'))
->setValue($repository_handles)) ->setValue($repository_handles))

View file

@ -26,7 +26,6 @@ final class PhabricatorTypeaheadCommonDatasourceController
$need_applications = false; $need_applications = false;
$need_lists = false; $need_lists = false;
$need_projs = false; $need_projs = false;
$need_repos = false;
$need_packages = false; $need_packages = false;
$need_upforgrabs = false; $need_upforgrabs = false;
$need_arcanist_projects = false; $need_arcanist_projects = false;
@ -78,9 +77,6 @@ final class PhabricatorTypeaheadCommonDatasourceController
$need_projs = true; $need_projs = true;
$need_packages = true; $need_packages = true;
break; break;
case 'repositories':
$need_repos = true;
break;
case 'packages': case 'packages':
$need_packages = true; $need_packages = true;
break; 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) { if ($need_packages) {
$packages = id(new PhabricatorOwnersPackage())->loadAll(); $packages = id(new PhabricatorOwnersPackage())->loadAll();
foreach ($packages as $package) { foreach ($packages as $package) {

View file

@ -43,6 +43,10 @@ abstract class PhabricatorTypeaheadDatasource extends Phobject {
return $this->query; return $this->query;
} }
public function getDatasourceURI() {
return '/typeahead/class/'.get_class($this).'/';
}
abstract public function getPlaceholderText(); abstract public function getPlaceholderText();
abstract public function getDatasourceApplicationClass(); abstract public function getDatasourceApplicationClass();
abstract public function loadResults(); abstract public function loadResults();

View file

@ -43,8 +43,10 @@ final class AphrontFormTokenizerControl extends AphrontFormControl {
$id = celerity_generate_unique_node_id(); $id = celerity_generate_unique_node_id();
} }
if (!$this->placeholder) { if (!strlen($this->placeholder)) {
$this->placeholder = $this->getDefaultPlaceholder(); $placeholder = $this->getDefaultPlaceholder();
} else {
$placeholder = $this->placeholder;
} }
$template = new AphrontTokenizerTemplateView(); $template = new AphrontTokenizerTemplateView();
@ -57,15 +59,21 @@ final class AphrontFormTokenizerControl extends AphrontFormControl {
$username = $this->user->getUsername(); $username = $this->user->getUsername();
} }
if ($this->datasource instanceof PhabricatorTypeaheadDatasource) {
$datasource_uri = $this->datasource->getDatasourceURI();
} else {
$datasource_uri = $this->datasource;
}
if (!$this->disableBehavior) { if (!$this->disableBehavior) {
Javelin::initBehavior('aphront-basic-tokenizer', array( Javelin::initBehavior('aphront-basic-tokenizer', array(
'id' => $id, 'id' => $id,
'src' => $this->datasource, 'src' => $datasource_uri,
'value' => mpull($values, 'getFullName', 'getPHID'), 'value' => mpull($values, 'getFullName', 'getPHID'),
'icons' => mpull($values, 'getIcon', 'getPHID'), 'icons' => mpull($values, 'getIcon', 'getPHID'),
'limit' => $this->limit, 'limit' => $this->limit,
'username' => $username, 'username' => $username,
'placeholder' => $this->placeholder, 'placeholder' => $placeholder,
)); ));
} }
@ -75,6 +83,10 @@ final class AphrontFormTokenizerControl extends AphrontFormControl {
private function getDefaultPlaceholder() { private function getDefaultPlaceholder() {
$datasource = $this->datasource; $datasource = $this->datasource;
if ($datasource instanceof PhabricatorTypeaheadDatasource) {
return $datasource->getPlaceholderText();
}
$matches = null; $matches = null;
if (!preg_match('@^/typeahead/common/(.*)/$@', $datasource, $matches)) { if (!preg_match('@^/typeahead/common/(.*)/$@', $datasource, $matches)) {
return null; return null;