back 1.0.38 y front 1.0.39 cambios en condicionales de sub preguntas, solo boleanos
This commit is contained in:
@@ -1062,12 +1062,12 @@ def create_answer(
|
|||||||
if not question:
|
if not question:
|
||||||
raise HTTPException(status_code=404, detail="Pregunta no encontrada")
|
raise HTTPException(status_code=404, detail="Pregunta no encontrada")
|
||||||
|
|
||||||
# Calcular puntos según status
|
# Sistema simplificado: 1 punto por pregunta correcta
|
||||||
points_earned = 0
|
points_earned = 0
|
||||||
if answer.status == "ok":
|
if answer.status == "ok":
|
||||||
points_earned = question.points
|
points_earned = 1
|
||||||
elif answer.status == "warning":
|
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
|
# Buscar si ya existe una respuesta para esta inspección y pregunta
|
||||||
existing_answer = db.query(models.Answer).filter(
|
existing_answer = db.query(models.Answer).filter(
|
||||||
|
|||||||
@@ -1130,107 +1130,127 @@ function QuestionsManagerModal({ checklist, onClose }) {
|
|||||||
<h4 className="text-sm font-semibold text-blue-900 mb-3">
|
<h4 className="text-sm font-semibold text-blue-900 mb-3">
|
||||||
⚡ Pregunta Condicional - Subpreguntas Anidadas (hasta 5 niveles)
|
⚡ Pregunta Condicional - Subpreguntas Anidadas (hasta 5 niveles)
|
||||||
</h4>
|
</h4>
|
||||||
<div className="grid grid-cols-2 gap-4">
|
{/* Solo permitir condicionales para boolean y single_choice */}
|
||||||
<div>
|
{(() => {
|
||||||
<label className="block text-sm font-medium text-gray-700 mb-1">
|
const currentType = formData.options?.type || formData.type
|
||||||
Pregunta padre
|
const allowConditional = ['boolean', 'single_choice'].includes(currentType)
|
||||||
</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
|
if (!allowConditional) {
|
||||||
const config = parentQ.options || {}
|
return (
|
||||||
const parentType = config.type || parentQ.type
|
<div className="p-3 bg-gray-50 rounded-lg border border-gray-200">
|
||||||
|
<p className="text-sm text-gray-600">
|
||||||
// Para boolean o single_choice, mostrar las opciones configuradas
|
ℹ️ Las preguntas condicionales solo están disponibles para tipos <strong>Boolean</strong> y <strong>Opción Única</strong>
|
||||||
if ((parentType === 'boolean' || parentType === 'single_choice') && config.choices) {
|
</p>
|
||||||
return config.choices.map((choice, idx) => (
|
</div>
|
||||||
<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 (
|
return (
|
||||||
<div className={`mt-3 p-2 rounded ${newDepth >= 5 ? 'bg-red-50 border border-red-200' : 'bg-blue-100'}`}>
|
<>
|
||||||
<p className="text-xs">
|
<div className="grid grid-cols-2 gap-4">
|
||||||
📊 <strong>Profundidad:</strong> Nivel {newDepth} de 5 máximo
|
<div>
|
||||||
{newDepth >= 5 && ' ⚠️ Máximo alcanzado'}
|
<label className="block text-sm font-medium text-gray-700 mb-1">
|
||||||
</p>
|
Pregunta padre
|
||||||
</div>
|
</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>
|
</div>
|
||||||
|
|||||||
@@ -101,9 +101,9 @@ export function QuestionTypeEditor({ value, onChange, maxPoints = 1 }) {
|
|||||||
case 'single_choice':
|
case 'single_choice':
|
||||||
case 'multiple_choice':
|
case 'multiple_choice':
|
||||||
newConfig.choices = [
|
newConfig.choices = [
|
||||||
{ value: 'option1', label: 'Opción 1', points: maxPoints },
|
{ value: 'option1', label: 'Opción 1', status: 'ok' },
|
||||||
{ value: 'option2', label: 'Opción 2', points: Math.floor(maxPoints / 2) },
|
{ value: 'option2', label: 'Opción 2', status: 'warning' },
|
||||||
{ value: 'option3', label: 'Opción 3', points: 0 }
|
{ value: 'option3', label: 'Opción 3', status: 'critical' }
|
||||||
]
|
]
|
||||||
newConfig.allow_other = false
|
newConfig.allow_other = false
|
||||||
break
|
break
|
||||||
@@ -112,7 +112,6 @@ export function QuestionTypeEditor({ value, onChange, maxPoints = 1 }) {
|
|||||||
newConfig.max = 5
|
newConfig.max = 5
|
||||||
newConfig.step = 1
|
newConfig.step = 1
|
||||||
newConfig.labels = { min: 'Muy malo', max: 'Excelente' }
|
newConfig.labels = { min: 'Muy malo', max: 'Excelente' }
|
||||||
newConfig.points_per_level = maxPoints / 5
|
|
||||||
break
|
break
|
||||||
case 'text':
|
case 'text':
|
||||||
newConfig.multiline = true
|
newConfig.multiline = true
|
||||||
@@ -152,7 +151,7 @@ export function QuestionTypeEditor({ value, onChange, maxPoints = 1 }) {
|
|||||||
const newChoices = [...config.choices, {
|
const newChoices = [...config.choices, {
|
||||||
value: `option${config.choices.length + 1}`,
|
value: `option${config.choices.length + 1}`,
|
||||||
label: `Opción ${config.choices.length + 1}`,
|
label: `Opción ${config.choices.length + 1}`,
|
||||||
points: 0
|
status: 'ok'
|
||||||
}]
|
}]
|
||||||
updateConfig({ choices: newChoices })
|
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"
|
className="w-full px-2 py-1 border border-gray-300 rounded mb-2 text-sm"
|
||||||
placeholder="Texto de la opción"
|
placeholder="Texto de la opción"
|
||||||
/>
|
/>
|
||||||
<div className="grid grid-cols-2 gap-2">
|
<div>
|
||||||
<div>
|
<label className="block text-xs text-gray-500 mb-1">Estado (Determina Puntuación)</label>
|
||||||
<label className="block text-xs text-gray-500 mb-1">Puntos</label>
|
<select
|
||||||
<input
|
value={choice.status || 'ok'}
|
||||||
type="number"
|
onChange={(e) => updateChoice(idx, 'status', e.target.value)}
|
||||||
value={choice.points}
|
className="w-full px-2 py-1 border border-gray-300 rounded text-sm"
|
||||||
onChange={(e) => updateChoice(idx, 'points', parseInt(e.target.value) || 0)}
|
>
|
||||||
className="w-full px-2 py-1 border border-gray-300 rounded text-sm"
|
<option value="ok">✓ OK (1pt)</option>
|
||||||
min="0"
|
<option value="warning">⚠ Advertencia (0.5pt)</option>
|
||||||
/>
|
<option value="critical">✗ Crítico (0pt)</option>
|
||||||
</div>
|
</select>
|
||||||
<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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
@@ -295,14 +282,16 @@ export function QuestionTypeEditor({ value, onChange, maxPoints = 1 }) {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<input
|
<select
|
||||||
type="number"
|
value={choice.status || 'ok'}
|
||||||
value={choice.points}
|
onChange={(e) => updateChoice(idx, 'status', e.target.value)}
|
||||||
onChange={(e) => updateChoice(idx, 'points', parseInt(e.target.value) || 0)}
|
|
||||||
className="w-full px-2 py-1 border border-gray-300 rounded text-sm"
|
className="w-full px-2 py-1 border border-gray-300 rounded text-sm"
|
||||||
placeholder="Puntos"
|
title="Define la puntuación: OK=1pt, Advertencia=0.5pt, Crítico=0pt"
|
||||||
min="0"
|
>
|
||||||
/>
|
<option value="ok">✓ OK (1pt)</option>
|
||||||
|
<option value="warning">⚠ Advertencia (0.5pt)</option>
|
||||||
|
<option value="critical">✗ Crítico (0pt)</option>
|
||||||
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ export default function Sidebar({ user, activeTab, setActiveTab, sidebarOpen, se
|
|||||||
{sidebarOpen && (
|
{sidebarOpen && (
|
||||||
<div className="flex items-center gap-2">
|
<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">
|
<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>
|
</div>
|
||||||
<h2 className="text-xl font-bold bg-gradient-to-r from-indigo-400 to-purple-400 bg-clip-text text-transparent">Ayutec</h2>
|
<h2 className="text-xl font-bold bg-gradient-to-r from-indigo-400 to-purple-400 bg-clip-text text-transparent">Ayutec</h2>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user