1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-25 06:50:55 +01:00

Modernize global search typeahead datasource

Summary: Ref T4420. Bring the global search up to date.

Test Plan: Typed various things into global search.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T4420

Differential Revision: https://secure.phabricator.com/D9889
This commit is contained in:
epriestley 2014-07-17 15:48:36 -07:00
parent cab442fe8c
commit 0a3a3eae00
7 changed files with 142 additions and 95 deletions

View file

@ -592,6 +592,7 @@ phutil_register_library_map(array(
'DiffusionSvnRawDiffQuery' => 'applications/diffusion/query/rawdiff/DiffusionSvnRawDiffQuery.php', 'DiffusionSvnRawDiffQuery' => 'applications/diffusion/query/rawdiff/DiffusionSvnRawDiffQuery.php',
'DiffusionSvnRequest' => 'applications/diffusion/request/DiffusionSvnRequest.php', 'DiffusionSvnRequest' => 'applications/diffusion/request/DiffusionSvnRequest.php',
'DiffusionSymbolController' => 'applications/diffusion/controller/DiffusionSymbolController.php', 'DiffusionSymbolController' => 'applications/diffusion/controller/DiffusionSymbolController.php',
'DiffusionSymbolDatasource' => 'applications/diffusion/typeahead/DiffusionSymbolDatasource.php',
'DiffusionSymbolQuery' => 'applications/diffusion/query/DiffusionSymbolQuery.php', 'DiffusionSymbolQuery' => 'applications/diffusion/query/DiffusionSymbolQuery.php',
'DiffusionTagListController' => 'applications/diffusion/controller/DiffusionTagListController.php', 'DiffusionTagListController' => 'applications/diffusion/controller/DiffusionTagListController.php',
'DiffusionTagListView' => 'applications/diffusion/view/DiffusionTagListView.php', 'DiffusionTagListView' => 'applications/diffusion/view/DiffusionTagListView.php',
@ -1150,6 +1151,7 @@ phutil_register_library_map(array(
'PhabricatorApplicationCountdown' => 'applications/countdown/application/PhabricatorApplicationCountdown.php', 'PhabricatorApplicationCountdown' => 'applications/countdown/application/PhabricatorApplicationCountdown.php',
'PhabricatorApplicationDaemons' => 'applications/daemon/application/PhabricatorApplicationDaemons.php', 'PhabricatorApplicationDaemons' => 'applications/daemon/application/PhabricatorApplicationDaemons.php',
'PhabricatorApplicationDashboard' => 'applications/dashboard/application/PhabricatorApplicationDashboard.php', 'PhabricatorApplicationDashboard' => 'applications/dashboard/application/PhabricatorApplicationDashboard.php',
'PhabricatorApplicationDatasource' => 'applications/meta/typeahead/PhabricatorApplicationDatasource.php',
'PhabricatorApplicationDetailViewController' => 'applications/meta/controller/PhabricatorApplicationDetailViewController.php', 'PhabricatorApplicationDetailViewController' => 'applications/meta/controller/PhabricatorApplicationDetailViewController.php',
'PhabricatorApplicationDifferential' => 'applications/differential/application/PhabricatorApplicationDifferential.php', 'PhabricatorApplicationDifferential' => 'applications/differential/application/PhabricatorApplicationDifferential.php',
'PhabricatorApplicationDiffusion' => 'applications/diffusion/application/PhabricatorApplicationDiffusion.php', 'PhabricatorApplicationDiffusion' => 'applications/diffusion/application/PhabricatorApplicationDiffusion.php',
@ -2157,6 +2159,7 @@ phutil_register_library_map(array(
'PhabricatorSearchConfigOptions' => 'applications/search/config/PhabricatorSearchConfigOptions.php', 'PhabricatorSearchConfigOptions' => 'applications/search/config/PhabricatorSearchConfigOptions.php',
'PhabricatorSearchController' => 'applications/search/controller/PhabricatorSearchController.php', 'PhabricatorSearchController' => 'applications/search/controller/PhabricatorSearchController.php',
'PhabricatorSearchDAO' => 'applications/search/storage/PhabricatorSearchDAO.php', 'PhabricatorSearchDAO' => 'applications/search/storage/PhabricatorSearchDAO.php',
'PhabricatorSearchDatasource' => 'applications/search/typeahead/PhabricatorSearchDatasource.php',
'PhabricatorSearchDeleteController' => 'applications/search/controller/PhabricatorSearchDeleteController.php', 'PhabricatorSearchDeleteController' => 'applications/search/controller/PhabricatorSearchDeleteController.php',
'PhabricatorSearchDocument' => 'applications/search/storage/document/PhabricatorSearchDocument.php', 'PhabricatorSearchDocument' => 'applications/search/storage/document/PhabricatorSearchDocument.php',
'PhabricatorSearchDocumentField' => 'applications/search/storage/document/PhabricatorSearchDocumentField.php', 'PhabricatorSearchDocumentField' => 'applications/search/storage/document/PhabricatorSearchDocumentField.php',
@ -3301,6 +3304,7 @@ phutil_register_library_map(array(
'DiffusionSvnRawDiffQuery' => 'DiffusionRawDiffQuery', 'DiffusionSvnRawDiffQuery' => 'DiffusionRawDiffQuery',
'DiffusionSvnRequest' => 'DiffusionRequest', 'DiffusionSvnRequest' => 'DiffusionRequest',
'DiffusionSymbolController' => 'DiffusionController', 'DiffusionSymbolController' => 'DiffusionController',
'DiffusionSymbolDatasource' => 'PhabricatorTypeaheadDatasource',
'DiffusionSymbolQuery' => 'PhabricatorOffsetPagedQuery', 'DiffusionSymbolQuery' => 'PhabricatorOffsetPagedQuery',
'DiffusionTagListController' => 'DiffusionController', 'DiffusionTagListController' => 'DiffusionController',
'DiffusionTagListView' => 'DiffusionView', 'DiffusionTagListView' => 'DiffusionView',
@ -3924,6 +3928,7 @@ phutil_register_library_map(array(
'PhabricatorApplicationCountdown' => 'PhabricatorApplication', 'PhabricatorApplicationCountdown' => 'PhabricatorApplication',
'PhabricatorApplicationDaemons' => 'PhabricatorApplication', 'PhabricatorApplicationDaemons' => 'PhabricatorApplication',
'PhabricatorApplicationDashboard' => 'PhabricatorApplication', 'PhabricatorApplicationDashboard' => 'PhabricatorApplication',
'PhabricatorApplicationDatasource' => 'PhabricatorTypeaheadDatasource',
'PhabricatorApplicationDetailViewController' => 'PhabricatorApplicationsController', 'PhabricatorApplicationDetailViewController' => 'PhabricatorApplicationsController',
'PhabricatorApplicationDifferential' => 'PhabricatorApplication', 'PhabricatorApplicationDifferential' => 'PhabricatorApplication',
'PhabricatorApplicationDiffusion' => 'PhabricatorApplication', 'PhabricatorApplicationDiffusion' => 'PhabricatorApplication',
@ -5004,6 +5009,7 @@ phutil_register_library_map(array(
'PhabricatorSearchConfigOptions' => 'PhabricatorApplicationConfigOptions', 'PhabricatorSearchConfigOptions' => 'PhabricatorApplicationConfigOptions',
'PhabricatorSearchController' => 'PhabricatorSearchBaseController', 'PhabricatorSearchController' => 'PhabricatorSearchBaseController',
'PhabricatorSearchDAO' => 'PhabricatorLiskDAO', 'PhabricatorSearchDAO' => 'PhabricatorLiskDAO',
'PhabricatorSearchDatasource' => 'PhabricatorTypeaheadCompositeDatasource',
'PhabricatorSearchDeleteController' => 'PhabricatorSearchBaseController', 'PhabricatorSearchDeleteController' => 'PhabricatorSearchBaseController',
'PhabricatorSearchDocument' => 'PhabricatorSearchDAO', 'PhabricatorSearchDocument' => 'PhabricatorSearchDAO',
'PhabricatorSearchDocumentField' => 'PhabricatorSearchDAO', 'PhabricatorSearchDocumentField' => 'PhabricatorSearchDAO',

View file

@ -0,0 +1,47 @@
<?php
final class DiffusionSymbolDatasource
extends PhabricatorTypeaheadDatasource {
public function getPlaceholderText() {
return pht('Type a symbol name...');
}
public function getDatasourceApplicationClass() {
return 'PhabricatorApplicationDiffusion';
}
public function loadResults() {
$viewer = $this->getViewer();
$raw_query = $this->getRawQuery();
$results = array();
if (strlen($raw_query)) {
$symbols = id(new DiffusionSymbolQuery())
->setNamePrefix($raw_query)
->setLimit(15)
->needArcanistProjects(true)
->needRepositories(true)
->needPaths(true)
->execute();
foreach ($symbols as $symbol) {
$lang = $symbol->getSymbolLanguage();
$name = $symbol->getSymbolName();
$type = $symbol->getSymbolType();
$proj = $symbol->getArcanistProject()->getName();
$results[] = id(new PhabricatorTypeaheadResult())
->setName($name)
->setURI($symbol->getURI())
->setPHID(md5($symbol->getURI())) // Just needs to be unique.
->setDisplayName($name)
->setDisplayType(strtoupper($lang).' '.ucwords($type).' ('.$proj.')')
->setPriorityType('symb');
}
}
return $results;
}
}

View file

@ -0,0 +1,43 @@
<?php
final class PhabricatorApplicationDatasource
extends PhabricatorTypeaheadDatasource {
public function getPlaceholderText() {
return pht('Type an application name...');
}
public function getDatasourceApplicationClass() {
return 'PhabricatorApplicationApplications';
}
public function loadResults() {
$viewer = $this->getViewer();
$raw_query = $this->getRawQuery();
$results = array();
$applications = PhabricatorApplication::getAllInstalledApplications();
foreach ($applications as $application) {
$uri = $application->getTypeaheadURI();
if (!$uri) {
continue;
}
$name = $application->getName().' '.$application->getShortDescription();
$img = 'apps-'.$application->getIconName().'-dark-large';
$results[] = id(new PhabricatorTypeaheadResult())
->setName($name)
->setURI($uri)
->setPHID($application->getPHID())
->setPriorityString($application->getName())
->setDisplayName($application->getName())
->setDisplayType($application->getShortDescription())
->setImageuRI($application->getIconURI())
->setPriorityType('apps')
->setImageSprite('phabricator-search-icon sprite-apps-large '.$img);
}
return $results;
}
}

View file

@ -3,6 +3,18 @@
final class PhabricatorPeopleDatasource final class PhabricatorPeopleDatasource
extends PhabricatorTypeaheadDatasource { extends PhabricatorTypeaheadDatasource {
private $enrichResults;
/**
* Controls enriched rendering, for global search. This is a bit hacky and
* should probably be handled in a more general way, but is fairly reasonable
* for now.
*/
public function setEnrichResults($enrich) {
$this->enrichResults = $enrich;
return $this;
}
public function getPlaceholderText() { public function getPlaceholderText() {
return pht('Type a username...'); return pht('Type a username...');
} }
@ -71,16 +83,14 @@ final class PhabricatorPeopleDatasource
} }
} }
// TODO: Restore this when mainsearch moves here. if ($this->enrichResults && $users) {
/*
if ($need_rich_data) {
$phids = mpull($users, 'getPHID'); $phids = mpull($users, 'getPHID');
$handles = $this->loadViewerHandles($phids); $handles = id(new PhabricatorHandleQuery())
->setViewer($viewer)
->withPHIDs($phids)
->execute();
} }
*/
foreach ($users as $user) { foreach ($users as $user) {
$closed = null; $closed = null;
if ($user->getIsDisabled()) { if ($user->getIsDisabled()) {
@ -98,10 +108,7 @@ final class PhabricatorPeopleDatasource
->setPriorityType('user') ->setPriorityType('user')
->setClosed($closed); ->setClosed($closed);
// TODO: Restore this too. if ($this->enrichResults) {
/*
if ($need_rich_data) {
$display_type = 'User'; $display_type = 'User';
if ($user->getIsAdmin()) { if ($user->getIsAdmin()) {
$display_type = 'Administrator'; $display_type = 'Administrator';
@ -110,8 +117,6 @@ final class PhabricatorPeopleDatasource
$result->setImageURI($handles[$user->getPHID()]->getImageURI()); $result->setImageURI($handles[$user->getPHID()]->getImageURI());
} }
*/
$results[] = $result; $results[] = $result;
} }

View file

@ -0,0 +1,24 @@
<?php
final class PhabricatorSearchDatasource
extends PhabricatorTypeaheadCompositeDatasource {
public function getPlaceholderText() {
return pht('Type an object name...');
}
public function getDatasourceApplicationClass() {
return 'PhabricatorApplicationSearch';
}
public function getComponentDatasources() {
return array(
id(new PhabricatorPeopleDatasource())->setEnrichResults(true),
new PhabricatorProjectDatasource(),
new PhabricatorApplicationDatasource(),
new PhabricatorTypeaheadMonogramDatasource(),
new DiffusionSymbolDatasource(),
);
}
}

View file

@ -19,24 +19,12 @@ final class PhabricatorTypeaheadCommonDatasourceController
$query = $request->getStr('q'); $query = $request->getStr('q');
$raw_query = $request->getStr('raw'); $raw_query = $request->getStr('raw');
$need_rich_data = false;
$need_users = false; $need_users = false;
$need_applications = false;
$need_projs = false; $need_projs = false;
$need_upforgrabs = false; $need_upforgrabs = false;
$need_noproject = false; $need_noproject = false;
$need_symbols = false; $need_rich_data = false;
$need_jump_objects = false;
switch ($this->type) { switch ($this->type) {
case 'mainsearch':
$need_users = true;
$need_applications = true;
$need_rich_data = true;
$need_symbols = true;
$need_projs = true;
$need_jump_objects = true;
break;
case 'searchowner': case 'searchowner':
$need_users = true; $need_users = true;
$need_upforgrabs = true; $need_upforgrabs = true;
@ -186,74 +174,6 @@ final class PhabricatorTypeaheadCommonDatasourceController
} }
} }
if ($need_applications) {
$applications = PhabricatorApplication::getAllInstalledApplications();
foreach ($applications as $application) {
$uri = $application->getTypeaheadURI();
if (!$uri) {
continue;
}
$name = $application->getName().' '.$application->getShortDescription();
$img = 'apps-'.$application->getIconName().'-dark-large';
$results[] = id(new PhabricatorTypeaheadResult())
->setName($name)
->setURI($uri)
->setPHID($application->getPHID())
->setPriorityString($application->getName())
->setDisplayName($application->getName())
->setDisplayType($application->getShortDescription())
->setImageuRI($application->getIconURI())
->setPriorityType('apps')
->setImageSprite('phabricator-search-icon sprite-apps-large '.$img);
}
}
if ($need_symbols) {
$symbols = id(new DiffusionSymbolQuery())
->setNamePrefix($query)
->setLimit(15)
->needArcanistProjects(true)
->needRepositories(true)
->needPaths(true)
->execute();
foreach ($symbols as $symbol) {
$lang = $symbol->getSymbolLanguage();
$name = $symbol->getSymbolName();
$type = $symbol->getSymbolType();
$proj = $symbol->getArcanistProject()->getName();
$results[] = id(new PhabricatorTypeaheadResult())
->setName($name)
->setURI($symbol->getURI())
->setPHID(md5($symbol->getURI())) // Just needs to be unique.
->setDisplayName($name)
->setDisplayType(strtoupper($lang).' '.ucwords($type).' ('.$proj.')')
->setPriorityType('symb');
}
}
if ($need_jump_objects) {
$objects = id(new PhabricatorObjectQuery())
->setViewer($viewer)
->withNames(array($raw_query))
->execute();
if ($objects) {
$handles = id(new PhabricatorHandleQuery())
->setViewer($viewer)
->withPHIDs(mpull($objects, 'getPHID'))
->execute();
$handle = head($handles);
if ($handle) {
$results[] = id(new PhabricatorTypeaheadResult())
->setName($handle->getFullName())
->setDisplayType($handle->getTypeName())
->setURI($handle->getURI())
->setPHID($handle->getPHID())
->setPriorityType('jump');
}
}
}
$content = mpull($results, 'getWireFormat'); $content = mpull($results, 'getWireFormat');
if ($request->isAjax()) { if ($request->isAjax()) {

View file

@ -35,13 +35,15 @@ final class PhabricatorMainMenuSearchView extends AphrontView {
), ),
''); '');
$search_datasource = new PhabricatorSearchDatasource();
Javelin::initBehavior( Javelin::initBehavior(
'phabricator-search-typeahead', 'phabricator-search-typeahead',
array( array(
'id' => $target_id, 'id' => $target_id,
'input' => $search_id, 'input' => $search_id,
'button' => $button_id, 'button' => $button_id,
'src' => '/typeahead/common/mainsearch/', 'src' => $search_datasource->getDatasourceURI(),
'limit' => 10, 'limit' => 10,
'placeholder' => pht('Search'), 'placeholder' => pht('Search'),
)); ));