mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-22 05:20:56 +01:00
Initial support for comments/append-edits in EditEngine
Summary: Ref T9132. This just replaces the "Add Comment" form in Paste with a generic flow in EditEngine. No actual field-awareness or action stacking or anything quite yet, but that will come in a bit. This mildly regresses drafts (which don't seem like a big deal for Pastes). I'll hook those up again in the next diff, but I want to build them in a better way that will work with multiple actions in a generic way, and solve T5031. Big practical advantage here is that applications don't need copy/pasted preview controllers. Test Plan: - Saw previews. - Added comments. Reviewers: chad Reviewed By: chad Maniphest Tasks: T9132 Differential Revision: https://secure.phabricator.com/D14637
This commit is contained in:
parent
274f115d41
commit
a1c7ba6b8b
7 changed files with 107 additions and 86 deletions
|
@ -2605,7 +2605,6 @@ phutil_register_library_map(array(
|
|||
'PhabricatorPasswordSettingsPanel' => 'applications/settings/panel/PhabricatorPasswordSettingsPanel.php',
|
||||
'PhabricatorPaste' => 'applications/paste/storage/PhabricatorPaste.php',
|
||||
'PhabricatorPasteApplication' => 'applications/paste/application/PhabricatorPasteApplication.php',
|
||||
'PhabricatorPasteCommentController' => 'applications/paste/controller/PhabricatorPasteCommentController.php',
|
||||
'PhabricatorPasteConfigOptions' => 'applications/paste/config/PhabricatorPasteConfigOptions.php',
|
||||
'PhabricatorPasteController' => 'applications/paste/controller/PhabricatorPasteController.php',
|
||||
'PhabricatorPasteDAO' => 'applications/paste/storage/PhabricatorPasteDAO.php',
|
||||
|
@ -6800,7 +6799,6 @@ phutil_register_library_map(array(
|
|||
'PhabricatorSpacesInterface',
|
||||
),
|
||||
'PhabricatorPasteApplication' => 'PhabricatorApplication',
|
||||
'PhabricatorPasteCommentController' => 'PhabricatorPasteController',
|
||||
'PhabricatorPasteConfigOptions' => 'PhabricatorApplicationConfigOptions',
|
||||
'PhabricatorPasteController' => 'PhabricatorController',
|
||||
'PhabricatorPasteDAO' => 'PhabricatorLiskDAO',
|
||||
|
|
|
@ -640,7 +640,7 @@ abstract class PhabricatorApplication
|
|||
'(?P<id>[0-9]\d*)/)?'.
|
||||
'(?:'.
|
||||
'(?:'.
|
||||
'(?P<editAction>parameters|nodefault)'.
|
||||
'(?P<editAction>parameters|nodefault|comment)'.
|
||||
'|'.
|
||||
'(?:form/(?P<formKey>[^/]+))'.
|
||||
')'.
|
||||
|
|
|
@ -41,7 +41,6 @@ final class PhabricatorPasteApplication extends PhabricatorApplication {
|
|||
'create/' => 'PhabricatorPasteEditController',
|
||||
$this->getEditRoutePattern('edit/') => 'PhabricatorPasteEditController',
|
||||
'raw/(?P<id>[1-9]\d*)/' => 'PhabricatorPasteRawController',
|
||||
'comment/(?P<id>[1-9]\d*)/' => 'PhabricatorPasteCommentController',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,63 +0,0 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorPasteCommentController
|
||||
extends PhabricatorPasteController {
|
||||
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$viewer = $request->getViewer();
|
||||
$id = $request->getURIData('id');
|
||||
|
||||
if (!$request->isFormPost()) {
|
||||
return new Aphront400Response();
|
||||
}
|
||||
|
||||
$paste = id(new PhabricatorPasteQuery())
|
||||
->setViewer($viewer)
|
||||
->withIDs(array($id))
|
||||
->executeOne();
|
||||
if (!$paste) {
|
||||
return new Aphront404Response();
|
||||
}
|
||||
|
||||
$is_preview = $request->isPreviewRequest();
|
||||
$draft = PhabricatorDraft::buildFromRequest($request);
|
||||
|
||||
$view_uri = $paste->getURI();
|
||||
|
||||
$xactions = array();
|
||||
$xactions[] = id(new PhabricatorPasteTransaction())
|
||||
->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)
|
||||
->attachComment(
|
||||
id(new PhabricatorPasteTransactionComment())
|
||||
->setContent($request->getStr('comment')));
|
||||
|
||||
$editor = id(new PhabricatorPasteEditor())
|
||||
->setActor($viewer)
|
||||
->setContinueOnNoEffect($request->isContinueRequest())
|
||||
->setContentSourceFromRequest($request)
|
||||
->setIsPreview($is_preview);
|
||||
|
||||
try {
|
||||
$xactions = $editor->applyTransactions($paste, $xactions);
|
||||
} catch (PhabricatorApplicationTransactionNoEffectException $ex) {
|
||||
return id(new PhabricatorApplicationTransactionNoEffectResponse())
|
||||
->setCancelURI($view_uri)
|
||||
->setException($ex);
|
||||
}
|
||||
|
||||
if ($draft) {
|
||||
$draft->replaceOrDelete();
|
||||
}
|
||||
|
||||
if ($request->isAjax() && $is_preview) {
|
||||
return id(new PhabricatorApplicationTransactionResponse())
|
||||
->setViewer($viewer)
|
||||
->setTransactions($xactions)
|
||||
->setIsPreview($is_preview);
|
||||
} else {
|
||||
return id(new AphrontRedirectResponse())
|
||||
->setURI($view_uri);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,8 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* group paste
|
||||
*/
|
||||
final class PhabricatorPasteViewController extends PhabricatorPasteController {
|
||||
|
||||
private $highlightMap;
|
||||
|
@ -73,21 +70,9 @@ final class PhabricatorPasteViewController extends PhabricatorPasteController {
|
|||
$paste,
|
||||
new PhabricatorPasteTransactionQuery());
|
||||
|
||||
$is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
|
||||
|
||||
$add_comment_header = $is_serious
|
||||
? pht('Add Comment')
|
||||
: pht('Eat Paste');
|
||||
|
||||
$draft = PhabricatorDraft::newFromUserAndKey($viewer, $paste->getPHID());
|
||||
|
||||
$add_comment_form = id(new PhabricatorApplicationTransactionCommentView())
|
||||
->setUser($viewer)
|
||||
->setObjectPHID($paste->getPHID())
|
||||
->setDraft($draft)
|
||||
->setHeaderText($add_comment_header)
|
||||
->setAction($this->getApplicationURI('/comment/'.$paste->getID().'/'))
|
||||
->setSubmitButtonName(pht('Add Comment'));
|
||||
$comment_view = id(new PhabricatorPasteEditEngine())
|
||||
->setViewer($viewer)
|
||||
->buildEditEngineCommentView($paste);
|
||||
|
||||
return $this->newPage()
|
||||
->setTitle($paste->getFullName())
|
||||
|
@ -101,7 +86,7 @@ final class PhabricatorPasteViewController extends PhabricatorPasteController {
|
|||
$object_box,
|
||||
$source_code,
|
||||
$timeline,
|
||||
$add_comment_form,
|
||||
$comment_view,
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
@ -38,6 +38,15 @@ final class PhabricatorPasteEditEngine
|
|||
return pht('Create Paste');
|
||||
}
|
||||
|
||||
protected function getCommentViewHeaderText($object) {
|
||||
$is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
|
||||
if (!$is_serious) {
|
||||
return pht('Eat Paste');
|
||||
}
|
||||
|
||||
return parent::getCommentViewHeaderText($object);
|
||||
}
|
||||
|
||||
protected function getObjectViewURI($object) {
|
||||
return '/P'.$object->getID();
|
||||
}
|
||||
|
|
|
@ -163,6 +163,22 @@ abstract class PhabricatorEditEngine
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* @task text
|
||||
*/
|
||||
protected function getCommentViewHeaderText($object) {
|
||||
return pht('Add Comment');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @task text
|
||||
*/
|
||||
protected function getCommentViewButtonText($object) {
|
||||
return pht('Add Comment');
|
||||
}
|
||||
|
||||
|
||||
/* -( Edit Engine Configuration )------------------------------------------ */
|
||||
|
||||
|
||||
|
@ -574,6 +590,8 @@ abstract class PhabricatorEditEngine
|
|||
return $this->buildParametersResponse($object);
|
||||
case 'nodefault':
|
||||
return $this->buildNoDefaultResponse($object);
|
||||
case 'comment':
|
||||
return $this->buildCommentResponse($object);
|
||||
default:
|
||||
return $this->buildEditResponse($object);
|
||||
}
|
||||
|
@ -854,6 +872,27 @@ abstract class PhabricatorEditEngine
|
|||
$crumbs->addAction($action);
|
||||
}
|
||||
|
||||
final public function buildEditEngineCommentView($object) {
|
||||
$viewer = $this->getViewer();
|
||||
$object_phid = $object->getPHID();
|
||||
|
||||
$header_text = $this->getCommentViewHeaderText($object);
|
||||
$button_text = $this->getCommentViewButtonText($object);
|
||||
|
||||
// TODO: Drafts.
|
||||
// $draft = PhabricatorDraft::newFromUserAndKey(
|
||||
// $viewer,
|
||||
// $object_phid);
|
||||
|
||||
$comment_uri = $this->getEditURI($object, 'comment/');
|
||||
|
||||
return id(new PhabricatorApplicationTransactionCommentView())
|
||||
->setUser($viewer)
|
||||
->setObjectPHID($object_phid)
|
||||
->setHeaderText($header_text)
|
||||
->setAction($comment_uri)
|
||||
->setSubmitButtonName($button_text);
|
||||
}
|
||||
|
||||
/* -( Responding to HTTP Parameter Requests )------------------------------ */
|
||||
|
||||
|
@ -911,6 +950,60 @@ abstract class PhabricatorEditEngine
|
|||
->addCancelButton($cancel_uri);
|
||||
}
|
||||
|
||||
private function buildCommentResponse($object) {
|
||||
$viewer = $this->getViewer();
|
||||
|
||||
if ($this->getIsCreate()) {
|
||||
return new Aphront404Response();
|
||||
}
|
||||
|
||||
$controller = $this->getController();
|
||||
$request = $controller->getRequest();
|
||||
|
||||
if (!$request->isFormPost()) {
|
||||
return new Aphront400Response();
|
||||
}
|
||||
|
||||
$is_preview = $request->isPreviewRequest();
|
||||
$view_uri = $this->getObjectViewURI($object);
|
||||
|
||||
$template = $object->getApplicationTransactionTemplate();
|
||||
$comment_template = $template->getApplicationTransactionCommentObject();
|
||||
|
||||
$xactions = array();
|
||||
|
||||
$xactions[] = id(clone $template)
|
||||
->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)
|
||||
->attachComment(
|
||||
id(clone $comment_template)
|
||||
->setContent($request->getStr('comment')));
|
||||
|
||||
$editor = $object->getApplicationTransactionEditor()
|
||||
->setActor($viewer)
|
||||
->setContinueOnNoEffect($request->isContinueRequest())
|
||||
->setContentSourceFromRequest($request)
|
||||
->setIsPreview($is_preview);
|
||||
|
||||
try {
|
||||
$xactions = $editor->applyTransactions($object, $xactions);
|
||||
} catch (PhabricatorApplicationTransactionNoEffectException $ex) {
|
||||
return id(new PhabricatorApplicationTransactionNoEffectResponse())
|
||||
->setCancelURI($view_uri)
|
||||
->setException($ex);
|
||||
}
|
||||
|
||||
if ($request->isAjax() && $is_preview) {
|
||||
return id(new PhabricatorApplicationTransactionResponse())
|
||||
->setViewer($viewer)
|
||||
->setTransactions($xactions)
|
||||
->setIsPreview($is_preview);
|
||||
} else {
|
||||
return id(new AphrontRedirectResponse())
|
||||
->setURI($view_uri);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* -( Conduit )------------------------------------------------------------ */
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue