fetchreview.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. var myApp = angular.module('myApp');
  2. myApp.controller('FetchreviewsController', ['$scope', '$http', '$location', '$routeParams', '$route', '$interval', function($scope, $http, $location, $routeParams, $route, $interval){
  3. console.log('FetchreviewsController loaded...');
  4. $scope.page = 0;
  5. $scope.nextpage = false;
  6. var promise;
  7. $scope.loading = false;
  8. $scope.getDownloadInfo = function(){
  9. var id = $routeParams.id;
  10. $scope.loading = true;
  11. $http.get('/crawler/getDownloadInfo/'+id).then(function(response){
  12. $scope.loading = false;
  13. $scope.app = response.data;
  14. if($scope.app.reviews.length % 40 == 0) {
  15. $scope.page = $scope.app.reviews.length/40;
  16. } else {
  17. $scope.page = Math.ceil($scope.app.reviews.length/40);
  18. }
  19. if($scope.page < 51) {
  20. $scope.checkNext();
  21. }
  22. });
  23. }
  24. $scope.checkNext = function(){
  25. var id = $routeParams.id;
  26. $scope.loading = true;
  27. $http.get('/crawler/apps/'+id+"/reviews/?page="+$scope.page).then(function(response){
  28. $scope.loading = false;
  29. if(response.status == 400) {
  30. $scope.reviews = {results:[]};
  31. } else {
  32. $scope.reviews = response.data;
  33. }
  34. }).catch(function() {
  35. $scope.reviews = {results:[]};
  36. $scope.loading = false;
  37. });
  38. }
  39. $scope.downloadNext = function(){
  40. var id = $routeParams.id;
  41. $scope.loopRequest(id);
  42. }
  43. $scope.loopRequest = function(id) {
  44. $scope.loading = true;
  45. $http.get('/crawler/fetchReview/'+id+"/?page="+$scope.page).then(function(response){
  46. $scope.loading = false;
  47. if(response.status == 400) {
  48. $scope.reviews = {results:[]};
  49. } else if($scope.app.reviews.length == response.data.reviews.length) {
  50. $scope.reviews = {results:[]};
  51. } else {
  52. $scope.app = response.data;
  53. $scope.page++;
  54. if($scope.page < 51)
  55. {
  56. $scope.loopRequest(id);
  57. } else {
  58. $scope.reviews = {results:[]};
  59. }
  60. }
  61. }).catch(function() {
  62. $scope.reviews = {results:[]};
  63. $scope.loading = false;
  64. });
  65. }
  66. }]);