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');
}
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] = '-';

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,
'inputs' => $inputs,
],
false,
true,
);
echo $migration_form.$spinner;
}

View File

@ -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 += "<br>" + 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");
}
}