Skip to content

Commit 5ef6809

Browse files
committed
Merge pull request tobami#107 from squiddy/js
Separate JS from Templates #2
2 parents 85239bf + 86d952c commit 5ef6809

9 files changed

Lines changed: 306 additions & 253 deletions

File tree

codespeed/static/js/changes.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
var Changes = (function(window){
2+
3+
// Localize globals
4+
var TIMELINE_URL = window.TIMELINE_URL, getLoadText = window.getLoadText;
5+
16
var currentproject, changethres, trendthres, projectmatrix, revisionboxes = {};
27

38
function getConfiguration() {
@@ -122,4 +127,17 @@ function init(defaults) {
122127
$("#revision").html(revisionboxes[defaults.project]);
123128
$("#revision").val(defaults.revision);
124129
$("#revision").change(refreshContent);
130+
131+
$("#permalink").click(function() {
132+
window.location = "?" + $.param(getConfiguration());
133+
});
134+
135+
refreshContent();
125136
}
137+
138+
return {
139+
init: init,
140+
config: config
141+
};
142+
143+
})(window);

codespeed/static/js/codespeed.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
2-
function permalink() {
3-
window.location="?" + $.param(getConfiguration());
4-
}
5-
61
function readCheckbox(el) {
72
/* Builds a string that holds all checked values in an input form */
83
var config = "";
@@ -30,3 +25,22 @@ function getLoadText(text, h, showloader) {
3025
loadtext += '</p></div>';
3126
return loadtext;
3227
}
28+
29+
$(function() {
30+
// Check all and none links
31+
$('.checkall').each(function() {
32+
var inputs = $(this).parent().children("li").children("input");
33+
$(this).click(function() {
34+
inputs.attr("checked", true);
35+
return false;
36+
});
37+
});
38+
39+
$('.uncheckall').each(function() {
40+
var inputs = $(this).parent().children("li").children("input");
41+
$(this).click(function() {
42+
inputs.attr("checked", false);
43+
return false;
44+
});
45+
});
46+
});

codespeed/static/js/comparison.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
var Comparison = (function(window){
2+
3+
// Localize globals
4+
var readCheckbox = window.readCheckbox, getLoadText = window.getLoadText;
5+
6+
var compdata, bench_units;
7+
18
function getConfiguration() {
29
return {
310
exe: readCheckbox("input[name='executables']:checked"),
@@ -375,3 +382,51 @@ function renderComparisonPlot(plotid, benchmarks, exes, enviros, baseline, chart
375382
$("#" + plotid).css('height', h);
376383
$.jqplot(plotid, plotdata, plotoptions);
377384
}
385+
386+
function init(defaults) {
387+
bench_units = defaults.bench_units;
388+
389+
// Set default values
390+
$("#chart_type").val(defaults.chart_type);
391+
$("#baseline").val(defaults.baseline);
392+
$("#direction").attr("checked", defaults.direction === "True");
393+
394+
var sel = $("input[name='executables']");
395+
$.each(defaults.executables, function(i, exe) {
396+
sel.filter("[value='" + exe + "']").attr('checked', true);
397+
});
398+
399+
sel = $("input[name='benchmarks']");
400+
$.each(defaults.benchmarks, function(i, bench) {
401+
sel.filter("[value='" + bench + "']").attr('checked', true);
402+
});
403+
404+
sel = $("input[name='environments']");
405+
$.each(defaults.environments, function(i, env) {
406+
sel.filter("[value='" + env + "']").attr('checked', true);
407+
});
408+
409+
$("#chart_type, #baseline, #direction, input[name='executables']," +
410+
"input[name='benchmarks'], input[name='environments']").change(refreshContent);
411+
412+
$('.checkall, .uncheckall').click(refreshContent);
413+
414+
$.ajaxSetup ({
415+
cache: false
416+
});
417+
418+
// Get comparison data
419+
var h = $("#content").height();//get height for loading text
420+
$("#cplot").html(getLoadText("Loading...", h, true));
421+
$.getJSON("json/", savedata);
422+
423+
$("#permalink").click(function() {
424+
window.location = "?" + $.param(getConfiguration());
425+
});
426+
}
427+
428+
return {
429+
init: init
430+
};
431+
432+
})(window);

codespeed/static/js/timeline.js

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
var Timeline = (function(window){
2+
3+
// Localize globals
4+
var CHANGES_URL = window.CHANGES_URL, readCheckbox = window.readCheckbox,
5+
getLoadText = window.getLoadText;
6+
7+
var seriesindex = [],
8+
baselineColor = "#d8b83f",
9+
seriesColors = ["#4bb2c5", "#EAA228", "#579575", "#953579", "#839557", "#ff5800", "#958c12", "#4b5de4", "#0085cc"],
10+
defaults;
11+
112
function setExeColors() {
213
// Set color data attribute for all executables
314
$("#executable > div.boxbody > ul > ul > li > input").each(function(index) {
@@ -36,7 +47,7 @@ function getConfiguration() {
3647
}
3748

3849
function permalinkToChanges(commitid, executableid, environment) {
39-
window.location=changes_url + "?rev=" + commitid + "&" + "exe=" + executableid + "&env=" + environment;
50+
window.location=CHANGES_URL + "?rev=" + commitid + "&" + "exe=" + executableid + "&env=" + environment;
4051
}
4152

4253
function OnMarkerClickHandler(ev, gridpos, datapos, neighbor, plot) {
@@ -248,3 +259,79 @@ function refreshSite(event) {
248259
setValuesOfInputFields(event);
249260
refreshContent();
250261
}
262+
263+
function setValuesOfInputFields(event) {
264+
// Either set the default value, or the one parsed from the url
265+
266+
// Reset all checkboxes
267+
$("input:checkbox").removeAttr('checked');
268+
269+
$("#revisions").val(valueOrDefault(event.parameters.revs, defaults.revisions));
270+
$("#baseline").val(valueOrDefault(event.parameters.base, defaults.baseline));
271+
272+
// Set default selected executables
273+
var executables = event.parameters.exe ? event.parameters.exe.split(',') : defaults.executables;
274+
var sel = $("input[name='executable']");
275+
276+
$.each(executables, function(i, exe) {
277+
sel.filter("[value='" + exe + "']").attr('checked', true);
278+
});
279+
280+
// Set default selected branches
281+
var branches = event.parameters.bran ? event.parameters.bran.split(',') : defaults.branches;
282+
sel = $("input[name='branch']");
283+
284+
$.each(branches, function(i, b) {
285+
sel.filter("[value='" + b + "']").attr('checked', true);
286+
});
287+
288+
// Set default selected benchmark
289+
var benchmark = valueOrDefault(event.parameters.ben, defaults.benchmark);
290+
$("input:radio[name='benchmark']")
291+
.filter("[value='" + benchmark + "']")
292+
.attr('checked', true);
293+
294+
// Set default selected environment
295+
var environment = valueOrDefault(event.parameters.env, defaults.environment);
296+
$("input:radio[name='environments']")
297+
.filter("[value='" + environment + "']")
298+
.attr('checked', true);
299+
300+
// Add color legend to executable list
301+
$("#executable div.boxbody > ul > ul > li > input").each(function() {
302+
$(this).parent()
303+
.find("div.seriescolor")
304+
.css("background-color", getColor($(this).attr("id").slice(10)));
305+
});
306+
307+
$("#baselinecolor").css("background-color", baselineColor);
308+
$("#equidistant").attr('checked', valueOrDefault(event.parameters.equid, defaults.equidistant === "on"));
309+
}
310+
311+
function init(def) {
312+
defaults = def;
313+
314+
$.ajaxSetup ({
315+
cache: false
316+
});
317+
318+
// Even listener for clicks on plot markers
319+
$.jqplot.eventListenerHooks.push(['jqplotClick', OnMarkerClickHandler]);
320+
321+
// Init and change handlers are set to the refreshContent handler
322+
$.address.init(initializeSite).change(refreshSite);
323+
324+
$('.checkall, .uncheckall').click(refreshContent);
325+
326+
setExeColors();
327+
328+
$("#permalink").click(function() {
329+
window.location = "?" + $.param(getConfiguration());
330+
});
331+
}
332+
333+
return {
334+
init: init
335+
};
336+
337+
})(window);

codespeed/templates/codespeed/changes.html

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,5 @@
11
{% extends "base.html" %}
22
{% block title %}{{ block.super }}: Changes{% endblock %}
3-
{% block extra_head %}
4-
{{ block.super }}
5-
<script type="text/javascript" src="{{ STATIC_URL }}js/jquery.tablesorter.min.js"></script>
6-
<script type="text/javascript" src="{{ STATIC_URL }}js/changes.js"></script>
7-
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js"></script>
8-
<script type="text/javascript">
9-
var TIMELINE_URL = "{% url timeline %}";
10-
11-
$(function() {
12-
// Configure defaults
13-
init({
14-
project: "{{ defaultexecutable.project }}",
15-
executable: "{{ defaultexecutable.id }}",
16-
environment: "{{ defaultenvironment.id }}",
17-
revision: "{{ selectedrevision.commitid }}",
18-
trend: "{{ defaulttrend }}",
19-
projectmatrix: eval({{ projectmatrix|safe }}),
20-
revisionlists: eval({{ revisionlists|safe }})
21-
});
22-
23-
config({
24-
changethres: {{ defaultchangethres }},
25-
trendthres: {{ defaulttrendthres }}
26-
});
27-
28-
refreshContent();
29-
});
30-
</script>
31-
{% endblock %}
323

334
{% block navigation %}
345
{{ block.super }}
@@ -83,9 +54,35 @@
8354

8455
<div id="configbar">
8556
<span class="options">Results for revision <select id="revision"></select></span>
86-
<a id="permalink" href="javascript:permalink();">Permalink</a>
57+
<a id="permalink" href="#">Permalink</a>
8758
</div>
8859
<div id="content" class="clearfix">
8960
<div id="contentwrap"></div>
9061
</div>
9162
{% endblock %}
63+
64+
{% block extra_body %}
65+
{{ block.super }}
66+
<script type="text/javascript" src="{{ STATIC_URL }}js/jquery.tablesorter.min.js"></script>
67+
<script type="text/javascript" src="{{ STATIC_URL }}js/changes.js"></script>
68+
<script type="text/javascript">
69+
var TIMELINE_URL = "{% url timeline %}";
70+
71+
$(function() {
72+
Changes.config({
73+
changethres: {{ defaultchangethres }},
74+
trendthres: {{ defaulttrendthres }}
75+
});
76+
77+
Changes.init({
78+
project: "{{ defaultexecutable.project }}",
79+
executable: "{{ defaultexecutable.id }}",
80+
environment: "{{ defaultenvironment.id }}",
81+
revision: "{{ selectedrevision.commitid }}",
82+
trend: "{{ defaulttrend }}",
83+
projectmatrix: eval({{ projectmatrix|safe }}),
84+
revisionlists: eval({{ revisionlists|safe }})
85+
});
86+
});
87+
</script>
88+
{% endblock %}

0 commit comments

Comments
 (0)