mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-23 15:22:41 +01:00
Restore comments on Ponder answers
Summary: Ref T3373. This is still pretty messy: - The JS bugs out a bit with multiple primary object PHIDs on a single page. I'll fix this in a followup. - The comment form itself is enormous, I'll restore some show/hide stuff in a followup. Test Plan: Added answer comments in Ponder. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T3373 Differential Revision: https://secure.phabricator.com/D6608
This commit is contained in:
parent
946a5cd5ce
commit
4be9ccaea8
8 changed files with 144 additions and 29 deletions
|
@ -2179,7 +2179,7 @@ celerity_register_resource_map(array(
|
||||||
),
|
),
|
||||||
'javelin-behavior-phabricator-transaction-comment-form' =>
|
'javelin-behavior-phabricator-transaction-comment-form' =>
|
||||||
array(
|
array(
|
||||||
'uri' => '/res/dddc07e9/rsrc/js/application/transactions/behavior-transaction-comment-form.js',
|
'uri' => '/res/3c8d3c10/rsrc/js/application/transactions/behavior-transaction-comment-form.js',
|
||||||
'type' => 'js',
|
'type' => 'js',
|
||||||
'requires' =>
|
'requires' =>
|
||||||
array(
|
array(
|
||||||
|
|
|
@ -1870,6 +1870,7 @@ phutil_register_library_map(array(
|
||||||
'PonderAddAnswerView' => 'applications/ponder/view/PonderAddAnswerView.php',
|
'PonderAddAnswerView' => 'applications/ponder/view/PonderAddAnswerView.php',
|
||||||
'PonderAddCommentView' => 'applications/ponder/view/PonderAddCommentView.php',
|
'PonderAddCommentView' => 'applications/ponder/view/PonderAddCommentView.php',
|
||||||
'PonderAnswer' => 'applications/ponder/storage/PonderAnswer.php',
|
'PonderAnswer' => 'applications/ponder/storage/PonderAnswer.php',
|
||||||
|
'PonderAnswerCommentController' => 'applications/ponder/controller/PonderAnswerCommentController.php',
|
||||||
'PonderAnswerEditController' => 'applications/ponder/controller/PonderAnswerEditController.php',
|
'PonderAnswerEditController' => 'applications/ponder/controller/PonderAnswerEditController.php',
|
||||||
'PonderAnswerEditor' => 'applications/ponder/editor/PonderAnswerEditor.php',
|
'PonderAnswerEditor' => 'applications/ponder/editor/PonderAnswerEditor.php',
|
||||||
'PonderAnswerListView' => 'applications/ponder/view/PonderAnswerListView.php',
|
'PonderAnswerListView' => 'applications/ponder/view/PonderAnswerListView.php',
|
||||||
|
@ -3994,6 +3995,7 @@ phutil_register_library_map(array(
|
||||||
4 => 'PhabricatorSubscribableInterface',
|
4 => 'PhabricatorSubscribableInterface',
|
||||||
5 => 'PhabricatorTokenReceiverInterface',
|
5 => 'PhabricatorTokenReceiverInterface',
|
||||||
),
|
),
|
||||||
|
'PonderAnswerCommentController' => 'PonderController',
|
||||||
'PonderAnswerEditController' => 'PonderController',
|
'PonderAnswerEditController' => 'PonderController',
|
||||||
'PonderAnswerEditor' => 'PhabricatorApplicationTransactionEditor',
|
'PonderAnswerEditor' => 'PhabricatorApplicationTransactionEditor',
|
||||||
'PonderAnswerListView' => 'AphrontView',
|
'PonderAnswerListView' => 'AphrontView',
|
||||||
|
|
|
@ -52,6 +52,7 @@ final class PhabricatorApplicationPonder extends PhabricatorApplication {
|
||||||
'(?:query/(?P<queryKey>[^/]+)/)?' => 'PonderQuestionListController',
|
'(?:query/(?P<queryKey>[^/]+)/)?' => 'PonderQuestionListController',
|
||||||
'answer/add/' => 'PonderAnswerSaveController',
|
'answer/add/' => 'PonderAnswerSaveController',
|
||||||
'answer/edit/(?P<id>\d+)/' => 'PonderAnswerEditController',
|
'answer/edit/(?P<id>\d+)/' => 'PonderAnswerEditController',
|
||||||
|
'answer/comment/(?P<id>\d+)/' => 'PonderAnswerCommentController',
|
||||||
'answer/preview/' => 'PonderAnswerPreviewController',
|
'answer/preview/' => 'PonderAnswerPreviewController',
|
||||||
'question/edit/(?:(?P<id>\d+)/)?' => 'PonderQuestionEditController',
|
'question/edit/(?:(?P<id>\d+)/)?' => 'PonderQuestionEditController',
|
||||||
'question/preview/' => 'PonderQuestionPreviewController',
|
'question/preview/' => 'PonderQuestionPreviewController',
|
||||||
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class PonderAnswerCommentController extends PonderController {
|
||||||
|
|
||||||
|
private $id;
|
||||||
|
|
||||||
|
public function willProcessRequest(array $data) {
|
||||||
|
$this->id = $data['id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function processRequest() {
|
||||||
|
$request = $this->getRequest();
|
||||||
|
$viewer = $request->getUser();
|
||||||
|
|
||||||
|
if (!$request->isFormPost()) {
|
||||||
|
return new Aphront400Response();
|
||||||
|
}
|
||||||
|
|
||||||
|
$answer = id(new PonderAnswerQuery())
|
||||||
|
->setViewer($viewer)
|
||||||
|
->withIDs(array($this->id))
|
||||||
|
->executeOne();
|
||||||
|
if (!$answer) {
|
||||||
|
return new Aphront404Response();
|
||||||
|
}
|
||||||
|
|
||||||
|
$is_preview = $request->isPreviewRequest();
|
||||||
|
// $draft = PhabricatorDraft::buildFromRequest($request);
|
||||||
|
|
||||||
|
$qid = $answer->getQuestion()->getID();
|
||||||
|
$aid = $answer->getID();
|
||||||
|
$view_uri = "Q{$qid}#A{$aid}";
|
||||||
|
|
||||||
|
$xactions = array();
|
||||||
|
$xactions[] = id(new PonderAnswerTransaction())
|
||||||
|
->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)
|
||||||
|
->attachComment(
|
||||||
|
id(new PonderAnswerTransactionComment())
|
||||||
|
->setContent($request->getStr('comment')));
|
||||||
|
|
||||||
|
$editor = id(new PonderAnswerEditor())
|
||||||
|
->setActor($viewer)
|
||||||
|
->setContinueOnNoEffect($request->isContinueRequest())
|
||||||
|
->setContentSourceFromRequest($request)
|
||||||
|
->setIsPreview($is_preview);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$xactions = $editor->applyTransactions($answer, $xactions);
|
||||||
|
} catch (PhabricatorApplicationTransactionNoEffectException $ex) {
|
||||||
|
return id(new PhabricatorApplicationTransactionNoEffectResponse())
|
||||||
|
->setCancelURI($view_uri)
|
||||||
|
->setException($ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if ($draft) {
|
||||||
|
// $draft->replaceOrDelete();
|
||||||
|
// }
|
||||||
|
|
||||||
|
if ($request->isAjax()) {
|
||||||
|
return id(new PhabricatorApplicationTransactionResponse())
|
||||||
|
->setViewer($viewer)
|
||||||
|
->setTransactions($xactions)
|
||||||
|
->setIsPreview($is_preview)
|
||||||
|
->setAnchorOffset($request->getStr('anchor'));
|
||||||
|
} else {
|
||||||
|
return id(new AphrontRedirectResponse())
|
||||||
|
->setURI($view_uri);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -14,13 +14,23 @@ final class PonderQuestionStatusController
|
||||||
public function processRequest() {
|
public function processRequest() {
|
||||||
|
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
$user = $request->getUser();
|
$viewer = $request->getUser();
|
||||||
|
|
||||||
$question = id(new PonderQuestion())->load($this->id);
|
$question = id(new PonderQuestionQuery())
|
||||||
|
->setViewer($viewer)
|
||||||
|
->withIDs(array($this->id))
|
||||||
|
->requireCapabilities(
|
||||||
|
array(
|
||||||
|
PhabricatorPolicyCapability::CAN_VIEW,
|
||||||
|
PhabricatorPolicyCapability::CAN_EDIT,
|
||||||
|
))
|
||||||
|
->executeOne();
|
||||||
if (!$question) {
|
if (!$question) {
|
||||||
return new Aphront404Response();
|
return new Aphront404Response();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Use transactions.
|
||||||
|
|
||||||
switch ($this->status) {
|
switch ($this->status) {
|
||||||
case 'open':
|
case 'open':
|
||||||
$question->setStatus(PonderQuestionStatus::STATUS_OPEN);
|
$question->setStatus(PonderQuestionStatus::STATUS_OPEN);
|
||||||
|
|
|
@ -209,6 +209,7 @@ final class PonderQuestionViewController extends PonderController {
|
||||||
foreach ($answers as $answer) {
|
foreach ($answers as $answer) {
|
||||||
$author_phid = $answer->getAuthorPHID();
|
$author_phid = $answer->getAuthorPHID();
|
||||||
$xactions = idx($xaction_groups, $answer->getPHID(), array());
|
$xactions = idx($xaction_groups, $answer->getPHID(), array());
|
||||||
|
$id = $answer->getID();
|
||||||
|
|
||||||
$out[] = phutil_tag('br');
|
$out[] = phutil_tag('br');
|
||||||
$out[] = phutil_tag('br');
|
$out[] = phutil_tag('br');
|
||||||
|
@ -218,13 +219,17 @@ final class PonderQuestionViewController extends PonderController {
|
||||||
|
|
||||||
$out[] = $this->buildAnswerActions($answer);
|
$out[] = $this->buildAnswerActions($answer);
|
||||||
$out[] = $this->buildAnswerProperties($answer);
|
$out[] = $this->buildAnswerProperties($answer);
|
||||||
|
|
||||||
$out[] = id(new PhabricatorApplicationTransactionView())
|
$out[] = id(new PhabricatorApplicationTransactionView())
|
||||||
->setUser($viewer)
|
->setUser($viewer)
|
||||||
->setTransactions($xactions)
|
->setTransactions($xactions)
|
||||||
->setMarkupEngine($engine);
|
->setMarkupEngine($engine);
|
||||||
|
|
||||||
// TODO: Add comment form
|
$out[] = id(new PhabricatorApplicationTransactionCommentView())
|
||||||
|
->setUser($viewer)
|
||||||
|
->setShowPreview(false)
|
||||||
|
->setAction($this->getApplicationURI("/answer/comment/{$id}/"))
|
||||||
|
->setSubmitButtonName(pht('Comment'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$out[] = phutil_tag('br');
|
$out[] = phutil_tag('br');
|
||||||
|
|
|
@ -16,6 +16,16 @@ class PhabricatorApplicationTransactionCommentView extends AphrontView {
|
||||||
private $commentID;
|
private $commentID;
|
||||||
private $draft;
|
private $draft;
|
||||||
private $requestURI;
|
private $requestURI;
|
||||||
|
private $showPreview = true;
|
||||||
|
|
||||||
|
public function setShowPreview($show_preview) {
|
||||||
|
$this->showPreview = $show_preview;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getShowPreview() {
|
||||||
|
return $this->showPreview;
|
||||||
|
}
|
||||||
|
|
||||||
public function setRequestURI(PhutilURI $request_uri) {
|
public function setRequestURI(PhutilURI $request_uri) {
|
||||||
$this->requestURI = $request_uri;
|
$this->requestURI = $request_uri;
|
||||||
|
@ -77,7 +87,11 @@ class PhabricatorApplicationTransactionCommentView extends AphrontView {
|
||||||
|
|
||||||
$comment = $this->renderCommentPanel();
|
$comment = $this->renderCommentPanel();
|
||||||
|
|
||||||
|
if ($this->getShowPreview()) {
|
||||||
$preview = $this->renderPreviewPanel();
|
$preview = $this->renderPreviewPanel();
|
||||||
|
} else {
|
||||||
|
$preview = null;
|
||||||
|
}
|
||||||
|
|
||||||
Javelin::initBehavior(
|
Javelin::initBehavior(
|
||||||
'phabricator-transaction-comment-form',
|
'phabricator-transaction-comment-form',
|
||||||
|
@ -92,8 +106,12 @@ class PhabricatorApplicationTransactionCommentView extends AphrontView {
|
||||||
'savingString' => pht('Saving Draft...'),
|
'savingString' => pht('Saving Draft...'),
|
||||||
'draftString' => pht('Saved Draft'),
|
'draftString' => pht('Saved Draft'),
|
||||||
|
|
||||||
|
'showPreview' => $this->getShowPreview(),
|
||||||
|
|
||||||
'actionURI' => $this->getAction(),
|
'actionURI' => $this->getAction(),
|
||||||
'draftKey' => $this->getDraft()->getDraftKey(),
|
'draftKey' => $this->getDraft()
|
||||||
|
? $this->getDraft()->getDraftKey()
|
||||||
|
: null,
|
||||||
));
|
));
|
||||||
|
|
||||||
return array($comment, $preview);
|
return array($comment, $preview);
|
||||||
|
|
|
@ -14,11 +14,16 @@ JX.behavior('phabricator-transaction-comment-form', function(config) {
|
||||||
|
|
||||||
JX.DOM.listen(form, 'willSubmit', null, function (e) {
|
JX.DOM.listen(form, 'willSubmit', null, function (e) {
|
||||||
e.kill();
|
e.kill();
|
||||||
|
if (config.showPreview) {
|
||||||
var preview = JX.$(config.panelID);
|
var preview = JX.$(config.panelID);
|
||||||
preview.style.opacity = 0.5;
|
preview.style.opacity = 0.5;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
JX.DOM.listen(form, 'willClear', null, function(e) {
|
JX.DOM.listen(form, 'willClear', null, function(e) {
|
||||||
JX.$(config.commentID).value = '';
|
JX.$(config.commentID).value = '';
|
||||||
|
|
||||||
|
if (config.showPreview) {
|
||||||
var preview = JX.$(config.panelID);
|
var preview = JX.$(config.panelID);
|
||||||
new JX.FX(preview)
|
new JX.FX(preview)
|
||||||
.setDuration(500)
|
.setDuration(500)
|
||||||
|
@ -26,6 +31,7 @@ JX.behavior('phabricator-transaction-comment-form', function(config) {
|
||||||
new JX.FX(preview).setDuration(1000).start({opacity: [0, 1]});
|
new JX.FX(preview).setDuration(1000).start({opacity: [0, 1]});
|
||||||
})
|
})
|
||||||
.start({opacity: [0.5, 0]});
|
.start({opacity: [0.5, 0]});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var getdata = function() {
|
var getdata = function() {
|
||||||
|
@ -55,6 +61,7 @@ JX.behavior('phabricator-transaction-comment-form', function(config) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (config.showPreview) {
|
||||||
var request = new JX.PhabricatorShapedRequest(
|
var request = new JX.PhabricatorShapedRequest(
|
||||||
config.actionURI,
|
config.actionURI,
|
||||||
onresponse,
|
onresponse,
|
||||||
|
@ -69,4 +76,5 @@ JX.behavior('phabricator-transaction-comment-form', function(config) {
|
||||||
JX.DOM.listen(form, 'shouldRefresh', null, always_trigger);
|
JX.DOM.listen(form, 'shouldRefresh', null, always_trigger);
|
||||||
|
|
||||||
request.start();
|
request.start();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue