@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.

Implement a projects() datasource function

Summary:
Ref T4100. This is like members(), but is implemented on top of the raw datasource. This is a lot simpler and involves way less code duplication.

I'll go back and implement members() like this, too.

Nothing actually uses this yet.

Test Plan:
- Used browse view to browse datasource.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T4100

Differential Revision: https://secure.phabricator.com/D12458

+121 -3
+2
src/__phutil_library_map__.php
··· 2664 2664 'PhabricatorUserPreferences' => 'applications/settings/storage/PhabricatorUserPreferences.php', 2665 2665 'PhabricatorUserProfile' => 'applications/people/storage/PhabricatorUserProfile.php', 2666 2666 'PhabricatorUserProfileEditor' => 'applications/people/editor/PhabricatorUserProfileEditor.php', 2667 + 'PhabricatorUserProjectsDatasource' => 'applications/people/typeahead/PhabricatorUserProjectsDatasource.php', 2667 2668 'PhabricatorUserRealNameField' => 'applications/people/customfield/PhabricatorUserRealNameField.php', 2668 2669 'PhabricatorUserRolesField' => 'applications/people/customfield/PhabricatorUserRolesField.php', 2669 2670 'PhabricatorUserSchemaSpec' => 'applications/people/storage/PhabricatorUserSchemaSpec.php', ··· 6083 6084 'PhabricatorUserPreferences' => 'PhabricatorUserDAO', 6084 6085 'PhabricatorUserProfile' => 'PhabricatorUserDAO', 6085 6086 'PhabricatorUserProfileEditor' => 'PhabricatorApplicationTransactionEditor', 6087 + 'PhabricatorUserProjectsDatasource' => 'PhabricatorTypeaheadCompositeDatasource', 6086 6088 'PhabricatorUserRealNameField' => 'PhabricatorUserCustomField', 6087 6089 'PhabricatorUserRolesField' => 'PhabricatorUserCustomField', 6088 6090 'PhabricatorUserSchemaSpec' => 'PhabricatorConfigSchemaSpec',
+85
src/applications/people/typeahead/PhabricatorUserProjectsDatasource.php
··· 1 + <?php 2 + 3 + final class PhabricatorUserProjectsDatasource 4 + extends PhabricatorTypeaheadCompositeDatasource { 5 + 6 + public function getPlaceholderText() { 7 + return pht('Type projects(<user>)...'); 8 + } 9 + 10 + public function getDatasourceApplicationClass() { 11 + return 'PhabricatorProjectApplication'; 12 + } 13 + 14 + public function getComponentDatasources() { 15 + return array( 16 + new PhabricatorPeopleDatasource(), 17 + ); 18 + } 19 + 20 + public function getDatasourceFunctions() { 21 + return array( 22 + 'projects' => array( 23 + 'name' => pht("Find results in any of a user's projects."), 24 + ), 25 + ); 26 + } 27 + 28 + protected function didLoadResults(array $results) { 29 + foreach ($results as $result) { 30 + $result 31 + ->setTokenType(PhabricatorTypeaheadTokenView::TYPE_FUNCTION) 32 + ->setIcon('fa-briefcase') 33 + ->setPHID('projects('.$result->getPHID().')') 34 + ->setDisplayName(pht('Projects: %s', $result->getDisplayName())) 35 + ->setName($result->getName().' projects'); 36 + } 37 + 38 + return $results; 39 + } 40 + 41 + protected function evaluateFunction($function, array $argv_list) { 42 + $phids = array(); 43 + foreach ($argv_list as $argv) { 44 + $phids[] = head($argv); 45 + } 46 + 47 + $projects = id(new PhabricatorPeopleQuery()) 48 + ->setViewer($this->getViewer()) 49 + ->needMembers(true) 50 + ->withPHIDs($phids) 51 + ->execute(); 52 + 53 + $results = array(); 54 + foreach ($projects as $project) { 55 + foreach ($project->getMemberPHIDs() as $phid) { 56 + $results[$phid] = $phid; 57 + } 58 + } 59 + 60 + return array_values($results); 61 + } 62 + 63 + public function renderFunctionTokens($function, array $argv_list) { 64 + $phids = array(); 65 + foreach ($argv_list as $argv) { 66 + $phids[] = head($argv); 67 + } 68 + 69 + $tokens = $this->renderTokens($phids); 70 + foreach ($tokens as $token) { 71 + if ($token->isInvalid()) { 72 + $token 73 + ->setValue(pht('Projects: Invalid User')); 74 + } else { 75 + $token 76 + ->setTokenType(PhabricatorTypeaheadTokenView::TYPE_FUNCTION) 77 + ->setKey('projects('.$token->getKey().')') 78 + ->setValue(pht('Projects: %s', $token->getValue())); 79 + } 80 + } 81 + 82 + return $tokens; 83 + } 84 + 85 + }
+16 -2
src/applications/typeahead/datasource/PhabricatorTypeaheadCompositeDatasource.php
··· 25 25 $offset = $this->getOffset(); 26 26 $limit = $this->getLimit(); 27 27 28 + // If the input query is a function like `members(platy`, and we can 29 + // parse the function, we strip the function off and hand the stripped 30 + // query to child sources. This makes it easier to implement function 31 + // sources in terms of real object sources. 32 + $raw_query = $this->getRawQuery(); 33 + if (self::isFunctionToken($raw_query)) { 34 + $function = $this->parseFunction($raw_query, $allow_partial = true); 35 + if ($function) { 36 + $raw_query = head($function['argv']); 37 + } 38 + } 39 + 28 40 $results = array(); 29 41 foreach ($this->getUsableDatasources() as $source) { 30 42 $source 31 - ->setRawQuery($this->getRawQuery()) 43 + ->setRawQuery($raw_query) 32 44 ->setQuery($this->getQuery()) 33 45 ->setViewer($this->getViewer()); 34 46 ··· 36 48 $source->setLimit($offset + $limit); 37 49 } 38 50 39 - $results[] = $source->loadResults(); 51 + $source_results = $source->loadResults(); 52 + $source_results = $source->didLoadResults($source_results); 53 + $results[] = $source_results; 40 54 } 41 55 42 56 $results = array_mergev($results);
+14 -1
src/applications/typeahead/datasource/PhabricatorTypeaheadDatasource.php
··· 90 90 abstract public function getDatasourceApplicationClass(); 91 91 abstract public function loadResults(); 92 92 93 + protected function didLoadResults(array $results) { 94 + return $results; 95 + } 96 + 93 97 public static function tokenizeString($string) { 94 98 $string = phutil_utf8_strtolower($string); 95 99 $string = trim($string); ··· 261 265 /** 262 266 * @task functions 263 267 */ 268 + public function getDatasourceFunctions() { 269 + return array(); 270 + } 271 + 272 + 273 + /** 274 + * @task functions 275 + */ 264 276 protected function canEvaluateFunction($function) { 265 - return false; 277 + $functions = $this->getDatasourceFunctions(); 278 + return isset($functions[$function]); 266 279 } 267 280 268 281
+4
src/applications/typeahead/view/PhabricatorTypeaheadTokenView.php
··· 44 44 return $token; 45 45 } 46 46 47 + public function isInvalid() { 48 + return ($this->getTokenType() == self::TYPE_INVALID); 49 + } 50 + 47 51 public function setKey($key) { 48 52 $this->key = $key; 49 53 return $this;