From a822f6db86d32bd302188d23e2017833a6d7625e Mon Sep 17 00:00:00 2001 From: Calvo Date: Mon, 9 Oct 2023 16:52:52 +0200 Subject: [PATCH] Fix discovery migration bugs --- .../wizards/DiscoveryTaskList.class.php | 2 +- .../wizards/ManageExtensions.class.php | 8 +++- .../include/javascript/manage_extensions.js | 43 +++++++++++-------- 3 files changed, 32 insertions(+), 21 deletions(-) diff --git a/pandora_console/godmode/wizards/DiscoveryTaskList.class.php b/pandora_console/godmode/wizards/DiscoveryTaskList.class.php index 421e6e3dc8..796f3a56d9 100644 --- a/pandora_console/godmode/wizards/DiscoveryTaskList.class.php +++ b/pandora_console/godmode/wizards/DiscoveryTaskList.class.php @@ -761,7 +761,7 @@ class DiscoveryTaskList extends HTML $data[3] = __('Manual'); } - if ($task['id_recon_script'] == 0 || $ipam === true && $task['type'] !== 15) { + if ($task['id_recon_script'] == 0 || $ipam === true && $task['type'] !== '15') { $data[4] = ui_print_truncate_text($subnet, 50, true, true, true, '[…]'); } else { $data[4] = '-'; diff --git a/pandora_console/godmode/wizards/ManageExtensions.class.php b/pandora_console/godmode/wizards/ManageExtensions.class.php index 2f794c74da..91ba1926e5 100644 --- a/pandora_console/godmode/wizards/ManageExtensions.class.php +++ b/pandora_console/godmode/wizards/ManageExtensions.class.php @@ -1256,13 +1256,17 @@ class ManageExtensions extends HTML ], ]; - $this->printForm( + $spinner = ''; + + $migration_form = $this->printForm( [ 'form' => $form, 'inputs' => $inputs, ], - false, + true, ); + + echo $migration_form.$spinner; } diff --git a/pandora_console/include/javascript/manage_extensions.js b/pandora_console/include/javascript/manage_extensions.js index 3148c8a6d9..f9febd8f28 100644 --- a/pandora_console/include/javascript/manage_extensions.js +++ b/pandora_console/include/javascript/manage_extensions.js @@ -1,5 +1,15 @@ /* globals $, page, url, textsToTranslate, confirmDialog*/ $(document).ready(function() { + function loading(status) { + if (status) { + $(".spinner-fixed").show(); + $("#button-upload_button").attr("disabled", "true"); + } else { + $(".spinner-fixed").hide(); + $("#button-upload_button").removeAttr("disabled"); + } + } + $("#uploadExtension").submit(function(e) { e.preventDefault(); var formData = new FormData(this); @@ -67,7 +77,6 @@ $(document).ready(function() { function show_migration_form(shortName, hash) { var title = textsToTranslate["Migrate"]; var method = "migrateApp"; - loading(true); $("#migrate_modal").dialog({ resizable: true, @@ -81,7 +90,6 @@ function show_migration_form(shortName, hash) { closeOnEscape: false, title: title, open: function() { - loading(false); $("#migrate_modal").empty(); $.ajax({ type: "POST", @@ -98,7 +106,7 @@ function show_migration_form(shortName, hash) { $("#button-migrate").click(function() { // All fields are required. - loading(true); + loadingMigration(true); $.ajax({ type: "POST", url: url, @@ -109,12 +117,11 @@ function show_migration_form(shortName, hash) { shortName: shortName }, success: function(data) { - loading(false); - showMsg(data); - $("input[name='button_migrate-" + shortName + "']").hide(); + loadingMigration(false); + showMsg(data, shortName); }, error: function(e) { - loading(false); + loadingMigration(false); e.error = e.statusText; showMsg(JSON.stringify(e)); } @@ -137,7 +144,7 @@ function show_migration_form(shortName, hash) { /** * Process ajax responses and shows a dialog with results. */ -function showMsg(data) { +function showMsg(data, shortName) { var title = textsToTranslate["migrationSuccess"]; var text = ""; var failed = 0; @@ -153,11 +160,9 @@ function showMsg(data) { title = textsToTranslate["Error"]; text = data["error"]; failed = 1; - } - if (data["report"] != undefined) { - data["report"].forEach(function(item) { - text += "
" + item; - }); + } else { + $("input[name='button_migrate-" + shortName + "']").hide(); + $("#migrate_modal").dialog("close"); } $("#msg").empty(); @@ -189,12 +194,14 @@ function showMsg(data) { }); } -function loading(status) { +function loadingMigration(status) { if (status) { - $(".spinner-fixed").show(); - $("#button-upload_button").attr("disabled", "true"); + $("#migration-spinner").show(); + $("#button-migrate").attr("disabled", "true"); + $("#button-cancel").attr("disabled", "true"); } else { - $(".spinner-fixed").hide(); - $("#button-upload_button").removeAttr("disabled"); + $("#migration-spinner").hide(); + $("#button-migrate").removeAttr("disabled"); + $("#button-cancel").removeAttr("disabled"); } }