Advertisement
Guest User

Untitled

a guest
Jan 12th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.45 KB | None | 0 0
  1. crossover.controller("rootController", ['$scope', '$rootScope', '$mdToast', '$mdMedia', '$mdDialog', '$location', '$http', function($scope, $rootScope, $mdToast, $mdMedia, $mdDialog, $location, $http){
  2. $rootScope.isLoggedIn = false;
  3. $rootScope.sessionId = null;
  4. $scope.showPopup = function(ev, template) {
  5. var useFullScreen = ($mdMedia('sm') || $mdMedia('xs')) && $scope.customFullscreen;
  6. $mdDialog.show({
  7. controller: DialogController,
  8. templateUrl: template,
  9. parent: angular.element(document.body),
  10. targetEvent: ev,
  11. clickOutsideToClose:true,
  12. fullscreen: useFullScreen
  13. })
  14. .then(function(answer) {
  15. if(answer){
  16. console.log("Hello");
  17. $mdToast.show(
  18. $mdToast.simple()
  19. .textContent('Request Sent!!!')
  20. .hideDelay(2000).position('top right')
  21. );
  22. }
  23. }, function() {
  24. //user cancelled wanna handle?
  25. });
  26. $scope.$watch(function() {
  27. return $mdMedia('xs') || $mdMedia('sm');
  28. }, function(wantsFullScreen) {
  29. $scope.customFullscreen = (wantsFullScreen === true);
  30. });
  31. };
  32. $scope.logout = function(){
  33. $rootScope.isLoggedIn = false;
  34. $rootScope.sessionId = '';
  35. $location.path("/login");
  36. //content type sent is text/json but they are not text/json actually
  37. //so angular giving error while accepting them.
  38. // $http.get("http://localhost:8080/logout?sessionid=" + $rootScope.sessionId, {parseJSON: false}).then(function(result){
  39. // $rootScope.isLoggedIn = false;
  40. // $rootScope.sessionId = '';
  41. // $location.path("/login");
  42. // });
  43. }
  44.  
  45. }]);
  46.  
  47. crossover.controller("loginController", ['$scope', '$http', '$rootScope', '$location', function($scope, $http, $rootScope, $location){
  48. $scope.user = {
  49. 'userName' : '',
  50. 'password': ''
  51. };
  52. $scope.doLogin = function(){
  53. $http.get("http://localhost:8080/login?username=" + $scope.user.userName +
  54. "&password=" + $scope.user.password)
  55. .then(function(res){
  56. if(res.data.sessionId == null){
  57. console.log("Invalid credentials");
  58. alert("Please provide correct credentials");
  59. }else{
  60. $rootScope.sessionId = res.data.sessionId;
  61. $rootScope.isLoggedIn = true;
  62. $location.path("/dashboard");
  63. }
  64. });
  65. }
  66. }]);
  67.  
  68. crossover.controller("dashboardController", ['$scope', '$location', '$rootScope', function($scope, $location, $rootScope){
  69. if($rootScope.isLoggedIn != true){
  70. $location.path("/login");
  71. }
  72. $scope.charts = [{
  73. 'what' : 'Sales Total per Sales Man',
  74. 'where': 'salestotal/salesman'
  75. }, {
  76. 'what' : 'Sales Total per Month',
  77. 'where': 'salestotal/month'
  78. },{
  79. 'what': 'Top 5 Sales Order',
  80. 'where': 'top5/order'
  81. },{
  82. 'what': 'Top 5 Sales Men',
  83. 'where': 'top5/salesman'
  84. }];
  85. $scope.goto = function(str){
  86. $location.path(str);
  87. }
  88. }]);
  89.  
  90. crossover.controller("pieController", ['$scope', '$rootScope', '$http', '$location', function($scope, $rootScope, $http, $location){
  91. if($rootScope.isLoggedIn != true){
  92. $location.path("/login");
  93. }
  94. $scope.labels = [];
  95. $scope.data = [];
  96.  
  97. $scope.refresh = function(){
  98. $http.get('http://localhost:8080/salesmandata?sessionid=' + $rootScope.sessionId).success(function(result){
  99. $scope.labels = [];
  100. $scope.data = [];
  101. angular.forEach(result.data, function(obj){
  102. $scope.labels.push(obj[0]);
  103. $scope.data.push(obj[1]);
  104. });
  105. });
  106. }
  107. $scope.refresh();
  108. }]);
  109.  
  110. crossover.controller('barController', ['$scope', '$rootScope', '$http', '$location', function($scope, $rootScope, $http, $location){
  111. if($rootScope.isLoggedIn != true){
  112. $location.path("/login");
  113. }
  114. $scope.labels = [];
  115. $scope.data = [[]];
  116. $scope.series = ['Series A'];
  117. $scope.options = { scaleShowVerticalLines: false};
  118. $scope.refresh = function(){
  119. $http.get('http://localhost:8080/lastyeardata?sessionid=' + $rootScope.sessionId).success(function(result){
  120. $scope.labels = [];
  121. $scope.data = [[]];
  122. angular.forEach(result.data, function(obj){
  123. $scope.labels.push(obj[0]);
  124. $scope.data[0].push(obj[1]);
  125. });
  126. });
  127. }
  128. $scope.refresh();
  129.  
  130. }]);
  131.  
  132. crossover.controller('part3Controller', ['$scope', '$rootScope', '$http', '$location', function($scope, $rootScope, $http, $location){
  133. if($rootScope.isLoggedIn != true){
  134. $location.path("/login");
  135. }
  136. $scope.items = [];
  137. $scope.refresh = function(){
  138. $http.get('http://localhost:8080/topsalesorders?sessionid=' + $rootScope.sessionId).success(function(result){
  139. $scope.items = [];
  140. angular.forEach(result.data, function(obj){
  141. $scope.items.push(obj);
  142. });
  143. });
  144. }
  145. $scope.refresh();
  146. }]);
  147.  
  148. crossover.controller('part4Controller', ['$scope', '$rootScope', '$http', '$location', function($scope, $rootScope, $http, $location){
  149. if($rootScope.isLoggedIn != true){
  150. $location.path("/login");
  151. }
  152. $scope.items = [];
  153. $scope.refresh = function(){
  154. $http.get('http://localhost:8080/topsalesmen?sessionid=' + $rootScope.sessionId).success(function(result){
  155. $scope.items = [];
  156. angular.forEach(result.data, function(obj){
  157. $scope.items.push({
  158. 'Name': obj[0],
  159. 'value': obj[1]
  160. });
  161. });
  162. }).error(function(result){
  163. alert("some error occurred");
  164. });
  165. }
  166. $scope.refresh();
  167. }]);
  168.  
  169. function DialogController($scope, $mdDialog) {
  170. $scope.hide = function() {
  171. $mdDialog.hide();
  172. };
  173. $scope.cancel = function() {
  174. $mdDialog.cancel();
  175. };
  176. $scope.send = function(answer) {
  177. $mdDialog.hide(answer);
  178. };
  179. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement