From 00422f24cdcd4e90339e19eed399d0e44f9bded4 Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 18 Aug 2021 18:50:53 -0400 Subject: [PATCH] Moved delete server to ajax call instead of a task. --- app/classes/shared/tasks.py | 10 ------ app/classes/web/ajax_handler.py | 12 +++++++ .../templates/panel/server_config.html | 33 +++++++++++++++++-- 3 files changed, 43 insertions(+), 12 deletions(-) diff --git a/app/classes/shared/tasks.py b/app/classes/shared/tasks.py index 572918db..91d8ff0b 100644 --- a/app/classes/shared/tasks.py +++ b/app/classes/shared/tasks.py @@ -113,16 +113,6 @@ class TasksManager: elif command == "update_executable": svr.jar_update() - elif command == "delete_server": - logger.info( - "Removing server from panel for server: {}".format(c['server_id']['server_name'])) - self.controller.remove_server(c['server_id']['server_id'], False) - - elif command == "delete_server_files": - logger.info( - "Removing server and all associated files for server: {}".format(c['server_id']['server_name'])) - self.controller.remove_server(c['server_id']['server_id'], True) - db_helper.mark_command_complete(c.get('command_id', None)) time.sleep(1) diff --git a/app/classes/web/ajax_handler.py b/app/classes/web/ajax_handler.py index bca9397e..c84983ad 100644 --- a/app/classes/web/ajax_handler.py +++ b/app/classes/web/ajax_handler.py @@ -229,6 +229,18 @@ class AjaxHandler(BaseHandler): # os.rmdir(dir_path) # Would only remove empty directories shutil.rmtree(dir_path) # Removes also when there are contents + elif page == "delete_server": + server_id = self.get_argument('id', None) + logger.info( + "Removing server from panel for server: {}".format(db_helper.get_server_friendly_name(server_id))) + self.controller.remove_server(server_id, False) + + elif page == "delete_server_files": + server_id = self.get_argument('id', None) + logger.info( + "Removing server and all associated files for server: {}".format(db_helper.get_server_friendly_name(server_id))) + self.controller.remove_server(server_id, True) + @tornado.web.authenticated def put(self, page): if page == "save_file": diff --git a/app/frontend/templates/panel/server_config.html b/app/frontend/templates/panel/server_config.html index 501e4d96..a4195bc7 100644 --- a/app/frontend/templates/panel/server_config.html +++ b/app/frontend/templates/panel/server_config.html @@ -203,6 +203,35 @@ }); + function deleteServerE(callback) { + var token = getCookie("_xsrf") + $.ajax({ + type: "DELETE", + headers: {'X-XSRFToken': token}, + url: '/ajax/delete_server?id={{ data['server_stats']['server_id']['server_id'] }}', + data: { + }, + success: function(data){ + console.log("got response:"); + console.log(data); + }, + }); + } + function deleteServerFilesE(path, callback) { + var token = getCookie("_xsrf") + $.ajax({ + type: "DELETE", + headers: {'X-XSRFToken': token}, + url: '/ajax/delete_server_files?id={{ data['server_stats']['server_id']['server_id'] }}', + data: { + }, + success: function(data){ + console.log("got response:"); + console.log(data); + }, + }); + } + let server_id = '{{ data['server_stats']['server_id']['server_id'] }}'; function send_command (server_id, command){ @@ -249,7 +278,7 @@ let server_id = '{{ data['server_stats']['server_id']['server_id'] }}'; }, callback: function(result) { if (!result){ - send_command(server_id, 'delete_server'); + deleteServerE() setTimeout(function(){ window.location = '/panel/dashboard'; }, 5000); bootbox.dialog({ backdrop: true, @@ -260,7 +289,7 @@ let server_id = '{{ data['server_stats']['server_id']['server_id'] }}'; return;} else{ - send_command(server_id, 'delete_server_files'); + deleteServerFilesE(); setTimeout(function(){ window.location = '/panel/dashboard'; }, 5000); bootbox.dialog({ backdrop: true,