some fix on delete action 80/6380/1
authorlombardofr <lombardo@everyup.it>
Tue, 24 Jul 2018 12:38:16 +0000 (14:38 +0200)
committerlombardofr <lombardo@everyup.it>
Tue, 24 Jul 2018 12:38:16 +0000 (14:38 +0200)
Change-Id: I0cda12e120c92ded03bdd7c87c66aceb410ea927
Signed-off-by: lombardofr <lombardo@everyup.it>
instancehandler/views.py
lib/osm/osmclient/clientv2.py
sdnctrlhandler/views.py
static/src/instancehandler/instance_list.js
static/src/projecthandler/descriptorslist.js
static/src/sdnctrlhandler/sdn_list.js
vimhandler/template/vim_list.html
vimhandler/views.py

index 149b9c1..1a37f90 100644 (file)
@@ -132,8 +132,7 @@ def delete(request, instance_id=None, type=None):
     client = Client()
     result = client.ns_delete(user.get_token(), instance_id, force)
     print result
-    return __response_handler(request, result, 'instances:list', to_redirect=True, type='ns',
-                              )
+    return __response_handler(request, result, 'instances:list', to_redirect=True, type='ns')
 
 
 def show_topology(request, instance_id=None, type=None):
@@ -360,7 +359,7 @@ def create_alarm(request, instance_id=None, type=None):
 def __response_handler(request, data_res, url=None, to_redirect=None, *args, **kwargs):
     raw_content_types = request.META.get('HTTP_ACCEPT', '*/*').split(',')
     if 'application/json' in raw_content_types or url is None:
-        return HttpResponse(json.dumps(data_res), content_type="application/json", *args, **kwargs)
+        return HttpResponse(json.dumps(data_res), content_type="application/json")
     elif to_redirect:
         return redirect(url, *args, **kwargs)
     else:
index 47c8e67..feb710c 100644 (file)
@@ -1,3 +1,19 @@
+#
+#   Copyright 2018 EveryUP Srl
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an  BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+#
+
 import requests
 import logging
 import json
@@ -317,9 +333,10 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.ok:
+        if r:
             result['error'] = False
-        result['data'] = Util.json_loads_byteified(r.text)
+        if r.status_code != requests.codes.no_content:
+            result['data'] = Util.json_loads_byteified(r.text)
         return result
 
     def nsd_onboard(self, token, package):
@@ -646,9 +663,10 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.ok:
+        if r:
             result['error'] = False
-        result['data'] = Util.json_loads_byteified(r.text)
+        if r.status_code != requests.codes.no_content:
+            result['data'] = Util.json_loads_byteified(r.text)
         return result
 
     def ns_get(self, token, id):
index aa89a59..e015ded 100644 (file)
@@ -75,7 +75,7 @@ def delete(request, sdn_id=None):
         del_res = client.sdn_delete(user.get_token(), sdn_id)
     except Exception as e:
         log.exception(e)
-    return __response_handler(request, {}, 'sdns:list', to_redirect=True, )
+    return __response_handler(request, del_res, 'sdns:list', to_redirect=True, )
 
 
 @login_required
index eed9d96..c53c0b4 100644 (file)
@@ -37,9 +37,32 @@ function newAlarmNs(url) {
 function deleteNs(url, force) {
     bootbox.confirm("Are you sure want to delete?", function (result) {
         if (result) {
-            if(force)
+            if (force)
                 url = url + '?force=true';
-            location.href = url
+            var dialog = bootbox.dialog({
+                message: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Loading...</div>',
+                closeButton: true
+            });
+            $.ajax({
+                url: url,
+                type: 'GET',
+                dataType: "json",
+                contentType: "application/json;charset=utf-8",
+                success: function (result) {
+                    if (result['error'] == true){
+                        dialog.modal('hide');
+                        bootbox.alert("An error occurred.");
+                    }
+                    else {
+                        dialog.modal('hide');
+                        location.reload();
+                    }
+                },
+                error: function (error) {
+                    dialog.modal('hide');
+                    bootbox.alert("An error occurred.");
+                }
+            });
         }
     })
 }
@@ -77,13 +100,13 @@ function showInstanceDetails(url_info) {
         contentType: "application/json;charset=utf-8",
         success: function (result) {
 
-            if(result['data'] !== undefined) {
+            if (result['data'] !== undefined) {
                 editorJSON.setValue(JSON.stringify(result['data'], null, "\t"));
                 editorJSON.setOption("autoRefresh", true);
                 dialog.modal('hide');
                 $('#modal_show_instance').modal('show');
             }
-            else{
+            else {
                 dialog.modal('hide');
                 bootbox.alert("An error occurred while retrieving the information.");
             }
@@ -146,20 +169,20 @@ $(document).ready(function () {
             },
             contentType: false,
             processData: false
-        }).done(function (response,textStatus, jqXHR) {
+        }).done(function (response, textStatus, jqXHR) {
             $('#modal_instance_new_action').modal('hide');
             bootbox.alert({
-                    title: "Action",
-                    message: "Action received."
-                });
-        }).fail(function(result){
-            var data  = result.responseJSON;
-            var title = "Error " + (data.code ? data.code: 'unknown');
-                var message = data.detail ? data.detail: 'No detail available.';
-                bootbox.alert({
-                    title: title,
-                    message: message
-                });
+                title: "Action",
+                message: "Action received."
+            });
+        }).fail(function (result) {
+            var data = result.responseJSON;
+            var title = "Error " + (data.code ? data.code : 'unknown');
+            var message = data.detail ? data.detail : 'No detail available.';
+            bootbox.alert({
+                title: title,
+                message: message
+            });
         });
     });
 
@@ -178,20 +201,20 @@ $(document).ready(function () {
             },
             contentType: false,
             processData: false
-        }).done(function (response,textStatus, jqXHR) {
+        }).done(function (response, textStatus, jqXHR) {
             $('#modal_instance_new_action').modal('hide');
             bootbox.alert({
-                    title: "Metric",
-                    message: "Alarm created."
-                });
-        }).fail(function(result){
-            var data  = result.responseJSON;
-            var title = "Error " + (data.code ? data.code: 'unknown');
-                var message = data.detail ? data.detail: 'No detail available.';
-                bootbox.alert({
-                    title: title,
-                    message: message
-                });
+                title: "Metric",
+                message: "Alarm created."
+            });
+        }).fail(function (result) {
+            var data = result.responseJSON;
+            var title = "Error " + (data.code ? data.code : 'unknown');
+            var message = data.detail ? data.detail : 'No detail available.';
+            bootbox.alert({
+                title: title,
+                message: message
+            });
         });
     });
 
@@ -210,20 +233,20 @@ $(document).ready(function () {
             },
             contentType: false,
             processData: false
-        }).done(function (response,textStatus, jqXHR) {
+        }).done(function (response, textStatus, jqXHR) {
             $('#modal_instance_new_action').modal('hide');
             bootbox.alert({
-                    title: "Metric",
-                    message: "Metric exported."
-                });
-        }).fail(function(result){
-            var data  = result.responseJSON;
-            var title = "Error " + (data.code ? data.code: 'unknown');
-                var message = data.detail ? data.detail: 'No detail available.';
-                bootbox.alert({
-                    title: title,
-                    message: message
-                });
+                title: "Metric",
+                message: "Metric exported."
+            });
+        }).fail(function (result) {
+            var data = result.responseJSON;
+            var title = "Error " + (data.code ? data.code : 'unknown');
+            var message = data.detail ? data.detail : 'No detail available.';
+            bootbox.alert({
+                title: title,
+                message: message
+            });
         });
     });
 
index 7fe1966..d6ee937 100644 (file)
@@ -1,7 +1,25 @@
 function deletePackage(descriptor_type, package_id) {
+    var dialog = bootbox.dialog({
+        message: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Loading...</div>',
+        closeButton: true
+    });
     bootbox.confirm("Are you sure want to delete?", function (result) {
         if (result) {
-            location.href = '/projects/descriptors/' + descriptor_type + '/' + package_id + '/delete'
+
+            $.ajax({
+                url: '/projects/descriptors/' + descriptor_type + '/' + package_id + '/delete',
+                type: 'GET',
+                dataType: "json",
+                contentType: "application/json;charset=utf-8",
+                success: function (result) {
+                    dialog.modal('hide');
+                    location.reload();
+                },
+                error: function (result) {
+                    dialog.modal('hide');
+                    bootbox.alert("An error occurred.");
+                }
+            });
         }
     })
 }
index 9da94be..013cb6f 100644 (file)
@@ -1,7 +1,30 @@
 function deleteSDN(sdn_uuid) {
     bootbox.confirm("Are you sure want to delete?", function (result) {
         if (result) {
-            location.href = '/sdn/' + sdn_uuid + '/delete'
+            var dialog = bootbox.dialog({
+                message: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Loading...</div>',
+                closeButton: true
+            });
+            $.ajax({
+                url: '/sdn/' + sdn_uuid + '/delete',
+                type: 'GET',
+                dataType: "json",
+                contentType: "application/json;charset=utf-8",
+                success: function (result) {
+                    if (result['error'] == true){
+                        dialog.modal('hide');
+                        bootbox.alert("An error occurred.");
+                    }
+                    else {
+                        dialog.modal('hide');
+                        location.reload();
+                    }
+                },
+                error: function (error) {
+                    dialog.modal('hide');
+                    bootbox.alert("An error occurred.");
+                }
+            });
         }
     })
 }
@@ -14,7 +37,6 @@ function showSDN(sdn_uuid) {
 
     $.ajax({
         url: '/sdn/' + sdn_uuid ,
-        //url: '/sdn/' + sdn_uuid,
         type: 'GET',
         dataType: "json",
         contentType: "application/json;charset=utf-8",
index 6823c72..07cb857 100644 (file)
         function deleteVim(url) {
             bootbox.confirm("Are you sure want to delete?", function (result) {
                 if (result) {
-                    location.href = url//'/vims/' + vim_uuid + '/delete'
+                    var dialog = bootbox.dialog({
+                        message: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Loading...</div>',
+                        closeButton: true
+                    });
+                    $.ajax({
+                        url: url,
+                        type: 'GET',
+                        dataType: "json",
+                        contentType: "application/json;charset=utf-8",
+                        success: function (result) {
+                            if (result['error'] == true) {
+                                dialog.modal('hide');
+                                bootbox.alert("An error occurred.");
+                            }
+                            else {
+                                dialog.modal('hide');
+                                location.reload();
+                            }
+                        },
+                        error: function (error) {
+                            dialog.modal('hide');
+                            bootbox.alert("An error occurred.");
+                        }
+                    });
                 }
             })
         }
index d41ff82..c40e4e9 100644 (file)
@@ -86,7 +86,7 @@ def delete(request, vim_id=None):
         del_res = client.vim_delete(user.get_token(), vim_id)
     except Exception as e:
         log.exception(e)
-    return __response_handler(request, {}, 'vims:list', to_redirect=True, )
+    return __response_handler(request, del_res, 'vims:list', to_redirect=True, )
 
 @login_required
 def show(request, vim_id=None):