Skip to content

Commit

Permalink
Completed tests are now loaded in on the new page.
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe committed Aug 29, 2010
1 parent 438390c commit 1b3532d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
19 changes: 18 additions & 1 deletion server.js
Expand Up @@ -104,6 +104,7 @@ app.get('/', function(req, res) {
});

// POST a new test record
var testStates = {};
app.post('/tests/', function(req, res) {
var urlRegex = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
if (req.body.url && urlRegex.test(req.body.url)) {
Expand All @@ -112,7 +113,11 @@ app.post('/tests/', function(req, res) {
db.saveDoc(id, {url: req.body.url, type: 'test', date: new Date() }, function(er, doc) {

// Asynchronously run tests
runTests(id, req.body.url);
testStates[id] = "running";
runTests(id, req.body.url, function() {
testStates[id] = "complete";
});

res.redirect( '/tests/' + id );
});
} else {
Expand All @@ -126,6 +131,18 @@ app.post('/tests/', function(req, res) {
}
});

/**
* Check whether tests are currently running for a given
* id.
*/
app.get('/tests/running/:id', function(req, res) {
if (testStates[req.params.id]) {
res.send(JSON.stringify({status: testStates[req.params.id]}));
} else {
res.send(JSON.stringify({status: 'unknown'}))
}
});

function runTests(test_id, url, callback, twitter, gitPayload) {
if (!url) {
return;
Expand Down
27 changes: 26 additions & 1 deletion views/layout.ejs
Expand Up @@ -14,7 +14,7 @@
textShadow: '-1px -1px 0px #5799bf',
color: '-linear-gradient(#ffffff, 0.6#ffffff, #eff9ff)'
});
var id = ''; // Needed.
</script>
</head>
<body>
Expand Down Expand Up @@ -64,6 +64,31 @@
}
return false;
});
// Check whether tests are currently running.
if (id > '') {
var redirect = false;
(function checkData() {
$.ajax({
url: '/tests/running/' + id ,
data: {},
dataType: 'json',
success: function (data) {
if (data.status == 'running') {
redirect = true;
setTimeout(checkData, 1000);
} else {
if (redirect == true) {
document.location = '/tests/' + id;
}
}
}
});
})();
}
// Fix cloud clipping issue
$('.bling-cloud2').attr('style', 'min-height:' + $('body').height() + 'px');
Expand Down
8 changes: 8 additions & 0 deletions views/view/tests/show.ejs
@@ -1,3 +1,11 @@
<script type="text/javascript">
<% if (id) { %>
var id = "<%= id %>";
<% } else { %>
var id = false;
<% } %>
</script>

<div class="titlebar">
<div class="container">
<div class="cronos"><%= test.url %></div><a class="button2" href="#"></a>
Expand Down

0 comments on commit 1b3532d

Please sign in to comment.