Differential D14828 Diff 35851 src/applications/search/controller/PhabricatorApplicationSearchController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/search/controller/PhabricatorApplicationSearchController.php
Show First 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | if ($this->queryKey == 'advanced') { | ||||
if ($request->isHTTPGet()) { | if ($request->isHTTPGet()) { | ||||
// If this is a GET request and it has some query data, don't | // If this is a GET request and it has some query data, don't | ||||
// do anything unless it's only before= or after=. We'll build and | // do anything unless it's only before= or after=. We'll build and | ||||
// execute a query from it below. This allows external tools to build | // execute a query from it below. This allows external tools to build | ||||
// URIs like "/query/?users=a,b". | // URIs like "/query/?users=a,b". | ||||
$pt_data = $request->getPassthroughRequestData(); | $pt_data = $request->getPassthroughRequestData(); | ||||
$exempt = array( | |||||
'before' => true, | |||||
'after' => true, | |||||
'nux' => true, | |||||
); | |||||
foreach ($pt_data as $pt_key => $pt_value) { | foreach ($pt_data as $pt_key => $pt_value) { | ||||
if ($pt_key != 'before' && $pt_key != 'after') { | if (isset($exempt[$pt_key])) { | ||||
continue; | |||||
} | |||||
$found_query_data = true; | $found_query_data = true; | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
} | |||||
if (!$found_query_data) { | if (!$found_query_data) { | ||||
// Otherwise, there's no query data so just run the user's default | // Otherwise, there's no query data so just run the user's default | ||||
// query for this application. | // query for this application. | ||||
$query_key = head_key($engine->loadEnabledNamedQueries()); | $query_key = head_key($engine->loadEnabledNamedQueries()); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | if ($run_query || $named_query) { | ||||
$this->getApplicationURI('query/advanced/?query='.$query_key), | $this->getApplicationURI('query/advanced/?query='.$query_key), | ||||
(!$named_query ? true : false)); | (!$named_query ? true : false)); | ||||
} else { | } else { | ||||
$box->setForm($form); | $box->setForm($form); | ||||
} | } | ||||
$body[] = $box; | $body[] = $box; | ||||
if ($run_query) { | if ($run_query) { | ||||
$box->setAnchor( | $box->setAnchor( | ||||
id(new PhabricatorAnchorView()) | id(new PhabricatorAnchorView()) | ||||
->setAnchorName('R')); | ->setAnchorName('R')); | ||||
try { | try { | ||||
$engine->setRequest($request); | |||||
$query = $engine->buildQueryFromSavedQuery($saved_query); | $query = $engine->buildQueryFromSavedQuery($saved_query); | ||||
$pager = $engine->newPagerForSavedQuery($saved_query); | $pager = $engine->newPagerForSavedQuery($saved_query); | ||||
$pager->readFromRequest($request); | $pager->readFromRequest($request); | ||||
$objects = $engine->executeQuery($query, $pager); | $objects = $engine->executeQuery($query, $pager); | ||||
$engine->setRequest($request); | $force_nux = $request->getBool('nux'); | ||||
if (!$objects || $force_nux) { | |||||
$nux_view = $this->renderNewUserView($engine, $force_nux); | |||||
chad: erm, where do I drop this new function? I tried `SearchEngine` but it complains about being… | |||||
} else { | |||||
$nux_view = null; | |||||
} | |||||
if ($nux_view) { | |||||
$box->appendChild($nux_view); | |||||
} else { | |||||
$list = $engine->renderResults($objects, $saved_query); | $list = $engine->renderResults($objects, $saved_query); | ||||
if (!($list instanceof PhabricatorApplicationSearchResultView)) { | if (!($list instanceof PhabricatorApplicationSearchResultView)) { | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'SearchEngines must render a "%s" object, but this engine '. | 'SearchEngines must render a "%s" object, but this engine '. | ||||
'(of class "%s") rendered something else.', | '(of class "%s") rendered something else.', | ||||
'PhabricatorApplicationSearchResultView', | 'PhabricatorApplicationSearchResultView', | ||||
get_class($engine))); | get_class($engine))); | ||||
} | } | ||||
if ($list->getActions()) { | if ($list->getActions()) { | ||||
foreach ($list->getActions() as $action) { | foreach ($list->getActions() as $action) { | ||||
$header->addActionLink($action); | $header->addActionLink($action); | ||||
} | } | ||||
} | } | ||||
if ($list->getObjectList()) { | if ($list->getObjectList()) { | ||||
$box->setObjectList($list->getObjectList()); | $box->setObjectList($list->getObjectList()); | ||||
} | } | ||||
if ($list->getTable()) { | if ($list->getTable()) { | ||||
$box->setTable($list->getTable()); | $box->setTable($list->getTable()); | ||||
} | } | ||||
if ($list->getInfoView()) { | if ($list->getInfoView()) { | ||||
$box->setInfoView($list->getInfoView()); | $box->setInfoView($list->getInfoView()); | ||||
} | } | ||||
if ($list->getContent()) { | if ($list->getContent()) { | ||||
$box->appendChild($list->getContent()); | $box->appendChild($list->getContent()); | ||||
} | } | ||||
if ($list->getCollapsed()) { | if ($list->getCollapsed()) { | ||||
$box->setCollapsed(true); | $box->setCollapsed(true); | ||||
} | } | ||||
if ($pager->willShowPagingControls()) { | if ($pager->willShowPagingControls()) { | ||||
$pager_box = id(new PHUIBoxView()) | $pager_box = id(new PHUIBoxView()) | ||||
->addPadding(PHUI::PADDING_MEDIUM) | ->addPadding(PHUI::PADDING_MEDIUM) | ||||
->addMargin(PHUI::MARGIN_LARGE) | ->addMargin(PHUI::MARGIN_LARGE) | ||||
->setBorder(true) | ->setBorder(true) | ||||
->appendChild($pager); | ->appendChild($pager); | ||||
$body[] = $pager_box; | $body[] = $pager_box; | ||||
} | } | ||||
} | |||||
} catch (PhabricatorTypeaheadInvalidTokenException $ex) { | } catch (PhabricatorTypeaheadInvalidTokenException $ex) { | ||||
$errors[] = pht( | $errors[] = pht( | ||||
'This query specifies an invalid parameter. Review the '. | 'This query specifies an invalid parameter. Review the '. | ||||
'query parameters and correct errors.'); | 'query parameters and correct errors.'); | ||||
} | } | ||||
} | } | ||||
if ($errors) { | if ($errors) { | ||||
▲ Show 20 Lines • Show All 121 Lines • ▼ Show 20 Lines | $nav = id(new AphrontSideNavFilterView()) | ||||
->setUser($viewer) | ->setUser($viewer) | ||||
->setBaseURI(new PhutilURI($this->getApplicationURI())); | ->setBaseURI(new PhutilURI($this->getApplicationURI())); | ||||
$engine->addNavigationItems($nav->getMenu()); | $engine->addNavigationItems($nav->getMenu()); | ||||
return $nav; | return $nav; | ||||
} | } | ||||
private function renderNewUserView( | |||||
PhabricatorApplicationSearchEngine $engine, | |||||
$force_nux) { | |||||
// Don't render NUX if the user has clicked away from the default page. | |||||
if (strlen($this->getQueryKey())) { | |||||
return null; | |||||
} | |||||
// Don't put NUX in panels because it would be weird. | |||||
if ($engine->isPanelContext()) { | |||||
return null; | |||||
} | |||||
// Try to render the view itself first, since this should be very cheap | |||||
// (just returning some text). | |||||
$nux_view = $engine->renderNewUserView(); | |||||
if (!$nux_view) { | |||||
return null; | |||||
} | |||||
$query = $engine->newQuery(); | |||||
if (!$query) { | |||||
return null; | |||||
} | |||||
// Try to load any object at all. If we can, the application has seen some | |||||
// use so we just render the normal view. | |||||
if (!$force_nux) { | |||||
$object = $query | |||||
->setViewer(PhabricatorUser::getOmnipotentUser()) | |||||
->setLimit(1) | |||||
->execute(); | |||||
if ($object) { | |||||
return null; | |||||
} | |||||
} | |||||
return $nux_view; | |||||
} | |||||
} | } |
erm, where do I drop this new function? I tried SearchEngine but it complains about being final.