From: lombardofr Date: Tue, 24 Jul 2018 12:38:16 +0000 (+0200) Subject: some fix on delete action X-Git-Tag: BUILD_v4.0.1_1~2 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=c9488202684cfc523815b2629239c285efef1253;p=osm%2FLW-UI.git some fix on delete action Change-Id: I0cda12e120c92ded03bdd7c87c66aceb410ea927 Signed-off-by: lombardofr --- diff --git a/instancehandler/views.py b/instancehandler/views.py index 149b9c1..1a37f90 100644 --- a/instancehandler/views.py +++ b/instancehandler/views.py @@ -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: diff --git a/lib/osm/osmclient/clientv2.py b/lib/osm/osmclient/clientv2.py index 47c8e67..feb710c 100644 --- a/lib/osm/osmclient/clientv2.py +++ b/lib/osm/osmclient/clientv2.py @@ -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): diff --git a/sdnctrlhandler/views.py b/sdnctrlhandler/views.py index aa89a59..e015ded 100644 --- a/sdnctrlhandler/views.py +++ b/sdnctrlhandler/views.py @@ -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 diff --git a/static/src/instancehandler/instance_list.js b/static/src/instancehandler/instance_list.js index eed9d96..c53c0b4 100644 --- a/static/src/instancehandler/instance_list.js +++ b/static/src/instancehandler/instance_list.js @@ -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: '
Loading...
', + 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 + }); }); }); diff --git a/static/src/projecthandler/descriptorslist.js b/static/src/projecthandler/descriptorslist.js index 7fe1966..d6ee937 100644 --- a/static/src/projecthandler/descriptorslist.js +++ b/static/src/projecthandler/descriptorslist.js @@ -1,7 +1,25 @@ function deletePackage(descriptor_type, package_id) { + var dialog = bootbox.dialog({ + message: '
Loading...
', + 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."); + } + }); } }) } diff --git a/static/src/sdnctrlhandler/sdn_list.js b/static/src/sdnctrlhandler/sdn_list.js index 9da94be..013cb6f 100644 --- a/static/src/sdnctrlhandler/sdn_list.js +++ b/static/src/sdnctrlhandler/sdn_list.js @@ -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: '
Loading...
', + 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", diff --git a/vimhandler/template/vim_list.html b/vimhandler/template/vim_list.html index 6823c72..07cb857 100644 --- a/vimhandler/template/vim_list.html +++ b/vimhandler/template/vim_list.html @@ -96,7 +96,30 @@ 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: '
Loading...
', + 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."); + } + }); } }) } diff --git a/vimhandler/views.py b/vimhandler/views.py index d41ff82..c40e4e9 100644 --- a/vimhandler/views.py +++ b/vimhandler/views.py @@ -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):