Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/diff/PhabricatorInlineCommentController.php
| <?php | <?php | ||||
| abstract class PhabricatorInlineCommentController | abstract class PhabricatorInlineCommentController | ||||
| extends PhabricatorController { | extends PhabricatorController { | ||||
| abstract protected function createComment(); | abstract protected function createComment(); | ||||
| abstract protected function loadComment($id); | abstract protected function loadComment($id); | ||||
| abstract protected function loadCommentForEdit($id); | abstract protected function loadCommentForEdit($id); | ||||
| abstract protected function loadCommentForDone($id); | abstract protected function loadCommentForDone($id); | ||||
| abstract protected function loadCommentByPHID($phid); | abstract protected function loadCommentByPHID($phid); | ||||
| abstract protected function loadObjectOwnerPHID( | abstract protected function loadObjectOwnerPHID( | ||||
| PhabricatorInlineCommentInterface $inline); | PhabricatorInlineComment $inline); | ||||
| abstract protected function deleteComment( | abstract protected function deleteComment( | ||||
| PhabricatorInlineCommentInterface $inline); | PhabricatorInlineComment $inline); | ||||
| abstract protected function undeleteComment( | abstract protected function undeleteComment( | ||||
| PhabricatorInlineCommentInterface $inline); | PhabricatorInlineComment $inline); | ||||
| abstract protected function saveComment( | abstract protected function saveComment( | ||||
| PhabricatorInlineCommentInterface $inline); | PhabricatorInlineComment $inline); | ||||
| protected function hideComments(array $ids) { | protected function hideComments(array $ids) { | ||||
| throw new PhutilMethodNotImplementedException(); | throw new PhutilMethodNotImplementedException(); | ||||
| } | } | ||||
| protected function showComments(array $ids) { | protected function showComments(array $ids) { | ||||
| throw new PhutilMethodNotImplementedException(); | throw new PhutilMethodNotImplementedException(); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | switch ($op) { | ||||
| if (!$request->validateCSRF()) { | if (!$request->validateCSRF()) { | ||||
| return new Aphront404Response(); | return new Aphront404Response(); | ||||
| } | } | ||||
| $inline = $this->loadCommentForDone($this->getCommentID()); | $inline = $this->loadCommentForDone($this->getCommentID()); | ||||
| $is_draft_state = false; | $is_draft_state = false; | ||||
| $is_checked = false; | $is_checked = false; | ||||
| switch ($inline->getFixedState()) { | switch ($inline->getFixedState()) { | ||||
| case PhabricatorInlineCommentInterface::STATE_DRAFT: | case PhabricatorInlineComment::STATE_DRAFT: | ||||
| $next_state = PhabricatorInlineCommentInterface::STATE_UNDONE; | $next_state = PhabricatorInlineComment::STATE_UNDONE; | ||||
| break; | break; | ||||
| case PhabricatorInlineCommentInterface::STATE_UNDRAFT: | case PhabricatorInlineComment::STATE_UNDRAFT: | ||||
| $next_state = PhabricatorInlineCommentInterface::STATE_DONE; | $next_state = PhabricatorInlineComment::STATE_DONE; | ||||
| $is_checked = true; | $is_checked = true; | ||||
| break; | break; | ||||
| case PhabricatorInlineCommentInterface::STATE_DONE: | case PhabricatorInlineComment::STATE_DONE: | ||||
| $next_state = PhabricatorInlineCommentInterface::STATE_UNDRAFT; | $next_state = PhabricatorInlineComment::STATE_UNDRAFT; | ||||
| $is_draft_state = true; | $is_draft_state = true; | ||||
| break; | break; | ||||
| default: | default: | ||||
| case PhabricatorInlineCommentInterface::STATE_UNDONE: | case PhabricatorInlineComment::STATE_UNDONE: | ||||
| $next_state = PhabricatorInlineCommentInterface::STATE_DRAFT; | $next_state = PhabricatorInlineComment::STATE_DRAFT; | ||||
| $is_draft_state = true; | $is_draft_state = true; | ||||
| $is_checked = true; | $is_checked = true; | ||||
| break; | break; | ||||
| } | } | ||||
| $inline->setFixedState($next_state)->save(); | $inline->setFixedState($next_state)->save(); | ||||
| return id(new AphrontAjaxResponse()) | return id(new AphrontAjaxResponse()) | ||||
| Show All 38 Lines | switch ($op) { | ||||
| return $this->buildEmptyResponse(); | return $this->buildEmptyResponse(); | ||||
| case 'edit': | case 'edit': | ||||
| $inline = $this->loadCommentForEdit($this->getCommentID()); | $inline = $this->loadCommentForEdit($this->getCommentID()); | ||||
| $text = $this->getCommentText(); | $text = $this->getCommentText(); | ||||
| if ($request->isFormPost()) { | if ($request->isFormPost()) { | ||||
| if (strlen($text)) { | if (strlen($text)) { | ||||
| $inline->setContent($text); | $inline | ||||
| ->setContent($text) | |||||
| ->setIsEditing(false); | |||||
| $this->saveComment($inline); | $this->saveComment($inline); | ||||
| return $this->buildRenderedCommentResponse( | return $this->buildRenderedCommentResponse( | ||||
| $inline, | $inline, | ||||
| $this->getIsOnRight()); | $this->getIsOnRight()); | ||||
| } else { | } else { | ||||
| $this->deleteComment($inline); | $this->deleteComment($inline); | ||||
| return $this->buildEmptyResponse(); | return $this->buildEmptyResponse(); | ||||
| } | } | ||||
| } | } else { | ||||
| $inline->setIsEditing(true); | |||||
| $edit_dialog = $this->buildEditDialog(); | if (strlen($text)) { | ||||
| $edit_dialog->setTitle(pht('Edit Inline Comment')); | $inline->setContent($text); | ||||
| } | |||||
| $edit_dialog->addHiddenInput('id', $this->getCommentID()); | $this->saveComment($inline); | ||||
| $edit_dialog->addHiddenInput('op', 'edit'); | } | ||||
| $edit_dialog->appendChild( | $edit_dialog = $this->buildEditDialog($inline) | ||||
| $this->renderTextArea( | ->setTitle(pht('Edit Inline Comment')); | ||||
| nonempty($text, $inline->getContent()))); | |||||
| $view = $this->buildScaffoldForView($edit_dialog); | $view = $this->buildScaffoldForView($edit_dialog); | ||||
| return id(new AphrontAjaxResponse()) | return id(new AphrontAjaxResponse()) | ||||
| ->setContent($view->render()); | ->setContent($view->render()); | ||||
| case 'create': | case 'reply': | ||||
| $text = $this->getCommentText(); | default: | ||||
| // NOTE: We read the values from the client (the display values), not | |||||
| if (!$request->isFormPost() || !strlen($text)) { | // the values from the database (the original values) when replying. | ||||
| return $this->buildEmptyResponse(); | // In particular, when replying to a ghost comment which was moved | ||||
| } | // across diffs and then moved backward to the most recent visible | ||||
| // line, we want to reply on the display line (which exists), not on | |||||
| // the comment's original line (which may not exist in this changeset). | |||||
| $is_new = $this->getIsNewFile(); | |||||
| $number = $this->getLineNumber(); | |||||
| $length = $this->getLineLength(); | |||||
| $inline = $this->createComment() | $inline = $this->createComment() | ||||
| ->setChangesetID($this->getChangesetID()) | ->setChangesetID($this->getChangesetID()) | ||||
| ->setAuthorPHID($viewer->getPHID()) | ->setAuthorPHID($viewer->getPHID()) | ||||
| ->setLineNumber($this->getLineNumber()) | ->setIsNewFile($is_new) | ||||
| ->setLineLength($this->getLineLength()) | ->setLineNumber($number) | ||||
| ->setIsNewFile($this->getIsNewFile()) | ->setLineLength($length) | ||||
| ->setContent($text); | ->setContent($this->getCommentText()) | ||||
| ->setReplyToCommentPHID($this->getReplyToCommentPHID()) | |||||
| if ($this->getReplyToCommentPHID()) { | ->setIsEditing(true); | ||||
| $inline->setReplyToCommentPHID($this->getReplyToCommentPHID()); | |||||
| } | |||||
| // If you own this object, mark your own inlines as "Done" by default. | // If you own this object, mark your own inlines as "Done" by default. | ||||
| $owner_phid = $this->loadObjectOwnerPHID($inline); | $owner_phid = $this->loadObjectOwnerPHID($inline); | ||||
| if ($owner_phid) { | if ($owner_phid) { | ||||
| if ($viewer->getPHID() == $owner_phid) { | if ($viewer->getPHID() == $owner_phid) { | ||||
| $fixed_state = PhabricatorInlineCommentInterface::STATE_DRAFT; | $fixed_state = PhabricatorInlineComment::STATE_DRAFT; | ||||
| $inline->setFixedState($fixed_state); | $inline->setFixedState($fixed_state); | ||||
| } | } | ||||
| } | } | ||||
| $this->saveComment($inline); | $this->saveComment($inline); | ||||
| return $this->buildRenderedCommentResponse( | $edit_dialog = $this->buildEditDialog($inline); | ||||
| $inline, | |||||
| $this->getIsOnRight()); | |||||
| case 'reply': | |||||
| default: | |||||
| $edit_dialog = $this->buildEditDialog(); | |||||
| if ($this->getOperation() == 'reply') { | if ($this->getOperation() == 'reply') { | ||||
| $edit_dialog->setTitle(pht('Reply to Inline Comment')); | $edit_dialog->setTitle(pht('Reply to Inline Comment')); | ||||
| } else { | } else { | ||||
| $edit_dialog->setTitle(pht('New Inline Comment')); | $edit_dialog->setTitle(pht('New Inline Comment')); | ||||
| } | } | ||||
| // NOTE: We read the values from the client (the display values), not | |||||
| // the values from the database (the original values) when replying. | |||||
| // In particular, when replying to a ghost comment which was moved | |||||
| // across diffs and then moved backward to the most recent visible | |||||
| // line, we want to reply on the display line (which exists), not on | |||||
| // the comment's original line (which may not exist in this changeset). | |||||
| $is_new = $this->getIsNewFile(); | |||||
| $number = $this->getLineNumber(); | |||||
| $length = $this->getLineLength(); | |||||
| $edit_dialog->addHiddenInput('op', 'create'); | |||||
| $edit_dialog->addHiddenInput('is_new', $is_new); | |||||
| $edit_dialog->addHiddenInput('number', $number); | |||||
| $edit_dialog->addHiddenInput('length', $length); | |||||
| $text_area = $this->renderTextArea($this->getCommentText()); | |||||
| $edit_dialog->appendChild($text_area); | |||||
| $view = $this->buildScaffoldForView($edit_dialog); | $view = $this->buildScaffoldForView($edit_dialog); | ||||
| return id(new AphrontAjaxResponse()) | return id(new AphrontAjaxResponse()) | ||||
| ->setContent($view->render()); | ->setContent($view->render()); | ||||
| } | } | ||||
| } | } | ||||
| private function readRequestParameters() { | private function readRequestParameters() { | ||||
| Show All 31 Lines | if ($this->getReplyToCommentPHID()) { | ||||
| $this->changesetID = $reply_comment->getChangesetID(); | $this->changesetID = $reply_comment->getChangesetID(); | ||||
| $this->isNewFile = $reply_comment->getIsNewFile(); | $this->isNewFile = $reply_comment->getIsNewFile(); | ||||
| $this->lineNumber = $reply_comment->getLineNumber(); | $this->lineNumber = $reply_comment->getLineNumber(); | ||||
| $this->lineLength = $reply_comment->getLineLength(); | $this->lineLength = $reply_comment->getLineLength(); | ||||
| } | } | ||||
| } | } | ||||
| private function buildEditDialog() { | private function buildEditDialog(PhabricatorInlineComment $inline) { | ||||
| $request = $this->getRequest(); | $request = $this->getRequest(); | ||||
| $viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
| $edit_dialog = id(new PHUIDiffInlineCommentEditView()) | $edit_dialog = id(new PHUIDiffInlineCommentEditView()) | ||||
| ->setUser($viewer) | ->setViewer($viewer) | ||||
| ->setSubmitURI($request->getRequestURI()) | ->setInlineComment($inline) | ||||
| ->setIsOnRight($this->getIsOnRight()) | ->setIsOnRight($this->getIsOnRight()) | ||||
| ->setIsNewFile($this->getIsNewFile()) | ->setRenderer($this->getRenderer()); | ||||
| ->setNumber($this->getLineNumber()) | |||||
| ->setLength($this->getLineLength()) | |||||
| ->setRenderer($this->getRenderer()) | |||||
| ->setReplyToCommentPHID($this->getReplyToCommentPHID()) | |||||
| ->setChangesetID($this->getChangesetID()); | |||||
| return $edit_dialog; | return $edit_dialog; | ||||
| } | } | ||||
| private function buildEmptyResponse() { | private function buildEmptyResponse() { | ||||
| return id(new AphrontAjaxResponse()) | return id(new AphrontAjaxResponse()) | ||||
| ->setContent( | ->setContent( | ||||
| array( | array( | ||||
| 'markup' => '', | 'markup' => '', | ||||
| )); | )); | ||||
| } | } | ||||
| private function buildRenderedCommentResponse( | private function buildRenderedCommentResponse( | ||||
| PhabricatorInlineCommentInterface $inline, | PhabricatorInlineComment $inline, | ||||
| $on_right) { | $on_right) { | ||||
| $request = $this->getRequest(); | $request = $this->getRequest(); | ||||
| $viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
| $engine = new PhabricatorMarkupEngine(); | $engine = new PhabricatorMarkupEngine(); | ||||
| $engine->setViewer($viewer); | $engine->setViewer($viewer); | ||||
| $engine->addObject( | $engine->addObject( | ||||
| $inline, | $inline, | ||||
| PhabricatorInlineCommentInterface::MARKUP_FIELD_BODY); | PhabricatorInlineComment::MARKUP_FIELD_BODY); | ||||
| $engine->process(); | $engine->process(); | ||||
| $phids = array($viewer->getPHID()); | $phids = array($viewer->getPHID()); | ||||
| $handles = $this->loadViewerHandles($phids); | $handles = $this->loadViewerHandles($phids); | ||||
| $object_owner_phid = $this->loadObjectOwnerPHID($inline); | $object_owner_phid = $this->loadObjectOwnerPHID($inline); | ||||
| $view = id(new PHUIDiffInlineCommentDetailView()) | $view = id(new PHUIDiffInlineCommentDetailView()) | ||||
| Show All 11 Lines | private function buildRenderedCommentResponse( | ||||
| return id(new AphrontAjaxResponse()) | return id(new AphrontAjaxResponse()) | ||||
| ->setContent( | ->setContent( | ||||
| array( | array( | ||||
| 'inlineCommentID' => $inline->getID(), | 'inlineCommentID' => $inline->getID(), | ||||
| 'markup' => $view->render(), | 'markup' => $view->render(), | ||||
| )); | )); | ||||
| } | } | ||||
| private function renderTextArea($text) { | |||||
| return id(new PhabricatorRemarkupControl()) | |||||
| ->setViewer($this->getViewer()) | |||||
| ->setSigil('differential-inline-comment-edit-textarea') | |||||
| ->setName('text') | |||||
| ->setValue($text) | |||||
| ->setDisableFullScreen(true); | |||||
| } | |||||
| private function buildScaffoldForView(PHUIDiffInlineCommentView $view) { | private function buildScaffoldForView(PHUIDiffInlineCommentView $view) { | ||||
| $renderer = DifferentialChangesetHTMLRenderer::getHTMLRendererByKey( | $renderer = DifferentialChangesetHTMLRenderer::getHTMLRendererByKey( | ||||
| $this->getRenderer()); | $this->getRenderer()); | ||||
| $view = $renderer->getRowScaffoldForInline($view); | $view = $renderer->getRowScaffoldForInline($view); | ||||
| return id(new PHUIDiffInlineCommentTableScaffold()) | return id(new PHUIDiffInlineCommentTableScaffold()) | ||||
| ->addRowScaffold($view); | ->addRowScaffold($view); | ||||
| } | } | ||||
| } | } | ||||