From b21b43131c143741942d8b8b4a1827401fee411e Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 11 May 2016 10:17:33 -0700 Subject: [PATCH] Clean up display of clone URIs a little bit Summary: Ref T10923. This makes the "Clone URI" UI a little nicer: - Show whether each URI is read-only, read-write, or external. - Clicking the button selects the URI. - Add a link to manage the appropriate credentials. Test Plan: {F1308302, size=full} Reviewers: chad Reviewed By: chad Maniphest Tasks: T10923 Differential Revision: https://secure.phabricator.com/D15891 --- resources/celerity/map.php | 13 +- src/__phutil_library_map__.php | 2 + .../DiffusionRepositoryController.php | 18 +-- .../diffusion/view/DiffusionCloneURIView.php | 131 ++++++++++++++++++ .../application/diffusion/diffusion-icons.css | 19 +++ .../rsrc/js/core/behavior-select-content.js | 23 +++ 6 files changed, 191 insertions(+), 15 deletions(-) create mode 100644 src/applications/diffusion/view/DiffusionCloneURIView.php create mode 100644 webroot/rsrc/js/core/behavior-select-content.js diff --git a/resources/celerity/map.php b/resources/celerity/map.php index 90d5720d2c..3e622a32b9 100644 --- a/resources/celerity/map.php +++ b/resources/celerity/map.php @@ -12,7 +12,7 @@ return array( 'darkconsole.pkg.js' => 'e7393ebb', 'differential.pkg.css' => '7ba78475', 'differential.pkg.js' => 'd0cd0df6', - 'diffusion.pkg.css' => 'dc8e0cc2', + 'diffusion.pkg.css' => '91c5d3a6', 'diffusion.pkg.js' => '3a9a8bfa', 'maniphest.pkg.css' => '4845691a', 'maniphest.pkg.js' => '949a7498', @@ -64,7 +64,7 @@ return array( 'rsrc/css/application/differential/revision-history.css' => '0e8eb855', 'rsrc/css/application/differential/revision-list.css' => 'f3c47d33', 'rsrc/css/application/differential/table-of-contents.css' => 'ae4b7a55', - 'rsrc/css/application/diffusion/diffusion-icons.css' => '3311444d', + 'rsrc/css/application/diffusion/diffusion-icons.css' => 'd678600a', 'rsrc/css/application/diffusion/diffusion-readme.css' => '297373eb', 'rsrc/css/application/diffusion/diffusion-source.css' => '68b30fd3', 'rsrc/css/application/feed/feed.css' => 'ecd4ec57', @@ -504,6 +504,7 @@ return array( 'rsrc/js/core/behavior-reveal-content.js' => '60821bc7', 'rsrc/js/core/behavior-scrollbar.js' => '834a1173', 'rsrc/js/core/behavior-search-typeahead.js' => '06c32383', + 'rsrc/js/core/behavior-select-content.js' => 'bf5374ef', 'rsrc/js/core/behavior-select-on-click.js' => '4e3e79a6', 'rsrc/js/core/behavior-time-typeahead.js' => '522431f7', 'rsrc/js/core/behavior-toggle-class.js' => '92b9ec77', @@ -557,7 +558,7 @@ return array( 'differential-revision-history-css' => '0e8eb855', 'differential-revision-list-css' => 'f3c47d33', 'differential-table-of-contents-css' => 'ae4b7a55', - 'diffusion-icons-css' => '3311444d', + 'diffusion-icons-css' => 'd678600a', 'diffusion-readme-css' => '297373eb', 'diffusion-source-css' => '68b30fd3', 'diviner-shared-css' => 'aa3656aa', @@ -685,6 +686,7 @@ return array( 'javelin-behavior-repository-crossreference' => 'e5339c43', 'javelin-behavior-scrollbar' => '834a1173', 'javelin-behavior-search-reorder-queries' => 'e9581f08', + 'javelin-behavior-select-content' => 'bf5374ef', 'javelin-behavior-select-on-click' => '4e3e79a6', 'javelin-behavior-slowvote-embed' => '887ad43f', 'javelin-behavior-stripe-payment-form' => '3f5d6dbf', @@ -1837,6 +1839,11 @@ return array( 'javelin-util', 'javelin-request', ), + 'bf5374ef' => array( + 'javelin-behavior', + 'javelin-stratcom', + 'javelin-dom', + ), 'bff6884b' => array( 'javelin-install', 'javelin-dom', diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 09fb23f221..74302c34e4 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -573,6 +573,7 @@ phutil_register_library_map(array( 'DiffusionCachedResolveRefsQuery' => 'applications/diffusion/query/DiffusionCachedResolveRefsQuery.php', 'DiffusionChangeController' => 'applications/diffusion/controller/DiffusionChangeController.php', 'DiffusionChangeHeraldFieldGroup' => 'applications/diffusion/herald/DiffusionChangeHeraldFieldGroup.php', + 'DiffusionCloneURIView' => 'applications/diffusion/view/DiffusionCloneURIView.php', 'DiffusionCommandEngine' => 'applications/diffusion/protocol/DiffusionCommandEngine.php', 'DiffusionCommandEngineTestCase' => 'applications/diffusion/protocol/__tests__/DiffusionCommandEngineTestCase.php', 'DiffusionCommitAffectedFilesHeraldField' => 'applications/diffusion/herald/DiffusionCommitAffectedFilesHeraldField.php', @@ -4792,6 +4793,7 @@ phutil_register_library_map(array( 'DiffusionCachedResolveRefsQuery' => 'DiffusionLowLevelQuery', 'DiffusionChangeController' => 'DiffusionController', 'DiffusionChangeHeraldFieldGroup' => 'HeraldFieldGroup', + 'DiffusionCloneURIView' => 'AphrontView', 'DiffusionCommandEngine' => 'Phobject', 'DiffusionCommandEngineTestCase' => 'PhabricatorTestCase', 'DiffusionCommitAffectedFilesHeraldField' => 'DiffusionCommitHeraldField', diff --git a/src/applications/diffusion/controller/DiffusionRepositoryController.php b/src/applications/diffusion/controller/DiffusionRepositoryController.php index 45fbf5c717..d38ad77787 100644 --- a/src/applications/diffusion/controller/DiffusionRepositoryController.php +++ b/src/applications/diffusion/controller/DiffusionRepositoryController.php @@ -669,8 +669,6 @@ final class DiffusionRepositoryController extends DiffusionController { PhabricatorRepository $repository, PhabricatorRepositoryURI $uri) { - require_celerity_resource('diffusion-icons-css'); - if ($repository->isSVN()) { $display = csprintf( 'svn checkout %R %R', @@ -681,17 +679,13 @@ final class DiffusionRepositoryController extends DiffusionController { } $display = (string)$display; + $viewer = $this->getViewer(); - $input = javelin_tag( - 'input', - array( - 'type' => 'text', - 'value' => $display, - 'class' => 'diffusion-clone-uri', - 'readonly' => 'true', - )); - - return $input; + return id(new DiffusionCloneURIView()) + ->setViewer($viewer) + ->setRepository($repository) + ->setRepositoryURI($uri) + ->setDisplayURI($display); } } diff --git a/src/applications/diffusion/view/DiffusionCloneURIView.php b/src/applications/diffusion/view/DiffusionCloneURIView.php new file mode 100644 index 0000000000..fc861ed183 --- /dev/null +++ b/src/applications/diffusion/view/DiffusionCloneURIView.php @@ -0,0 +1,131 @@ +repository = $repository; + return $this; + } + + public function getRepository() { + return $this->repository; + } + + public function setRepositoryURI(PhabricatorRepositoryURI $repository_uri) { + $this->repositoryURI = $repository_uri; + return $this; + } + + public function getRepositoryURI() { + return $this->repositoryURI; + } + + public function setDisplayURI($display_uri) { + $this->displayURI = $display_uri; + return $this; + } + + public function getDisplayURI() { + return $this->displayURI; + } + + public function render() { + require_celerity_resource('diffusion-icons-css'); + + Javelin::initBehavior('select-content'); + + $uri_id = celerity_generate_unique_node_id(); + + $display = $this->getDisplayURI(); + + $input = javelin_tag( + 'input', + array( + 'id' => $uri_id, + 'type' => 'text', + 'value' => $display, + 'class' => 'diffusion-clone-uri', + 'readonly' => 'true', + )); + + $uri = $this->getRepositoryURI(); + switch ($uri->getEffectiveIOType()) { + case PhabricatorRepositoryURI::IO_READ: + $io_icon = 'fa-eye'; + $io_tip = pht('Read-Only'); + break; + case PhabricatorRepositoryURI::IO_READWRITE: + $io_icon = 'fa-download'; + $io_tip = pht('Read / Write'); + break; + default: + $io_icon = 'fa-cloud'; + $io_tip = pht('External'); + break; + } + + $io = id(new PHUIButtonView()) + ->setTag('a') + ->setColor(PHUIButtonView::GREY) + ->setIcon($io_icon) + ->setHref('#') + ->addSigil('select-content') + ->addSigil('has-tooltip') + ->setMetadata( + array( + 'tip' => $io_tip, + 'selectID' => $uri_id, + )); + + switch ($uri->getEffectiveIOType()) { + case PhabricatorRepositoryURI::IO_READ: + case PhabricatorRepositoryURI::IO_READWRITE: + switch ($uri->getBuiltinProtocol()) { + case PhabricatorRepositoryURI::BUILTIN_PROTOCOL_SSH: + $auth_uri = '/settings/panel/ssh/'; + $auth_tip = pht('Manage SSH Keys'); + $auth_disabled = false; + break; + default: + $auth_uri = '/settings/panel/vcspassword'; + $auth_tip = pht('Manage Password'); + $auth_disabled = false; + break; + } + break; + default: + $auth_disabled = true; + $auth_tip = pht('External'); + $auth_uri = '#'; + break; + } + + $credentials = id(new PHUIButtonView()) + ->setTag('a') + ->setColor(PHUIButtonView::GREY) + ->setIcon('fa-key') + ->setTooltip($auth_tip) + ->setHref($auth_uri) + ->setDisabled($auth_disabled); + + $cells = array(); + $cells[] = phutil_tag('td', array(), $input); + $cells[] = phutil_tag('th', array(), $io); + $cells[] = phutil_tag('th', array(), $credentials); + + $row = phutil_tag('tr', array(), $cells); + + return phutil_tag( + 'table', + array( + 'class' => 'diffusion-clone-uri-table', + ), + $row); + } + +} diff --git a/webroot/rsrc/css/application/diffusion/diffusion-icons.css b/webroot/rsrc/css/application/diffusion/diffusion-icons.css index c735e3d842..0e00f6e46f 100644 --- a/webroot/rsrc/css/application/diffusion/diffusion-icons.css +++ b/webroot/rsrc/css/application/diffusion/diffusion-icons.css @@ -28,3 +28,22 @@ input.diffusion-clone-uri { .diffusion-search-boxen .phui-form-view { padding: 0; } + +.diffusion-clone-uri-table { + width: 100%; +} + +.diffusion-clone-uri-table th { + width: 24px; + padding: 0 0 0 4px; +} + +.diffusion-clone-uri-table th a.button { + width: 12px; + height: 19px; +} + +.diffusion-clone-uri-table th a.button .phui-icon-view { + left: 12px; + top: 7px; +} diff --git a/webroot/rsrc/js/core/behavior-select-content.js b/webroot/rsrc/js/core/behavior-select-content.js new file mode 100644 index 0000000000..b54b6308cf --- /dev/null +++ b/webroot/rsrc/js/core/behavior-select-content.js @@ -0,0 +1,23 @@ +/** + * @provides javelin-behavior-select-content + * @requires javelin-behavior + * javelin-stratcom + * javelin-dom + * @javelin + */ + +JX.behavior('select-content', function() { + JX.Stratcom.listen( + 'click', + 'select-content', + function(e) { + e.kill(); + + var node = e.getNode('select-content'); + var data = JX.Stratcom.getData(node); + + var target = JX.$(data.selectID); + JX.DOM.focus(target); + target.select(); + }); +});