1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-31 08:58:20 +01:00

Add basic NUX support to SearchEngines

Summary:
This is just putting a hook in that pretty much works. Behavior:

  - If you visit `/maniphest/?nux=true`, it always shows NUX for testing.
  - Otherwise, it shows NUX if there are no objects in the application yet.

Test Plan: {F1031846}

Reviewers: chad

Reviewed By: chad

Differential Revision: https://secure.phabricator.com/D14828
This commit is contained in:
epriestley 2015-12-19 12:43:05 -08:00
parent 9d1ba9c038
commit dbb84f1ddc
2 changed files with 129 additions and 42 deletions

View file

@ -107,13 +107,21 @@ final class PhabricatorApplicationSearchController
// 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
@ -203,12 +211,15 @@ final class PhabricatorApplicationSearchController
$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);
@ -216,7 +227,16 @@ final class PhabricatorApplicationSearchController
$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);
} 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)) {
@ -258,7 +278,7 @@ final class PhabricatorApplicationSearchController
->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 '.
@ -396,4 +416,47 @@ final class PhabricatorApplicationSearchController
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;
}
} }

View file

@ -1354,4 +1354,28 @@ abstract class PhabricatorApplicationSearchEngine extends Phobject {
return $attachments; return $attachments;
} }
final public function renderNewUserView() {
$head = $this->getNewUserHeader();
$body = $this->getNewUserBody();
if (!strlen($head) && !strlen($body)) {
return null;
}
$viewer = $this->requireViewer();
return id(new PHUIBoxView())
->addMargin(PHUI::MARGIN_LARGE)
->appendChild($head)
->appendChild(new PHUIRemarkupView($viewer, $body));
}
protected function getNewUserHeader() {
return null;
}
protected function getNewUserBody() {
return null;
}
} }