mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 22:10:55 +01:00
Simplify members() datasource function
Summary: Ref T4100. Implement members() in terms of the real projects datasource. Test Plan: Used members() functions in Differential, browsed members() functions. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T4100 Differential Revision: https://secure.phabricator.com/D12459
This commit is contained in:
parent
c246aa2638
commit
eb69b115a7
3 changed files with 33 additions and 69 deletions
|
@ -5675,7 +5675,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorProjectIcon' => 'Phobject',
|
||||
'PhabricatorProjectListController' => 'PhabricatorProjectController',
|
||||
'PhabricatorProjectMemberOfProjectEdgeType' => 'PhabricatorEdgeType',
|
||||
'PhabricatorProjectMembersDatasource' => 'PhabricatorTypeaheadDatasource',
|
||||
'PhabricatorProjectMembersDatasource' => 'PhabricatorTypeaheadCompositeDatasource',
|
||||
'PhabricatorProjectMembersEditController' => 'PhabricatorProjectController',
|
||||
'PhabricatorProjectMembersRemoveController' => 'PhabricatorProjectController',
|
||||
'PhabricatorProjectMoveController' => 'PhabricatorProjectController',
|
||||
|
|
|
@ -73,6 +73,7 @@ final class PhabricatorUserProjectsDatasource
|
|||
->setValue(pht('Projects: Invalid User'));
|
||||
} else {
|
||||
$token
|
||||
->setIcon('fa-users')
|
||||
->setTokenType(PhabricatorTypeaheadTokenView::TYPE_FUNCTION)
|
||||
->setKey('projects('.$token->getKey().')')
|
||||
->setValue(pht('Projects: %s', $token->getValue()));
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorProjectMembersDatasource
|
||||
extends PhabricatorTypeaheadDatasource {
|
||||
extends PhabricatorTypeaheadCompositeDatasource {
|
||||
|
||||
public function getPlaceholderText() {
|
||||
return pht('Type members(<project>)...');
|
||||
|
@ -11,40 +11,33 @@ final class PhabricatorProjectMembersDatasource
|
|||
return 'PhabricatorProjectApplication';
|
||||
}
|
||||
|
||||
public function loadResults() {
|
||||
$viewer = $this->getViewer();
|
||||
$raw_query = $this->getRawQuery();
|
||||
|
||||
$pattern = $raw_query;
|
||||
if (self::isFunctionToken($raw_query)) {
|
||||
$function = $this->parseFunction($raw_query, $allow_partial = true);
|
||||
if ($function) {
|
||||
$pattern = head($function['argv']);
|
||||
}
|
||||
public function getComponentDatasources() {
|
||||
return array(
|
||||
new PhabricatorProjectDatasource(),
|
||||
);
|
||||
}
|
||||
|
||||
// Allow users to type "#qa" or "qa" to find "Quality Assurance".
|
||||
$pattern = ltrim($pattern, '#');
|
||||
$tokens = self::tokenizeString($pattern);
|
||||
|
||||
$query = $this->newQuery();
|
||||
if ($tokens) {
|
||||
$query->withNameTokens($tokens);
|
||||
public function getDatasourceFunctions() {
|
||||
return array(
|
||||
'members' => array(
|
||||
'name' => pht('Find results for members of a project.'),
|
||||
),
|
||||
);
|
||||
}
|
||||
$projects = $this->executeQuery($query);
|
||||
|
||||
$results = array();
|
||||
foreach ($projects as $project) {
|
||||
$results[] = $this->buildProjectResult($project);
|
||||
protected function didLoadResults(array $results) {
|
||||
foreach ($results as $result) {
|
||||
$result
|
||||
->setTokenType(PhabricatorTypeaheadTokenView::TYPE_FUNCTION)
|
||||
->setIcon('fa-users')
|
||||
->setPHID('members('.$result->getPHID().')')
|
||||
->setDisplayName(pht('Members: %s', $result->getDisplayName()))
|
||||
->setName($result->getName().' members');
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
protected function canEvaluateFunction($function) {
|
||||
return ($function == 'members');
|
||||
}
|
||||
|
||||
protected function evaluateFunction($function, array $argv_list) {
|
||||
$phids = array();
|
||||
foreach ($argv_list as $argv) {
|
||||
|
@ -73,51 +66,21 @@ final class PhabricatorProjectMembersDatasource
|
|||
$phids[] = head($argv);
|
||||
}
|
||||
|
||||
$projects = $this->newQuery()
|
||||
->withPHIDs($phids)
|
||||
->execute();
|
||||
$projects = mpull($projects, null, 'getPHID');
|
||||
|
||||
$tokens = array();
|
||||
foreach ($phids as $phid) {
|
||||
$project = idx($projects, $phid);
|
||||
if ($project) {
|
||||
$result = $this->buildProjectResult($project);
|
||||
$tokens[] = PhabricatorTypeaheadTokenView::newFromTypeaheadResult(
|
||||
$result);
|
||||
$tokens = $this->renderTokens($phids);
|
||||
foreach ($tokens as $token) {
|
||||
if ($token->isInvalid()) {
|
||||
$token
|
||||
->setValue(pht('Members: Invalid Project'));
|
||||
} else {
|
||||
$tokens[] = $this->newInvalidToken(pht('Members: Invalid Project'));
|
||||
$token
|
||||
->setIcon('fa-users')
|
||||
->setTokenType(PhabricatorTypeaheadTokenView::TYPE_FUNCTION)
|
||||
->setKey('members('.$token->getKey().')')
|
||||
->setValue(pht('Members: %s', $token->getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
return $tokens;
|
||||
}
|
||||
|
||||
private function newQuery() {
|
||||
return id(new PhabricatorProjectQuery())
|
||||
->setViewer($this->getViewer())
|
||||
->needImages(true)
|
||||
->needSlugs(true);
|
||||
}
|
||||
|
||||
private function buildProjectResult(PhabricatorProject $project) {
|
||||
$closed = null;
|
||||
if ($project->isArchived()) {
|
||||
$closed = pht('Archived');
|
||||
}
|
||||
|
||||
$all_strings = mpull($project->getSlugs(), 'getSlug');
|
||||
$all_strings[] = 'members';
|
||||
$all_strings[] = $project->getName();
|
||||
$all_strings = implode(' ', $all_strings);
|
||||
|
||||
return $this->newFunctionResult()
|
||||
->setName($all_strings)
|
||||
->setDisplayName(pht('Members: %s', $project->getName()))
|
||||
->setURI('/tag/'.$project->getPrimarySlug().'/')
|
||||
->setPHID('members('.$project->getPHID().')')
|
||||
->setIcon('fa-users')
|
||||
->setClosed($closed);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue