From c51eb2696d43dd3ae6373d3cf099b61aa1bc3ded Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 10 May 2011 16:18:47 -0700 Subject: [PATCH] Add drafts to Maniphest Summary: Use PhabricatorDraft to save text when previewing it so you don't lose stuff if your browser crashes. Test Plan: Typed some text, closed/reopened the page, text was still there. Submitted comment, text vanished. Reviewed By: tuomaspelkonen Reviewers: rm, tuomaspelkonen, jungejason, aran CC: aran, tuomaspelkonen Differential Revision: 262 --- .../ManiphestTaskDetailController.php | 11 +++++++++++ .../controller/taskdetail/__init__.php | 1 + .../ManiphestTransactionPreviewController.php | 17 +++++++++++++++++ .../controller/transactionpreview/__init__.php | 3 +++ .../ManiphestTransactionSaveController.php | 8 ++++++++ .../controller/transactionsave/__init__.php | 1 + 6 files changed, 41 insertions(+) diff --git a/src/applications/maniphest/controller/taskdetail/ManiphestTaskDetailController.php b/src/applications/maniphest/controller/taskdetail/ManiphestTaskDetailController.php index 98e9027f12..9b9dafe20c 100644 --- a/src/applications/maniphest/controller/taskdetail/ManiphestTaskDetailController.php +++ b/src/applications/maniphest/controller/taskdetail/ManiphestTaskDetailController.php @@ -207,6 +207,16 @@ class ManiphestTaskDetailController extends ManiphestController { $user->getPHID() => $user->getUsername().' ('.$user->getRealName().')', ); + $draft = id(new PhabricatorDraft())->loadOneWhere( + 'authorPHID = %s AND draftKey = %s', + $user->getPHID(), + $task->getPHID()); + if ($draft) { + $draft_text = $draft->getDraft(); + } else { + $draft_text = null; + } + $comment_form = new AphrontFormView(); $comment_form ->setUser($user) @@ -268,6 +278,7 @@ class ManiphestTaskDetailController extends ManiphestController { id(new AphrontFormTextAreaControl()) ->setLabel('Comments') ->setName('comments') + ->setValue($draft_text) ->setID('transaction-comments')) ->appendChild( id(new AphrontFormSubmitControl()) diff --git a/src/applications/maniphest/controller/taskdetail/__init__.php b/src/applications/maniphest/controller/taskdetail/__init__.php index d62041b5bd..ea95fe847e 100644 --- a/src/applications/maniphest/controller/taskdetail/__init__.php +++ b/src/applications/maniphest/controller/taskdetail/__init__.php @@ -8,6 +8,7 @@ phutil_require_module('phabricator', 'aphront/response/404'); phutil_require_module('phabricator', 'applications/differential/parser/markup'); +phutil_require_module('phabricator', 'applications/draft/storage/draft'); phutil_require_module('phabricator', 'applications/maniphest/constants/priority'); phutil_require_module('phabricator', 'applications/maniphest/constants/status'); phutil_require_module('phabricator', 'applications/maniphest/constants/transactiontype'); diff --git a/src/applications/maniphest/controller/transactionpreview/ManiphestTransactionPreviewController.php b/src/applications/maniphest/controller/transactionpreview/ManiphestTransactionPreviewController.php index ec8082b19e..bd834b12f4 100644 --- a/src/applications/maniphest/controller/transactionpreview/ManiphestTransactionPreviewController.php +++ b/src/applications/maniphest/controller/transactionpreview/ManiphestTransactionPreviewController.php @@ -31,6 +31,23 @@ class ManiphestTransactionPreviewController extends ManiphestController { $comments = $request->getStr('comments'); + $task = id(new ManiphestTask())->load($this->id); + if (!$task) { + return new Aphront404Response(); + } + + $draft = id(new PhabricatorDraft())->loadOneWhere( + 'authorPHID = %s AND draftKey = %s', + $user->getPHID(), + $task->getPHID()); + if (!$draft) { + $draft = new PhabricatorDraft(); + $draft->setAuthorPHID($user->getPHID()); + $draft->setDraftKey($task->getPHID()); + } + $draft->setDraft($comments); + $draft->save(); + $handles = id(new PhabricatorObjectHandleData(array($user->getPHID()))) ->loadHandles(); diff --git a/src/applications/maniphest/controller/transactionpreview/__init__.php b/src/applications/maniphest/controller/transactionpreview/__init__.php index 75371bc120..f228cbff40 100644 --- a/src/applications/maniphest/controller/transactionpreview/__init__.php +++ b/src/applications/maniphest/controller/transactionpreview/__init__.php @@ -6,10 +6,13 @@ +phutil_require_module('phabricator', 'aphront/response/404'); phutil_require_module('phabricator', 'aphront/response/ajax'); phutil_require_module('phabricator', 'applications/differential/parser/markup'); +phutil_require_module('phabricator', 'applications/draft/storage/draft'); phutil_require_module('phabricator', 'applications/maniphest/constants/transactiontype'); phutil_require_module('phabricator', 'applications/maniphest/controller/base'); +phutil_require_module('phabricator', 'applications/maniphest/storage/task'); phutil_require_module('phabricator', 'applications/maniphest/storage/transaction'); phutil_require_module('phabricator', 'applications/maniphest/view/transactionlist'); phutil_require_module('phabricator', 'applications/phid/handle/data'); diff --git a/src/applications/maniphest/controller/transactionsave/ManiphestTransactionSaveController.php b/src/applications/maniphest/controller/transactionsave/ManiphestTransactionSaveController.php index ee2eafde7d..0c66906dbd 100644 --- a/src/applications/maniphest/controller/transactionsave/ManiphestTransactionSaveController.php +++ b/src/applications/maniphest/controller/transactionsave/ManiphestTransactionSaveController.php @@ -143,6 +143,14 @@ class ManiphestTransactionSaveController extends ManiphestController { $editor = new ManiphestTransactionEditor(); $editor->applyTransactions($task, $transactions); + $draft = id(new PhabricatorDraft())->loadOneWhere( + 'authorPHID = %s AND draftKey = %s', + $user->getPHID(), + $task->getPHID()); + if ($draft) { + $draft->delete(); + } + return id(new AphrontRedirectResponse()) ->setURI('/T'.$task->getID()); } diff --git a/src/applications/maniphest/controller/transactionsave/__init__.php b/src/applications/maniphest/controller/transactionsave/__init__.php index 2e4dd9538a..b06f03b2db 100644 --- a/src/applications/maniphest/controller/transactionsave/__init__.php +++ b/src/applications/maniphest/controller/transactionsave/__init__.php @@ -8,6 +8,7 @@ phutil_require_module('phabricator', 'aphront/response/404'); phutil_require_module('phabricator', 'aphront/response/redirect'); +phutil_require_module('phabricator', 'applications/draft/storage/draft'); phutil_require_module('phabricator', 'applications/files/storage/file'); phutil_require_module('phabricator', 'applications/maniphest/constants/status'); phutil_require_module('phabricator', 'applications/maniphest/constants/transactiontype');