1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-19 12:00:55 +01:00

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
This commit is contained in:
epriestley 2015-04-18 11:04:50 -07:00
parent c2fc065bfb
commit f331463d50
4 changed files with 101 additions and 18 deletions

View file

@ -2295,9 +2295,11 @@ phutil_register_library_map(array(
'PhabricatorProjectIcon' => 'applications/project/icon/PhabricatorProjectIcon.php', 'PhabricatorProjectIcon' => 'applications/project/icon/PhabricatorProjectIcon.php',
'PhabricatorProjectInterface' => 'applications/project/interface/PhabricatorProjectInterface.php', 'PhabricatorProjectInterface' => 'applications/project/interface/PhabricatorProjectInterface.php',
'PhabricatorProjectListController' => 'applications/project/controller/PhabricatorProjectListController.php', 'PhabricatorProjectListController' => 'applications/project/controller/PhabricatorProjectListController.php',
'PhabricatorProjectLogicDatasource' => 'applications/project/typeahead/PhabricatorProjectLogicDatasource.php',
'PhabricatorProjectLogicalAndDatasource' => 'applications/project/typeahead/PhabricatorProjectLogicalAndDatasource.php', 'PhabricatorProjectLogicalAndDatasource' => 'applications/project/typeahead/PhabricatorProjectLogicalAndDatasource.php',
'PhabricatorProjectLogicalDatasource' => 'applications/project/typeahead/PhabricatorProjectLogicalDatasource.php',
'PhabricatorProjectLogicalOrNotDatasource' => 'applications/project/typeahead/PhabricatorProjectLogicalOrNotDatasource.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', 'PhabricatorProjectMemberOfProjectEdgeType' => 'applications/project/edge/PhabricatorProjectMemberOfProjectEdgeType.php',
'PhabricatorProjectMembersDatasource' => 'applications/project/typeahead/PhabricatorProjectMembersDatasource.php', 'PhabricatorProjectMembersDatasource' => 'applications/project/typeahead/PhabricatorProjectMembersDatasource.php',
'PhabricatorProjectMembersEditController' => 'applications/project/controller/PhabricatorProjectMembersEditController.php', 'PhabricatorProjectMembersEditController' => 'applications/project/controller/PhabricatorProjectMembersEditController.php',
@ -2668,7 +2670,6 @@ phutil_register_library_map(array(
'PhabricatorUserPreferences' => 'applications/settings/storage/PhabricatorUserPreferences.php', 'PhabricatorUserPreferences' => 'applications/settings/storage/PhabricatorUserPreferences.php',
'PhabricatorUserProfile' => 'applications/people/storage/PhabricatorUserProfile.php', 'PhabricatorUserProfile' => 'applications/people/storage/PhabricatorUserProfile.php',
'PhabricatorUserProfileEditor' => 'applications/people/editor/PhabricatorUserProfileEditor.php', 'PhabricatorUserProfileEditor' => 'applications/people/editor/PhabricatorUserProfileEditor.php',
'PhabricatorUserProjectsDatasource' => 'applications/people/typeahead/PhabricatorUserProjectsDatasource.php',
'PhabricatorUserRealNameField' => 'applications/people/customfield/PhabricatorUserRealNameField.php', 'PhabricatorUserRealNameField' => 'applications/people/customfield/PhabricatorUserRealNameField.php',
'PhabricatorUserRolesField' => 'applications/people/customfield/PhabricatorUserRolesField.php', 'PhabricatorUserRolesField' => 'applications/people/customfield/PhabricatorUserRolesField.php',
'PhabricatorUserSchemaSpec' => 'applications/people/storage/PhabricatorUserSchemaSpec.php', 'PhabricatorUserSchemaSpec' => 'applications/people/storage/PhabricatorUserSchemaSpec.php',
@ -5678,9 +5679,11 @@ phutil_register_library_map(array(
'PhabricatorProjectFeedController' => 'PhabricatorProjectController', 'PhabricatorProjectFeedController' => 'PhabricatorProjectController',
'PhabricatorProjectIcon' => 'Phobject', 'PhabricatorProjectIcon' => 'Phobject',
'PhabricatorProjectListController' => 'PhabricatorProjectController', 'PhabricatorProjectListController' => 'PhabricatorProjectController',
'PhabricatorProjectLogicDatasource' => 'PhabricatorTypeaheadCompositeDatasource',
'PhabricatorProjectLogicalAndDatasource' => 'PhabricatorTypeaheadCompositeDatasource', 'PhabricatorProjectLogicalAndDatasource' => 'PhabricatorTypeaheadCompositeDatasource',
'PhabricatorProjectLogicalDatasource' => 'PhabricatorTypeaheadCompositeDatasource',
'PhabricatorProjectLogicalOrNotDatasource' => 'PhabricatorTypeaheadCompositeDatasource', 'PhabricatorProjectLogicalOrNotDatasource' => 'PhabricatorTypeaheadCompositeDatasource',
'PhabricatorProjectLogicalUserDatasource' => 'PhabricatorTypeaheadCompositeDatasource',
'PhabricatorProjectLogicalViewerDatasource' => 'PhabricatorTypeaheadDatasource',
'PhabricatorProjectMemberOfProjectEdgeType' => 'PhabricatorEdgeType', 'PhabricatorProjectMemberOfProjectEdgeType' => 'PhabricatorEdgeType',
'PhabricatorProjectMembersDatasource' => 'PhabricatorTypeaheadCompositeDatasource', 'PhabricatorProjectMembersDatasource' => 'PhabricatorTypeaheadCompositeDatasource',
'PhabricatorProjectMembersEditController' => 'PhabricatorProjectController', 'PhabricatorProjectMembersEditController' => 'PhabricatorProjectController',
@ -6092,7 +6095,6 @@ phutil_register_library_map(array(
'PhabricatorUserPreferences' => 'PhabricatorUserDAO', 'PhabricatorUserPreferences' => 'PhabricatorUserDAO',
'PhabricatorUserProfile' => 'PhabricatorUserDAO', 'PhabricatorUserProfile' => 'PhabricatorUserDAO',
'PhabricatorUserProfileEditor' => 'PhabricatorApplicationTransactionEditor', 'PhabricatorUserProfileEditor' => 'PhabricatorApplicationTransactionEditor',
'PhabricatorUserProjectsDatasource' => 'PhabricatorTypeaheadCompositeDatasource',
'PhabricatorUserRealNameField' => 'PhabricatorUserCustomField', 'PhabricatorUserRealNameField' => 'PhabricatorUserCustomField',
'PhabricatorUserRolesField' => 'PhabricatorUserCustomField', 'PhabricatorUserRolesField' => 'PhabricatorUserCustomField',
'PhabricatorUserSchemaSpec' => 'PhabricatorConfigSchemaSpec', 'PhabricatorUserSchemaSpec' => 'PhabricatorConfigSchemaSpec',

View file

@ -1,6 +1,6 @@
<?php <?php
final class PhabricatorProjectLogicDatasource final class PhabricatorProjectLogicalDatasource
extends PhabricatorTypeaheadCompositeDatasource { extends PhabricatorTypeaheadCompositeDatasource {
public function getPlaceholderText() { public function getPlaceholderText() {
@ -16,6 +16,8 @@ final class PhabricatorProjectLogicDatasource
new PhabricatorProjectNoProjectsDatasource(), new PhabricatorProjectNoProjectsDatasource(),
new PhabricatorProjectLogicalAndDatasource(), new PhabricatorProjectLogicalAndDatasource(),
new PhabricatorProjectLogicalOrNotDatasource(), new PhabricatorProjectLogicalOrNotDatasource(),
new PhabricatorProjectLogicalViewerDatasource(),
new PhabricatorProjectLogicalUserDatasource(),
); );
} }

View file

@ -1,6 +1,6 @@
<?php <?php
final class PhabricatorUserProjectsDatasource final class PhabricatorProjectLogicalUserDatasource
extends PhabricatorTypeaheadCompositeDatasource { extends PhabricatorTypeaheadCompositeDatasource {
public function getPlaceholderText() { public function getPlaceholderText() {
@ -29,9 +29,9 @@ final class PhabricatorUserProjectsDatasource
foreach ($results as $result) { foreach ($results as $result) {
$result $result
->setTokenType(PhabricatorTypeaheadTokenView::TYPE_FUNCTION) ->setTokenType(PhabricatorTypeaheadTokenView::TYPE_FUNCTION)
->setIcon('fa-briefcase') ->setIcon('fa-asterisk')
->setPHID('projects('.$result->getPHID().')') ->setPHID('projects('.$result->getPHID().')')
->setDisplayName(pht('Projects: %s', $result->getDisplayName())) ->setDisplayName(pht("User's Projects: %s", $result->getDisplayName()))
->setName($result->getName().' projects'); ->setName($result->getName().' projects');
} }
@ -44,20 +44,19 @@ final class PhabricatorUserProjectsDatasource
$phids[] = head($argv); $phids[] = head($argv);
} }
$projects = id(new PhabricatorPeopleQuery()) $projects = id(new PhabricatorProjectQuery())
->setViewer($this->getViewer()) ->setViewer($this->getViewer())
->needMembers(true) ->withMemberPHIDs($phids)
->withPHIDs($phids)
->execute(); ->execute();
$results = array(); $results = array();
foreach ($projects as $project) { foreach ($projects as $project) {
foreach ($project->getMemberPHIDs() as $phid) { $results[] = new PhabricatorQueryConstraint(
$results[$phid] = $phid; PhabricatorQueryConstraint::OPERATOR_OR,
} $project->getPHID());
} }
return array_values($results); return $results;
} }
public function renderFunctionTokens($function, array $argv_list) { public function renderFunctionTokens($function, array $argv_list) {
@ -70,13 +69,13 @@ final class PhabricatorUserProjectsDatasource
foreach ($tokens as $token) { foreach ($tokens as $token) {
if ($token->isInvalid()) { if ($token->isInvalid()) {
$token $token
->setValue(pht('Projects: Invalid User')); ->setValue(pht("User's Projects: Invalid User"));
} else { } else {
$token $token
->setIcon('fa-users') ->setIcon('fa-asterisk')
->setTokenType(PhabricatorTypeaheadTokenView::TYPE_FUNCTION) ->setTokenType(PhabricatorTypeaheadTokenView::TYPE_FUNCTION)
->setKey('projects('.$token->getKey().')') ->setKey('projects('.$token->getKey().')')
->setValue(pht('Projects: %s', $token->getValue())); ->setValue(pht("User's Projects: %s", $token->getValue()));
} }
} }

View file

@ -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);
}
}