@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+66 -28
+2 -1
src/__phutil_library_map__.php
··· 5 5 * @generated 6 6 * @phutil-library-version 2 7 7 */ 8 - 9 8 phutil_register_library_map(array( 10 9 '__library_version__' => 2, 11 10 'class' => ··· 544 543 'DiffusionRenameHistoryQuery' => 'applications/diffusion/query/DiffusionRenameHistoryQuery.php', 545 544 'DiffusionRepositoryController' => 'applications/diffusion/controller/DiffusionRepositoryController.php', 546 545 'DiffusionRepositoryCreateController' => 'applications/diffusion/controller/DiffusionRepositoryCreateController.php', 546 + 'DiffusionRepositoryDatasource' => 'applications/diffusion/typeahead/DiffusionRepositoryDatasource.php', 547 547 'DiffusionRepositoryDefaultController' => 'applications/diffusion/controller/DiffusionRepositoryDefaultController.php', 548 548 'DiffusionRepositoryEditActionsController' => 'applications/diffusion/controller/DiffusionRepositoryEditActionsController.php', 549 549 'DiffusionRepositoryEditActivateController' => 'applications/diffusion/controller/DiffusionRepositoryEditActivateController.php', ··· 3245 3245 'DiffusionRefNotFoundException' => 'Exception', 3246 3246 'DiffusionRepositoryController' => 'DiffusionController', 3247 3247 'DiffusionRepositoryCreateController' => 'DiffusionRepositoryEditController', 3248 + 'DiffusionRepositoryDatasource' => 'PhabricatorTypeaheadDatasource', 3248 3249 'DiffusionRepositoryDefaultController' => 'DiffusionController', 3249 3250 'DiffusionRepositoryEditActionsController' => 'DiffusionRepositoryEditController', 3250 3251 'DiffusionRepositoryEditActivateController' => 'DiffusionRepositoryEditController',
+1 -1
src/applications/differential/customfield/DifferentialRepositoryField.php
··· 49 49 50 50 return id(new AphrontFormTokenizerControl()) 51 51 ->setName($this->getFieldKey()) 52 - ->setDatasource('/typeahead/common/repositories/') 52 + ->setDatasource(new DiffusionRepositoryDatasource()) 53 53 ->setValue($control_value) 54 54 ->setError($this->getFieldError()) 55 55 ->setLabel($this->getFieldName())
+1 -1
src/applications/differential/query/DifferentialRevisionSearchEngine.php
··· 167 167 id(new AphrontFormTokenizerControl()) 168 168 ->setLabel(pht('Repositories')) 169 169 ->setName('repositories') 170 - ->setDatasource('/typeahead/common/repositories/') 170 + ->setDatasource(new DiffusionRepositoryDatasource()) 171 171 ->setValue(array_select_keys($handles, $repository_phids))) 172 172 ->appendChild( 173 173 id(new AphrontFormSelectControl())
+35
src/applications/diffusion/typeahead/DiffusionRepositoryDatasource.php
··· 1 + <?php 2 + 3 + final class DiffusionRepositoryDatasource 4 + extends PhabricatorTypeaheadDatasource { 5 + 6 + public function getPlaceholderText() { 7 + return pht('Type a repository name...'); 8 + } 9 + 10 + public function getDatasourceApplicationClass() { 11 + return 'PhabricatorApplicationDiffusion'; 12 + } 13 + 14 + public function loadResults() { 15 + $viewer = $this->getViewer(); 16 + $raw_query = $this->getRawQuery(); 17 + 18 + $results = array(); 19 + 20 + $repos = id(new PhabricatorRepositoryQuery()) 21 + ->setViewer($viewer) 22 + ->execute(); 23 + foreach ($repos as $repo) { 24 + $results[] = id(new PhabricatorTypeaheadResult()) 25 + ->setName($repo->getMonogram().' '.$repo->getName()) 26 + ->setURI('/diffusion/'.$repo->getCallsign().'/') 27 + ->setPHID($repo->getPHID()) 28 + ->setPriorityString($repo->getMonogram()) 29 + ->setIcon('fa-database bluegrey'); 30 + } 31 + 32 + return $results; 33 + } 34 + 35 + }
+2 -1
src/applications/herald/controller/HeraldRuleController.php
··· 592 592 'source' => array( 593 593 'email' => '/typeahead/common/mailable/', 594 594 'user' => '/typeahead/common/accounts/', 595 - 'repository' => '/typeahead/common/repositories/', 595 + 'repository' => 596 + id(new DiffusionRepositoryDatasource())->getDatasourceURI(), 596 597 'package' => '/typeahead/common/packages/', 597 598 'project' => '/typeahead/common/projects/', 598 599 'userorproject' => '/typeahead/common/accountsorprojects/',
+4 -2
src/applications/repository/phid/PhabricatorRepositoryPHIDTypeRepository.php
··· 33 33 foreach ($handles as $phid => $handle) { 34 34 $repository = $objects[$phid]; 35 35 36 + $monogram = $repository->getMonogram(); 36 37 $callsign = $repository->getCallsign(); 37 38 $name = $repository->getName(); 38 39 39 - $handle->setName("r{$callsign}"); 40 - $handle->setFullName("r{$callsign} ({$name})"); 40 + $handle->setName($monogram); 41 + $handle->setFullName("{$monogram} {$name}"); 41 42 $handle->setURI("/diffusion/{$callsign}/"); 43 + $handle->setIcon('fa-database'); 42 44 } 43 45 } 44 46
+1 -1
src/applications/repository/query/PhabricatorRepositoryPushLogSearchEngine.php
··· 74 74 $form 75 75 ->appendChild( 76 76 id(new AphrontFormTokenizerControl()) 77 - ->setDatasource('/typeahead/common/repositories/') 77 + ->setDatasource(new DiffusionRepositoryDatasource()) 78 78 ->setName('repositories') 79 79 ->setLabel(pht('Repositories')) 80 80 ->setValue($repository_handles))
-17
src/applications/typeahead/controller/PhabricatorTypeaheadCommonDatasourceController.php
··· 26 26 $need_applications = false; 27 27 $need_lists = false; 28 28 $need_projs = false; 29 - $need_repos = false; 30 29 $need_packages = false; 31 30 $need_upforgrabs = false; 32 31 $need_arcanist_projects = false; ··· 77 76 $need_users = true; 78 77 $need_projs = true; 79 78 $need_packages = true; 80 - break; 81 - case 'repositories': 82 - $need_repos = true; 83 79 break; 84 80 case 'packages': 85 81 $need_packages = true; ··· 295 291 $proj_result->setImageURI($proj->getProfileImageURI()); 296 292 297 293 $results[] = $proj_result; 298 - } 299 - } 300 - 301 - if ($need_repos) { 302 - $repos = id(new PhabricatorRepositoryQuery()) 303 - ->setViewer($viewer) 304 - ->execute(); 305 - foreach ($repos as $repo) { 306 - $results[] = id(new PhabricatorTypeaheadResult()) 307 - ->setName('r'.$repo->getCallsign().' ('.$repo->getName().')') 308 - ->setURI('/diffusion/'.$repo->getCallsign().'/') 309 - ->setPHID($repo->getPHID()) 310 - ->setPriorityString('r'.$repo->getCallsign()); 311 294 } 312 295 } 313 296
+4
src/applications/typeahead/datasource/PhabricatorTypeaheadDatasource.php
··· 43 43 return $this->query; 44 44 } 45 45 46 + public function getDatasourceURI() { 47 + return '/typeahead/class/'.get_class($this).'/'; 48 + } 49 + 46 50 abstract public function getPlaceholderText(); 47 51 abstract public function getDatasourceApplicationClass(); 48 52 abstract public function loadResults();
+16 -4
src/view/form/control/AphrontFormTokenizerControl.php
··· 43 43 $id = celerity_generate_unique_node_id(); 44 44 } 45 45 46 - if (!$this->placeholder) { 47 - $this->placeholder = $this->getDefaultPlaceholder(); 46 + if (!strlen($this->placeholder)) { 47 + $placeholder = $this->getDefaultPlaceholder(); 48 + } else { 49 + $placeholder = $this->placeholder; 48 50 } 49 51 50 52 $template = new AphrontTokenizerTemplateView(); ··· 57 59 $username = $this->user->getUsername(); 58 60 } 59 61 62 + if ($this->datasource instanceof PhabricatorTypeaheadDatasource) { 63 + $datasource_uri = $this->datasource->getDatasourceURI(); 64 + } else { 65 + $datasource_uri = $this->datasource; 66 + } 67 + 60 68 if (!$this->disableBehavior) { 61 69 Javelin::initBehavior('aphront-basic-tokenizer', array( 62 70 'id' => $id, 63 - 'src' => $this->datasource, 71 + 'src' => $datasource_uri, 64 72 'value' => mpull($values, 'getFullName', 'getPHID'), 65 73 'icons' => mpull($values, 'getIcon', 'getPHID'), 66 74 'limit' => $this->limit, 67 75 'username' => $username, 68 - 'placeholder' => $this->placeholder, 76 + 'placeholder' => $placeholder, 69 77 )); 70 78 } 71 79 ··· 74 82 75 83 private function getDefaultPlaceholder() { 76 84 $datasource = $this->datasource; 85 + 86 + if ($datasource instanceof PhabricatorTypeaheadDatasource) { 87 + return $datasource->getPlaceholderText(); 88 + } 77 89 78 90 $matches = null; 79 91 if (!preg_match('@^/typeahead/common/(.*)/$@', $datasource, $matches)) {