diff --git a/front/src/js/app.js b/front/src/js/app.js
index 4c4f43b..c629140 100644
--- a/front/src/js/app.js
+++ b/front/src/js/app.js
@@ -10,6 +10,7 @@ var yltApp = angular.module('YellowLabTools', [
'timelineCtrl',
'runsFactory',
'resultsFactory',
+ 'apiService',
'menuService',
'gradeDirective',
'offendersDirectives'
diff --git a/front/src/js/controllers/dashboardCtrl.js b/front/src/js/controllers/dashboardCtrl.js
index 4243e7b..d693e7f 100644
--- a/front/src/js/controllers/dashboardCtrl.js
+++ b/front/src/js/controllers/dashboardCtrl.js
@@ -1,6 +1,6 @@
var dashboardCtrl = angular.module('dashboardCtrl', ['resultsFactory', 'menuService']);
-dashboardCtrl.controller('DashboardCtrl', ['$scope', '$rootScope', '$routeParams', '$location', 'Results', 'Runs', 'Menu', function($scope, $rootScope, $routeParams, $location, Results, Runs, Menu) {
+dashboardCtrl.controller('DashboardCtrl', ['$scope', '$rootScope', '$routeParams', '$location', 'Results', 'API', 'Menu', function($scope, $rootScope, $routeParams, $location, Results, API, Menu) {
$scope.runId = $routeParams.runId;
$scope.Menu = Menu.setCurrentPage('dashboard', $scope.runId);
$scope.fromSocialShare = $location.search().share;
@@ -34,13 +34,7 @@ dashboardCtrl.controller('DashboardCtrl', ['$scope', '$rootScope', '$routeParams
};
$scope.testAgain = function() {
- Runs.save({
- url: $scope.result.params.url,
- waitForResponse: false,
- screenshot: true
- }, function(data) {
- $location.path('/queue/' + data.runId);
- });
+ API.launchTest($scope.result.params.url);
};
/// When comming from a social shared link, the user needs to click on "See full report" button to display the full dashboard.
diff --git a/front/src/js/controllers/indexCtrl.js b/front/src/js/controllers/indexCtrl.js
index e460d83..bbf4f12 100644
--- a/front/src/js/controllers/indexCtrl.js
+++ b/front/src/js/controllers/indexCtrl.js
@@ -1,16 +1,9 @@
var indexCtrl = angular.module('indexCtrl', []);
-indexCtrl.controller('IndexCtrl', ['$scope', '$location', 'Runs', function($scope, $location, Runs) {
+indexCtrl.controller('IndexCtrl', ['$scope', '$location', 'API', function($scope, $location, API) {
$scope.launchTest = function() {
if ($scope.url) {
- Runs.save({
- url: $scope.url,
- waitForResponse: false,
- screenshot: true
- }, function(data) {
- $location.path('/queue/' + data.runId);
- });
-
+ API.launchTest();
}
};
}]);
\ No newline at end of file
diff --git a/front/src/js/controllers/ruleCtrl.js b/front/src/js/controllers/ruleCtrl.js
index 27e9dcd..d5aec07 100644
--- a/front/src/js/controllers/ruleCtrl.js
+++ b/front/src/js/controllers/ruleCtrl.js
@@ -1,6 +1,6 @@
var ruleCtrl = angular.module('ruleCtrl', []);
-ruleCtrl.controller('RuleCtrl', ['$scope', '$rootScope', '$routeParams', '$location', '$sce', 'Menu', 'Results', 'Runs', function($scope, $rootScope, $routeParams, $location, $sce, Menu, Results, Runs) {
+ruleCtrl.controller('RuleCtrl', ['$scope', '$rootScope', '$routeParams', '$location', '$sce', 'Menu', 'Results', 'API', function($scope, $rootScope, $routeParams, $location, $sce, Menu, Results, API) {
$scope.runId = $routeParams.runId;
$scope.policyName = $routeParams.policy;
$scope.Menu = Menu.setCurrentPage(null, $scope.runId);
@@ -29,13 +29,7 @@ ruleCtrl.controller('RuleCtrl', ['$scope', '$rootScope', '$routeParams', '$locat
};
$scope.testAgain = function() {
- Runs.save({
- url: $scope.result.params.url,
- waitForResponse: false,
- screenshot: true
- }, function(data) {
- $location.path('/queue/' + data.runId);
- });
+ API.launchTest($scope.result.params.url);
};
loadResults();
diff --git a/front/src/js/controllers/screenshotCtrl.js b/front/src/js/controllers/screenshotCtrl.js
index 57d7632..1120d9c 100644
--- a/front/src/js/controllers/screenshotCtrl.js
+++ b/front/src/js/controllers/screenshotCtrl.js
@@ -1,6 +1,6 @@
var screenshotCtrl = angular.module('screenshotCtrl', ['resultsFactory', 'menuService']);
-screenshotCtrl.controller('ScreenshotCtrl', ['$scope', '$rootScope', '$routeParams', '$location', 'Results', 'Runs', 'Menu', function($scope, $rootScope, $routeParams, $location, Results, Runs, Menu) {
+screenshotCtrl.controller('ScreenshotCtrl', ['$scope', '$rootScope', '$routeParams', '$location', 'Results', 'API', 'Menu', function($scope, $rootScope, $routeParams, $location, Results, API, Menu) {
$scope.runId = $routeParams.runId;
$scope.Menu = Menu.setCurrentPage(null, $scope.runId);
@@ -24,13 +24,7 @@ screenshotCtrl.controller('ScreenshotCtrl', ['$scope', '$rootScope', '$routePara
};
$scope.testAgain = function() {
- Runs.save({
- url: $scope.result.params.url,
- waitForResponse: false,
- screenshot: true
- }, function(data) {
- $location.path('/queue/' + data.runId);
- });
+ API.launchTest($scope.result.params.url);
};
loadResults();
diff --git a/front/src/js/controllers/timelineCtrl.js b/front/src/js/controllers/timelineCtrl.js
index 2dd1943..6ea6a0c 100644
--- a/front/src/js/controllers/timelineCtrl.js
+++ b/front/src/js/controllers/timelineCtrl.js
@@ -1,6 +1,6 @@
var timelineCtrl = angular.module('timelineCtrl', []);
-timelineCtrl.controller('TimelineCtrl', ['$scope', '$rootScope', '$routeParams', '$location', '$timeout', 'Menu', 'Results', 'Runs', function($scope, $rootScope, $routeParams, $location, $timeout, Menu, Results, Runs) {
+timelineCtrl.controller('TimelineCtrl', ['$scope', '$rootScope', '$routeParams', '$location', '$timeout', 'Menu', 'Results', 'API', function($scope, $rootScope, $routeParams, $location, $timeout, Menu, Results, API) {
$scope.runId = $routeParams.runId;
$scope.Menu = Menu.setCurrentPage('timeline', $scope.runId);
@@ -132,13 +132,7 @@ timelineCtrl.controller('TimelineCtrl', ['$scope', '$rootScope', '$routeParams',
};
$scope.testAgain = function() {
- Runs.save({
- url: $scope.result.params.url,
- waitForResponse: false,
- screenshot: true
- }, function(data) {
- $location.path('/queue/' + data.runId);
- });
+ API.launchTest($scope.result.params.url);
};
loadResults();
diff --git a/front/src/js/services/apiService.js b/front/src/js/services/apiService.js
new file mode 100644
index 0000000..27aaac9
--- /dev/null
+++ b/front/src/js/services/apiService.js
@@ -0,0 +1,26 @@
+var apiService = angular.module('apiService', []);
+
+apiService.factory('API', ['$location', 'Runs', 'Results', function($location, Runs, Results) {
+
+ return {
+
+ launchTest: function(url) {
+ Runs.save({
+ url: url,
+ waitForResponse: false,
+ screenshot: true
+ }, function(data) {
+ $location.path('/queue/' + data.runId);
+ }, function(response) {
+ if (response.status === 429) {
+ alert('Too many requests, you reached the max number of requests allowed in 24h');
+ } else {
+ alert('An error occured...');
+ }
+ });
+ }
+
+
+ };
+
+}]);
\ No newline at end of file
diff --git a/front/src/main.html b/front/src/main.html
index d7304eb..a095988 100644
--- a/front/src/main.html
+++ b/front/src/main.html
@@ -33,6 +33,7 @@
+