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 4c8b26e  Removed restangular from ProfileService (#3626)
4c8b26e is described below

commit 4c8b26ef4dd554350a13c10e40c7795f06b6fb8e
Author: ocket8888 <[email protected]>
AuthorDate: Tue Jul 23 09:28:38 2019 -0500

    Removed restangular from ProfileService (#3626)
    
    * Removed restangular from ./ProfileService.js
    
    * Fixed some service methods not throwing in error handlers
---
 .../app/src/common/api/ProfileService.js           | 154 ++++++++++++---------
 1 file changed, 88 insertions(+), 66 deletions(-)

diff --git a/traffic_portal/app/src/common/api/ProfileService.js 
b/traffic_portal/app/src/common/api/ProfileService.js
index 446ce1f..f805c41 100644
--- a/traffic_portal/app/src/common/api/ProfileService.js
+++ b/traffic_portal/app/src/common/api/ProfileService.js
@@ -17,109 +17,131 @@
  * under the License.
  */
 
-var ProfileService = function(Restangular, $http, $q, locationUtils, 
messageModel, ENV) {
+var ProfileService = function($http, locationUtils, messageModel, ENV) {
 
     this.getProfiles = function(queryParams) {
-        return Restangular.all('profiles').getList(queryParams);
+        return $http.get(ENV.api['root'] + 'profiles', {params: 
queryParams}).then(
+            function(result) {
+                return result.data.response;
+            },
+            function(err) {
+                throw err;
+            }
+        );
     };
 
     this.getProfile = function(id, queryParams) {
-        return Restangular.one("profiles", id).get(queryParams);
+        return $http.get(ENV.api['root'] + 'profiles', {params: {id: 
id}}).then(
+            function (result) {
+                return result.data.response[0];
+            },
+            function (err) {
+                throw err;
+            }
+        );
     };
 
     this.createProfile = function(profile) {
-        return Restangular.service('profiles').post(profile)
-            .then(
-            function() {
+        return $http.post(ENV.api['root'] + 'profiles', profile).then(
+            function(result) {
                 messageModel.setMessages([ { level: 'success', text: 'Profile 
created' } ], true);
                 locationUtils.navigateToPath('/profiles');
+                return result;
             },
-            function(fault) {
-                messageModel.setMessages(fault.data.alerts, false);
+            function(err) {
+                messageModel.setMessages(err.data.alerts, false);
+                throw err;
             }
         );
     };
 
     this.updateProfile = function(profile) {
-        return profile.put()
-            .then(
-                function() {
-                    messageModel.setMessages([ { level: 'success', text: 
'Profile updated' } ], false);
-                },
-                function(fault) {
-                    messageModel.setMessages(fault.data.alerts, false);
-                }
+        return $http.put(ENV.api['root'] + 'profiles/' + profile.id, 
profile).then(
+            function(result) {
+                messageModel.setMessages([ { level: 'success', text: 'Profile 
updated' } ], false);
+                return result;
+            },
+            function(err) {
+                messageModel.setMessages(err.data.alerts, false);
+                throw err;
+            }
         );
     };
 
     this.deleteProfile = function(id) {
-        var request = $q.defer();
-
-        $http.delete(ENV.api['root'] + "profiles/" + 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'] + "profiles/" + id).then(
+            function(result) {
+                return result.data;
+            },
+            function(err) {
+                messageModel.setMessages(err.data.alerts, false);
+                throw err;
+            }
+        );
     };
 
     this.getParameterProfiles = function(paramId) {
-        return Restangular.one('parameters', paramId).getList('profiles');
+        return $http.get(ENV.api['root'] + 'parameters/' + paramId + 
'/profiles').then(
+            function (result) {
+                return result.data.response;
+            },
+            function (err) {
+                throw err;
+            }
+        );
     };
 
     this.getParamUnassignedProfiles = function(paramId) {
-        return Restangular.one('parameters', 
paramId).getList('unassigned_profiles');
+        return $http.get(ENV.api['root'] + 'parameters/' + paramId + 
'/unassigned_profiles').then(
+            function (result) {
+                return result.data.response;
+            },
+            function (err) {
+                throw err;
+            }
+        );
     };
 
     this.cloneProfile = function(sourceName, cloneName) {
-        return $http.post(ENV.api['root'] + "profiles/name/" + cloneName + 
"/copy/" + sourceName)
-            .then(
-                function(result) {
-                    messageModel.setMessages(result.data.alerts, true);
-                    locationUtils.navigateToPath('/profiles/' + 
result.data.response.id);
-                },
-                function(fault) {
-                    messageModel.setMessages(fault.data.alerts, false);
-                }
-            );
+        return $http.post(ENV.api['root'] + "profiles/name/" + cloneName + 
"/copy/" + sourceName).then(
+            function(result) {
+                messageModel.setMessages(result.data.alerts, true);
+                locationUtils.navigateToPath('/profiles/' + 
result.data.response.id);
+                return result;
+            },
+            function(err) {
+                messageModel.setMessages(err.data.alerts, false);
+                throw err;
+            }
+        );
     };
 
     this.exportProfile = function(id) {
-        var deferred = $q.defer();
-
-        $http.get(ENV.api['root'] + "profiles/" + id + "/export")
-            .then(
-                function(result) {
-                    deferred.resolve(result.data);
-                },
-                function(fault) {
-                    deferred.reject(fault);
-                }
-            );
-
-        return deferred.promise;
+        return $http.get(ENV.api['root'] + "profiles/" + id + "/export").then(
+            function(result) {
+                return result.data;
+            },
+            function(err) {
+                throw err;
+            }
+        );
     };
 
     this.importProfile = function(importJSON) {
-        return $http.post(ENV.api['root'] + "profiles/import", importJSON)
-            .then(
-                function(result) {
-                    messageModel.setMessages(result.data.alerts, true);
-                    locationUtils.navigateToPath('/profiles/' + 
result.data.response.id);
-                },
-                function(fault) {
-                    messageModel.setMessages(fault.data.alerts, false);
-                }
-            );
+        return $http.post(ENV.api['root'] + "profiles/import", 
importJSON).then(
+            function(result) {
+                messageModel.setMessages(result.data.alerts, true);
+                locationUtils.navigateToPath('/profiles/' + 
result.data.response.id);
+                return result;
+            },
+            function(err) {
+                messageModel.setMessages(err.data.alerts, false);
+                throw err;
+            }
+        );
     };
 
 };
 
-ProfileService.$inject = ['Restangular', '$http', '$q', 'locationUtils', 
'messageModel', 'ENV'];
+ProfileService.$inject = ['$http', 'locationUtils', 'messageModel', 'ENV'];
 module.exports = ProfileService;

Reply via email to