From bd350abbe91c1d13764c7d7b756ee2c9617d009e Mon Sep 17 00:00:00 2001 From: Anh Nhan Nguyen Date: Mon, 15 Apr 2013 06:52:28 -0700 Subject: [PATCH] Probably added app menu for mobile Summary: Messy POC. I hope I did this one right :P Refs T2014 Test Plan: Switched browser forcefully into `device-phone`, saw filters in the menu top right. Browsed around Differential in desktop mode, nothing was broken, I think. Reviewers: epriestley, chad, btrahan CC: aran, Korvin Maniphest Tasks: T2014 Differential Revision: https://secure.phabricator.com/D5693 --- .../controller/DifferentialController.php | 64 ++++++++++++++++++- .../DifferentialRevisionListController.php | 50 +-------------- 2 files changed, 64 insertions(+), 50 deletions(-) diff --git a/src/applications/differential/controller/DifferentialController.php b/src/applications/differential/controller/DifferentialController.php index 9d79c82f14..332b76d466 100644 --- a/src/applications/differential/controller/DifferentialController.php +++ b/src/applications/differential/controller/DifferentialController.php @@ -10,8 +10,6 @@ abstract class DifferentialController extends PhabricatorController { require_celerity_resource('differential-core-view-css'); - $viewer_is_anonymous = !$this->getRequest()->getUser()->isLoggedIn(); - $page = $this->buildStandardPageView(); $page->setApplicationName(pht('Differential')); $page->setBaseURI('/differential/'); @@ -27,7 +25,6 @@ abstract class DifferentialController extends PhabricatorController { public function buildApplicationCrumbs() { $crumbs = parent::buildApplicationCrumbs(); - $create_uri = new PhutilURI('/differential/diff/create/'); $crumbs->addAction( id(new PhabricatorMenuItemView()) ->setHref($this->getApplicationURI('/diff/create/')) @@ -37,4 +34,65 @@ abstract class DifferentialController extends PhabricatorController { return $crumbs; } + public function buildSideNav($filter = null, + $for_app = false, $username = null) { + + $viewer_is_anonymous = !$this->getRequest()->getUser()->isLoggedIn(); + + $uri = id(new PhutilURI('/differential/filter/')) + ->setQueryParams($this->getRequest()->getRequestURI()->getQueryParams()); + $filters = $this->getFilters(); + $filter = $this->selectFilter($filters, $filter, $viewer_is_anonymous); + + $side_nav = new AphrontSideNavFilterView(); + $side_nav->setBaseURI($uri); + foreach ($filters as $filter) { + list($filter_name, $display_name) = $filter; + if ($filter_name) { + $side_nav->addFilter($filter_name.'/'.$username, $display_name); + } else { + $side_nav->addLabel($display_name); + } + } + + return $side_nav; + } + + protected function getFilters() { + return array( + array(null, pht('User Revisions')), + array('active', pht('Active')), + array('revisions', pht('Revisions')), + array('reviews', pht('Reviews')), + array('subscribed', pht('Subscribed')), + array('drafts', pht('Draft Reviews')), + array(null, pht('All Revisions')), + array('all', pht('All')), + ); + } + + protected function selectFilter( + array $filters, + $requested_filter, + $viewer_is_anonymous) { + + $default_filter = ($viewer_is_anonymous ? 'all' : 'active'); + + // If the user requested a filter, make sure it actually exists. + if ($requested_filter) { + foreach ($filters as $filter) { + if ($filter[0] === $requested_filter) { + return $requested_filter; + } + } + } + + // If not, return the default filter. + return $default_filter; + } + + public function buildApplicationMenu() { + return $this->buildSideNav(null, true)->getMenu(); + } + } diff --git a/src/applications/differential/controller/DifferentialRevisionListController.php b/src/applications/differential/controller/DifferentialRevisionListController.php index e54143a466..88393f61cc 100644 --- a/src/applications/differential/controller/DifferentialRevisionListController.php +++ b/src/applications/differential/controller/DifferentialRevisionListController.php @@ -17,7 +17,6 @@ final class DifferentialRevisionListController extends DifferentialController { public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); - $viewer_is_anonymous = !$user->isLoggedIn(); $params = array_filter( array( @@ -26,12 +25,9 @@ final class DifferentialRevisionListController extends DifferentialController { )); $params['participants'] = $request->getArr('participants'); - $default_filter = ($viewer_is_anonymous ? 'all' : 'active'); $filters = $this->getFilters(); - $this->filter = $this->selectFilter( - $filters, - $this->filter, - $default_filter); + $this->filter = $this->selectFilter($filters, + $this->filter, !$user->isLoggedIn()); // Redirect from search to canonical URL. $phid_arr = $request->getArr('view_users'); @@ -80,16 +76,7 @@ final class DifferentialRevisionListController extends DifferentialController { 'order' => 'modified', ); - $side_nav = new AphrontSideNavFilterView(); - $side_nav->setBaseURI(id(clone $uri)->setPath('/differential/filter/')); - foreach ($filters as $filter) { - list($filter_name, $display_name) = $filter; - if ($filter_name) { - $side_nav->addFilter($filter_name.'/'.$username, $display_name); - } else { - $side_nav->addLabel($display_name); - } - } + $side_nav = $this->buildSideNav($this->filter, false, $username); $side_nav->selectFilter($this->filter.'/'.$username, null); $panels = array(); @@ -202,37 +189,6 @@ final class DifferentialRevisionListController extends DifferentialController { )); } - private function getFilters() { - return array( - array(null, pht('User Revisions')), - array('active', pht('Active')), - array('revisions', pht('Revisions')), - array('reviews', pht('Reviews')), - array('subscribed', pht('Subscribed')), - array('drafts', pht('Draft Reviews')), - array(null, pht('All Revisions')), - array('all', pht('All')), - ); - } - - private function selectFilter( - array $filters, - $requested_filter, - $default_filter) { - - // If the user requested a filter, make sure it actually exists. - if ($requested_filter) { - foreach ($filters as $filter) { - if ($filter[0] === $requested_filter) { - return $requested_filter; - } - } - } - - // If not, return the default filter. - return $default_filter; - } - private function getFilterRequiresUser($filter) { static $requires = array( 'active' => true,