From e15b3fc6f34bd9cbb2d60866bc0ae892b6889780 Mon Sep 17 00:00:00 2001 From: Bob Trahan Date: Thu, 2 Feb 2012 15:21:30 -0800 Subject: [PATCH] Clean up initialization of Differential Show More Behavior in Maniphest Summary: add a static variable to the method and use it so we don't init more than once! Test Plan: add a "phlog" and noted only init'd one time. verified "show more" links worked correctly. Reviewers: epriestley Reviewed By: epriestley CC: aran, epriestley Maniphest Tasks: T666 Differential Revision: https://secure.phabricator.com/D1553 --- src/__phutil_library_map__.php | 2 ++ ...AphrontDefaultApplicationConfiguration.php | 2 ++ ...niphestTaskDescriptionChangeController.php | 12 ++------ ...ManiphestTaskDescriptionDiffController.php | 29 +++++++++++++++++++ .../controller/descriptiondiff/__init__.php | 12 ++++++++ .../ManiphestTransactionDetailView.php | 15 +--------- .../ManiphestTransactionListView.php | 17 ++++++++++- .../view/transactionlist/__init__.php | 4 +++ 8 files changed, 68 insertions(+), 25 deletions(-) create mode 100644 src/applications/maniphest/controller/descriptiondiff/ManiphestTaskDescriptionDiffController.php create mode 100644 src/applications/maniphest/controller/descriptiondiff/__init__.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 66d5311ab0..ab072b3d63 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -395,6 +395,7 @@ phutil_register_library_map(array( 'ManiphestTask' => 'applications/maniphest/storage/task', 'ManiphestTaskAuxiliaryStorage' => 'applications/maniphest/storage/auxiliary', 'ManiphestTaskDescriptionChangeController' => 'applications/maniphest/controller/descriptionchange', + 'ManiphestTaskDescriptionDiffController' => 'applications/maniphest/controller/descriptiondiff', 'ManiphestTaskDescriptionPreviewController' => 'applications/maniphest/controller/descriptionpreview', 'ManiphestTaskDetailController' => 'applications/maniphest/controller/taskdetail', 'ManiphestTaskEditController' => 'applications/maniphest/controller/taskedit', @@ -1131,6 +1132,7 @@ phutil_register_library_map(array( 'ManiphestTask' => 'ManiphestDAO', 'ManiphestTaskAuxiliaryStorage' => 'ManiphestDAO', 'ManiphestTaskDescriptionChangeController' => 'ManiphestController', + 'ManiphestTaskDescriptionDiffController' => 'ManiphestTaskDescriptionChangeController', 'ManiphestTaskDescriptionPreviewController' => 'ManiphestController', 'ManiphestTaskDetailController' => 'ManiphestController', 'ManiphestTaskEditController' => 'ManiphestController', diff --git a/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php b/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php index ec5d10359f..e39bfb4476 100644 --- a/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php +++ b/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php @@ -167,6 +167,8 @@ class AphrontDefaultApplicationConfiguration 'edit/(?P\d+)/$' => 'ManiphestTaskEditController', 'descriptionchange/(?P\d+)/$' => 'ManiphestTaskDescriptionChangeController', + 'descriptiondiff/$' => + 'ManiphestTaskDescriptionDiffController', 'descriptionpreview/$' => 'ManiphestTaskDescriptionPreviewController', ), diff --git a/src/applications/maniphest/controller/descriptionchange/ManiphestTaskDescriptionChangeController.php b/src/applications/maniphest/controller/descriptionchange/ManiphestTaskDescriptionChangeController.php index 9b7a4b3505..8f9a81945e 100644 --- a/src/applications/maniphest/controller/descriptionchange/ManiphestTaskDescriptionChangeController.php +++ b/src/applications/maniphest/controller/descriptionchange/ManiphestTaskDescriptionChangeController.php @@ -1,7 +1,7 @@ transactionID = $transaction_id; return $this; } @@ -37,17 +37,9 @@ class ManiphestTaskDescriptionChangeController extends ManiphestController { } public function processRequest() { - $request = $this->getRequest(); $user = $request->getUser(); - // this means we're using "show more" on a diff of a description and - // should thus use the rendering reference to identify the transaction - $ref = $request->getStr('ref'); - if ($ref) { - $this->setTransactionID($ref); - } - $transaction_id = $this->getTransactionID(); $transaction = id(new ManiphestTransaction())->load($transaction_id); if (!$transaction) { diff --git a/src/applications/maniphest/controller/descriptiondiff/ManiphestTaskDescriptionDiffController.php b/src/applications/maniphest/controller/descriptiondiff/ManiphestTaskDescriptionDiffController.php new file mode 100644 index 0000000000..e9e00eddd4 --- /dev/null +++ b/src/applications/maniphest/controller/descriptiondiff/ManiphestTaskDescriptionDiffController.php @@ -0,0 +1,29 @@ +getRequest()->getStr('ref'); + $this->setTransactionID($ref); + } +} diff --git a/src/applications/maniphest/controller/descriptiondiff/__init__.php b/src/applications/maniphest/controller/descriptiondiff/__init__.php new file mode 100644 index 0000000000..7e1ba1bbda --- /dev/null +++ b/src/applications/maniphest/controller/descriptiondiff/__init__.php @@ -0,0 +1,12 @@ +getTransactionType()) { case ManiphestTransactionType::TYPE_DESCRIPTION: $id = $transaction->getID(); + $old_text = wordwrap($transaction->getOldValue(), 80); $new_text = wordwrap($transaction->getNewValue(), 80); @@ -593,20 +594,6 @@ class ManiphestTransactionDetailView extends ManiphestView { Javelin::initBehavior('maniphest-transaction-expand'); - switch ($transaction->getTransactionType()) { - case ManiphestTransactionType::TYPE_DESCRIPTION: - require_celerity_resource('differential-changeset-view-css'); - require_celerity_resource('syntax-highlighting-css'); - $whitespace_mode = DifferentialChangesetParser::WHITESPACE_SHOW_ALL; - Javelin::initBehavior('differential-show-more', array( - 'uri' => '/maniphest/task/descriptionchange/'.$id.'/', - 'whitespace' => $whitespace_mode, - )); - break; - default: - break; - } - return javelin_render_tag( 'a', array( diff --git a/src/applications/maniphest/view/transactionlist/ManiphestTransactionListView.php b/src/applications/maniphest/view/transactionlist/ManiphestTransactionListView.php index 466c62df05..a7761e291e 100644 --- a/src/applications/maniphest/view/transactionlist/ManiphestTransactionListView.php +++ b/src/applications/maniphest/view/transactionlist/ManiphestTransactionListView.php @@ -1,7 +1,7 @@ transactions as $transaction) { + if ($transaction->getTransactionType() == + ManiphestTransactionType::TYPE_DESCRIPTION) { + $has_description_transaction = true; + } if ($last === null) { $last = $transaction; $group[] = $transaction; @@ -80,6 +85,16 @@ class ManiphestTransactionListView extends ManiphestView { $groups[] = $group; } + if ($has_description_transaction) { + require_celerity_resource('differential-changeset-view-css'); + require_celerity_resource('syntax-highlighting-css'); + $whitespace_mode = DifferentialChangesetParser::WHITESPACE_SHOW_ALL; + Javelin::initBehavior('differential-show-more', array( + 'uri' => '/maniphest/task/descriptiondiff/', + 'whitespace' => $whitespace_mode, + )); + } + $sequence = 1; foreach ($groups as $group) { $view = new ManiphestTransactionDetailView(); diff --git a/src/applications/maniphest/view/transactionlist/__init__.php b/src/applications/maniphest/view/transactionlist/__init__.php index 6611e4539a..9f8ccfe06d 100644 --- a/src/applications/maniphest/view/transactionlist/__init__.php +++ b/src/applications/maniphest/view/transactionlist/__init__.php @@ -6,8 +6,12 @@ +phutil_require_module('phabricator', 'applications/differential/parser/changeset'); +phutil_require_module('phabricator', 'applications/maniphest/constants/transactiontype'); phutil_require_module('phabricator', 'applications/maniphest/view/base'); phutil_require_module('phabricator', 'applications/maniphest/view/transactiondetail'); +phutil_require_module('phabricator', 'infrastructure/celerity/api'); +phutil_require_module('phabricator', 'infrastructure/javelin/api'); phutil_require_source('ManiphestTransactionListView.php');