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 5da4a5b Removed restangular from TypeService (#3597)
5da4a5b is described below
commit 5da4a5b43605d499c474a38dfdc33d20a88a3913
Author: ocket8888 <[email protected]>
AuthorDate: Fri Jul 26 15:59:48 2019 -0600
Removed restangular from TypeService (#3597)
* Removed restangular from ./TypeService.js
* Fixed some service methods not throwing in error handlers
---
traffic_portal/app/src/common/api/TypeService.js | 77 +++++++++++++++---------
1 file changed, 47 insertions(+), 30 deletions(-)
diff --git a/traffic_portal/app/src/common/api/TypeService.js
b/traffic_portal/app/src/common/api/TypeService.js
index aab6000..8076b1c 100644
--- a/traffic_portal/app/src/common/api/TypeService.js
+++ b/traffic_portal/app/src/common/api/TypeService.js
@@ -17,54 +17,71 @@
* under the License.
*/
-var TypeService = function(Restangular, locationUtils, messageModel) {
+var TypeService = function($http, ENV, locationUtils, messageModel) {
this.getTypes = function(queryParams) {
- return Restangular.all('types').getList(queryParams);
+ return $http.get(ENV.api['root'] + 'types', {params:
queryParams}).then(
+ function (result) {
+ return result.data.response;
+ },
+ function (err) {
+ throw err;
+ }
+ )
};
this.getType = function(id) {
- return Restangular.one("types", id).get();
+ return $http.get(ENV.api['root'] + 'types', {params: {id: id}}).then(
+ function (result) {
+ return result.data.response[0];
+ },
+ function (err) {
+ throw err;
+ }
+ )
};
this.createType = function(type) {
- return Restangular.service('types').post(type)
- .then(
- function() {
- messageModel.setMessages([ { level: 'success', text: 'Type
created' } ], true);
- locationUtils.navigateToPath('/types');
- },
- function(fault) {
- messageModel.setMessages(fault.data.alerts, false);
- }
- );
+ return $http.post(ENV.api['root'] + 'types', type).then(
+ function(result) {
+ messageModel.setMessages([ { level: 'success', text: 'Type
created' } ], true);
+ locationUtils.navigateToPath('/types');
+ return result;
+ },
+ function(err) {
+ messageModel.setMessages(err.data.alerts, false);
+ throw err;
+ }
+ );
};
this.updateType = function(type) {
- return type.put()
- .then(
- function() {
- messageModel.setMessages([ { level: 'success', text: 'Type
updated' } ], false);
- },
- function(fault) {
- messageModel.setMessages(fault.data.alerts, false);
- }
+ return $http.put(ENV.api['root'] + 'types/' + type.id, type).then(
+ function(result) {
+ messageModel.setMessages([ { level: 'success', text: 'Type
updated' } ], false);
+ return result;
+ },
+ function(err) {
+ messageModel.setMessages(err.data.alerts, false);
+ throw err;
+ }
);
};
this.deleteType = function(id) {
- return Restangular.one("types", id).remove()
- .then(
- function() {
- messageModel.setMessages([ { level: 'success', text: 'Type
deleted' } ], true);
- },
- function(fault) {
- messageModel.setMessages(fault.data.alerts, true);
- }
+ return $http.delete(ENV.api['root'] + "types/" + id).then(
+ function(result) {
+ messageModel.setMessages([ { level: 'success', text: 'Type
deleted' } ], true);
+ return result;
+ },
+ function(err) {
+ messageModel.setMessages(err.data.alerts, true);
+ throw err;
+ }
);
};
};
-TypeService.$inject = ['Restangular', 'locationUtils', 'messageModel'];
+TypeService.$inject = ['$http', 'ENV', 'locationUtils', 'messageModel'];
module.exports = TypeService;