You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2012/12/19 17:25:53 UTC
[17/48] git commit: [#5389] ticket:229 add option to switch viewer to
side-by-side mode (dirty styles)
[#5389] ticket:229 add option to switch viewer to side-by-side mode (dirty styles)
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/a68e4214
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/a68e4214
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/a68e4214
Branch: refs/heads/db/4790
Commit: a68e4214baac8ebfe94631959443c3182c3663bf
Parents: 7f4fb63
Author: Igor Bondarenko <je...@gmail.com>
Authored: Wed Dec 5 13:11:35 2012 +0000
Committer: Cory Johns <jo...@geek.net>
Committed: Mon Dec 17 22:21:16 2012 +0000
----------------------------------------------------------------------
Allura/allura/controllers/repository.py | 35 ++++++++++++++--------
Allura/allura/templates/repo/barediff.html | 6 +++-
Allura/allura/templates/repo/commit.html | 20 +++++++++++++
Allura/allura/templates/repo/diff.html | 20 ++++++++++++-
4 files changed, 65 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/a68e4214/Allura/allura/controllers/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/repository.py b/Allura/allura/controllers/repository.py
index 7a61445..1d8a061 100644
--- a/Allura/allura/controllers/repository.py
+++ b/Allura/allura/controllers/repository.py
@@ -11,6 +11,7 @@ from webob import exc
import tg
from tg import redirect, expose, flash, url, validate
from tg.decorators import with_trailing_slash, without_trailing_slash
+from tg import session as web_session
from formencode import validators
from bson import ObjectId
from ming.base import Object
@@ -529,10 +530,10 @@ class FileBrowser(BaseController):
return self.raw()
elif 'diff' in kw:
tg.decorators.override_template(self.index, 'jinja:allura:templates/repo/diff.html')
- return self.diff(kw['diff'])
+ return self.diff(kw['diff'], kw.pop('diformat', None))
elif 'barediff' in kw:
tg.decorators.override_template(self.index, 'jinja:allura:templates/repo/barediff.html')
- return self.diff(kw['barediff'])
+ return self.diff(kw['barediff'], kw.pop('diformat', None))
else:
force_display = 'force' in kw
context = self._blob.context()
@@ -559,7 +560,7 @@ class FileBrowser(BaseController):
'Content-Disposition', 'attachment;filename=' + filename)
return iter(self._blob)
- def diff(self, commit):
+ def diff(self, commit, fmt=None):
try:
path, filename = os.path.split(self._blob.path())
a_ci = c.app.repo.commit(commit)
@@ -569,19 +570,27 @@ class FileBrowser(BaseController):
a = []
apath = ''
b = self._blob
+
+ if not self._blob.has_html_view:
+ diff = "Cannot display: file marked as a binary type."
+ return dict(a=a, b=b, diff=diff)
+
la = list(a)
lb = list(b)
+ adesc = (u'a' + h.really_unicode(apath)).encode('utf-8')
+ bdesc = (u'b' + h.really_unicode(b.path())).encode('utf-8')
- diff = "Cannot display: file marked as a binary type."
- if self._blob.has_html_view:
- diff = ''.join(difflib.unified_diff(
- la, lb,
- ('a' + apath).encode('utf-8'),
- ('b' + b.path()).encode('utf-8')))
-
- return dict(
- a=a, b=b,
- diff=diff)
+ if not fmt:
+ fmt = web_session.get('diformat', '')
+ else:
+ web_session['diformat'] = fmt
+ web_session.save()
+ if fmt == 'sidebyside':
+ hd = difflib.HtmlDiff(tabsize=4)
+ diff = hd.make_table(la, lb, adesc, bdesc, context=True)
+ else:
+ diff = ''.join(difflib.unified_diff(la, lb, adesc, bdesc))
+ return dict(a=a, b=b, diff=diff)
def topo_sort(children, parents, dates, head_ids):
to_visit = sorted(list(set(head_ids)), key=lambda x: dates[x])
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/a68e4214/Allura/allura/templates/repo/barediff.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/repo/barediff.html b/Allura/allura/templates/repo/barediff.html
index 6279364..4dfce67 100644
--- a/Allura/allura/templates/repo/barediff.html
+++ b/Allura/allura/templates/repo/barediff.html
@@ -6,5 +6,9 @@
alt="{{h.text.truncate(b._commit._id, 10)}}"
title="{{h.text.truncate(b._commit._id, 10)}}"/>
{% else %}
- {{g.highlight(diff, lexer='diff')}}
+ {% if session.diformat == 'sidebyside' %}
+ {{diff|safe}}
+ {% else %}
+ {{g.highlight(diff, lexer='diff')}}
+ {% endif%}
{% endif %}
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/a68e4214/Allura/allura/templates/repo/commit.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/repo/commit.html b/Allura/allura/templates/repo/commit.html
index fd3c247..6057f5a 100644
--- a/Allura/allura/templates/repo/commit.html
+++ b/Allura/allura/templates/repo/commit.html
@@ -56,6 +56,25 @@ Commit <a href="{{commit.url()}}">{{commit.shorthand_id()}}</a> {{commit_labels(
}
$(document).ready(function() {
document.diff_queue_timer = setInterval(load_diff, WAIT_FOR);
+
+ $('.switch-diff-format-link').click(function() {
+ var diformat = $(this).attr('data-diformat');
+ var href = $(this).attr('href');
+ var diffid = $(this).attr('data-diffid');
+ self = $(this);
+ if (diformat == 'sidebyside') {
+ href = href + '&diformat=regular';
+ $('#' + diffid).load(href, function() {
+ self.attr('data-diformat', 'regular');
+ });
+ } else {
+ href = href + '&diformat=sidebyside';
+ $('#' + diffid).load(href, function() {
+ self.attr('data-diformat', 'sidebyside');
+ });
+ }
+ return false;
+ });
});
</script>
{% endblock %}
@@ -86,6 +105,7 @@ Commit <a href="{{commit.url()}}">{{commit.shorthand_id()}}</a> {{commit_labels(
{% if type in ('added', 'changed') %}
<a href="{{commit.url()}}tree/{{h.really_unicode(file)}}">{{h.really_unicode(file)}}</a>
<a class="commit-diff-link" href="{{commit.url()}}tree/{{h.really_unicode(file)}}?diff={{prev[0]._id if prev else ''}}">Diff</a>
+ <a class="commit-diff-link switch-diff-format-link" data-diformat={{session.diformat}} data-diffid="diff-{{loop.index}}" href="{{commit.url()}}tree/{{h.really_unicode(file)}}?barediff={{prev[0]._id if prev else ''}}">Switch regular/side-by-side view</a>
{% elif type == 'removed' %}
<a href="{{prev[0].url()}}tree/{{h.really_unicode(file)}}">{{h.really_unicode(file)}}</a>
{% elif type == 'copied' %}
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/a68e4214/Allura/allura/templates/repo/diff.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/repo/diff.html b/Allura/allura/templates/repo/diff.html
index fbdfad2..5156bd8 100644
--- a/Allura/allura/templates/repo/diff.html
+++ b/Allura/allura/templates/repo/diff.html
@@ -28,8 +28,24 @@
</div>
{% else %}
<div class="clip grid-19">
- <h3><span class="ico-l"><b data-icon="{{g.icons['table'].char}}" class="ico {{g.icons['table'].css}}"></b> {{h.really_unicode(a.filename) or h.html.literal(' ')}}</span></h3>
- {{g.highlight(diff, lexer='diff')}}
+ <h3>
+ <span class="ico-l"><b data-icon="{{g.icons['table'].char}}" class="ico {{g.icons['table'].css}}"></b> {{h.really_unicode(a.filename) or h.html.literal(' ')}}</span>
+ <span class="fright">
+ {% if session.diformat == 'sidebyside' %}
+ {% set switch_url = request.url.replace('&diformat=sidebyside', '') + '&diformat=regular' %}
+ {% set switch_text = 'regular' %}
+ {% else %}
+ {% set switch_url = request.url.replace('&diformat=regular', '') + '&diformat=sidebyside' %}
+ {% set switch_text = 'side-by-side' %}
+ {% endif %}
+ <a href="{{ switch_url }}">Switch to {{ switch_text }} view</a>
+ <span>
+ </h3>
+ {% if session.diformat == 'sidebyside' %}
+ {{diff|safe}}
+ {% else %}
+ {{g.highlight(diff, lexer='diff')}}
+ {% endif %}
</div>
{% endif %}
{% endblock %}