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 2018/08/13 17:11:26 UTC

[trafficcontrol] 07/12: changed Restangular to use

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

commit a820545c5cd8e6b984bda64d5e229ea7b9aa16c4
Author: Jesse Rivas <je...@comcast.com>
AuthorDate: Tue Jul 31 14:58:08 2018 -0600

    changed Restangular to use
    
    WIP
---
 .../app/src/common/api/StaticDnsEntryService.js    | 33 ++++++++++++++++------
 ...mEditDeliveryServiceStaticDnsEntryController.js |  6 ++--
 .../form.deliveryServiceStaticDnsEntry.tpl.html    |  2 +-
 .../staticDnsEntries/edit/index.js                 |  2 +-
 4 files changed, 29 insertions(+), 14 deletions(-)

diff --git a/traffic_portal/app/src/common/api/StaticDnsEntryService.js b/traffic_portal/app/src/common/api/StaticDnsEntryService.js
index 4382538..afe96f7 100644
--- a/traffic_portal/app/src/common/api/StaticDnsEntryService.js
+++ b/traffic_portal/app/src/common/api/StaticDnsEntryService.js
@@ -23,29 +23,44 @@ var StaticDnsEntryService = function($http, $q, Restangular, locationUtils, mess
 		return Restangular.all('staticdnsentries').getList(queryParams);
 	};
 
+	this.getStaticDnsEntry = function(id) {
+        return Restangular.one('staticdnsentries?id=' + id).get();
+    };
+
     this.createDeliveryServiceStaticDnsEntry = function(staticDnsEntry) {
-        return Restangular.service('staticdnsentries').post(staticDnsEntry)
+        var request = $q.defer();
+
+        $http.post(ENV.api['root'] + "staticdnsentries", staticDnsEntry)
             .then(
-                function() {
-                    messageModel.setMessages([ { level: 'success', text: 'Static DNS Entry created' } ], true);
+                function(response) {
+                    messageModel.setMessages(response.data.alerts, true);
                     locationUtils.navigateToPath('/delivery-services/' + staticDnsEntry.deliveryServiceId + '/static-dns-entries');
+                    request.resolve(response);
                 },
                 function(fault) {
-                    messageModel.setMessages(fault.data.alerts, false);
+                    messageModel.setMessages(fault.data.alerts, false)
+                    request.reject(fault);
                 }
             );
+
+        return request.promise;
     };
 
-    this.deleteDeliveryServiceStaticDnsEntry = function(queryParams) {
-        return Restangular.all('staticdnsentries').remove(queryParams)
+    this.deleteDeliveryServiceStaticDnsEntry = function(id) {
+        var deferred = $q.defer();
+
+        $http.delete(ENV.api['root'] + "staticdnsentries?id=" + id)
             .then(
-                function() {
-                    messageModel.setMessages([ { level: 'success', text: 'Static DNS Entry deleted' } ], true);
+                function(response) {
+                    messageModel.setMessages(response.data.alerts, true);
+                    deferred.resolve(response);
                 },
                 function(fault) {
-                    messageModel.setMessages(fault.data.alerts, true);
+                    messageModel.setMessages(fault.data.alerts, false);
+                    deferred.reject(fault);
                 }
             );
+        return deferred.promise;
     };
 
     this.updateDeliveryServiceStaticDnsEntry = function(id, staticDnsEntry) {
diff --git a/traffic_portal/app/src/common/modules/form/deliveryServiceStaticDnsEntry/edit/FormEditDeliveryServiceStaticDnsEntryController.js b/traffic_portal/app/src/common/modules/form/deliveryServiceStaticDnsEntry/edit/FormEditDeliveryServiceStaticDnsEntryController.js
index 5a5a4d1..15aa49a 100644
--- a/traffic_portal/app/src/common/modules/form/deliveryServiceStaticDnsEntry/edit/FormEditDeliveryServiceStaticDnsEntryController.js
+++ b/traffic_portal/app/src/common/modules/form/deliveryServiceStaticDnsEntry/edit/FormEditDeliveryServiceStaticDnsEntryController.js
@@ -23,13 +23,13 @@ var FormEditDeliveryServiceStaticDnsEntryController = function(deliveryService,
     angular.extend(this, $controller('FormDeliveryServiceStaticDnsEntryController', { deliveryService: deliveryService, staticDnsEntry: staticDnsEntry, $scope: $scope }));
 
     var deleteDeliveryServiceStaticDnsEntry = function(dsId, staticDnsEntryId) {
-        staticDnsEntryService.deleteDeliveryServiceStaticDnsEntry({ id: staticDnsEntryId })
+        staticDnsEntryService.deleteDeliveryServiceStaticDnsEntry(staticDnsEntryId)
             .then(function() {
                 locationUtils.navigateToPath('/delivery-services/' + dsId + '/static-dns-entries');
             });
     };
 
-    $scope.staticDnsEntry = staticDnsEntry[0];
+    $scope.staticDnsEntry = staticDnsEntry;
     $scope.host = angular.copy($scope.staticDnsEntry.host);
 
     $scope.settings = {
@@ -47,7 +47,7 @@ var FormEditDeliveryServiceStaticDnsEntryController = function(deliveryService,
 
     $scope.confirmDelete = function(staticDnsEntry) {
         var params = {
-            title: 'Delete Delivery Service StaticDnsEntry on host: ' + staticDnsEntry.host + ' with address: ' + staticDnsEntry.address,
+            title: 'Delete Delivery Service Static DNS Entry on host: ' + staticDnsEntry.host + ' with address: ' + staticDnsEntry.address,
             key: staticDnsEntry.host
         };
         var modalInstance = $uibModal.open({
diff --git a/traffic_portal/app/src/common/modules/form/deliveryServiceStaticDnsEntry/form.deliveryServiceStaticDnsEntry.tpl.html b/traffic_portal/app/src/common/modules/form/deliveryServiceStaticDnsEntry/form.deliveryServiceStaticDnsEntry.tpl.html
index 0f980a8..2542542 100644
--- a/traffic_portal/app/src/common/modules/form/deliveryServiceStaticDnsEntry/form.deliveryServiceStaticDnsEntry.tpl.html
+++ b/traffic_portal/app/src/common/modules/form/deliveryServiceStaticDnsEntry/form.deliveryServiceStaticDnsEntry.tpl.html
@@ -48,7 +48,7 @@ under the License.
                 </div>
             </div>
             <div class="form-group" ng-class="{'has-error': hasError(dsStaticDnsEntryForm.cachegroup), 'has-feedback': hasError(dsStaticDnsEntryForm.cachegroup)}">
-                <label class="control-label col-md-2 col-sm-2 col-xs-12">Cache Group</label>
+                <label class="control-label col-md-2 col-sm-2 col-xs-12">Cache Group *</label>
                 <div class="col-md-10 col-sm-10 col-xs-12">
                     <select name="cachegroup" class="form-control" ng-model="staticDnsEntry.cachegroupId" ng-options="cachegroup.id as cachegroup.name for cachegroup in cacheGroups" required>
                         <option value="">Select...</option>
diff --git a/traffic_portal/app/src/modules/private/deliveryServices/staticDnsEntries/edit/index.js b/traffic_portal/app/src/modules/private/deliveryServices/staticDnsEntries/edit/index.js
index 62bf5d5..906342b 100644
--- a/traffic_portal/app/src/modules/private/deliveryServices/staticDnsEntries/edit/index.js
+++ b/traffic_portal/app/src/modules/private/deliveryServices/staticDnsEntries/edit/index.js
@@ -31,7 +31,7 @@ module.exports = angular.module('trafficPortal.private.deliveryServices.staticDn
 								return deliveryServiceService.getDeliveryService($stateParams.deliveryServiceId);
 							},
 							staticDnsEntry: function($stateParams, staticDnsEntryService) {
-								return staticDnsEntryService.getStaticDnsEntries({ deliveryserviceId: $stateParams.deliveryServiceId, id: $stateParams.staticDnsEntryId });
+								return staticDnsEntryService.getStaticDnsEntry($stateParams.staticDnsEntryId);
 							}
 						}
 					}