fix(v3.4.6): fix reservation cascade, remove calendar mocks, strip auto meet links, friendly dates, dynamic building floors and career filter
This commit is contained in:
+3
-3
@@ -85,9 +85,9 @@ const env = nunjucks.configure(path.join(__dirname, '../views'), {
|
||||
});
|
||||
|
||||
// Versiones institucionales del sistema
|
||||
const APP_VERSION = '3.4.5';
|
||||
const FRONTEND_VERSION = '3.4.5';
|
||||
const BACKEND_VERSION = '3.4.5';
|
||||
const APP_VERSION = '3.4.6';
|
||||
const FRONTEND_VERSION = '3.4.6';
|
||||
const BACKEND_VERSION = '3.4.6';
|
||||
|
||||
env.addGlobal('app_version', APP_VERSION);
|
||||
env.addGlobal('frontend_version', FRONTEND_VERSION);
|
||||
|
||||
@@ -85,12 +85,17 @@ const handleListBuildings = async (req, res) => {
|
||||
.filter(b => !b.is_virtual)
|
||||
.reduce((acc, b) => acc + (b.physical_capacity || b.total_capacity || 0), 0);
|
||||
|
||||
const total_floors = stats.total_floors || buildings
|
||||
.filter(b => !b.is_virtual)
|
||||
.reduce((acc, b) => acc + (parseInt(b.floors, 10) || 0), 0);
|
||||
|
||||
res.render('buildings/list', {
|
||||
title: 'Gestión de Edificios - Edu-Space Admin',
|
||||
buildings,
|
||||
total_classrooms: stats.total_classrooms || buildings.reduce((a, b) => a + (b.classrooms_count || 0), 0),
|
||||
total_capacity: total_physical_capacity,
|
||||
total_physical_capacity,
|
||||
total_floors,
|
||||
search,
|
||||
status_filter: status
|
||||
});
|
||||
@@ -102,6 +107,7 @@ const handleListBuildings = async (req, res) => {
|
||||
total_classrooms: 31,
|
||||
total_capacity: 1250,
|
||||
total_physical_capacity: 1250,
|
||||
total_floors: 4,
|
||||
search: '',
|
||||
status_filter: ''
|
||||
});
|
||||
@@ -174,10 +180,44 @@ router.get(['/view/:id', '/view_building', '/:id'], async (req, res) => {
|
||||
floors_display: is_virtual ? 'Digital' : String(building.floors ?? 1)
|
||||
};
|
||||
|
||||
// Agrupación dinámica por piso / nivel
|
||||
const floorsMap = new Map();
|
||||
classrooms.forEach(c => {
|
||||
const floorKey = c.floor_display || (c.floor === '0' || c.floor === 'PB' ? 'Planta Baja (PB)' : (c.floor ? (c.floor.toLowerCase().startsWith('piso') ? c.floor : `Piso ${c.floor}`) : 'Planta Baja (PB)'));
|
||||
if (!floorsMap.has(floorKey)) {
|
||||
floorsMap.set(floorKey, []);
|
||||
}
|
||||
floorsMap.get(floorKey).push(c);
|
||||
});
|
||||
|
||||
const sortedFloorKeys = Array.from(floorsMap.keys()).sort((a, b) => {
|
||||
const fA = String(a).toUpperCase();
|
||||
const fB = String(b).toUpperCase();
|
||||
if (fA.includes('SUB') || fA.includes('SS')) return -1;
|
||||
if (fB.includes('SUB') || fB.includes('SS')) return 1;
|
||||
if (fA.includes('PB') || fA.includes('PLANTA BAJA')) return -1;
|
||||
if (fB.includes('PB') || fB.includes('PLANTA BAJA')) return 1;
|
||||
if (fA.includes('EP') || fA.includes('ENTRE')) return -1;
|
||||
if (fB.includes('EP') || fB.includes('ENTRE')) return 1;
|
||||
return fA.localeCompare(fB, undefined, { numeric: true });
|
||||
});
|
||||
|
||||
const floors_list = sortedFloorKeys.map(floorName => ({
|
||||
floor_name: floorName,
|
||||
classrooms: floorsMap.get(floorName)
|
||||
}));
|
||||
|
||||
const classrooms_by_floor = {};
|
||||
floorsMap.forEach((rooms, floorName) => {
|
||||
classrooms_by_floor[floorName] = rooms;
|
||||
});
|
||||
|
||||
res.render('buildings/view', {
|
||||
title: `Edificio ${building.name} - Edu-Space Admin`,
|
||||
building,
|
||||
classrooms
|
||||
classrooms,
|
||||
classrooms_by_floor,
|
||||
floors_list
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -456,16 +456,53 @@ 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
|
||||
// Fetch upcoming reservations for this classroom (encompassing full 2026 academic term)
|
||||
try {
|
||||
const rRes = await req.apiClient.get(`/reservations?classroom_id=${classroomId}&start_date=2026-08-31&end_date=2026-10-01`);
|
||||
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)) || [];
|
||||
upcomingReservations = allClassroomRes.map(r => ({
|
||||
...r,
|
||||
date_display: r.start_time ? r.start_time.split('T')[0] : '',
|
||||
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, 20);
|
||||
const dayNames = ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'];
|
||||
|
||||
upcomingReservations = allClassroomRes.map(r => {
|
||||
let dateDisplayFriendly = '';
|
||||
let timeRangeFriendly = '';
|
||||
let fullDisplay = '';
|
||||
|
||||
if (r.start_time) {
|
||||
try {
|
||||
const rawStart = String(r.start_time).replace(' ', 'T');
|
||||
const rawEnd = r.end_time ? String(r.end_time).replace(' ', 'T') : '';
|
||||
const dtStart = new Date(rawStart);
|
||||
const dtEnd = rawEnd ? new Date(rawEnd) : null;
|
||||
|
||||
const dayName = dayNames[dtStart.getDay()];
|
||||
const d = String(dtStart.getDate()).padStart(2, '0');
|
||||
const m = String(dtStart.getMonth() + 1).padStart(2, '0');
|
||||
const y = dtStart.getFullYear();
|
||||
dateDisplayFriendly = `${dayName} ${d}/${m}/${y}`;
|
||||
|
||||
const sH = String(dtStart.getHours()).padStart(2, '0');
|
||||
const sM = String(dtStart.getMinutes()).padStart(2, '0');
|
||||
const eH = dtEnd ? String(dtEnd.getHours()).padStart(2, '0') : '';
|
||||
const eM = dtEnd ? String(dtEnd.getMinutes()).padStart(2, '0') : '';
|
||||
timeRangeFriendly = dtEnd ? `${sH}:${sM} a ${eH}:${eM} hs` : `${sH}:${sM} hs`;
|
||||
fullDisplay = `${dateDisplayFriendly} · ${timeRangeFriendly}`;
|
||||
} catch (e) {
|
||||
dateDisplayFriendly = r.start_time.split('T')[0] || r.start_time;
|
||||
timeRangeFriendly = r.end_time ? `${r.start_time} - ${r.end_time}` : r.start_time;
|
||||
fullDisplay = `${dateDisplayFriendly} · ${timeRangeFriendly}`;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
...r,
|
||||
date_display: r.start_time ? r.start_time.split('T')[0] : '',
|
||||
date_display_friendly: dateDisplayFriendly,
|
||||
time_range_friendly: timeRangeFriendly,
|
||||
full_display: fullDisplay,
|
||||
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);
|
||||
} catch (e) {
|
||||
console.warn('Could not fetch reservations for classroom:', e.message);
|
||||
}
|
||||
|
||||
@@ -29,6 +29,23 @@ const handleCalendarView = async (req, res) => {
|
||||
console.warn('Could not fetch unassigned commissions for calendar:', e.message);
|
||||
}
|
||||
|
||||
let careers = [];
|
||||
let subjects = [];
|
||||
try {
|
||||
const [carRes, subRes] = await Promise.allSettled([
|
||||
req.apiClient.get('/careers'),
|
||||
req.apiClient.get('/subjects')
|
||||
]);
|
||||
if (carRes.status === 'fulfilled' && carRes.value.data) {
|
||||
careers = carRes.value.data.careers || [];
|
||||
}
|
||||
if (subRes.status === 'fulfilled' && subRes.value.data) {
|
||||
subjects = subRes.value.data.subjects || [];
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('Could not fetch real careers/subjects for calendar filters:', e.message);
|
||||
}
|
||||
|
||||
res.render('schedule/calendar', {
|
||||
title: 'Reservations Calendar - Edu-Space Admin',
|
||||
today_date: new Date().toISOString().split('T')[0],
|
||||
@@ -39,15 +56,8 @@ const handleCalendarView = async (req, res) => {
|
||||
capacity: c.capacity || 40
|
||||
})),
|
||||
unassigned_commissions: unassignedCommissions,
|
||||
subjects: [
|
||||
{ id: 1, name: 'Arquitectura de Software', code: 'ARQ-101' },
|
||||
{ id: 2, name: 'Bases de Datos II', code: 'BD-201' },
|
||||
{ id: 3, name: 'Programación Avanzada', code: 'PRG-301' }
|
||||
],
|
||||
careers: [
|
||||
{ id: 1, name: 'Licenciatura en Sistemas' },
|
||||
{ id: 2, name: 'Tecnicatura Universitaria en Desarrollo de Software' }
|
||||
],
|
||||
subjects,
|
||||
careers,
|
||||
buildings: Array.from(buildingsMap.values()),
|
||||
available_floors: Array.from(floorsSet).sort(),
|
||||
session: { get: (k, d) => d }
|
||||
@@ -89,27 +99,34 @@ const handleCalendarData = async (req, res) => {
|
||||
if (r.status === 'PENDING') eventColor = '#F59E0B';
|
||||
else if (isVirtual) eventColor = '#6366F1';
|
||||
|
||||
const subjectName = r.subject_name || r.purpose || 'Clase Regular';
|
||||
const subjectCode = r.subject_code || '';
|
||||
const careerName = (r.commission && r.commission.career_names) || (r.commission && r.commission.career_name) || r.career_names || r.career_name || '';
|
||||
const commissionCode = (r.commission && r.commission.code) || r.commission_code || '';
|
||||
const roomName = r.classroom_name || (r.classroom ? r.classroom.code : 'Aula');
|
||||
const locationDisplay = (r.classroom && r.classroom.location_display) || (r.classroom && r.classroom.building) || r.classroom_name || 'Edificio Central';
|
||||
|
||||
return {
|
||||
id: r.id,
|
||||
title: `${r.purpose || 'Clase Regular'} - ${r.classroom_name || 'Aula'}`,
|
||||
title: `${subjectName} - ${roomName}`,
|
||||
start: r.start_time,
|
||||
end: r.end_time,
|
||||
backgroundColor: eventColor,
|
||||
borderColor: eventColor,
|
||||
extendedProps: {
|
||||
subject_name: 'Arquitectura de Software',
|
||||
subject_code: 'ARQ-101',
|
||||
classroom: r.classroom_name || 'Aula Principal',
|
||||
subject_name: subjectName,
|
||||
subject_code: subjectCode,
|
||||
classroom: roomName,
|
||||
is_virtual: isVirtual,
|
||||
location_display: r.classroom_name || 'Edificio Central',
|
||||
career: 'Licenciatura en Sistemas',
|
||||
commission: 'COM-A',
|
||||
shift: r.shift || 'Noche',
|
||||
location_display: locationDisplay,
|
||||
career: careerName,
|
||||
commission: commissionCode,
|
||||
shift: r.shift || 'Mañana',
|
||||
status: (r.status || 'CONFIRMED').toUpperCase(),
|
||||
purpose: r.purpose || 'Clase Regular',
|
||||
attendees: r.expected_attendees || 35,
|
||||
teacher: r.teacher_name || 'Profesor Titular',
|
||||
virtual_link: r.virtual_link || '',
|
||||
purpose: r.purpose || subjectName,
|
||||
attendees: r.expected_attendees || 30,
|
||||
teacher: r.teacher_name || '',
|
||||
virtual_link: r.effective_virtual_link || r.virtual_link || '',
|
||||
cancel_url: `/schedule/cancel_reservation?id=${r.id}`
|
||||
}
|
||||
};
|
||||
@@ -528,11 +545,18 @@ const handleAddReservation = async (req, res) => {
|
||||
commission_id: commissionOptions
|
||||
});
|
||||
|
||||
const classroomDataMap = {};
|
||||
classroomList.forEach(c => { classroomDataMap[c.id] = c; });
|
||||
const commissionDataMap = {};
|
||||
commissionList.forEach(c => { commissionDataMap[c.id] = c; });
|
||||
|
||||
res.render('schedule/add', {
|
||||
title: 'New Reservation - Edu-Space Admin',
|
||||
form,
|
||||
classroom_list: classroomList,
|
||||
commission_list: commissionList,
|
||||
classroom_data_json: JSON.stringify(classroomDataMap),
|
||||
commission_data_json: JSON.stringify(commissionDataMap),
|
||||
buildings: Array.from(buildingsMap.values()),
|
||||
initial_commission_id: initialCommissionId,
|
||||
initial_classroom_id: initialClassroomId
|
||||
@@ -737,12 +761,19 @@ const handleEditReservation = async (req, res) => {
|
||||
commission_id: commissionOptions
|
||||
});
|
||||
|
||||
const classroomDataMap = {};
|
||||
classroomList.forEach(c => { classroomDataMap[c.id] = c; });
|
||||
const commissionDataMap = {};
|
||||
commissionList.forEach(c => { commissionDataMap[c.id] = c; });
|
||||
|
||||
res.render('schedule/edit', {
|
||||
title: `Modificar Reserva #${id} - Edu-Space Admin`,
|
||||
reservation,
|
||||
form,
|
||||
classroom_list: classroomList,
|
||||
commission_list: commissionList,
|
||||
classroom_data_json: JSON.stringify(classroomDataMap),
|
||||
commission_data_json: JSON.stringify(commissionDataMap),
|
||||
buildings: Array.from(buildingsMap.values())
|
||||
});
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user