From 5f2553047d8bb9a813b4cb56495abbcff7439a17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20M=C3=A9tais?= Date: Fri, 6 Feb 2015 12:03:02 +0100 Subject: [PATCH] Add a warning when max runs per day is reached --- front/src/js/app.js | 1 + front/src/js/controllers/dashboardCtrl.js | 10 ++------- front/src/js/controllers/indexCtrl.js | 11 ++------- front/src/js/controllers/ruleCtrl.js | 10 ++------- front/src/js/controllers/screenshotCtrl.js | 10 ++------- front/src/js/controllers/timelineCtrl.js | 10 ++------- front/src/js/services/apiService.js | 26 ++++++++++++++++++++++ front/src/main.html | 1 + 8 files changed, 38 insertions(+), 41 deletions(-) create mode 100644 front/src/js/services/apiService.js 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 @@ +