Boton de guardar funcionando

This commit is contained in:
Miguel 2025-02-09 13:16:26 +01:00
parent 7b369ba199
commit caa983c8da
2 changed files with 119 additions and 25 deletions

View File

@ -0,0 +1,62 @@
Iniciando ejecución de x1.py...
=== Ejecutando Script de Prueba 1 ===
Configuraciones cargadas:
Nivel 1: {
"api_key": "your-api-key-here",
"model": "gpt-3.5-turbo"
}
Nivel 2: {
"input_dir": "D:/Datos/Entrada",
"output_dir": "D:/Datos/Salida",
"batch_size": 50
}
Nivel 3: {
"campo_1739099176331": "",
"debug_mode": false,
"process_type": "basic",
"project_name": "Test2"
}
Simulando procesamiento...
Progreso: 20%
Progreso: 40%
Progreso: 60%
Progreso: 80%
Progreso: 100%
¡Proceso completado!
Ejecución completada.
Iniciando ejecución de x1.py...
=== Ejecutando Script de Prueba 1 ===
Configuraciones cargadas:
Nivel 1: {
"api_key": "your-api-key-here",
"model": "gpt-3.5-turbo"
}
Nivel 2: {
"input_dir": "D:/Datos/Entrada",
"output_dir": "D:/Datos/Salida",
"batch_size": 50
}
Nivel 3: {
"campo_1739099176331": "",
"debug_mode": true,
"process_type": "basic",
"project_name": "Test2"
}
Simulando procesamiento...
Progreso: 20%
Progreso: 40%
Progreso: 60%
Progreso: 80%
Progreso: 100%
¡Proceso completado!
Ejecución completada.

View File

@ -106,9 +106,17 @@
return;
}
const formHtml = generateFormFields(schema, data || {}, '', level);
console.log(`Generated HTML for ${containerId}:`, formHtml.substring(0, 100) + '...'); // Debug line
container.innerHTML = formHtml;
container.innerHTML = `
<form id="config-form-${level}" class="space-y-4">
${generateFormFields(schema, data || {}, '', level)}
</form>
<div class="flex justify-end mt-4">
<button onclick="saveConfig(${level})"
class="bg-green-500 text-white px-4 py-2 rounded">
Guardar Configuración
</button>
</div>
`;
} catch (error) {
console.error(`Error rendering form ${containerId}:`, error);
container.innerHTML = '<p class="text-red-500">Error cargando el esquema.</p>';
@ -792,24 +800,57 @@
// Agregar función para guardar configuración
async function saveConfig(level) {
try {
const data = collectFormData(level);
const form = document.getElementById(`config-form-${level}`);
const formData = {};
// Recolectar datos de todos los inputs en el formulario
form.querySelectorAll('input, select').forEach(input => {
const key = input.getAttribute('data-key');
if (!key) return;
let value;
if (input.type === 'checkbox') {
value = input.checked;
} else if (input.type === 'number') {
value = Number(input.value);
} else {
value = input.value;
}
// Manejar claves anidadas (por ejemplo: "parent.child")
const keys = key.split('.');
let current = formData;
for (let i = 0; i < keys.length - 1; i++) {
current[keys[i]] = current[keys[i]] || {};
current = current[keys[i]];
}
current[keys[keys.length - 1]] = value;
});
// Enviar datos al servidor
const response = await fetch(`/api/config/${level}?group=${currentGroup}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data)
body: JSON.stringify(formData)
});
if (!response.ok) throw new Error('Error al guardar la configuración');
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
// Mostrar mensaje de éxito
const result = await response.json();
if (result.status === 'success') {
alert('Configuración guardada correctamente');
// Recargar el formulario para mostrar los datos actualizados
const configResponse = await fetch(`/api/config/${level}?group=${currentGroup}`);
const updatedData = await configResponse.json();
await renderForm(`level${level}-form`, updatedData);
} else {
throw new Error(result.message || 'Error desconocido');
}
} catch (error) {
alert('Error: ' + error.message);
console.error('Error saving config:', error);
alert('Error guardando la configuración: ' + error.message);
}
}
</script>
@ -961,9 +1002,6 @@
<button class="bg-blue-500 text-white px-4 py-2 rounded" onclick="modifySchema(1)">
Modificar Esquema
</button>
<button class="bg-green-500 text-white px-4 py-2 rounded" onclick="saveConfig(1)">
Guardar Configuración
</button>
</div>
</div>
</div>
@ -983,9 +1021,6 @@
<button class="bg-blue-500 text-white px-4 py-2 rounded" onclick="modifySchema(2)">
Modificar Esquema
</button>
<button class="bg-green-500 text-white px-4 py-2 rounded" onclick="saveConfig(2)">
Guardar Configuración
</button>
</div>
</div>
</div>
@ -1047,9 +1082,6 @@
<button class="bg-blue-500 text-white px-4 py-2 rounded" onclick="modifySchema(3)">
Modificar Esquema
</button>
<button class="bg-green-500 text-white px-4 py-2 rounded" onclick="saveConfig(3)">
Guardar Configuración
</button>
</div>
</div>
</div>