Skip to content

Commit 90680b9

Browse files
authored
Merge pull request tobami#226 from str4d/174-changes-navigation
Add previous and next revision nav links to Changes view
2 parents 7be8ea9 + 43a95a3 commit 90680b9

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
@@ -516,6 +516,47 @@ def getchangestable(request):
516516
raise Http404()
517517
selectedrev = get_object_or_404(Revision, commitid=request.GET.get('rev'),
518518
branch__project=executable.project)
519+
prevrev = Revision.objects.filter(
520+
branch=selectedrev.branch,
521+
date__lt=selectedrev.date,
522+
).order_by('-date').first()
523+
if prevrev:
524+
try:
525+
summary = Report.objects.get(
526+
revision=prevrev,
527+
executable=executable,
528+
environment=environment).item_description
529+
except Report.DoesNotExist:
530+
summary = ''
531+
prevrev = {
532+
'desc': str(prevrev),
533+
'rev': prevrev.commitid,
534+
'short_rev': prevrev.get_short_commitid(),
535+
'summary': summary,
536+
}
537+
else:
538+
prevrev = None
539+
540+
nextrev = Revision.objects.filter(
541+
branch=selectedrev.branch,
542+
date__gt=selectedrev.date,
543+
).order_by('date').first()
544+
if nextrev:
545+
try:
546+
summary = Report.objects.get(
547+
revision=nextrev,
548+
executable=executable,
549+
environment=environment).item_description
550+
except Report.DoesNotExist:
551+
summary = ''
552+
nextrev = {
553+
'desc': str(nextrev),
554+
'rev': nextrev.commitid,
555+
'short_rev': nextrev.get_short_commitid(),
556+
'summary': summary,
557+
}
558+
else:
559+
nextrev = None
519560

520561
report, created = Report.objects.get_or_create(
521562
executable=executable, environment=environment, revision=selectedrev
@@ -534,6 +575,8 @@ def getchangestable(request):
534575
'rev': selectedrev,
535576
'exe': executable,
536577
'env': environment,
578+
'prev': prevrev,
579+
'next': nextrev,
537580
}, context_instance=RequestContext(request))
538581

539582

0 commit comments

Comments
 (0)