back 1.0.38 y front 1.0.39 cambios en condicionales de sub preguntas, solo boleanos

This commit is contained in:
2025-11-25 22:43:14 -03:00
parent 1ef07ad2c5
commit 4c8938a24e
4 changed files with 147 additions and 138 deletions

View File

@@ -1062,12 +1062,12 @@ def create_answer(
if not question:
raise HTTPException(status_code=404, detail="Pregunta no encontrada")
# Calcular puntos según status
# Sistema simplificado: 1 punto por pregunta correcta
points_earned = 0
if answer.status == "ok":
points_earned = question.points
points_earned = 1
elif answer.status == "warning":
points_earned = int(question.points * 0.5)
points_earned = 0.5
# Buscar si ya existe una respuesta para esta inspección y pregunta
existing_answer = db.query(models.Answer).filter(

View File

@@ -1130,107 +1130,127 @@ function QuestionsManagerModal({ checklist, onClose }) {
<h4 className="text-sm font-semibold text-blue-900 mb-3">
Pregunta Condicional - Subpreguntas Anidadas (hasta 5 niveles)
</h4>
<div className="grid grid-cols-2 gap-4">
<div>
<label className="block text-sm font-medium text-gray-700 mb-1">
Pregunta padre
</label>
<select
value={formData.parent_question_id || ''}
onChange={(e) => setFormData({
...formData,
parent_question_id: e.target.value ? parseInt(e.target.value) : null,
show_if_answer: '' // Reset al cambiar padre
})}
className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-purple-500 bg-white"
>
<option value="">Ninguna (pregunta principal)</option>
{questions
.filter(q => {
// Permitir cualquier pregunta que no sea esta misma
// y que tenga depth_level < 5 (para no exceder límite)
const depth = q.depth_level || 0
return depth < 5
})
.map(q => {
const depth = q.depth_level || 0
const indent = ' '.repeat(depth)
const levelLabel = depth > 0 ? ` [Nivel ${depth}]` : ''
return (
<option key={q.id} value={q.id}>
{indent}#{q.id} - {q.text.substring(0, 40)}{q.text.length > 40 ? '...' : ''}{levelLabel}
</option>
)
})
}
</select>
<p className="text-xs text-gray-500 mt-1">
Esta pregunta aparecerá solo si se cumple la condición de la pregunta padre
</p>
</div>
<div>
<label className="block text-sm font-medium text-gray-700 mb-1">
Mostrar si la respuesta es:
</label>
<select
value={formData.show_if_answer}
onChange={(e) => setFormData({ ...formData, show_if_answer: e.target.value })}
className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-purple-500 bg-white"
disabled={!formData.parent_question_id}
>
<option value="">Seleccione...</option>
{formData.parent_question_id && (() => {
const parentQ = questions.find(q => q.id === formData.parent_question_id)
if (!parentQ) return null
// Leer opciones del nuevo formato
const config = parentQ.options || {}
const parentType = config.type || parentQ.type
// Para boolean o single_choice, mostrar las opciones configuradas
if ((parentType === 'boolean' || parentType === 'single_choice') && config.choices) {
return config.choices.map((choice, idx) => (
<option key={idx} value={choice.value}>
{choice.label}
</option>
))
}
// Compatibilidad con tipos antiguos
if (parentType === 'pass_fail') {
return [
<option key="pass" value="pass"> Pasa</option>,
<option key="fail" value="fail"> Falla</option>
]
} else if (parentType === 'good_bad') {
return [
<option key="good" value="good"> Bueno</option>,
<option key="bad" value="bad"> Malo</option>
]
}
return <option disabled>Tipo de pregunta no compatible</option>
})()}
</select>
<p className="text-xs text-gray-500 mt-1">
La pregunta solo se mostrará con esta respuesta específica
</p>
</div>
</div>
{/* Indicador de profundidad */}
{formData.parent_question_id && (() => {
const parentQ = questions.find(q => q.id === formData.parent_question_id)
const parentDepth = parentQ?.depth_level || 0
const newDepth = parentDepth + 1
{/* Solo permitir condicionales para boolean y single_choice */}
{(() => {
const currentType = formData.options?.type || formData.type
const allowConditional = ['boolean', 'single_choice'].includes(currentType)
if (!allowConditional) {
return (
<div className="p-3 bg-gray-50 rounded-lg border border-gray-200">
<p className="text-sm text-gray-600">
Las preguntas condicionales solo están disponibles para tipos <strong>Boolean</strong> y <strong>Opción Única</strong>
</p>
</div>
)
}
return (
<div className={`mt-3 p-2 rounded ${newDepth >= 5 ? 'bg-red-50 border border-red-200' : 'bg-blue-100'}`}>
<p className="text-xs">
📊 <strong>Profundidad:</strong> Nivel {newDepth} de 5 máximo
{newDepth >= 5 && ' ⚠️ Máximo alcanzado'}
</p>
</div>
<>
<div className="grid grid-cols-2 gap-4">
<div>
<label className="block text-sm font-medium text-gray-700 mb-1">
Pregunta padre
</label>
<select
value={formData.parent_question_id || ''}
onChange={(e) => setFormData({
...formData,
parent_question_id: e.target.value ? parseInt(e.target.value) : null,
show_if_answer: '' // Reset al cambiar padre
})}
className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-purple-500 bg-white"
>
<option value="">Ninguna (pregunta principal)</option>
{questions
.filter(q => {
// Permitir cualquier pregunta que no sea esta misma
// y que tenga depth_level < 5 (para no exceder límite)
const depth = q.depth_level || 0
return depth < 5
})
.map(q => {
const depth = q.depth_level || 0
const indent = ' '.repeat(depth)
const levelLabel = depth > 0 ? ` [Nivel ${depth}]` : ''
return (
<option key={q.id} value={q.id}>
{indent}#{q.id} - {q.text.substring(0, 40)}{q.text.length > 40 ? '...' : ''}{levelLabel}
</option>
)
})
}
</select>
<p className="text-xs text-gray-500 mt-1">
Esta pregunta aparecerá solo si se cumple la condición de la pregunta padre
</p>
</div>
<div>
<label className="block text-sm font-medium text-gray-700 mb-1">
Mostrar si la respuesta es:
</label>
<select
value={formData.show_if_answer}
onChange={(e) => setFormData({ ...formData, show_if_answer: e.target.value })}
className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-purple-500 bg-white"
disabled={!formData.parent_question_id}
>
<option value="">Seleccione...</option>
{formData.parent_question_id && (() => {
const parentQ = questions.find(q => q.id === formData.parent_question_id)
if (!parentQ) return null
// Leer opciones del nuevo formato
const config = parentQ.options || {}
const parentType = config.type || parentQ.type
// Para boolean o single_choice, mostrar las opciones configuradas
if ((parentType === 'boolean' || parentType === 'single_choice') && config.choices) {
return config.choices.map((choice, idx) => (
<option key={idx} value={choice.value}>
{choice.label}
</option>
))
}
// Compatibilidad con tipos antiguos
if (parentType === 'pass_fail') {
return [
<option key="pass" value="pass"> Pasa</option>,
<option key="fail" value="fail"> Falla</option>
]
} else if (parentType === 'good_bad') {
return [
<option key="good" value="good"> Bueno</option>,
<option key="bad" value="bad"> Malo</option>
]
}
return <option disabled>Tipo de pregunta no compatible</option>
})()}
</select>
<p className="text-xs text-gray-500 mt-1">
La pregunta solo se mostrará con esta respuesta específica
</p>
</div>
</div>
{/* Indicador de profundidad */}
{formData.parent_question_id && (() => {
const parentQ = questions.find(q => q.id === formData.parent_question_id)
const parentDepth = parentQ?.depth_level || 0
const newDepth = parentDepth + 1
return (
<div className={`mt-3 p-2 rounded ${newDepth >= 5 ? 'bg-red-50 border border-red-200' : 'bg-blue-100'}`}>
<p className="text-xs">
📊 <strong>Profundidad:</strong> Nivel {newDepth} de 5 máximo
{newDepth >= 5 && ' ⚠️ Máximo alcanzado'}
</p>
</div>
)
})()}
</>
)
})()}
</div>

View File

@@ -101,9 +101,9 @@ export function QuestionTypeEditor({ value, onChange, maxPoints = 1 }) {
case 'single_choice':
case 'multiple_choice':
newConfig.choices = [
{ value: 'option1', label: 'Opción 1', points: maxPoints },
{ value: 'option2', label: 'Opción 2', points: Math.floor(maxPoints / 2) },
{ value: 'option3', label: 'Opción 3', points: 0 }
{ value: 'option1', label: 'Opción 1', status: 'ok' },
{ value: 'option2', label: 'Opción 2', status: 'warning' },
{ value: 'option3', label: 'Opción 3', status: 'critical' }
]
newConfig.allow_other = false
break
@@ -112,7 +112,6 @@ export function QuestionTypeEditor({ value, onChange, maxPoints = 1 }) {
newConfig.max = 5
newConfig.step = 1
newConfig.labels = { min: 'Muy malo', max: 'Excelente' }
newConfig.points_per_level = maxPoints / 5
break
case 'text':
newConfig.multiline = true
@@ -152,7 +151,7 @@ export function QuestionTypeEditor({ value, onChange, maxPoints = 1 }) {
const newChoices = [...config.choices, {
value: `option${config.choices.length + 1}`,
label: `Opción ${config.choices.length + 1}`,
points: 0
status: 'ok'
}]
updateConfig({ choices: newChoices })
}
@@ -232,29 +231,17 @@ export function QuestionTypeEditor({ value, onChange, maxPoints = 1 }) {
className="w-full px-2 py-1 border border-gray-300 rounded mb-2 text-sm"
placeholder="Texto de la opción"
/>
<div className="grid grid-cols-2 gap-2">
<div>
<label className="block text-xs text-gray-500 mb-1">Puntos</label>
<input
type="number"
value={choice.points}
onChange={(e) => updateChoice(idx, 'points', parseInt(e.target.value) || 0)}
className="w-full px-2 py-1 border border-gray-300 rounded text-sm"
min="0"
/>
</div>
<div>
<label className="block text-xs text-gray-500 mb-1">Estado</label>
<select
value={choice.status || 'info'}
onChange={(e) => updateChoice(idx, 'status', e.target.value)}
className="w-full px-2 py-1 border border-gray-300 rounded text-sm"
>
{STATUS_OPTIONS.map(s => (
<option key={s.value} value={s.value}>{s.label}</option>
))}
</select>
</div>
<div>
<label className="block text-xs text-gray-500 mb-1">Estado (Determina Puntuación)</label>
<select
value={choice.status || 'ok'}
onChange={(e) => updateChoice(idx, 'status', e.target.value)}
className="w-full px-2 py-1 border border-gray-300 rounded text-sm"
>
<option value="ok"> OK (1pt)</option>
<option value="warning"> Advertencia (0.5pt)</option>
<option value="critical"> Crítico (0pt)</option>
</select>
</div>
</div>
))}
@@ -295,14 +282,16 @@ export function QuestionTypeEditor({ value, onChange, maxPoints = 1 }) {
/>
</div>
<div>
<input
type="number"
value={choice.points}
onChange={(e) => updateChoice(idx, 'points', parseInt(e.target.value) || 0)}
<select
value={choice.status || 'ok'}
onChange={(e) => updateChoice(idx, 'status', e.target.value)}
className="w-full px-2 py-1 border border-gray-300 rounded text-sm"
placeholder="Puntos"
min="0"
/>
title="Define la puntuación: OK=1pt, Advertencia=0.5pt, Crítico=0pt"
>
<option value="ok"> OK (1pt)</option>
<option value="warning"> Advertencia (0.5pt)</option>
<option value="critical"> Crítico (0pt)</option>
</select>
</div>
</div>
<button

View File

@@ -6,7 +6,7 @@ export default function Sidebar({ user, activeTab, setActiveTab, sidebarOpen, se
{sidebarOpen && (
<div className="flex items-center gap-2">
<div className="w-8 h-8 bg-gradient-to-br from-indigo-500 to-purple-500 rounded-lg flex items-center justify-center">
<span className="text-white font-bold text-lg">S</span>
<span className="text-white font-bold text-lg">A</span>
</div>
<h2 className="text-xl font-bold bg-gradient-to-r from-indigo-400 to-purple-400 bg-clip-text text-transparent">Ayutec</h2>
</div>