Mejoras: NER, embeddings, dashboard, docker-compose y limpieza

This commit is contained in:
jlimolina 2025-11-17 19:37:05 +01:00
parent 6c5aff9936
commit d508dc2058
19 changed files with 2218 additions and 1185 deletions

View file

@ -88,10 +88,16 @@ document.addEventListener('DOMContentLoaded', function() {
const form = document.getElementById('filter-form');
const continenteSelect = document.getElementById('continente_id');
const paisSelect = document.getElementById('pais_id');
const categoriaSelect = document.getElementById('categoria_id');
const fechaInput = document.getElementById('fecha');
const qInput = document.getElementById('q');
const pageInput = document.getElementById('page');
const origInput = document.getElementById('orig');
const langInput = document.getElementById('lang');
function setPage1() { pageInput.value = 1; }
function filtrarPaises() {
const continenteId = continenteSelect.value;
for (let i = 1; i < paisSelect.options.length; i++) {
@ -105,22 +111,14 @@ document.addEventListener('DOMContentLoaded', function() {
}
}
async function cargarNoticias(keepPage) {
if (!keepPage) pageInput.value = 1;
const formData = new FormData(form);
const params = new URLSearchParams(formData);
const newUrl = `${form.action}?${params.toString()}`;
async function cargarNoticiasFromURL(url) {
const container = document.getElementById('noticias-container');
container.style.opacity = '0.5';
container.innerHTML = '<div style="text-align:center; padding: 40px;"><i class="fas fa-spinner fa-spin fa-2x"></i></div>';
try {
const response = await fetch(newUrl, { headers: { 'X-Requested-With': 'XMLHttpRequest' } });
const response = await fetch(url, { headers: { 'X-Requested-With': 'XMLHttpRequest' } });
const html = await response.text();
container.innerHTML = html;
window.history.pushState({path: newUrl}, '', newUrl);
} catch (error) {
console.error('Error al filtrar noticias:', error);
container.innerHTML = '<p style="color:var(--error-color); text-align:center;">Error al cargar las noticias.</p>';
@ -129,11 +127,25 @@ document.addEventListener('DOMContentLoaded', function() {
}
}
async function cargarNoticias(keepPage) {
if (!keepPage) setPage1();
const formData = new FormData(form);
const params = new URLSearchParams(formData);
const newUrl = `${form.action}?${params.toString()}`;
await cargarNoticiasFromURL(newUrl);
// Actualizar historial
window.history.pushState({ path: newUrl }, '', newUrl);
}
// Submit manual
form.addEventListener('submit', function(e) {
e.preventDefault();
cargarNoticias(false);
});
// Toggle traducción/original
const toggleOrig = document.getElementById('toggle-orig');
const toggleTr = document.getElementById('toggle-tr');
@ -153,12 +165,38 @@ document.addEventListener('DOMContentLoaded', function() {
});
}
// Cambios en selects/fecha -> recarga automática
continenteSelect.addEventListener('change', function() {
filtrarPaises();
cargarNoticias(false);
});
paisSelect.addEventListener('change', function() {
cargarNoticias(false);
});
categoriaSelect.addEventListener('change', function() {
cargarNoticias(false);
});
fechaInput.addEventListener('change', function() {
cargarNoticias(false);
});
// Debounce búsqueda
let qTimer = null;
qInput.addEventListener('input', function() {
if (qTimer) clearTimeout(qTimer);
qTimer = setTimeout(() => {
cargarNoticias(false);
}, 450);
});
// Cargar países al inicio
filtrarPaises();
// Soporte de navegación del historial
window.addEventListener('popstate', function(e) {
const url = (e.state && e.state.path) ? e.state.path : window.location.href;
cargarNoticiasFromURL(url);
});
});
</script>
{% endblock %}