From 25e90e7e2880b1a56f1517af28148ca4637b04da Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Thu, 18 Jun 2026 10:54:19 -0500 Subject: [PATCH] Fix: auto-trigger hints while typing --- app/templates/queries.html | 853 +++++++++++++++++++------------------ 1 file changed, 427 insertions(+), 426 deletions(-) diff --git a/app/templates/queries.html b/app/templates/queries.html index b392061..6cc7236 100644 --- a/app/templates/queries.html +++ b/app/templates/queries.html @@ -1,385 +1,385 @@ -{% extends "base.html" %} -{% block title %}Consultas SQL{% endblock %} -{% block header %}Consultas SQL{% endblock %} -{% block content %} - -
- - -
- -
-
-
-
-
-

Mis Consultas

- -
-
- {% for q in queries %} -
-
-
- {{ q.name }} - {{ q.query_type }} -
-

{{ q.description or 'Sin descripción' }}

-
- -
- {% endfor %} -
-
-
- -
-
-
-

Editor SQL

-
-
-
- -
-
- - -
-
- - -
-
-
- - -
-
-
- - -
-
- - -
-
-
-
- -
-

Parámetros disponibles

-

- Usa :doc_num para filtro por documento, - :factura para filtro por factura, - :fecha_ini y :fecha_fin para rango de fechas. -

- - -
-
-
-
- - - - -{% endblock %} +} + +document.addEventListener('DOMContentLoaded', function() { + document.querySelector('form').addEventListener('submit', function() { + document.getElementById('q_text').value = sqlEditor ? sqlEditor.getValue() : document.getElementById('q_text').value; + }); + initSqlEditor(); +}); + +async function ejecutarTest(btn, queryId) { + btn.disabled = true; btn.innerHTML = ' Probando...'; + try { + const form = new FormData(); form.append('query_id', queryId); + const resp = await fetch('/queries/test', { method: 'POST', body: form }); + const data = await resp.json(); + if (data.error) { showToast(data.error, 'error'); return; } + let html = ''; + data.columns.forEach(c => { html += ''; }); + html += ''; + data.rows.forEach(r => { + html += ''; + data.columns.forEach(c => { html += ''; }); + html += ''; + }); + html += '
' + c + '
' + (r[c] ?? '') + '
'; + html += '

Total: ' + data.total + ' registros (mostrando ' + data.rows.length + ')

'; + const modal = document.createElement('div'); + modal.className = 'fixed inset-0 z-50 flex items-center justify-center bg-black bg-opacity-50'; + modal.innerHTML = '

Resultado

' + html + '
'; + document.body.appendChild(modal); + } catch(e) { showToast('Error: ' + e.message, 'error'); } + finally { btn.disabled = false; btn.innerHTML = ' Probar'; } +} + +{% endblock %}