From c6a6ba976e655f181c2b8a35920cae429b381c26 Mon Sep 17 00:00:00 2001 From: ronalds Date: Tue, 2 Dec 2025 17:22:55 -0300 Subject: [PATCH] =?UTF-8?q?Versiones=20actualizadas:=20Frontend:=201.0.96?= =?UTF-8?q?=20=E2=86=92=201.0.97=20Service=20Worker:=201.0.96=20=E2=86=92?= =?UTF-8?q?=201.0.97=20Backend:=201.0.92=20(sin=20cambios)=20Resultado:=20?= =?UTF-8?q?=E2=9C=85=20Las=20preguntas=20padre=20se=20mueven=20CON=20todos?= =?UTF-8?q?=20sus=20hijos=20=E2=9C=85=20Los=20hijos=20mantienen=20su=20ord?= =?UTF-8?q?en=20relativo=20al=20padre=20=E2=9C=85=20No=20hay=20conflictos?= =?UTF-8?q?=20de=20orden=20entre=20preguntas=20=E2=9C=85=20El=20sistema=20?= =?UTF-8?q?usa=20espaciado=20inteligente=20(0,=2010,=2020...)=20para=20evi?= =?UTF-8?q?tar=20colisiones=20=E2=9C=85=20Las=20subpreguntas=20solo=20se?= =?UTF-8?q?=20mueven=20dentro=20de=20su=20padre?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/package.json | 2 +- frontend/public/service-worker.js | 2 +- frontend/src/App.jsx | 95 +++++++++++++++++++++++-------- 3 files changed, 72 insertions(+), 27 deletions(-) diff --git a/frontend/package.json b/frontend/package.json index 882e45f..d22c7e2 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,7 +1,7 @@ { "name": "checklist-frontend", "private": true, - "version": "1.0.96", + "version": "1.0.97", "type": "module", "scripts": { "dev": "vite", diff --git a/frontend/public/service-worker.js b/frontend/public/service-worker.js index 08d0557..2fdde6f 100644 --- a/frontend/public/service-worker.js +++ b/frontend/public/service-worker.js @@ -1,6 +1,6 @@ // Service Worker para PWA con detección de actualizaciones // IMPORTANTE: Actualizar esta versión cada vez que se despliegue una nueva versión -const CACHE_NAME = 'ayutec-v1.0.96'; +const CACHE_NAME = 'ayutec-v1.0.97'; const urlsToCache = [ '/', '/index.html' diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index 646e8be..0fef5be 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -1458,34 +1458,79 @@ function QuestionsManagerModal({ checklist, onClose }) { return } - // Filtrar solo las preguntas del mismo nivel/grupo - let questionsList - if (draggedIsChild) { - // Solo subpreguntas del mismo padre - questionsList = questions.filter(q => - q.parent_question_id === draggedQuestion.parent_question_id - ).sort((a, b) => a.order - b.order) // Ordenar por order actual + // Preparar datos para el backend + let reorderData = [] + + if (!draggedIsChild) { + // CASO 1: Mover pregunta padre (con sus hijos) + + // Obtener todas las preguntas padre ordenadas + const parentQuestions = questions.filter(q => !q.parent_question_id) + .sort((a, b) => a.order - b.order) + + const draggedIdx = parentQuestions.findIndex(q => q.id === draggedQuestion.id) + const targetIdx = parentQuestions.findIndex(q => q.id === targetQuestion.id) + + // Reordenar la lista de padres + const reorderedParents = [...parentQuestions] + const [movedParent] = reorderedParents.splice(draggedIdx, 1) + reorderedParents.splice(targetIdx, 0, movedParent) + + // Asignar nuevos valores de order espaciados (cada padre tiene +100, hijos usan +1, +2, +3...) + let currentOrder = 0 + + reorderedParents.forEach(parent => { + // Asignar order al padre + reorderData.push({ + question_id: parent.id, + new_order: currentOrder + }) + + currentOrder += 1 + + // Obtener y ordenar los hijos de este padre + const children = questions.filter(q => q.parent_question_id === parent.id) + .sort((a, b) => a.order - b.order) + + // Asignar order a cada hijo + children.forEach(child => { + reorderData.push({ + question_id: child.id, + new_order: currentOrder + }) + currentOrder += 1 + }) + + // Dejar espacio para el siguiente padre (saltar a siguiente decena) + currentOrder = Math.ceil(currentOrder / 10) * 10 + }) + } else { - // Solo preguntas padre (sin parent_question_id) - questionsList = questions.filter(q => !q.parent_question_id) - .sort((a, b) => a.order - b.order) // Ordenar por order actual + // CASO 2: Mover subpregunta (solo dentro del mismo padre) + + const parentId = draggedQuestion.parent_question_id + const siblings = questions.filter(q => q.parent_question_id === parentId) + .sort((a, b) => a.order - b.order) + + const draggedIdx = siblings.findIndex(q => q.id === draggedQuestion.id) + const targetIdx = siblings.findIndex(q => q.id === targetQuestion.id) + + // Reordenar hermanos + const reorderedSiblings = [...siblings] + const [movedChild] = reorderedSiblings.splice(draggedIdx, 1) + reorderedSiblings.splice(targetIdx, 0, movedChild) + + // Mantener el order base del primer hermano y solo incrementar + const baseOrder = Math.min(...siblings.map(s => s.order)) + + reorderedSiblings.forEach((child, index) => { + reorderData.push({ + question_id: child.id, + new_order: baseOrder + index + }) + }) } - const draggedIndex = questionsList.findIndex(q => q.id === draggedQuestion.id) - const targetIndex = questionsList.findIndex(q => q.id === targetQuestion.id) - - // Crear nueva lista con el orden actualizado - const newList = [...questionsList] - const [movedQuestion] = newList.splice(draggedIndex, 1) - newList.splice(targetIndex, 0, movedQuestion) - - // Preparar datos para el backend usando los valores de 'order' originales - // Esto mantiene el orden relativo correcto con respecto a otras preguntas - const reorderData = newList.map((q, index) => ({ - question_id: q.id, - new_order: questionsList[index].order // Usar el order de la posición correspondiente - })) - try { const token = localStorage.getItem('token') const API_URL = import.meta.env.VITE_API_URL || ''