1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 05:50:55 +01:00

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
This commit is contained in:
epriestley 2014-05-05 10:55:58 -07:00
parent b3476af5f0
commit 707c5aec81
8 changed files with 187 additions and 2 deletions

View file

@ -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',

View file

@ -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".

View file

@ -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())

View file

@ -19,6 +19,8 @@ final class PhabricatorApplicationTransactions extends PhabricatorApplication {
=> 'PhabricatorApplicationTransactionCommentRemoveController',
'history/(?<phid>[^/]+)/'
=> 'PhabricatorApplicationTransactionCommentHistoryController',
'quote/(?<phid>[^/]+)/'
=> 'PhabricatorApplicationTransactionCommentQuoteController',
'detail/(?<phid>[^/]+)/'
=> 'PhabricatorApplicationTransactionDetailController',
'(?P<value>old|new)/(?<phid>[^/]+)/'

View file

@ -0,0 +1,67 @@
<?php
final class PhabricatorApplicationTransactionCommentQuoteController
extends PhabricatorApplicationTransactionController {
private $phid;
public function willProcessRequest(array $data) {
$this->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,
));
}
}

View file

@ -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) {

View file

@ -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',

View file

@ -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',