Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/diff/PhabricatorInlineCommentController.php
Show All 13 Lines | abstract class PhabricatorInlineCommentController | ||||
private $changesetID; | private $changesetID; | ||||
private $isNewFile; | private $isNewFile; | ||||
private $isOnRight; | private $isOnRight; | ||||
private $lineNumber; | private $lineNumber; | ||||
private $lineLength; | private $lineLength; | ||||
private $commentText; | private $commentText; | ||||
private $operation; | private $operation; | ||||
private $commentID; | private $commentID; | ||||
private $renderer; | |||||
public function getCommentID() { | public function getCommentID() { | ||||
return $this->commentID; | return $this->commentID; | ||||
} | } | ||||
public function getOperation() { | public function getOperation() { | ||||
return $this->operation; | return $this->operation; | ||||
} | } | ||||
Show All 17 Lines | abstract class PhabricatorInlineCommentController | ||||
public function getChangesetID() { | public function getChangesetID() { | ||||
return $this->changesetID; | return $this->changesetID; | ||||
} | } | ||||
public function getIsNewFile() { | public function getIsNewFile() { | ||||
return $this->isNewFile; | return $this->isNewFile; | ||||
} | } | ||||
public function setRenderer($renderer) { | |||||
$this->renderer = $renderer; | |||||
return $this; | |||||
} | |||||
public function getRenderer() { | |||||
return $this->renderer; | |||||
} | |||||
public function processRequest() { | public function processRequest() { | ||||
$request = $this->getRequest(); | $request = $this->getRequest(); | ||||
$user = $request->getUser(); | $user = $request->getUser(); | ||||
$this->readRequestParameters(); | $this->readRequestParameters(); | ||||
switch ($this->getOperation()) { | switch ($this->getOperation()) { | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | switch ($this->getOperation()) { | ||||
$edit_dialog->appendChild( | $edit_dialog->appendChild( | ||||
$this->renderTextArea( | $this->renderTextArea( | ||||
nonempty($text, $inline->getContent()))); | nonempty($text, $inline->getContent()))); | ||||
return id(new AphrontAjaxResponse()) | return id(new AphrontAjaxResponse()) | ||||
->setContent($edit_dialog->render()); | ->setContent($edit_dialog->render()); | ||||
case 'create': | case 'create': | ||||
$text = $this->getCommentText(); | $text = $this->getCommentText(); | ||||
if (!$request->isFormPost() || !strlen($text)) { | if (!$request->isFormPost() || !strlen($text)) { | ||||
return $this->buildEmptyResponse(); | return $this->buildEmptyResponse(); | ||||
} | } | ||||
$inline = $this->createComment() | $inline = $this->createComment() | ||||
->setChangesetID($this->getChangesetID()) | ->setChangesetID($this->getChangesetID()) | ||||
Show All 27 Lines | switch ($this->getOperation()) { | ||||
$length = $this->getLineLength(); | $length = $this->getLineLength(); | ||||
} | } | ||||
$edit_dialog->addHiddenInput('op', 'create'); | $edit_dialog->addHiddenInput('op', 'create'); | ||||
$edit_dialog->addHiddenInput('changeset', $changeset); | $edit_dialog->addHiddenInput('changeset', $changeset); | ||||
$edit_dialog->addHiddenInput('is_new', $is_new); | $edit_dialog->addHiddenInput('is_new', $is_new); | ||||
$edit_dialog->addHiddenInput('number', $number); | $edit_dialog->addHiddenInput('number', $number); | ||||
$edit_dialog->addHiddenInput('length', $length); | $edit_dialog->addHiddenInput('length', $length); | ||||
$edit_dialog->addHiddenInput('renderer', $this->getRenderer()); | |||||
$text_area = $this->renderTextArea($this->getCommentText()); | $text_area = $this->renderTextArea($this->getCommentText()); | ||||
$edit_dialog->appendChild($text_area); | $edit_dialog->appendChild($text_area); | ||||
return id(new AphrontAjaxResponse()) | return id(new AphrontAjaxResponse()) | ||||
->setContent($edit_dialog->render()); | ->setContent($edit_dialog->render()); | ||||
} | } | ||||
} | } | ||||
private function readRequestParameters() { | private function readRequestParameters() { | ||||
$request = $this->getRequest(); | $request = $this->getRequest(); | ||||
// NOTE: This isn't necessarily a DifferentialChangeset ID, just an | // NOTE: This isn't necessarily a DifferentialChangeset ID, just an | ||||
// application identifier for the changeset. In Diffusion, it's a Path ID. | // application identifier for the changeset. In Diffusion, it's a Path ID. | ||||
$this->changesetID = $request->getInt('changeset'); | $this->changesetID = $request->getInt('changeset'); | ||||
$this->isNewFile = (int)$request->getBool('is_new'); | $this->isNewFile = (int)$request->getBool('is_new'); | ||||
$this->isOnRight = $request->getBool('on_right'); | $this->isOnRight = $request->getBool('on_right'); | ||||
$this->lineNumber = $request->getInt('number'); | $this->lineNumber = $request->getInt('number'); | ||||
$this->lineLength = $request->getInt('length'); | $this->lineLength = $request->getInt('length'); | ||||
$this->commentText = $request->getStr('text'); | $this->commentText = $request->getStr('text'); | ||||
$this->commentID = $request->getInt('id'); | $this->commentID = $request->getInt('id'); | ||||
$this->operation = $request->getStr('op'); | $this->operation = $request->getStr('op'); | ||||
$this->renderer = $request->getStr('renderer'); | |||||
} | } | ||||
private function buildEditDialog() { | private function buildEditDialog() { | ||||
$request = $this->getRequest(); | $request = $this->getRequest(); | ||||
$user = $request->getUser(); | $user = $request->getUser(); | ||||
$edit_dialog = new DifferentialInlineCommentEditView(); | $edit_dialog = id(new DifferentialInlineCommentEditView()) | ||||
$edit_dialog->setUser($user); | ->setUser($user) | ||||
$edit_dialog->setSubmitURI($request->getRequestURI()); | ->setSubmitURI($request->getRequestURI()) | ||||
$edit_dialog->setOnRight($this->getIsOnRight()); | ->setOnRight($this->getIsOnRight()) | ||||
$edit_dialog->setNumber($this->getLineNumber()); | ->setNumber($this->getLineNumber()) | ||||
$edit_dialog->setLength($this->getLineLength()); | ->setLength($this->getLineLength()) | ||||
->setRenderer($this->getRenderer()); | |||||
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, | PhabricatorInlineCommentInterface $inline, | ||||
$on_right) { | $on_right) { | ||||
$request = $this->getRequest(); | $request = $this->getRequest(); | ||||
$user = $request->getUser(); | $user = $request->getUser(); | ||||
$engine = new PhabricatorMarkupEngine(); | $engine = new PhabricatorMarkupEngine(); | ||||
$engine->setViewer($user); | $engine->setViewer($user); | ||||
$engine->addObject( | $engine->addObject( | ||||
$inline, | $inline, | ||||
PhabricatorInlineCommentInterface::MARKUP_FIELD_BODY); | PhabricatorInlineCommentInterface::MARKUP_FIELD_BODY); | ||||
$engine->process(); | $engine->process(); | ||||
$phids = array($user->getPHID()); | $phids = array($user->getPHID()); | ||||
$handles = $this->loadViewerHandles($phids); | $handles = $this->loadViewerHandles($phids); | ||||
$view = new DifferentialInlineCommentView(); | $view = id(new DifferentialInlineCommentView()) | ||||
$view->setInlineComment($inline); | ->setInlineComment($inline) | ||||
$view->setOnRight($on_right); | ->setOnRight($on_right) | ||||
$view->setBuildScaffolding(true); | ->setBuildScaffolding(true) | ||||
$view->setMarkupEngine($engine); | ->setMarkupEngine($engine) | ||||
$view->setHandles($handles); | ->setHandles($handles) | ||||
$view->setEditable(true); | ->setEditable(true) | ||||
->setRenderer($this->getRenderer()); | |||||
return id(new AphrontAjaxResponse()) | return id(new AphrontAjaxResponse()) | ||||
->setContent( | ->setContent( | ||||
array( | array( | ||||
'inlineCommentID' => $inline->getID(), | 'inlineCommentID' => $inline->getID(), | ||||
'markup' => $view->render(), | 'markup' => $view->render(), | ||||
)); | )); | ||||
} | } | ||||
Show All 11 Lines |