From 707c5aec81386cd4d5c440429f482921a4a97de0 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 5 May 2014 10:55:58 -0700 Subject: [PATCH] Add a quote action to Differential and Maniphest Summary: Ref T4119. This is ugly for now, but technically works. The comment area and transaction log don't realy know about each other, so for the moment the linking is a bit manual. Differential/Maniphest are special cases anyway. Test Plan: {F149992} Reviewers: chad, btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T4119 Differential Revision: https://secure.phabricator.com/D8957 --- src/__phutil_library_map__.php | 2 + .../DifferentialRevisionViewController.php | 8 ++- .../ManiphestTaskDetailController.php | 2 + .../PhabricatorApplicationTransactions.php | 2 + ...ationTransactionCommentQuoteController.php | 67 +++++++++++++++++++ .../PhabricatorApplicationTransactionView.php | 31 +++++++++ src/view/phui/PHUITimelineEventView.php | 45 +++++++++++++ .../transactions/behavior-transaction-list.js | 32 +++++++++ 8 files changed, 187 insertions(+), 2 deletions(-) create mode 100644 src/applications/transactions/controller/PhabricatorApplicationTransactionCommentQuoteController.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 36fee60a42..4bfae19988 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1164,6 +1164,7 @@ phutil_register_library_map(array( 'PhabricatorApplicationTransactionCommentEditor' => 'applications/transactions/editor/PhabricatorApplicationTransactionCommentEditor.php', 'PhabricatorApplicationTransactionCommentHistoryController' => 'applications/transactions/controller/PhabricatorApplicationTransactionCommentHistoryController.php', 'PhabricatorApplicationTransactionCommentQuery' => 'applications/transactions/query/PhabricatorApplicationTransactionCommentQuery.php', + 'PhabricatorApplicationTransactionCommentQuoteController' => 'applications/transactions/controller/PhabricatorApplicationTransactionCommentQuoteController.php', 'PhabricatorApplicationTransactionCommentRemoveController' => 'applications/transactions/controller/PhabricatorApplicationTransactionCommentRemoveController.php', 'PhabricatorApplicationTransactionCommentView' => 'applications/transactions/view/PhabricatorApplicationTransactionCommentView.php', 'PhabricatorApplicationTransactionController' => 'applications/transactions/controller/PhabricatorApplicationTransactionController.php', @@ -3936,6 +3937,7 @@ phutil_register_library_map(array( 'PhabricatorApplicationTransactionCommentEditor' => 'PhabricatorEditor', 'PhabricatorApplicationTransactionCommentHistoryController' => 'PhabricatorApplicationTransactionController', 'PhabricatorApplicationTransactionCommentQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', + 'PhabricatorApplicationTransactionCommentQuoteController' => 'PhabricatorApplicationTransactionController', 'PhabricatorApplicationTransactionCommentRemoveController' => 'PhabricatorApplicationTransactionController', 'PhabricatorApplicationTransactionCommentView' => 'AphrontView', 'PhabricatorApplicationTransactionController' => 'PhabricatorController', diff --git a/src/applications/differential/controller/DifferentialRevisionViewController.php b/src/applications/differential/controller/DifferentialRevisionViewController.php index f62fb62ea7..d767db70cf 100644 --- a/src/applications/differential/controller/DifferentialRevisionViewController.php +++ b/src/applications/differential/controller/DifferentialRevisionViewController.php @@ -256,6 +256,11 @@ final class DifferentialRevisionViewController extends DifferentialController { $target, $all_changesets); + if (!$viewer_is_anonymous) { + $comment_view->setQuoteRef('D'.$revision->getID()); + $comment_view->setQuoteTargetID('comment-content'); + } + $wrap_id = celerity_generate_unique_node_id(); $comment_view = phutil_tag( 'div', @@ -373,8 +378,6 @@ final class DifferentialRevisionViewController extends DifferentialController { $comment_form->setErrorView($review_warnings_panel); } - // TODO: Restore the ability for fields to add accept warnings. - $comment_form->setActions($this->getRevisionCommentActions($revision)); $action_uri = $this->getApplicationURI( 'comment/save/'.$revision->getID().'/'); @@ -415,6 +418,7 @@ final class DifferentialRevisionViewController extends DifferentialController { $changeset_view, )); if ($comment_form) { + $page_pane->appendChild($comment_form); } else { // TODO: For now, just use this to get "Login to Comment". diff --git a/src/applications/maniphest/controller/ManiphestTaskDetailController.php b/src/applications/maniphest/controller/ManiphestTaskDetailController.php index b6fae69d70..f47aa1da0c 100644 --- a/src/applications/maniphest/controller/ManiphestTaskDetailController.php +++ b/src/applications/maniphest/controller/ManiphestTaskDetailController.php @@ -377,6 +377,8 @@ final class ManiphestTaskDetailController extends ManiphestController { ->setFlush(true) ->setHeaderText($comment_header) ->appendChild($comment_form); + $timeline->setQuoteTargetID('transaction-comments'); + $timeline->setQuoteRef($object_name); } $object_box = id(new PHUIObjectBoxView()) diff --git a/src/applications/transactions/application/PhabricatorApplicationTransactions.php b/src/applications/transactions/application/PhabricatorApplicationTransactions.php index aa7f4da9d4..8dc14807f4 100644 --- a/src/applications/transactions/application/PhabricatorApplicationTransactions.php +++ b/src/applications/transactions/application/PhabricatorApplicationTransactions.php @@ -19,6 +19,8 @@ final class PhabricatorApplicationTransactions extends PhabricatorApplication { => 'PhabricatorApplicationTransactionCommentRemoveController', 'history/(?[^/]+)/' => 'PhabricatorApplicationTransactionCommentHistoryController', + 'quote/(?[^/]+)/' + => 'PhabricatorApplicationTransactionCommentQuoteController', 'detail/(?[^/]+)/' => 'PhabricatorApplicationTransactionDetailController', '(?Pold|new)/(?[^/]+)/' diff --git a/src/applications/transactions/controller/PhabricatorApplicationTransactionCommentQuoteController.php b/src/applications/transactions/controller/PhabricatorApplicationTransactionCommentQuoteController.php new file mode 100644 index 0000000000..2e20b1ac3b --- /dev/null +++ b/src/applications/transactions/controller/PhabricatorApplicationTransactionCommentQuoteController.php @@ -0,0 +1,67 @@ +phid = $data['phid']; + } + + public function processRequest() { + $request = $this->getRequest(); + $viewer = $request->getUser(); + + $xaction = id(new PhabricatorObjectQuery()) + ->withPHIDs(array($this->phid)) + ->setViewer($viewer) + ->executeOne(); + if (!$xaction) { + return new Aphront404Response(); + } + + if (!$xaction->getComment()) { + return new Aphront404Response(); + } + + if ($xaction->getComment()->getIsRemoved()) { + return new Aphront400Response(); + } + + if (!$xaction->hasComment()) { + return new Aphront404Response(); + } + + $content = $xaction->getComment()->getContent(); + $content = phutil_split_lines($content, true); + foreach ($content as $key => $line) { + if (strlen($line) && ($line[0] != '>')) { + $content[$key] = '> '.$line; + } else { + $content[$key] = '>'.$line; + } + } + $content = implode('', $content); + + $author = id(new PhabricatorHandleQuery()) + ->setViewer($viewer) + ->withPHIDs(array($xaction->getComment()->getAuthorPHID())) + ->executeOne(); + + $ref = $request->getStr('ref'); + if (strlen($ref)) { + $quote = pht('In %s, %s wrote:', $ref, '@'.$author->getName()); + } else { + $quote = pht('%s wrote:', '@'.$author->getName()); + } + + $content = ">>! {$quote}\n{$content}"; + + return id(new AphrontAjaxResponse())->setContent( + array( + 'quoteText' => $content, + )); + } + +} diff --git a/src/applications/transactions/view/PhabricatorApplicationTransactionView.php b/src/applications/transactions/view/PhabricatorApplicationTransactionView.php index 1a7ae7010d..0dd9358b36 100644 --- a/src/applications/transactions/view/PhabricatorApplicationTransactionView.php +++ b/src/applications/transactions/view/PhabricatorApplicationTransactionView.php @@ -12,6 +12,26 @@ class PhabricatorApplicationTransactionView extends AphrontView { private $isPreview; private $objectPHID; private $shouldTerminate = false; + private $quoteTargetID; + private $quoteRef; + + public function setQuoteRef($quote_ref) { + $this->quoteRef = $quote_ref; + return $this; + } + + public function getQuoteRef() { + return $this->quoteRef; + } + + public function setQuoteTargetID($quote_target_id) { + $this->quoteTargetID = $quote_target_id; + return $this; + } + + public function getQuoteTargetID() { + return $this->quoteTargetID; + } public function setObjectPHID($object_phid) { $this->objectPHID = $object_phid; @@ -376,6 +396,17 @@ class PhabricatorApplicationTransactionView extends AphrontView { $event->setIsEdited(true); } + // If we have a place for quoted text to go and this is a quotable + // comment, pass the quote target ID to the event view. + if ($this->getQuoteTargetID()) { + if ($xaction->hasComment()) { + if (!$has_removed_comment && !$has_deleted_comment) { + $event->setQuoteTargetID($this->getQuoteTargetID()); + $event->setQuoteRef($this->getQuoteRef()); + } + } + } + $can_edit = PhabricatorPolicyCapability::CAN_EDIT; if ($xaction->hasComment() || $has_deleted_comment) { diff --git a/src/view/phui/PHUITimelineEventView.php b/src/view/phui/PHUITimelineEventView.php index 0f2baa5030..e2c7371592 100644 --- a/src/view/phui/PHUITimelineEventView.php +++ b/src/view/phui/PHUITimelineEventView.php @@ -21,6 +21,26 @@ final class PHUITimelineEventView extends AphrontView { private $hideByDefault; private $token; private $tokenRemoved; + private $quoteTargetID; + private $quoteRef; + + public function setQuoteRef($quote_ref) { + $this->quoteRef = $quote_ref; + return $this; + } + + public function getQuoteRef() { + return $this->quoteRef; + } + + public function setQuoteTargetID($quote_target_id) { + $this->quoteTargetID = $quote_target_id; + return $this; + } + + public function getQuoteTargetID() { + return $this->quoteTargetID; + } public function setHideByDefault($hide_by_default) { $this->hideByDefault = $hide_by_default; @@ -357,6 +377,31 @@ final class PHUITimelineEventView extends AphrontView { } else { $xaction_phid = $this->getTransactionPHID(); + if ($this->getQuoteTargetID()) { + + $ref = null; + if ($this->getQuoteRef()) { + $ref = $this->getQuoteRef(); + if ($this->anchor) { + $ref = $ref.'#'.$this->anchor; + } + } + + $extra[] = javelin_tag( + 'a', + array( + 'href' => '#', + 'sigil' => 'transaction-quote', + 'mustcapture' => true, + 'meta' => array( + 'targetID' => $this->getQuoteTargetID(), + 'uri' => '/transactions/quote/'.$xaction_phid.'/', + 'ref' => $ref, + ), + ), + pht('Quote')); + } + if ($this->getIsEdited()) { $extra[] = javelin_tag( 'a', diff --git a/webroot/rsrc/js/application/transactions/behavior-transaction-list.js b/webroot/rsrc/js/application/transactions/behavior-transaction-list.js index 9f504e3a95..abed702c14 100644 --- a/webroot/rsrc/js/application/transactions/behavior-transaction-list.js +++ b/webroot/rsrc/js/application/transactions/behavior-transaction-list.js @@ -6,6 +6,7 @@ * javelin-dom * javelin-fx * javelin-util + * phabricator-textareautils */ JX.behavior('phabricator-transaction-list', function(config) { @@ -115,6 +116,37 @@ JX.behavior('phabricator-transaction-list', function(config) { e.kill(); }); + JX.DOM.listen( + list, + 'click', + 'transaction-quote', + function(e) { + e.kill(); + + var data = e.getNodeData('transaction-quote'); + new JX.Workflow(data.uri) + .setData({ref: data.ref}) + .setHandler(function(r) { + var textarea = JX.$(data.targetID); + + JX.DOM.scrollTo(textarea); + + var value = textarea.value; + if (value.length) { + value += "\n\n"; + } + value += r.quoteText; + value += "\n\n"; + textarea.value = value; + + JX.TextAreaUtils.setSelectionRange( + textarea, + textarea.value.length, + textarea.value.length); + }) + .start(); + }); + JX.Stratcom.listen( ['submit', 'didSyntheticSubmit'], 'transaction-append',