From 233953bc4ab2371317f329c4d5cf4aa4c611ecdd Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 31 Jan 2011 20:38:13 -0800 Subject: [PATCH] Straighten out the "show more context" stuff. --- src/__celerity_resource_map__.php | 12 +++++- ...AphrontDefaultApplicationConfiguration.php | 2 +- .../DifferentialChangesetViewController.php | 38 +++++++++++++---- .../controller/changesetview/__init__.php | 1 + .../changeset/DifferentialChangesetParser.php | 37 ++++++++++------ .../parser/changeset/__init__.php | 1 + .../DifferentialChangesetListView.php | 8 ++-- .../differential/behavior-populate.js | 5 +-- .../differential/behavior-show-more.js | 42 +++++++++++++++++++ 9 files changed, 118 insertions(+), 28 deletions(-) create mode 100644 webroot/rsrc/js/application/differential/behavior-show-more.js diff --git a/src/__celerity_resource_map__.php b/src/__celerity_resource_map__.php index 44c6321e90..7d01e98ab8 100644 --- a/src/__celerity_resource_map__.php +++ b/src/__celerity_resource_map__.php @@ -228,7 +228,7 @@ celerity_register_resource_map(array( ), 'javelin-behavior-differential-populate' => array( - 'uri' => '/res/9982573c/rsrc/js/application/differential/behavior-populate.js', + 'uri' => '/res/f7efbf62/rsrc/js/application/differential/behavior-populate.js', 'type' => 'js', 'requires' => array( @@ -236,6 +236,16 @@ celerity_register_resource_map(array( ), 'disk' => '/rsrc/js/application/differential/behavior-populate.js', ), + 'javelin-behavior-differential-show-more' => + array( + 'uri' => '/res/d26ebcae/rsrc/js/application/differential/behavior-show-more.js', + 'type' => 'js', + 'requires' => + array( + 0 => 'javelin-lib-dev', + ), + 'disk' => '/rsrc/js/application/differential/behavior-show-more.js', + ), 'javelin-init-dev' => array( 'uri' => '/res/c57a9e89/rsrc/js/javelin/init.dev.js', diff --git a/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php b/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php index 046b99f300..85367d98f0 100644 --- a/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php +++ b/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php @@ -83,7 +83,7 @@ class AphrontDefaultApplicationConfiguration '$' => 'DifferentialRevisionListController', 'filter/(?\w+)/$' => 'DifferentialRevisionListController', 'diff/(?\d+)/$' => 'DifferentialDiffViewController', - 'changeset/(?\d+)/$' => 'DifferentialChangesetViewController', + 'changeset/$' => 'DifferentialChangesetViewController', 'revision/edit/(?:(?\d+)/)?$' => 'DifferentialRevisionEditController', 'comment/' => array( diff --git a/src/applications/differential/controller/changesetview/DifferentialChangesetViewController.php b/src/applications/differential/controller/changesetview/DifferentialChangesetViewController.php index 1afedc16cb..f8d7cab6c2 100644 --- a/src/applications/differential/controller/changesetview/DifferentialChangesetViewController.php +++ b/src/applications/differential/controller/changesetview/DifferentialChangesetViewController.php @@ -18,31 +18,53 @@ class DifferentialChangesetViewController extends DifferentialController { - private $id; - - public function willProcessRequest(array $data) { - $this->id = $data['id']; - } public function processRequest() { - $changeset = id(new DifferentialChangeset())->load($this->id); + $request = $this->getRequest(); + + $id = $request->getStr('id'); + + $changeset = id(new DifferentialChangeset())->load($id); if (!$changeset) { return new Aphront404Response(); } $changeset->attachHunks($changeset->loadHunks()); + $range_s = null; + $range_e = null; + $mask = array(); + + $range = $request->getStr('range'); + if ($range) { + $match = null; + if (preg_match('@^(\d+)-(\d+)(?:/(\d+)-(\d+))?$@', $range, $match)) { + $range_s = (int)$match[1]; + $range_e = (int)$match[2]; + if (count($match) > 3) { + $start = (int)$match[3]; + $len = (int)$match[4]; + for ($ii = $start; $ii < $start + $len; $ii++) { + $mask[$ii] = true; + } + } + } + } + $parser = new DifferentialChangesetParser(); $parser->setChangeset($changeset); - $output = $parser->render(); + $output = $parser->render(null, $range_s, $range_e, $mask); - $request = $this->getRequest(); if ($request->isAjax()) { return id(new AphrontAjaxResponse()) ->setContent($output); } + Javelin::initBehavior('differential-show-more', array( + 'uri' => '/differential/changeset/', + )); + $detail = new DifferentialChangesetDetailView(); $detail->setChangeset($changeset); $detail->appendChild($output); diff --git a/src/applications/differential/controller/changesetview/__init__.php b/src/applications/differential/controller/changesetview/__init__.php index f872d3acbd..6be43a56c1 100644 --- a/src/applications/differential/controller/changesetview/__init__.php +++ b/src/applications/differential/controller/changesetview/__init__.php @@ -12,6 +12,7 @@ phutil_require_module('phabricator', 'applications/differential/controller/base' phutil_require_module('phabricator', 'applications/differential/parser/changeset'); phutil_require_module('phabricator', 'applications/differential/storage/changeset'); phutil_require_module('phabricator', 'applications/differential/view/changesetdetailview'); +phutil_require_module('phabricator', 'infrastructure/javelin/api'); phutil_require_module('phutil', 'utils'); diff --git a/src/applications/differential/parser/changeset/DifferentialChangesetParser.php b/src/applications/differential/parser/changeset/DifferentialChangesetParser.php index 9cf45434c0..ba34fd0ffd 100644 --- a/src/applications/differential/parser/changeset/DifferentialChangesetParser.php +++ b/src/applications/differential/parser/changeset/DifferentialChangesetParser.php @@ -845,23 +845,27 @@ EOSYNTHETIC; if ($more) { $more = ' '. - phutil_render_tag( + javelin_render_tag( 'a', array( 'mustcapture' => true, 'sigil' => 'show-more', 'class' => 'complete', - 'meta' => 'TODO', + 'href' => '#', + 'meta' => array( + 'id' => $changeset_id, + 'range' => "0-{$end}", + ), ), 'Show File Contents'); } else { $more = null; } - return phutil_render_tag( + return javelin_render_tag( 'tr', array( - 'sigil' => 'contex-target', + 'sigil' => 'context-target', ), ''. phutil_escape_html($message). @@ -881,7 +885,7 @@ EOSYNTHETIC; $context_not_available = null; if ($this->missingOld || $this->missingNew) { - $context_not_available = phutil_render_tag( + $context_not_available = javelin_render_tag( 'tr', array( 'sigil' => 'context-target', @@ -949,40 +953,49 @@ EOSYNTHETIC; $contents = array(); if ($len > 40) { - $contents[] = phutil_render_tag( + $contents[] = javelin_render_tag( 'a', array( 'href' => '#', 'mustcapture' => true, 'sigil' => 'show-more', - 'meta' => '', // TODO + 'meta' => array( + 'id' => $changeset, + 'range' => "{$top}-{$len}/{$top}-20", + ), ), "\xE2\x96\xB2 Show 20 Lines"); } - $contents[] = phutil_render_tag( + $contents[] = javelin_render_tag( 'a', array( 'href' => '#', 'mustcapture' => true, 'sigil' => 'show-more', - 'meta' => '', // TODO + 'meta' => array( + 'id' => $changeset, + 'range' => "{$top}-{$len}/{$top}-{$len}", + ), ), 'Show All '.$len.' Lines'); if ($len > 40) { - $contents[] = phutil_render_tag( + $contents[] = javelin_render_tag( 'a', array( 'href' => '#', 'mustcapture' => true, 'sigil' => 'show-more', - 'meta' => '', // TODO + 'meta' => array( + 'id' => $changeset, + 'range' => "{$top}-{$len}/{$end}-20", + ), ), "\xE2\x96\xBC Show 20 Lines"); }; - $container = phutil_render_tag( + $container = javelin_render_tag( 'tr', array( 'sigil' => 'context-target', diff --git a/src/applications/differential/parser/changeset/__init__.php b/src/applications/differential/parser/changeset/__init__.php index 5c540dfa42..8b8e1ff60f 100644 --- a/src/applications/differential/parser/changeset/__init__.php +++ b/src/applications/differential/parser/changeset/__init__.php @@ -13,6 +13,7 @@ phutil_require_module('phabricator', 'applications/differential/constants/change phutil_require_module('phabricator', 'applications/differential/storage/changeset'); phutil_require_module('phabricator', 'applications/differential/storage/diff'); phutil_require_module('phabricator', 'applications/files/uri'); +phutil_require_module('phabricator', 'infrastructure/javelin/markup'); phutil_require_module('phabricator', 'storage/queryfx'); phutil_require_module('phutil', 'filesystem'); diff --git a/src/applications/differential/view/changesetlistview/DifferentialChangesetListView.php b/src/applications/differential/view/changesetlistview/DifferentialChangesetListView.php index 476813604a..b2c2387068 100644 --- a/src/applications/differential/view/changesetlistview/DifferentialChangesetListView.php +++ b/src/applications/differential/view/changesetlistview/DifferentialChangesetListView.php @@ -66,7 +66,7 @@ class DifferentialChangesetListView extends AphrontView { 'whitespace' => $whitespace, )); */ - $detail_uri = '/differential/changeset/'.$changeset->getID().'/'; + $detail_uri = '/differential/changeset/?id='.$changeset->getID(); $detail_button = phutil_render_tag( 'a', @@ -99,10 +99,12 @@ class DifferentialChangesetListView extends AphrontView { Javelin::initBehavior('differential-populate', array( 'registry' => $mapping, 'whitespace' => $whitespace, - 'uri' => '/differential/changeset/',//$render_uri, + 'uri' => '/differential/changeset/', )); - + Javelin::initBehavior('differential-show-more', array( + 'uri' => '/differential/changeset/', + )); /* diff --git a/webroot/rsrc/js/application/differential/behavior-populate.js b/webroot/rsrc/js/application/differential/behavior-populate.js index 4c39fd17ae..6409521253 100644 --- a/webroot/rsrc/js/application/differential/behavior-populate.js +++ b/webroot/rsrc/js/application/differential/behavior-populate.js @@ -9,11 +9,10 @@ JX.behavior('differential-populate', function(config) { JX.DOM.replace(JX.$(target), JX.HTML(response)); } - var uri; for (var k in config.registry) { - uri = config.uri + config.registry[k][0] + '/'; - new JX.Request(uri, JX.bind(null, onresponse, k)) + new JX.Request(config.uri, JX.bind(null, onresponse, k)) .setData({ + id: config.registry[k][0], against: config.registry[k][1], whitespace: config.whitespace }) diff --git a/webroot/rsrc/js/application/differential/behavior-show-more.js b/webroot/rsrc/js/application/differential/behavior-show-more.js new file mode 100644 index 0000000000..25748ba6af --- /dev/null +++ b/webroot/rsrc/js/application/differential/behavior-show-more.js @@ -0,0 +1,42 @@ +/** + * @provides javelin-behavior-differential-show-more + * @requires javelin-lib-dev + */ + +JX.behavior('differential-show-more', function(config) { + + function onresponse(origin, response) { + var div = JX.$N('div', {}, JX.HTML(response)); + var anchor = origin.getNode('context-target'); + var root = anchor.parentNode; + copyRows(root, div, anchor); + root.removeChild(anchor); + } + + JX.Stratcom.listen( + 'click', + 'show-more', + function(e) { + var context = e.getNodes()['context-target']; + var container = JX.DOM.find(context, 'td'); + JX.DOM.setContent(container, 'Loading...'); + JX.DOM.alterClass(context, 'differential-show-more-loading', true); + var data = e.getData()['show-more']; + new JX.Request(config.uri, JX.bind(null, onresponse, e)) + .setData(data) + .send(); + e.kill(); + }); + +}); + +function copyRows(dst, src, before) { + var rows = JX.DOM.scry(src, 'tr'); + for (var ii = 0; ii < rows.length; ii++) { + if (before) { + dst.insertBefore(rows[ii], before); + } else { + dst.appendChild(rows[ii]); + } + } +}