1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-25 23:10:57 +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',
'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',

View file

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

View file

@ -1,6 +1,6 @@
<?php
final class PhabricatorUserProjectsDatasource
final class PhabricatorProjectLogicalUserDatasource
extends PhabricatorTypeaheadCompositeDatasource {
public function getPlaceholderText() {
@ -29,9 +29,9 @@ final class PhabricatorUserProjectsDatasource
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 @@ 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()));
}
}

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