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

Make "user's projects" a logical datasource and add viewerprojects()

Summary:
Ref T4100. Ref T5595. This converts `projects(user)` into a logical datasource.

Also adds a viewerprojects() logical datasource.

Test Plan: {F375546}

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T4100, T5595

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

+101 -18
+6 -4
src/__phutil_library_map__.php
··· 2295 2295 'PhabricatorProjectIcon' => 'applications/project/icon/PhabricatorProjectIcon.php', 2296 2296 'PhabricatorProjectInterface' => 'applications/project/interface/PhabricatorProjectInterface.php', 2297 2297 'PhabricatorProjectListController' => 'applications/project/controller/PhabricatorProjectListController.php', 2298 - 'PhabricatorProjectLogicDatasource' => 'applications/project/typeahead/PhabricatorProjectLogicDatasource.php', 2299 2298 'PhabricatorProjectLogicalAndDatasource' => 'applications/project/typeahead/PhabricatorProjectLogicalAndDatasource.php', 2299 + 'PhabricatorProjectLogicalDatasource' => 'applications/project/typeahead/PhabricatorProjectLogicalDatasource.php', 2300 2300 'PhabricatorProjectLogicalOrNotDatasource' => 'applications/project/typeahead/PhabricatorProjectLogicalOrNotDatasource.php', 2301 + 'PhabricatorProjectLogicalUserDatasource' => 'applications/project/typeahead/PhabricatorProjectLogicalUserDatasource.php', 2302 + 'PhabricatorProjectLogicalViewerDatasource' => 'applications/project/typeahead/PhabricatorProjectLogicalViewerDatasource.php', 2301 2303 'PhabricatorProjectMemberOfProjectEdgeType' => 'applications/project/edge/PhabricatorProjectMemberOfProjectEdgeType.php', 2302 2304 'PhabricatorProjectMembersDatasource' => 'applications/project/typeahead/PhabricatorProjectMembersDatasource.php', 2303 2305 'PhabricatorProjectMembersEditController' => 'applications/project/controller/PhabricatorProjectMembersEditController.php', ··· 2668 2670 'PhabricatorUserPreferences' => 'applications/settings/storage/PhabricatorUserPreferences.php', 2669 2671 'PhabricatorUserProfile' => 'applications/people/storage/PhabricatorUserProfile.php', 2670 2672 'PhabricatorUserProfileEditor' => 'applications/people/editor/PhabricatorUserProfileEditor.php', 2671 - 'PhabricatorUserProjectsDatasource' => 'applications/people/typeahead/PhabricatorUserProjectsDatasource.php', 2672 2673 'PhabricatorUserRealNameField' => 'applications/people/customfield/PhabricatorUserRealNameField.php', 2673 2674 'PhabricatorUserRolesField' => 'applications/people/customfield/PhabricatorUserRolesField.php', 2674 2675 'PhabricatorUserSchemaSpec' => 'applications/people/storage/PhabricatorUserSchemaSpec.php', ··· 5678 5679 'PhabricatorProjectFeedController' => 'PhabricatorProjectController', 5679 5680 'PhabricatorProjectIcon' => 'Phobject', 5680 5681 'PhabricatorProjectListController' => 'PhabricatorProjectController', 5681 - 'PhabricatorProjectLogicDatasource' => 'PhabricatorTypeaheadCompositeDatasource', 5682 5682 'PhabricatorProjectLogicalAndDatasource' => 'PhabricatorTypeaheadCompositeDatasource', 5683 + 'PhabricatorProjectLogicalDatasource' => 'PhabricatorTypeaheadCompositeDatasource', 5683 5684 'PhabricatorProjectLogicalOrNotDatasource' => 'PhabricatorTypeaheadCompositeDatasource', 5685 + 'PhabricatorProjectLogicalUserDatasource' => 'PhabricatorTypeaheadCompositeDatasource', 5686 + 'PhabricatorProjectLogicalViewerDatasource' => 'PhabricatorTypeaheadDatasource', 5684 5687 'PhabricatorProjectMemberOfProjectEdgeType' => 'PhabricatorEdgeType', 5685 5688 'PhabricatorProjectMembersDatasource' => 'PhabricatorTypeaheadCompositeDatasource', 5686 5689 'PhabricatorProjectMembersEditController' => 'PhabricatorProjectController', ··· 6092 6095 'PhabricatorUserPreferences' => 'PhabricatorUserDAO', 6093 6096 'PhabricatorUserProfile' => 'PhabricatorUserDAO', 6094 6097 'PhabricatorUserProfileEditor' => 'PhabricatorApplicationTransactionEditor', 6095 - 'PhabricatorUserProjectsDatasource' => 'PhabricatorTypeaheadCompositeDatasource', 6096 6098 'PhabricatorUserRealNameField' => 'PhabricatorUserCustomField', 6097 6099 'PhabricatorUserRolesField' => 'PhabricatorUserCustomField', 6098 6100 'PhabricatorUserSchemaSpec' => 'PhabricatorConfigSchemaSpec',
+12 -13
src/applications/people/typeahead/PhabricatorUserProjectsDatasource.php src/applications/project/typeahead/PhabricatorProjectLogicalUserDatasource.php
··· 1 1 <?php 2 2 3 - final class PhabricatorUserProjectsDatasource 3 + final class PhabricatorProjectLogicalUserDatasource 4 4 extends PhabricatorTypeaheadCompositeDatasource { 5 5 6 6 public function getPlaceholderText() { ··· 29 29 foreach ($results as $result) { 30 30 $result 31 31 ->setTokenType(PhabricatorTypeaheadTokenView::TYPE_FUNCTION) 32 - ->setIcon('fa-briefcase') 32 + ->setIcon('fa-asterisk') 33 33 ->setPHID('projects('.$result->getPHID().')') 34 - ->setDisplayName(pht('Projects: %s', $result->getDisplayName())) 34 + ->setDisplayName(pht("User's Projects: %s", $result->getDisplayName())) 35 35 ->setName($result->getName().' projects'); 36 36 } 37 37 ··· 44 44 $phids[] = head($argv); 45 45 } 46 46 47 - $projects = id(new PhabricatorPeopleQuery()) 47 + $projects = id(new PhabricatorProjectQuery()) 48 48 ->setViewer($this->getViewer()) 49 - ->needMembers(true) 50 - ->withPHIDs($phids) 49 + ->withMemberPHIDs($phids) 51 50 ->execute(); 52 51 53 52 $results = array(); 54 53 foreach ($projects as $project) { 55 - foreach ($project->getMemberPHIDs() as $phid) { 56 - $results[$phid] = $phid; 57 - } 54 + $results[] = new PhabricatorQueryConstraint( 55 + PhabricatorQueryConstraint::OPERATOR_OR, 56 + $project->getPHID()); 58 57 } 59 58 60 - return array_values($results); 59 + return $results; 61 60 } 62 61 63 62 public function renderFunctionTokens($function, array $argv_list) { ··· 70 69 foreach ($tokens as $token) { 71 70 if ($token->isInvalid()) { 72 71 $token 73 - ->setValue(pht('Projects: Invalid User')); 72 + ->setValue(pht("User's Projects: Invalid User")); 74 73 } else { 75 74 $token 76 - ->setIcon('fa-users') 75 + ->setIcon('fa-asterisk') 77 76 ->setTokenType(PhabricatorTypeaheadTokenView::TYPE_FUNCTION) 78 77 ->setKey('projects('.$token->getKey().')') 79 - ->setValue(pht('Projects: %s', $token->getValue())); 78 + ->setValue(pht("User's Projects: %s", $token->getValue())); 80 79 } 81 80 } 82 81
+3 -1
src/applications/project/typeahead/PhabricatorProjectLogicDatasource.php src/applications/project/typeahead/PhabricatorProjectLogicalDatasource.php
··· 1 1 <?php 2 2 3 - final class PhabricatorProjectLogicDatasource 3 + final class PhabricatorProjectLogicalDatasource 4 4 extends PhabricatorTypeaheadCompositeDatasource { 5 5 6 6 public function getPlaceholderText() { ··· 16 16 new PhabricatorProjectNoProjectsDatasource(), 17 17 new PhabricatorProjectLogicalAndDatasource(), 18 18 new PhabricatorProjectLogicalOrNotDatasource(), 19 + new PhabricatorProjectLogicalViewerDatasource(), 20 + new PhabricatorProjectLogicalUserDatasource(), 19 21 ); 20 22 } 21 23
+80
src/applications/project/typeahead/PhabricatorProjectLogicalViewerDatasource.php
··· 1 + <?php 2 + 3 + final class PhabricatorProjectLogicalViewerDatasource 4 + extends PhabricatorTypeaheadDatasource { 5 + 6 + public function getPlaceholderText() { 7 + return pht('Type viewerprojects()...'); 8 + } 9 + 10 + public function getDatasourceApplicationClass() { 11 + return 'PhabricatorProjectApplication'; 12 + } 13 + 14 + public function getDatasourceFunctions() { 15 + return array( 16 + 'viewerprojects' => array( 17 + 'name' => pht("Find results in any of the current viewer's projects."), 18 + ), 19 + ); 20 + } 21 + 22 + public function loadResults() { 23 + if ($this->getViewer()->getPHID()) { 24 + $results = array($this->renderViewerProjectsFunctionToken()); 25 + } else { 26 + $results = array(); 27 + } 28 + 29 + return $this->filterResultsAgainstTokens($results); 30 + } 31 + 32 + protected function canEvaluateFunction($function) { 33 + if (!$this->getViewer()->getPHID()) { 34 + return false; 35 + } 36 + 37 + return parent::canEvaluateFunction($function); 38 + } 39 + 40 + protected function evaluateFunction($function, array $argv_list) { 41 + $viewer = $this->getViewer(); 42 + 43 + $projects = id(new PhabricatorProjectQuery()) 44 + ->setViewer($viewer) 45 + ->withMemberPHIDs(array($viewer->getPHID())) 46 + ->execute(); 47 + $phids = mpull($projects, 'getPHID'); 48 + 49 + $results = array(); 50 + foreach ($phids as $phid) { 51 + $results[] = new PhabricatorQueryConstraint( 52 + PhabricatorQueryConstraint::OPERATOR_OR, 53 + $phid); 54 + } 55 + 56 + return $results; 57 + } 58 + 59 + public function renderViewerProjectsFunctionTokens( 60 + $function, 61 + array $argv_list) { 62 + 63 + $tokens = array(); 64 + foreach ($argv_list as $argv) { 65 + $tokens[] = PhabricatorTypeaheadTokenView::newFromTypeaheadResult( 66 + $this->renderViewerProjectsFunctionToken()); 67 + } 68 + 69 + return $tokens; 70 + } 71 + 72 + private function renderViewerProjectsFunctionToken() { 73 + return $this->newFunctionResult() 74 + ->setName(pht('Current Viewer\'s Projects')) 75 + ->setPHID('viewerprojects()') 76 + ->setIcon('fa-asterisk') 77 + ->setUnique(true); 78 + } 79 + 80 + }