From bb4cf7d6b37ef6de2032cc9ebbe72515307b20ae Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 24 Jun 2011 12:21:48 -0700 Subject: [PATCH] Add an "Add CCs" action to Differential Summary: We currently have only an "Add reviewers" action, add "Add CCs". This can also be accomplished less-discoverably with mentions. Test Plan: Added reviewers and CCs to revisions. Toggled display between reviewers and CCs. Reviewed By: jungejason Reviewers: tomo, mroch, jsp, jungejason, aran, tuomaspelkonen CC: aran, jungejason Differential Revision: 521 --- src/__celerity_resource_map__.php | 8 +-- .../constants/action/DifferentialAction.php | 3 ++ .../DifferentialCommentSaveController.php | 2 + .../DifferentialRevisionViewController.php | 9 ++++ .../comment/DifferentialCommentEditor.php | 37 ++++++++++++++ .../storage/comment/DifferentialComment.php | 3 +- .../addcomment/DifferentialAddCommentView.php | 25 +++++++-- .../DifferentialRevisionCommentView.php | 23 +++++++-- .../behavior-add-reviewers-and-ccs.js | 51 +++++++++++++++++++ .../differential/behavior-add-reviewers.js | 35 ------------- 10 files changed, 147 insertions(+), 49 deletions(-) create mode 100644 webroot/rsrc/js/application/differential/behavior-add-reviewers-and-ccs.js delete mode 100644 webroot/rsrc/js/application/differential/behavior-add-reviewers.js diff --git a/src/__celerity_resource_map__.php b/src/__celerity_resource_map__.php index 84a976d8a3..5ad6c5afac 100644 --- a/src/__celerity_resource_map__.php +++ b/src/__celerity_resource_map__.php @@ -381,9 +381,9 @@ celerity_register_resource_map(array( ), 'disk' => '/rsrc/js/application/differential/behavior-accept-with-errors.js', ), - 'javelin-behavior-differential-add-reviewers' => + 'javelin-behavior-differential-add-reviewers-and-ccs' => array( - 'uri' => '/res/dc79790c/rsrc/js/application/differential/behavior-add-reviewers.js', + 'uri' => '/res/fc352745/rsrc/js/application/differential/behavior-add-reviewers-and-ccs.js', 'type' => 'js', 'requires' => array( @@ -393,7 +393,7 @@ celerity_register_resource_map(array( 3 => 'javelin-typeahead', 4 => 'javelin-typeahead-preloaded-source', ), - 'disk' => '/rsrc/js/application/differential/behavior-add-reviewers.js', + 'disk' => '/rsrc/js/application/differential/behavior-add-reviewers-and-ccs.js', ), 'javelin-behavior-differential-comment-jump' => array( @@ -893,7 +893,7 @@ celerity_register_resource_map(array( ), 'maniphest-task-summary-css' => array( - 'uri' => '/res/e86389c4/rsrc/css/application/maniphest/task-summary.css', + 'uri' => '/res/14cb4b5d/rsrc/css/application/maniphest/task-summary.css', 'type' => 'css', 'requires' => array( diff --git a/src/applications/differential/constants/action/DifferentialAction.php b/src/applications/differential/constants/action/DifferentialAction.php index 49633d60e9..c39d10803e 100644 --- a/src/applications/differential/constants/action/DifferentialAction.php +++ b/src/applications/differential/constants/action/DifferentialAction.php @@ -32,6 +32,7 @@ final class DifferentialAction { const ACTION_TESTPLAN = 'testplan'; const ACTION_CREATE = 'create'; const ACTION_ADDREVIEWERS = 'add_reviewers'; + const ACTION_ADDCCS = 'add_ccs'; public static function getActionPastTenseVerb($action) { static $verbs = array( @@ -49,6 +50,7 @@ final class DifferentialAction { self::ACTION_TESTPLAN => 'explained the test plan for', self::ACTION_CREATE => 'created', self::ACTION_ADDREVIEWERS => 'added reviewers to', + self::ACTION_ADDCCS => 'added CCs to', ); if (!empty($verbs[$action])) { @@ -69,6 +71,7 @@ final class DifferentialAction { self::ACTION_RECLAIM => 'Reclaim Revision', self::ACTION_RESIGN => 'Resign as Reviewer', self::ACTION_ADDREVIEWERS => 'Add Reviewers', + self::ACTION_ADDCCS => 'Add CCs', ); if (!empty($verbs[$action])) { diff --git a/src/applications/differential/controller/commentsave/DifferentialCommentSaveController.php b/src/applications/differential/controller/commentsave/DifferentialCommentSaveController.php index 70fcd2d9f2..6355d44240 100644 --- a/src/applications/differential/controller/commentsave/DifferentialCommentSaveController.php +++ b/src/applications/differential/controller/commentsave/DifferentialCommentSaveController.php @@ -33,6 +33,7 @@ class DifferentialCommentSaveController extends DifferentialController { $comment = $request->getStr('comment'); $action = $request->getStr('action'); $reviewers = $request->getArr('reviewers'); + $ccs = $request->getArr('ccs'); $editor = new DifferentialCommentEditor( $revision, @@ -44,6 +45,7 @@ class DifferentialCommentSaveController extends DifferentialController { ->setAttachInlineComments(true) ->setAddCC($action != DifferentialAction::ACTION_RESIGN) ->setAddedReviewers($reviewers) + ->setAddedCCs($ccs) ->save(); // TODO: Diff change detection? diff --git a/src/applications/differential/controller/revisionview/DifferentialRevisionViewController.php b/src/applications/differential/controller/revisionview/DifferentialRevisionViewController.php index 84cc22647c..c334249482 100644 --- a/src/applications/differential/controller/revisionview/DifferentialRevisionViewController.php +++ b/src/applications/differential/controller/revisionview/DifferentialRevisionViewController.php @@ -89,6 +89,14 @@ class DifferentialRevisionViewController extends DifferentialController { $object_phids[] = $phid; } } + $added_ccs = idx( + $metadata, + DifferentialComment::METADATA_ADDED_CCS); + if ($added_ccs) { + foreach ($added_ccs as $phid) { + $object_phids[] = $phid; + } + } } foreach ($revision->getAttached() as $type => $phids) { @@ -570,6 +578,7 @@ class DifferentialRevisionViewController extends DifferentialController { } $actions[DifferentialAction::ACTION_ADDREVIEWERS] = true; + $actions[DifferentialAction::ACTION_ADDCCS] = true; return array_keys(array_filter($actions)); } diff --git a/src/applications/differential/editor/comment/DifferentialCommentEditor.php b/src/applications/differential/editor/comment/DifferentialCommentEditor.php index a12adcd878..d2690e019f 100644 --- a/src/applications/differential/editor/comment/DifferentialCommentEditor.php +++ b/src/applications/differential/editor/comment/DifferentialCommentEditor.php @@ -27,6 +27,7 @@ class DifferentialCommentEditor { protected $addCC; protected $changedByCommit; protected $addedReviewers = array(); + private $addedCCs = array(); private $parentMessageID; @@ -78,6 +79,15 @@ class DifferentialCommentEditor { return $this->addedReviewers; } + public function setAddedCCs($added_ccs) { + $this->addedCCs = $added_ccs; + return $this; + } + + public function getAddedCCs() { + return $this->addedCCs; + } + public function save() { $revision = $this->revision; $action = $this->action; @@ -258,7 +268,34 @@ class DifferentialCommentEditor { $action = DifferentialAction::ACTION_COMMENT; } break; + case DifferentialAction::ACTION_ADDCCS: + $added_ccs = $this->getAddedCCs(); + $current_ccs = $revision->getCCPHIDs(); + if ($current_ccs) { + $current_ccs = array_combine($current_ccs, $current_ccs); + foreach ($added_ccs as $k => $cc) { + if (isset($current_ccs[$cc])) { + unset($added_ccs[$k]); + } + } + } + + if ($added_ccs) { + foreach ($added_ccs as $cc) { + DifferentialRevisionEditor::addCC( + $revision, + $cc, + $this->actorPHID); + } + + $key = DifferentialComment::METADATA_ADDED_CCS; + $metadata[$key] = $added_ccs; + + } else { + $action = DifferentialAction::ACTION_COMMENT; + } + break; default: throw new Exception('Unsupported action.'); } diff --git a/src/applications/differential/storage/comment/DifferentialComment.php b/src/applications/differential/storage/comment/DifferentialComment.php index 8eebf0afe3..674ea034f3 100644 --- a/src/applications/differential/storage/comment/DifferentialComment.php +++ b/src/applications/differential/storage/comment/DifferentialComment.php @@ -18,7 +18,8 @@ class DifferentialComment extends DifferentialDAO { - const METADATA_ADDED_REVIEWERS = 'added-reviewers'; + const METADATA_ADDED_REVIEWERS = 'added-reviewers'; + const METADATA_ADDED_CCS = 'added-ccs'; protected $authorPHID; protected $revisionID; diff --git a/src/applications/differential/view/addcomment/DifferentialAddCommentView.php b/src/applications/differential/view/addcomment/DifferentialAddCommentView.php index 5ebadc8699..9b177498f3 100644 --- a/src/applications/differential/view/addcomment/DifferentialAddCommentView.php +++ b/src/applications/differential/view/addcomment/DifferentialAddCommentView.php @@ -93,6 +93,14 @@ final class DifferentialAddCommentView extends AphrontView { ->setControlStyle('display: none') ->setID('add-reviewers-tokenizer') ->setDisableBehavior(true)) + ->appendChild( + id(new AphrontFormTokenizerControl()) + ->setLabel('Add CCs') + ->setName('ccs') + ->setControlID('add-ccs') + ->setControlStyle('display: none') + ->setID('add-ccs-tokenizer') + ->setDisableBehavior(true)) ->appendChild( id(new AphrontFormTextAreaControl()) ->setName('comment') @@ -104,12 +112,21 @@ final class DifferentialAddCommentView extends AphrontView { ->setValue('Clowncopterize')); Javelin::initBehavior( - 'differential-add-reviewers', + 'differential-add-reviewers-and-ccs', array( - 'src' => '/typeahead/common/users/', - 'tokenizer' => 'add-reviewers-tokenizer', + 'dynamic' => array( + 'add_reviewers' => array( + 'tokenizer' => 'add-reviewers-tokenizer', + 'src' => '/typeahead/common/users/', + 'row' => 'add-reviewers', + ), + 'add_ccs' => array( + 'tokenizer' => 'add-ccs-tokenizer', + 'src' => '/typeahead/common/mailable/', + 'row' => 'add-ccs', + ), + ), 'select' => 'comment-action', - 'row' => 'add-reviewers', )); $diff = $revision->loadActiveDiff(); diff --git a/src/applications/differential/view/revisioncomment/DifferentialRevisionCommentView.php b/src/applications/differential/view/revisioncomment/DifferentialRevisionCommentView.php index 7b08c5d85d..8976952bc0 100644 --- a/src/applications/differential/view/revisioncomment/DifferentialRevisionCommentView.php +++ b/src/applications/differential/view/revisioncomment/DifferentialRevisionCommentView.php @@ -231,14 +231,19 @@ final class DifferentialRevisionCommentView extends AphrontView { $metadata, DifferentialComment::METADATA_ADDED_REVIEWERS); if ($added_reviewers) { - $reviewers = array(); - foreach ($added_reviewers as $phid) { - $reviewers[] = $this->handles[$phid]->renderLink(); - } - $reviewers = 'Added reviewers: '.implode(', ', $reviewers); + $reviewers = 'Added reviewers: '.$this->renderHandleList( + $added_reviewers); $metadata_blocks[] = $reviewers; } + $added_ccs = idx( + $metadata, + DifferentialComment::METADATA_ADDED_CCS); + if ($added_ccs) { + $ccs = 'Added CCs: '.$this->renderHandleList($added_ccs); + $metadata_blocks[] = $ccs; + } + if ($metadata_blocks) { $metadata_blocks = '
'. @@ -271,4 +276,12 @@ final class DifferentialRevisionCommentView extends AphrontView { '
'); } + private function renderHandleList(array $phids) { + $result = array(); + foreach ($phids as $phid) { + $result[] = $this->handles[$phid]->renderLink(); + } + return implode(', ', $result); + } + } diff --git a/webroot/rsrc/js/application/differential/behavior-add-reviewers-and-ccs.js b/webroot/rsrc/js/application/differential/behavior-add-reviewers-and-ccs.js new file mode 100644 index 0000000000..e4759d4ea3 --- /dev/null +++ b/webroot/rsrc/js/application/differential/behavior-add-reviewers-and-ccs.js @@ -0,0 +1,51 @@ +/** + * @provides javelin-behavior-differential-add-reviewers-and-ccs + * @requires javelin-behavior + * javelin-dom + * javelin-tokenizer + * javelin-typeahead + * javelin-typeahead-preloaded-source + */ + +JX.behavior('differential-add-reviewers-and-ccs', function(config) { + + function buildTokenizer(props) { + var root = JX.$(props.tokenizer); + var datasource = new JX.TypeaheadPreloadedSource(props.src); + + var typeahead = new JX.Typeahead(root); + typeahead.setDatasource(datasource); + + var tokenizer = new JX.Tokenizer(root); + tokenizer.setTypeahead(typeahead); + tokenizer.start(); + + return tokenizer; + } + + var dynamic = {}; + for (var k in config.dynamic) { + props = config.dynamic[k]; + dynamic[k] = { + row : JX.$(props.row), + tokenizer : buildTokenizer(props) + }; + } + + JX.DOM.listen( + JX.$(config.select), + 'change', + null, + function(e) { + var v = JX.$(config.select).value; + for (var k in dynamic) { + if (v == k) { + JX.DOM.show(dynamic[k].row); + dynamic[k].tokenizer.refresh(); + } else { + JX.DOM.hide(dynamic[k].row); + } + } + }); +}); + diff --git a/webroot/rsrc/js/application/differential/behavior-add-reviewers.js b/webroot/rsrc/js/application/differential/behavior-add-reviewers.js deleted file mode 100644 index a90f9924d3..0000000000 --- a/webroot/rsrc/js/application/differential/behavior-add-reviewers.js +++ /dev/null @@ -1,35 +0,0 @@ -/** - * @provides javelin-behavior-differential-add-reviewers - * @requires javelin-behavior - * javelin-dom - * javelin-tokenizer - * javelin-typeahead - * javelin-typeahead-preloaded-source - */ - -JX.behavior('differential-add-reviewers', function(config) { - - var root = JX.$(config.tokenizer); - var datasource = new JX.TypeaheadPreloadedSource(config.src); - - var typeahead = new JX.Typeahead(root); - typeahead.setDatasource(datasource); - - var tokenizer = new JX.Tokenizer(root); - tokenizer.setTypeahead(typeahead); - tokenizer.start(); - - JX.DOM.listen( - JX.$(config.select), - 'change', - null, - function(e) { - if (JX.$(config.select).value == 'add_reviewers') { - JX.DOM.show(JX.$(config.row)); - tokenizer.refresh(); - } else { - JX.DOM.hide(JX.$(config.row)); - } - }); -}); -