Skip to content

Commit 43a95a3

Browse files
committed
Add previous and next revision nav links to Changes view
Closes tobami#174
1 parent 33b2a3d commit 43a95a3

4 files changed

Lines changed: 89 additions & 3 deletions

File tree

codespeed/static/css/main.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,18 @@ div#configbar span.options {
165165
padding-right: 1.8em; font-size: 90%; white-space: nowrap; }
166166
div#configbar input { margin-right: 0; vertical-align: middle; }
167167

168+
div#contentnav a {
169+
font-size: small;
170+
padding-bottom: 0.25em;
171+
}
172+
div#contentnav a:hover { text-decoration: underline; }
173+
div#contentnav #previous {
174+
float: left;
175+
}
176+
div#contentnav #next {
177+
float: right;
178+
}
179+
168180
div#content, div.about_content {
169181
margin-left: 14.5em;
170182
text-align: center;

codespeed/static/js/changes.js

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ var TIMELINE_URL = window.TIMELINE_URL, getLoadText = window.getLoadText;
55

66
var currentproject, changethres, trendthres, projectmatrix, revisionboxes = {};
77

8-
function getConfiguration() {
8+
function getConfiguration(revision) {
99
return {
1010
tre: $("#trend option:selected").val(),
11-
rev: $("#revision option:selected").val(),
11+
rev: revision || $("#revision option:selected").val(),
1212
exe: $("input[name='executable']:checked").val(),
1313
env: $("input[name='environment']:checked").val()
1414
};
@@ -66,14 +66,40 @@ function updateTable() {
6666

6767
//Configure table as tablesorter
6868
$(".tablesorter").tablesorter({widgets: ['zebra']});
69+
70+
// Set prev and next links
71+
$("#previous").click(function() {
72+
refreshContentRev(
73+
$("#previous").data("revision"),
74+
$("#previous").data("desc")
75+
);
76+
});
77+
$("#next").click(function() {
78+
refreshContentRev(
79+
$("#next").data("revision"),
80+
$("#next").data("desc")
81+
);
82+
});
6983
}
7084

7185
function refreshContent() {
86+
refreshContentTable($("#revision option:selected").val());
87+
}
88+
89+
function refreshContentRev(revision, desc) {
90+
if ($('#revision option[value='+revision+']').length == 0) {
91+
$("#revision").append($("<option value='" + revision + "'>" + desc + "</option>"));
92+
}
93+
$("#revision").val(revision);
94+
refreshContentTable(revision);
95+
}
96+
97+
function refreshContentTable(revision) {
7298
var h = $("#content").height();//get height for loading text
7399
$("#contentwrap").fadeOut("fast", function() {
74100
$(this).show();
75101
$(this).html(getLoadText("Loading...", h));
76-
$(this).load("table/", $.param(getConfiguration()), function() { updateTable(); });
102+
$(this).load("table/", $.param(getConfiguration(revision)), function() { updateTable(); });
77103
});
78104
}
79105

codespeed/templates/codespeed/changes_table.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
{% load percentages %}
22

3+
<div id="contentnav">
4+
{% if prev %}<a id="previous" href="#" data-revision="{{ prev.rev }}" data-desc="{{ prev.desc }}">← {{ prev.short_rev }}{% if prev.summary %} ({{ prev.summary }}){% endif %}</a>{% endif %}
5+
{% if next %}<a id="next" href="#" data-revision="{{ next.rev }}" data-desc="{{ next.desc }}">{{ next.short_rev }}{% if next.summary %} ({{ next.summary }}){% endif %} →</a>{% endif %}
6+
</div>
7+
38
{% for units in tablelist %}
49
<table class="tablesorter" data-lessisbetter="{{ units.lessisbetter }}">
510
<thead>

codespeed/views.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,47 @@ def getchangestable(request):
497497
raise Http404()
498498
selectedrev = get_object_or_404(Revision, commitid=request.GET.get('rev'),
499499
branch__project=executable.project)
500+
prevrev = Revision.objects.filter(
501+
branch=selectedrev.branch,
502+
date__lt=selectedrev.date,
503+
).order_by('-date').first()
504+
if prevrev:
505+
try:
506+
summary = Report.objects.get(
507+
revision=prevrev,
508+
executable=executable,
509+
environment=environment).item_description
510+
except Report.DoesNotExist:
511+
summary = ''
512+
prevrev = {
513+
'desc': str(prevrev),
514+
'rev': prevrev.commitid,
515+
'short_rev': prevrev.get_short_commitid(),
516+
'summary': summary,
517+
}
518+
else:
519+
prevrev = None
520+
521+
nextrev = Revision.objects.filter(
522+
branch=selectedrev.branch,
523+
date__gt=selectedrev.date,
524+
).order_by('date').first()
525+
if nextrev:
526+
try:
527+
summary = Report.objects.get(
528+
revision=nextrev,
529+
executable=executable,
530+
environment=environment).item_description
531+
except Report.DoesNotExist:
532+
summary = ''
533+
nextrev = {
534+
'desc': str(nextrev),
535+
'rev': nextrev.commitid,
536+
'short_rev': nextrev.get_short_commitid(),
537+
'summary': summary,
538+
}
539+
else:
540+
nextrev = None
500541

501542
report, created = Report.objects.get_or_create(
502543
executable=executable, environment=environment, revision=selectedrev
@@ -515,6 +556,8 @@ def getchangestable(request):
515556
'rev': selectedrev,
516557
'exe': executable,
517558
'env': environment,
559+
'prev': prevrev,
560+
'next': nextrev,
518561
}, context_instance=RequestContext(request))
519562

520563

0 commit comments

Comments
 (0)