Skip to content

Commit 320498d

Browse files
committed
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
1 parent 099695a commit 320498d

9 files changed

+97
-24
lines changed

src/__celerity_resource_map__.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2178,7 +2178,7 @@
21782178
),
21792179
'javelin-behavior-phabricator-transaction-list' =>
21802180
array(
2181-
'uri' => '/res/8d602093/rsrc/js/application/transactions/behavior-transaction-list.js',
2181+
'uri' => '/res/db441ac4/rsrc/js/application/transactions/behavior-transaction-list.js',
21822182
'type' => 'js',
21832183
'requires' =>
21842184
array(

src/__phutil_library_map__.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,7 @@
837837
'PhabricatorApplicationTransactionCommentQuery' => 'applications/transactions/query/PhabricatorApplicationTransactionCommentQuery.php',
838838
'PhabricatorApplicationTransactionCommentView' => 'applications/transactions/view/PhabricatorApplicationTransactionCommentView.php',
839839
'PhabricatorApplicationTransactionController' => 'applications/transactions/controller/PhabricatorApplicationTransactionController.php',
840+
'PhabricatorApplicationTransactionDetailController' => 'applications/transactions/controller/PhabricatorApplicationTransactionDetailController.php',
840841
'PhabricatorApplicationTransactionEditor' => 'applications/transactions/editor/PhabricatorApplicationTransactionEditor.php',
841842
'PhabricatorApplicationTransactionFeedStory' => 'applications/transactions/feed/PhabricatorApplicationTransactionFeedStory.php',
842843
'PhabricatorApplicationTransactionInterface' => 'applications/transactions/interface/PhabricatorApplicationTransactionInterface.php',
@@ -2878,6 +2879,7 @@
28782879
'PhabricatorApplicationTransactionCommentQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
28792880
'PhabricatorApplicationTransactionCommentView' => 'AphrontView',
28802881
'PhabricatorApplicationTransactionController' => 'PhabricatorController',
2882+
'PhabricatorApplicationTransactionDetailController' => 'PhabricatorApplicationTransactionController',
28812883
'PhabricatorApplicationTransactionEditor' => 'PhabricatorEditor',
28822884
'PhabricatorApplicationTransactionFeedStory' => 'PhabricatorFeedStory',
28832885
'PhabricatorApplicationTransactionNoEffectException' => 'Exception',

src/applications/transactions/application/PhabricatorApplicationTransactions.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public function getRoutes() {
1717
=> 'PhabricatorApplicationTransactionCommentEditController',
1818
'history/(?<phid>[^/]+)/'
1919
=> 'PhabricatorApplicationTransactionCommentHistoryController',
20+
'detail/(?<phid>[^/]+)/'
21+
=> 'PhabricatorApplicationTransactionDetailController',
2022
),
2123
);
2224
}

src/applications/transactions/controller/PhabricatorApplicationTransactionCommentEditController.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ public function processRequest() {
1313
$request = $this->getRequest();
1414
$user = $request->getUser();
1515

16-
$xactions = id(new PhabricatorObjectHandleData(array($this->phid)))
16+
$xaction = id(new PhabricatorObjectQuery())
17+
->withPHIDs(array($this->phid))
1718
->setViewer($user)
18-
->loadObjects();
19-
$xaction = idx($xactions, $this->phid);
19+
->executeOne();
2020

2121
if (!$xaction) {
2222
// TODO: This may also mean you don't have permission to edit the object,
@@ -33,10 +33,6 @@ public function processRequest() {
3333

3434
$obj_phid = $xaction->getObjectPHID();
3535
$obj_handle = PhabricatorObjectHandleData::loadOneHandle($obj_phid, $user);
36-
if (!$obj_handle) {
37-
// Require the corresponding object exist and be visible to the user.
38-
return new Aphront404Response();
39-
}
4036

4137
if ($request->isDialogFormPost()) {
4238
$text = $request->getStr('text');

src/applications/transactions/controller/PhabricatorApplicationTransactionCommentHistoryController.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ public function processRequest() {
1313
$request = $this->getRequest();
1414
$user = $request->getUser();
1515

16-
$xactions = id(new PhabricatorObjectHandleData(array($this->phid)))
16+
$xaction = id(new PhabricatorObjectQuery())
17+
->withPHIDs(array($this->phid))
1718
->setViewer($user)
18-
->loadObjects();
19-
$xaction = idx($xactions, $this->phid);
19+
->executeOne();
2020

2121
if (!$xaction) {
2222
// TODO: This may also mean you don't have permission to edit the object,
@@ -30,13 +30,6 @@ public function processRequest() {
3030
return new Aphront404Response();
3131
}
3232

33-
$obj_phid = $xaction->getObjectPHID();
34-
$obj_handle = PhabricatorObjectHandleData::loadOneHandle($obj_phid, $user);
35-
if (!$obj_handle) {
36-
// Require the corresponding object exist and be visible to the user.
37-
return new Aphront404Response();
38-
}
39-
4033
$comments = id(new PhabricatorApplicationTransactionCommentQuery())
4134
->setViewer($user)
4235
->setTemplate($xaction->getApplicationTransactionCommentObject())
@@ -59,13 +52,15 @@ public function processRequest() {
5952
->attachComment($comment);
6053
}
6154

55+
$obj_phid = $xaction->getObjectPHID();
56+
$obj_handle = PhabricatorObjectHandleData::loadOneHandle($obj_phid, $user);
57+
6258
$view = id(new PhabricatorApplicationTransactionView())
6359
->setUser($user)
6460
->setObjectPHID($obj_phid)
6561
->setTransactions($xactions)
6662
->setShowEditActions(false);
6763

68-
6964
$dialog = id(new AphrontDialogView())
7065
->setUser($user)
7166
->setWidth(AphrontDialogView::WIDTH_FULL)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
final class PhabricatorApplicationTransactionDetailController
4+
extends PhabricatorApplicationTransactionController {
5+
6+
private $phid;
7+
8+
public function willProcessRequest(array $data) {
9+
$this->phid = $data['phid'];
10+
}
11+
12+
public function processRequest() {
13+
$request = $this->getRequest();
14+
$user = $request->getUser();
15+
16+
$xaction = id(new PhabricatorObjectQuery())
17+
->withPHIDs(array($this->phid))
18+
->setViewer($user)
19+
->executeOne();
20+
21+
if (!$xaction) {
22+
// future proofing for the day visibility of transactions can change
23+
return new Aphront404Response();
24+
}
25+
26+
return id(new PhabricatorApplicationTransactionResponse())
27+
->setViewer($user)
28+
->setTransactions(array($xaction))
29+
->setIsDetailView(true)
30+
->setAnchorOffset($request->getStr('anchor'));
31+
}
32+
33+
}

src/applications/transactions/response/PhabricatorApplicationTransactionResponse.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ final class PhabricatorApplicationTransactionResponse
77
private $transactions;
88
private $anchorOffset;
99
private $isPreview;
10+
private $isDetailView;
1011

1112
protected function buildProxy() {
1213
return new AphrontAjaxResponse();
@@ -46,6 +47,11 @@ public function setIsPreview($is_preview) {
4647
return $this;
4748
}
4849

50+
public function setIsDetailView($is_detail_view) {
51+
$this->isDetailView = $is_detail_view;
52+
return $this;
53+
}
54+
4955
public function reduceProxyResponse() {
5056
if ($this->getTransactions()) {
5157
$view = head($this->getTransactions())
@@ -57,7 +63,8 @@ public function reduceProxyResponse() {
5763
$view
5864
->setUser($this->getViewer())
5965
->setTransactions($this->getTransactions())
60-
->setIsPreview($this->isPreview);
66+
->setIsPreview($this->isPreview)
67+
->setIsDetailView($this->isDetailView);
6168

6269
if ($this->getAnchorOffset()) {
6370
$view->setAnchorOffset($this->getAnchorOffset());

src/applications/transactions/view/PhabricatorApplicationTransactionView.php

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ class PhabricatorApplicationTransactionView extends AphrontView {
1111
private $showEditActions = true;
1212
private $isPreview;
1313
private $objectPHID;
14+
private $isDetailView;
15+
16+
public function setIsDetailView($is_detail_view) {
17+
$this->isDetailView = $is_detail_view;
18+
return $this;
19+
}
1420

1521
public function setObjectPHID($object_phid) {
1622
$this->objectPHID = $object_phid;
@@ -89,10 +95,15 @@ public function buildEvents() {
8995

9096
$title = $xaction->getTitle();
9197
if ($xaction->hasChangeDetails()) {
98+
if ($this->isPreview || $this->isDetailView) {
99+
$details = $this->buildChangeDetails($xaction);
100+
} else {
101+
$details = $this->buildChangeDetailsLink($xaction);
102+
}
92103
$title = array(
93104
$title,
94105
' ',
95-
$this->buildChangeDetails($xaction),
106+
$details,
96107
);
97108
}
98109
$event->setTitle($title);
@@ -168,7 +179,6 @@ public function render() {
168179
return $view->render();
169180
}
170181

171-
172182
protected function getOrBuildEngine() {
173183
if ($this->engine) {
174184
return $this->engine;
@@ -205,6 +215,7 @@ private function buildChangeDetails(
205215
'sigil' => 'reveal-content',
206216
'mustcapture' => true,
207217
'id' => $show_id,
218+
'style' => 'display: none',
208219
'meta' => array(
209220
'hideIDs' => array($show_id),
210221
'showIDs' => array($hide_id, $content_id),
@@ -219,7 +230,6 @@ private function buildChangeDetails(
219230
'sigil' => 'reveal-content',
220231
'mustcapture' => true,
221232
'id' => $hide_id,
222-
'style' => 'display: none',
223233
'meta' => array(
224234
'hideIDs' => array($hide_id, $content_id),
225235
'showIDs' => array($show_id),
@@ -231,7 +241,6 @@ private function buildChangeDetails(
231241
'div',
232242
array(
233243
'id' => $content_id,
234-
'style' => 'display: none',
235244
'class' => 'phabricator-timeline-change-details',
236245
),
237246
$xaction->renderChangeDetails($this->getUser()));
@@ -243,6 +252,22 @@ private function buildChangeDetails(
243252
);
244253
}
245254

255+
private function buildChangeDetailsLink(
256+
PhabricatorApplicationTransaction $xaction) {
257+
258+
return javelin_tag(
259+
'a',
260+
array(
261+
'href' => '/transactions/detail/'.$xaction->getPHID().'/',
262+
'sigil' => 'transaction-detail',
263+
'mustcapture' => true,
264+
'meta' => array(
265+
'anchor' => $this->anchorOffset,
266+
),
267+
),
268+
pht('(Show Details)'));
269+
}
270+
246271
protected function shouldGroupTransactions(
247272
PhabricatorApplicationTransaction $u,
248273
PhabricatorApplicationTransaction $v) {

webroot/rsrc/js/application/transactions/behavior-transaction-list.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,19 @@ JX.behavior('phabricator-transaction-list', function(config) {
7575
e.kill();
7676
});
7777

78+
JX.DOM.listen(list, 'click', 'transaction-detail', function(e) {
79+
if (!e.isNormalClick()) {
80+
return;
81+
}
82+
83+
JX.Workflow.newFromLink(e.getTarget())
84+
.setData({anchor: e.getData('anchor')})
85+
.setHandler(ontransactions)
86+
.start();
87+
88+
e.kill();
89+
});
90+
7891
JX.Stratcom.listen(
7992
['submit', 'didSyntheticSubmit'],
8093
'transaction-append',

0 commit comments

Comments
 (0)