Differential D14382 Diff 34770 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 52 Lines • ▼ Show 20 Lines | if (!$parent) { | ||||
pht('You must delegate to this controller, not invoke it directly.')); | pht('You must delegate to this controller, not invoke it directly.')); | ||||
} | } | ||||
$engine = $this->getSearchEngine(); | $engine = $this->getSearchEngine(); | ||||
if (!$engine) { | if (!$engine) { | ||||
throw new PhutilInvalidStateException('setEngine'); | throw new PhutilInvalidStateException('setEngine'); | ||||
} | } | ||||
$nav = $this->getNavigation(); | |||||
if (!$nav) { | |||||
throw new PhutilInvalidStateException('setNavigation'); | |||||
} | |||||
$engine->setViewer($this->getRequest()->getUser()); | $engine->setViewer($this->getRequest()->getUser()); | ||||
$parent = $this->getDelegatingController(); | $parent = $this->getDelegatingController(); | ||||
} | } | ||||
public function processRequest() { | public function processRequest() { | ||||
$this->validateDelegatingController(); | $this->validateDelegatingController(); | ||||
$key = $this->getQueryKey(); | $key = $this->getQueryKey(); | ||||
if ($key == 'edit') { | if ($key == 'edit') { | ||||
return $this->processEditRequest(); | return $this->processEditRequest(); | ||||
} else { | } else { | ||||
return $this->processSearchRequest(); | return $this->processSearchRequest(); | ||||
} | } | ||||
} | } | ||||
private function processSearchRequest() { | private function processSearchRequest() { | ||||
$parent = $this->getDelegatingController(); | $parent = $this->getDelegatingController(); | ||||
$request = $this->getRequest(); | $request = $this->getRequest(); | ||||
$user = $request->getUser(); | $user = $request->getUser(); | ||||
$engine = $this->getSearchEngine(); | $engine = $this->getSearchEngine(); | ||||
$nav = $this->getNavigation(); | $nav = $this->getNavigation(); | ||||
if (!$nav) { | |||||
$nav = $this->buildNavigation(); | |||||
} | |||||
if ($request->isFormPost()) { | if ($request->isFormPost()) { | ||||
$saved_query = $engine->buildSavedQueryFromRequest($request); | $saved_query = $engine->buildSavedQueryFromRequest($request); | ||||
$engine->saveQuery($saved_query); | $engine->saveQuery($saved_query); | ||||
return id(new AphrontRedirectResponse())->setURI( | return id(new AphrontRedirectResponse())->setURI( | ||||
$engine->getQueryResultsPageURI($saved_query->getQueryKey()).'#R'); | $engine->getQueryResultsPageURI($saved_query->getQueryKey()).'#R'); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | if ($run_query && !$named_query && $user->isLoggedIn()) { | ||||
'/search/edit/'.$saved_query->getQueryKey().'/', | '/search/edit/'.$saved_query->getQueryKey().'/', | ||||
pht('Save Custom Query...')); | pht('Save Custom Query...')); | ||||
} | } | ||||
// TODO: A "Create Dashboard Panel" action goes here somewhere once | // TODO: A "Create Dashboard Panel" action goes here somewhere once | ||||
// we sort out T5307. | // we sort out T5307. | ||||
$form->appendChild($submit); | $form->appendChild($submit); | ||||
$body = array(); | |||||
if ($this->getPreface()) { | if ($this->getPreface()) { | ||||
$nav->appendChild($this->getPreface()); | $body[] = $this->getPreface(); | ||||
} | } | ||||
if ($named_query) { | if ($named_query) { | ||||
$title = $named_query->getQueryName(); | $title = $named_query->getQueryName(); | ||||
} else { | } else { | ||||
$title = pht('Advanced Search'); | $title = pht('Advanced Search'); | ||||
} | } | ||||
Show All 9 Lines | if ($run_query || $named_query) { | ||||
pht('Hide Query'), | pht('Hide Query'), | ||||
$form, | $form, | ||||
$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); | ||||
} | } | ||||
$nav->appendChild($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 { | ||||
$query = $engine->buildQueryFromSavedQuery($saved_query); | $query = $engine->buildQueryFromSavedQuery($saved_query); | ||||
Show All 38 Lines | if ($run_query) { | ||||
} | } | ||||
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); | ||||
$nav->appendChild($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) { | ||||
$box->setFormErrors($errors, pht('Query Errors')); | $box->setFormErrors($errors, pht('Query Errors')); | ||||
} | } | ||||
$crumbs = $parent | $crumbs = $parent | ||||
->buildApplicationCrumbs() | ->buildApplicationCrumbs() | ||||
->addTextCrumb($title); | ->addTextCrumb($title); | ||||
$nav->setCrumbs($crumbs); | return $this->newPage() | ||||
->setApplicationMenu($this->buildApplicationMenu()) | |||||
return $this->buildApplicationPage( | ->setTitle(pht('Query: %s', $title)) | ||||
$nav, | ->setCrumbs($crumbs) | ||||
array( | ->setNavigation($nav) | ||||
'title' => pht('Query: %s', $title), | ->appendChild($body); | ||||
)); | |||||
} | } | ||||
private function processEditRequest() { | private function processEditRequest() { | ||||
$parent = $this->getDelegatingController(); | $parent = $this->getDelegatingController(); | ||||
$request = $this->getRequest(); | $request = $this->getRequest(); | ||||
$user = $request->getUser(); | $user = $request->getUser(); | ||||
$engine = $this->getSearchEngine(); | $engine = $this->getSearchEngine(); | ||||
$nav = $this->getNavigation(); | $nav = $this->getNavigation(); | ||||
if (!$nav) { | |||||
$nav = $this->buildNavigation(); | |||||
} | |||||
$named_queries = $engine->loadAllNamedQueries(); | $named_queries = $engine->loadAllNamedQueries(); | ||||
$list_id = celerity_generate_unique_node_id(); | $list_id = celerity_generate_unique_node_id(); | ||||
$list = new PHUIObjectItemListView(); | $list = new PHUIObjectItemListView(); | ||||
$list->setUser($user); | $list->setUser($user); | ||||
$list->setID($list_id); | $list->setID($list_id); | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | private function processEditRequest() { | ||||
$list->setNoDataString(pht('No saved queries.')); | $list->setNoDataString(pht('No saved queries.')); | ||||
$crumbs = $parent | $crumbs = $parent | ||||
->buildApplicationCrumbs() | ->buildApplicationCrumbs() | ||||
->addTextCrumb(pht('Saved Queries'), $engine->getQueryManagementURI()); | ->addTextCrumb(pht('Saved Queries'), $engine->getQueryManagementURI()); | ||||
$nav->selectFilter('query/edit'); | $nav->selectFilter('query/edit'); | ||||
$nav->setCrumbs($crumbs); | |||||
$box = id(new PHUIObjectBoxView()) | $box = id(new PHUIObjectBoxView()) | ||||
->setHeaderText(pht('Saved Queries')) | ->setHeaderText(pht('Saved Queries')) | ||||
->setObjectList($list); | ->setObjectList($list); | ||||
$nav->appendChild($box); | return $this->newPage() | ||||
->setApplicationMenu($this->buildApplicationMenu()) | |||||
return $parent->buildApplicationPage( | ->setTitle(pht('Saved Queries')) | ||||
$nav, | ->setCrumbs($crumbs) | ||||
array( | ->setNavigation($nav) | ||||
'title' => pht('Saved Queries'), | ->appendChild($box); | ||||
)); | |||||
} | } | ||||
public function buildApplicationMenu() { | public function buildApplicationMenu() { | ||||
return $this->getDelegatingController()->buildApplicationMenu(); | $menu = $this->getDelegatingController() | ||||
->buildApplicationMenu(); | |||||
if ($menu instanceof PHUIApplicationMenuView) { | |||||
$menu->setSearchEngine($this->getSearchEngine()); | |||||
} | |||||
return $menu; | |||||
} | |||||
private function buildNavigation() { | |||||
$viewer = $this->getViewer(); | |||||
$engine = $this->getSearchEngine(); | |||||
$nav = id(new AphrontSideNavFilterView()) | |||||
->setUser($viewer) | |||||
->setBaseURI(new PhutilURI($this->getApplicationURI())); | |||||
$engine->addNavigationItems($nav->getMenu()); | |||||
return $nav; | |||||
} | } | ||||
} | } |