1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-29 10:12:41 +01:00

Straighten out the "show more context" stuff.

This commit is contained in:
epriestley 2011-01-31 20:38:13 -08:00
parent 6a94f054d2
commit 233953bc4a
9 changed files with 118 additions and 28 deletions

View file

@ -228,7 +228,7 @@ celerity_register_resource_map(array(
), ),
'javelin-behavior-differential-populate' => 'javelin-behavior-differential-populate' =>
array( array(
'uri' => '/res/9982573c/rsrc/js/application/differential/behavior-populate.js', 'uri' => '/res/f7efbf62/rsrc/js/application/differential/behavior-populate.js',
'type' => 'js', 'type' => 'js',
'requires' => 'requires' =>
array( array(
@ -236,6 +236,16 @@ celerity_register_resource_map(array(
), ),
'disk' => '/rsrc/js/application/differential/behavior-populate.js', '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' => 'javelin-init-dev' =>
array( array(
'uri' => '/res/c57a9e89/rsrc/js/javelin/init.dev.js', 'uri' => '/res/c57a9e89/rsrc/js/javelin/init.dev.js',

View file

@ -83,7 +83,7 @@ class AphrontDefaultApplicationConfiguration
'$' => 'DifferentialRevisionListController', '$' => 'DifferentialRevisionListController',
'filter/(?<filter>\w+)/$' => 'DifferentialRevisionListController', 'filter/(?<filter>\w+)/$' => 'DifferentialRevisionListController',
'diff/(?<id>\d+)/$' => 'DifferentialDiffViewController', 'diff/(?<id>\d+)/$' => 'DifferentialDiffViewController',
'changeset/(?<id>\d+)/$' => 'DifferentialChangesetViewController', 'changeset/$' => 'DifferentialChangesetViewController',
'revision/edit/(?:(?<id>\d+)/)?$' 'revision/edit/(?:(?<id>\d+)/)?$'
=> 'DifferentialRevisionEditController', => 'DifferentialRevisionEditController',
'comment/' => array( 'comment/' => array(

View file

@ -18,31 +18,53 @@
class DifferentialChangesetViewController extends DifferentialController { class DifferentialChangesetViewController extends DifferentialController {
private $id;
public function willProcessRequest(array $data) {
$this->id = $data['id'];
}
public function processRequest() { 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) { if (!$changeset) {
return new Aphront404Response(); return new Aphront404Response();
} }
$changeset->attachHunks($changeset->loadHunks()); $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 = new DifferentialChangesetParser();
$parser->setChangeset($changeset); $parser->setChangeset($changeset);
$output = $parser->render(); $output = $parser->render(null, $range_s, $range_e, $mask);
$request = $this->getRequest();
if ($request->isAjax()) { if ($request->isAjax()) {
return id(new AphrontAjaxResponse()) return id(new AphrontAjaxResponse())
->setContent($output); ->setContent($output);
} }
Javelin::initBehavior('differential-show-more', array(
'uri' => '/differential/changeset/',
));
$detail = new DifferentialChangesetDetailView(); $detail = new DifferentialChangesetDetailView();
$detail->setChangeset($changeset); $detail->setChangeset($changeset);
$detail->appendChild($output); $detail->appendChild($output);

View file

@ -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/parser/changeset');
phutil_require_module('phabricator', 'applications/differential/storage/changeset'); phutil_require_module('phabricator', 'applications/differential/storage/changeset');
phutil_require_module('phabricator', 'applications/differential/view/changesetdetailview'); phutil_require_module('phabricator', 'applications/differential/view/changesetdetailview');
phutil_require_module('phabricator', 'infrastructure/javelin/api');
phutil_require_module('phutil', 'utils'); phutil_require_module('phutil', 'utils');

View file

@ -845,23 +845,27 @@ EOSYNTHETIC;
if ($more) { if ($more) {
$more = $more =
' '. ' '.
phutil_render_tag( javelin_render_tag(
'a', 'a',
array( array(
'mustcapture' => true, 'mustcapture' => true,
'sigil' => 'show-more', 'sigil' => 'show-more',
'class' => 'complete', 'class' => 'complete',
'meta' => 'TODO', 'href' => '#',
'meta' => array(
'id' => $changeset_id,
'range' => "0-{$end}",
),
), ),
'Show File Contents'); 'Show File Contents');
} else { } else {
$more = null; $more = null;
} }
return phutil_render_tag( return javelin_render_tag(
'tr', 'tr',
array( array(
'sigil' => 'contex-target', 'sigil' => 'context-target',
), ),
'<td class="differential-shield" colspan="4">'. '<td class="differential-shield" colspan="4">'.
phutil_escape_html($message). phutil_escape_html($message).
@ -881,7 +885,7 @@ EOSYNTHETIC;
$context_not_available = null; $context_not_available = null;
if ($this->missingOld || $this->missingNew) { if ($this->missingOld || $this->missingNew) {
$context_not_available = phutil_render_tag( $context_not_available = javelin_render_tag(
'tr', 'tr',
array( array(
'sigil' => 'context-target', 'sigil' => 'context-target',
@ -949,40 +953,49 @@ EOSYNTHETIC;
$contents = array(); $contents = array();
if ($len > 40) { if ($len > 40) {
$contents[] = phutil_render_tag( $contents[] = javelin_render_tag(
'a', 'a',
array( array(
'href' => '#', 'href' => '#',
'mustcapture' => true, 'mustcapture' => true,
'sigil' => 'show-more', 'sigil' => 'show-more',
'meta' => '', // TODO 'meta' => array(
'id' => $changeset,
'range' => "{$top}-{$len}/{$top}-20",
),
), ),
"\xE2\x96\xB2 Show 20 Lines"); "\xE2\x96\xB2 Show 20 Lines");
} }
$contents[] = phutil_render_tag( $contents[] = javelin_render_tag(
'a', 'a',
array( array(
'href' => '#', 'href' => '#',
'mustcapture' => true, 'mustcapture' => true,
'sigil' => 'show-more', 'sigil' => 'show-more',
'meta' => '', // TODO 'meta' => array(
'id' => $changeset,
'range' => "{$top}-{$len}/{$top}-{$len}",
),
), ),
'Show All '.$len.' Lines'); 'Show All '.$len.' Lines');
if ($len > 40) { if ($len > 40) {
$contents[] = phutil_render_tag( $contents[] = javelin_render_tag(
'a', 'a',
array( array(
'href' => '#', 'href' => '#',
'mustcapture' => true, 'mustcapture' => true,
'sigil' => 'show-more', 'sigil' => 'show-more',
'meta' => '', // TODO 'meta' => array(
'id' => $changeset,
'range' => "{$top}-{$len}/{$end}-20",
),
), ),
"\xE2\x96\xBC Show 20 Lines"); "\xE2\x96\xBC Show 20 Lines");
}; };
$container = phutil_render_tag( $container = javelin_render_tag(
'tr', 'tr',
array( array(
'sigil' => 'context-target', 'sigil' => 'context-target',

View file

@ -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/changeset');
phutil_require_module('phabricator', 'applications/differential/storage/diff'); phutil_require_module('phabricator', 'applications/differential/storage/diff');
phutil_require_module('phabricator', 'applications/files/uri'); phutil_require_module('phabricator', 'applications/files/uri');
phutil_require_module('phabricator', 'infrastructure/javelin/markup');
phutil_require_module('phabricator', 'storage/queryfx'); phutil_require_module('phabricator', 'storage/queryfx');
phutil_require_module('phutil', 'filesystem'); phutil_require_module('phutil', 'filesystem');

View file

@ -66,7 +66,7 @@ class DifferentialChangesetListView extends AphrontView {
'whitespace' => $whitespace, 'whitespace' => $whitespace,
)); ));
*/ */
$detail_uri = '/differential/changeset/'.$changeset->getID().'/'; $detail_uri = '/differential/changeset/?id='.$changeset->getID();
$detail_button = phutil_render_tag( $detail_button = phutil_render_tag(
'a', 'a',
@ -99,10 +99,12 @@ class DifferentialChangesetListView extends AphrontView {
Javelin::initBehavior('differential-populate', array( Javelin::initBehavior('differential-populate', array(
'registry' => $mapping, 'registry' => $mapping,
'whitespace' => $whitespace, 'whitespace' => $whitespace,
'uri' => '/differential/changeset/',//$render_uri, 'uri' => '/differential/changeset/',
)); ));
Javelin::initBehavior('differential-show-more', array(
'uri' => '/differential/changeset/',
));
/* /*

View file

@ -9,11 +9,10 @@ JX.behavior('differential-populate', function(config) {
JX.DOM.replace(JX.$(target), JX.HTML(response)); JX.DOM.replace(JX.$(target), JX.HTML(response));
} }
var uri;
for (var k in config.registry) { for (var k in config.registry) {
uri = config.uri + config.registry[k][0] + '/'; new JX.Request(config.uri, JX.bind(null, onresponse, k))
new JX.Request(uri, JX.bind(null, onresponse, k))
.setData({ .setData({
id: config.registry[k][0],
against: config.registry[k][1], against: config.registry[k][1],
whitespace: config.whitespace whitespace: config.whitespace
}) })

View file

@ -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]);
}
}
}