From 7de17fb75ec344671a7c9add7f2161d760631d5c Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 5 Jan 2016 05:00:22 -0800 Subject: [PATCH] Modernize tag and branch controllers in Diffusion Summary: Ref T4245. Prepares these controllers to accept alternate identifers, plus minor spacing and layout fixes. Test Plan: Viewed tags, viewed branches. Reviewers: chad Reviewed By: chad Maniphest Tasks: T4245 Differential Revision: https://secure.phabricator.com/D14941 --- .../PhabricatorDiffusionApplication.php | 2 +- .../DiffusionBranchTableController.php | 37 ++++++++++-------- .../controller/DiffusionController.php | 27 +++++++------ .../controller/DiffusionTagListController.php | 39 +++++++++++-------- .../diffusion/request/DiffusionRequest.php | 6 +++ 5 files changed, 63 insertions(+), 48 deletions(-) diff --git a/src/applications/diffusion/application/PhabricatorDiffusionApplication.php b/src/applications/diffusion/application/PhabricatorDiffusionApplication.php index db967bad63..6be8f8ffe8 100644 --- a/src/applications/diffusion/application/PhabricatorDiffusionApplication.php +++ b/src/applications/diffusion/application/PhabricatorDiffusionApplication.php @@ -64,7 +64,7 @@ final class PhabricatorDiffusionApplication extends PhabricatorApplication { '(?:query/(?P[^/]+)/)?' => 'DiffusionPushLogListController', 'view/(?P\d+)/' => 'DiffusionPushEventViewController', ), - '(?P[A-Z]+)/' => array( + '(?P(?P[A-Z]+))/' => array( '' => 'DiffusionRepositoryController', 'repository/(?P.*)' => 'DiffusionRepositoryController', diff --git a/src/applications/diffusion/controller/DiffusionBranchTableController.php b/src/applications/diffusion/controller/DiffusionBranchTableController.php index 98157f8056..a040c8084e 100644 --- a/src/applications/diffusion/controller/DiffusionBranchTableController.php +++ b/src/applications/diffusion/controller/DiffusionBranchTableController.php @@ -6,15 +6,18 @@ final class DiffusionBranchTableController extends DiffusionController { return true; } - protected function processDiffusionRequest(AphrontRequest $request) { - $drequest = $this->getDiffusionRequest(); - $viewer = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $response = $this->loadDiffusionContext(); + if ($response) { + return $response; + } + $viewer = $this->getViewer(); + $drequest = $this->getDiffusionRequest(); $repository = $drequest->getRepository(); - $pager = new PHUIPagerView(); - $pager->setURI($request->getRequestURI(), 'offset'); - $pager->setOffset($request->getInt('offset')); + $pager = id(new PHUIPagerView()) + ->readFromRequest($request); // TODO: Add support for branches that contain commit $branches = $this->callConduitWithDiffusionRequest( @@ -57,18 +60,20 @@ final class DiffusionBranchTableController extends DiffusionController { 'branches' => true, )); - return $this->buildApplicationPage( - array( - $crumbs, - $content, - $pager, - ), - array( - 'title' => array( + $pager_box = $this->renderTablePagerBox($pager); + + return $this->newPage() + ->setTitle( + array( pht('Branches'), $repository->getDisplayName(), - ), - )); + )) + ->setCrumbs($crumbs) + ->appendChild( + array( + $content, + $pager_box, + )); } } diff --git a/src/applications/diffusion/controller/DiffusionController.php b/src/applications/diffusion/controller/DiffusionController.php index daff943438..dc916c7e9e 100644 --- a/src/applications/diffusion/controller/DiffusionController.php +++ b/src/applications/diffusion/controller/DiffusionController.php @@ -61,23 +61,16 @@ abstract class DiffusionController extends PhabricatorController { $identifier = (int)$request->getURIData('repositoryID'); } - $blob = $request->getURIData('dblob'); - if (strlen($blob)) { - $parsed = DiffusionRequest::parseRequestBlob($blob); - } else { - $parsed = array( - 'commit' => $request->getURIData('commit'), - 'path' => $request->getURIData('path'), - 'line' => $request->getURIData('line'), - 'branch' => $request->getURIData('branch'), - 'lint' => $request->getStr('lint'), - ); - } - $params = array( 'repository' => $identifier, 'user' => $viewer, - ) + $parsed; + 'blob' => $request->getURIData('dblob'), + 'commit' => $request->getURIData('commit'), + 'path' => $request->getURIData('path'), + 'line' => $request->getURIData('line'), + 'branch' => $request->getURIData('branch'), + 'lint' => $request->getStr('lint'), + ); $drequest = DiffusionRequest::newFromDictionary($params); @@ -286,4 +279,10 @@ abstract class DiffusionController extends PhabricatorController { ->appendChild($body); } + protected function renderTablePagerBox(PHUIPagerView $pager) { + return id(new PHUIBoxView()) + ->addMargin(PHUI::MARGIN_LARGE) + ->appendChild($pager); + } + } diff --git a/src/applications/diffusion/controller/DiffusionTagListController.php b/src/applications/diffusion/controller/DiffusionTagListController.php index a5e90bd46c..4749675bbb 100644 --- a/src/applications/diffusion/controller/DiffusionTagListController.php +++ b/src/applications/diffusion/controller/DiffusionTagListController.php @@ -6,22 +6,25 @@ final class DiffusionTagListController extends DiffusionController { return true; } - protected function processDiffusionRequest(AphrontRequest $request) { - $drequest = $this->getDiffusionRequest(); - $viewer = $request->getUser(); + public function handleRequest(AphrontRequest $request) { + $response = $this->loadDiffusionContext(); + if ($response) { + return $response; + } + $viewer = $this->getViewer(); + $drequest = $this->getDiffusionRequest(); $repository = $drequest->getRepository(); - $pager = new PHUIPagerView(); - $pager->setURI($request->getRequestURI(), 'offset'); - $pager->setOffset($request->getInt('offset')); + $pager = id(new PHUIPagerView()) + ->readFromRequest($request); $params = array( 'limit' => $pager->getPageSize() + 1, 'offset' => $pager->getOffset(), ); - if ($drequest->getSymbolicCommit()) { + if (strlen($drequest->getSymbolicCommit())) { $is_commit = true; $params['commit'] = $drequest->getSymbolicCommit(); } else { @@ -79,18 +82,20 @@ final class DiffusionTagListController extends DiffusionController { 'commit' => $drequest->getSymbolicCommit(), )); - return $this->buildApplicationPage( - array( - $crumbs, - $content, - $pager, - ), - array( - 'title' => array( + $pager_box = $this->renderTablePagerBox($pager); + + return $this->newPage() + ->setTitle( + array( pht('Tags'), $repository->getDisplayName(), - ), - )); + )) + ->setCrumbs($crumbs) + ->appendChild( + array( + $content, + $pager_box, + )); } } diff --git a/src/applications/diffusion/request/DiffusionRequest.php b/src/applications/diffusion/request/DiffusionRequest.php index a9a062167b..08b7c876c2 100644 --- a/src/applications/diffusion/request/DiffusionRequest.php +++ b/src/applications/diffusion/request/DiffusionRequest.php @@ -225,6 +225,12 @@ abstract class DiffusionRequest extends Phobject { * @task new */ final private function initializeFromDictionary(array $data) { + $blob = idx($data, 'blob'); + if (strlen($blob)) { + $blob = self::parseRequestBlob($blob, $this->supportsBranches()); + $data = $blob + $data; + } + $this->path = idx($data, 'path'); $this->line = idx($data, 'line'); $this->initFromConduit = idx($data, 'initFromConduit', true);