Re-implement revision comparison
This commit is contained in:
parent
497f743976
commit
184a47185c
|
@ -28,7 +28,7 @@ def compare(name, fsha, dots, lsha):
|
||||||
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
|
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
|
||||||
return current_app.login_manager.unauthorized()
|
return current_app.login_manager.unauthorized()
|
||||||
|
|
||||||
diff = g.current_wiki.get_page(name, sha=lsha).compare(fsha)
|
diff = g.current_wiki.get_page(name, sha=fsha).compare(lsha)
|
||||||
return render_template('wiki/compare.html',
|
return render_template('wiki/compare.html',
|
||||||
name=name, diff=diff, old=fsha, new=lsha)
|
name=name, diff=diff, old=fsha, new=lsha)
|
||||||
|
|
||||||
|
@ -79,6 +79,7 @@ def history_data(name):
|
||||||
items = list(itertools.islice(page.history, start, start + length))
|
items = list(itertools.islice(page.history, start, start + length))
|
||||||
for item in items:
|
for item in items:
|
||||||
item['gravatar'] = gravatar_url(item['author_email'])
|
item['gravatar'] = gravatar_url(item['author_email'])
|
||||||
|
item['DT_RowId'] = item['sha']
|
||||||
total_records, hist_complete = page.history_cache
|
total_records, hist_complete = page.history_cache
|
||||||
if not hist_complete:
|
if not hist_complete:
|
||||||
# Force datatables to fetch more data when it gets to the end
|
# Force datatables to fetch more data when it gets to the end
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
<a class="btn btn-default btn-sm compare-revisions">Compare Revisions</a>
|
<a class="btn btn-default btn-sm compare-revisions">Compare Revisions</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<table class="table table-bordered revision-tbl data-table">
|
<table class="table table-bordered revision-tbl dataTable DTTT_selectable">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
|
@ -21,10 +21,29 @@
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block css %}
|
||||||
|
<style type="text/css">
|
||||||
|
table.dataTable td {
|
||||||
|
transition: background-color 0.5s linear, color 0.5s linear;
|
||||||
|
transition-delay: 0.1s;
|
||||||
|
}
|
||||||
|
table.dataTable tr.active td {
|
||||||
|
transition: background-color 0.1s linear, color 0.1s linear;
|
||||||
|
transition-delay: 0s
|
||||||
|
}
|
||||||
|
table.dataTable tbody tr:hover {
|
||||||
|
background-color: #d8d8d8 !important;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
{% block js %}
|
{% block js %}
|
||||||
<script>
|
<script>
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
$('.data-table').dataTable({
|
var selected = [];
|
||||||
|
var selected_pos = [];
|
||||||
|
|
||||||
|
$('.dataTable').dataTable({
|
||||||
serverSide: true,
|
serverSide: true,
|
||||||
ajax: '{{ url_for('.history_data', name=name) }}',
|
ajax: '{{ url_for('.history_data', name=name) }}',
|
||||||
ordering: false,
|
ordering: false,
|
||||||
|
@ -38,26 +57,42 @@
|
||||||
return date.toDateString();
|
return date.toDateString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
});
|
rowCallback: function( row, data, index ) {
|
||||||
});
|
index += $('.dataTable').DataTable().page.info().start;
|
||||||
$(function(){
|
$(row).data('index', index);
|
||||||
$('.revision-tbl :checkbox').change(function () {
|
if ( $.inArray(data.DT_RowId, selected) !== -1 ) {
|
||||||
var $cs=$(this).closest('.revision-tbl').find(':checkbox:checked');
|
$(row).addClass('active');
|
||||||
if ($cs.length > 2) {
|
}
|
||||||
this.checked=false;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('.dataTable tbody').on('click', 'tr', function () {
|
||||||
|
var id = this.id;
|
||||||
|
var selected_index = $.inArray(id, selected);
|
||||||
|
|
||||||
|
if ( selected_index === -1 ) {
|
||||||
|
selected.push( id );
|
||||||
|
selected_pos.push( $(this).data('index') );
|
||||||
|
if ( selected.length > 2) {
|
||||||
|
// Only 2 selected at once
|
||||||
|
var shifted = selected.shift();
|
||||||
|
selected_pos.shift();
|
||||||
|
$('#' + shifted).removeClass('active');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
selected.splice( selected_index, 1 );
|
||||||
|
selected_pos.splice( selected_index, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$(this).toggleClass('active');
|
||||||
|
});
|
||||||
$(".compare-revisions").click(function(){
|
$(".compare-revisions").click(function(){
|
||||||
var $cs = $('.revision-tbl').find(':checkbox:checked');
|
if (selected.length != 2) return;
|
||||||
if ($cs.length != 2) return;
|
if (selected_pos[1] > selected_pos[0]) {
|
||||||
var revs = [];
|
selected.reverse()
|
||||||
$.each($cs, function(i, v){
|
}
|
||||||
revs.push(v.value);
|
revs = selected.join("..");
|
||||||
});
|
|
||||||
revs.reverse();
|
|
||||||
revs = revs.join("..");
|
|
||||||
location.href = "{{ config.RELATIVE_PATH }}/_compare/{{ name }}/" + revs;
|
location.href = "{{ config.RELATIVE_PATH }}/_compare/{{ name }}/" + revs;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue