diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index d660977e49..b35bc03a52 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -2525,6 +2525,7 @@ phutil_register_library_map(array( 'PhabricatorSearchRelationship' => 'applications/search/constants/PhabricatorSearchRelationship.php', 'PhabricatorSearchResultView' => 'applications/search/view/PhabricatorSearchResultView.php', 'PhabricatorSearchSelectController' => 'applications/search/controller/PhabricatorSearchSelectController.php', + 'PhabricatorSearchSpacesField' => 'applications/search/field/PhabricatorSearchSpacesField.php', 'PhabricatorSearchStringListField' => 'applications/search/field/PhabricatorSearchStringListField.php', 'PhabricatorSearchTokenizerField' => 'applications/search/field/PhabricatorSearchTokenizerField.php', 'PhabricatorSearchUsersField' => 'applications/search/field/PhabricatorSearchUsersField.php', @@ -2578,6 +2579,7 @@ phutil_register_library_map(array( 'PhabricatorSpacesInterface' => 'applications/spaces/interface/PhabricatorSpacesInterface.php', 'PhabricatorSpacesListController' => 'applications/spaces/controller/PhabricatorSpacesListController.php', 'PhabricatorSpacesNamespace' => 'applications/spaces/storage/PhabricatorSpacesNamespace.php', + 'PhabricatorSpacesNamespaceDatasource' => 'applications/spaces/typeahead/PhabricatorSpacesNamespaceDatasource.php', 'PhabricatorSpacesNamespaceEditor' => 'applications/spaces/editor/PhabricatorSpacesNamespaceEditor.php', 'PhabricatorSpacesNamespacePHIDType' => 'applications/spaces/phid/PhabricatorSpacesNamespacePHIDType.php', 'PhabricatorSpacesNamespaceQuery' => 'applications/spaces/query/PhabricatorSpacesNamespaceQuery.php', @@ -6020,6 +6022,7 @@ phutil_register_library_map(array( 'PhabricatorSearchPreferencesSettingsPanel' => 'PhabricatorSettingsPanel', 'PhabricatorSearchResultView' => 'AphrontView', 'PhabricatorSearchSelectController' => 'PhabricatorSearchBaseController', + 'PhabricatorSearchSpacesField' => 'PhabricatorSearchTokenizerField', 'PhabricatorSearchStringListField' => 'PhabricatorSearchField', 'PhabricatorSearchTokenizerField' => 'PhabricatorSearchField', 'PhabricatorSearchUsersField' => 'PhabricatorSearchTokenizerField', @@ -6083,6 +6086,7 @@ phutil_register_library_map(array( 'PhabricatorApplicationTransactionInterface', 'PhabricatorDestructibleInterface', ), + 'PhabricatorSpacesNamespaceDatasource' => 'PhabricatorTypeaheadDatasource', 'PhabricatorSpacesNamespaceEditor' => 'PhabricatorApplicationTransactionEditor', 'PhabricatorSpacesNamespacePHIDType' => 'PhabricatorPHIDType', 'PhabricatorSpacesNamespaceQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', diff --git a/src/applications/paste/query/PhabricatorPasteSearchEngine.php b/src/applications/paste/query/PhabricatorPasteSearchEngine.php index bbc01164b7..2d69d441fa 100644 --- a/src/applications/paste/query/PhabricatorPasteSearchEngine.php +++ b/src/applications/paste/query/PhabricatorPasteSearchEngine.php @@ -11,6 +11,10 @@ final class PhabricatorPasteSearchEngine return 'PhabricatorPasteApplication'; } + public function newResultObject() { + return new PhabricatorPaste(); + } + public function buildQueryFromParameters(array $map) { $query = id(new PhabricatorPasteQuery()) ->needContent(true); diff --git a/src/applications/search/engine/PhabricatorApplicationSearchEngine.php b/src/applications/search/engine/PhabricatorApplicationSearchEngine.php index 1f2c7a3b45..d83f1ed85f 100644 --- a/src/applications/search/engine/PhabricatorApplicationSearchEngine.php +++ b/src/applications/search/engine/PhabricatorApplicationSearchEngine.php @@ -26,6 +26,10 @@ abstract class PhabricatorApplicationSearchEngine extends Phobject { const CONTEXT_LIST = 'list'; const CONTEXT_PANEL = 'panel'; + public function newResultObject() { + return null; + } + public function setViewer(PhabricatorUser $viewer) { $this->viewer = $viewer; return $this; @@ -102,7 +106,20 @@ abstract class PhabricatorApplicationSearchEngine extends Phobject { $parameters[$field->getKey()] = $value; } - return $this->buildQueryFromParameters($parameters); + $query = $this->buildQueryFromParameters($parameters); + + $object = $this->newResultObject(); + if (!$object) { + return $query; + } + + if ($object instanceof PhabricatorSpacesInterface) { + if (!empty($parameters['spacePHIDs'])) { + $query->withSpacePHIDs($parameters['spacePHIDs']); + } + } + + return $query; } protected function buildQueryFromParameters(array $parameters) { @@ -146,6 +163,20 @@ abstract class PhabricatorApplicationSearchEngine extends Phobject { $fields[] = $field; } + $object = $this->newResultObject(); + if (!$object) { + return $fields; + } + + if ($object instanceof PhabricatorSpacesInterface) { + if (PhabricatorSpacesNamespaceQuery::getSpacesExist()) { + $fields[] = id(new PhabricatorSearchSpacesField()) + ->setKey('spacePHIDs') + ->setAliases(array('space', 'spaces')) + ->setLabel(pht('Spaces')); + } + } + return $fields; } @@ -893,6 +924,10 @@ abstract class PhabricatorApplicationSearchEngine extends Phobject { * @task appsearch */ public function getCustomFieldObject() { + $object = $this->newResultObject(); + if ($object instanceof PhabricatorCustomFieldInterface) { + return $object; + } return null; } diff --git a/src/applications/search/field/PhabricatorSearchSpacesField.php b/src/applications/search/field/PhabricatorSearchSpacesField.php new file mode 100644 index 0000000000..670e47db11 --- /dev/null +++ b/src/applications/search/field/PhabricatorSearchSpacesField.php @@ -0,0 +1,43 @@ +getViewer(); + $list = $this->getListFromRequest($request, $key); + + $type = new PhabricatorSpacesNamespacePHIDType(); + $phids = array(); + $names = array(); + foreach ($list as $item) { + if ($type->canLoadNamedObject($item)) { + $names[] = $item; + } else { + $phids[] = $item; + } + } + + if ($names) { + $spaces = id(new PhabricatorObjectQuery()) + ->setViewer($viewer) + ->withNames($names) + ->execute(); + foreach (mpull($spaces, 'getPHID') as $phid) { + $phids[] = $phid; + } + $phids = array_unique($phids); + } + + return $phids; + } + +} diff --git a/src/applications/spaces/phid/PhabricatorSpacesNamespacePHIDType.php b/src/applications/spaces/phid/PhabricatorSpacesNamespacePHIDType.php index ad7fd05130..22dfcffac4 100644 --- a/src/applications/spaces/phid/PhabricatorSpacesNamespacePHIDType.php +++ b/src/applications/spaces/phid/PhabricatorSpacesNamespacePHIDType.php @@ -9,6 +9,10 @@ final class PhabricatorSpacesNamespacePHIDType return pht('Space'); } + public function getPHIDTypeApplicationClass() { + return 'PhabricatorSpacesApplication'; + } + public function newObject() { return new PhabricatorSpacesNamespace(); } diff --git a/src/applications/spaces/query/PhabricatorSpacesNamespaceQuery.php b/src/applications/spaces/query/PhabricatorSpacesNamespaceQuery.php index 815a18b927..6280136de4 100644 --- a/src/applications/spaces/query/PhabricatorSpacesNamespaceQuery.php +++ b/src/applications/spaces/query/PhabricatorSpacesNamespaceQuery.php @@ -86,6 +86,10 @@ final class PhabricatorSpacesNamespaceQuery )); } + public static function getSpacesExist() { + return (bool)self::getAllSpaces(); + } + public static function getAllSpaces() { $cache = PhabricatorCaches::getRequestCache(); $cache_key = self::KEY_ALL; diff --git a/src/applications/spaces/typeahead/PhabricatorSpacesNamespaceDatasource.php b/src/applications/spaces/typeahead/PhabricatorSpacesNamespaceDatasource.php new file mode 100644 index 0000000000..046e3b0f4f --- /dev/null +++ b/src/applications/spaces/typeahead/PhabricatorSpacesNamespaceDatasource.php @@ -0,0 +1,32 @@ +executeQuery($query); + $results = array(); + foreach ($spaces as $space) { + $results[] = id(new PhabricatorTypeaheadResult()) + ->setName($space->getNamespaceName()) + ->setPHID($space->getPHID()); + } + + return $this->filterResultsAgainstTokens($results); + } + +}