From ebf2435c49fe2d4482757237ef7504d475b380fb Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 10 Jan 2013 16:06:29 -0800 Subject: [PATCH] Make feed its own application Summary: Fixes the two-level nav issue introduced by D4376. (My claim that this page is device ready in the code is something of a lie, but it's fairly close.) (@chad, this could use an icon at some point, or you can point me at which one you want and I can take a stab at slicing it.) Test Plan: Looked at feed; saw it not-broken. Also checked public feed (which should just merge at some point). Reviewers: btrahan, chad Reviewed By: btrahan CC: aran Differential Revision: https://secure.phabricator.com/D4381 --- src/__phutil_library_map__.php | 4 + ...AphrontDefaultApplicationConfiguration.php | 5 -- .../PhabricatorDirectoryMainController.php | 78 ------------------- .../PhabricatorApplicationFeed.php | 31 ++++++++ .../controller/PhabricatorFeedController.php | 15 ++++ .../PhabricatorFeedMainController.php | 78 +++++++++++++++++++ 6 files changed, 128 insertions(+), 83 deletions(-) create mode 100644 src/applications/feed/application/PhabricatorApplicationFeed.php create mode 100644 src/applications/feed/controller/PhabricatorFeedMainController.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 7ae067e06f..5d409fa23e 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -601,6 +601,7 @@ phutil_register_library_map(array( 'PhabricatorApplicationDiviner' => 'applications/diviner/application/PhabricatorApplicationDiviner.php', 'PhabricatorApplicationDrydock' => 'applications/drydock/application/PhabricatorApplicationDrydock.php', 'PhabricatorApplicationFact' => 'applications/fact/application/PhabricatorApplicationFact.php', + 'PhabricatorApplicationFeed' => 'applications/feed/application/PhabricatorApplicationFeed.php', 'PhabricatorApplicationFiles' => 'applications/files/application/PhabricatorApplicationFiles.php', 'PhabricatorApplicationFlags' => 'applications/flag/application/PhabricatorApplicationFlags.php', 'PhabricatorApplicationHerald' => 'applications/herald/application/PhabricatorApplicationHerald.php', @@ -800,6 +801,7 @@ phutil_register_library_map(array( 'PhabricatorFeedConstants' => 'applications/feed/constants/PhabricatorFeedConstants.php', 'PhabricatorFeedController' => 'applications/feed/controller/PhabricatorFeedController.php', 'PhabricatorFeedDAO' => 'applications/feed/storage/PhabricatorFeedDAO.php', + 'PhabricatorFeedMainController' => 'applications/feed/controller/PhabricatorFeedMainController.php', 'PhabricatorFeedPublicStreamController' => 'applications/feed/controller/PhabricatorFeedPublicStreamController.php', 'PhabricatorFeedQuery' => 'applications/feed/PhabricatorFeedQuery.php', 'PhabricatorFeedStory' => 'applications/feed/story/PhabricatorFeedStory.php', @@ -1948,6 +1950,7 @@ phutil_register_library_map(array( 'PhabricatorApplicationDiviner' => 'PhabricatorApplication', 'PhabricatorApplicationDrydock' => 'PhabricatorApplication', 'PhabricatorApplicationFact' => 'PhabricatorApplication', + 'PhabricatorApplicationFeed' => 'PhabricatorApplication', 'PhabricatorApplicationFiles' => 'PhabricatorApplication', 'PhabricatorApplicationFlags' => 'PhabricatorApplication', 'PhabricatorApplicationHerald' => 'PhabricatorApplication', @@ -2153,6 +2156,7 @@ phutil_register_library_map(array( 'PhabricatorFactUpdateIterator' => 'PhutilBufferedIterator', 'PhabricatorFeedController' => 'PhabricatorController', 'PhabricatorFeedDAO' => 'PhabricatorLiskDAO', + 'PhabricatorFeedMainController' => 'PhabricatorFeedController', 'PhabricatorFeedPublicStreamController' => 'PhabricatorFeedController', 'PhabricatorFeedQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhabricatorFeedStory' => 'PhabricatorPolicyInterface', diff --git a/src/aphront/configuration/AphrontDefaultApplicationConfiguration.php b/src/aphront/configuration/AphrontDefaultApplicationConfiguration.php index 57ab9f84e3..0d7f3a3b7d 100644 --- a/src/aphront/configuration/AphrontDefaultApplicationConfiguration.php +++ b/src/aphront/configuration/AphrontDefaultApplicationConfiguration.php @@ -18,11 +18,6 @@ class AphrontDefaultApplicationConfiguration return $this->getResourceURIMapRules() + array( '/(?:(?P(?:jump))/)?' => 'PhabricatorDirectoryMainController', - '/(?:(?Pfeed)/)' => array( - 'public/' => 'PhabricatorFeedPublicStreamController', - '(?:(?P[^/]+)/)?' => - 'PhabricatorDirectoryMainController', - ), '/typeahead/' => array( 'common/(?P\w+)/' diff --git a/src/applications/directory/controller/PhabricatorDirectoryMainController.php b/src/applications/directory/controller/PhabricatorDirectoryMainController.php index b5a5d53b51..3e6f1145b3 100644 --- a/src/applications/directory/controller/PhabricatorDirectoryMainController.php +++ b/src/applications/directory/controller/PhabricatorDirectoryMainController.php @@ -21,7 +21,6 @@ final class PhabricatorDirectoryMainController case 'jump': break; case 'home': - case 'feed': $project_query = new PhabricatorProjectQuery(); $project_query->setViewer($user); $project_query->withMemberPHIDs(array($user->getPHID())); @@ -32,8 +31,6 @@ final class PhabricatorDirectoryMainController } switch ($this->filter) { - case 'feed': - return $this->buildFeedResponse($nav, $projects); case 'jump': return $this->buildJumpResponse($nav); default: @@ -111,46 +108,6 @@ final class PhabricatorDirectoryMainController )); } - private function buildFeedResponse($nav, array $projects) { - assert_instances_of($projects, 'PhabricatorProject'); - - $subnav = new AphrontSideNavFilterView(); - $subnav->setBaseURI(new PhutilURI('/feed/')); - - $subnav->addFilter('all', 'All Activity', '/feed/'); - $subnav->addFilter('projects', 'My Projects'); - - $nav->appendChild($subnav); - - $filter = $subnav->selectFilter($this->subfilter, 'all'); - - $view = null; - switch ($filter) { - case 'all': - $view = $this->buildFeedView(array()); - break; - case 'projects': - if ($projects) { - $phids = mpull($projects, 'getPHID'); - $view = $this->buildFeedView($phids); - } else { - $view = new AphrontErrorView(); - $view->setSeverity(AphrontErrorView::SEVERITY_NODATA); - $view->setTitle('No Projects'); - $view->appendChild('You have not joined any projects.'); - } - break; - } - - $subnav->appendChild($view); - - return $this->buildStandardPageResponse( - $nav, - array( - 'title' => 'Feed', - )); - } - private function buildUnbreakNowPanel() { $user = $this->getRequest()->getUser(); $user_phid = $user->getPHID(); @@ -377,41 +334,6 @@ final class PhabricatorDirectoryMainController return $view; } - private function buildFeedView(array $phids) { - $request = $this->getRequest(); - $user = $request->getUser(); - $user_phid = $user->getPHID(); - - $feed_query = new PhabricatorFeedQuery(); - $feed_query->setViewer($user); - if ($phids) { - $feed_query->setFilterPHIDs($phids); - } - - $pager = new AphrontCursorPagerView(); - $pager->readFromRequest($request); - $pager->setPageSize(200); - - $feed = $feed_query->executeWithCursorPager($pager); - - $builder = new PhabricatorFeedBuilder($feed); - $builder->setUser($user); - $feed_view = $builder->buildView(); - - return - '
'. - '
'. - '

Feed

'. - '
'. - $feed_view->render(). - '
'. - $pager->render(). - '
'. - '
'; - } - private function buildJumpPanel($query=null) { $request = $this->getRequest(); $user = $request->getUser(); diff --git a/src/applications/feed/application/PhabricatorApplicationFeed.php b/src/applications/feed/application/PhabricatorApplicationFeed.php new file mode 100644 index 0000000000..2c089ac344 --- /dev/null +++ b/src/applications/feed/application/PhabricatorApplicationFeed.php @@ -0,0 +1,31 @@ + array( + 'public/' => 'PhabricatorFeedPublicStreamController', + '(?:(?P[^/]+)/)?' => 'PhabricatorFeedMainController', + ), + ); + } + + public function getApplicationGroup() { + return self::GROUP_COMMUNICATION; + } + +} + diff --git a/src/applications/feed/controller/PhabricatorFeedController.php b/src/applications/feed/controller/PhabricatorFeedController.php index d8d7c3c094..1e0c1afb20 100644 --- a/src/applications/feed/controller/PhabricatorFeedController.php +++ b/src/applications/feed/controller/PhabricatorFeedController.php @@ -22,4 +22,19 @@ abstract class PhabricatorFeedController extends PhabricatorController { return $response->setContent($page->render()); } + protected function buildSideNavView() { + $nav = new AphrontSideNavFilterView(); + $nav->setBaseURI(new PhutilURI($this->getApplicationURI())); + + $nav->addLabel('Feed'); + $nav->addFilter('all', 'All Activity'); + $nav->addFilter('projects', 'My Projects'); + + return $nav; + } + + protected function buildApplicationMenu() { + return $this->buildSideNavView()->getMenu(); + } + } diff --git a/src/applications/feed/controller/PhabricatorFeedMainController.php b/src/applications/feed/controller/PhabricatorFeedMainController.php new file mode 100644 index 0000000000..1aa8bab356 --- /dev/null +++ b/src/applications/feed/controller/PhabricatorFeedMainController.php @@ -0,0 +1,78 @@ +filter = idx($data, 'filter'); + } + + public function processRequest() { + $request = $this->getRequest(); + $user = $request->getUser(); + + $nav = $this->buildSideNavView(); + $filter = $nav->selectFilter($this->filter, 'all'); + + $pager = new AphrontCursorPagerView(); + $pager->readFromRequest($request); + $pager->setPageSize(200); + + + $query = id(new PhabricatorFeedQuery()) + ->setViewer($user); + + $nodata = null; + switch ($filter) { + case 'all': + $title = pht('Feed'); + break; + case 'projects': + $projects = id(new PhabricatorProjectQuery()) + ->setViewer($user) + ->withMemberPHIDs(array($user->getPHID())) + ->execute(); + + if (!$projects) { + $nodata = pht('You have not joined any projects.'); + } else { + $query->setFilterPHIDs(mpull($projects, 'getPHID')); + } + + $title = pht('Feed: My Projects'); + break; + } + + if ($nodata) { + $feed_view = id(new AphrontErrorView()) + ->setSeverity(AphrontErrorView::SEVERITY_NODATA) + ->setTitle(pht('No Stories')) + ->appendChild($nodata); + } else { + $feed = $query->executeWithCursorPager($pager); + + $builder = new PhabricatorFeedBuilder($feed); + $builder->setUser($user); + $feed_view = $builder->buildView(); + } + + $header = id(new PhabricatorHeaderView()) + ->setHeader($title); + + $nav->appendChild( + array( + $header, + $feed_view, + $pager, + )); + + return $this->buildApplicationPage( + $nav, + array( + 'title' => $title, + 'device' => true, + )); + } + +}