From 1227c8d5da65c6e79dfe97c5fcbd5e823876616e Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 19 Mar 2012 19:57:41 -0700 Subject: [PATCH] Add "View Options" dropdown to Differential / Audit Summary: Depends on D1921. Depends on D1899. Add the "View Options" dropdown menu to Diffusion, with options like "show standalone", "show raw file", "show all", etc. Test Plan: Viewed commits in Differential and Diffusion. Reviewers: davidreuss, nh, btrahan Reviewed By: btrahan CC: aran, epriestley Maniphest Tasks: T904 Differential Revision: https://secure.phabricator.com/D1932 --- .../DifferentialRevisionViewController.php | 6 +- .../DifferentialChangesetListView.php | 160 +++++++++++------- .../commit/DiffusionCommitController.php | 8 + .../diff/DiffusionDiffController.php | 25 +++ .../diffusion/controller/diff/__init__.php | 1 + .../differential/behavior-dropdown-menus.js | 22 ++- 6 files changed, 151 insertions(+), 71 deletions(-) diff --git a/src/applications/differential/controller/revisionview/DifferentialRevisionViewController.php b/src/applications/differential/controller/revisionview/DifferentialRevisionViewController.php index 322e682d9c..89185c28b0 100644 --- a/src/applications/differential/controller/revisionview/DifferentialRevisionViewController.php +++ b/src/applications/differential/controller/revisionview/DifferentialRevisionViewController.php @@ -243,7 +243,11 @@ final class DifferentialRevisionViewController extends DifferentialController { '/differential/comment/inline/edit/'.$revision->getID().'/'); } - $changeset_view->setStandaloneViews(true); + $changeset_view->setStandaloneURI('/differential/changeset/'); + $changeset_view->setRawFileURIs( + '/differential/changeset/?view=old', + '/differential/changeset/?view=new'); + $changeset_view->setUser($user); $changeset_view->setDiff($target); $changeset_view->setRenderingReferences($rendering_references); diff --git a/src/applications/differential/view/changesetlistview/DifferentialChangesetListView.php b/src/applications/differential/view/changesetlistview/DifferentialChangesetListView.php index 3344fb2469..0422d1bcc8 100644 --- a/src/applications/differential/view/changesetlistview/DifferentialChangesetListView.php +++ b/src/applications/differential/view/changesetlistview/DifferentialChangesetListView.php @@ -23,7 +23,11 @@ final class DifferentialChangesetListView extends AphrontView { private $inlineURI; private $renderURI = '/differential/changeset/'; private $whitespace; - private $standaloneViews; + + private $standaloneURI; + private $leftRawFileURI; + private $rightRawFileURI; + private $user; private $symbolIndexes = array(); private $repository; @@ -40,11 +44,6 @@ final class DifferentialChangesetListView extends AphrontView { return $this; } - public function setStandaloneViews($has_standalone_views) { - $this->standaloneViews = $has_standalone_views; - return $this; - } - public function setUser(PhabricatorUser $user) { $this->user = $user; return $this; @@ -89,22 +88,26 @@ final class DifferentialChangesetListView extends AphrontView { return $this->vsMap; } + public function setStandaloneURI($uri) { + $this->standaloneURI = $uri; + return $this; + } + + public function setRawFileURIs($l, $r) { + $this->leftRawFileURI = $l; + $this->rightRawFileURI = $r; + return $this; + } + public function render() { require_celerity_resource('differential-changeset-view-css'); $changesets = $this->changesets; - if ($this->standaloneViews) { - Javelin::initBehavior( - 'differential-dropdown-menus', - array()); - } - Javelin::initBehavior('buoyant', array()); $output = array(); $mapping = array(); - $repository = $this->repository; foreach ($changesets as $key => $changeset) { $file = $changeset->getFilename(); $class = 'differential-changeset'; @@ -116,59 +119,13 @@ final class DifferentialChangesetListView extends AphrontView { $detail = new DifferentialChangesetDetailView(); - $detail_button = null; - if ($this->standaloneViews) { - $detail_uri = new PhutilURI($this->renderURI); - $detail_uri->setQueryParams(array('ref' => $ref)); - - $diffusion_uri = null; - if ($repository) { - $diffusion_uri = $repository->getDiffusionBrowseURIForPath( - $changeset->getAbsoluteRepositoryPath($this->diff, $repository)); - } - - $meta = array( - 'detailURI' => - (string)$detail_uri->alter('whitespace', $this->whitespace), - 'diffusionURI' => $diffusion_uri, - 'containerID' => $detail->getID(), - ); - $change = $changeset->getChangeType(); - if ($change != DifferentialChangeType::TYPE_ADD) { - $meta['leftURI'] = (string)$detail_uri->alter('view', 'old'); - } - if ($change != DifferentialChangeType::TYPE_DELETE && - $change != DifferentialChangeType::TYPE_MULTICOPY) { - $meta['rightURI'] = (string)$detail_uri->alter('view', 'new'); - } - - if ($this->user && $repository) { - $path = ltrim( - $changeset->getAbsoluteRepositoryPath($this->diff, $repository), - '/'); - $line = 1; // TODO: get first changed line - $editor_link = $this->user->loadEditorLink($path, $line, $repository); - if ($editor_link) { - $meta['editor'] = $editor_link; - } else { - $meta['editorConfigure'] = '/settings/page/preferences/'; - } - } - - $detail_button = javelin_render_tag( - 'a', - array( - 'class' => 'button small grey', - 'meta' => $meta, - 'href' => $meta['detailURI'], - 'target' => '_blank', - 'sigil' => 'differential-view-options', - ), - "View Options \xE2\x96\xBC"); - } + $view_options = $this->renderViewOptionsDropdown( + $detail, + $ref, + $changeset); $detail->setChangeset($changeset); - $detail->addButton($detail_button); + $detail->addButton($view_options); $detail->setSymbolIndex(idx($this->symbolIndexes, $key)); $detail->setVsChangesetID(idx($this->vsMap, $changeset->getID())); @@ -250,4 +207,79 @@ final class DifferentialChangesetListView extends AphrontView { ); } + private function renderViewOptionsDropdown( + DifferentialChangesetDetailView $detail, + $ref, + DifferentialChangeset $changeset) { + + $meta = array(); + + $qparams = array( + 'ref' => $ref, + 'whitespace' => $this->whitespace, + ); + + if ($this->standaloneURI) { + $uri = new PhutilURI($this->standaloneURI); + $uri->setQueryParams($uri->getQueryParams() + $qparams); + $meta['standaloneURI'] = (string)$uri; + } + + $repository = $this->repository; + if ($repository) { + $meta['diffusionURI'] = $repository->getDiffusionBrowseURIForPath( + $changeset->getAbsoluteRepositoryPath($this->diff, $repository)); + } + + $change = $changeset->getChangeType(); + + if ($this->leftRawFileURI) { + if ($change != DifferentialChangeType::TYPE_ADD) { + $uri = new PhutilURI($this->leftRawFileURI); + $uri->setQueryParams($uri->getQueryParams() + $qparams); + $meta['leftURI'] = (string)$uri; + } + } + + if ($this->rightRawFileURI) { + if ($change != DifferentialChangeType::TYPE_DELETE && + $change != DifferentialChangeType::TYPE_MULTICOPY) { + $uri = new PhutilURI($this->rightRawFileURI); + $uri->setQueryParams($uri->getQueryParams() + $qparams); + $meta['rightURI'] = (string)$uri; + } + } + + $user = $this->user; + if ($user && $repository) { + $path = ltrim( + $changeset->getAbsoluteRepositoryPath($this->diff, $repository), + '/'); + $line = 1; // TODO: get first changed line + $editor_link = $user->loadEditorLink($path, $line, $repository); + if ($editor_link) { + $meta['editor'] = $editor_link; + } else { + $meta['editorConfigure'] = '/settings/page/preferences/'; + } + } + + $meta['containerID'] = $detail->getID(); + + Javelin::initBehavior( + 'differential-dropdown-menus', + array()); + + return javelin_render_tag( + 'a', + array( + 'class' => 'button small grey', + 'meta' => $meta, + 'href' => idx($meta, 'detailURI', '#'), + 'target' => '_blank', + 'sigil' => 'differential-view-options', + ), + "View Options \xE2\x96\xBC"); + } + } diff --git a/src/applications/diffusion/controller/commit/DiffusionCommitController.php b/src/applications/diffusion/controller/commit/DiffusionCommitController.php index 4cbbce85b1..9b4e9a7d8e 100644 --- a/src/applications/diffusion/controller/commit/DiffusionCommitController.php +++ b/src/applications/diffusion/controller/commit/DiffusionCommitController.php @@ -223,6 +223,14 @@ final class DiffusionCommitController extends DiffusionController { $change_list->setRenderURI('/diffusion/'.$callsign.'/diff/'); $change_list->setUser($user); + $change_list->setStandaloneURI( + '/diffusion/'.$callsign.'/diff/'); + $change_list->setRawFileURIs( + // TODO: Implement this, somewhat tricky if there's an octopus merge + // or whatever? + null, + '/diffusion/'.$callsign.'/diff/?view=r'); + $change_list->setInlineCommentControllerURI( '/diffusion/inline/'.phutil_escape_uri($commit->getPHID()).'/'); diff --git a/src/applications/diffusion/controller/diff/DiffusionDiffController.php b/src/applications/diffusion/controller/diff/DiffusionDiffController.php index 5da607e117..f9f73b2d78 100644 --- a/src/applications/diffusion/controller/diff/DiffusionDiffController.php +++ b/src/applications/diffusion/controller/diff/DiffusionDiffController.php @@ -32,6 +32,31 @@ final class DiffusionDiffController extends DiffusionController { $request = $this->getRequest(); $user = $request->getUser(); + if (!$request->isAjax()) { + + // This request came out of the dropdown menu, either "View Standalone" + // or "View Raw File". + + $view = $request->getStr('view'); + if ($view == 'r') { + $uri = $drequest->generateURI( + array( + 'action' => 'browse', + 'params' => array( + 'view' => 'raw', + ), + )); + } else { + $uri = $drequest->generateURI( + array( + 'action' => 'change', + )); + } + + return id(new AphrontRedirectResponse())->setURI($uri); + } + + $diff_query = DiffusionDiffQuery::newFromDiffusionRequest($drequest); $changeset = $diff_query->loadChangeset(); diff --git a/src/applications/diffusion/controller/diff/__init__.php b/src/applications/diffusion/controller/diff/__init__.php index c85129d9ff..fc75cd6c64 100644 --- a/src/applications/diffusion/controller/diff/__init__.php +++ b/src/applications/diffusion/controller/diff/__init__.php @@ -7,6 +7,7 @@ phutil_require_module('phabricator', 'aphront/response/404'); +phutil_require_module('phabricator', 'aphront/response/redirect'); phutil_require_module('phabricator', 'applications/audit/storage/inlinecommment'); phutil_require_module('phabricator', 'applications/differential/parser/changeset'); phutil_require_module('phabricator', 'applications/diffusion/controller/base'); diff --git a/webroot/rsrc/js/application/differential/behavior-dropdown-menus.js b/webroot/rsrc/js/application/differential/behavior-dropdown-menus.js index 73dba5650b..7c7c3958c8 100644 --- a/webroot/rsrc/js/application/differential/behavior-dropdown-menus.js +++ b/webroot/rsrc/js/application/differential/behavior-dropdown-menus.js @@ -41,27 +41,37 @@ JX.behavior('differential-dropdown-menus', function(config) { var reveal_item = new JX.PhabricatorMenuItem('', show_more); - var diffusion_item = link_to('Browse in Diffusion', data.diffusionURI); - if (!data.diffusionURI) { - diffusion_item.setDisabled(true); + var diffusion_item; + if (data.diffusionURI) { + // Show this only if we have a link, since when this appears in Diffusion + // it is otherwise potentially confusing. + diffusion_item = link_to('Browse in Diffusion', data.diffusionURI); } var menu = new JX.PhabricatorDropdownMenu(buttons[ii]) - .addItem(reveal_item) - .addItem(diffusion_item) - .addItem(link_to('View Standalone', data.detailURI)); + .addItem(reveal_item); + + if (diffusion_item) { + menu.addItem(diffusion_item); + } + + menu.addItem(link_to('View Standalone', data.standaloneURI)); + if (data.leftURI) { menu.addItem(link_to('Show Raw File (Left)', data.leftURI)); } + if (data.rightURI) { menu.addItem(link_to('Show Raw File (Right)', data.rightURI)); } + if (data.editor) { menu.addItem(new JX.PhabricatorMenuItem( 'Open in Editor', JX.bind(null, location.assign, data.editor), // Open in the same window. data.editor)); } + if (data.editorConfigure) { menu.addItem(link_to('Configure Editor', data.editorConfigure)); }