fix(bedelia): corregir purga academica con integridad referencial, circuito agil de asignacion de aulas y documentacion v3.1.0
This commit is contained in:
@@ -332,13 +332,25 @@ const handlePostClassroom = async (req, res) => {
|
||||
targetBuilding = new_building_name;
|
||||
}
|
||||
|
||||
let bId = parseInt(targetBuilding, 10);
|
||||
if (isNaN(bId) || bId <= 0) {
|
||||
bId = (String(targetBuilding).toLowerCase().includes('virtual')) ? 2 : 1;
|
||||
}
|
||||
|
||||
const isVirtual = Boolean(
|
||||
bId === 2 ||
|
||||
String(targetBuilding).toLowerCase().includes('virtual') ||
|
||||
String(room_number).toUpperCase().includes('VIRTUAL') ||
|
||||
String(floor).toUpperCase() === 'DIGITAL'
|
||||
);
|
||||
|
||||
const payload = {
|
||||
code: room_number || `Aula-${Date.now()}`,
|
||||
capacity: (capacity === '∞' || capacity === '0' || !capacity) ? 0 : parseInt(capacity, 10),
|
||||
floor: floor || 'PB',
|
||||
building_id: (targetBuilding === '2' || targetBuilding === 'Campus Virtual') ? 2 : 1,
|
||||
capacity: (isVirtual || capacity === '∞' || capacity === '0' || !capacity) ? 0 : parseInt(capacity, 10),
|
||||
floor: floor || (isVirtual ? 'Digital' : 'PB'),
|
||||
building_id: bId,
|
||||
description: description || '',
|
||||
is_virtual: Boolean(targetBuilding === '2' || targetBuilding === 'Campus Virtual'),
|
||||
is_virtual: isVirtual,
|
||||
is_active: is_active === 'true' || is_active === 'on' || is_active === true
|
||||
};
|
||||
|
||||
@@ -529,13 +541,25 @@ const handlePostEditClassroom = async (req, res) => {
|
||||
targetBuilding = new_building_name;
|
||||
}
|
||||
|
||||
let bId = parseInt(targetBuilding, 10);
|
||||
if (isNaN(bId) || bId <= 0) {
|
||||
bId = (String(targetBuilding).toLowerCase().includes('virtual')) ? 2 : 1;
|
||||
}
|
||||
|
||||
const isVirtual = Boolean(
|
||||
bId === 2 ||
|
||||
String(targetBuilding).toLowerCase().includes('virtual') ||
|
||||
String(room_number).toUpperCase().includes('VIRTUAL') ||
|
||||
String(floor).toUpperCase() === 'DIGITAL'
|
||||
);
|
||||
|
||||
const payload = {
|
||||
code: room_number,
|
||||
capacity: (capacity === '∞' || capacity === '0' || !capacity) ? 0 : parseInt(capacity, 10),
|
||||
floor: floor || 'PB',
|
||||
building_id: (targetBuilding === '2' || targetBuilding === 'Campus Virtual') ? 2 : 1,
|
||||
capacity: (isVirtual || capacity === '∞' || capacity === '0' || !capacity) ? 0 : parseInt(capacity, 10),
|
||||
floor: floor || (isVirtual ? 'Digital' : 'PB'),
|
||||
building_id: bId,
|
||||
description: description || '',
|
||||
is_virtual: Boolean(targetBuilding === '2' || targetBuilding === 'Campus Virtual'),
|
||||
is_virtual: isVirtual,
|
||||
is_active: is_active === 'true' || is_active === 'on' || is_active === true
|
||||
};
|
||||
|
||||
|
||||
@@ -307,13 +307,33 @@ const handleAddReservation = async (req, res) => {
|
||||
};
|
||||
});
|
||||
|
||||
const commissionList = [
|
||||
{ id: 1, code: 'COM-ARQ-01', name: 'Arquitectura de Software - Comisión A', virtual_link: 'https://meet.google.com/edu-arq-01', max_students: 35 },
|
||||
{ id: 2, code: 'COM-BD-01', name: 'Bases de Datos II - Comisión Única', virtual_link: 'https://meet.google.com/edu-bd-01', max_students: 40 },
|
||||
{ id: 3, code: 'COM-PRG-01', name: 'Programación Avanzada - Comisión B', virtual_link: 'https://meet.google.com/edu-prg-01', max_students: 30 },
|
||||
{ id: 4, code: 'COM-RED-01', name: 'Redes y Telecomunicaciones - Comisión A', virtual_link: '', max_students: 28 },
|
||||
{ id: 5, code: 'COM-IA-01', name: 'Inteligencia Artificial - Comisión Tarde', virtual_link: 'https://meet.google.com/edu-ia-01', max_students: 32 }
|
||||
];
|
||||
let commissionList = [];
|
||||
try {
|
||||
const commRes = await req.apiClient.get('/commissions', { params: { active: 'true' } });
|
||||
if (commRes.data && commRes.data.commissions) {
|
||||
commissionList = commRes.data.commissions.map(c => ({
|
||||
id: c.id,
|
||||
code: c.full_code || c.code || `COM-${c.id}`,
|
||||
name: `${c.subject_name || 'Asignatura'} · ${c.code}`,
|
||||
subject_name: c.subject_name || 'Asignatura',
|
||||
max_students: c.max_students || 35,
|
||||
current_students: c.current_students || 0,
|
||||
shift: c.shift || 'Tarde',
|
||||
schedule: c.schedule || '',
|
||||
virtual_link: c.virtual_link || ''
|
||||
}));
|
||||
}
|
||||
} catch (commErr) {
|
||||
console.warn('Could not fetch real commissions:', commErr.message);
|
||||
}
|
||||
|
||||
if (commissionList.length === 0) {
|
||||
commissionList = [
|
||||
{ id: 1, code: 'COM-ARQ-01', name: 'Arquitectura de Software - Comisión A', virtual_link: 'https://meet.google.com/edu-arq-01', max_students: 35 },
|
||||
{ id: 2, code: 'COM-BD-01', name: 'Bases de Datos II - Comisión Única', virtual_link: 'https://meet.google.com/edu-bd-01', max_students: 40 },
|
||||
{ id: 3, code: 'COM-PRG-01', name: 'Programación Avanzada - Comisión B', virtual_link: 'https://meet.google.com/edu-prg-01', max_students: 30 }
|
||||
];
|
||||
}
|
||||
|
||||
const classroomOptions = [
|
||||
{ value: '', text: '-- Selecciona Aula --' },
|
||||
@@ -322,20 +342,36 @@ const handleAddReservation = async (req, res) => {
|
||||
|
||||
const commissionOptions = [
|
||||
{ value: '', text: '-- Selecciona Comisión / Materia --' },
|
||||
...commissionList.map(c => ({ value: c.id, text: `${c.code} · ${c.name} (${c.max_students} alum.)` }))
|
||||
...commissionList.map(c => ({ value: c.id, text: `${c.code} · ${c.name} (${c.max_students} alum. - ${c.shift || 'Turno'})` }))
|
||||
];
|
||||
|
||||
const initialClassroomId = req.query.classroom_id || '';
|
||||
const initialCommissionId = req.query.commission_id || '';
|
||||
let initialPurpose = 'Clase Regular';
|
||||
let initialExpectedAttendees = 30;
|
||||
let initialVirtualLink = '';
|
||||
|
||||
if (initialCommissionId) {
|
||||
const foundComm = commissionList.find(c => String(c.id) === String(initialCommissionId));
|
||||
if (foundComm) {
|
||||
initialPurpose = `${foundComm.subject_name} (${foundComm.code})`;
|
||||
initialExpectedAttendees = foundComm.max_students || 30;
|
||||
initialVirtualLink = foundComm.virtual_link || '';
|
||||
}
|
||||
}
|
||||
|
||||
const now = new Date();
|
||||
const startTimeDefault = new Date(now.getTime() + 3600000).toISOString().substring(0, 16);
|
||||
const endTimeDefault = new Date(now.getTime() + 7200000).toISOString().substring(0, 16);
|
||||
|
||||
const form = createFormMock({
|
||||
classroom_id: initialClassroomId,
|
||||
commission_id: initialCommissionId,
|
||||
start_time: startTimeDefault,
|
||||
end_time: endTimeDefault,
|
||||
expected_attendees: 30,
|
||||
purpose: 'Clase Regular'
|
||||
expected_attendees: initialExpectedAttendees,
|
||||
purpose: initialPurpose,
|
||||
virtual_link: initialVirtualLink
|
||||
}, {
|
||||
classroom_id: classroomOptions,
|
||||
commission_id: commissionOptions
|
||||
@@ -346,7 +382,9 @@ const handleAddReservation = async (req, res) => {
|
||||
form,
|
||||
classroom_list: classroomList,
|
||||
commission_list: commissionList,
|
||||
buildings: Array.from(buildingsMap.values())
|
||||
buildings: Array.from(buildingsMap.values()),
|
||||
initial_commission_id: initialCommissionId,
|
||||
initial_classroom_id: initialClassroomId
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error rendering add reservation:', error.message);
|
||||
@@ -499,13 +537,32 @@ const handleEditReservation = async (req, res) => {
|
||||
};
|
||||
});
|
||||
|
||||
const commissionList = [
|
||||
{ id: 1, code: 'COM-ARQ-01', name: 'Arquitectura de Software - Comisión A', virtual_link: 'https://meet.google.com/edu-arq-01', max_students: 35 },
|
||||
{ id: 2, code: 'COM-BD-01', name: 'Bases de Datos II - Comisión Única', virtual_link: 'https://meet.google.com/edu-bd-01', max_students: 40 },
|
||||
{ id: 3, code: 'COM-PRG-01', name: 'Programación Avanzada - Comisión B', virtual_link: 'https://meet.google.com/edu-prg-01', max_students: 30 },
|
||||
{ id: 4, code: 'COM-RED-01', name: 'Redes y Telecomunicaciones - Comisión A', virtual_link: '', max_students: 28 },
|
||||
{ id: 5, code: 'COM-IA-01', name: 'Inteligencia Artificial - Comisión Tarde', virtual_link: 'https://meet.google.com/edu-ia-01', max_students: 32 }
|
||||
];
|
||||
let commissionList = [];
|
||||
try {
|
||||
const commRes = await req.apiClient.get('/commissions');
|
||||
if (commRes.data && commRes.data.commissions) {
|
||||
commissionList = commRes.data.commissions.map(c => ({
|
||||
id: c.id,
|
||||
code: c.full_code || c.code || `COM-${c.id}`,
|
||||
name: `${c.subject_name || 'Asignatura'} · ${c.code}`,
|
||||
subject_name: c.subject_name || 'Asignatura',
|
||||
max_students: c.max_students || 35,
|
||||
current_students: c.current_students || 0,
|
||||
shift: c.shift || 'Tarde',
|
||||
schedule: c.schedule || '',
|
||||
virtual_link: c.virtual_link || ''
|
||||
}));
|
||||
}
|
||||
} catch (commErr) {
|
||||
console.warn('Could not fetch real commissions for edit:', commErr.message);
|
||||
}
|
||||
|
||||
if (commissionList.length === 0) {
|
||||
commissionList = [
|
||||
{ id: 1, code: 'COM-ARQ-01', name: 'Arquitectura de Software - Comisión A', virtual_link: 'https://meet.google.com/edu-arq-01', max_students: 35 },
|
||||
{ id: 2, code: 'COM-BD-01', name: 'Bases de Datos II - Comisión Única', virtual_link: 'https://meet.google.com/edu-bd-01', max_students: 40 }
|
||||
];
|
||||
}
|
||||
|
||||
const classroomOptions = classroomList.map(c => ({ value: c.id, text: `${c.code} · ${c.floor_display} (Cap: ${c.capacity_display})` }));
|
||||
const commissionOptions = commissionList.map(c => ({ value: c.id, text: `${c.code} · ${c.name} (${c.max_students} alum.)` }));
|
||||
|
||||
@@ -231,6 +231,10 @@
|
||||
class="btn btn-outline-primary py-0 px-2" title="Gestionar e Inscribir Alumnos">
|
||||
<i class="bi bi-gear"></i>
|
||||
</a>
|
||||
<a href="/schedule/add_reservation?commission_id={{ comm.id }}"
|
||||
class="btn btn-outline-info py-0 px-2" title="Asignar Aula / Horario a esta Comisión">
|
||||
<i class="bi bi-calendar-plus"></i>
|
||||
</a>
|
||||
<button type="button" class="btn btn-outline-secondary py-0 px-2"
|
||||
data-bs-toggle="modal" data-bs-target="#modalEditCommission"
|
||||
data-id="{{ comm.id }}"
|
||||
|
||||
@@ -460,28 +460,94 @@ function toggleSelectAll(checked) {
|
||||
}
|
||||
|
||||
function openPurgeModal() {
|
||||
const anyChecked = document.getElementById('chk_reservations').checked ||
|
||||
document.getElementById('chk_classrooms').checked ||
|
||||
document.getElementById('chk_commissions').checked ||
|
||||
document.getElementById('chk_subjects').checked ||
|
||||
document.getElementById('chk_careers').checked ||
|
||||
document.getElementById('chk_all').checked;
|
||||
const isAll = document.getElementById('chk_all').checked;
|
||||
const isRes = isAll || document.getElementById('chk_reservations').checked;
|
||||
const isCls = isAll || document.getElementById('chk_classrooms').checked;
|
||||
const isCom = isAll || document.getElementById('chk_commissions').checked;
|
||||
const isSub = isAll || document.getElementById('chk_subjects').checked;
|
||||
const isCar = isAll || document.getElementById('chk_careers').checked;
|
||||
|
||||
const anyChecked = isRes || isCls || isCom || isSub || isCar;
|
||||
if (!anyChecked) {
|
||||
alert('Por favor seleccione al menos una entidad para purgar.');
|
||||
return;
|
||||
}
|
||||
|
||||
const listEl = document.getElementById('purgeEntitiesList');
|
||||
if (listEl) {
|
||||
listEl.innerHTML = '';
|
||||
if (isAll) {
|
||||
listEl.innerHTML += '<li class="list-group-item list-group-item-danger fw-bold"><i class="bi bi-trash-fill me-2"></i>REINICIO TOTAL DEL ESQUEMA (Carreras, Asignaturas, Comisiones, Aulas y Reservas)</li>';
|
||||
} else {
|
||||
if (isCar) listEl.innerHTML += '<li class="list-group-item text-danger fw-semibold"><i class="bi bi-mortarboard me-2"></i>Carreras Académicas y sus Asignaturas asociadas</li>';
|
||||
if (isSub && !isCar) listEl.innerHTML += '<li class="list-group-item text-danger fw-semibold"><i class="bi bi-book me-2"></i>Asignaturas / Materias y sus Comisiones</li>';
|
||||
if (isCom && !isSub && !isCar) listEl.innerHTML += '<li class="list-group-item text-danger fw-semibold"><i class="bi bi-diagram-3 me-2"></i>Comisiones de Cursada e Inscripciones</li>';
|
||||
if (isRes) listEl.innerHTML += '<li class="list-group-item text-danger"><i class="bi bi-calendar-event me-2"></i>Asignaciones de Aulas (Reservas del Calendario)</li>';
|
||||
if (isCls) listEl.innerHTML += '<li class="list-group-item text-danger"><i class="bi bi-door-open me-2"></i>Aulas Físicas y Virtuales</li>';
|
||||
}
|
||||
}
|
||||
|
||||
const modalEl = document.getElementById('purgeConfirmModal');
|
||||
if (modalEl) {
|
||||
const modal = new bootstrap.Modal(modalEl);
|
||||
modal.show();
|
||||
if (modalEl && typeof bootstrap !== 'undefined' && bootstrap.Modal) {
|
||||
try {
|
||||
const modal = new bootstrap.Modal(modalEl);
|
||||
modal.show();
|
||||
return;
|
||||
} catch (e) {
|
||||
console.warn('Bootstrap modal error, falling back to window.confirm:', e);
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback nativo si Bootstrap modal no estuviera disponible
|
||||
if (confirm("ATENCIÓN: ¿Confirma la purga y eliminación permanente de los datos académicos seleccionados?\nEsta acción es irreversible.")) {
|
||||
confirmPurge();
|
||||
}
|
||||
}
|
||||
|
||||
function confirmPurge() {
|
||||
const btn = document.getElementById('btnDoPurge');
|
||||
if (btn) {
|
||||
btn.disabled = true;
|
||||
btn.innerHTML = '<span class="spinner-border spinner-border-sm me-2"></span>Purgando base de datos...';
|
||||
}
|
||||
const form = document.getElementById('purgeForm');
|
||||
if (form) {
|
||||
form.submit();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- Modal: Confirmación de Purga de Datos Académicos -->
|
||||
<div class="modal fade" id="purgeConfirmModal" tabindex="-1" aria-labelledby="purgeConfirmModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
<div class="modal-content border-0 shadow-lg">
|
||||
<div class="modal-header bg-danger text-white py-3">
|
||||
<h5 class="modal-title h6 fw-bold" id="purgeConfirmModalLabel">
|
||||
<i class="bi bi-exclamation-triangle-fill me-2"></i>Confirmar Purga de Datos Académicos
|
||||
</h5>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body p-4">
|
||||
<p class="mb-3 text-body">
|
||||
Se procederá a <strong>eliminar de forma permanente</strong> los siguientes registros de la base de datos:
|
||||
</p>
|
||||
<ul class="list-group list-group-flush border rounded mb-3 small" id="purgeEntitiesList">
|
||||
<!-- Poblado dinámicamente -->
|
||||
</ul>
|
||||
<div class="alert alert-warning small mb-0 d-flex gap-2 align-items-start">
|
||||
<i class="bi bi-shield-lock-fill fs-5 text-warning flex-shrink-0"></i>
|
||||
<div>
|
||||
<strong>Seguridad del Sistema:</strong> Los usuarios del sistema (administradores, bedeles, docentes, alumnos), sus contraseñas, roles RBAC y registros de auditoría <u>permanecerán intactos</u>.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer bg-body-tertiary border-top py-2">
|
||||
<button type="button" class="btn btn-outline-secondary btn-sm" data-bs-dismiss="modal">Cancelar</button>
|
||||
<button type="button" class="btn btn-danger btn-sm px-3" id="btnDoPurge" onclick="confirmPurge()">
|
||||
<i class="bi bi-trash-fill me-1"></i>Sí, Confirmar Purga
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
@@ -605,7 +605,33 @@ $(document).ready(function() {
|
||||
updateSummary();
|
||||
});
|
||||
|
||||
// Sincronización inicial si classroom_id viene precargado (desde aulas o query)
|
||||
const preselectedClassroomId = $classroom.val();
|
||||
if (preselectedClassroomId && classroomData[preselectedClassroomId]) {
|
||||
const c = classroomData[preselectedClassroomId];
|
||||
if (c.building_id) {
|
||||
$building.val(c.building_id).trigger('change');
|
||||
if (c.floor) {
|
||||
$floor.val(c.floor).trigger('change');
|
||||
}
|
||||
$classroom.val(preselectedClassroomId);
|
||||
}
|
||||
}
|
||||
|
||||
// Sincronización inicial si commission_id viene precargado (desde comisiones o query)
|
||||
const preselectedCommId = $('#commission-select').val();
|
||||
if (preselectedCommId && commissionData[preselectedCommId]) {
|
||||
const comm = commissionData[preselectedCommId];
|
||||
if (comm.virtual_link && !$('#virtual_link').val().trim()) {
|
||||
$('#virtual_link').val(comm.virtual_link);
|
||||
}
|
||||
if (comm.max_students && (!($('#expected_attendees').val()) || $('#expected_attendees').val() == '30')) {
|
||||
$('#expected_attendees').val(comm.max_students);
|
||||
}
|
||||
}
|
||||
|
||||
updateSummary();
|
||||
checkCapacity();
|
||||
|
||||
// Form validation
|
||||
$('#reservation-form').on('submit', function(e) {
|
||||
|
||||
Reference in New Issue
Block a user