-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleans up Horizon's JavaScript to make it properly modular and well-organized. Adds unit tests written in QUnit for some of the JS modules as a starting point for the JS test framework. You can visit /qunit/ with DEBUG=True in your settings to access the JS test runner. Fixes bug 961509. Change-Id: Ica33765660d0ed80f22c71bc96f122c3fc8b80cc
- Loading branch information
1 parent
7ce7905
commit 41c3a59
Showing
45 changed files
with
2,567 additions
and
2,642 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* Queued ajax handling for Horizon. | ||
* | ||
* Note: The number of concurrent AJAX connections hanlded in the queue | ||
* can be configured by setting an "ajax_queue_limit" key in | ||
* settings.HORIZON_CONFIG to the desired number (or None to disable queue | ||
* limiting). | ||
*/ | ||
horizon.ajax = { | ||
// This will be our jQuery queue container. | ||
_queue: [], | ||
_active: [], | ||
get_messages: function (request) { | ||
return request.getResponseHeader("X-Horizon-Messages"); | ||
}, | ||
// Function to add a new call to the queue. | ||
queue: function(opts) { | ||
var complete = opts.complete, | ||
active = horizon.ajax._active; | ||
|
||
opts.complete = function () { | ||
var index = $.inArray(request, active); | ||
if (index > -1) { | ||
active.splice(index, 1); | ||
} | ||
horizon.ajax.next(); | ||
if (complete) { | ||
complete.apply(this, arguments); | ||
} | ||
}; | ||
|
||
function request() { | ||
return $.ajax(opts); | ||
} | ||
|
||
// Queue the request | ||
horizon.ajax._queue.push(request); | ||
|
||
// Start up the queue handler in case it's stopped. | ||
horizon.ajax.next(); | ||
}, | ||
next: function () { | ||
var queue = horizon.ajax._queue, | ||
limit = horizon.conf.ajax.queue_limit, | ||
request; | ||
if (queue.length && (!limit || horizon.ajax._active.length < limit)) { | ||
request = queue.pop(); | ||
horizon.ajax._active.push(request); | ||
return request(); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
horizon.conf = { | ||
// Placeholders; updated by Django. | ||
debug: null, // | ||
static_url: null, | ||
ajax: { | ||
queue_limit: null | ||
}, | ||
|
||
// Config options which may be overridden. | ||
spinner_options: { | ||
inline: { | ||
lines: 10, | ||
length: 5, | ||
width: 2, | ||
radius: 3, | ||
color: '#000', | ||
speed: 0.8, | ||
trail: 50, | ||
zIndex: 100 | ||
}, | ||
modal: { | ||
lines: 10, | ||
length: 15, | ||
width: 4, | ||
radius: 10, | ||
color: '#000', | ||
speed: 0.8, | ||
trail: 50 | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* Convenience functions for dealing with namespaced Horizon cookies. */ | ||
horizon.cookies = { | ||
read: function (cookie_name) { | ||
// Read in a cookie which contains JSON, and return a parsed object. | ||
var cookie = $.cookie("horizon." + cookie_name); | ||
if (cookie === null) { | ||
return {}; | ||
} | ||
return $.parseJSON(cookie); | ||
}, | ||
write: function (cookie_name, data) { | ||
// Overwrites a cookie. | ||
$.cookie("horizon." + cookie_name, JSON.stringify(data), {path: "/"}); | ||
}, | ||
update: function (cookie_name, key, value) { | ||
var data = horizon.cookies.read("horizon." + cookie_name); | ||
data[key] = value; | ||
horizon.cookies.write(cookie_name, data); | ||
}, | ||
remove: function (cookie_name) { | ||
$.cookie("horizon." + cookie_name, null); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
horizon.instances = { | ||
user_decided_length: false, | ||
|
||
getConsoleLog: function(via_user_submit) { | ||
var form_element = $("#tail_length"), | ||
data; | ||
|
||
if (!via_user_submit) { | ||
via_user_submit = false; | ||
} | ||
|
||
if(this.user_decided_length) { | ||
data = $(form_element).serialize(); | ||
} else { | ||
data = "length=35"; | ||
} | ||
|
||
$.ajax({ | ||
url: $(form_element).attr('action'), | ||
data: data, | ||
method: 'get', | ||
success: function(response_body) { | ||
$('pre.logs').text(response_body); | ||
}, | ||
error: function(response) { | ||
if(via_user_submit) { | ||
horizon.clearErrorMessages(); | ||
horizon.alert('error', 'There was a problem communicating with the server, please try again.'); | ||
} | ||
} | ||
}); | ||
} | ||
}; | ||
|
||
horizon.addInitFunction(function () { | ||
$(document).on('submit', '#tail_length', function (evt) { | ||
horizon.instances.user_decided_length = true; | ||
horizon.instances.getConsoleLog(true); | ||
evt.preventDefault(); | ||
}); | ||
}); |
Oops, something went wrong.