diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 4eeb77603a..ed6a1bccd7 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -2295,9 +2295,11 @@ phutil_register_library_map(array( 'PhabricatorProjectIcon' => 'applications/project/icon/PhabricatorProjectIcon.php', 'PhabricatorProjectInterface' => 'applications/project/interface/PhabricatorProjectInterface.php', 'PhabricatorProjectListController' => 'applications/project/controller/PhabricatorProjectListController.php', - 'PhabricatorProjectLogicDatasource' => 'applications/project/typeahead/PhabricatorProjectLogicDatasource.php', 'PhabricatorProjectLogicalAndDatasource' => 'applications/project/typeahead/PhabricatorProjectLogicalAndDatasource.php', + 'PhabricatorProjectLogicalDatasource' => 'applications/project/typeahead/PhabricatorProjectLogicalDatasource.php', 'PhabricatorProjectLogicalOrNotDatasource' => 'applications/project/typeahead/PhabricatorProjectLogicalOrNotDatasource.php', + 'PhabricatorProjectLogicalUserDatasource' => 'applications/project/typeahead/PhabricatorProjectLogicalUserDatasource.php', + 'PhabricatorProjectLogicalViewerDatasource' => 'applications/project/typeahead/PhabricatorProjectLogicalViewerDatasource.php', 'PhabricatorProjectMemberOfProjectEdgeType' => 'applications/project/edge/PhabricatorProjectMemberOfProjectEdgeType.php', 'PhabricatorProjectMembersDatasource' => 'applications/project/typeahead/PhabricatorProjectMembersDatasource.php', 'PhabricatorProjectMembersEditController' => 'applications/project/controller/PhabricatorProjectMembersEditController.php', @@ -2668,7 +2670,6 @@ phutil_register_library_map(array( 'PhabricatorUserPreferences' => 'applications/settings/storage/PhabricatorUserPreferences.php', 'PhabricatorUserProfile' => 'applications/people/storage/PhabricatorUserProfile.php', 'PhabricatorUserProfileEditor' => 'applications/people/editor/PhabricatorUserProfileEditor.php', - 'PhabricatorUserProjectsDatasource' => 'applications/people/typeahead/PhabricatorUserProjectsDatasource.php', 'PhabricatorUserRealNameField' => 'applications/people/customfield/PhabricatorUserRealNameField.php', 'PhabricatorUserRolesField' => 'applications/people/customfield/PhabricatorUserRolesField.php', 'PhabricatorUserSchemaSpec' => 'applications/people/storage/PhabricatorUserSchemaSpec.php', @@ -5678,9 +5679,11 @@ phutil_register_library_map(array( 'PhabricatorProjectFeedController' => 'PhabricatorProjectController', 'PhabricatorProjectIcon' => 'Phobject', 'PhabricatorProjectListController' => 'PhabricatorProjectController', - 'PhabricatorProjectLogicDatasource' => 'PhabricatorTypeaheadCompositeDatasource', 'PhabricatorProjectLogicalAndDatasource' => 'PhabricatorTypeaheadCompositeDatasource', + 'PhabricatorProjectLogicalDatasource' => 'PhabricatorTypeaheadCompositeDatasource', 'PhabricatorProjectLogicalOrNotDatasource' => 'PhabricatorTypeaheadCompositeDatasource', + 'PhabricatorProjectLogicalUserDatasource' => 'PhabricatorTypeaheadCompositeDatasource', + 'PhabricatorProjectLogicalViewerDatasource' => 'PhabricatorTypeaheadDatasource', 'PhabricatorProjectMemberOfProjectEdgeType' => 'PhabricatorEdgeType', 'PhabricatorProjectMembersDatasource' => 'PhabricatorTypeaheadCompositeDatasource', 'PhabricatorProjectMembersEditController' => 'PhabricatorProjectController', @@ -6092,7 +6095,6 @@ phutil_register_library_map(array( 'PhabricatorUserPreferences' => 'PhabricatorUserDAO', 'PhabricatorUserProfile' => 'PhabricatorUserDAO', 'PhabricatorUserProfileEditor' => 'PhabricatorApplicationTransactionEditor', - 'PhabricatorUserProjectsDatasource' => 'PhabricatorTypeaheadCompositeDatasource', 'PhabricatorUserRealNameField' => 'PhabricatorUserCustomField', 'PhabricatorUserRolesField' => 'PhabricatorUserCustomField', 'PhabricatorUserSchemaSpec' => 'PhabricatorConfigSchemaSpec', diff --git a/src/applications/project/typeahead/PhabricatorProjectLogicDatasource.php b/src/applications/project/typeahead/PhabricatorProjectLogicalDatasource.php similarity index 76% rename from src/applications/project/typeahead/PhabricatorProjectLogicDatasource.php rename to src/applications/project/typeahead/PhabricatorProjectLogicalDatasource.php index 89088a486e..17afb30c99 100644 --- a/src/applications/project/typeahead/PhabricatorProjectLogicDatasource.php +++ b/src/applications/project/typeahead/PhabricatorProjectLogicalDatasource.php @@ -1,6 +1,6 @@ setTokenType(PhabricatorTypeaheadTokenView::TYPE_FUNCTION) - ->setIcon('fa-briefcase') + ->setIcon('fa-asterisk') ->setPHID('projects('.$result->getPHID().')') - ->setDisplayName(pht('Projects: %s', $result->getDisplayName())) + ->setDisplayName(pht("User's Projects: %s", $result->getDisplayName())) ->setName($result->getName().' projects'); } @@ -44,20 +44,19 @@ final class PhabricatorUserProjectsDatasource $phids[] = head($argv); } - $projects = id(new PhabricatorPeopleQuery()) + $projects = id(new PhabricatorProjectQuery()) ->setViewer($this->getViewer()) - ->needMembers(true) - ->withPHIDs($phids) + ->withMemberPHIDs($phids) ->execute(); $results = array(); foreach ($projects as $project) { - foreach ($project->getMemberPHIDs() as $phid) { - $results[$phid] = $phid; - } + $results[] = new PhabricatorQueryConstraint( + PhabricatorQueryConstraint::OPERATOR_OR, + $project->getPHID()); } - return array_values($results); + return $results; } public function renderFunctionTokens($function, array $argv_list) { @@ -70,13 +69,13 @@ final class PhabricatorUserProjectsDatasource foreach ($tokens as $token) { if ($token->isInvalid()) { $token - ->setValue(pht('Projects: Invalid User')); + ->setValue(pht("User's Projects: Invalid User")); } else { $token - ->setIcon('fa-users') + ->setIcon('fa-asterisk') ->setTokenType(PhabricatorTypeaheadTokenView::TYPE_FUNCTION) ->setKey('projects('.$token->getKey().')') - ->setValue(pht('Projects: %s', $token->getValue())); + ->setValue(pht("User's Projects: %s", $token->getValue())); } } diff --git a/src/applications/project/typeahead/PhabricatorProjectLogicalViewerDatasource.php b/src/applications/project/typeahead/PhabricatorProjectLogicalViewerDatasource.php new file mode 100644 index 0000000000..530ded391b --- /dev/null +++ b/src/applications/project/typeahead/PhabricatorProjectLogicalViewerDatasource.php @@ -0,0 +1,80 @@ + array( + 'name' => pht("Find results in any of the current viewer's projects."), + ), + ); + } + + public function loadResults() { + if ($this->getViewer()->getPHID()) { + $results = array($this->renderViewerProjectsFunctionToken()); + } else { + $results = array(); + } + + return $this->filterResultsAgainstTokens($results); + } + + protected function canEvaluateFunction($function) { + if (!$this->getViewer()->getPHID()) { + return false; + } + + return parent::canEvaluateFunction($function); + } + + protected function evaluateFunction($function, array $argv_list) { + $viewer = $this->getViewer(); + + $projects = id(new PhabricatorProjectQuery()) + ->setViewer($viewer) + ->withMemberPHIDs(array($viewer->getPHID())) + ->execute(); + $phids = mpull($projects, 'getPHID'); + + $results = array(); + foreach ($phids as $phid) { + $results[] = new PhabricatorQueryConstraint( + PhabricatorQueryConstraint::OPERATOR_OR, + $phid); + } + + return $results; + } + + public function renderViewerProjectsFunctionTokens( + $function, + array $argv_list) { + + $tokens = array(); + foreach ($argv_list as $argv) { + $tokens[] = PhabricatorTypeaheadTokenView::newFromTypeaheadResult( + $this->renderViewerProjectsFunctionToken()); + } + + return $tokens; + } + + private function renderViewerProjectsFunctionToken() { + return $this->newFunctionResult() + ->setName(pht('Current Viewer\'s Projects')) + ->setPHID('viewerprojects()') + ->setIcon('fa-asterisk') + ->setUnique(true); + } + +}