Page MenuHomePhabricator

D12462.diff
No OneTemporary

D12462.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -2295,9 +2295,11 @@
'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 @@
'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 @@
'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 @@
'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
rename from src/applications/project/typeahead/PhabricatorProjectLogicDatasource.php
rename to src/applications/project/typeahead/PhabricatorProjectLogicalDatasource.php
--- a/src/applications/project/typeahead/PhabricatorProjectLogicDatasource.php
+++ b/src/applications/project/typeahead/PhabricatorProjectLogicalDatasource.php
@@ -1,6 +1,6 @@
<?php
-final class PhabricatorProjectLogicDatasource
+final class PhabricatorProjectLogicalDatasource
extends PhabricatorTypeaheadCompositeDatasource {
public function getPlaceholderText() {
@@ -16,6 +16,8 @@
new PhabricatorProjectNoProjectsDatasource(),
new PhabricatorProjectLogicalAndDatasource(),
new PhabricatorProjectLogicalOrNotDatasource(),
+ new PhabricatorProjectLogicalViewerDatasource(),
+ new PhabricatorProjectLogicalUserDatasource(),
);
}
diff --git a/src/applications/people/typeahead/PhabricatorUserProjectsDatasource.php b/src/applications/project/typeahead/PhabricatorProjectLogicalUserDatasource.php
rename from src/applications/people/typeahead/PhabricatorUserProjectsDatasource.php
rename to src/applications/project/typeahead/PhabricatorProjectLogicalUserDatasource.php
--- a/src/applications/people/typeahead/PhabricatorUserProjectsDatasource.php
+++ b/src/applications/project/typeahead/PhabricatorProjectLogicalUserDatasource.php
@@ -1,6 +1,6 @@
<?php
-final class PhabricatorUserProjectsDatasource
+final class PhabricatorProjectLogicalUserDatasource
extends PhabricatorTypeaheadCompositeDatasource {
public function getPlaceholderText() {
@@ -29,9 +29,9 @@
foreach ($results as $result) {
$result
->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 @@
$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 @@
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
--- /dev/null
+++ b/src/applications/project/typeahead/PhabricatorProjectLogicalViewerDatasource.php
@@ -0,0 +1,80 @@
+<?php
+
+final class PhabricatorProjectLogicalViewerDatasource
+ extends PhabricatorTypeaheadDatasource {
+
+ public function getPlaceholderText() {
+ return pht('Type viewerprojects()...');
+ }
+
+ public function getDatasourceApplicationClass() {
+ return 'PhabricatorProjectApplication';
+ }
+
+ public function getDatasourceFunctions() {
+ return array(
+ 'viewerprojects' => 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);
+ }
+
+}

File Metadata

Mime Type
text/plain
Expires
Thu, Oct 31, 9:10 PM (2 w, 4 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6725205
Default Alt Text
D12462.diff (9 KB)

Event Timeline