Fix discovery migration bugs

This commit is contained in:
Calvo 2023-10-09 16:52:52 +02:00
parent 62b52b901a
commit a822f6db86
3 changed files with 32 additions and 21 deletions

View File

@ -761,7 +761,7 @@ class DiscoveryTaskList extends HTML
$data[3] = __('Manual'); $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, '[…]'); $data[4] = ui_print_truncate_text($subnet, 50, true, true, true, '[…]');
} else { } else {
$data[4] = '-'; $data[4] = '-';

View File

@ -1256,13 +1256,17 @@ class ManageExtensions extends HTML
], ],
]; ];
$this->printForm( $spinner = '<div id="migration-spinner" class="invisible spinner-fixed"></div>';
$migration_form = $this->printForm(
[ [
'form' => $form, 'form' => $form,
'inputs' => $inputs, 'inputs' => $inputs,
], ],
false, true,
); );
echo $migration_form.$spinner;
} }

View File

@ -1,5 +1,15 @@
/* globals $, page, url, textsToTranslate, confirmDialog*/ /* globals $, page, url, textsToTranslate, confirmDialog*/
$(document).ready(function() { $(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) { $("#uploadExtension").submit(function(e) {
e.preventDefault(); e.preventDefault();
var formData = new FormData(this); var formData = new FormData(this);
@ -67,7 +77,6 @@ $(document).ready(function() {
function show_migration_form(shortName, hash) { function show_migration_form(shortName, hash) {
var title = textsToTranslate["Migrate"]; var title = textsToTranslate["Migrate"];
var method = "migrateApp"; var method = "migrateApp";
loading(true);
$("#migrate_modal").dialog({ $("#migrate_modal").dialog({
resizable: true, resizable: true,
@ -81,7 +90,6 @@ function show_migration_form(shortName, hash) {
closeOnEscape: false, closeOnEscape: false,
title: title, title: title,
open: function() { open: function() {
loading(false);
$("#migrate_modal").empty(); $("#migrate_modal").empty();
$.ajax({ $.ajax({
type: "POST", type: "POST",
@ -98,7 +106,7 @@ function show_migration_form(shortName, hash) {
$("#button-migrate").click(function() { $("#button-migrate").click(function() {
// All fields are required. // All fields are required.
loading(true); loadingMigration(true);
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: url, url: url,
@ -109,12 +117,11 @@ function show_migration_form(shortName, hash) {
shortName: shortName shortName: shortName
}, },
success: function(data) { success: function(data) {
loading(false); loadingMigration(false);
showMsg(data); showMsg(data, shortName);
$("input[name='button_migrate-" + shortName + "']").hide();
}, },
error: function(e) { error: function(e) {
loading(false); loadingMigration(false);
e.error = e.statusText; e.error = e.statusText;
showMsg(JSON.stringify(e)); showMsg(JSON.stringify(e));
} }
@ -137,7 +144,7 @@ function show_migration_form(shortName, hash) {
/** /**
* Process ajax responses and shows a dialog with results. * Process ajax responses and shows a dialog with results.
*/ */
function showMsg(data) { function showMsg(data, shortName) {
var title = textsToTranslate["migrationSuccess"]; var title = textsToTranslate["migrationSuccess"];
var text = ""; var text = "";
var failed = 0; var failed = 0;
@ -153,11 +160,9 @@ function showMsg(data) {
title = textsToTranslate["Error"]; title = textsToTranslate["Error"];
text = data["error"]; text = data["error"];
failed = 1; failed = 1;
} } else {
if (data["report"] != undefined) { $("input[name='button_migrate-" + shortName + "']").hide();
data["report"].forEach(function(item) { $("#migrate_modal").dialog("close");
text += "<br>" + item;
});
} }
$("#msg").empty(); $("#msg").empty();
@ -189,12 +194,14 @@ function showMsg(data) {
}); });
} }
function loading(status) { function loadingMigration(status) {
if (status) { if (status) {
$(".spinner-fixed").show(); $("#migration-spinner").show();
$("#button-upload_button").attr("disabled", "true"); $("#button-migrate").attr("disabled", "true");
$("#button-cancel").attr("disabled", "true");
} else { } else {
$(".spinner-fixed").hide(); $("#migration-spinner").hide();
$("#button-upload_button").removeAttr("disabled"); $("#button-migrate").removeAttr("disabled");
$("#button-cancel").removeAttr("disabled");
} }
} }