From 644f377915de1f6f55c6bec0bedb00e5b28df9fe Mon Sep 17 00:00:00 2001 From: epriestley Date: Sun, 28 Jul 2013 18:32:55 -0700 Subject: [PATCH] Move non-comment transactions to a separate history view in Ponder Summary: Ref T3373. Most edits aren't too interesting, put them on a separate history page. Test Plan: Viewed question page; viewed history page for question and answer. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T3373 Differential Revision: https://secure.phabricator.com/D6612 --- src/__phutil_library_map__.php | 4 + .../PhabricatorApplicationPonder.php | 2 + .../PonderAnswerHistoryController.php | 73 +++++++++++++++++++ .../PonderQuestionHistoryController.php | 68 +++++++++++++++++ .../PonderQuestionViewController.php | 14 ++++ ...PhabricatorApplicationTransactionQuery.php | 13 ++++ 6 files changed, 174 insertions(+) create mode 100644 src/applications/ponder/controller/PonderAnswerHistoryController.php create mode 100644 src/applications/ponder/controller/PonderQuestionHistoryController.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index cbaf178d68..997736938b 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1873,6 +1873,7 @@ phutil_register_library_map(array( 'PonderAnswerCommentController' => 'applications/ponder/controller/PonderAnswerCommentController.php', 'PonderAnswerEditController' => 'applications/ponder/controller/PonderAnswerEditController.php', 'PonderAnswerEditor' => 'applications/ponder/editor/PonderAnswerEditor.php', + 'PonderAnswerHistoryController' => 'applications/ponder/controller/PonderAnswerHistoryController.php', 'PonderAnswerListView' => 'applications/ponder/view/PonderAnswerListView.php', 'PonderAnswerQuery' => 'applications/ponder/query/PonderAnswerQuery.php', 'PonderAnswerSaveController' => 'applications/ponder/controller/PonderAnswerSaveController.php', @@ -1900,6 +1901,7 @@ phutil_register_library_map(array( 'PonderQuestionDetailView' => 'applications/ponder/view/PonderQuestionDetailView.php', 'PonderQuestionEditController' => 'applications/ponder/controller/PonderQuestionEditController.php', 'PonderQuestionEditor' => 'applications/ponder/editor/PonderQuestionEditor.php', + 'PonderQuestionHistoryController' => 'applications/ponder/controller/PonderQuestionHistoryController.php', 'PonderQuestionListController' => 'applications/ponder/controller/PonderQuestionListController.php', 'PonderQuestionMailReceiver' => 'applications/ponder/mail/PonderQuestionMailReceiver.php', 'PonderQuestionPreviewController' => 'applications/ponder/controller/PonderQuestionPreviewController.php', @@ -3997,6 +3999,7 @@ phutil_register_library_map(array( 'PonderAnswerCommentController' => 'PonderController', 'PonderAnswerEditController' => 'PonderController', 'PonderAnswerEditor' => 'PhabricatorApplicationTransactionEditor', + 'PonderAnswerHistoryController' => 'PonderController', 'PonderAnswerListView' => 'AphrontView', 'PonderAnswerQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PonderAnswerSaveController' => 'PonderController', @@ -4035,6 +4038,7 @@ phutil_register_library_map(array( 'PonderQuestionDetailView' => 'AphrontView', 'PonderQuestionEditController' => 'PonderController', 'PonderQuestionEditor' => 'PhabricatorApplicationTransactionEditor', + 'PonderQuestionHistoryController' => 'PonderController', 'PonderQuestionListController' => array( 0 => 'PonderController', diff --git a/src/applications/ponder/application/PhabricatorApplicationPonder.php b/src/applications/ponder/application/PhabricatorApplicationPonder.php index 35c31a95d9..c9b9fdd4ce 100644 --- a/src/applications/ponder/application/PhabricatorApplicationPonder.php +++ b/src/applications/ponder/application/PhabricatorApplicationPonder.php @@ -53,8 +53,10 @@ final class PhabricatorApplicationPonder extends PhabricatorApplication { 'answer/add/' => 'PonderAnswerSaveController', 'answer/edit/(?P\d+)/' => 'PonderAnswerEditController', 'answer/comment/(?P\d+)/' => 'PonderAnswerCommentController', + 'answer/history/(?P\d+)/' => 'PonderAnswerHistoryController', 'question/edit/(?:(?P\d+)/)?' => 'PonderQuestionEditController', 'question/comment/(?P\d+)/' => 'PonderQuestionCommentController', + 'question/history/(?P\d+)/' => 'PonderQuestionHistoryController', 'question/preview/' => 'PonderQuestionPreviewController', 'question/(?Popen|close)/(?P[1-9]\d*)/' => 'PonderQuestionStatusController', diff --git a/src/applications/ponder/controller/PonderAnswerHistoryController.php b/src/applications/ponder/controller/PonderAnswerHistoryController.php new file mode 100644 index 0000000000..39e69a9484 --- /dev/null +++ b/src/applications/ponder/controller/PonderAnswerHistoryController.php @@ -0,0 +1,73 @@ +id = $data['id']; + } + + public function processRequest() { + $request = $this->getRequest(); + $viewer = $request->getUser(); + + $answer = id(new PonderAnswerQuery()) + ->setViewer($viewer) + ->withIDs(array($this->id)) + ->executeOne(); + if (!$answer) { + return new Aphront404Response(); + } + + $xactions = id(new PonderAnswerTransactionQuery()) + ->setViewer($viewer) + ->withObjectPHIDs(array($answer->getPHID())) + ->execute(); + + $engine = id(new PhabricatorMarkupEngine()) + ->setViewer($viewer); + foreach ($xactions as $xaction) { + if ($xaction->getComment()) { + $engine->addObject( + $xaction->getComment(), + PhabricatorApplicationTransactionComment::MARKUP_FIELD_COMMENT); + } + } + $engine->process(); + + $timeline = id(new PhabricatorApplicationTransactionView()) + ->setUser($viewer) + ->setObjectPHID($answer->getPHID()) + ->setTransactions($xactions) + ->setMarkupEngine($engine); + + $qid = $answer->getQuestion()->getID(); + $aid = $answer->getID(); + + $crumbs = $this->buildApplicationCrumbs(); + $crumbs->addCrumb( + id(new PhabricatorCrumbView()) + ->setName("Q{$qid}") + ->setHref("/Q{$qid}")); + $crumbs->addCrumb( + id(new PhabricatorCrumbView()) + ->setName("A{$aid}") + ->setHref("/Q{$qid}#{$aid}")); + $crumbs->addCrumb( + id(new PhabricatorCrumbView()) + ->setName(pht('History'))); + + return $this->buildApplicationPage( + array( + $crumbs, + $timeline, + ), + array( + 'title' => pht('Answer History'), + 'dust' => true, + 'device' => true, + )); + } + +} diff --git a/src/applications/ponder/controller/PonderQuestionHistoryController.php b/src/applications/ponder/controller/PonderQuestionHistoryController.php new file mode 100644 index 0000000000..85c76b1a7d --- /dev/null +++ b/src/applications/ponder/controller/PonderQuestionHistoryController.php @@ -0,0 +1,68 @@ +id = $data['id']; + } + + public function processRequest() { + $request = $this->getRequest(); + $viewer = $request->getUser(); + + $question = id(new PonderQuestionQuery()) + ->setViewer($viewer) + ->withIDs(array($this->id)) + ->executeOne(); + if (!$question) { + return new Aphront404Response(); + } + + $xactions = id(new PonderQuestionTransactionQuery()) + ->setViewer($viewer) + ->withObjectPHIDs(array($question->getPHID())) + ->execute(); + + $engine = id(new PhabricatorMarkupEngine()) + ->setViewer($viewer); + foreach ($xactions as $xaction) { + if ($xaction->getComment()) { + $engine->addObject( + $xaction->getComment(), + PhabricatorApplicationTransactionComment::MARKUP_FIELD_COMMENT); + } + } + $engine->process(); + + $timeline = id(new PhabricatorApplicationTransactionView()) + ->setUser($viewer) + ->setObjectPHID($question->getPHID()) + ->setTransactions($xactions) + ->setMarkupEngine($engine); + + $qid = $question->getID(); + + $crumbs = $this->buildApplicationCrumbs(); + $crumbs->addCrumb( + id(new PhabricatorCrumbView()) + ->setName("Q{$qid}") + ->setHref("/Q{$qid}")); + $crumbs->addCrumb( + id(new PhabricatorCrumbView()) + ->setName(pht('History'))); + + return $this->buildApplicationPage( + array( + $crumbs, + $timeline, + ), + array( + 'title' => pht('Question History'), + 'dust' => true, + 'device' => true, + )); + } + +} diff --git a/src/applications/ponder/controller/PonderQuestionViewController.php b/src/applications/ponder/controller/PonderQuestionViewController.php index c006fd7692..d71026b299 100644 --- a/src/applications/ponder/controller/PonderQuestionViewController.php +++ b/src/applications/ponder/controller/PonderQuestionViewController.php @@ -113,6 +113,12 @@ final class PonderQuestionViewController extends PonderController { ->setDisabled(!$can_edit) ->setHref($this->getApplicationURI("/question/{$href}/{$id}/"))); + $view->addAction( + id(new PhabricatorActionView()) + ->setIcon('transcript') + ->setName(pht('View History')) + ->setHref($this->getApplicationURI("/question/history/{$id}/"))); + return $view; } @@ -156,6 +162,7 @@ final class PonderQuestionViewController extends PonderController { $xactions = id(new PonderQuestionTransactionQuery()) ->setViewer($viewer) + ->withTransactionTypes(array(PhabricatorTransactions::TYPE_COMMENT)) ->withObjectPHIDs(array($question->getPHID())) ->execute(); @@ -200,6 +207,7 @@ final class PonderQuestionViewController extends PonderController { $xactions = id(new PonderAnswerTransactionQuery()) ->setViewer($viewer) + ->withTransactionTypes(array(PhabricatorTransactions::TYPE_COMMENT)) ->withObjectPHIDs(mpull($answers, 'getPHID')) ->execute(); @@ -274,6 +282,12 @@ final class PonderQuestionViewController extends PonderController { ->setDisabled(!$can_edit) ->setWorkflow(!$can_edit)); + $view->addAction( + id(new PhabricatorActionView()) + ->setIcon('transcript') + ->setName(pht('View History')) + ->setHref($this->getApplicationURI("/answer/history/{$id}/"))); + return $view; } diff --git a/src/applications/transactions/query/PhabricatorApplicationTransactionQuery.php b/src/applications/transactions/query/PhabricatorApplicationTransactionQuery.php index b0d17233cf..25d930e970 100644 --- a/src/applications/transactions/query/PhabricatorApplicationTransactionQuery.php +++ b/src/applications/transactions/query/PhabricatorApplicationTransactionQuery.php @@ -6,6 +6,7 @@ abstract class PhabricatorApplicationTransactionQuery private $phids; private $objectPHIDs; private $authorPHIDs; + private $transactionTypes; private $needComments = true; private $needHandles = true; @@ -35,6 +36,11 @@ abstract class PhabricatorApplicationTransactionQuery return $this; } + public function withTransactionTypes(array $transaction_types) { + $this->transactionTypes = $transaction_types; + return $this; + } + public function needComments($need) { $this->needComments = $need; return $this; @@ -133,6 +139,13 @@ abstract class PhabricatorApplicationTransactionQuery $this->authorPHIDs); } + if ($this->transactionTypes) { + $where[] = qsprintf( + $conn_r, + 'transactionType IN (%Ls)', + $this->transactionTypes); + } + foreach ($this->buildMoreWhereClauses($conn_r) as $clause) { $where[] = $clause; }