diff --git a/front/src/img/favicon-fail.png b/front/src/img/favicon-fail.png new file mode 100644 index 0000000..faeba8f Binary files /dev/null and b/front/src/img/favicon-fail.png differ diff --git a/front/src/img/favicon-success.png b/front/src/img/favicon-success.png new file mode 100644 index 0000000..168e621 Binary files /dev/null and b/front/src/img/favicon-success.png differ diff --git a/front/src/js/controllers/queueCtrl.js b/front/src/js/controllers/queueCtrl.js index f62775d..4c61d2d 100644 --- a/front/src/js/controllers/queueCtrl.js +++ b/front/src/js/controllers/queueCtrl.js @@ -5,6 +5,16 @@ queueCtrl.controller('QueueCtrl', ['$scope', '$routeParams', '$location', 'Runs' var numberOfTries = 0; + var favicon = document.querySelector('link[rel=icon]'); + var faviconUrl = 'img/favicon.png'; + var faviconSuccessUrl = 'img/favicon-success.png'; + var faviconFailUrl = 'img/favicon-fail.png'; + var faviconInterval = null; + var faviconCounter = 0; + var faviconCanvas = null; + var faviconCanvasContext = null; + var faviconImage = null; + function getRunStatus () { Runs.get({runId: $scope.runId}, function(data) { $scope.url = data.params.url; @@ -15,23 +25,30 @@ queueCtrl.controller('QueueCtrl', ['$scope', '$routeParams', '$location', 'Runs' if (data.status.statusCode === 'awaiting') { numberOfTries ++; + rotateFavicon(); // Retrying every 2 seconds (and increasing the delay a bit more each time) setTimeout(getRunStatus, 2000 + (numberOfTries * 100)); } else if (data.status.statusCode === 'running') { numberOfTries ++; + rotateFavicon(); // Retrying every second or so setTimeout(getRunStatus, 1000 + (numberOfTries * 10)); } else if (data.status.statusCode === 'complete') { + stopFavicon(true); + $location.path('/result/' + $scope.runId).replace(); } else { - // Handled by the view + stopFavicon(false); + + // The rest is handled by the view } }, function(response) { if (response.status === 404) { + stopFavicon(false); $scope.notFound = true; $scope.connectionLost = false; } else if (response.status === 0) { @@ -42,6 +59,39 @@ queueCtrl.controller('QueueCtrl', ['$scope', '$routeParams', '$location', 'Runs' } }); } + + function rotateFavicon() { + if (!faviconInterval) { + faviconImage = new Image(); + faviconImage.onload = function() { + faviconCanvas = document.getElementById('faviconRotator'); + faviconCanvasContext = faviconCanvas.getContext('2d'); + faviconCanvasContext.fillStyle = '#212240'; + + if (!!faviconCanvasContext) { + faviconInterval = window.setInterval(faviconTick, 1000); + } + }; + faviconImage.src = faviconUrl; + } + } + + function faviconTick() { + faviconCounter ++; + faviconCanvasContext.save(); + faviconCanvasContext.fillRect(0, 0, 32, 32); + faviconCanvasContext.translate(16, 16); + faviconCanvasContext.rotate(45 * faviconCounter * Math.PI / 180); + faviconCanvasContext.translate(-16, -16); + faviconCanvasContext.drawImage(faviconImage, 0, 0, 32, 32); + faviconCanvasContext.restore(); + favicon.href = faviconCanvas.toDataURL('image/png'); + } + + function stopFavicon(isSuccess) { + window.clearInterval(faviconInterval); + favicon.href = isSuccess ? faviconSuccessUrl : faviconFailUrl; + } getRunStatus(); }]); diff --git a/front/src/views/queue.html b/front/src/views/queue.html index e86b249..d628768 100644 --- a/front/src/views/queue.html +++ b/front/src/views/queue.html @@ -42,4 +42,5 @@
Connection lost with server

Check your wifi cable, or maybe YellowLab.tools is rebooting.

-
\ No newline at end of file + + \ No newline at end of file