fix(classrooms): excluir reservas pasadas de próximas clases y cursadas activas (v3.8.11)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "frontend",
|
||||
"version": "3.8.10",
|
||||
"version": "3.8.11",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
||||
+3
-3
@@ -86,9 +86,9 @@ const env = nunjucks.configure(path.join(__dirname, '../views'), {
|
||||
});
|
||||
|
||||
// Versiones institucionales del sistema
|
||||
const APP_VERSION = '3.8.10';
|
||||
const FRONTEND_VERSION = '3.8.10';
|
||||
const BACKEND_VERSION = '3.8.10';
|
||||
const APP_VERSION = '3.8.11';
|
||||
const FRONTEND_VERSION = '3.8.11';
|
||||
const BACKEND_VERSION = '3.8.11';
|
||||
|
||||
env.addGlobal('app_version', APP_VERSION);
|
||||
env.addGlobal('frontend_version', FRONTEND_VERSION);
|
||||
|
||||
@@ -122,6 +122,24 @@ const handleClassroomsList = async (req, res) => {
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Fechas operativas dinámicas calculadas desde el momento actual
|
||||
const now = new Date();
|
||||
const todayIso = now.toISOString().split('T')[0];
|
||||
|
||||
const dayOfWeek = now.getDay();
|
||||
const diffToMonday = (dayOfWeek === 0 ? -6 : 1) - dayOfWeek;
|
||||
const monday = new Date(now);
|
||||
monday.setDate(now.getDate() + diffToMonday);
|
||||
const sunday = new Date(monday);
|
||||
sunday.setDate(monday.getDate() + 6);
|
||||
const weekStartIso = monday.toISOString().split('T')[0];
|
||||
const weekEndIso = sunday.toISOString().split('T')[0];
|
||||
|
||||
const firstDayOfMonth = new Date(now.getFullYear(), now.getMonth(), 1);
|
||||
const lastDayOfMonth = new Date(now.getFullYear(), now.getMonth() + 1, 0);
|
||||
const monthStartIso = firstDayOfMonth.toISOString().split('T')[0];
|
||||
const monthEndIso = lastDayOfMonth.toISOString().split('T')[0];
|
||||
|
||||
// Normalizar campos de salas virtuales para garantizar compatibilidad con plantillas Nunjucks
|
||||
virtual_rooms = virtual_rooms.map(room => ({
|
||||
...room,
|
||||
@@ -130,7 +148,21 @@ const handleClassroomsList = async (req, res) => {
|
||||
week_count: room.week_count !== undefined ? room.week_count : (room.week_classes || 0),
|
||||
month_count: room.month_count !== undefined ? room.month_count : (room.month_classes || 0),
|
||||
total_count: room.total_count !== undefined ? room.total_count : (room.res_count || 0),
|
||||
reservations: room.reservations || []
|
||||
reservations: (room.reservations || []).map(r => {
|
||||
const sStr = String(r.start_time || '');
|
||||
const eStr = String(r.end_time || '');
|
||||
const dPart = sStr.includes('T') ? sStr.split('T')[0] : (sStr.split(' ')[0] || '');
|
||||
const isPast = dPart < todayIso;
|
||||
const sTime = sStr.includes('T') ? sStr.split('T')[1].substring(0, 5) : (sStr.split(' ')[1] ? sStr.split(' ')[1].substring(0, 5) : sStr);
|
||||
const eTime = eStr.includes('T') ? eStr.split('T')[1].substring(0, 5) : (eStr.split(' ')[1] ? eStr.split(' ')[1].substring(0, 5) : eStr);
|
||||
return {
|
||||
...r,
|
||||
date_clean: dPart,
|
||||
time_clean: `${sTime} a ${eTime} hs`,
|
||||
is_past: isPast,
|
||||
status_display: isPast ? 'Finalizada' : (r.status || 'CONFIRMED')
|
||||
};
|
||||
})
|
||||
}));
|
||||
|
||||
// Si la búsqueda está activa en modo virtual, filtrar el catálogo de salas virtuales
|
||||
@@ -150,24 +182,6 @@ const handleClassroomsList = async (req, res) => {
|
||||
virtual_count = allClassrooms.filter(c => Boolean(c.is_virtual || (c.code || '').includes('VIRTUAL'))).length;
|
||||
}
|
||||
|
||||
// 2. Fechas operativas dinámicas calculadas desde el momento actual
|
||||
const now = new Date();
|
||||
const todayIso = now.toISOString().split('T')[0];
|
||||
|
||||
const dayOfWeek = now.getDay();
|
||||
const diffToMonday = (dayOfWeek === 0 ? -6 : 1) - dayOfWeek;
|
||||
const monday = new Date(now);
|
||||
monday.setDate(now.getDate() + diffToMonday);
|
||||
const sunday = new Date(monday);
|
||||
sunday.setDate(monday.getDate() + 6);
|
||||
const weekStartIso = monday.toISOString().split('T')[0];
|
||||
const weekEndIso = sunday.toISOString().split('T')[0];
|
||||
|
||||
const firstDayOfMonth = new Date(now.getFullYear(), now.getMonth(), 1);
|
||||
const lastDayOfMonth = new Date(now.getFullYear(), now.getMonth() + 1, 0);
|
||||
const monthStartIso = firstDayOfMonth.toISOString().split('T')[0];
|
||||
const monthEndIso = lastDayOfMonth.toISOString().split('T')[0];
|
||||
|
||||
const dateFilters = {
|
||||
today: todayIso,
|
||||
week_start: weekStartIso,
|
||||
@@ -194,8 +208,18 @@ const handleClassroomsList = async (req, res) => {
|
||||
// Formatear aulas físicas y calcular métricas de ocupación en base al calendario activo
|
||||
const formattedItems = filtered.map(c => {
|
||||
const c_res = allReservations.filter(r => (c.id !== undefined && (String(r.classroom_id) === String(c.id) || (r.classroom && String(r.classroom.id) === String(c.id)))));
|
||||
|
||||
// Filtrar únicamente reservas activas y vigentes (de hoy en adelante) para las cursadas asignadas del aula
|
||||
const nowIso = now.toISOString();
|
||||
const active_c_res = c_res.filter(r => {
|
||||
const rawEnd = r.end_time ? String(r.end_time).replace(' ', 'T') : '';
|
||||
const rawStart = r.start_time ? String(r.start_time).replace(' ', 'T') : '';
|
||||
const datePart = rawStart.split('T')[0];
|
||||
return datePart >= todayIso || (rawEnd && rawEnd >= nowIso);
|
||||
});
|
||||
|
||||
const commMap = new Map();
|
||||
c_res.forEach(r => {
|
||||
active_c_res.forEach(r => {
|
||||
const cid = r.commission_id || (r.commission && r.commission.id) || r.id;
|
||||
if (!commMap.has(cid)) {
|
||||
commMap.set(cid, {
|
||||
@@ -237,7 +261,8 @@ const handleClassroomsList = async (req, res) => {
|
||||
floor_display: c.floor_display || (c.floor === '0' || c.floor === 'PB' ? 'Planta Baja' : `Piso ${c.floor}`),
|
||||
resources: c.resources || [],
|
||||
assigned_commissions: Array.from(commMap.values()),
|
||||
total_classes: c_res.length
|
||||
total_classes: active_c_res.length,
|
||||
historical_classes: c_res.length
|
||||
};
|
||||
});
|
||||
|
||||
@@ -440,6 +465,7 @@ const handleViewClassroom = async (req, res) => {
|
||||
try {
|
||||
let classroom = null;
|
||||
let upcomingReservations = [];
|
||||
let pastReservations = [];
|
||||
|
||||
try {
|
||||
const cRes = await req.apiClient.get(`/classrooms/${classroomId}`);
|
||||
@@ -468,13 +494,17 @@ const handleViewClassroom = async (req, res) => {
|
||||
classroom.code_display = classroom.code_display || classroom.code || `Aula-${classroomId}`;
|
||||
classroom.building_entity = classroom.building_entity || null;
|
||||
|
||||
// Fetch upcoming reservations for this classroom (encompassing full 2026 academic term)
|
||||
// Fetch upcoming and past reservations for this classroom
|
||||
try {
|
||||
const now = new Date();
|
||||
const todayIso = now.toISOString().split('T')[0];
|
||||
const nowIso = now.toISOString();
|
||||
|
||||
const rRes = await req.apiClient.get(`/reservations?classroom_id=${classroomId}&start_date=2026-08-01&end_date=2026-12-31`);
|
||||
const allClassroomRes = (rRes.data && (rRes.data.reservations || rRes.data)) || [];
|
||||
const dayNames = ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'];
|
||||
|
||||
upcomingReservations = allClassroomRes.map(r => {
|
||||
const formatReservationItem = (r) => {
|
||||
let dateDisplayFriendly = '';
|
||||
let timeRangeFriendly = '';
|
||||
let fullDisplay = '';
|
||||
@@ -514,7 +544,26 @@ const handleViewClassroom = async (req, res) => {
|
||||
start_time_display: r.start_time ? (r.start_time.includes('T') ? r.start_time.split('T')[1].substring(0, 5) : r.start_time) : '',
|
||||
end_time_display: r.end_time ? (r.end_time.includes('T') ? r.end_time.split('T')[1].substring(0, 5) : r.end_time) : ''
|
||||
};
|
||||
}).sort((a, b) => (a.start_time || '').localeCompare(b.start_time || '')).slice(0, 30);
|
||||
};
|
||||
|
||||
// Filtrar estrictamente Próximas Reservas (de hoy en adelante o no finalizadas)
|
||||
const upcomingRaw = allClassroomRes.filter(r => {
|
||||
const rawEnd = r.end_time ? String(r.end_time).replace(' ', 'T') : '';
|
||||
const rawStart = r.start_time ? String(r.start_time).replace(' ', 'T') : '';
|
||||
const datePart = rawStart.split('T')[0];
|
||||
return datePart >= todayIso || (rawEnd && rawEnd >= nowIso);
|
||||
});
|
||||
|
||||
// Reservas pasadas (ya concluidas en fechas anteriores)
|
||||
const pastRaw = allClassroomRes.filter(r => {
|
||||
const rawEnd = r.end_time ? String(r.end_time).replace(' ', 'T') : '';
|
||||
const rawStart = r.start_time ? String(r.start_time).replace(' ', 'T') : '';
|
||||
const datePart = rawStart.split('T')[0];
|
||||
return datePart < todayIso && (!rawEnd || rawEnd < nowIso);
|
||||
});
|
||||
|
||||
upcomingReservations = upcomingRaw.map(formatReservationItem).sort((a, b) => (a.start_time || '').localeCompare(b.start_time || '')).slice(0, 30);
|
||||
pastReservations = pastRaw.map(formatReservationItem).sort((a, b) => (b.start_time || '').localeCompare(a.start_time || '')).slice(0, 30);
|
||||
} catch (e) {
|
||||
console.warn('Could not fetch reservations for classroom:', e.message);
|
||||
}
|
||||
@@ -522,7 +571,8 @@ const handleViewClassroom = async (req, res) => {
|
||||
res.render('classrooms/view', {
|
||||
title: `${classroom.code_display} - Edu-Space Admin`,
|
||||
classroom,
|
||||
upcoming_reservations: upcomingReservations
|
||||
upcoming_reservations: upcomingReservations,
|
||||
past_reservations: pastReservations
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error in view classroom:', error.message);
|
||||
|
||||
@@ -952,9 +952,9 @@
|
||||
<tr>
|
||||
<td class="text-muted">#{{ r.id }}</td>
|
||||
<td>
|
||||
<span class="fw-bold text-body">{{ r.start_time }}</span>
|
||||
<span class="fw-bold text-body">{{ r.date_clean or r.start_time }}</span>
|
||||
<span class="text-muted d-block font-monospace" style="font-size: 0.72rem;">
|
||||
{{ r.start_time }} - {{ r.end_time }} hs
|
||||
<i class="bi bi-clock me-1"></i>{{ r.time_clean or (r.start_time + ' - ' + r.end_time) }}
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
@@ -974,9 +974,15 @@
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{% if r.is_past %}
|
||||
<span class="badge bg-secondary-subtle text-secondary border" style="font-size: 0.68rem;">
|
||||
<i class="bi bi-check2-circle me-1"></i>Finalizada
|
||||
</span>
|
||||
{% else %}
|
||||
<span class="badge bg-success-subtle text-success border border-success-subtle" style="font-size: 0.68rem;">
|
||||
{{ r.status }}
|
||||
</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td class="text-end">
|
||||
<div class="btn-group btn-group-sm">
|
||||
|
||||
@@ -168,6 +168,50 @@
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if past_reservations and (past_reservations|length > 0) %}
|
||||
<div class="border-top p-3 bg-body-tertiary">
|
||||
<div class="d-flex justify-content-between align-items-center">
|
||||
<span class="small fw-semibold text-muted">
|
||||
<i class="bi bi-clock-history me-1"></i>Historial de Clases Finalizadas ({{ past_reservations|length }})
|
||||
</span>
|
||||
<button class="btn btn-sm btn-link text-decoration-none p-0 text-muted" type="button" data-bs-toggle="collapse" data-bs-target="#collapsePastClasses" aria-expanded="false" style="font-size: 0.75rem;">
|
||||
Ver historial anterior <i class="bi bi-chevron-down ms-1"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div class="collapse mt-2" id="collapsePastClasses">
|
||||
<div class="table-responsive bg-body rounded border">
|
||||
<table class="table table-sm table-hover align-middle mb-0" style="font-size: 0.78rem;">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th class="ps-2">Fecha y Horario</th>
|
||||
<th>Materia</th>
|
||||
<th>Comisión</th>
|
||||
<th class="text-end pe-2">Estado</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for pres in past_reservations %}
|
||||
<tr class="text-muted">
|
||||
<td class="ps-2">
|
||||
<i class="bi bi-check2-circle me-1 text-secondary"></i>{{ pres.date_display_friendly }} · {{ pres.time_range_friendly }}
|
||||
</td>
|
||||
<td>
|
||||
<span class="fw-semibold">{{ pres.subject_name }}</span>
|
||||
{% if pres.subject_code %}
|
||||
<small class="badge bg-secondary-subtle text-secondary font-monospace ms-1">{{ pres.subject_code }}</small>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td><span class="badge bg-secondary-subtle text-secondary font-monospace">{{ pres.commission.code if pres.commission else 'C1' }}</span></td>
|
||||
<td class="text-end pe-2"><span class="badge bg-secondary-subtle text-secondary border">Finalizada</span></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user