1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-25 16:22:43 +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' =>
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',

View file

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

View file

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

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

View file

@ -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',
),
'<td class="differential-shield" colspan="4">'.
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',

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/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');

View file

@ -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/',
));
/*

View file

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

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