mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 05:50:55 +01:00
Update Legalpad to use comment transactions
Summary: Updates Legalpad to use comment transactions Test Plan: Leave some comments. Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Differential Revision: https://secure.phabricator.com/D17867
This commit is contained in:
parent
e1a97616cb
commit
28a23e3822
4 changed files with 9 additions and 102 deletions
|
@ -1404,7 +1404,6 @@ phutil_register_library_map(array(
|
|||
'LegalpadDefaultViewCapability' => 'applications/legalpad/capability/LegalpadDefaultViewCapability.php',
|
||||
'LegalpadDocument' => 'applications/legalpad/storage/LegalpadDocument.php',
|
||||
'LegalpadDocumentBody' => 'applications/legalpad/storage/LegalpadDocumentBody.php',
|
||||
'LegalpadDocumentCommentController' => 'applications/legalpad/controller/LegalpadDocumentCommentController.php',
|
||||
'LegalpadDocumentDatasource' => 'applications/legalpad/typeahead/LegalpadDocumentDatasource.php',
|
||||
'LegalpadDocumentDoneController' => 'applications/legalpad/controller/LegalpadDocumentDoneController.php',
|
||||
'LegalpadDocumentEditController' => 'applications/legalpad/controller/LegalpadDocumentEditController.php',
|
||||
|
@ -6436,7 +6435,6 @@ phutil_register_library_map(array(
|
|||
'LegalpadDAO',
|
||||
'PhabricatorMarkupInterface',
|
||||
),
|
||||
'LegalpadDocumentCommentController' => 'LegalpadController',
|
||||
'LegalpadDocumentDatasource' => 'PhabricatorTypeaheadDatasource',
|
||||
'LegalpadDocumentDoneController' => 'LegalpadController',
|
||||
'LegalpadDocumentEditController' => 'LegalpadController',
|
||||
|
|
|
@ -57,7 +57,6 @@ final class PhabricatorLegalpadApplication extends PhabricatorApplication {
|
|||
=> 'LegalpadDocumentListController',
|
||||
$this->getEditRoutePattern('edit/')
|
||||
=> 'LegalpadDocumentEditController',
|
||||
'comment/(?P<id>\d+)/' => 'LegalpadDocumentCommentController',
|
||||
'view/(?P<id>\d+)/' => 'LegalpadDocumentManageController',
|
||||
'done/' => 'LegalpadDocumentDoneController',
|
||||
'verify/(?P<code>[^/]+)/'
|
||||
|
|
|
@ -1,72 +0,0 @@
|
|||
<?php
|
||||
|
||||
final class LegalpadDocumentCommentController extends LegalpadController {
|
||||
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$viewer = $request->getViewer();
|
||||
$id = $request->getURIData('id');
|
||||
|
||||
if (!$request->isFormPost()) {
|
||||
return new Aphront400Response();
|
||||
}
|
||||
|
||||
$document = id(new LegalpadDocumentQuery())
|
||||
->setViewer($viewer)
|
||||
->withIDs(array($id))
|
||||
->needDocumentBodies(true)
|
||||
->executeOne();
|
||||
|
||||
if (!$document) {
|
||||
return new Aphront404Response();
|
||||
}
|
||||
|
||||
$is_preview = $request->isPreviewRequest();
|
||||
|
||||
$draft = PhabricatorDraft::buildFromRequest($request);
|
||||
|
||||
$document_uri = $this->getApplicationURI('view/'.$document->getID());
|
||||
|
||||
$comment = $request->getStr('comment');
|
||||
|
||||
$xactions = array();
|
||||
|
||||
if (strlen($comment)) {
|
||||
$xactions[] = id(new LegalpadTransaction())
|
||||
->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)
|
||||
->attachComment(
|
||||
id(new LegalpadTransactionComment())
|
||||
->setDocumentID($document->getID())
|
||||
->setLineNumber(0)
|
||||
->setLineLength(0)
|
||||
->setContent($comment));
|
||||
}
|
||||
|
||||
$editor = id(new LegalpadDocumentEditor())
|
||||
->setActor($viewer)
|
||||
->setContentSourceFromRequest($request)
|
||||
->setContinueOnNoEffect($request->isContinueRequest())
|
||||
->setIsPreview($is_preview);
|
||||
|
||||
try {
|
||||
$xactions = $editor->applyTransactions($document, $xactions);
|
||||
} catch (PhabricatorApplicationTransactionNoEffectException $ex) {
|
||||
return id(new PhabricatorApplicationTransactionNoEffectResponse())
|
||||
->setCancelURI($document_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($document_uri);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -37,6 +37,7 @@ final class LegalpadDocumentManageController extends LegalpadController {
|
|||
$document,
|
||||
new LegalpadTransactionQuery(),
|
||||
$engine);
|
||||
$timeline->setQuoteRef($document->getMonogram());
|
||||
|
||||
$title = $document_body->getTitle();
|
||||
|
||||
|
@ -50,9 +51,7 @@ final class LegalpadDocumentManageController extends LegalpadController {
|
|||
$properties = $this->buildPropertyView($document, $engine);
|
||||
$document_view = $this->buildDocumentView($document, $engine);
|
||||
|
||||
$comment_form_id = celerity_generate_unique_node_id();
|
||||
|
||||
$add_comment = $this->buildAddCommentView($document, $comment_form_id);
|
||||
$comment_form = $this->buildCommentView($document, $timeline);
|
||||
|
||||
$crumbs = $this->buildApplicationCrumbs();
|
||||
$crumbs->addTextCrumb(
|
||||
|
@ -69,7 +68,7 @@ final class LegalpadDocumentManageController extends LegalpadController {
|
|||
$properties,
|
||||
$document_view,
|
||||
$timeline,
|
||||
$add_comment,
|
||||
$comment_form,
|
||||
));
|
||||
|
||||
return $this->newPage()
|
||||
|
@ -181,31 +180,14 @@ final class LegalpadDocumentManageController extends LegalpadController {
|
|||
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY);
|
||||
}
|
||||
|
||||
private function buildAddCommentView(
|
||||
LegalpadDocument $document,
|
||||
$comment_form_id) {
|
||||
private function buildCommentView(LegalpadDocument $document, $timeline) {
|
||||
$viewer = $this->getViewer();
|
||||
$box = id(new LegalpadDocumentEditEngine())
|
||||
->setViewer($viewer)
|
||||
->buildEditEngineCommentView($document)
|
||||
->setTransactionTimeline($timeline);
|
||||
|
||||
$draft = PhabricatorDraft::newFromUserAndKey($viewer, $document->getPHID());
|
||||
|
||||
$is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
|
||||
|
||||
$title = $is_serious
|
||||
? pht('Add Comment')
|
||||
: pht('Debate Legislation');
|
||||
|
||||
$form = id(new PhabricatorApplicationTransactionCommentView())
|
||||
->setUser($viewer)
|
||||
->setObjectPHID($document->getPHID())
|
||||
->setFormID($comment_form_id)
|
||||
->setHeaderText($title)
|
||||
->setDraft($draft)
|
||||
->setSubmitButtonName(pht('Add Comment'))
|
||||
->setAction($this->getApplicationURI('/comment/'.$document->getID().'/'))
|
||||
->setRequestURI($this->getRequest()->getRequestURI());
|
||||
|
||||
return $form;
|
||||
|
||||
return $box;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue