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

Refine global search UI for tokenizer functions

Summary:
Ref T4100.

  - Removes the "with unowned" checkbox in favor of the "no owners" function.
  - Support functions in "Authors" and "Owners".

Test Plan:
  - Ran various global search and Maniphest queries.

{F379931}

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T4100

Differential Revision: https://secure.phabricator.com/D12523
This commit is contained in:
epriestley 2015-04-23 03:07:24 -07:00
parent 91714568f5
commit 135c8799e6
9 changed files with 61 additions and 34 deletions

View file

@ -1033,8 +1033,6 @@ phutil_register_library_map(array(
'ManiphestInfoConduitAPIMethod' => 'applications/maniphest/conduit/ManiphestInfoConduitAPIMethod.php',
'ManiphestNameIndex' => 'applications/maniphest/storage/ManiphestNameIndex.php',
'ManiphestNameIndexEventListener' => 'applications/maniphest/event/ManiphestNameIndexEventListener.php',
'ManiphestNoOwnerDatasource' => 'applications/maniphest/typeahead/ManiphestNoOwnerDatasource.php',
'ManiphestOwnerDatasource' => 'applications/maniphest/typeahead/ManiphestOwnerDatasource.php',
'ManiphestPriorityEmailCommand' => 'applications/maniphest/command/ManiphestPriorityEmailCommand.php',
'ManiphestQueryConduitAPIMethod' => 'applications/maniphest/conduit/ManiphestQueryConduitAPIMethod.php',
'ManiphestQueryStatusesConduitAPIMethod' => 'applications/maniphest/conduit/ManiphestQueryStatusesConduitAPIMethod.php',
@ -2207,6 +2205,8 @@ phutil_register_library_map(array(
'PhabricatorPeopleLogSearchEngine' => 'applications/people/query/PhabricatorPeopleLogSearchEngine.php',
'PhabricatorPeopleLogsController' => 'applications/people/controller/PhabricatorPeopleLogsController.php',
'PhabricatorPeopleNewController' => 'applications/people/controller/PhabricatorPeopleNewController.php',
'PhabricatorPeopleNoOwnerDatasource' => 'applications/people/typeahead/PhabricatorPeopleNoOwnerDatasource.php',
'PhabricatorPeopleOwnerDatasource' => 'applications/people/typeahead/PhabricatorPeopleOwnerDatasource.php',
'PhabricatorPeopleProfileController' => 'applications/people/controller/PhabricatorPeopleProfileController.php',
'PhabricatorPeopleProfileEditController' => 'applications/people/controller/PhabricatorPeopleProfileEditController.php',
'PhabricatorPeopleProfilePictureController' => 'applications/people/controller/PhabricatorPeopleProfilePictureController.php',
@ -4309,8 +4309,6 @@ phutil_register_library_map(array(
'ManiphestInfoConduitAPIMethod' => 'ManiphestConduitAPIMethod',
'ManiphestNameIndex' => 'ManiphestDAO',
'ManiphestNameIndexEventListener' => 'PhabricatorEventListener',
'ManiphestNoOwnerDatasource' => 'PhabricatorTypeaheadDatasource',
'ManiphestOwnerDatasource' => 'PhabricatorTypeaheadCompositeDatasource',
'ManiphestPriorityEmailCommand' => 'ManiphestEmailCommand',
'ManiphestQueryConduitAPIMethod' => 'ManiphestConduitAPIMethod',
'ManiphestQueryStatusesConduitAPIMethod' => 'ManiphestConduitAPIMethod',
@ -5575,6 +5573,8 @@ phutil_register_library_map(array(
'PhabricatorPeopleLogSearchEngine' => 'PhabricatorApplicationSearchEngine',
'PhabricatorPeopleLogsController' => 'PhabricatorPeopleController',
'PhabricatorPeopleNewController' => 'PhabricatorPeopleController',
'PhabricatorPeopleNoOwnerDatasource' => 'PhabricatorTypeaheadDatasource',
'PhabricatorPeopleOwnerDatasource' => 'PhabricatorTypeaheadCompositeDatasource',
'PhabricatorPeopleProfileController' => 'PhabricatorPeopleController',
'PhabricatorPeopleProfileEditController' => 'PhabricatorPeopleController',
'PhabricatorPeopleProfilePictureController' => 'PhabricatorPeopleController',

View file

@ -265,8 +265,8 @@ final class ManiphestBatchEditController extends ManiphestController {
continue 2;
}
$value = head($value);
$no_owner = ManiphestNoOwnerDatasource::FUNCTION_TOKEN;
if ($value === ManiphestNoOwnerDatasource::FUNCTION_TOKEN) {
$no_owner = PhabricatorPeopleNoOwnerDatasource::FUNCTION_TOKEN;
if ($value === $no_owner) {
$value = null;
}
break;

View file

@ -75,7 +75,7 @@ final class ManiphestTaskQuery extends PhabricatorCursorPagedPolicyAwareQuery {
}
public function withOwners(array $owners) {
$no_owner = ManiphestNoOwnerDatasource::FUNCTION_TOKEN;
$no_owner = PhabricatorPeopleNoOwnerDatasource::FUNCTION_TOKEN;
$this->includeUnowned = false;
foreach ($owners as $k => $phid) {

View file

@ -137,7 +137,7 @@ final class ManiphestTaskSearchEngine
$query->withSubscribers($subscriber_phids);
}
$datasource = id(new ManiphestOwnerDatasource())
$datasource = id(new PhabricatorPeopleOwnerDatasource())
->setViewer($this->requireViewer());
$assigned_phids = $this->readAssignedPHIDs($saved);
@ -311,7 +311,7 @@ final class ManiphestTaskSearchEngine
$form
->appendControl(
id(new AphrontFormTokenizerControl())
->setDatasource(new ManiphestOwnerDatasource())
->setDatasource(new PhabricatorPeopleOwnerDatasource())
->setName('assigned')
->setLabel(pht('Assigned To'))
->setValue($assigned_phids))
@ -560,7 +560,7 @@ final class ManiphestTaskSearchEngine
// typeaheads, and is retained for compatibility. We could remove it by
// migrating old saved queries.
if ($saved->getParameter('withUnassigned')) {
$assigned_phids[] = ManiphestNoOwnerDatasource::FUNCTION_TOKEN;
$assigned_phids[] = PhabricatorPeopleNoOwnerDatasource::FUNCTION_TOKEN;
}
return $assigned_phids;

View file

@ -14,7 +14,7 @@ final class ManiphestAssigneeDatasource
public function getComponentDatasources() {
return array(
new PhabricatorPeopleDatasource(),
new ManiphestNoOwnerDatasource(),
new PhabricatorPeopleNoOwnerDatasource(),
);
}

View file

@ -1,6 +1,6 @@
<?php
final class ManiphestNoOwnerDatasource
final class PhabricatorPeopleNoOwnerDatasource
extends PhabricatorTypeaheadDatasource {
const FUNCTION_TOKEN = 'none()';
@ -14,7 +14,7 @@ final class ManiphestNoOwnerDatasource
}
public function getDatasourceApplicationClass() {
return 'PhabricatorManiphestApplication';
return 'PhabricatorPeopleApplication';
}
public function getDatasourceFunctions() {

View file

@ -1,6 +1,6 @@
<?php
final class ManiphestOwnerDatasource
final class PhabricatorPeopleOwnerDatasource
extends PhabricatorTypeaheadCompositeDatasource {
public function getBrowseTitle() {
@ -14,7 +14,7 @@ final class ManiphestOwnerDatasource
public function getComponentDatasources() {
return array(
new PhabricatorViewerDatasource(),
new ManiphestNoOwnerDatasource(),
new PhabricatorPeopleNoOwnerDatasource(),
new PhabricatorPeopleDatasource(),
new PhabricatorProjectMembersDatasource(),
);

View file

@ -79,6 +79,9 @@ final class PhabricatorProjectMembersDatasource
$tokens = $this->renderTokens($phids);
foreach ($tokens as $token) {
// Remove any project color on this token.
$token->setColor(null);
if ($token->isInvalid()) {
$token
->setValue(pht('Members: Invalid Project'));

View file

@ -30,10 +30,6 @@ final class PhabricatorSearchApplicationSearchEngine
'ownerPHIDs',
$this->readUsersFromRequest($request, 'ownerPHIDs'));
$saved->setParameter(
'withUnowned',
$this->readBoolFromRequest($request, 'withUnowned'));
$saved->setParameter(
'subscriberPHIDs',
$this->readPHIDsFromRequest($request, 'subscriberPHIDs'));
@ -46,8 +42,34 @@ final class PhabricatorSearchApplicationSearchEngine
}
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
$query = id(new PhabricatorSearchDocumentQuery())
->withSavedQuery($saved);
$query = new PhabricatorSearchDocumentQuery();
// Convert the saved query into a resolved form (without typeahead
// functions) which the fulltext search engines can execute.
$config = clone $saved;
$viewer = $this->requireViewer();
$datasource = id(new PhabricatorPeopleOwnerDatasource())
->setViewer($viewer);
$owner_phids = $this->readOwnerPHIDs($config);
$owner_phids = $datasource->evaluateTokens($owner_phids);
foreach ($owner_phids as $key => $phid) {
if ($phid == PhabricatorPeopleNoOwnerDatasource::FUNCTION_TOKEN) {
$config->setParameter('withUnowned', true);
unset($owner_phids[$key]);
}
}
$config->setParameter('ownerPHIDs', $owner_phids);
$datasource = id(new PhabricatorTypeaheadUserParameterizedDatasource())
->setViewer($viewer);
$author_phids = $config->getParameter('authorPHIDs', array());
$author_phids = $datasource->evaluateTokens($author_phids);
$config->setParameter('authorPHIDs', $author_phids);
$query->withSavedQuery($config);
return $query;
}
@ -62,12 +84,10 @@ final class PhabricatorSearchApplicationSearchEngine
$project_value = null;
$author_phids = $saved->getParameter('authorPHIDs', array());
$owner_phids = $saved->getParameter('ownerPHIDs', array());
$owner_phids = $this->readOwnerPHIDs($saved);
$subscriber_phids = $saved->getParameter('subscriberPHIDs', array());
$project_phids = $saved->getParameter('projectPHIDs', array());
$with_unowned = $saved->getParameter('withUnowned', array());
$status_values = $saved->getParameter('statuses', array());
$status_values = array_fuse($status_values);
@ -114,26 +134,19 @@ final class PhabricatorSearchApplicationSearchEngine
id(new AphrontFormTokenizerControl())
->setName('authorPHIDs')
->setLabel('Authors')
->setDatasource(new PhabricatorPeopleDatasource())
->setDatasource(new PhabricatorTypeaheadUserParameterizedDatasource())
->setValue($author_phids))
->appendControl(
id(new AphrontFormTokenizerControl())
->setName('ownerPHIDs')
->setLabel('Owners')
->setDatasource(new ManiphestOwnerDatasource())
->setDatasource(new PhabricatorPeopleOwnerDatasource())
->setValue($owner_phids))
->appendChild(
id(new AphrontFormCheckboxControl())
->addCheckbox(
'withUnowned',
1,
pht('Show only unowned documents.'),
$with_unowned))
->appendControl(
id(new AphrontFormTokenizerControl())
->setName('subscriberPHIDs')
->setLabel('Subscribers')
->setDatasource(new PhabricatorPeopleDatasource())
->setDatasource(new PhabricatorMetaMTAMailableDatasource())
->setValue($subscriber_phids))
->appendControl(
id(new AphrontFormTokenizerControl())
@ -242,4 +255,15 @@ final class PhabricatorSearchApplicationSearchEngine
return $results;
}
private function readOwnerPHIDs(PhabricatorSavedQuery $saved) {
$owner_phids = $saved->getParameter('ownerPHIDs', array());
// This was an old checkbox from before typeahead functions.
if ($saved->getParameter('withUnowned')) {
$owner_phids[] = PhabricatorPeopleNoOwnerDatasource::FUNCTION_TOKEN;
}
return $owner_phids;
}
}