From be9cc235b2edbef23242b05203eb88a29e42949a Mon Sep 17 00:00:00 2001 From: Chad Little Date: Wed, 23 Sep 2015 12:48:19 -0700 Subject: [PATCH] Add Application Routes to Phame AppSearch queries Summary: Fixes T9388, lays in basic ApplicationSearch. Test Plan: Build a dashboard with Posts and Blogs, click on search icon, get sent to correct page. Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Maniphest Tasks: T9388 Differential Revision: https://secure.phabricator.com/D14146 --- .../PhabricatorPhameApplication.php | 2 + .../blog/PhameBlogListController.php | 95 ++++------------ .../post/PhamePostListController.php | 103 ++++++------------ .../phame/query/PhamePostSearchEngine.php | 1 + 4 files changed, 55 insertions(+), 146 deletions(-) diff --git a/src/applications/phame/application/PhabricatorPhameApplication.php b/src/applications/phame/application/PhabricatorPhameApplication.php index f7643c6097..ec98087adf 100644 --- a/src/applications/phame/application/PhabricatorPhameApplication.php +++ b/src/applications/phame/application/PhabricatorPhameApplication.php @@ -42,6 +42,7 @@ final class PhabricatorPhameApplication extends PhabricatorApplication { 'live/(?P[^/]+)/(?P.*)' => 'PhameBlogLiveController', 'post/' => array( '(?:(?Pdraft|all)/)?' => 'PhamePostListController', + '(?:query/(?P[^/]+)/)?' => 'PhamePostListController', 'blogger/(?P[\w\.-_]+)/' => 'PhamePostListController', 'delete/(?P[^/]+)/' => 'PhamePostDeleteController', 'edit/(?:(?P[^/]+)/)?' => 'PhamePostEditController', @@ -56,6 +57,7 @@ final class PhabricatorPhameApplication extends PhabricatorApplication { ), 'blog/' => array( '(?:(?Puser|all)/)?' => 'PhameBlogListController', + '(?:query/(?P[^/]+)/)?' => 'PhameBlogListController', 'delete/(?P[^/]+)/' => 'PhameBlogDeleteController', 'edit/(?P[^/]+)/' => 'PhameBlogEditController', 'view/(?P[^/]+)/' => 'PhameBlogViewController', diff --git a/src/applications/phame/controller/blog/PhameBlogListController.php b/src/applications/phame/controller/blog/PhameBlogListController.php index 9d0253d89c..965e1eec49 100644 --- a/src/applications/phame/controller/blog/PhameBlogListController.php +++ b/src/applications/phame/controller/blog/PhameBlogListController.php @@ -2,86 +2,33 @@ final class PhameBlogListController extends PhameController { - public function handleRequest(AphrontRequest $request) { - $user = $request->getUser(); - - $nav = $this->renderSideNavFilterView(null); - $filter = $request->getURIData('filter'); - $filter = $nav->selectFilter('blog/'.$filter, 'blog/user'); - - $query = id(new PhameBlogQuery()) - ->setViewer($user); - - switch ($filter) { - case 'blog/all': - $title = pht('All Blogs'); - $nodata = pht('No blogs have been created.'); - break; - case 'blog/user': - $title = pht('Joinable Blogs'); - $nodata = pht('There are no blogs you can contribute to.'); - $query->requireCapabilities( - array( - PhabricatorPolicyCapability::CAN_JOIN, - )); - break; - default: - throw new Exception(pht("Unknown filter '%s'!", $filter)); - } - - $pager = id(new PHUIPagerView()) - ->setURI($request->getRequestURI(), 'offset') - ->setOffset($request->getInt('offset')); - - $blogs = $query->executeWithOffsetPager($pager); - - $blog_list = $this->renderBlogList($blogs, $user, $nodata); - $blog_list->setPager($pager); - - $box = id(new PHUIObjectBoxView()) - ->setHeaderText($title) - ->setObjectList($blog_list); - - $crumbs = $this->buildApplicationCrumbs(); - $crumbs->addTextCrumb($title, $this->getApplicationURI()); - - $nav->appendChild( - array( - $crumbs, - $box, - )); - - return $this->buildApplicationPage( - $nav, - array( - 'title' => $title, - )); + public function shouldAllowPublic() { + return true; } - private function renderBlogList( - array $blogs, - PhabricatorUser $viewer, - $nodata) { + public function handleRequest(AphrontRequest $request) { + $query_key = $request->getURIData('queryKey'); + $controller = id(new PhabricatorApplicationSearchController()) + ->setQueryKey($query_key) + ->setSearchEngine(new PhameBlogSearchEngine()) + ->setNavigation($this->buildSideNavView()); - $view = new PHUIObjectItemListView(); - $view->setNoDataString($nodata); - $view->setUser($viewer); - foreach ($blogs as $blog) { + return $this->delegateToController($controller); + } - $id = $blog->getID(); - $item = id(new PHUIObjectItemView()) - ->setUser($viewer) - ->setObject($blog) - ->setHeader($blog->getName()) - ->setStatusIcon('fa-star') - ->setHref($this->getApplicationURI("/blog/view/{$id}/")) - ->addAttribute($blog->getSkin()) - ->addAttribute($blog->getDomain()); + public function buildSideNavView() { + $viewer = $this->getRequest()->getUser(); - $view->addItem($item); - } + $nav = new AphrontSideNavFilterView(); + $nav->setBaseURI(new PhutilURI($this->getApplicationURI())); - return $view; + id(new PhameBlogSearchEngine()) + ->setViewer($viewer) + ->addNavigationItems($nav->getMenu()); + + $nav->selectFilter(null); + + return $nav; } } diff --git a/src/applications/phame/controller/post/PhamePostListController.php b/src/applications/phame/controller/post/PhamePostListController.php index b2b28bd4eb..fb38a830bb 100644 --- a/src/applications/phame/controller/post/PhamePostListController.php +++ b/src/applications/phame/controller/post/PhamePostListController.php @@ -2,78 +2,37 @@ final class PhamePostListController extends PhameController { - public function handleRequest(AphrontRequest $request) { - $viewer = $request->getViewer(); - $filter = $request->getURIData('filter'); - $bloggername = $request->getURIData('bloggername'); - - $query = id(new PhamePostQuery()) - ->setViewer($viewer); - - $nav = $this->renderSideNavFilterView(); - $nodata = null; - - switch ($filter) { - case 'draft': - $query->withBloggerPHIDs(array($viewer->getPHID())); - $query->withVisibility(PhamePost::VISIBILITY_DRAFT); - $nodata = pht('You have no unpublished drafts.'); - $title = pht('Unpublished Drafts'); - $nav->selectFilter('post/draft'); - break; - case 'blogger': - if ($bloggername) { - $blogger = id(new PhabricatorUser())->loadOneWhere( - 'username = %s', - $bloggername); - if (!$blogger) { - return new Aphront404Response(); - } - } else { - $blogger = $viewer; - } - - $query->withBloggerPHIDs(array($blogger->getPHID())); - if ($blogger->getPHID() == $viewer->getPHID()) { - $nav->selectFilter('post'); - $nodata = pht('You have not written any posts.'); - } else { - $nodata = pht('%s has not written any posts.', $blogger); - } - $title = pht('Posts by %s', $blogger); - break; - default: - case 'all': - $nodata = pht('There are no visible posts.'); - $title = pht('Posts'); - $nav->selectFilter('post/all'); - break; - } - - $pager = id(new AphrontCursorPagerView()) - ->readFromRequest($request); - - $posts = $query->executeWithCursorPager($pager); - - $post_list = $this->renderPostList($posts, $viewer, $nodata); - $post_list = id(new PHUIObjectBoxView()) - ->setHeaderText($title) - ->appendChild($post_list); - - $crumbs = $this->buildApplicationCrumbs(); - $crumbs->addTextCrumb($title, $this->getApplicationURI()); - - $nav->appendChild( - array( - $crumbs, - $post_list, - )); - - return $this->buildApplicationPage( - $nav, - array( - 'title' => $title, - )); + public function shouldAllowPublic() { + return true; } + public function handleRequest(AphrontRequest $request) { + $query_key = $request->getURIData('queryKey'); + $controller = id(new PhabricatorApplicationSearchController()) + ->setQueryKey($query_key) + ->setSearchEngine(new PhamePostSearchEngine()) + ->setNavigation($this->buildSideNavView()); + + return $this->delegateToController($controller); + } + + public function buildSideNavView() { + $viewer = $this->getRequest()->getUser(); + + $nav = new AphrontSideNavFilterView(); + $nav->setBaseURI(new PhutilURI($this->getApplicationURI())); + + id(new PhamePostSearchEngine()) + ->setViewer($viewer) + ->addNavigationItems($nav->getMenu()); + + $nav->addLabel(pht('Blogs')); + $nav->addFilter('blog/', pht('Manage Blogs')); + + $nav->selectFilter(null); + + return $nav; + } + + } diff --git a/src/applications/phame/query/PhamePostSearchEngine.php b/src/applications/phame/query/PhamePostSearchEngine.php index a5feb3d634..cedc02cc7a 100644 --- a/src/applications/phame/query/PhamePostSearchEngine.php +++ b/src/applications/phame/query/PhamePostSearchEngine.php @@ -29,6 +29,7 @@ final class PhamePostSearchEngine return array( id(new PhabricatorSearchSelectField()) ->setKey('visibility') + ->setLabel(pht('Visibility')) ->setOptions(array( '' => pht('All'), PhamePost::VISIBILITY_PUBLISHED => pht('Live'),