Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.37 KB | None | 0 0
  1. (function() {
  2. 'use strict';
  3.  
  4. var app = angular.module('app');
  5. app.controller('AddController', AddController);
  6.  
  7. function AddController($scope, $http) {
  8. $scope.mArray = [];
  9. $scope.clickButton = function() {
  10. $scope.conn = {
  11. 'deviceToken' : '',
  12. 'deviceOs' : '',
  13. 'userName' : ''
  14. };
  15.  
  16. if ($scope.device_token == "" || $scope.device_os == ""
  17. || $scope.user_name == ""
  18. || $scope.device_token == undefined
  19. || $scope.device_os == undefined
  20. || $scope.user_name == undefined) {
  21. alert("Please fill the fields");
  22. } else {
  23. $scope.conn.deviceToken = $scope.device_token;
  24. $scope.conn.deviceOs = $scope.device_os;
  25. $scope.conn.userName = $scope.user_name;
  26. $scope.mArray.push($scope.conn);
  27. $scope.addDeviceToDb($scope.conn);
  28. console.log("hai -" + $scope.mArray.length);
  29. for (var i = 0; i < $scope.mArray.length; i++) {
  30. console.log($scope.mArray.indexOf($scope.mArray[i]) + 1);
  31. }
  32. }
  33. }
  34.  
  35. $scope.PushNotification = function(row) {
  36. // use $.param jQuery function to serialize data from JSON
  37. console.log(row);
  38. var data = JSON.stringify({
  39. "notification" : {
  40. "title" : "Ionic 2 FCM Starter", // Any value
  41. "body" : "new Message", // Any
  42. // value
  43. "sound" : "default", // If you want notification sound
  44. "click_action" : "FCM_PLUGIN_ACTIVITY", // Must be present
  45. // for Android
  46. "icon" : "fcm_push_icon" // White icon Android resource
  47. },
  48. "data" : {
  49. "param1" : "value1"
  50. },
  51. "to" : row.deviceToken,
  52. // "cYK3qwfbb54:APA91bGx0kMMvzyKudcjObxZO5slHg5b8PB8wysfdMf_1wlfErkM7XO7sMHj-tL_a9hDkZ-gyPXzr6wm1NWDNIpfcl5xN1vCgESB4HeUyG4pHpjfCeXcKY7th1GRJbMC84zTJAt3fXKT",
  53. // Topic or single device
  54. "priority" : "high", // If not set, notification won't be
  55. // delivered on completely closed iOS
  56. // app
  57. "restricted_package_name" : "" // Optional. Set for application
  58. // filtering
  59. });
  60.  
  61. var config = {
  62. headers : {
  63. 'Content-Type' : 'application/json',
  64. 'Authorization' : 'key=AAAAgXKnYTY:APA91bFRvdDdqD2vnY3kFQjOAu1lgYVY7DgsxsA9d3p2WOvQp1txbEqnibBDRjfv5duq1SG0NdYZeUNXzg_fI8d4p--9O-po2-ISDwlg4qh3uQdCprLQV5n8thJaIWXOz3eHYSbIdB33FC7x_EjaACBQLb44HflgBQ'
  65. }
  66. }
  67.  
  68. $http.post('https://fcm.googleapis.com/fcm/send', data, config)
  69. .success(function(data, status, headers, config) {
  70. $scope.PostDataResponse = data;
  71. }).error(
  72. function(data, status, header, config) {
  73. $scope.ResponseDetails = "Data: " + data
  74. + "<hr />status: " + status
  75. + "<hr />headers: " + header
  76. + "<hr />config: " + config;
  77. });
  78. alert("Message Successfully send");
  79. }
  80.  
  81. $scope.addDeviceToDb = function(data) {
  82.  
  83. $http(
  84. {
  85. method : 'POST',
  86. url : "http://10.10.14.54:8080/FcmBackend_ws/rest/add_device",
  87. headers : {
  88. 'Content-Type' : 'application/json'
  89. },
  90. transformRequest : function(obj) {
  91. var str = [];
  92. for ( var p in obj)
  93. str.push(encodeURIComponent(p) + "="
  94. + encodeURIComponent(obj[p]));
  95. return str.join("&");
  96. },
  97. data : {
  98. token : data.deviceToken,
  99. device_os : data.deviceOs,
  100. device_version : data.userName
  101. }
  102. }).success(
  103. function(data, status, headers, config) {
  104. console.log("Successfull data : " + data.toString
  105. + " status :" + status);
  106. }).error(function(data, status, header, config) {
  107. console.log("Failed data : " + data + " status :" + status);
  108.  
  109. });
  110. }
  111. var getDeviceFromDb = function(data,$http) {
  112.  
  113. var response = $http({
  114. method : 'GET',
  115. url : "http://localhost:8080/FcmBackend_ws/rest/devices",
  116. withCredentials : true,
  117. headers : {
  118. 'Content-Type' : 'application/json; charset=utf-8'
  119. }
  120. }).success(
  121. function(data, status, headers, config) {
  122. console.log("Successfull data1 : " + data.toString
  123. + " status :" + status);
  124. }).error(function(data, status, header, config) {
  125. console.log("Failed data1 : " + data + " status :" + status);
  126.  
  127. });
  128. }
  129. getDeviceFromDb();
  130. }
  131.  
  132. })();
  133.  
  134. Error: $http is not a function
  135. AddController/getDeviceFromDb@http://localhost/fcmDashBoard /add/add.controller.js:113:19
  136. AddController@http://localhost/fcmDashBoard/add/add.controller.js:129:3
  137. invoke@https://code.angularjs.org/1.2.20/angular.js:3918:14
  138. instantiate@https://code.angularjs.org/1.2.20/angular.js:3929:23
  139. $ControllerProvider/this.$get</<@https://code.angularjs.org/1.2.20 /angular.js:7216:18
  140. nodeLinkFn/<@https://code.angularjs.org/1.2.20/angular.js:6607:34
  141. forEach@https://code.angularjs.org/1.2.20/angular.js:332:11
  142. nodeLinkFn@https://code.angularjs.org/1.2.20/angular.js:6594:11
  143. compositeLinkFn@https://code.angularjs.org/1.2.20/angular.js:6039:13
  144. publicLinkFn@https://code.angularjs.org/1.2.20/angular.js:5934:30
  145. ngViewFillContentFactory/<.link@https://code.angularjs.org/1.2.20/angular- route.js:921:7
  146. nodeLinkFn@https://code.angularjs.org/1.2.20/angular.js:6648:13
  147. compositeLinkFn@https://code.angularjs.org/1.2.20/angular.js:6039:13
  148. publicLinkFn@https://code.angularjs.org/1.2.20/angular.js:5934:30
  149. createBoundTranscludeFn/boundTranscludeFn@https://code.angularjs.org /1.2.20/angular.js:6059:21
  150. controllersBoundTransclude@https://code.angularjs.org/1.2.20/angular.js:6669:18
  151. update@https://code.angularjs.org/1.2.20/angular-route.js:871:25
  152. $RootScopeProvider/this.$get</Scope.prototype.$broadcast@https://code.angularjs.org/1.2.20/angular.js:12887:15
  153. updateRoute/<@https://code.angularjs.org/1.2.20/angular-route.js:552:15
  154. qFactory/defer/deferred.promise.then/wrappedCallback@https: //code.angularjs.org/1.2.20/angular.js:11498:31
  155. qFactory/defer/deferred.promise.then/wrappedCallback@https://code.angularjs.org/1.2.20/angular.js:11498:31
  156. qFactory/ref/<.then/<@https://code.angularjs.org/1.2.20/angular.js:11584:26
  157. $RootScopeProvider/this.$get</Scope.prototype.$eval@https://code.angularjs.org/1.2.20/angular.js:12608:16
  158. $RootScopeProvider/this.$get</Scope.prototype.$digest@https://code.angularjs.org/1.2.20/angular.js:12420:15
  159. $RootScopeProvider/this.$get</Scope.prototype.$apply@https://code.angularjs.org/1.2.20/angular.js:12712:13
  160. done@https://code.angularjs.org/1.2.20/angular.js:8315:34
  161. completeRequest@https://code.angularjs.org/1.2.20/angular.js:8527:7
  162. createHttpBackend/</xhr.onreadystatechange@https://code.angularjs.org/1.2.20/angular.js:8466:1
  163. <div class="ng-scope" ng-view="">`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement