From caa983c8daeccaeadf837dcc8c9fe3ee008d2389 Mon Sep 17 00:00:00 2001 From: Miguel Date: Sun, 9 Feb 2025 13:16:26 +0100 Subject: [PATCH] Boton de guardar funcionando --- data/log.txt | 62 +++++++++++++++++++++++++++++++++ templates/index.html | 82 ++++++++++++++++++++++++++++++-------------- 2 files changed, 119 insertions(+), 25 deletions(-) diff --git a/data/log.txt b/data/log.txt index e69de29..2fdfa8f 100644 --- a/data/log.txt +++ b/data/log.txt @@ -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. diff --git a/templates/index.html b/templates/index.html index 1ce5f8d..9195dbf 100644 --- a/templates/index.html +++ b/templates/index.html @@ -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 = ` +
+ ${generateFormFields(schema, data || {}, '', level)} +
+
+ +
+ `; } catch (error) { console.error(`Error rendering form ${containerId}:`, error); container.innerHTML = '

Error cargando el esquema.

'; @@ -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'); - - // Mostrar mensaje de éxito - 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); + + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + + 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); } } @@ -961,9 +1002,6 @@ - @@ -983,9 +1021,6 @@ - @@ -1047,9 +1082,6 @@ -