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

Support PhabricatorSpacesInterface in ApplicationSearch UI

Summary: Ref T8441. Does what it says, provided other conditions (like using the new SearchField stuff) are fulfilled.

Test Plan:
{F473836}

{F473837}

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T8441

Differential Revision: https://secure.phabricator.com/D13171
This commit is contained in:
epriestley 2015-06-05 11:21:45 -07:00
parent 65b891b095
commit b5dfd34e4a
7 changed files with 127 additions and 1 deletions

View file

@ -2525,6 +2525,7 @@ phutil_register_library_map(array(
'PhabricatorSearchRelationship' => 'applications/search/constants/PhabricatorSearchRelationship.php', 'PhabricatorSearchRelationship' => 'applications/search/constants/PhabricatorSearchRelationship.php',
'PhabricatorSearchResultView' => 'applications/search/view/PhabricatorSearchResultView.php', 'PhabricatorSearchResultView' => 'applications/search/view/PhabricatorSearchResultView.php',
'PhabricatorSearchSelectController' => 'applications/search/controller/PhabricatorSearchSelectController.php', 'PhabricatorSearchSelectController' => 'applications/search/controller/PhabricatorSearchSelectController.php',
'PhabricatorSearchSpacesField' => 'applications/search/field/PhabricatorSearchSpacesField.php',
'PhabricatorSearchStringListField' => 'applications/search/field/PhabricatorSearchStringListField.php', 'PhabricatorSearchStringListField' => 'applications/search/field/PhabricatorSearchStringListField.php',
'PhabricatorSearchTokenizerField' => 'applications/search/field/PhabricatorSearchTokenizerField.php', 'PhabricatorSearchTokenizerField' => 'applications/search/field/PhabricatorSearchTokenizerField.php',
'PhabricatorSearchUsersField' => 'applications/search/field/PhabricatorSearchUsersField.php', 'PhabricatorSearchUsersField' => 'applications/search/field/PhabricatorSearchUsersField.php',
@ -2578,6 +2579,7 @@ phutil_register_library_map(array(
'PhabricatorSpacesInterface' => 'applications/spaces/interface/PhabricatorSpacesInterface.php', 'PhabricatorSpacesInterface' => 'applications/spaces/interface/PhabricatorSpacesInterface.php',
'PhabricatorSpacesListController' => 'applications/spaces/controller/PhabricatorSpacesListController.php', 'PhabricatorSpacesListController' => 'applications/spaces/controller/PhabricatorSpacesListController.php',
'PhabricatorSpacesNamespace' => 'applications/spaces/storage/PhabricatorSpacesNamespace.php', 'PhabricatorSpacesNamespace' => 'applications/spaces/storage/PhabricatorSpacesNamespace.php',
'PhabricatorSpacesNamespaceDatasource' => 'applications/spaces/typeahead/PhabricatorSpacesNamespaceDatasource.php',
'PhabricatorSpacesNamespaceEditor' => 'applications/spaces/editor/PhabricatorSpacesNamespaceEditor.php', 'PhabricatorSpacesNamespaceEditor' => 'applications/spaces/editor/PhabricatorSpacesNamespaceEditor.php',
'PhabricatorSpacesNamespacePHIDType' => 'applications/spaces/phid/PhabricatorSpacesNamespacePHIDType.php', 'PhabricatorSpacesNamespacePHIDType' => 'applications/spaces/phid/PhabricatorSpacesNamespacePHIDType.php',
'PhabricatorSpacesNamespaceQuery' => 'applications/spaces/query/PhabricatorSpacesNamespaceQuery.php', 'PhabricatorSpacesNamespaceQuery' => 'applications/spaces/query/PhabricatorSpacesNamespaceQuery.php',
@ -6020,6 +6022,7 @@ phutil_register_library_map(array(
'PhabricatorSearchPreferencesSettingsPanel' => 'PhabricatorSettingsPanel', 'PhabricatorSearchPreferencesSettingsPanel' => 'PhabricatorSettingsPanel',
'PhabricatorSearchResultView' => 'AphrontView', 'PhabricatorSearchResultView' => 'AphrontView',
'PhabricatorSearchSelectController' => 'PhabricatorSearchBaseController', 'PhabricatorSearchSelectController' => 'PhabricatorSearchBaseController',
'PhabricatorSearchSpacesField' => 'PhabricatorSearchTokenizerField',
'PhabricatorSearchStringListField' => 'PhabricatorSearchField', 'PhabricatorSearchStringListField' => 'PhabricatorSearchField',
'PhabricatorSearchTokenizerField' => 'PhabricatorSearchField', 'PhabricatorSearchTokenizerField' => 'PhabricatorSearchField',
'PhabricatorSearchUsersField' => 'PhabricatorSearchTokenizerField', 'PhabricatorSearchUsersField' => 'PhabricatorSearchTokenizerField',
@ -6083,6 +6086,7 @@ phutil_register_library_map(array(
'PhabricatorApplicationTransactionInterface', 'PhabricatorApplicationTransactionInterface',
'PhabricatorDestructibleInterface', 'PhabricatorDestructibleInterface',
), ),
'PhabricatorSpacesNamespaceDatasource' => 'PhabricatorTypeaheadDatasource',
'PhabricatorSpacesNamespaceEditor' => 'PhabricatorApplicationTransactionEditor', 'PhabricatorSpacesNamespaceEditor' => 'PhabricatorApplicationTransactionEditor',
'PhabricatorSpacesNamespacePHIDType' => 'PhabricatorPHIDType', 'PhabricatorSpacesNamespacePHIDType' => 'PhabricatorPHIDType',
'PhabricatorSpacesNamespaceQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhabricatorSpacesNamespaceQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',

View file

@ -11,6 +11,10 @@ final class PhabricatorPasteSearchEngine
return 'PhabricatorPasteApplication'; return 'PhabricatorPasteApplication';
} }
public function newResultObject() {
return new PhabricatorPaste();
}
public function buildQueryFromParameters(array $map) { public function buildQueryFromParameters(array $map) {
$query = id(new PhabricatorPasteQuery()) $query = id(new PhabricatorPasteQuery())
->needContent(true); ->needContent(true);

View file

@ -26,6 +26,10 @@ abstract class PhabricatorApplicationSearchEngine extends Phobject {
const CONTEXT_LIST = 'list'; const CONTEXT_LIST = 'list';
const CONTEXT_PANEL = 'panel'; const CONTEXT_PANEL = 'panel';
public function newResultObject() {
return null;
}
public function setViewer(PhabricatorUser $viewer) { public function setViewer(PhabricatorUser $viewer) {
$this->viewer = $viewer; $this->viewer = $viewer;
return $this; return $this;
@ -102,7 +106,20 @@ abstract class PhabricatorApplicationSearchEngine extends Phobject {
$parameters[$field->getKey()] = $value; $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) { protected function buildQueryFromParameters(array $parameters) {
@ -146,6 +163,20 @@ abstract class PhabricatorApplicationSearchEngine extends Phobject {
$fields[] = $field; $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; return $fields;
} }
@ -893,6 +924,10 @@ abstract class PhabricatorApplicationSearchEngine extends Phobject {
* @task appsearch * @task appsearch
*/ */
public function getCustomFieldObject() { public function getCustomFieldObject() {
$object = $this->newResultObject();
if ($object instanceof PhabricatorCustomFieldInterface) {
return $object;
}
return null; return null;
} }

View file

@ -0,0 +1,43 @@
<?php
final class PhabricatorSearchSpacesField
extends PhabricatorSearchTokenizerField {
protected function getDefaultValue() {
return array();
}
protected function newDatasource() {
return new PhabricatorSpacesNamespaceDatasource();
}
protected function getValueFromRequest(AphrontRequest $request, $key) {
$viewer = $this->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;
}
}

View file

@ -9,6 +9,10 @@ final class PhabricatorSpacesNamespacePHIDType
return pht('Space'); return pht('Space');
} }
public function getPHIDTypeApplicationClass() {
return 'PhabricatorSpacesApplication';
}
public function newObject() { public function newObject() {
return new PhabricatorSpacesNamespace(); return new PhabricatorSpacesNamespace();
} }

View file

@ -86,6 +86,10 @@ final class PhabricatorSpacesNamespaceQuery
)); ));
} }
public static function getSpacesExist() {
return (bool)self::getAllSpaces();
}
public static function getAllSpaces() { public static function getAllSpaces() {
$cache = PhabricatorCaches::getRequestCache(); $cache = PhabricatorCaches::getRequestCache();
$cache_key = self::KEY_ALL; $cache_key = self::KEY_ALL;

View file

@ -0,0 +1,32 @@
<?php
final class PhabricatorSpacesNamespaceDatasource
extends PhabricatorTypeaheadDatasource {
public function getBrowseTitle() {
return pht('Browse Spaces');
}
public function getPlaceholderText() {
return pht('Type a space name...');
}
public function getDatasourceApplicationClass() {
return 'PhabricatorSpacesApplication';
}
public function loadResults() {
$query = id(new PhabricatorSpacesNamespaceQuery());
$spaces = $this->executeQuery($query);
$results = array();
foreach ($spaces as $space) {
$results[] = id(new PhabricatorTypeaheadResult())
->setName($space->getNamespaceName())
->setPHID($space->getPHID());
}
return $this->filterResultsAgainstTokens($results);
}
}