You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by mi...@apache.org on 2019/07/23 14:28:12 UTC

[trafficcontrol] branch master updated: Removed restangular from ParameterService (#3623)

This is an automated email from the ASF dual-hosted git repository.

mitchell852 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/master by this push:
     new e05493c  Removed restangular from ParameterService (#3623)
e05493c is described below

commit e05493cad54a08b389d16e198aa20bf08de46ec8
Author: ocket8888 <oc...@gmail.com>
AuthorDate: Tue Jul 23 09:28:06 2019 -0500

    Removed restangular from ParameterService (#3623)
    
    * Removed restangular from ./ParameterService.js
    
    * Fixed some service methods not throwing in error handlers
---
 .../app/src/common/api/ParameterService.js         | 94 +++++++++++++++-------
 1 file changed, 63 insertions(+), 31 deletions(-)

diff --git a/traffic_portal/app/src/common/api/ParameterService.js b/traffic_portal/app/src/common/api/ParameterService.js
index 691f663..4303451 100644
--- a/traffic_portal/app/src/common/api/ParameterService.js
+++ b/traffic_portal/app/src/common/api/ParameterService.js
@@ -17,72 +17,104 @@
  * under the License.
  */
 
-var ParameterService = function(Restangular, $http, $q, locationUtils, messageModel, ENV) {
+var ParameterService = function($http, locationUtils, messageModel, ENV) {
 
     this.getParameters = function(queryParams) {
-        return Restangular.all('parameters').getList(queryParams);
+        return $http.get(ENV.api['root'] + 'parameters', {params: queryParams}).then(
+            function (result) {
+                return result.data.response
+            },
+            function (err) {
+                throw err;
+            }
+        );
     };
 
     this.getParameter = function(id) {
-        return Restangular.one("parameters", id).get();
+        return $http.get(ENV.api['root'] + 'parameters', {params: {id: id}}).then(
+            function (result) {
+                return result.data.response[0];
+            },
+            function (err) {
+                throw err;
+            }
+        );
     };
 
     this.createParameter = function(parameter) {
-        return Restangular.service('parameters').post(parameter)
-            .then(
-            function() {
+        return $http.post(ENV.api['root'] + 'parameters', parameter).then(
+            function(result) {
                 messageModel.setMessages([ { level: 'success', text: 'Parameter created' } ], true);
                 locationUtils.navigateToPath('/parameters');
+                return result;
             },
-            function(fault) {
-                messageModel.setMessages(fault.data.alerts, false);
+            function(err) {
+                messageModel.setMessages(err.data.alerts, false);
+                throw err;
             }
         );
     };
 
     this.updateParameter = function(parameter) {
-        return parameter.put()
-            .then(
-            function() {
+        return $http.put(ENV.api['root'] + 'parameters/' + parameter.id, parameter).then(
+            function(result) {
                 messageModel.setMessages([ { level: 'success', text: 'Parameter updated' } ], false);
+                return result;
             },
-            function(fault) {
-                messageModel.setMessages(fault.data.alerts, false);
+            function(err) {
+                messageModel.setMessages(err.data.alerts, false);
+                throw err;
             }
         );
     };
 
     this.deleteParameter = function(id) {
-        var request = $q.defer();
-
-        $http.delete(ENV.api['root'] + "parameters/" + id)
-            .then(
-                function(result) {
-                    request.resolve(result.data);
-                },
-                function(fault) {
-                    messageModel.setMessages(fault.data.alerts, false);
-                    request.reject(fault);
-                }
-            );
-
-        return request.promise;
+        return $http.delete(ENV.api['root'] + "parameters/" + id).then(
+            function(result) {
+                return result.data;
+            },
+            function(err) {
+                messageModel.setMessages(err.data.alerts, false);
+                throw err;
+            }
+        );
     };
 
 
     this.getProfileParameters = function(profileId) {
-        return Restangular.one('profiles', profileId).getList('parameters');
+        return $http.get(ENV.api['root'] + 'profiles/' + profileId + '/parameters').then(
+            function (result) {
+                return result.data.response;
+            },
+            function (err) {
+                throw err;
+            }
+        );
     };
 
     this.getProfileUnassignedParams = function(profileId) {
-        return Restangular.one('profiles', profileId).getList('unassigned_parameters');
+        return $http.get(ENV.api['root'] + 'profiles/' + profileId + 'unassigned_parameters').then(
+            function (result) {
+                return result.data.response;
+            },
+            function (err) {
+                throw err;
+            }
+        );
     };
 
     this.getCacheGroupUnassignedParams = function(cgId) {
-        return Restangular.one('cachegroups', cgId).getList('unassigned_parameters');
+        return $http.get(ENV.api['root'] + 'cachegroups/' + cgId + '/unassigned_parameters').then(
+            function (result) {
+                return result.data.response;
+            },
+            function (err) {
+                throw err;
+            }
+        );
     };
 
 };
 
-ParameterService.$inject = ['Restangular', '$http', '$q', 'locationUtils', 'messageModel', 'ENV'];
+ParameterService.$inject = ['$http', 'locationUtils', 'messageModel', 'ENV'];
 module.exports = ParameterService;