mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-24 22:40: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:
parent
cab442fe8c
commit
0a3a3eae00
7 changed files with 142 additions and 95 deletions
|
@ -592,6 +592,7 @@ phutil_register_library_map(array(
|
|||
'DiffusionSvnRawDiffQuery' => 'applications/diffusion/query/rawdiff/DiffusionSvnRawDiffQuery.php',
|
||||
'DiffusionSvnRequest' => 'applications/diffusion/request/DiffusionSvnRequest.php',
|
||||
'DiffusionSymbolController' => 'applications/diffusion/controller/DiffusionSymbolController.php',
|
||||
'DiffusionSymbolDatasource' => 'applications/diffusion/typeahead/DiffusionSymbolDatasource.php',
|
||||
'DiffusionSymbolQuery' => 'applications/diffusion/query/DiffusionSymbolQuery.php',
|
||||
'DiffusionTagListController' => 'applications/diffusion/controller/DiffusionTagListController.php',
|
||||
'DiffusionTagListView' => 'applications/diffusion/view/DiffusionTagListView.php',
|
||||
|
@ -1150,6 +1151,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorApplicationCountdown' => 'applications/countdown/application/PhabricatorApplicationCountdown.php',
|
||||
'PhabricatorApplicationDaemons' => 'applications/daemon/application/PhabricatorApplicationDaemons.php',
|
||||
'PhabricatorApplicationDashboard' => 'applications/dashboard/application/PhabricatorApplicationDashboard.php',
|
||||
'PhabricatorApplicationDatasource' => 'applications/meta/typeahead/PhabricatorApplicationDatasource.php',
|
||||
'PhabricatorApplicationDetailViewController' => 'applications/meta/controller/PhabricatorApplicationDetailViewController.php',
|
||||
'PhabricatorApplicationDifferential' => 'applications/differential/application/PhabricatorApplicationDifferential.php',
|
||||
'PhabricatorApplicationDiffusion' => 'applications/diffusion/application/PhabricatorApplicationDiffusion.php',
|
||||
|
@ -2157,6 +2159,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorSearchConfigOptions' => 'applications/search/config/PhabricatorSearchConfigOptions.php',
|
||||
'PhabricatorSearchController' => 'applications/search/controller/PhabricatorSearchController.php',
|
||||
'PhabricatorSearchDAO' => 'applications/search/storage/PhabricatorSearchDAO.php',
|
||||
'PhabricatorSearchDatasource' => 'applications/search/typeahead/PhabricatorSearchDatasource.php',
|
||||
'PhabricatorSearchDeleteController' => 'applications/search/controller/PhabricatorSearchDeleteController.php',
|
||||
'PhabricatorSearchDocument' => 'applications/search/storage/document/PhabricatorSearchDocument.php',
|
||||
'PhabricatorSearchDocumentField' => 'applications/search/storage/document/PhabricatorSearchDocumentField.php',
|
||||
|
@ -3301,6 +3304,7 @@ phutil_register_library_map(array(
|
|||
'DiffusionSvnRawDiffQuery' => 'DiffusionRawDiffQuery',
|
||||
'DiffusionSvnRequest' => 'DiffusionRequest',
|
||||
'DiffusionSymbolController' => 'DiffusionController',
|
||||
'DiffusionSymbolDatasource' => 'PhabricatorTypeaheadDatasource',
|
||||
'DiffusionSymbolQuery' => 'PhabricatorOffsetPagedQuery',
|
||||
'DiffusionTagListController' => 'DiffusionController',
|
||||
'DiffusionTagListView' => 'DiffusionView',
|
||||
|
@ -3924,6 +3928,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorApplicationCountdown' => 'PhabricatorApplication',
|
||||
'PhabricatorApplicationDaemons' => 'PhabricatorApplication',
|
||||
'PhabricatorApplicationDashboard' => 'PhabricatorApplication',
|
||||
'PhabricatorApplicationDatasource' => 'PhabricatorTypeaheadDatasource',
|
||||
'PhabricatorApplicationDetailViewController' => 'PhabricatorApplicationsController',
|
||||
'PhabricatorApplicationDifferential' => 'PhabricatorApplication',
|
||||
'PhabricatorApplicationDiffusion' => 'PhabricatorApplication',
|
||||
|
@ -5004,6 +5009,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorSearchConfigOptions' => 'PhabricatorApplicationConfigOptions',
|
||||
'PhabricatorSearchController' => 'PhabricatorSearchBaseController',
|
||||
'PhabricatorSearchDAO' => 'PhabricatorLiskDAO',
|
||||
'PhabricatorSearchDatasource' => 'PhabricatorTypeaheadCompositeDatasource',
|
||||
'PhabricatorSearchDeleteController' => 'PhabricatorSearchBaseController',
|
||||
'PhabricatorSearchDocument' => 'PhabricatorSearchDAO',
|
||||
'PhabricatorSearchDocumentField' => 'PhabricatorSearchDAO',
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -3,6 +3,18 @@
|
|||
final class PhabricatorPeopleDatasource
|
||||
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() {
|
||||
return pht('Type a username...');
|
||||
}
|
||||
|
@ -71,16 +83,14 @@ final class PhabricatorPeopleDatasource
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: Restore this when mainsearch moves here.
|
||||
/*
|
||||
|
||||
if ($need_rich_data) {
|
||||
if ($this->enrichResults && $users) {
|
||||
$phids = mpull($users, 'getPHID');
|
||||
$handles = $this->loadViewerHandles($phids);
|
||||
$handles = id(new PhabricatorHandleQuery())
|
||||
->setViewer($viewer)
|
||||
->withPHIDs($phids)
|
||||
->execute();
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
foreach ($users as $user) {
|
||||
$closed = null;
|
||||
if ($user->getIsDisabled()) {
|
||||
|
@ -98,10 +108,7 @@ final class PhabricatorPeopleDatasource
|
|||
->setPriorityType('user')
|
||||
->setClosed($closed);
|
||||
|
||||
// TODO: Restore this too.
|
||||
/*
|
||||
|
||||
if ($need_rich_data) {
|
||||
if ($this->enrichResults) {
|
||||
$display_type = 'User';
|
||||
if ($user->getIsAdmin()) {
|
||||
$display_type = 'Administrator';
|
||||
|
@ -110,8 +117,6 @@ final class PhabricatorPeopleDatasource
|
|||
$result->setImageURI($handles[$user->getPHID()]->getImageURI());
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
$results[] = $result;
|
||||
}
|
||||
|
||||
|
|
|
@ -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(),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -19,24 +19,12 @@ final class PhabricatorTypeaheadCommonDatasourceController
|
|||
$query = $request->getStr('q');
|
||||
$raw_query = $request->getStr('raw');
|
||||
|
||||
$need_rich_data = false;
|
||||
|
||||
$need_users = false;
|
||||
$need_applications = false;
|
||||
$need_projs = false;
|
||||
$need_upforgrabs = false;
|
||||
$need_noproject = false;
|
||||
$need_symbols = false;
|
||||
$need_jump_objects = false;
|
||||
$need_rich_data = false;
|
||||
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':
|
||||
$need_users = 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');
|
||||
|
||||
if ($request->isAjax()) {
|
||||
|
|
|
@ -35,13 +35,15 @@ final class PhabricatorMainMenuSearchView extends AphrontView {
|
|||
),
|
||||
'');
|
||||
|
||||
$search_datasource = new PhabricatorSearchDatasource();
|
||||
|
||||
Javelin::initBehavior(
|
||||
'phabricator-search-typeahead',
|
||||
array(
|
||||
'id' => $target_id,
|
||||
'input' => $search_id,
|
||||
'button' => $button_id,
|
||||
'src' => '/typeahead/common/mainsearch/',
|
||||
'src' => $search_datasource->getDatasourceURI(),
|
||||
'limit' => 10,
|
||||
'placeholder' => pht('Search'),
|
||||
));
|
||||
|
|
Loading…
Reference in a new issue