Transactions - make the details stuff generic and ajaxy
Summary: Fixes T2213 Test Plan: Updated a pholio mock description. Observed that when I first showed details there was a round trip made. Toggled show / hide noting no more trips made to server. Reviewers: epriestley Reviewed By: epriestley CC: Korvin, aran Maniphest Tasks: T2213 Differential Revision: https://secure.phabricator.com/D6801
This commit is contained in:
		| @@ -2178,7 +2178,7 @@ celerity_register_resource_map(array( | |||||||
|   ), |   ), | ||||||
|   'javelin-behavior-phabricator-transaction-list' => |   'javelin-behavior-phabricator-transaction-list' => | ||||||
|   array( |   array( | ||||||
|     'uri' => '/res/8d602093/rsrc/js/application/transactions/behavior-transaction-list.js', |     'uri' => '/res/db441ac4/rsrc/js/application/transactions/behavior-transaction-list.js', | ||||||
|     'type' => 'js', |     'type' => 'js', | ||||||
|     'requires' => |     'requires' => | ||||||
|     array( |     array( | ||||||
|   | |||||||
| @@ -837,6 +837,7 @@ phutil_register_library_map(array( | |||||||
|     'PhabricatorApplicationTransactionCommentQuery' => 'applications/transactions/query/PhabricatorApplicationTransactionCommentQuery.php', |     'PhabricatorApplicationTransactionCommentQuery' => 'applications/transactions/query/PhabricatorApplicationTransactionCommentQuery.php', | ||||||
|     'PhabricatorApplicationTransactionCommentView' => 'applications/transactions/view/PhabricatorApplicationTransactionCommentView.php', |     'PhabricatorApplicationTransactionCommentView' => 'applications/transactions/view/PhabricatorApplicationTransactionCommentView.php', | ||||||
|     'PhabricatorApplicationTransactionController' => 'applications/transactions/controller/PhabricatorApplicationTransactionController.php', |     'PhabricatorApplicationTransactionController' => 'applications/transactions/controller/PhabricatorApplicationTransactionController.php', | ||||||
|  |     'PhabricatorApplicationTransactionDetailController' => 'applications/transactions/controller/PhabricatorApplicationTransactionDetailController.php', | ||||||
|     'PhabricatorApplicationTransactionEditor' => 'applications/transactions/editor/PhabricatorApplicationTransactionEditor.php', |     'PhabricatorApplicationTransactionEditor' => 'applications/transactions/editor/PhabricatorApplicationTransactionEditor.php', | ||||||
|     'PhabricatorApplicationTransactionFeedStory' => 'applications/transactions/feed/PhabricatorApplicationTransactionFeedStory.php', |     'PhabricatorApplicationTransactionFeedStory' => 'applications/transactions/feed/PhabricatorApplicationTransactionFeedStory.php', | ||||||
|     'PhabricatorApplicationTransactionInterface' => 'applications/transactions/interface/PhabricatorApplicationTransactionInterface.php', |     'PhabricatorApplicationTransactionInterface' => 'applications/transactions/interface/PhabricatorApplicationTransactionInterface.php', | ||||||
| @@ -2878,6 +2879,7 @@ phutil_register_library_map(array( | |||||||
|     'PhabricatorApplicationTransactionCommentQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', |     'PhabricatorApplicationTransactionCommentQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', | ||||||
|     'PhabricatorApplicationTransactionCommentView' => 'AphrontView', |     'PhabricatorApplicationTransactionCommentView' => 'AphrontView', | ||||||
|     'PhabricatorApplicationTransactionController' => 'PhabricatorController', |     'PhabricatorApplicationTransactionController' => 'PhabricatorController', | ||||||
|  |     'PhabricatorApplicationTransactionDetailController' => 'PhabricatorApplicationTransactionController', | ||||||
|     'PhabricatorApplicationTransactionEditor' => 'PhabricatorEditor', |     'PhabricatorApplicationTransactionEditor' => 'PhabricatorEditor', | ||||||
|     'PhabricatorApplicationTransactionFeedStory' => 'PhabricatorFeedStory', |     'PhabricatorApplicationTransactionFeedStory' => 'PhabricatorFeedStory', | ||||||
|     'PhabricatorApplicationTransactionNoEffectException' => 'Exception', |     'PhabricatorApplicationTransactionNoEffectException' => 'Exception', | ||||||
|   | |||||||
| @@ -17,6 +17,8 @@ final class PhabricatorApplicationTransactions extends PhabricatorApplication { | |||||||
|           => 'PhabricatorApplicationTransactionCommentEditController', |           => 'PhabricatorApplicationTransactionCommentEditController', | ||||||
|         'history/(?<phid>[^/]+)/' |         'history/(?<phid>[^/]+)/' | ||||||
|           => 'PhabricatorApplicationTransactionCommentHistoryController', |           => 'PhabricatorApplicationTransactionCommentHistoryController', | ||||||
|  |         'detail/(?<phid>[^/]+)/' | ||||||
|  |           => 'PhabricatorApplicationTransactionDetailController', | ||||||
|       ), |       ), | ||||||
|     ); |     ); | ||||||
|   } |   } | ||||||
|   | |||||||
| @@ -13,10 +13,10 @@ final class PhabricatorApplicationTransactionCommentEditController | |||||||
|     $request = $this->getRequest(); |     $request = $this->getRequest(); | ||||||
|     $user = $request->getUser(); |     $user = $request->getUser(); | ||||||
|  |  | ||||||
|     $xactions = id(new PhabricatorObjectHandleData(array($this->phid))) |     $xaction = id(new PhabricatorObjectQuery()) | ||||||
|  |       ->withPHIDs(array($this->phid)) | ||||||
|       ->setViewer($user) |       ->setViewer($user) | ||||||
|       ->loadObjects(); |       ->executeOne(); | ||||||
|     $xaction = idx($xactions, $this->phid); |  | ||||||
|  |  | ||||||
|     if (!$xaction) { |     if (!$xaction) { | ||||||
|       // TODO: This may also mean you don't have permission to edit the object, |       // TODO: This may also mean you don't have permission to edit the object, | ||||||
| @@ -33,10 +33,6 @@ final class PhabricatorApplicationTransactionCommentEditController | |||||||
|  |  | ||||||
|     $obj_phid = $xaction->getObjectPHID(); |     $obj_phid = $xaction->getObjectPHID(); | ||||||
|     $obj_handle = PhabricatorObjectHandleData::loadOneHandle($obj_phid, $user); |     $obj_handle = PhabricatorObjectHandleData::loadOneHandle($obj_phid, $user); | ||||||
|     if (!$obj_handle) { |  | ||||||
|       // Require the corresponding object exist and be visible to the user. |  | ||||||
|       return new Aphront404Response(); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     if ($request->isDialogFormPost()) { |     if ($request->isDialogFormPost()) { | ||||||
|       $text = $request->getStr('text'); |       $text = $request->getStr('text'); | ||||||
|   | |||||||
| @@ -13,10 +13,10 @@ final class PhabricatorApplicationTransactionCommentHistoryController | |||||||
|     $request = $this->getRequest(); |     $request = $this->getRequest(); | ||||||
|     $user = $request->getUser(); |     $user = $request->getUser(); | ||||||
|  |  | ||||||
|     $xactions = id(new PhabricatorObjectHandleData(array($this->phid))) |     $xaction = id(new PhabricatorObjectQuery()) | ||||||
|  |       ->withPHIDs(array($this->phid)) | ||||||
|       ->setViewer($user) |       ->setViewer($user) | ||||||
|       ->loadObjects(); |       ->executeOne(); | ||||||
|     $xaction = idx($xactions, $this->phid); |  | ||||||
|  |  | ||||||
|     if (!$xaction) { |     if (!$xaction) { | ||||||
|       // TODO: This may also mean you don't have permission to edit the object, |       // TODO: This may also mean you don't have permission to edit the object, | ||||||
| @@ -30,13 +30,6 @@ final class PhabricatorApplicationTransactionCommentHistoryController | |||||||
|       return new Aphront404Response(); |       return new Aphront404Response(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     $obj_phid = $xaction->getObjectPHID(); |  | ||||||
|     $obj_handle = PhabricatorObjectHandleData::loadOneHandle($obj_phid, $user); |  | ||||||
|     if (!$obj_handle) { |  | ||||||
|       // Require the corresponding object exist and be visible to the user. |  | ||||||
|       return new Aphront404Response(); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     $comments = id(new PhabricatorApplicationTransactionCommentQuery()) |     $comments = id(new PhabricatorApplicationTransactionCommentQuery()) | ||||||
|       ->setViewer($user) |       ->setViewer($user) | ||||||
|       ->setTemplate($xaction->getApplicationTransactionCommentObject()) |       ->setTemplate($xaction->getApplicationTransactionCommentObject()) | ||||||
| @@ -59,13 +52,15 @@ final class PhabricatorApplicationTransactionCommentHistoryController | |||||||
|         ->attachComment($comment); |         ->attachComment($comment); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     $obj_phid = $xaction->getObjectPHID(); | ||||||
|  |     $obj_handle = PhabricatorObjectHandleData::loadOneHandle($obj_phid, $user); | ||||||
|  |  | ||||||
|     $view = id(new PhabricatorApplicationTransactionView()) |     $view = id(new PhabricatorApplicationTransactionView()) | ||||||
|       ->setUser($user) |       ->setUser($user) | ||||||
|       ->setObjectPHID($obj_phid) |       ->setObjectPHID($obj_phid) | ||||||
|       ->setTransactions($xactions) |       ->setTransactions($xactions) | ||||||
|       ->setShowEditActions(false); |       ->setShowEditActions(false); | ||||||
|  |  | ||||||
|  |  | ||||||
|     $dialog = id(new AphrontDialogView()) |     $dialog = id(new AphrontDialogView()) | ||||||
|       ->setUser($user) |       ->setUser($user) | ||||||
|       ->setWidth(AphrontDialogView::WIDTH_FULL) |       ->setWidth(AphrontDialogView::WIDTH_FULL) | ||||||
|   | |||||||
| @@ -0,0 +1,33 @@ | |||||||
|  | <?php | ||||||
|  |  | ||||||
|  | final class PhabricatorApplicationTransactionDetailController | ||||||
|  |   extends PhabricatorApplicationTransactionController { | ||||||
|  |  | ||||||
|  |   private $phid; | ||||||
|  |  | ||||||
|  |   public function willProcessRequest(array $data) { | ||||||
|  |     $this->phid = $data['phid']; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   public function processRequest() { | ||||||
|  |     $request = $this->getRequest(); | ||||||
|  |     $user = $request->getUser(); | ||||||
|  |  | ||||||
|  |     $xaction = id(new PhabricatorObjectQuery()) | ||||||
|  |       ->withPHIDs(array($this->phid)) | ||||||
|  |       ->setViewer($user) | ||||||
|  |       ->executeOne(); | ||||||
|  |  | ||||||
|  |     if (!$xaction) { | ||||||
|  |       // future proofing for the day visibility of transactions can change | ||||||
|  |       return new Aphront404Response(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     return id(new PhabricatorApplicationTransactionResponse()) | ||||||
|  |       ->setViewer($user) | ||||||
|  |       ->setTransactions(array($xaction)) | ||||||
|  |       ->setIsDetailView(true) | ||||||
|  |       ->setAnchorOffset($request->getStr('anchor')); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  | } | ||||||
| @@ -7,6 +7,7 @@ final class PhabricatorApplicationTransactionResponse | |||||||
|   private $transactions; |   private $transactions; | ||||||
|   private $anchorOffset; |   private $anchorOffset; | ||||||
|   private $isPreview; |   private $isPreview; | ||||||
|  |   private $isDetailView; | ||||||
|  |  | ||||||
|   protected function buildProxy() { |   protected function buildProxy() { | ||||||
|     return new AphrontAjaxResponse(); |     return new AphrontAjaxResponse(); | ||||||
| @@ -46,6 +47,11 @@ final class PhabricatorApplicationTransactionResponse | |||||||
|     return $this; |     return $this; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   public function setIsDetailView($is_detail_view) { | ||||||
|  |     $this->isDetailView = $is_detail_view; | ||||||
|  |     return $this; | ||||||
|  |   } | ||||||
|  |  | ||||||
|   public function reduceProxyResponse() { |   public function reduceProxyResponse() { | ||||||
|     if ($this->getTransactions()) { |     if ($this->getTransactions()) { | ||||||
|       $view = head($this->getTransactions()) |       $view = head($this->getTransactions()) | ||||||
| @@ -57,7 +63,8 @@ final class PhabricatorApplicationTransactionResponse | |||||||
|     $view |     $view | ||||||
|       ->setUser($this->getViewer()) |       ->setUser($this->getViewer()) | ||||||
|       ->setTransactions($this->getTransactions()) |       ->setTransactions($this->getTransactions()) | ||||||
|       ->setIsPreview($this->isPreview); |       ->setIsPreview($this->isPreview) | ||||||
|  |       ->setIsDetailView($this->isDetailView); | ||||||
|  |  | ||||||
|     if ($this->getAnchorOffset()) { |     if ($this->getAnchorOffset()) { | ||||||
|       $view->setAnchorOffset($this->getAnchorOffset()); |       $view->setAnchorOffset($this->getAnchorOffset()); | ||||||
|   | |||||||
| @@ -11,6 +11,12 @@ class PhabricatorApplicationTransactionView extends AphrontView { | |||||||
|   private $showEditActions = true; |   private $showEditActions = true; | ||||||
|   private $isPreview; |   private $isPreview; | ||||||
|   private $objectPHID; |   private $objectPHID; | ||||||
|  |   private $isDetailView; | ||||||
|  |  | ||||||
|  |   public function setIsDetailView($is_detail_view) { | ||||||
|  |     $this->isDetailView = $is_detail_view; | ||||||
|  |     return $this; | ||||||
|  |   } | ||||||
|  |  | ||||||
|   public function setObjectPHID($object_phid) { |   public function setObjectPHID($object_phid) { | ||||||
|     $this->objectPHID = $object_phid; |     $this->objectPHID = $object_phid; | ||||||
| @@ -89,10 +95,15 @@ class PhabricatorApplicationTransactionView extends AphrontView { | |||||||
|  |  | ||||||
|       $title = $xaction->getTitle(); |       $title = $xaction->getTitle(); | ||||||
|       if ($xaction->hasChangeDetails()) { |       if ($xaction->hasChangeDetails()) { | ||||||
|  |         if ($this->isPreview || $this->isDetailView) { | ||||||
|  |           $details = $this->buildChangeDetails($xaction); | ||||||
|  |         } else { | ||||||
|  |           $details = $this->buildChangeDetailsLink($xaction); | ||||||
|  |         } | ||||||
|         $title = array( |         $title = array( | ||||||
|           $title, |           $title, | ||||||
|           ' ', |           ' ', | ||||||
|           $this->buildChangeDetails($xaction), |           $details, | ||||||
|         ); |         ); | ||||||
|       } |       } | ||||||
|       $event->setTitle($title); |       $event->setTitle($title); | ||||||
| @@ -168,7 +179,6 @@ class PhabricatorApplicationTransactionView extends AphrontView { | |||||||
|     return $view->render(); |     return $view->render(); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |  | ||||||
|   protected function getOrBuildEngine() { |   protected function getOrBuildEngine() { | ||||||
|     if ($this->engine) { |     if ($this->engine) { | ||||||
|       return $this->engine; |       return $this->engine; | ||||||
| @@ -205,6 +215,7 @@ class PhabricatorApplicationTransactionView extends AphrontView { | |||||||
|         'sigil' => 'reveal-content', |         'sigil' => 'reveal-content', | ||||||
|         'mustcapture' => true, |         'mustcapture' => true, | ||||||
|         'id' => $show_id, |         'id' => $show_id, | ||||||
|  |         'style' => 'display: none', | ||||||
|         'meta' => array( |         'meta' => array( | ||||||
|           'hideIDs' => array($show_id), |           'hideIDs' => array($show_id), | ||||||
|           'showIDs' => array($hide_id, $content_id), |           'showIDs' => array($hide_id, $content_id), | ||||||
| @@ -219,7 +230,6 @@ class PhabricatorApplicationTransactionView extends AphrontView { | |||||||
|         'sigil' => 'reveal-content', |         'sigil' => 'reveal-content', | ||||||
|         'mustcapture' => true, |         'mustcapture' => true, | ||||||
|         'id' => $hide_id, |         'id' => $hide_id, | ||||||
|         'style' => 'display: none', |  | ||||||
|         'meta' => array( |         'meta' => array( | ||||||
|           'hideIDs' => array($hide_id, $content_id), |           'hideIDs' => array($hide_id, $content_id), | ||||||
|           'showIDs' => array($show_id), |           'showIDs' => array($show_id), | ||||||
| @@ -231,7 +241,6 @@ class PhabricatorApplicationTransactionView extends AphrontView { | |||||||
|       'div', |       'div', | ||||||
|       array( |       array( | ||||||
|         'id'    => $content_id, |         'id'    => $content_id, | ||||||
|         'style' => 'display: none', |  | ||||||
|         'class' => 'phabricator-timeline-change-details', |         'class' => 'phabricator-timeline-change-details', | ||||||
|       ), |       ), | ||||||
|       $xaction->renderChangeDetails($this->getUser())); |       $xaction->renderChangeDetails($this->getUser())); | ||||||
| @@ -243,6 +252,22 @@ class PhabricatorApplicationTransactionView extends AphrontView { | |||||||
|     ); |     ); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   private function buildChangeDetailsLink( | ||||||
|  |     PhabricatorApplicationTransaction $xaction) { | ||||||
|  |  | ||||||
|  |     return javelin_tag( | ||||||
|  |       'a', | ||||||
|  |       array( | ||||||
|  |         'href' => '/transactions/detail/'.$xaction->getPHID().'/', | ||||||
|  |         'sigil' => 'transaction-detail', | ||||||
|  |         'mustcapture' => true, | ||||||
|  |         'meta' => array( | ||||||
|  |           'anchor' => $this->anchorOffset, | ||||||
|  |         ), | ||||||
|  |       ), | ||||||
|  |       pht('(Show Details)')); | ||||||
|  |   } | ||||||
|  |  | ||||||
|   protected function shouldGroupTransactions( |   protected function shouldGroupTransactions( | ||||||
|     PhabricatorApplicationTransaction $u, |     PhabricatorApplicationTransaction $u, | ||||||
|     PhabricatorApplicationTransaction $v) { |     PhabricatorApplicationTransaction $v) { | ||||||
|   | |||||||
| @@ -75,6 +75,19 @@ JX.behavior('phabricator-transaction-list', function(config) { | |||||||
|     e.kill(); |     e.kill(); | ||||||
|   }); |   }); | ||||||
|  |  | ||||||
|  |   JX.DOM.listen(list, 'click', 'transaction-detail', function(e) { | ||||||
|  |     if (!e.isNormalClick()) { | ||||||
|  |       return; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     JX.Workflow.newFromLink(e.getTarget()) | ||||||
|  |       .setData({anchor: e.getData('anchor')}) | ||||||
|  |       .setHandler(ontransactions) | ||||||
|  |       .start(); | ||||||
|  |  | ||||||
|  |     e.kill(); | ||||||
|  |   }); | ||||||
|  |  | ||||||
|   JX.Stratcom.listen( |   JX.Stratcom.listen( | ||||||
|     ['submit', 'didSyntheticSubmit'], |     ['submit', 'didSyntheticSubmit'], | ||||||
|     'transaction-append', |     'transaction-append', | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Bob Trahan
					Bob Trahan