From dcb5eb8e3571f00d2adbc207dd15190d11db76ce Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 27 May 2013 13:41:09 -0700 Subject: [PATCH] Slightly improve saved query UX Summary: Ref T2625. - Show saved queries in the left nav. - Highlight the correct stuff in the left nav. Test Plan: Clicked all left-nav stuff. Reviewers: btrahan, blc Reviewed By: btrahan CC: aran Maniphest Tasks: T2625 Differential Revision: https://secure.phabricator.com/D6053 --- .../controller/PhabricatorPasteController.php | 35 ++++++++++++------- .../PhabricatorPasteListController.php | 14 ++++---- .../PhabricatorPasteQueriesController.php | 4 +-- .../query/PhabricatorPasteSearchEngine.php | 2 +- 4 files changed, 33 insertions(+), 22 deletions(-) diff --git a/src/applications/paste/controller/PhabricatorPasteController.php b/src/applications/paste/controller/PhabricatorPasteController.php index 7581c5f39d..45371dcbb6 100644 --- a/src/applications/paste/controller/PhabricatorPasteController.php +++ b/src/applications/paste/controller/PhabricatorPasteController.php @@ -2,35 +2,44 @@ abstract class PhabricatorPasteController extends PhabricatorController { - public function buildSideNavView($filter = null, $for_app = false) { + public function buildSideNavView($for_app = false) { $user = $this->getRequest()->getUser(); $nav = new AphrontSideNavFilterView(); - $nav->setBaseURI(new PhutilURI($this->getApplicationURI('filter/'))); + $nav->setBaseURI(new PhutilURI($this->getApplicationURI())); if ($for_app) { - $nav->addFilter('', pht('Create Paste'), - $this->getApplicationURI('/create/')); + $nav->addFilter('create', pht('Create Paste')); } - $nav->addLabel(pht('Filters')); - $nav->addFilter('all', pht('All Pastes')); - if ($user->isLoggedIn()) { - $nav->addFilter('my', pht('My Pastes')); + $nav->addLabel(pht('Queries')); + + $named_queries = id(new PhabricatorNamedQueryQuery()) + ->setViewer($user) + ->withUserPHIDs(array($user->getPHID())) + ->withEngineClassNames(array('PhabricatorPasteSearchEngine')) + ->execute(); + + foreach ($named_queries as $query) { + $nav->addFilter('query/'.$query->getQueryKey(), $query->getQueryName()); } + $nav->addFilter('filter/all', pht('All Pastes')); + if ($user->isLoggedIn()) { + $nav->addFilter('filter/my', pht('My Pastes')); + } + $nav->addFilter('savedqueries', pht('Edit Queries...')); + $nav->addLabel(pht('Search')); - $nav->addFilter('advanced', pht('Advanced Search')); - $nav->addFilter('', pht('Saved Queries'), - $this->getApplicationURI('/savedqueries/')); + $nav->addFilter('filter/advanced', pht('Advanced Search')); - $nav->selectFilter($filter, 'all'); + $nav->selectFilter(null); return $nav; } public function buildApplicationMenu() { - return $this->buildSideNavView(null, true)->getMenu(); + return $this->buildSideNavView(true)->getMenu(); } public function buildApplicationCrumbs() { diff --git a/src/applications/paste/controller/PhabricatorPasteListController.php b/src/applications/paste/controller/PhabricatorPasteListController.php index 8693319395..e0f3d15d80 100644 --- a/src/applications/paste/controller/PhabricatorPasteListController.php +++ b/src/applications/paste/controller/PhabricatorPasteListController.php @@ -29,12 +29,8 @@ final class PhabricatorPasteListController extends PhabricatorPasteController { ->setURI('/paste/query/'.$saved->getQueryKey().'/'); } - $nav = $this->buildSideNavView($this->filter); - $filter = $nav->getSelectedFilter(); - - $saved_query = new PhabricatorSavedQuery(); + $nav = $this->buildSideNavView(); $engine = id(new PhabricatorPasteSearchEngine()) - ->setPasteSearchFilter($filter) ->setPasteSearchUser($request->getUser()); if ($this->queryKey !== null) { @@ -48,7 +44,13 @@ final class PhabricatorPasteListController extends PhabricatorPasteController { $query = id(new PhabricatorPasteSearchEngine()) ->buildQueryFromSavedQuery($saved_query); + + $nav->selectFilter('query/'.$this->queryKey); + $filter = null; } else { + $filter = $nav->selectFilter('filter/'.$this->filter); + $engine->setPasteSearchFilter($filter); + $saved_query = $engine->buildSavedQueryFromRequest($request); $query = $engine->buildQueryFromSavedQuery($saved_query); } @@ -63,7 +65,7 @@ final class PhabricatorPasteListController extends PhabricatorPasteController { $list->setPager($pager); $list->setNoDataString(pht("No results found for this query.")); - if ($this->queryKey !== null || $filter == "advanced") { + if ($this->queryKey !== null || $filter == "filter/advanced") { $form = $engine->buildSearchForm($saved_query); $nav->appendChild( array( diff --git a/src/applications/paste/controller/PhabricatorPasteQueriesController.php b/src/applications/paste/controller/PhabricatorPasteQueriesController.php index feb47c9ddd..5bafa4a821 100644 --- a/src/applications/paste/controller/PhabricatorPasteQueriesController.php +++ b/src/applications/paste/controller/PhabricatorPasteQueriesController.php @@ -7,8 +7,8 @@ final class PhabricatorPasteQueriesController $request = $this->getRequest(); $user = $request->getUser(); - $nav = $this->buildSideNavView(""); - $filter = $nav->getSelectedFilter(); + $nav = $this->buildSideNavView(); + $nav->selectFilter('savedqueries'); $named_queries = id(new PhabricatorNamedQueryQuery()) ->setViewer($user) diff --git a/src/applications/paste/query/PhabricatorPasteSearchEngine.php b/src/applications/paste/query/PhabricatorPasteSearchEngine.php index d342d666f3..51c18e81f8 100644 --- a/src/applications/paste/query/PhabricatorPasteSearchEngine.php +++ b/src/applications/paste/query/PhabricatorPasteSearchEngine.php @@ -21,7 +21,7 @@ final class PhabricatorPasteSearchEngine $saved = new PhabricatorSavedQuery(); - if ($this->filter == "my") { + if ($this->filter == "filter/my") { $user = $request->getUser(); $saved->setParameter('authorPHIDs', array($user->getPHID())); } else {