mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-22 19:49:02 +01:00
Restore Ponder question commenting
Summary: Ref T3373. Same issues as the other commenting patch; it's huge and the JS is a bit buggy. Backend is fine, though. Test Plan: Made some comments on a question. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T3373 Differential Revision: https://secure.phabricator.com/D6610
This commit is contained in:
parent
d4b24a2c07
commit
b6130ad49e
6 changed files with 83 additions and 110 deletions
|
@ -1874,7 +1874,6 @@ phutil_register_library_map(array(
|
|||
'PonderAnswerEditController' => 'applications/ponder/controller/PonderAnswerEditController.php',
|
||||
'PonderAnswerEditor' => 'applications/ponder/editor/PonderAnswerEditor.php',
|
||||
'PonderAnswerListView' => 'applications/ponder/view/PonderAnswerListView.php',
|
||||
'PonderAnswerPreviewController' => 'applications/ponder/controller/PonderAnswerPreviewController.php',
|
||||
'PonderAnswerQuery' => 'applications/ponder/query/PonderAnswerQuery.php',
|
||||
'PonderAnswerSaveController' => 'applications/ponder/controller/PonderAnswerSaveController.php',
|
||||
'PonderAnswerTransaction' => 'applications/ponder/storage/PonderAnswerTransaction.php',
|
||||
|
@ -1887,7 +1886,6 @@ phutil_register_library_map(array(
|
|||
'PonderCommentListView' => 'applications/ponder/view/PonderCommentListView.php',
|
||||
'PonderCommentMail' => 'applications/ponder/mail/PonderCommentMail.php',
|
||||
'PonderCommentQuery' => 'applications/ponder/query/PonderCommentQuery.php',
|
||||
'PonderCommentSaveController' => 'applications/ponder/controller/PonderCommentSaveController.php',
|
||||
'PonderConstants' => 'applications/ponder/constants/PonderConstants.php',
|
||||
'PonderController' => 'applications/ponder/controller/PonderController.php',
|
||||
'PonderDAO' => 'applications/ponder/storage/PonderDAO.php',
|
||||
|
@ -1898,6 +1896,7 @@ phutil_register_library_map(array(
|
|||
'PonderPHIDTypeQuestion' => 'applications/ponder/phid/PonderPHIDTypeQuestion.php',
|
||||
'PonderPostBodyView' => 'applications/ponder/view/PonderPostBodyView.php',
|
||||
'PonderQuestion' => 'applications/ponder/storage/PonderQuestion.php',
|
||||
'PonderQuestionCommentController' => 'applications/ponder/controller/PonderQuestionCommentController.php',
|
||||
'PonderQuestionDetailView' => 'applications/ponder/view/PonderQuestionDetailView.php',
|
||||
'PonderQuestionEditController' => 'applications/ponder/controller/PonderQuestionEditController.php',
|
||||
'PonderQuestionEditor' => 'applications/ponder/editor/PonderQuestionEditor.php',
|
||||
|
@ -3999,7 +3998,6 @@ phutil_register_library_map(array(
|
|||
'PonderAnswerEditController' => 'PonderController',
|
||||
'PonderAnswerEditor' => 'PhabricatorApplicationTransactionEditor',
|
||||
'PonderAnswerListView' => 'AphrontView',
|
||||
'PonderAnswerPreviewController' => 'PonderController',
|
||||
'PonderAnswerQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
'PonderAnswerSaveController' => 'PonderController',
|
||||
'PonderAnswerTransaction' => 'PhabricatorApplicationTransaction',
|
||||
|
@ -4016,7 +4014,6 @@ phutil_register_library_map(array(
|
|||
'PonderCommentListView' => 'AphrontView',
|
||||
'PonderCommentMail' => 'PonderMail',
|
||||
'PonderCommentQuery' => 'PhabricatorQuery',
|
||||
'PonderCommentSaveController' => 'PonderController',
|
||||
'PonderController' => 'PhabricatorController',
|
||||
'PonderDAO' => 'PhabricatorLiskDAO',
|
||||
'PonderLiterals' => 'PonderConstants',
|
||||
|
@ -4034,6 +4031,7 @@ phutil_register_library_map(array(
|
|||
4 => 'PhabricatorPolicyInterface',
|
||||
5 => 'PhabricatorTokenReceiverInterface',
|
||||
),
|
||||
'PonderQuestionCommentController' => 'PonderController',
|
||||
'PonderQuestionDetailView' => 'AphrontView',
|
||||
'PonderQuestionEditController' => 'PonderController',
|
||||
'PonderQuestionEditor' => 'PhabricatorApplicationTransactionEditor',
|
||||
|
|
|
@ -53,12 +53,11 @@ final class PhabricatorApplicationPonder extends PhabricatorApplication {
|
|||
'answer/add/' => 'PonderAnswerSaveController',
|
||||
'answer/edit/(?P<id>\d+)/' => 'PonderAnswerEditController',
|
||||
'answer/comment/(?P<id>\d+)/' => 'PonderAnswerCommentController',
|
||||
'answer/preview/' => 'PonderAnswerPreviewController',
|
||||
'question/edit/(?:(?P<id>\d+)/)?' => 'PonderQuestionEditController',
|
||||
'question/comment/(?P<id>\d+)/' => 'PonderQuestionCommentController',
|
||||
'question/preview/' => 'PonderQuestionPreviewController',
|
||||
'question/(?P<status>open|close)/(?P<id>[1-9]\d*)/' =>
|
||||
'PonderQuestionStatusController',
|
||||
'comment/add/' => 'PonderCommentSaveController',
|
||||
'(?P<kind>question)/vote/' => 'PonderVoteSaveController',
|
||||
'(?P<kind>answer)/vote/' => 'PonderVoteSaveController'
|
||||
),
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
<?php
|
||||
|
||||
final class PonderAnswerPreviewController
|
||||
extends PonderController {
|
||||
|
||||
public function processRequest() {
|
||||
$request = $this->getRequest();
|
||||
$viewer = $request->getUser();
|
||||
$question_id = $request->getInt('question_id');
|
||||
|
||||
$question = id(new PonderQuestionQuery())
|
||||
->setViewer($viewer)
|
||||
->withIDs(array($question_id))
|
||||
->executeOne();
|
||||
if (!$question) {
|
||||
return new Aphront404Response();
|
||||
}
|
||||
|
||||
$author_phid = $viewer->getPHID();
|
||||
$object_phids = array($author_phid);
|
||||
$handles = $this->loadViewerHandles($object_phids);
|
||||
|
||||
$answer = new PonderAnswer();
|
||||
$answer->setContent($request->getStr('content'));
|
||||
$answer->setAuthorPHID($author_phid);
|
||||
|
||||
$view = new PonderPostBodyView();
|
||||
$view
|
||||
->setQuestion($question)
|
||||
->setTarget($answer)
|
||||
->setPreview(true)
|
||||
->setUser($viewer)
|
||||
->setHandles($handles)
|
||||
->setAction(PonderLiterals::LITERAL_ANSWERED);
|
||||
|
||||
return id(new AphrontAjaxResponse())
|
||||
->setContent($view->render());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
<?php
|
||||
|
||||
final class PonderCommentSaveController extends PonderController {
|
||||
|
||||
public function processRequest() {
|
||||
$request = $this->getRequest();
|
||||
if (!$request->isFormPost()) {
|
||||
return new Aphront400Response();
|
||||
}
|
||||
|
||||
$user = $request->getUser();
|
||||
$question_id = $request->getInt('question_id');
|
||||
$question = id(new PonderQuestionQuery())
|
||||
->setViewer($user)
|
||||
->withIDs(array($question_id))
|
||||
->executeOne();
|
||||
if (!$question) {
|
||||
return new Aphront404Response();
|
||||
}
|
||||
|
||||
$question->attachRelated();
|
||||
|
||||
$target = $request->getStr('target');
|
||||
$objects = id(new PhabricatorObjectHandleData(array($target)))
|
||||
->setViewer($user)
|
||||
->loadHandles();
|
||||
if (!$objects) {
|
||||
return new Aphront404Response();
|
||||
}
|
||||
|
||||
$content = $request->getStr('content');
|
||||
|
||||
if (!strlen(trim($content))) {
|
||||
$dialog = new AphrontDialogView();
|
||||
$dialog->setUser($request->getUser());
|
||||
$dialog->setTitle(pht('Empty Comment'));
|
||||
$dialog->appendChild(phutil_tag('p', array(), pht(
|
||||
'Your comment must not be empty.')));
|
||||
$dialog->addCancelButton('/Q'.$question_id);
|
||||
|
||||
return id(new AphrontDialogResponse())->setDialog($dialog);
|
||||
}
|
||||
|
||||
$res = new PonderComment();
|
||||
$res
|
||||
->setContent($content)
|
||||
->setAuthorPHID($user->getPHID())
|
||||
->setTargetPHID($target);
|
||||
|
||||
id(new PonderCommentEditor())
|
||||
->setQuestion($question)
|
||||
->setComment($res)
|
||||
->setTargetPHID($target)
|
||||
->setActor($user)
|
||||
->save();
|
||||
|
||||
return id(new AphrontRedirectResponse())
|
||||
->setURI(
|
||||
id(new PhutilURI('/Q'. $question->getID())));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
|
||||
final class PonderQuestionCommentController 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();
|
||||
}
|
||||
|
||||
$question = id(new PonderQuestionQuery())
|
||||
->setViewer($viewer)
|
||||
->withIDs(array($this->id))
|
||||
->executeOne();
|
||||
if (!$question) {
|
||||
return new Aphront404Response();
|
||||
}
|
||||
|
||||
$is_preview = $request->isPreviewRequest();
|
||||
// $draft = PhabricatorDraft::buildFromRequest($request);
|
||||
|
||||
$qid = $question->getID();
|
||||
$view_uri = "Q{$qid}";
|
||||
|
||||
$xactions = array();
|
||||
$xactions[] = id(new PonderQuestionTransaction())
|
||||
->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)
|
||||
->attachComment(
|
||||
id(new PonderQuestionTransactionComment())
|
||||
->setContent($request->getStr('comment')));
|
||||
|
||||
$editor = id(new PonderQuestionEditor())
|
||||
->setActor($viewer)
|
||||
->setContinueOnNoEffect($request->isContinueRequest())
|
||||
->setContentSourceFromRequest($request)
|
||||
->setIsPreview($is_preview);
|
||||
|
||||
try {
|
||||
$xactions = $editor->applyTransactions($question, $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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -152,6 +152,7 @@ final class PonderQuestionViewController extends PonderController {
|
|||
|
||||
private function buildQuestionTransactions(PonderQuestion $question) {
|
||||
$viewer = $this->getRequest()->getUser();
|
||||
$id = $question->getID();
|
||||
|
||||
$xactions = id(new PonderQuestionTransactionQuery())
|
||||
->setViewer($viewer)
|
||||
|
@ -174,9 +175,16 @@ final class PonderQuestionViewController extends PonderController {
|
|||
->setTransactions($xactions)
|
||||
->setMarkupEngine($engine);
|
||||
|
||||
// TODO: Add comment form.
|
||||
$add_comment = id(new PhabricatorApplicationTransactionCommentView())
|
||||
->setUser($viewer)
|
||||
->setShowPreview(false)
|
||||
->setAction($this->getApplicationURI("/question/comment/{$id}/"))
|
||||
->setSubmitButtonName(pht('Comment'));
|
||||
|
||||
return $timeline;
|
||||
return array(
|
||||
$timeline,
|
||||
$add_comment,
|
||||
);
|
||||
}
|
||||
|
||||
private function buildAnswers(array $answers) {
|
||||
|
|
Loading…
Add table
Reference in a new issue